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.

DGUSScreenHandler.h 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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(const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
  35. 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);
  36. #if 0
  37. static void sendinfoscreen_ch_mks(const uint16_t *line1, const uint16_t *line2, const uint16_t *line3, const uint16_t *line4);
  38. static void sendinfoscreen_en_mks(const char *line1, const char *line2, const char *line3, const char *line4) ;
  39. static void sendinfoscreen_mks(const void *line1, const void *line2, const void *line3, const void *line4, uint16_t language);
  40. #endif
  41. // "M117" Message -- msg is a RAM ptr.
  42. static void setstatusmessage(const char *msg);
  43. // The same for messages from Flash
  44. static void setstatusmessagePGM(PGM_P const msg);
  45. // Callback for VP "Display wants to change screen on idle printer"
  46. static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr);
  47. // Callback for VP "Screen has been changed"
  48. static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr);
  49. static void ScreenBackChange(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. static void EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr);
  61. static void LanguageChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  62. static void GetOffsetValue(DGUS_VP_Variable &var, void *val_ptr);
  63. static void Level_Ctrl_MKS(DGUS_VP_Variable &var, void *val_ptr);
  64. static void MeshLevel(DGUS_VP_Variable &var, void *val_ptr);
  65. static void MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *val_ptr);
  66. static void ManualAssistLeveling(DGUS_VP_Variable &var, void *val_ptr);
  67. static void ZoffsetConfirm(DGUS_VP_Variable &var, void *val_ptr);
  68. static void Z_offset_select(DGUS_VP_Variable &var, void *val_ptr);
  69. static void GetManualMovestep(DGUS_VP_Variable &var, void *val_ptr);
  70. static void GetZoffsetDistance(DGUS_VP_Variable &var, void *val_ptr);
  71. static void GetMinExtrudeTemp(DGUS_VP_Variable &var, void *val_ptr);
  72. static void GetParkPos_MKS(DGUS_VP_Variable &var, void *val_ptr);
  73. #if ENABLED(PREVENT_COLD_EXTRUSION)
  74. static void HandleGetExMinTemp_MKS(DGUS_VP_Variable &var, void *val_ptr);
  75. #endif
  76. static void DGUS_LanguageDisplay(uint8_t var);
  77. static void TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr);
  78. static void GetTurnOffCtrl(DGUS_VP_Variable &var, void *val_ptr);
  79. static void LanguagePInit(void);
  80. static void DGUS_Runout_Idle(void);
  81. static void DGUS_RunoutInit(void);
  82. static void DGUS_ExtrudeLoadInit(void);
  83. static void LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr);
  84. static void SD_FileBack(DGUS_VP_Variable &var, void *val_ptr);
  85. // Hook for manual move.
  86. static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr);
  87. // Hook for manual extrude.
  88. static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr);
  89. // Hook for motor lock and unlook
  90. static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr);
  91. #if ENABLED(POWER_LOSS_RECOVERY)
  92. // Hook for power loss recovery.
  93. static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr);
  94. #endif
  95. // Hook for settings
  96. static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr);
  97. static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr);
  98. static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr);
  99. static void HandleStepPerMMChanged_MKS(DGUS_VP_Variable &var, void *val_ptr);
  100. static void HandleStepPerMMExtruderChanged_MKS(DGUS_VP_Variable &var, void *val_ptr);
  101. static void HandleMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  102. static void HandleExtruderMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  103. static void HandleAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  104. static void HandleMaxAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  105. static void HandleExtruderAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  106. static void HandleChangeLevelPoint_MKS(DGUS_VP_Variable &var, void *val_ptr);
  107. static void HandleTravelAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  108. static void HandleFeedRateMinChange_MKS(DGUS_VP_Variable &var, void *val_ptr);
  109. static void HandleMin_T_F_MKS(DGUS_VP_Variable &var, void *val_ptr);
  110. #if HAS_PID_HEATING
  111. // Hook for "Change this temperature PID para"
  112. static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr);
  113. // Hook for PID autotune
  114. static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr);
  115. #endif
  116. #if HAS_BED_PROBE
  117. // Hook for "Change probe offset z"
  118. static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr);
  119. #endif
  120. #if ENABLED(BABYSTEPPING)
  121. // Hook for live z adjust action
  122. static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr);
  123. #endif
  124. #if HAS_FAN
  125. // Hook for fan control
  126. static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr);
  127. #endif
  128. // Hook for heater control
  129. static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr);
  130. #if ENABLED(DGUS_PREHEAT_UI)
  131. // Hook for preheat
  132. static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr);
  133. #endif
  134. #if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
  135. // Hook for filament load and unload filament option
  136. static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr);
  137. // Hook for filament load and unload
  138. static void HandleFilamentLoadUnload(DGUS_VP_Variable &var);
  139. static void MKS_FilamentLoadUnload(DGUS_VP_Variable &var, void *val_ptr, const int filamentDir);
  140. static void MKS_FilamentLoad(DGUS_VP_Variable &var, void *val_ptr);
  141. static void MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr);
  142. static void MKS_LOAD_UNLOAD_IDLE();
  143. static void MKS_LOAD_Cancle(DGUS_VP_Variable &var, void *val_ptr);
  144. static void GetManualFilament(DGUS_VP_Variable &var, void *val_ptr);
  145. static void GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ptr);
  146. #endif
  147. #if ENABLED(SDSUPPORT)
  148. // Callback for VP "Display wants to change screen when there is a SD card"
  149. static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr);
  150. // Scroll buttons on the file listing screen.
  151. static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr);
  152. // File touched.
  153. static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr);
  154. // start print after confirmation received.
  155. static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr);
  156. // User hit the pause, resume or abort button.
  157. static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr);
  158. // User confirmed the abort action
  159. static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr);
  160. // User hit the tune button
  161. static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr);
  162. // Send a single filename to the display.
  163. static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var);
  164. // Marlin informed us that a new SD has been inserted.
  165. static void SDCardInserted();
  166. // Marlin informed us that the SD Card has been removed().
  167. static void SDCardRemoved();
  168. // Marlin informed us about a bad SD Card.
  169. static void SDCardError();
  170. // Marlin informed us about SD print completion.
  171. static void SDPrintingFinished();
  172. #else
  173. static void PrintReturn(DGUS_VP_Variable &var, void *val_ptr);
  174. #endif
  175. // OK Button on the Confirm screen.
  176. static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr);
  177. // Update data after going to a new screen (by display or by GotoScreen)
  178. // remember: store the last-displayed screen, so it can be returned to.
  179. // (e.g for popup messages)
  180. static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false);
  181. // Recall the remembered screen.
  182. static void PopToOldScreen();
  183. // Make the display show the screen and update all VPs in it.
  184. static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false);
  185. static void UpdateScreenVPData();
  186. // Helpers to convert and transfer data to the display.
  187. static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var);
  188. static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var);
  189. static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var);
  190. static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var);
  191. static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var);
  192. static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var);
  193. static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var);
  194. static void DGUSLCD_SendPrintTimeToDisplay_MKS(DGUS_VP_Variable &var);
  195. static void DGUSLCD_SendBabyStepToDisplay_MKS(DGUS_VP_Variable &var);
  196. static void DGUSLCD_SendFanToDisplay(DGUS_VP_Variable &var);
  197. static void DGUSLCD_SendGbkToDisplay(DGUS_VP_Variable &var);
  198. static void DGUSLCD_SendStringToDisplay_Language_MKS(DGUS_VP_Variable &var);
  199. static void DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var);
  200. #if ENABLED(PRINTCOUNTER)
  201. static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var);
  202. static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var);
  203. #endif
  204. #if HAS_FAN
  205. static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var);
  206. #endif
  207. static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var);
  208. #if ENABLED(DGUS_UI_WAITING)
  209. static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var);
  210. #endif
  211. // Send a value from 0..100 to a variable with a range from 0..255
  212. static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr);
  213. static void DGUSLCD_SetUint8(DGUS_VP_Variable &var, void *val_ptr);
  214. template<typename T>
  215. static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) {
  216. if (!var.memadr) return;
  217. union { unsigned char tmp[sizeof(T)]; T t; } x;
  218. unsigned char *ptr = (unsigned char*)val_ptr;
  219. LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1];
  220. *(T*)var.memadr = x.t;
  221. }
  222. // Send a float value to the display.
  223. // Display will get a 4-byte integer scaled to the number of digits:
  224. // Tell the display the number of digits and it cheats by displaying a dot between...
  225. template<unsigned int decimals>
  226. static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) {
  227. if (var.memadr) {
  228. float f = *(float *)var.memadr;
  229. f *= cpow(10, decimals);
  230. dgusdisplay.WriteVariable(var.VP, (long)f);
  231. }
  232. }
  233. // Send a float value to the display.
  234. // Display will get a 2-byte integer scaled to the number of digits:
  235. // Tell the display the number of digits and it cheats by displaying a dot between...
  236. template<unsigned int decimals>
  237. static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) {
  238. if (var.memadr) {
  239. float f = *(float *)var.memadr;
  240. DEBUG_ECHOLNPAIR_F(" >> ", f, 6);
  241. f *= cpow(10, decimals);
  242. dgusdisplay.WriteVariable(var.VP, (int16_t)f);
  243. }
  244. }
  245. // Force an update of all VP on the current screen.
  246. static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; }
  247. // Has all VPs sent to the screen
  248. static inline bool IsScreenComplete() { return ScreenComplete; }
  249. static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; }
  250. static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; }
  251. private:
  252. static DGUSLCD_Screens current_screen; //< currently on screen
  253. static constexpr uint8_t NUM_PAST_SCREENS = 4;
  254. static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; //< LIFO with past screens for the "back" button.
  255. static uint8_t update_ptr; //< Last sent entry in the VPList for the actual screen.
  256. static uint16_t skipVP; //< When updating the screen data, skip this one, because the user is interacting with it.
  257. static bool ScreenComplete; //< All VPs sent to screen?
  258. static uint16_t ConfirmVP; //< context for confirm screen (VP that will be emulated-sent on "OK").
  259. #if ENABLED(SDSUPPORT)
  260. static int16_t top_file; //< file on top of file chooser
  261. static int16_t file_to_print; //< touched file to be confirmed
  262. #endif
  263. static void (*confirm_action_cb)();
  264. };
  265. #define MKS_Language_Choose 0x00
  266. #define MKS_Language_NoChoose 0x01
  267. #define MKS_SimpleChinese 0
  268. #define MKS_English 1
  269. extern uint8_t mks_language_index;
  270. extern bool DGUSAutoTurnOff;
  271. #if ENABLED(POWER_LOSS_RECOVERY)
  272. #define PLR_SCREEN_RECOVER MKSLCD_SCREEN_PRINT
  273. #define PLR_SCREEN_CANCEL MKSLCD_SCREEN_HOME
  274. #endif