My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DGUSScreenHandler.cpp 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. #include "../../../../inc/MarlinConfigPre.h"
  23. #if ENABLED(DGUS_LCD_UI_FYSETC)
  24. #include "../DGUSScreenHandler.h"
  25. #include "../../../../MarlinCore.h"
  26. #include "../../../../gcode/queue.h"
  27. #include "../../../../libs/duration_t.h"
  28. #include "../../../../module/settings.h"
  29. #include "../../../../module/temperature.h"
  30. #include "../../../../module/motion.h"
  31. #include "../../../../module/planner.h"
  32. #include "../../../../module/printcounter.h"
  33. #include "../../../../sd/cardreader.h"
  34. #if ENABLED(POWER_LOSS_RECOVERY)
  35. #include "../../../../feature/powerloss.h"
  36. #endif
  37. #if ENABLED(SDSUPPORT)
  38. void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) {
  39. uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file;
  40. if (touched_nr > filelist.count()) return;
  41. if (!filelist.seek(touched_nr)) return;
  42. if (filelist.isDir()) {
  43. filelist.changeDir(filelist.filename());
  44. top_file = 0;
  45. ForceCompleteUpdate();
  46. return;
  47. }
  48. #if ENABLED(DGUS_PRINT_FILENAME)
  49. // Send print filename
  50. dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), VP_SD_FileName_LEN, true);
  51. #endif
  52. // Setup Confirmation screen
  53. file_to_print = touched_nr;
  54. HandleUserConfirmationPopUp(VP_SD_FileSelectConfirm, nullptr, PSTR("Print file"), filelist.filename(), PSTR("from SD Card?"), true, true, false, true);
  55. }
  56. void DGUSScreenHandler::DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr) {
  57. if (!filelist.seek(file_to_print)) return;
  58. ExtUI::printFile(filelist.shortFilename());
  59. GotoScreen(DGUSLCD_SCREEN_SDPRINTMANIPULATION);
  60. }
  61. void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) {
  62. if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes.
  63. switch (swap16(*(uint16_t*)val_ptr)) {
  64. case 0: { // Resume
  65. if (ExtUI::isPrintingFromMediaPaused()) {
  66. ExtUI::resumePrint();
  67. }
  68. } break;
  69. case 1: // Pause
  70. GotoScreen(MKSLCD_SCREEN_PAUSE);
  71. if (!ExtUI::isPrintingFromMediaPaused()) {
  72. ExtUI::pausePrint();
  73. //ExtUI::mks_pausePrint();
  74. }
  75. break;
  76. case 2: // Abort
  77. HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true);
  78. break;
  79. }
  80. }
  81. void DGUSScreenHandler::DGUSLCD_SD_SendFilename(DGUS_VP_Variable& var) {
  82. uint16_t target_line = (var.VP - VP_SD_FileName0) / VP_SD_FileName_LEN;
  83. if (target_line > DGUS_SD_FILESPERSCREEN) return;
  84. char tmpfilename[VP_SD_FileName_LEN + 1] = "";
  85. var.memadr = (void*)tmpfilename;
  86. if (filelist.seek(top_file + target_line)) {
  87. snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s%c"), filelist.filename(), filelist.isDir() ? '/' : 0); // snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s"), filelist.filename());
  88. }
  89. DGUSLCD_SendStringToDisplay(var);
  90. }
  91. void DGUSScreenHandler::SDCardInserted() {
  92. top_file = 0;
  93. filelist.refresh();
  94. auto cs = getCurrentScreen();
  95. if (cs == DGUSLCD_SCREEN_MAIN || cs == DGUSLCD_SCREEN_STATUS)
  96. GotoScreen(DGUSLCD_SCREEN_SDFILELIST);
  97. }
  98. void DGUSScreenHandler::SDCardRemoved() {
  99. if (current_screen == DGUSLCD_SCREEN_SDFILELIST
  100. || (current_screen == DGUSLCD_SCREEN_CONFIRM && (ConfirmVP == VP_SD_AbortPrintConfirmed || ConfirmVP == VP_SD_FileSelectConfirm))
  101. || current_screen == DGUSLCD_SCREEN_SDPRINTMANIPULATION
  102. ) GotoScreen(DGUSLCD_SCREEN_MAIN);
  103. }
  104. #endif // SDSUPPORT
  105. void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) {
  106. uint8_t *tmp = (uint8_t*)val_ptr;
  107. // The keycode in target is coded as <from-frame><to-frame>, so 0x0100A means
  108. // from screen 1 (main) to 10 (temperature). DGUSLCD_SCREEN_POPUP is special,
  109. // meaning "return to previous screen"
  110. DGUSLCD_Screens target = (DGUSLCD_Screens)tmp[1];
  111. DEBUG_ECHOLNPAIR("\n DEBUG target", target);
  112. if (target == DGUSLCD_SCREEN_POPUP) {
  113. // Special handling for popup is to return to previous menu
  114. if (current_screen == DGUSLCD_SCREEN_POPUP && confirm_action_cb) confirm_action_cb();
  115. PopToOldScreen();
  116. return;
  117. }
  118. UpdateNewScreen(target);
  119. #ifdef DEBUG_DGUSLCD
  120. if (!DGUSLCD_FindScreenVPMapList(target)) DEBUG_ECHOLNPAIR("WARNING: No screen Mapping found for ", target);
  121. #endif
  122. }
  123. void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
  124. DEBUG_ECHOLNPGM("HandleManualMove");
  125. int16_t movevalue = swap16(*(uint16_t*)val_ptr);
  126. #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
  127. if (movevalue) {
  128. const uint16_t choice = *(uint16_t*)var.memadr;
  129. movevalue = movevalue < 0 ? -choice : choice;
  130. }
  131. #endif
  132. char axiscode;
  133. unsigned int speed = 1500; // FIXME: get default feedrate for manual moves, dont hardcode.
  134. switch (var.VP) {
  135. default: return;
  136. case VP_MOVE_X:
  137. axiscode = 'X';
  138. if (!ExtUI::canMove(ExtUI::axis_t::X)) goto cannotmove;
  139. break;
  140. case VP_MOVE_Y:
  141. axiscode = 'Y';
  142. if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove;
  143. break;
  144. case VP_MOVE_Z:
  145. axiscode = 'Z';
  146. speed = 300; // default to 5mm/s
  147. if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove;
  148. break;
  149. case VP_HOME_ALL: // only used for homing
  150. axiscode = '\0';
  151. movevalue = 0; // ignore value sent from display, this VP is _ONLY_ for homing.
  152. break;
  153. }
  154. if (!movevalue) {
  155. // homing
  156. DEBUG_ECHOPAIR(" homing ", AS_CHAR(axiscode));
  157. char buf[6] = "G28 X";
  158. buf[4] = axiscode;
  159. //DEBUG_ECHOPAIR(" ", buf);
  160. queue.enqueue_one_now(buf);
  161. //DEBUG_ECHOLNPGM(" ✓");
  162. ForceCompleteUpdate();
  163. return;
  164. }
  165. else {
  166. // movement
  167. DEBUG_ECHOPAIR(" move ", AS_CHAR(axiscode));
  168. bool old_relative_mode = relative_mode;
  169. if (!relative_mode) {
  170. //DEBUG_ECHOPGM(" G91");
  171. queue.enqueue_now_P(PSTR("G91"));
  172. //DEBUG_ECHOPGM(" ✓ ");
  173. }
  174. char buf[32]; // G1 X9999.99 F12345
  175. unsigned int backup_speed = MMS_TO_MMM(feedrate_mm_s);
  176. char sign[] = "\0";
  177. int16_t value = movevalue / 100;
  178. if (movevalue < 0) { value = -value; sign[0] = '-'; }
  179. int16_t fraction = ABS(movevalue) % 100;
  180. snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed);
  181. //DEBUG_ECHOPAIR(" ", buf);
  182. queue.enqueue_one_now(buf);
  183. //DEBUG_ECHOLNPGM(" ✓ ");
  184. if (backup_speed != speed) {
  185. snprintf_P(buf, 32, PSTR("G0 F%d"), backup_speed);
  186. queue.enqueue_one_now(buf);
  187. //DEBUG_ECHOPAIR(" ", buf);
  188. }
  189. // while (!enqueue_and_echo_command(buf)) idle();
  190. //DEBUG_ECHOLNPGM(" ✓ ");
  191. if (!old_relative_mode) {
  192. //DEBUG_ECHOPGM("G90");
  193. queue.enqueue_now_P(PSTR("G90"));
  194. //DEBUG_ECHOPGM(" ✓ ");
  195. }
  196. }
  197. ForceCompleteUpdate();
  198. DEBUG_ECHOLNPGM("manmv done.");
  199. return;
  200. cannotmove:
  201. DEBUG_ECHOLNPAIR(" cannot move ", AS_CHAR(axiscode));
  202. return;
  203. }
  204. #if HAS_PID_HEATING
  205. void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) {
  206. uint16_t rawvalue = swap16(*(uint16_t*)val_ptr);
  207. DEBUG_ECHOLNPAIR("V1:", rawvalue);
  208. float value = (float)rawvalue / 10;
  209. DEBUG_ECHOLNPAIR("V2:", value);
  210. float newvalue = 0;
  211. switch (var.VP) {
  212. default: return;
  213. #if HOTENDS >= 1
  214. case VP_E0_PID_P: newvalue = value; break;
  215. case VP_E0_PID_I: newvalue = scalePID_i(value); break;
  216. case VP_E0_PID_D: newvalue = scalePID_d(value); break;
  217. #endif
  218. #if HOTENDS >= 2
  219. case VP_E1_PID_P: newvalue = value; break;
  220. case VP_E1_PID_I: newvalue = scalePID_i(value); break;
  221. case VP_E1_PID_D: newvalue = scalePID_d(value); break;
  222. #endif
  223. #if HAS_HEATED_BED
  224. case VP_BED_PID_P: newvalue = value; break;
  225. case VP_BED_PID_I: newvalue = scalePID_i(value); break;
  226. case VP_BED_PID_D: newvalue = scalePID_d(value); break;
  227. #endif
  228. }
  229. DEBUG_ECHOLNPAIR_F("V3:", newvalue);
  230. *(float *)var.memadr = newvalue;
  231. skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
  232. }
  233. #endif // HAS_PID_HEATING
  234. #if ENABLED(BABYSTEPPING)
  235. void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) {
  236. DEBUG_ECHOLNPGM("HandleLiveAdjustZ");
  237. int16_t flag = swap16(*(uint16_t*)val_ptr),
  238. steps = flag ? -20 : 20;
  239. ExtUI::smartAdjustAxis_steps(steps, ExtUI::axis_t::Z, true);
  240. ForceCompleteUpdate();
  241. }
  242. #endif
  243. #if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
  244. void DGUSScreenHandler::HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr) {
  245. DEBUG_ECHOLNPGM("HandleFilamentOption");
  246. uint8_t e_temp = 0;
  247. filament_data.heated = false;
  248. uint16_t preheat_option = swap16(*(uint16_t*)val_ptr);
  249. if (preheat_option <= 8) { // Load filament type
  250. filament_data.action = 1;
  251. }
  252. else if (preheat_option >= 10) { // Unload filament type
  253. preheat_option -= 10;
  254. filament_data.action = 2;
  255. filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH;
  256. }
  257. else { // Cancel filament operation
  258. filament_data.action = 0;
  259. }
  260. switch (preheat_option) {
  261. case 0: // Load PLA
  262. #ifdef PREHEAT_1_TEMP_HOTEND
  263. e_temp = PREHEAT_1_TEMP_HOTEND;
  264. #endif
  265. break;
  266. case 1: // Load ABS
  267. TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND);
  268. break;
  269. case 2: // Load PET
  270. #ifdef PREHEAT_3_TEMP_HOTEND
  271. e_temp = PREHEAT_3_TEMP_HOTEND;
  272. #endif
  273. break;
  274. case 3: // Load FLEX
  275. #ifdef PREHEAT_4_TEMP_HOTEND
  276. e_temp = PREHEAT_4_TEMP_HOTEND;
  277. #endif
  278. break;
  279. case 9: // Cool down
  280. default:
  281. e_temp = 0;
  282. break;
  283. }
  284. if (filament_data.action == 0) { // Go back to utility screen
  285. #if HOTENDS >= 1
  286. thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0);
  287. #endif
  288. #if HOTENDS >= 2
  289. thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1);
  290. #endif
  291. GotoScreen(DGUSLCD_SCREEN_UTILITY);
  292. }
  293. else { // Go to the preheat screen to show the heating progress
  294. switch (var.VP) {
  295. default: return;
  296. #if HOTENDS >= 1
  297. case VP_E0_FILAMENT_LOAD_UNLOAD:
  298. filament_data.extruder = ExtUI::extruder_t::E0;
  299. thermalManager.setTargetHotend(e_temp, filament_data.extruder);
  300. break;
  301. #endif
  302. #if HOTENDS >= 2
  303. case VP_E1_FILAMENT_LOAD_UNLOAD:
  304. filament_data.extruder = ExtUI::extruder_t::E1;
  305. thermalManager.setTargetHotend(e_temp, filament_data.extruder);
  306. break;
  307. #endif
  308. }
  309. GotoScreen(DGUSLCD_SCREEN_FILAMENT_HEATING);
  310. }
  311. }
  312. void DGUSScreenHandler::HandleFilamentLoadUnload(DGUS_VP_Variable &var) {
  313. DEBUG_ECHOLNPGM("HandleFilamentLoadUnload");
  314. if (filament_data.action <= 0) return;
  315. // If we close to the target temperature, we can start load or unload the filament
  316. if (thermalManager.hotEnoughToExtrude(filament_data.extruder) && \
  317. thermalManager.targetHotEnoughToExtrude(filament_data.extruder)) {
  318. float movevalue = DGUS_FILAMENT_LOAD_LENGTH_PER_TIME;
  319. if (filament_data.action == 1) { // load filament
  320. if (!filament_data.heated) {
  321. //GotoScreen(DGUSLCD_SCREEN_FILAMENT_LOADING);
  322. filament_data.heated = true;
  323. }
  324. movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue;
  325. }
  326. else { // unload filament
  327. if (!filament_data.heated) {
  328. GotoScreen(DGUSLCD_SCREEN_FILAMENT_UNLOADING);
  329. filament_data.heated = true;
  330. }
  331. // Before unloading extrude to prevent jamming
  332. if (filament_data.purge_length >= 0) {
  333. movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue;
  334. filament_data.purge_length -= movevalue;
  335. }
  336. else {
  337. movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) - movevalue;
  338. }
  339. }
  340. ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder);
  341. }
  342. }
  343. #endif // DGUS_FILAMENT_LOADUNLOAD
  344. bool DGUSScreenHandler::loop() {
  345. dgusdisplay.loop();
  346. const millis_t ms = millis();
  347. static millis_t next_event_ms = 0;
  348. if (!IsScreenComplete() || ELAPSED(ms, next_event_ms)) {
  349. next_event_ms = ms + DGUS_UPDATE_INTERVAL_MS;
  350. UpdateScreenVPData();
  351. }
  352. #if ENABLED(SHOW_BOOTSCREEN)
  353. static bool booted = false;
  354. if (!booted && TERN0(POWER_LOSS_RECOVERY, recovery.valid()))
  355. booted = true;
  356. if (!booted && ELAPSED(ms, TERN(USE_MKS_GREEN_UI, 1000, BOOTSCREEN_TIMEOUT)))
  357. booted = true;
  358. #endif
  359. return IsScreenComplete();
  360. }
  361. #endif // DGUS_LCD_UI_FYSETC