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.

chiron_tft.cpp 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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. /**
  23. * lcd/extui/lib/chiron_tft.cpp
  24. *
  25. * Extensible_UI implementation for Anycubic Chiron
  26. * Written By Nick Wells, 2020 [https://github.com/SwiftNick]
  27. * (not affiliated with Anycubic, Ltd.)
  28. */
  29. #include "../../../../inc/MarlinConfigPre.h"
  30. #if ENABLED(ANYCUBIC_LCD_CHIRON)
  31. #include "chiron_tft.h"
  32. #include "Tunes.h"
  33. #include "FileNavigator.h"
  34. #include "../../../../gcode/queue.h"
  35. #include "../../../../sd/cardreader.h"
  36. #include "../../../../libs/numtostr.h"
  37. #include "../../../../MarlinCore.h"
  38. namespace Anycubic {
  39. printer_state_t ChironTFT::printer_state;
  40. paused_state_t ChironTFT::pause_state;
  41. heater_state_t ChironTFT::hotend_state;
  42. heater_state_t ChironTFT::hotbed_state;
  43. xy_uint8_t ChironTFT::selectedmeshpoint;
  44. char ChironTFT::selectedfile[MAX_PATH_LEN];
  45. char ChironTFT::panel_command[MAX_CMND_LEN];
  46. uint8_t ChironTFT::command_len;
  47. float ChironTFT::live_Zoffset;
  48. file_menu_t ChironTFT::file_menu;
  49. ChironTFT::ChironTFT(){}
  50. void ChironTFT::Startup() {
  51. selectedfile[0] = '\0';
  52. panel_command[0] = '\0';
  53. command_len = 0;
  54. printer_state = AC_printer_idle;
  55. pause_state = AC_paused_idle;
  56. hotend_state = AC_heater_off;
  57. hotbed_state = AC_heater_off;
  58. live_Zoffset = 0.0;
  59. file_menu = AC_menu_file;
  60. // Setup pins for powerloss detection
  61. // Two IO pins are connected on the Trigorilla Board
  62. // On a power interruption the OUTAGECON_PIN goes low.
  63. #if ENABLED(POWER_LOSS_RECOVERY)
  64. OUT_WRITE(OUTAGECON_PIN, HIGH);
  65. #endif
  66. // Filament runout is handled by Marlin settings in Configuration.h
  67. // set FIL_RUNOUT_STATE HIGH // Pin state indicating that filament is NOT present.
  68. // enable FIL_RUNOUT_PULLUP
  69. TFTSer.begin(115200);
  70. // Signal Board has reset
  71. SendtoTFTLN(AC_msg_main_board_has_reset);
  72. safe_delay(200);
  73. // Enable levelling and Disable end stops during print
  74. // as Z home places nozzle above the bed so we need to allow it past the end stops
  75. injectCommands_P(AC_cmnd_enable_levelling);
  76. // Startup tunes are defined in Tunes.h
  77. //PlayTune(BEEPER_PIN, Anycubic_PowerOn, 1);
  78. PlayTune(BEEPER_PIN, GB_PowerOn, 1);
  79. #if ACDEBUGLEVEL
  80. SERIAL_ECHOLNPAIR("AC Debug Level ", ACDEBUGLEVEL);
  81. #endif
  82. SendtoTFTLN(AC_msg_ready);
  83. }
  84. void ChironTFT::IdleLoop() {
  85. if (ReadTFTCommand()) {
  86. ProcessPanelRequest();
  87. command_len = 0;
  88. }
  89. CheckHeaters();
  90. }
  91. void ChironTFT::PrinterKilled(PGM_P error,PGM_P component) {
  92. SendtoTFTLN(AC_msg_kill_lcd);
  93. #if ACDEBUG(AC_MARLIN)
  94. SERIAL_ECHOLNPAIR("PrinterKilled()\nerror: ", error , "\ncomponent: ", component);
  95. #endif
  96. }
  97. void ChironTFT::MediaEvent(media_event_t event) {
  98. #if ACDEBUG(AC_MARLIN)
  99. SERIAL_ECHOLNPAIR("ProcessMediaStatus() ", event);
  100. #endif
  101. switch (event) {
  102. case AC_media_inserted:
  103. SendtoTFTLN(AC_msg_sd_card_inserted);
  104. break;
  105. case AC_media_removed:
  106. SendtoTFTLN(AC_msg_sd_card_removed);
  107. break;
  108. case AC_media_error:
  109. SendtoTFTLN(AC_msg_no_sd_card);
  110. break;
  111. }
  112. }
  113. void ChironTFT::TimerEvent(timer_event_t event) {
  114. #if ACDEBUG(AC_MARLIN)
  115. SERIAL_ECHOLNPAIR("TimerEvent() ", event);
  116. SERIAL_ECHOLNPAIR("Printer State: ", printer_state);
  117. #endif
  118. switch (event) {
  119. case AC_timer_started: {
  120. live_Zoffset = 0.0; // reset print offset
  121. setSoftEndstopState(false); // disable endstops to print
  122. printer_state = AC_printer_printing;
  123. SendtoTFTLN(AC_msg_print_from_sd_card);
  124. } break;
  125. case AC_timer_paused: {
  126. printer_state = AC_printer_paused;
  127. pause_state = AC_paused_idle;
  128. SendtoTFTLN(AC_msg_paused);
  129. } break;
  130. case AC_timer_stopped: {
  131. if (printer_state != AC_printer_idle) {
  132. printer_state = AC_printer_stopping;
  133. SendtoTFTLN(AC_msg_print_complete);
  134. }
  135. setSoftEndstopState(true); // enable endstops
  136. } break;
  137. }
  138. }
  139. void ChironTFT::FilamentRunout() {
  140. #if ACDEBUG(AC_MARLIN)
  141. SERIAL_ECHOLNPAIR("FilamentRunout() printer_state ", printer_state);
  142. #endif
  143. // 1 Signal filament out
  144. SendtoTFTLN(isPrintingFromMedia() ? AC_msg_filament_out_alert : AC_msg_filament_out_block);
  145. //printer_state = AC_printer_filament_out;
  146. PlayTune(BEEPER_PIN, FilamentOut, 1);
  147. }
  148. void ChironTFT::ConfirmationRequest(const char * const msg) {
  149. // M108 continue
  150. #if ACDEBUG(AC_MARLIN)
  151. SERIAL_ECHOLNPAIR("ConfirmationRequest() ", msg, " printer_state:", printer_state);
  152. #endif
  153. switch (printer_state) {
  154. case AC_printer_pausing: {
  155. if (strcmp_P(msg, MARLIN_msg_print_paused) == 0 || strcmp_P(msg, MARLIN_msg_nozzle_parked) == 0) {
  156. SendtoTFTLN(AC_msg_paused); // enable continue button
  157. printer_state = AC_printer_paused;
  158. }
  159. } break;
  160. case AC_printer_resuming_from_power_outage:
  161. case AC_printer_printing:
  162. case AC_printer_paused: {
  163. // Heater timout, send acknowledgement
  164. if (strcmp_P(msg, MARLIN_msg_heater_timeout) == 0) {
  165. pause_state = AC_paused_heater_timed_out;
  166. SendtoTFTLN(AC_msg_paused); // enable continue button
  167. PlayTune(BEEPER_PIN,Heater_Timedout,1);
  168. }
  169. // Reheat finished, send acknowledgement
  170. else if (strcmp_P(msg, MARLIN_msg_reheat_done) == 0) {
  171. pause_state = AC_paused_idle;
  172. SendtoTFTLN(AC_msg_paused); // enable continue button
  173. }
  174. // Filament Purging, send acknowledgement enter run mode
  175. else if (strcmp_P(msg, MARLIN_msg_filament_purging) == 0) {
  176. pause_state = AC_paused_purging_filament;
  177. SendtoTFTLN(AC_msg_paused); // enable continue button
  178. }
  179. } break;
  180. default:
  181. break;
  182. }
  183. }
  184. void ChironTFT::StatusChange(const char * const msg) {
  185. #if ACDEBUG(AC_MARLIN)
  186. SERIAL_ECHOLNPAIR("StatusChange() ", msg);
  187. SERIAL_ECHOLNPAIR("printer_state:", printer_state);
  188. #endif
  189. bool msg_matched = false;
  190. // The only way to get printer status is to parse messages
  191. // Use the state to minimise the work we do here.
  192. switch (printer_state) {
  193. case AC_printer_probing: {
  194. // If probing completes ok save the mesh and park
  195. // Ignore the custom machine name
  196. if (strcmp_P(msg + strlen(CUSTOM_MACHINE_NAME), MARLIN_msg_ready) == 0) {
  197. injectCommands_P(PSTR("M500\nG27"));
  198. SendtoTFTLN(AC_msg_probing_complete);
  199. printer_state = AC_printer_idle;
  200. msg_matched = true;
  201. }
  202. // If probing fails dont save the mesh raise the probe above the bad point
  203. if (strcmp_P(msg, MARLIN_msg_probing_failed) == 0) {
  204. PlayTune(BEEPER_PIN, BeepBeepBeeep, 1);
  205. injectCommands_P(PSTR("G1 Z50 F500"));
  206. SendtoTFTLN(AC_msg_probing_complete);
  207. printer_state = AC_printer_idle;
  208. msg_matched = true;
  209. }
  210. } break;
  211. case AC_printer_printing: {
  212. if (strcmp_P(msg, MARLIN_msg_reheating) == 0) {
  213. SendtoTFTLN(AC_msg_paused); // enable continue button
  214. msg_matched = true;
  215. }
  216. } break;
  217. case AC_printer_pausing: {
  218. if (strcmp_P(msg, MARLIN_msg_print_paused) == 0) {
  219. SendtoTFTLN(AC_msg_paused);
  220. printer_state = AC_printer_paused;
  221. pause_state = AC_paused_idle;
  222. msg_matched = true;
  223. }
  224. } break;
  225. case AC_printer_stopping: {
  226. if (strcmp_P(msg, MARLIN_msg_print_aborted) == 0) {
  227. SendtoTFTLN(AC_msg_stop);
  228. printer_state = AC_printer_idle;
  229. msg_matched = true;
  230. }
  231. } break;
  232. default:
  233. break;
  234. }
  235. // If not matched earlier see if this was a heater message
  236. if (!msg_matched) {
  237. if (strcmp_P(msg, MARLIN_msg_extruder_heating) == 0) {
  238. SendtoTFTLN(AC_msg_nozzle_heating);
  239. hotend_state = AC_heater_temp_set;
  240. }
  241. else if (strcmp_P(msg, MARLIN_msg_bed_heating) == 0) {
  242. SendtoTFTLN(AC_msg_bed_heating);
  243. hotbed_state = AC_heater_temp_set;
  244. }
  245. }
  246. }
  247. void ChironTFT::PowerLossRecovery() {
  248. printer_state = AC_printer_resuming_from_power_outage; // Play tune to notify user we can recover.
  249. PlayTune(BEEPER_PIN, SOS, 1);
  250. SERIAL_ECHOLNPGM("Resuming from power outage...");
  251. SERIAL_ECHOLNPGM("Select SD file then press resume");
  252. }
  253. void ChironTFT::SendtoTFT(PGM_P str) { // A helper to print PROGMEN string to the panel
  254. #if ACDEBUG(AC_SOME)
  255. serialprintPGM(str);
  256. #endif
  257. while (const char c = pgm_read_byte(str++)) TFTSer.print(c);
  258. }
  259. void ChironTFT::SendtoTFTLN(PGM_P str = nullptr) {
  260. if (str) {
  261. #if ACDEBUG(AC_SOME)
  262. SERIAL_ECHOPGM("> ");
  263. #endif
  264. SendtoTFT(str);
  265. #if ACDEBUG(AC_SOME)
  266. SERIAL_EOL();
  267. #endif
  268. }
  269. TFTSer.println("");
  270. }
  271. bool ChironTFT::ReadTFTCommand() {
  272. bool command_ready = false;
  273. while(TFTSer.available() > 0 && command_len < MAX_CMND_LEN) {
  274. panel_command[command_len] = TFTSer.read();
  275. if (panel_command[command_len] == '\n') {
  276. command_ready = true;
  277. break;
  278. }
  279. command_len++;
  280. }
  281. if (command_ready) {
  282. panel_command[command_len] = 0x00;
  283. #if ACDEBUG(AC_ALL)
  284. SERIAL_ECHOLNPAIR("< ", panel_command);
  285. #endif
  286. #if ACDEBUG(AC_SOME)
  287. // Ignore status request commands
  288. uint8_t req = atoi(&panel_command[1]);
  289. if (req > 7 && req != 20) {
  290. SERIAL_ECHOLNPAIR("> ", panel_command);
  291. SERIAL_ECHOLNPAIR("printer_state:", printer_state);
  292. }
  293. #endif
  294. }
  295. return command_ready;
  296. }
  297. int8_t ChironTFT::Findcmndpos(const char * buff, char q) {
  298. int8_t pos = 0;
  299. do { if (buff[pos] == q) return pos; } while(++pos < MAX_CMND_LEN);
  300. return -1;
  301. }
  302. void ChironTFT::CheckHeaters() {
  303. uint8_t faultDuration = 0;
  304. float temp = 0;
  305. // if the hotend temp is abnormal, confirm state before signalling panel
  306. temp = getActualTemp_celsius(E0);
  307. while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) {
  308. faultDuration++;
  309. if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) {
  310. SendtoTFTLN(AC_msg_nozzle_temp_abnormal);
  311. SERIAL_ECHOLNPAIR("Extruder temp abnormal! : ", temp);
  312. break;
  313. }
  314. delay_ms(500);
  315. temp = getActualTemp_celsius(E0);
  316. }
  317. // If the hotbed temp is abnormal, confirm state before signaling panel
  318. faultDuration = 0;
  319. temp = getActualTemp_celsius(BED);
  320. while (!WITHIN(temp, BED_MINTEMP, BED_MAXTEMP)) {
  321. faultDuration++;
  322. if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) {
  323. SendtoTFTLN(AC_msg_nozzle_temp_abnormal);
  324. SERIAL_ECHOLNPAIR_P("Bed temp abnormal! : ", temp);
  325. break;
  326. }
  327. delay_ms(500);
  328. temp = getActualTemp_celsius(E0);
  329. }
  330. // Update panel with hotend heater status
  331. if (hotend_state != AC_heater_temp_reached) {
  332. if (WITHIN(getActualTemp_celsius(E0) - getTargetTemp_celsius(E0), -1, 1)) {
  333. SendtoTFTLN(AC_msg_nozzle_heating_done);
  334. hotend_state = AC_heater_temp_reached;
  335. }
  336. }
  337. // Update panel with bed heater status
  338. if (hotbed_state != AC_heater_temp_reached) {
  339. if (WITHIN(getActualTemp_celsius(BED) - getTargetTemp_celsius(BED), -0.5, 0.5)) {
  340. SendtoTFTLN(AC_msg_bed_heating_done);
  341. hotbed_state = AC_heater_temp_reached;
  342. }
  343. }
  344. }
  345. void ChironTFT::SendFileList(int8_t startindex) {
  346. // Respond to panel request for 4 files starting at index
  347. #if ACDEBUG(AC_INFO)
  348. SERIAL_ECHOLNPAIR("## SendFileList ## ", startindex);
  349. #endif
  350. SendtoTFTLN(PSTR("FN "));
  351. filenavigator.getFiles(startindex);
  352. SendtoTFTLN(PSTR("END"));
  353. }
  354. void ChironTFT::SelectFile() {
  355. strncpy(selectedfile, panel_command + 4, command_len - 4);
  356. selectedfile[command_len - 5] = '\0';
  357. #if ACDEBUG(AC_FILE)
  358. SERIAL_ECHOLNPAIR_F(" Selected File: ",selectedfile);
  359. #endif
  360. switch (selectedfile[0]) {
  361. case '/': // Valid file selected
  362. SendtoTFTLN(AC_msg_sd_file_open_success);
  363. break;
  364. case '<': // .. (go up folder level)
  365. filenavigator.upDIR();
  366. SendtoTFTLN(AC_msg_sd_file_open_failed);
  367. SendFileList( 0 );
  368. break;
  369. default: // enter sub folder
  370. filenavigator.changeDIR(selectedfile);
  371. SendtoTFTLN(AC_msg_sd_file_open_failed);
  372. SendFileList( 0 );
  373. break;
  374. }
  375. }
  376. void ChironTFT::InjectCommandandWait(PGM_P cmd) {
  377. //injectCommands_P(cmnd); queue.enqueue_now_P(cmd);
  378. //SERIAL_ECHOLN(PSTR("Inject>"));
  379. }
  380. void ChironTFT::ProcessPanelRequest() {
  381. // Break these up into logical blocks // as its easier to navigate than one huge switch case!
  382. int8_t req = atoi(&panel_command[1]);
  383. // Information requests A0 - A8 and A33
  384. if (req <= 8 || req == 33) PanelInfo(req);
  385. // Simple Actions A9 - A28
  386. else if ( req <= 28) PanelAction(req);
  387. // Process Initiation
  388. else if (req <= 34) PanelProcess(req);
  389. else SendtoTFTLN();
  390. }
  391. void ChironTFT::PanelInfo(uint8_t req) {
  392. // information requests A0-A8 and A33
  393. switch (req) {
  394. case 0: // A0 Get HOTEND Temp
  395. SendtoTFT(PSTR("A0V "));
  396. TFTSer.println(getActualTemp_celsius(E0));
  397. break;
  398. case 1: // A1 Get HOTEND Target Temp
  399. SendtoTFT(PSTR("A1V "));
  400. TFTSer.println(getTargetTemp_celsius(E0));
  401. break;
  402. case 2: // A2 Get BED Temp
  403. SendtoTFT(PSTR("A2V "));
  404. TFTSer.println(getActualTemp_celsius(BED));
  405. break;
  406. case 3: // A3 Get BED Target Temp
  407. SendtoTFT(PSTR("A3V "));
  408. TFTSer.println(getTargetTemp_celsius(BED));
  409. break;
  410. case 4: // A4 Get FAN Speed
  411. SendtoTFT(PSTR("A4V "));
  412. TFTSer.println(getActualFan_percent(FAN0));
  413. break;
  414. case 5: // A5 Get Current Coordinates
  415. SendtoTFT(PSTR("A5V X: "));
  416. TFTSer.print(getAxisPosition_mm(X));
  417. SendtoTFT(PSTR(" Y: "));
  418. TFTSer.print(getAxisPosition_mm(Y));
  419. SendtoTFT(PSTR(" Z: "));
  420. TFTSer.println(getAxisPosition_mm(Z));
  421. break;
  422. case 6: // A6 Get printing progress
  423. if (isPrintingFromMedia()) {
  424. SendtoTFT(PSTR("A6V "));
  425. TFTSer.println(ui8tostr2(getProgress_percent()));
  426. }
  427. else
  428. SendtoTFTLN(PSTR("A6V ---"));
  429. break;
  430. case 7: { // A7 Get Printing Time
  431. uint32_t time = getProgress_seconds_elapsed() / 60;
  432. SendtoTFT(PSTR("A7V "));
  433. TFTSer.print(ui8tostr2(time / 60));
  434. SendtoTFT(PSTR(" H "));
  435. TFTSer.print(ui8tostr2(time % 60));
  436. SendtoTFT(PSTR(" M"));
  437. #if ACDEBUG(AC_ALL)
  438. SERIAL_ECHOLNPAIR("Print time ", ui8tostr2(time / 60), ":", ui8tostr2(time % 60));
  439. #endif
  440. } break;
  441. case 8: // A8 Get SD Card list A8 S0
  442. if (!isMediaInserted()) safe_delay(500);
  443. if (!isMediaInserted()) // Make sure the card is removed
  444. SendtoTFTLN(AC_msg_no_sd_card);
  445. else if (panel_command[3] == 'S')
  446. SendFileList( atoi( &panel_command[4] ) );
  447. break;
  448. case 33: // A33 Get firmware info
  449. SendtoTFT(PSTR("J33 "));
  450. SendtoTFTLN(PSTR(SHORT_BUILD_VERSION));
  451. break;
  452. }
  453. }
  454. void ChironTFT::PanelAction(uint8_t req) {
  455. switch (req) {
  456. case 9: // A9 Pause SD print
  457. if (isPrintingFromMedia()) {
  458. SendtoTFTLN(AC_msg_pause);
  459. pausePrint();
  460. printer_state = AC_printer_pausing;
  461. }
  462. else
  463. SendtoTFTLN(AC_msg_stop);
  464. break;
  465. case 10: // A10 Resume SD Print
  466. if (pause_state == AC_paused_idle || printer_state == AC_printer_resuming_from_power_outage)
  467. resumePrint();
  468. else
  469. setUserConfirmed();
  470. break;
  471. case 11: // A11 Stop SD print
  472. if (isPrintingFromMedia()) {
  473. printer_state = AC_printer_stopping;
  474. stopPrint();
  475. }
  476. else {
  477. if (printer_state == AC_printer_resuming_from_power_outage)
  478. injectCommands_P(PSTR("M1000 C")); // Cancel recovery
  479. SendtoTFTLN(AC_msg_stop);
  480. printer_state = AC_printer_idle;
  481. }
  482. break;
  483. case 12: // A12 Kill printer
  484. kill(); // from marlincore.h
  485. break;
  486. case 13: // A13 Select file
  487. SelectFile();
  488. break;
  489. case 14: { // A14 Start Printing
  490. // Allows printer to restart the job if we dont want to recover
  491. if (printer_state == AC_printer_resuming_from_power_outage) {
  492. injectCommands_P(PSTR("M1000 C")); // Cancel recovery
  493. printer_state = AC_printer_idle;
  494. }
  495. #if ACDebugLevel >= 1
  496. SERIAL_ECHOLNPAIR_F("Print: ", selectedfile);
  497. #endif
  498. // the card library needs a path starting // but the File api doesn't...
  499. char file[MAX_PATH_LEN];
  500. file[0] = '/';
  501. strcpy(file + 1, selectedfile);
  502. printFile(file);
  503. SendtoTFTLN(AC_msg_print_from_sd_card);
  504. } break;
  505. case 15: // A15 Resuming from outage
  506. if (printer_state == AC_printer_resuming_from_power_outage)
  507. // Need to home here to restore the Z position
  508. injectCommands_P(AC_cmnd_power_loss_recovery);
  509. injectCommands_P(PSTR("M1000")); // home and start recovery
  510. break;
  511. case 16: { // A16 Set HotEnd temp A17 S170
  512. const float set_Htemp = atof(&panel_command[5]);
  513. hotend_state = set_Htemp ? AC_heater_temp_set : AC_heater_off;
  514. switch ((char)panel_command[4]) {
  515. // Set Temp
  516. case 'S': case 'C': setTargetTemp_celsius(set_Htemp, E0);
  517. }
  518. } break;
  519. case 17: { // A17 Set bed temp
  520. const float set_Btemp = atof(&panel_command[5]);
  521. hotbed_state = set_Btemp ? AC_heater_temp_set : AC_heater_off;
  522. if (panel_command[4] == 'S')
  523. setTargetTemp_celsius(set_Btemp, BED);
  524. } break;
  525. case 18: // A18 Set Fan Speed
  526. if (panel_command[4] == 'S')
  527. setTargetFan_percent(atof(&panel_command[5]), FAN0);
  528. break;
  529. case 19: // A19 Motors off
  530. if (!isPrinting()) {
  531. disable_all_steppers(); // from marlincore.h
  532. SendtoTFTLN(AC_msg_ready);
  533. }
  534. break;
  535. case 20: // A20 Read/write print speed
  536. if (panel_command[4] == 'S')
  537. setFeedrate_percent(atoi(&panel_command[5]));
  538. else {
  539. SendtoTFT(PSTR("A20V "));
  540. TFTSer.println(getFeedrate_percent());
  541. }
  542. break;
  543. case 21: // A21 Home Axis A21 X
  544. if (!isPrinting()) {
  545. switch ((char)panel_command[4]) {
  546. case 'X': injectCommands_P(PSTR("G28 X")); break;
  547. case 'Y': injectCommands_P(PSTR("G28 Y")); break;
  548. case 'Z': injectCommands_P(PSTR("G28 Z")); break;
  549. case 'C': injectCommands_P(PSTR("G28")); break;
  550. }
  551. }
  552. break;
  553. case 22: // A22 Move Axis A22 Y +10F3000
  554. // Ignore request if printing
  555. if (!isPrinting()) {
  556. // setAxisPosition_mm() uses pre defined manual feedrates so ignore the feedrate from the panel
  557. setSoftEndstopState(true); // enable endstops
  558. float newposition = atof(&panel_command[6]);
  559. #if ACDEBUG(AC_ACTION)
  560. SERIAL_ECHOLNPAIR("Nudge ", panel_command[4], " axis ", newposition);
  561. #endif
  562. switch (panel_command[4]) {
  563. case 'X': setAxisPosition_mm(getAxisPosition_mm(X) + newposition, X); break;
  564. case 'Y': setAxisPosition_mm(getAxisPosition_mm(Y) + newposition, Y); break;
  565. case 'Z': setAxisPosition_mm(getAxisPosition_mm(Z) + newposition, Z); break;
  566. case 'E': // The only time we get this command is from the filament load/unload menu
  567. // the standard movement is too slow so we will use the load unlod GCode to speed it up a bit
  568. if (canMove(E0) && !commandsInQueue())
  569. injectCommands_P(newposition > 0 ? AC_cmnd_manual_load_filament : AC_cmnd_manual_unload_filament);
  570. break;
  571. }
  572. }
  573. break;
  574. case 23: // A23 Preheat PLA
  575. // Ignore request if printing
  576. if (!isPrinting()) {
  577. // Temps defined in configuration.h
  578. setTargetTemp_celsius(PREHEAT_1_TEMP_BED, BED);
  579. setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, E0);
  580. SendtoTFTLN();
  581. hotbed_state = AC_heater_temp_set;
  582. hotend_state = AC_heater_temp_set;
  583. }
  584. break;
  585. case 24: // A24 Preheat ABS
  586. // Ignore request if printing
  587. if (!isPrinting()) {
  588. setTargetTemp_celsius(PREHEAT_2_TEMP_BED, BED);
  589. setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, E0);
  590. SendtoTFTLN();
  591. hotbed_state = AC_heater_temp_set;
  592. hotend_state = AC_heater_temp_set;
  593. }
  594. break;
  595. case 25: // A25 Cool Down
  596. // Ignore request if printing
  597. if (!isPrinting()) {
  598. setTargetTemp_celsius(0, E0);
  599. setTargetTemp_celsius(0, BED);
  600. SendtoTFTLN(AC_msg_ready);
  601. hotbed_state = AC_heater_off;
  602. hotend_state = AC_heater_off;
  603. }
  604. break;
  605. case 26: // A26 Refresh SD
  606. // M22 M21 maybe needed here to reset sd card
  607. filenavigator.reset();
  608. break;
  609. case 27: // A27 Servo Angles adjust
  610. break;
  611. case 28: // A28 Filament set A28 O/C
  612. // Ignore request if printing
  613. if (isPrinting()) break;
  614. SendtoTFTLN();
  615. break;
  616. }
  617. }
  618. void ChironTFT::PanelProcess(uint8_t req) {
  619. switch (req) {
  620. case 29: { // A29 Read Mesh Point A29 X1 Y1
  621. xy_uint8_t pos;
  622. float pos_z;
  623. pos.x = atoi(&panel_command[5]);
  624. pos.y = atoi(&panel_command[8]);
  625. pos_z = getMeshPoint(pos);
  626. SendtoTFT(PSTR("A29V "));
  627. TFTSer.println(pos_z * 100);
  628. if (!isPrinting()) {
  629. setSoftEndstopState(true); // disable endstops
  630. // If the same meshpoint is selected twice in a row, move the head to that ready for adjustment
  631. if ((selectedmeshpoint.x == pos.x) && (selectedmeshpoint.y == pos.y)) {
  632. if (!isPositionKnown())
  633. injectCommands_P(PSTR("G28")); // home
  634. if (isPositionKnown()) {
  635. #if ACDEBUG(AC_INFO)
  636. SERIAL_ECHOLNPAIR("Moving to mesh point at x: ", pos.x, " y: ", pos.y, " z: ", pos_z);
  637. #endif
  638. // Go up before moving
  639. setAxisPosition_mm(3.0,Z);
  640. setAxisPosition_mm(17 + (93 * pos.x), X);
  641. setAxisPosition_mm(20 + (93 * pos.y), Y);
  642. setAxisPosition_mm(0.0, Z);
  643. #if ACDEBUG(AC_INFO)
  644. SERIAL_ECHOLNPAIR("Current Z: ", getAxisPosition_mm(Z));
  645. #endif
  646. }
  647. }
  648. selectedmeshpoint.x = pos.x;
  649. selectedmeshpoint.y = pos.y;
  650. }
  651. } break;
  652. case 30: { // A30 Auto leveling
  653. if (panel_command[3] == 'S') { // Start probing
  654. // Ignore request if printing
  655. if (isPrinting())
  656. SendtoTFTLN(AC_msg_probing_not_allowed); // forbid auto leveling
  657. else {
  658. injectCommands_P(isMachineHomed() ? PSTR("G29") : PSTR("G28\nG29"));
  659. printer_state = AC_printer_probing;
  660. SendtoTFTLN(AC_msg_start_probing);
  661. }
  662. }
  663. else SendtoTFTLN(AC_msg_start_probing);
  664. } break;
  665. case 31: { // A31 Adjust all Probe Points
  666. switch (panel_command[3]) {
  667. case 'C': // Restore and apply original offsets
  668. if (!isPrinting()) {
  669. injectCommands_P(PSTR("M501\nM420 S1"));
  670. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  671. }
  672. break;
  673. case 'D': // Save Z Offset tables and restore levelling state
  674. if (!isPrinting()) {
  675. setAxisPosition_mm(1.0,Z);
  676. injectCommands_P(PSTR("M500"));
  677. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  678. }
  679. break;
  680. case 'G': // Get current offset
  681. SendtoTFT(PSTR("A31V "));
  682. // When printing use the live z Offset position
  683. // we will use babystepping to move the print head
  684. if (isPrinting())
  685. TFTSer.println(live_Zoffset);
  686. else {
  687. TFTSer.println(getZOffset_mm());
  688. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  689. }
  690. break;
  691. case 'S': { // Set offset (adjusts all points by value)
  692. float Zshift = atof(&panel_command[4]);
  693. setSoftEndstopState(false); // disable endstops
  694. // Allow temporary Z position nudging during print
  695. // From the levelling panel use the all points UI to adjust the print pos.
  696. if (isPrinting()) {
  697. #if ACDEBUG(AC_INFO)
  698. SERIAL_ECHOLNPAIR("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift);
  699. #endif
  700. if (isAxisPositionKnown(Z)) {
  701. #if ACDEBUG(AC_INFO)
  702. const float currZpos = getAxisPosition_mm(Z);
  703. SERIAL_ECHOLNPAIR("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
  704. #endif
  705. // Use babystepping to adjust the head position
  706. int16_t steps = mmToWholeSteps(constrain(Zshift,-0.05,0.05), Z);
  707. #if ACDEBUG(AC_INFO)
  708. SERIAL_ECHOLNPAIR("Steps to move Z: ", steps);
  709. #endif
  710. babystepAxis_steps(steps, Z);
  711. live_Zoffset += Zshift;
  712. }
  713. SendtoTFT(PSTR("A31V "));
  714. TFTSer.println(live_Zoffset);
  715. }
  716. else {
  717. GRID_LOOP(x, y) {
  718. const xy_uint8_t pos { x, y };
  719. const float currval = getMeshPoint(pos);
  720. setMeshPoint(pos, constrain(currval + Zshift, AC_LOWEST_MESHPOINT_VAL, 2));
  721. }
  722. const float currZOffset = getZOffset_mm();
  723. #if ACDEBUG(AC_INFO)
  724. SERIAL_ECHOLNPAIR("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift);
  725. #endif
  726. setZOffset_mm(currZOffset + Zshift);
  727. SendtoTFT(PSTR("A31V "));
  728. TFTSer.println(getZOffset_mm());
  729. if (isAxisPositionKnown(Z)) {
  730. // Move Z axis
  731. const float currZpos = getAxisPosition_mm(Z);
  732. #if ACDEBUG(AC_INFO)
  733. SERIAL_ECHOLNPAIR("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
  734. #endif
  735. setAxisPosition_mm(currZpos+constrain(Zshift,-0.05,0.05),Z);
  736. }
  737. }
  738. } break;
  739. } // end switch
  740. } break;
  741. case 32: { // A32 clean leveling beep flag
  742. // Ignore request if printing
  743. //if (isPrinting()) break;
  744. //injectCommands_P(PSTR("M500\nM420 S1\nG1 Z10 F240\nG1 X0 Y0 F6000"));
  745. //TFTSer.println("");
  746. } break;
  747. // A33 firmware info request seet PanelInfo()
  748. case 34: { // A34 Adjust single mesh point A34 C/S X1 Y1 V123
  749. if (panel_command[3] == 'C') { // Restore original offsets
  750. injectCommands_P(PSTR("M501\nM420 S1"));
  751. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  752. //printer_state = AC_printer_idle;
  753. }
  754. else {
  755. xy_uint8_t pos;
  756. pos.x = atoi(&panel_command[5]);
  757. pos.y = atoi(&panel_command[8]);
  758. float currmesh = getMeshPoint(pos);
  759. float newval = atof(&panel_command[11])/100;
  760. #if ACDEBUG(AC_INFO)
  761. SERIAL_ECHOLNPAIR("Change mesh point x:", pos.x, " y:", pos.y);
  762. SERIAL_ECHOLNPAIR("from ", currmesh, " to ", newval);
  763. #endif
  764. // Update Meshpoint
  765. setMeshPoint(pos,newval);
  766. if (printer_state == AC_printer_idle || printer_state == AC_printer_probing /*!isPrinting()*/) {
  767. // if we are at the current mesh point indicated on the panel Move Z pos +/- 0.05mm
  768. // (The panel changes the mesh value by +/- 0.05mm on each button press)
  769. if (selectedmeshpoint.x == pos.x && selectedmeshpoint.y == pos.y) {
  770. setSoftEndstopState(false);
  771. float currZpos = getAxisPosition_mm(Z);
  772. #if ACDEBUG(AC_INFO)
  773. SERIAL_ECHOLNPAIR("Move Z pos from ", currZpos, " to ", currZpos + constrain(newval - currmesh, -0.05, 0.05));
  774. #endif
  775. setAxisPosition_mm(currZpos + constrain(newval - currmesh, -0.05, 0.05), Z);
  776. }
  777. }
  778. }
  779. } break;
  780. }
  781. }
  782. } // namespace
  783. #endif // ANYCUBIC_LCD_CHIRON