Skip to content

Commit a74ee52

Browse files
yufanyufanvgadreau
authored andcommitted
More customizable DGUSDisplay (MarlinFirmware#18700)
1 parent f2e2a6a commit a74ee52

11 files changed

+1669
-1583
lines changed

Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp

+23-1,121
Large diffs are not rendered by default.

Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h

-217
Original file line numberDiff line numberDiff line change
@@ -90,223 +90,6 @@ extern DGUSDisplay dgusdisplay;
9090
// compile-time x^y
9191
constexpr float cpow(const float x, const int y) { return y == 0 ? 1.0 : x * cpow(x, y - 1); }
9292

93-
class DGUSScreenVariableHandler {
94-
public:
95-
DGUSScreenVariableHandler() = default;
96-
97-
static bool loop();
98-
99-
/// Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen
100-
/// The bools specifing whether the strings are in RAM or FLASH.
101-
static void sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
102-
103-
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
104-
105-
/// "M117" Message -- msg is a RAM ptr.
106-
static void setstatusmessage(const char* msg);
107-
/// The same for messages from Flash
108-
static void setstatusmessagePGM(PGM_P const msg);
109-
// Callback for VP "Display wants to change screen on idle printer"
110-
static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr);
111-
// Callback for VP "Screen has been changed"
112-
static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr);
113-
// Callback for VP "All Heaters Off"
114-
static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr);
115-
// Hook for "Change this temperature"
116-
static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr);
117-
// Hook for "Change Flowrate"
118-
static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr);
119-
#if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
120-
// Hook for manual move option
121-
static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr);
122-
#endif
123-
// Hook for manual move.
124-
static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr);
125-
// Hook for manual extrude.
126-
static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr);
127-
// Hook for motor lock and unlook
128-
static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr);
129-
#if ENABLED(POWER_LOSS_RECOVERY)
130-
// Hook for power loss recovery.
131-
static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr);
132-
#endif
133-
// Hook for settings
134-
static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr);
135-
static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr);
136-
static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr);
137-
#if HAS_PID_HEATING
138-
// Hook for "Change this temperature PID para"
139-
static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr);
140-
// Hook for PID autotune
141-
static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr);
142-
#endif
143-
#if HAS_BED_PROBE
144-
// Hook for "Change probe offset z"
145-
static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr);
146-
#endif
147-
#if ENABLED(BABYSTEPPING)
148-
// Hook for live z adjust action
149-
static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr);
150-
#endif
151-
#if HAS_FAN
152-
// Hook for fan control
153-
static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr);
154-
#endif
155-
// Hook for heater control
156-
static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr);
157-
#if ENABLED(DGUS_PREHEAT_UI)
158-
// Hook for preheat
159-
static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr);
160-
#endif
161-
#if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
162-
// Hook for filament load and unload filament option
163-
static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr);
164-
// Hook for filament load and unload
165-
static void HandleFilamentLoadUnload(DGUS_VP_Variable &var);
166-
#endif
167-
168-
#if ENABLED(SDSUPPORT)
169-
// Callback for VP "Display wants to change screen when there is a SD card"
170-
static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr);
171-
/// Scroll buttons on the file listing screen.
172-
static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr);
173-
/// File touched.
174-
static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr);
175-
/// start print after confirmation received.
176-
static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr);
177-
/// User hit the pause, resume or abort button.
178-
static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr);
179-
/// User confirmed the abort action
180-
static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr);
181-
/// User hit the tune button
182-
static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr);
183-
/// Send a single filename to the display.
184-
static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var);
185-
/// Marlin informed us that a new SD has been inserted.
186-
static void SDCardInserted();
187-
/// Marlin informed us that the SD Card has been removed().
188-
static void SDCardRemoved();
189-
/// Marlin informed us about a bad SD Card.
190-
static void SDCardError();
191-
#endif
192-
193-
// OK Button the Confirm screen.
194-
static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr);
195-
196-
// Update data after went to new screen (by display or by GotoScreen)
197-
// remember: store the last-displayed screen, so it can get returned to.
198-
// (e.g for pop up messages)
199-
static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false);
200-
201-
// Recall the remembered screen.
202-
static void PopToOldScreen();
203-
204-
// Make the display show the screen and update all VPs in it.
205-
static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false);
206-
207-
static void UpdateScreenVPData();
208-
209-
// Helpers to convert and transfer data to the display.
210-
static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var);
211-
static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var);
212-
static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var);
213-
static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var);
214-
static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var);
215-
static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var);
216-
static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var);
217-
#if ENABLED(PRINTCOUNTER)
218-
static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var);
219-
static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var);
220-
#endif
221-
#if HAS_FAN
222-
static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var);
223-
#endif
224-
static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var);
225-
#if ENABLED(DGUS_UI_WAITING)
226-
static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var);
227-
#endif
228-
229-
/// Send a value from 0..100 to a variable with a range from 0..255
230-
static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr);
231-
232-
template<typename T>
233-
static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) {
234-
if (!var.memadr) return;
235-
union { unsigned char tmp[sizeof(T)]; T t; } x;
236-
unsigned char *ptr = (unsigned char*)val_ptr;
237-
LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1];
238-
*(T*)var.memadr = x.t;
239-
}
240-
241-
/// Send a float value to the display.
242-
/// Display will get a 4-byte integer scaled to the number of digits:
243-
/// Tell the display the number of digits and it cheats by displaying a dot between...
244-
template<unsigned int decimals>
245-
static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) {
246-
if (var.memadr) {
247-
float f = *(float *)var.memadr;
248-
f *= cpow(10, decimals);
249-
union { long l; char lb[4]; } endian;
250-
251-
char tmp[4];
252-
endian.l = f;
253-
tmp[0] = endian.lb[3];
254-
tmp[1] = endian.lb[2];
255-
tmp[2] = endian.lb[1];
256-
tmp[3] = endian.lb[0];
257-
dgusdisplay.WriteVariable(var.VP, tmp, 4);
258-
}
259-
}
260-
261-
/// Send a float value to the display.
262-
/// Display will get a 2-byte integer scaled to the number of digits:
263-
/// Tell the display the number of digits and it cheats by displaying a dot between...
264-
template<unsigned int decimals>
265-
static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) {
266-
if (var.memadr) {
267-
float f = *(float *)var.memadr;
268-
DEBUG_ECHOLNPAIR_F(" >> ", f, 6);
269-
f *= cpow(10, decimals);
270-
union { int16_t i; char lb[2]; } endian;
271-
272-
char tmp[2];
273-
endian.i = f;
274-
tmp[0] = endian.lb[1];
275-
tmp[1] = endian.lb[0];
276-
dgusdisplay.WriteVariable(var.VP, tmp, 2);
277-
}
278-
}
279-
280-
/// Force an update of all VP on the current screen.
281-
static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; }
282-
/// Has all VPs sent to the screen
283-
static inline bool IsScreenComplete() { return ScreenComplete; }
284-
285-
static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; }
286-
287-
static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; }
288-
289-
private:
290-
static DGUSLCD_Screens current_screen; ///< currently on screen
291-
static constexpr uint8_t NUM_PAST_SCREENS = 4;
292-
static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; ///< LIFO with past screens for the "back" button.
293-
294-
static uint8_t update_ptr; ///< Last sent entry in the VPList for the actual screen.
295-
static uint16_t skipVP; ///< When updating the screen data, skip this one, because the user is interacting with it.
296-
static bool ScreenComplete; ///< All VPs sent to screen?
297-
298-
static uint16_t ConfirmVP; ///< context for confirm screen (VP that will be emulated-sent on "OK").
299-
300-
#if ENABLED(SDSUPPORT)
301-
static int16_t top_file; ///< file on top of file chooser
302-
static int16_t file_to_print; ///< touched file to be confirmed
303-
#endif
304-
305-
static void (*confirm_action_cb)();
306-
};
307-
308-
extern DGUSScreenVariableHandler ScreenHandler;
309-
31093
/// Find the flash address of a DGUS_VP_Variable for the VP.
31194
extern const DGUS_VP_Variable* DGUSLCD_FindVPVar(const uint16_t vp);
31295

Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "DGUSVPVariable.h"
2727

28+
#include <stdint.h>
29+
2830
// This file defines the interaction between Marlin and the display firmware.
2931

3032
// information on which screen which VP is displayed
@@ -41,6 +43,8 @@ extern const struct VPMapping VPMap[];
4143
// List of VPs handled by Marlin / The Display.
4244
extern const struct DGUS_VP_Variable ListOfVP[];
4345

46+
#include "../../../../inc/MarlinConfig.h"
47+
4448
#if ENABLED(DGUS_LCD_UI_ORIGIN)
4549
#include "origin/DGUSDisplayDef.h"
4650
#elif ENABLED(DGUS_LCD_UI_FYSETC)

0 commit comments

Comments
 (0)