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 28KB

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