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.

DGUSDisplayDef.cpp 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. /* DGUS implementation written by coldtobi in 2019 for Marlin */
  23. #include "../../../../../inc/MarlinConfigPre.h"
  24. #if ENABLED(DGUS_LCD_UI_ORIGIN)
  25. #include "../DGUSDisplayDef.h"
  26. #include "../DGUSDisplay.h"
  27. #include "../DGUSScreenHandler.h"
  28. #include "../../../../../module/temperature.h"
  29. #include "../../../../../module/motion.h"
  30. #include "../../../../../module/planner.h"
  31. #include "../../../../marlinui.h"
  32. #include "../../../ui_api.h"
  33. #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
  34. uint16_t distanceToMove = 10;
  35. #endif
  36. using namespace ExtUI;
  37. const uint16_t VPList_Boot[] PROGMEM = {
  38. VP_MARLIN_VERSION,
  39. 0x0000
  40. };
  41. const uint16_t VPList_Main[] PROGMEM = {
  42. /* VP_M117, for completeness, but it cannot be auto-uploaded. */
  43. 0x0000
  44. };
  45. const uint16_t VPList_Temp[] PROGMEM = {
  46. #if HOTENDS >= 1
  47. VP_T_E0_Is, VP_T_E0_Set,
  48. #endif
  49. #if HOTENDS >= 2
  50. VP_T_E1_Is, VP_T_E1_Set,
  51. #endif
  52. #if HAS_HEATED_BED
  53. VP_T_Bed_Is, VP_T_Bed_Set,
  54. #endif
  55. 0x0000
  56. };
  57. const uint16_t VPList_Status[] PROGMEM = {
  58. /* VP_M117, for completeness, but it cannot be auto-uploaded */
  59. #if HOTENDS >= 1
  60. VP_T_E0_Is, VP_T_E0_Set,
  61. #endif
  62. #if HOTENDS >= 2
  63. VP_T_E1_Is, VP_T_E1_Set,
  64. #endif
  65. #if HAS_HEATED_BED
  66. VP_T_Bed_Is, VP_T_Bed_Set,
  67. #endif
  68. #if HAS_FAN
  69. VP_Fan0_Percentage,
  70. #endif
  71. VP_XPos, VP_YPos, VP_ZPos,
  72. VP_Fan0_Percentage,
  73. VP_Feedrate_Percentage,
  74. VP_PrintProgress_Percentage,
  75. 0x0000
  76. };
  77. const uint16_t VPList_Status2[] PROGMEM = {
  78. /* VP_M117, for completeness, but it cannot be auto-uploaded */
  79. #if HOTENDS >= 1
  80. VP_Flowrate_E0,
  81. #endif
  82. #if HOTENDS >= 2
  83. VP_Flowrate_E1,
  84. #endif
  85. VP_PrintProgress_Percentage,
  86. VP_PrintTime,
  87. 0x0000
  88. };
  89. const uint16_t VPList_ManualMove[] PROGMEM = {
  90. VP_XPos, VP_YPos, VP_ZPos,
  91. 0x0000
  92. };
  93. const uint16_t VPList_ManualExtrude[] PROGMEM = {
  94. VP_EPos,
  95. 0x0000
  96. };
  97. const uint16_t VPList_FanAndFeedrate[] PROGMEM = {
  98. VP_Feedrate_Percentage, VP_Fan0_Percentage,
  99. 0x0000
  100. };
  101. const uint16_t VPList_SD_FlowRates[] PROGMEM = {
  102. VP_Flowrate_E0, VP_Flowrate_E1,
  103. 0x0000
  104. };
  105. const uint16_t VPList_SDFileList[] PROGMEM = {
  106. VP_SD_FileName0, VP_SD_FileName1, VP_SD_FileName2, VP_SD_FileName3, VP_SD_FileName4,
  107. 0x0000
  108. };
  109. const uint16_t VPList_SD_PrintManipulation[] PROGMEM = {
  110. VP_PrintProgress_Percentage, VP_PrintTime,
  111. 0x0000
  112. };
  113. const struct VPMapping VPMap[] PROGMEM = {
  114. { DGUSLCD_SCREEN_BOOT, VPList_Boot },
  115. { DGUSLCD_SCREEN_MAIN, VPList_Main },
  116. { DGUSLCD_SCREEN_TEMPERATURE, VPList_Temp },
  117. { DGUSLCD_SCREEN_STATUS, VPList_Status },
  118. { DGUSLCD_SCREEN_STATUS2, VPList_Status2 },
  119. { DGUSLCD_SCREEN_MANUALMOVE, VPList_ManualMove },
  120. { DGUSLCD_SCREEN_MANUALEXTRUDE, VPList_ManualExtrude },
  121. { DGUSLCD_SCREEN_FANANDFEEDRATE, VPList_FanAndFeedrate },
  122. { DGUSLCD_SCREEN_FLOWRATES, VPList_SD_FlowRates },
  123. { DGUSLCD_SCREEN_SDPRINTMANIPULATION, VPList_SD_PrintManipulation },
  124. { DGUSLCD_SCREEN_SDFILELIST, VPList_SDFileList },
  125. { 0 , nullptr } // List is terminated with an nullptr as table entry.
  126. };
  127. const char MarlinVersion[] PROGMEM = SHORT_BUILD_VERSION;
  128. // Helper to define a DGUS_VP_Variable for common use cases.
  129. #define VPHELPER(VPADR, VPADRVAR, RXFPTR, TXFPTR ) { .VP=VPADR, .memadr=VPADRVAR, .size=sizeof(VPADRVAR), \
  130. .set_by_display_handler = RXFPTR, .send_to_display_handler = TXFPTR }
  131. // Helper to define a DGUS_VP_Variable when the sizeo of the var cannot be determined automaticalyl (eg. a string)
  132. #define VPHELPER_STR(VPADR, VPADRVAR, STRLEN, RXFPTR, TXFPTR ) { .VP=VPADR, .memadr=VPADRVAR, .size=STRLEN, \
  133. .set_by_display_handler = RXFPTR, .send_to_display_handler = TXFPTR }
  134. const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {
  135. // Helper to detect touch events
  136. VPHELPER(VP_SCREENCHANGE, nullptr, ScreenHandler.ScreenChangeHook, nullptr),
  137. VPHELPER(VP_SCREENCHANGE_ASK, nullptr, ScreenHandler.ScreenChangeHookIfIdle, nullptr),
  138. #if ENABLED(SDSUPPORT)
  139. VPHELPER(VP_SCREENCHANGE_WHENSD, nullptr, ScreenHandler.ScreenChangeHookIfSD, nullptr),
  140. #endif
  141. VPHELPER(VP_CONFIRMED, nullptr, ScreenHandler.ScreenConfirmedOK, nullptr),
  142. VPHELPER(VP_TEMP_ALL_OFF, nullptr, &ScreenHandler.HandleAllHeatersOff, nullptr),
  143. #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
  144. VPHELPER(VP_MOVE_OPTION, &distanceToMove, &ScreenHandler.HandleManualMoveOption, nullptr),
  145. #endif
  146. #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
  147. VPHELPER(VP_MOVE_X, &distanceToMove, &ScreenHandler.HandleManualMove, nullptr),
  148. VPHELPER(VP_MOVE_Y, &distanceToMove, &ScreenHandler.HandleManualMove, nullptr),
  149. VPHELPER(VP_MOVE_Z, &distanceToMove, &ScreenHandler.HandleManualMove, nullptr),
  150. VPHELPER(VP_HOME_ALL, &distanceToMove, &ScreenHandler.HandleManualMove, nullptr),
  151. #else
  152. VPHELPER(VP_MOVE_X, nullptr, &ScreenHandler.HandleManualMove, nullptr),
  153. VPHELPER(VP_MOVE_Y, nullptr, &ScreenHandler.HandleManualMove, nullptr),
  154. VPHELPER(VP_MOVE_Z, nullptr, &ScreenHandler.HandleManualMove, nullptr),
  155. VPHELPER(VP_HOME_ALL, nullptr, &ScreenHandler.HandleManualMove, nullptr),
  156. #endif
  157. VPHELPER(VP_MOTOR_LOCK_UNLOK, nullptr, &ScreenHandler.HandleMotorLockUnlock, nullptr),
  158. #if ENABLED(POWER_LOSS_RECOVERY)
  159. VPHELPER(VP_POWER_LOSS_RECOVERY, nullptr, &ScreenHandler.HandlePowerLossRecovery, nullptr),
  160. #endif
  161. VPHELPER(VP_SETTINGS, nullptr, &ScreenHandler.HandleSettings, nullptr),
  162. { .VP = VP_MARLIN_VERSION, .memadr = (void*)MarlinVersion, .size = VP_MARLIN_VERSION_LEN, .set_by_display_handler = nullptr, .send_to_display_handler =&ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
  163. // M117 LCD String (We don't need the string in memory but "just" push it to the display on demand, hence the nullptr
  164. { .VP = VP_M117, .memadr = nullptr, .size = VP_M117_LEN, .set_by_display_handler = nullptr, .send_to_display_handler =&ScreenHandler.DGUSLCD_SendStringToDisplay },
  165. // Temperature Data
  166. #if HOTENDS >= 1
  167. VPHELPER(VP_T_E0_Is, nullptr, nullptr, SET_VARIABLE(getActualTemp_celsius, E0, long)),
  168. VPHELPER(VP_T_E0_Set, nullptr, GET_VARIABLE(setTargetTemp_celsius, E0),
  169. SET_VARIABLE(getTargetTemp_celsius, E0)),
  170. VPHELPER(VP_Flowrate_E0, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
  171. VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
  172. VPHELPER(VP_MOVE_E0, nullptr, &ScreenHandler.HandleManualExtrude, nullptr),
  173. VPHELPER(VP_E0_CONTROL, &thermalManager.temp_hotend[0].target, &ScreenHandler.HandleHeaterControl, nullptr),
  174. VPHELPER(VP_E0_STATUS, &thermalManager.temp_hotend[0].target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay),
  175. #if ENABLED(DGUS_PREHEAT_UI)
  176. VPHELPER(VP_E0_BED_PREHEAT, nullptr, &ScreenHandler.HandlePreheat, nullptr),
  177. #endif
  178. #if ENABLED(PIDTEMP)
  179. VPHELPER(VP_E0_PID_P, &thermalManager.temp_hotend[0].pid.Kp, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID),
  180. VPHELPER(VP_E0_PID_I, &thermalManager.temp_hotend[0].pid.Ki, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID),
  181. VPHELPER(VP_E0_PID_D, &thermalManager.temp_hotend[0].pid.Kd, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID),
  182. VPHELPER(VP_PID_AUTOTUNE_E0, nullptr, &ScreenHandler.HandlePIDAutotune, nullptr),
  183. #endif
  184. #if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
  185. VPHELPER(VP_E0_FILAMENT_LOAD_UNLOAD, nullptr, &ScreenHandler.HandleFilamentOption, &ScreenHandler.HandleFilamentLoadUnload),
  186. #endif
  187. #endif
  188. #if HOTENDS >= 2
  189. VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, DGUSLCD_SendFloatAsLongValueToDisplay<0>),
  190. VPHELPER(VP_T_E1_Set, &thermalManager.temp_hotend[1].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
  191. VPHELPER(VP_Flowrate_E1, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
  192. VPHELPER(VP_MOVE_E1, nullptr, &ScreenHandler.HandleManualExtrude, nullptr),
  193. VPHELPER(VP_E1_CONTROL, &thermalManager.temp_hotend[1].target, &ScreenHandler.HandleHeaterControl, nullptr),
  194. VPHELPER(VP_E1_STATUS, &thermalManager.temp_hotend[1].target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay),
  195. #if ENABLED(PIDTEMP)
  196. VPHELPER(VP_PID_AUTOTUNE_E1, nullptr, &ScreenHandler.HandlePIDAutotune, nullptr),
  197. #endif
  198. #endif
  199. #if HAS_HEATED_BED
  200. VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>),
  201. VPHELPER(VP_T_Bed_Set, &thermalManager.temp_bed.target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
  202. VPHELPER(VP_BED_CONTROL, &thermalManager.temp_bed.target, &ScreenHandler.HandleHeaterControl, nullptr),
  203. VPHELPER(VP_BED_STATUS, &thermalManager.temp_bed.target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay),
  204. #if ENABLED(PIDTEMPBED)
  205. VPHELPER(VP_BED_PID_P, &thermalManager.temp_bed.pid.Kp, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID),
  206. VPHELPER(VP_BED_PID_I, &thermalManager.temp_bed.pid.Ki, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID),
  207. VPHELPER(VP_BED_PID_D, &thermalManager.temp_bed.pid.Kd, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID),
  208. #endif
  209. #endif
  210. // Fan Data
  211. #if HAS_FAN
  212. #define FAN_VPHELPER(N) \
  213. VPHELPER(VP_Fan##N##_Percentage, &thermalManager.fan_speed[N], ScreenHandler.DGUSLCD_PercentageToUint8, &ScreenHandler.DGUSLCD_SendPercentageToDisplay), \
  214. VPHELPER(VP_FAN##N##_CONTROL, &thermalManager.fan_speed[N], &ScreenHandler.HandleFanControl, nullptr), \
  215. VPHELPER(VP_FAN##N##_STATUS, &thermalManager.fan_speed[N], nullptr, &ScreenHandler.DGUSLCD_SendFanStatusToDisplay),
  216. REPEAT(FAN_COUNT, FAN_VPHELPER)
  217. #endif
  218. // Feedrate
  219. VPHELPER(VP_Feedrate_Percentage, &feedrate_percentage, ScreenHandler.DGUSLCD_SetValueDirectly<int16_t>, &ScreenHandler.DGUSLCD_SendWordValueToDisplay ),
  220. // Position Data
  221. VPHELPER(VP_XPos, &current_position.x, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
  222. VPHELPER(VP_YPos, &current_position.y, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
  223. VPHELPER(VP_ZPos, &current_position.z, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
  224. // Print Progress
  225. VPHELPER(VP_PrintProgress_Percentage, nullptr, nullptr, ScreenHandler.DGUSLCD_SendPrintProgressToDisplay ),
  226. // Print Time
  227. VPHELPER_STR(VP_PrintTime, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeToDisplay ),
  228. #if ENABLED(PRINTCOUNTER)
  229. VPHELPER_STR(VP_PrintAccTime, nullptr, VP_PrintAccTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintAccTimeToDisplay ),
  230. VPHELPER_STR(VP_PrintsTotal, nullptr, VP_PrintsTotal_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintsTotalToDisplay ),
  231. #endif
  232. VPHELPER(VP_X_STEP_PER_MM, &planner.settings.axis_steps_per_mm[X_AXIS], ScreenHandler.HandleStepPerMMChanged, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<1>),
  233. VPHELPER(VP_Y_STEP_PER_MM, &planner.settings.axis_steps_per_mm[Y_AXIS], ScreenHandler.HandleStepPerMMChanged, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<1>),
  234. VPHELPER(VP_Z_STEP_PER_MM, &planner.settings.axis_steps_per_mm[Z_AXIS], ScreenHandler.HandleStepPerMMChanged, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<1>),
  235. #if HOTENDS >= 1
  236. VPHELPER(VP_E0_STEP_PER_MM, &planner.settings.axis_steps_per_mm[E_AXIS_N(0)], ScreenHandler.HandleStepPerMMExtruderChanged, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<1>),
  237. #endif
  238. #if HOTENDS >= 2
  239. VPHELPER(VP_E1_STEP_PER_MM, &planner.settings.axis_steps_per_mm[E_AXIS_N(1)], ScreenHandler.HandleStepPerMMExtruderChanged, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<1>),
  240. #endif
  241. // SDCard File listing.
  242. #if ENABLED(SDSUPPORT)
  243. VPHELPER(VP_SD_ScrollEvent, nullptr, ScreenHandler.DGUSLCD_SD_ScrollFilelist, nullptr),
  244. VPHELPER(VP_SD_FileSelected, nullptr, ScreenHandler.DGUSLCD_SD_FileSelected, nullptr),
  245. VPHELPER(VP_SD_FileSelectConfirm, nullptr, ScreenHandler.DGUSLCD_SD_StartPrint, nullptr),
  246. VPHELPER_STR(VP_SD_FileName0, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
  247. VPHELPER_STR(VP_SD_FileName1, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
  248. VPHELPER_STR(VP_SD_FileName2, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
  249. VPHELPER_STR(VP_SD_FileName3, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
  250. VPHELPER_STR(VP_SD_FileName4, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
  251. VPHELPER(VP_SD_ResumePauseAbort, nullptr, ScreenHandler.DGUSLCD_SD_ResumePauseAbort, nullptr),
  252. VPHELPER(VP_SD_AbortPrintConfirmed, nullptr, ScreenHandler.DGUSLCD_SD_ReallyAbort, nullptr),
  253. VPHELPER(VP_SD_Print_Setting, nullptr, ScreenHandler.DGUSLCD_SD_PrintTune, nullptr),
  254. #if HAS_BED_PROBE
  255. VPHELPER(VP_SD_Print_ProbeOffsetZ, &probe.offset.z, ScreenHandler.HandleProbeOffsetZChanged, &ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<2>),
  256. #if ENABLED(BABYSTEPPING)
  257. VPHELPER(VP_SD_Print_LiveAdjustZ, nullptr, ScreenHandler.HandleLiveAdjustZ, nullptr),
  258. #endif
  259. #endif
  260. #endif
  261. #if ENABLED(DGUS_UI_WAITING)
  262. VPHELPER(VP_WAITING_STATUS, nullptr, nullptr, ScreenHandler.DGUSLCD_SendWaitingStatusToDisplay),
  263. #endif
  264. // Messages for the User, shared by the popup and the kill screen. They cant be autouploaded as we do not buffer content.
  265. { .VP = VP_MSGSTR1, .memadr = nullptr, .size = VP_MSGSTR1_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
  266. { .VP = VP_MSGSTR2, .memadr = nullptr, .size = VP_MSGSTR2_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
  267. { .VP = VP_MSGSTR3, .memadr = nullptr, .size = VP_MSGSTR3_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
  268. { .VP = VP_MSGSTR4, .memadr = nullptr, .size = VP_MSGSTR4_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
  269. VPHELPER(0, 0, 0, 0) // must be last entry.
  270. };
  271. #endif // DGUS_LCD_UI_ORIGIN