Skip to content

Commit 60f8e87

Browse files
authored
✨ DGUS Reloaded: Filament Sensor, Language, Standing Status (#28590)
1 parent e11bf0f commit 60f8e87

13 files changed

Lines changed: 213 additions & 4 deletions

‎Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include "config/DGUS_ScreenID.h"
3131

3232
#include "../ui_api.h"
33+
34+
#if HAS_FILAMENT_SENSOR
35+
#include "../../../feature/runout.h"
36+
#endif
3337
#include "../../../core/language.h"
3438
#include "../../../module/temperature.h"
3539
#include "../../../module/printcounter.h"
@@ -934,6 +938,64 @@ void DGUSRxHandler::waitContinue(DGUS_VP &vp, void *data_ptr) {
934938
screen.triggerFullUpdate();
935939
}
936940

941+
#if HAS_FILAMENT_SENSOR
942+
943+
void DGUSRxHandler::filamentSensorToggle(DGUS_VP &vp, void *data_ptr) {
944+
UNUSED(vp);
945+
946+
const DGUS_Data::FilamentSensor sensor = (DGUS_Data::FilamentSensor)((uint8_t*)data_ptr)[1];
947+
948+
switch (sensor) {
949+
default: return;
950+
case DGUS_Data::FilamentSensor::RUNOUT:
951+
ExtUI::setFilamentRunoutEnabled(!ExtUI::getFilamentRunoutEnabled());
952+
break;
953+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
954+
case DGUS_Data::FilamentSensor::JAM:
955+
if (runout.motion_distance() > 0) {
956+
screen.jam_length = runout.motion_distance();
957+
runout.set_motion_distance(0);
958+
}
959+
else
960+
runout.set_motion_distance(screen.jam_length);
961+
break;
962+
#endif
963+
}
964+
965+
runout.reset();
966+
screen.triggerFullUpdate();
967+
}
968+
969+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
970+
void DGUSRxHandler::filamentSensorJam(DGUS_VP &vp, void *data_ptr) {
971+
UNUSED(vp);
972+
973+
const uint16_t length = BE16_P(data_ptr);
974+
975+
if (length) screen.jam_length = length;
976+
runout.set_motion_distance(length);
977+
runout.reset();
978+
979+
screen.triggerFullUpdate();
980+
}
981+
#endif
982+
983+
void DGUSRxHandler::filamentSensorSave(DGUS_VP &vp, void *data_ptr) {
984+
UNUSED(vp);
985+
UNUSED(data_ptr);
986+
987+
screen.triggerEEPROMSave();
988+
}
989+
990+
#endif // HAS_FILAMENT_SENSOR
991+
992+
void DGUSRxHandler::language(DGUS_VP &vp, void *data_ptr) {
993+
UNUSED(vp);
994+
995+
screen.language = ((uint8_t*)data_ptr)[1];
996+
screen.triggerEEPROMSave();
997+
}
998+
937999
void DGUSRxHandler::fanSpeed(DGUS_VP &vp, void *data_ptr) {
9381000
uint8_t speed = ((uint8_t*)data_ptr)[1];
9391001
switch (vp.addr) {

‎Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ namespace DGUSRxHandler {
8686
void waitAbort(DGUS_VP &, void *);
8787
void waitContinue(DGUS_VP &, void *);
8888

89+
#if HAS_FILAMENT_SENSOR
90+
void filamentSensorToggle(DGUS_VP &, void *);
91+
void filamentSensorSave(DGUS_VP &, void *);
92+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
93+
void filamentSensorJam(DGUS_VP &, void *);
94+
#endif
95+
#endif
96+
97+
void language(DGUS_VP &, void *);
98+
8999
void fanSpeed(DGUS_VP &, void *);
90100

91101
void volume(DGUS_VP &, void *);

‎Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ bool DGUSScreenHandler::wait_continue = false;
6666

6767
bool DGUSScreenHandler::leveling_active = false;
6868

69+
uint8_t DGUSScreenHandler::language = 0;
70+
71+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
72+
uint16_t DGUSScreenHandler::jam_length = DGUS_DEFAULT_JAM_LEN;
73+
#endif
74+
6975
millis_t DGUSScreenHandler::status_expire = 0;
76+
char DGUSScreenHandler::standing_status[] = "";
7077
millis_t DGUSScreenHandler::eeprom_save = 0;
7178

7279
void DGUSScreenHandler::init() {
@@ -135,7 +142,7 @@ void DGUSScreenHandler::loop() {
135142
}
136143

137144
if (status_expire > 0 && ELAPSED(ms, status_expire)) {
138-
setStatusMessage(FPSTR(NUL_STR), 0);
145+
setStatusMessage(standing_status, 0); // Back to Marlin's own status
139146
return;
140147
}
141148

@@ -191,6 +198,7 @@ void DGUSScreenHandler::storeSettings(char *buff) {
191198
data.volume = dgus.getVolume();
192199
data.brightness = dgus.getBrightness();
193200
data.abl_okay = (ExtUI::getLevelingActive() && ExtUI::getLevelingIsValid());
201+
data.language = language;
194202

195203
memcpy(buff, &data, sizeof(data));
196204
}
@@ -204,6 +212,7 @@ void DGUSScreenHandler::loadSettings(const char *buff) {
204212

205213
dgus.setVolume(data.initialized ? data.volume : DGUS_DEFAULT_VOLUME);
206214
dgus.setBrightness(data.initialized ? data.brightness : DGUS_DEFAULT_BRIGHTNESS);
215+
language = data.initialized ? data.language : 0;
207216

208217
if (data.initialized) {
209218
leveling_active = (data.abl_okay && ExtUI::getLevelingIsValid());
@@ -372,15 +381,28 @@ void DGUSScreenHandler::setMessageLine_P(PGM_P const msg, const uint8_t line) {
372381
}
373382

374383
void DGUSScreenHandler::setStatusMessage(const char* msg, const millis_t duration) {
375-
dgus.writeString((uint16_t)DGUS_Addr::MESSAGE_Status, msg, DGUS_STATUS_LEN, false, true);
384+
dgus.writeString((uint16_t)DGUS_Addr::MESSAGE_Status, msg, DGUS_STATUS_LEN, true, false, false);
376385
status_expire = (duration > 0 ? ExtUI::safe_millis() + duration : 0);
377386
}
378387

379388
void DGUSScreenHandler::setStatusMessage(FSTR_P const fmsg, const millis_t duration) {
380-
dgus.writeString((uint16_t)DGUS_Addr::MESSAGE_Status, fmsg, DGUS_STATUS_LEN, false, true);
389+
dgus.writeString((uint16_t)DGUS_Addr::MESSAGE_Status, fmsg, DGUS_STATUS_LEN, true, false, false);
381390
status_expire = (duration > 0 ? ExtUI::safe_millis() + duration : 0);
382391
}
383392

393+
static PGMSTR(k_machine_name, MACHINE_NAME);
394+
395+
// Marlin's own status ("<machine name> Ready.", "Printing...") stays on screen until the next one, and comes
396+
// back when a screen message expires. The machine name has its own field, so drop it from the message.
397+
void DGUSScreenHandler::setStandingStatus(const char * const msg) {
398+
const char *m = msg;
399+
const size_t n = strlen_P(k_machine_name);
400+
if (n && strncmp_P(m, k_machine_name, n) == 0 && m[n] == ' ') m += n + 1;
401+
strncpy(standing_status, m, DGUS_STATUS_LEN);
402+
standing_status[DGUS_STATUS_LEN] = '\0';
403+
setStatusMessage(standing_status, 0);
404+
}
405+
384406
void DGUSScreenHandler::showWaitScreen(const DGUS_ScreenID return_screenID, const bool has_continue/*=false*/) {
385407
if (return_screenID != DGUS_ScreenID::WAIT)
386408
wait_return_screenID = return_screenID;

‎Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class DGUSScreenHandler {
7575

7676
static void setStatusMessage(const char* msg, const millis_t duration=DGUS_STATUS_EXPIRATION_MS);
7777
static void setStatusMessage(FSTR_P const msg, const millis_t duration=DGUS_STATUS_EXPIRATION_MS);
78+
static void setStandingStatus(const char * const msg);
7879

7980
static void showWaitScreen(const DGUS_ScreenID return_screenID, const bool has_continue=false);
8081
static void showWaitScreen(FSTR_P const msg, const DGUS_ScreenID return_screenID, const bool has_continue=false);
@@ -113,6 +114,12 @@ class DGUSScreenHandler {
113114

114115
static bool leveling_active;
115116

117+
static uint8_t language;
118+
119+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
120+
static uint16_t jam_length;
121+
#endif
122+
116123
private:
117124
static const DGUS_Addr* findScreenAddrList(const DGUS_ScreenID screenID);
118125
static bool callScreenSetup(const DGUS_ScreenID screenID);
@@ -130,13 +137,15 @@ class DGUSScreenHandler {
130137
static DGUS_ScreenID wait_return_screenID;
131138

132139
static millis_t status_expire;
140+
static char standing_status[DGUS_STATUS_LEN + 1];
133141
static millis_t eeprom_save;
134142

135143
typedef struct {
136144
bool initialized;
137145
uint8_t volume;
138146
uint8_t brightness;
139147
bool abl_okay;
148+
uint8_t language;
140149
} eeprom_data_t;
141150
};
142151

‎Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.cpp‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include "config/DGUS_Data.h"
3131

3232
#include "../ui_api.h"
33+
34+
#if HAS_FILAMENT_SENSOR
35+
#include "../../../feature/runout.h"
36+
#endif
3337
#include "../../../module/stepper.h"
3438
#include "../../../module/temperature.h"
3539
#include "../../../module/printcounter.h"
@@ -509,6 +513,38 @@ void DGUSTxHandler::waitIcons(DGUS_VP &vp) {
509513
dgus.write((uint16_t)vp.addr, Swap16(icons));
510514
}
511515

516+
#if HAS_FILAMENT_SENSOR
517+
518+
void DGUSTxHandler::filamentSensorIcons(DGUS_VP &vp) {
519+
uint16_t icons = 0;
520+
521+
if (ExtUI::getFilamentRunoutEnabled())
522+
icons |= (uint16_t)DGUS_Data::FilamentSensorIcon::RUNOUT;
523+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
524+
if (runout.motion_distance() > 0)
525+
icons |= (uint16_t)DGUS_Data::FilamentSensorIcon::JAM;
526+
#endif
527+
if (!FILAMENT_IS_OUT())
528+
icons |= (uint16_t)DGUS_Data::FilamentSensorIcon::PRESENT;
529+
530+
dgus.write((uint16_t)vp.addr, Swap16(icons));
531+
}
532+
533+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
534+
void DGUSTxHandler::filamentSensorJam(DGUS_VP &vp) {
535+
if (runout.motion_distance() > 0)
536+
screen.jam_length = runout.motion_distance();
537+
538+
dgus.write((uint16_t)vp.addr, Swap16(screen.jam_length));
539+
}
540+
#endif
541+
542+
#endif // HAS_FILAMENT_SENSOR
543+
544+
void DGUSTxHandler::language(DGUS_VP &vp) {
545+
dgus.write((uint16_t)vp.addr, Swap16((uint16_t)screen.language));
546+
}
547+
512548
void DGUSTxHandler::fanSpeed(DGUS_VP &vp) {
513549
uint16_t fan_speed;
514550

‎Marlin/src/lcd/extui/dgus_reloaded/DGUSTxHandler.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ namespace DGUSTxHandler {
7070

7171
void waitIcons(DGUS_VP &);
7272

73+
#if HAS_FILAMENT_SENSOR
74+
void filamentSensorIcons(DGUS_VP &);
75+
#if ENABLED(FILAMENT_SWITCH_AND_MOTION)
76+
void filamentSensorJam(DGUS_VP &);
77+
#endif
78+
#endif
79+
80+
void language(DGUS_VP &);
81+
7382
void fanSpeed(DGUS_VP &);
7483

7584
void volume(DGUS_VP &);

‎Marlin/src/lcd/extui/dgus_reloaded/config/DGUS_Addr.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ enum class DGUS_Addr : uint16_t {
9696
POWERLOSS_Resume = 0x202D, // Popup / Data: DGUS_Data::Popup
9797
WAIT_Abort = 0x202E, // Popup / Data: DGUS_Data::Popup
9898
WAIT_Continue = 0x202F,
99+
FILAMENT_SENSOR_Toggle = 0x2030, // Data: DGUS_Data::FilamentSensor
100+
FILAMENT_SENSOR_Save = 0x2032,
99101

100102
// WRITE-ONLY VARIABLES
101103

@@ -157,6 +159,7 @@ enum class DGUS_Addr : uint16_t {
157159
INFOS_FilamentUsed = 0x31A5, // 0x31A5 - 0x31BC
158160
WAIT_Icons = 0x31BD, // Bits: DGUS_Data::WaitIcon
159161
STATUS_Icons = 0x31BE, // Bits: DGUS_Data::StatusIcon
162+
FILAMENT_SENSOR_Icons = 0x31BF, // Bits: DGUS_Data::FilamentSensorIcon
160163

161164
// READ-WRITE VARIABLES
162165

@@ -165,6 +168,8 @@ enum class DGUS_Addr : uint16_t {
165168
PID_Cycles = 0x4021, // Type: Integer (16 bits unsigned)
166169
VOLUME_Level = 0x4022, // Type: Integer (16 bits unsigned) / Data: volume as percent (0-100)
167170
BRIGHTNESS_Level = 0x4023, // Type: Integer (16 bits unsigned) / Data: brightness as percent (0-100)
171+
LANGUAGE = 0x4024, // Type: Integer (16 bits unsigned) / Data: index of the screen files' language
172+
FILAMENT_SENSOR_Jam = 0x4025, // Type: Integer (16 bits unsigned) / Data: jam length in mm, 0 turns jam detection off
168173

169174
// SPECIAL CASES
170175

‎Marlin/src/lcd/extui/dgus_reloaded/config/DGUS_Constants.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
#define DGUS_DEFAULT_FILAMENT_LEN 10
7474
#endif
7575

76+
#ifndef DGUS_DEFAULT_JAM_LEN
77+
#define DGUS_DEFAULT_JAM_LEN 10 // (mm) Jam length restored when jam detection is turned back on
78+
#endif
79+
7680
#ifndef DGUS_LEVEL_CENTER_X
7781
#define DGUS_LEVEL_CENTER_X ((X_BED_SIZE) / 2)
7882
#endif

‎Marlin/src/lcd/extui/dgus_reloaded/config/DGUS_Data.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ namespace DGUS_Data {
9898
BUTTON2 = 1
9999
};
100100

101+
enum class FilamentSensor : uint8_t {
102+
RUNOUT = 0,
103+
JAM = 1
104+
};
105+
101106
// TX constants
102107

103108
enum class SDType : uint16_t {
@@ -117,6 +122,12 @@ namespace DGUS_Data {
117122
RESUME = 1U << 1
118123
};
119124

125+
enum class FilamentSensorIcon : uint16_t {
126+
RUNOUT = 1U << 0,
127+
JAM = 1U << 1,
128+
PRESENT = 1U << 2
129+
};
130+
120131
enum class Status : uint16_t {
121132
DISABLED = 0,
122133
ENABLED = 1

‎Marlin/src/lcd/extui/dgus_reloaded/config/DGUS_ScreenID.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum class DGUS_ScreenID : uint8_t {
4545
VOLUME = 20,
4646
BRIGHTNESS = 21,
4747
INFOS = 22,
48+
FILAMENT_SENSOR = 23,
4849
DEBUG = 240,
4950
POWERLOSS = 248,
5051
WAIT = 249,

0 commit comments

Comments
 (0)