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

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