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

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