My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DGUSScreenHandlerBase.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "DGUSDisplay.h"
  24. #include "DGUSVPVariable.h"
  25. #include "DGUSDisplayDef.h"
  26. #include "../../../inc/MarlinConfig.h"
  27. enum DGUSLCD_Screens : uint8_t;
  28. class DGUSScreenHandler {
  29. public:
  30. DGUSScreenHandler() = default;
  31. static bool loop();
  32. // Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen
  33. // The bools specifying whether the strings are in RAM or FLASH.
  34. static void sendinfoscreen(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
  35. static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
  36. sendinfoscreen(FTOP(line1), FTOP(line2), line3, line4, l1inflash, l2inflash, l3inflash, liinflash);
  37. }
  38. static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, FSTR_P const line3, FSTR_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
  39. sendinfoscreen(FTOP(line1), FTOP(line2), FTOP(line3), FTOP(line4), l1inflash, l2inflash, l3inflash, liinflash);
  40. }
  41. static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
  42. // "M117" Message -- msg is a RAM ptr.
  43. static void setstatusmessage(const char *msg);
  44. // The same for messages from Flash
  45. static void setstatusmessagePGM(PGM_P const msg);
  46. // Callback for VP "Display wants to change screen on idle printer"
  47. static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr);
  48. // Callback for VP "Screen has been changed"
  49. static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr);
  50. // Callback for VP "All Heaters Off"
  51. static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr);
  52. // Hook for "Change this temperature"
  53. static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr);
  54. // Hook for "Change Flowrate"
  55. static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr);
  56. #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
  57. // Hook for manual move option
  58. static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr);
  59. #endif
  60. // Hook for manual move.
  61. static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr);
  62. // Hook for manual extrude.
  63. static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr);
  64. // Hook for motor lock and unlook
  65. static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr);
  66. #if ENABLED(POWER_LOSS_RECOVERY)
  67. // Hook for power loss recovery.
  68. static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr);
  69. #endif
  70. // Hook for settings
  71. static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr);
  72. static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr);
  73. static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr);
  74. #if HAS_PID_HEATING
  75. // Hook for "Change this temperature PID para"
  76. static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr);
  77. // Hook for PID autotune
  78. static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr);
  79. #endif
  80. #if HAS_BED_PROBE
  81. // Hook for "Change probe offset z"
  82. static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr);
  83. #endif
  84. #if ENABLED(BABYSTEPPING)
  85. // Hook for live z adjust action
  86. static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr);
  87. #endif
  88. #if HAS_FAN
  89. // Hook for fan control
  90. static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr);
  91. #endif
  92. // Hook for heater control
  93. static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr);
  94. #if ENABLED(DGUS_PREHEAT_UI)
  95. // Hook for preheat
  96. static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr);
  97. #endif
  98. #if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
  99. // Hook for filament load and unload filament option
  100. static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr);
  101. // Hook for filament load and unload
  102. static void HandleFilamentLoadUnload(DGUS_VP_Variable &var);
  103. #endif
  104. #if ENABLED(SDSUPPORT)
  105. // Callback for VP "Display wants to change screen when there is a SD card"
  106. static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr);
  107. // Scroll buttons on the file listing screen.
  108. static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr);
  109. // File touched.
  110. static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr);
  111. // start print after confirmation received.
  112. static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr);
  113. // User hit the pause, resume or abort button.
  114. static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr);
  115. // User confirmed the abort action
  116. static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr);
  117. // User hit the tune button
  118. static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr);
  119. // Send a single filename to the display.
  120. static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var);
  121. // Marlin informed us that a new SD has been inserted.
  122. static void SDCardInserted();
  123. // Marlin informed us that the SD Card has been removed().
  124. static void SDCardRemoved();
  125. // Marlin informed us about a bad SD Card.
  126. static void SDCardError();
  127. #endif
  128. // OK Button on the Confirm screen.
  129. static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr);
  130. // Update data after going to a new screen (by display or by GotoScreen)
  131. // remember to store the last-displayed screen so it can be restored.
  132. // (e.g., for popup messages)
  133. static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false);
  134. // Recall the remembered screen.
  135. static void PopToOldScreen();
  136. // Make the display show the screen and update all VPs in it.
  137. static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false);
  138. static void UpdateScreenVPData();
  139. // Helpers to convert and transfer data to the display.
  140. static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var);
  141. static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var);
  142. static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var);
  143. static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var);
  144. static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var);
  145. static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var);
  146. static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var);
  147. #if ENABLED(PRINTCOUNTER)
  148. static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var);
  149. static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var);
  150. #endif
  151. #if HAS_FAN
  152. static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var);
  153. #endif
  154. static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var);
  155. #if ENABLED(DGUS_UI_WAITING)
  156. static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var);
  157. #endif
  158. // Send a value from 0..100 to a variable with a range from 0..255
  159. static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr);
  160. template<typename T>
  161. static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) {
  162. if (!var.memadr) return;
  163. union { unsigned char tmp[sizeof(T)]; T t; } x;
  164. unsigned char *ptr = (unsigned char*)val_ptr;
  165. LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1];
  166. *(T*)var.memadr = x.t;
  167. }
  168. // Send a float value to the display.
  169. // Display will get a 4-byte integer scaled to the number of digits:
  170. // Tell the display the number of digits and it cheats by displaying a dot between...
  171. template<unsigned int decimals>
  172. static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) {
  173. if (var.memadr) {
  174. float f = *(float *)var.memadr;
  175. f *= cpow(10, decimals);
  176. dgusdisplay.WriteVariable(var.VP, (long)f);
  177. }
  178. }
  179. // Send a float value to the display.
  180. // Display will get a 2-byte integer scaled to the number of digits:
  181. // Tell the display the number of digits and it cheats by displaying a dot between...
  182. template<unsigned int decimals>
  183. static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) {
  184. if (var.memadr) {
  185. float f = *(float *)var.memadr;
  186. DEBUG_ECHOLNPAIR_F(" >> ", f, 6);
  187. f *= cpow(10, decimals);
  188. dgusdisplay.WriteVariable(var.VP, (int16_t)f);
  189. }
  190. }
  191. // Force an update of all VP on the current screen.
  192. static void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; }
  193. // Has all VPs sent to the screen
  194. static bool IsScreenComplete() { return ScreenComplete; }
  195. static DGUSLCD_Screens getCurrentScreen() { return current_screen; }
  196. static void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; }
  197. protected:
  198. static DGUSLCD_Screens current_screen; //< currently on screen
  199. static constexpr uint8_t NUM_PAST_SCREENS = 4;
  200. static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; //< LIFO with past screens for the "back" button.
  201. static uint8_t update_ptr; //< Last sent entry in the VPList for the actual screen.
  202. static uint16_t skipVP; //< When updating the screen data, skip this one, because the user is interacting with it.
  203. static bool ScreenComplete; //< All VPs sent to screen?
  204. static uint16_t ConfirmVP; //< context for confirm screen (VP that will be emulated-sent on "OK").
  205. #if ENABLED(SDSUPPORT)
  206. static int16_t top_file; //< file on top of file chooser
  207. static int16_t file_to_print; //< touched file to be confirmed
  208. #endif
  209. static void (*confirm_action_cb)();
  210. };