My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

chiron_tft.cpp 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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_P(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(PGM_P error,PGM_P 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(CUSTOM_MACHINE_NAME), MARLIN_msg_ready) == 0) {
  215. injectCommands_P(PSTR("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_P(PSTR("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(PGM_P str) { // A helper to print PROGMEM string to the panel
  280. #if ACDEBUG(AC_SOME)
  281. SERIAL_ECHOPGM_P(str);
  282. #endif
  283. while (const char c = pgm_read_byte(str++)) TFTSer.write(c);
  284. }
  285. void ChironTFT::SendtoTFTLN(PGM_P str = nullptr) {
  286. if (str) {
  287. #if ACDEBUG(AC_SOME)
  288. SERIAL_ECHOPGM("> ");
  289. #endif
  290. SendtoTFT(str);
  291. #if ACDEBUG(AC_SOME)
  292. SERIAL_EOL();
  293. #endif
  294. }
  295. TFTSer.println();
  296. }
  297. bool ChironTFT::ReadTFTCommand() {
  298. bool command_ready = false;
  299. while (TFTSer.available() > 0 && command_len < MAX_CMND_LEN) {
  300. panel_command[command_len] = TFTSer.read();
  301. if (panel_command[command_len] == '\n') {
  302. command_ready = true;
  303. break;
  304. }
  305. command_len++;
  306. }
  307. if (command_ready || command_len == MAX_CMND_LEN) {
  308. panel_command[command_len] = '\0';
  309. #if ACDEBUG(AC_ALL)
  310. SERIAL_ECHOLNPGM("len(",command_len,") < ", panel_command);
  311. #endif
  312. command_ready = true;
  313. }
  314. return command_ready;
  315. }
  316. int8_t ChironTFT::FindToken(char c) {
  317. int8_t pos = 0;
  318. do {
  319. if (panel_command[pos] == c) {
  320. #if ACDEBUG(AC_INFO)
  321. SERIAL_ECHOLNPGM("Tpos:", pos, " ", c);
  322. #endif
  323. return pos;
  324. }
  325. } while(++pos < command_len);
  326. #if ACDEBUG(AC_INFO)
  327. SERIAL_ECHOLNPGM("Not found: ", c);
  328. #endif
  329. return -1;
  330. }
  331. void ChironTFT::CheckHeaters() {
  332. uint8_t faultDuration = 0;
  333. // if the hotend temp is abnormal, confirm state before signalling panel
  334. celsius_float_t temp = getActualTemp_celsius(E0);
  335. while (!WITHIN(temp, HEATER_0_MINTEMP, HEATER_0_MAXTEMP)) {
  336. faultDuration++;
  337. if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) {
  338. SendtoTFTLN(AC_msg_nozzle_temp_abnormal);
  339. last_error = AC_error_abnormal_temp_t0;
  340. SERIAL_ECHOLNPGM("Extruder temp abnormal! : ", temp);
  341. break;
  342. }
  343. delay_ms(500);
  344. temp = getActualTemp_celsius(E0);
  345. }
  346. // If the hotbed temp is abnormal, confirm state before signaling panel
  347. faultDuration = 0;
  348. temp = getActualTemp_celsius(BED);
  349. while (!WITHIN(temp, BED_MINTEMP, BED_MAXTEMP)) {
  350. faultDuration++;
  351. if (faultDuration >= AC_HEATER_FAULT_VALIDATION_TIME) {
  352. SendtoTFTLN(AC_msg_nozzle_temp_abnormal);
  353. last_error = AC_error_abnormal_temp_bed;
  354. SERIAL_ECHOLNPGM("Bed temp abnormal! : ", temp);
  355. break;
  356. }
  357. delay_ms(500);
  358. temp = getActualTemp_celsius(E0);
  359. }
  360. // Update panel with hotend heater status
  361. if (hotend_state != AC_heater_temp_reached) {
  362. if (WITHIN(getActualTemp_celsius(E0) - getTargetTemp_celsius(E0), -(TEMP_WINDOW), TEMP_WINDOW)) {
  363. SendtoTFTLN(AC_msg_nozzle_heating_done);
  364. hotend_state = AC_heater_temp_reached;
  365. }
  366. }
  367. // Update panel with bed heater status
  368. if (hotbed_state != AC_heater_temp_reached) {
  369. if (WITHIN(getActualTemp_celsius(BED) - getTargetTemp_celsius(BED), -(TEMP_BED_WINDOW), TEMP_BED_WINDOW)) {
  370. SendtoTFTLN(AC_msg_bed_heating_done);
  371. hotbed_state = AC_heater_temp_reached;
  372. }
  373. }
  374. }
  375. void ChironTFT::SendFileList(int8_t startindex) {
  376. // Respond to panel request for 4 files starting at index
  377. #if ACDEBUG(AC_INFO)
  378. SERIAL_ECHOLNPGM("## SendFileList ## ", startindex);
  379. #endif
  380. SendtoTFTLN(PSTR("FN "));
  381. filenavigator.getFiles(startindex, panel_type, 4);
  382. SendtoTFTLN(PSTR("END"));
  383. }
  384. void ChironTFT::SelectFile() {
  385. if (panel_type == AC_panel_new) {
  386. strncpy(selectedfile, panel_command + 4, command_len - 3);
  387. selectedfile[command_len - 4] = '\0';
  388. }
  389. else {
  390. strncpy(selectedfile, panel_command + 4, command_len - 4);
  391. selectedfile[command_len - 5] = '\0';
  392. }
  393. #if ACDEBUG(AC_FILE)
  394. SERIAL_ECHOLNPGM(" Selected File: ",selectedfile);
  395. #endif
  396. switch (selectedfile[0]) {
  397. case '/': // Valid file selected
  398. SendtoTFTLN(AC_msg_sd_file_open_success);
  399. break;
  400. case '<': // .. (go up folder level)
  401. filenavigator.upDIR();
  402. SendtoTFTLN(AC_msg_sd_file_open_failed);
  403. SendFileList( 0 );
  404. break;
  405. default: // enter sub folder
  406. // for new panel remove the '.GCO' tag that was added to the end of the path
  407. if (panel_type == AC_panel_new)
  408. selectedfile[strlen(selectedfile) - 4] = '\0';
  409. filenavigator.changeDIR(selectedfile);
  410. SendtoTFTLN(AC_msg_sd_file_open_failed);
  411. SendFileList( 0 );
  412. break;
  413. }
  414. }
  415. void ChironTFT::ProcessPanelRequest() {
  416. // Break these up into logical blocks // as its easier to navigate than one huge switch case!
  417. int8_t tpos = FindToken('A');
  418. // Panel request are 'A0' - 'A36'
  419. if (tpos != -1) {
  420. const int8_t req = atoi(&panel_command[tpos+1]);
  421. // Information requests A0 - A8 and A33
  422. if (req <= 8 || req == 33) PanelInfo(req);
  423. // Simple Actions A9 - A28
  424. else if (req <= 28) PanelAction(req);
  425. // Process Initiation
  426. else if (req <= 36) PanelProcess(req);
  427. }
  428. else {
  429. #if AUTO_DETECT_CHIRON_TFT
  430. // This may be a response to a panel type detection query
  431. if (panel_type == AC_panel_unknown) {
  432. tpos = FindToken('S'); // old panel will respond to 'SIZE' with 'SXY 480 320'
  433. if (tpos != -1) {
  434. if (panel_command[tpos+1]== 'X' && panel_command[tpos+2]=='Y') {
  435. panel_type = AC_panel_standard;
  436. SERIAL_ECHOLNF(AC_msg_old_panel_detected);
  437. }
  438. }
  439. else {
  440. tpos = FindToken('['); // new panel will respond to 'J200' with '[0]=0'
  441. if (tpos != -1) {
  442. if (panel_command[tpos+1]== '0' && panel_command[tpos+2]==']') {
  443. panel_type = AC_panel_new;
  444. SERIAL_ECHOLNF(AC_msg_new_panel_detected);
  445. }
  446. }
  447. }
  448. return;
  449. }
  450. #endif
  451. SendtoTFTLN(); // Ignore unknown requests
  452. }
  453. }
  454. void ChironTFT::PanelInfo(uint8_t req) {
  455. // information requests A0-A8 and A33
  456. switch (req) {
  457. case 0: // A0 Get HOTEND Temp
  458. SendtoTFT(PSTR("A0V "));
  459. TFTSer.println(getActualTemp_celsius(E0));
  460. break;
  461. case 1: // A1 Get HOTEND Target Temp
  462. SendtoTFT(PSTR("A1V "));
  463. TFTSer.println(getTargetTemp_celsius(E0));
  464. break;
  465. case 2: // A2 Get BED Temp
  466. SendtoTFT(PSTR("A2V "));
  467. TFTSer.println(getActualTemp_celsius(BED));
  468. break;
  469. case 3: // A3 Get BED Target Temp
  470. SendtoTFT(PSTR("A3V "));
  471. TFTSer.println(getTargetTemp_celsius(BED));
  472. break;
  473. case 4: // A4 Get FAN Speed
  474. SendtoTFT(PSTR("A4V "));
  475. TFTSer.println(getActualFan_percent(FAN0));
  476. break;
  477. case 5: // A5 Get Current Coordinates
  478. SendtoTFT(PSTR("A5V X: "));
  479. TFTSer.print(getAxisPosition_mm(X));
  480. SendtoTFT(PSTR(" Y: "));
  481. TFTSer.print(getAxisPosition_mm(Y));
  482. SendtoTFT(PSTR(" Z: "));
  483. TFTSer.println(getAxisPosition_mm(Z));
  484. break;
  485. case 6: // A6 Get printing progress
  486. if (isPrintingFromMedia()) {
  487. SendtoTFT(PSTR("A6V "));
  488. TFTSer.println(ui8tostr2(getProgress_percent()));
  489. }
  490. else
  491. SendtoTFTLN(PSTR("A6V ---"));
  492. break;
  493. case 7: { // A7 Get Printing Time
  494. uint32_t time = getProgress_seconds_elapsed() / 60;
  495. SendtoTFT(PSTR("A7V "));
  496. TFTSer.print(ui8tostr2(time / 60));
  497. SendtoTFT(PSTR(" H "));
  498. TFTSer.print(ui8tostr2(time % 60));
  499. SendtoTFT(PSTR(" M"));
  500. #if ACDEBUG(AC_ALL)
  501. SERIAL_ECHOLNPGM("Print time ", ui8tostr2(time / 60), ":", ui8tostr2(time % 60));
  502. #endif
  503. } break;
  504. case 8: // A8 Get SD Card list A8 S0
  505. if (!isMediaInserted()) safe_delay(500);
  506. if (!isMediaInserted()) // Make sure the card is removed
  507. SendtoTFTLN(AC_msg_no_sd_card);
  508. else if (panel_command[3] == 'S')
  509. SendFileList( atoi( &panel_command[4] ) );
  510. break;
  511. case 33: // A33 Get firmware info
  512. SendtoTFT(PSTR("J33 "));
  513. // If there is an error recorded, show that instead of the FW version
  514. if (!GetLastError()) SendtoTFTLN(PSTR(SHORT_BUILD_VERSION));
  515. break;
  516. }
  517. }
  518. void ChironTFT::PanelAction(uint8_t req) {
  519. switch (req) {
  520. case 9: // A9 Pause SD print
  521. if (isPrintingFromMedia()) {
  522. SendtoTFTLN(AC_msg_pause);
  523. pausePrint();
  524. printer_state = AC_printer_pausing;
  525. }
  526. else
  527. SendtoTFTLN(AC_msg_stop);
  528. break;
  529. case 10: // A10 Resume SD Print
  530. if (pause_state == AC_paused_idle || printer_state == AC_printer_resuming_from_power_outage)
  531. resumePrint();
  532. else
  533. setUserConfirmed();
  534. break;
  535. case 11: // A11 Stop SD print
  536. if (isPrintingFromMedia()) {
  537. printer_state = AC_printer_stopping;
  538. stopPrint();
  539. }
  540. else {
  541. if (printer_state == AC_printer_resuming_from_power_outage)
  542. injectCommands_P(PSTR("M1000 C")); // Cancel recovery
  543. SendtoTFTLN(AC_msg_stop);
  544. printer_state = AC_printer_idle;
  545. }
  546. break;
  547. case 12: // A12 Kill printer
  548. kill(); // from marlincore.h
  549. break;
  550. case 13: // A13 Select file
  551. SelectFile();
  552. break;
  553. case 14: { // A14 Start Printing
  554. // Allows printer to restart the job if we don't want to recover
  555. if (printer_state == AC_printer_resuming_from_power_outage) {
  556. injectCommands_P(PSTR("M1000 C")); // Cancel recovery
  557. printer_state = AC_printer_idle;
  558. }
  559. #if ACDebugLevel >= 1
  560. SERIAL_ECHOLNPAIR_F("Print: ", selectedfile);
  561. #endif
  562. printFile(selectedfile);
  563. SendtoTFTLN(AC_msg_print_from_sd_card);
  564. } break;
  565. case 15: // A15 Resuming from outage
  566. if (printer_state == AC_printer_resuming_from_power_outage) {
  567. // Need to home here to restore the Z position
  568. injectCommands_P(AC_cmnd_power_loss_recovery);
  569. injectCommands_P(PSTR("M1000")); // home and start recovery
  570. }
  571. break;
  572. case 16: { // A16 Set HotEnd temp A17 S170
  573. const float set_Htemp = atof(&panel_command[5]);
  574. hotend_state = set_Htemp ? AC_heater_temp_set : AC_heater_off;
  575. switch ((char)panel_command[4]) {
  576. // Set Temp
  577. case 'S': case 'C': setTargetTemp_celsius(set_Htemp, E0);
  578. }
  579. } break;
  580. case 17: { // A17 Set bed temp
  581. const float set_Btemp = atof(&panel_command[5]);
  582. hotbed_state = set_Btemp ? AC_heater_temp_set : AC_heater_off;
  583. if (panel_command[4] == 'S')
  584. setTargetTemp_celsius(set_Btemp, BED);
  585. } break;
  586. case 18: // A18 Set Fan Speed
  587. if (panel_command[4] == 'S')
  588. setTargetFan_percent(atof(&panel_command[5]), FAN0);
  589. break;
  590. case 19: // A19 Motors off
  591. if (!isPrinting()) {
  592. stepper.disable_all_steppers();
  593. SendtoTFTLN(AC_msg_ready);
  594. }
  595. break;
  596. case 20: // A20 Read/write print speed
  597. if (panel_command[4] == 'S')
  598. setFeedrate_percent(atoi(&panel_command[5]));
  599. else {
  600. SendtoTFT(PSTR("A20V "));
  601. TFTSer.println(getFeedrate_percent());
  602. }
  603. break;
  604. case 21: // A21 Home Axis A21 X
  605. if (!isPrinting()) {
  606. switch ((char)panel_command[4]) {
  607. case 'X': injectCommands_P(PSTR("G28X")); break;
  608. case 'Y': injectCommands_P(PSTR("G28Y")); break;
  609. case 'Z': injectCommands_P(PSTR("G28Z")); break;
  610. case 'C': injectCommands_P(G28_STR); break;
  611. }
  612. }
  613. break;
  614. case 22: { // A22 Move Axis
  615. // The commands have changed on the new panel
  616. // Old TFT A22 X -1F1500 A22 X +1F1500
  617. // New TFT A22 X-1.0 F1500 A22 X1.0 F1500
  618. // lets just wrap this in a gcode relative nonprint move and let the controller deal with it
  619. // G91 G0 <panel command> G90
  620. if (!isPrinting()) { // Ignore request if printing
  621. char MoveCmnd[30];
  622. sprintf_P(MoveCmnd, PSTR("G91\nG0%s\nG90"), panel_command + 3);
  623. #if ACDEBUG(AC_ACTION)
  624. SERIAL_ECHOLNPGM("Move: ", MoveCmnd);
  625. #endif
  626. setSoftEndstopState(true); // enable endstops
  627. injectCommands(MoveCmnd);
  628. }
  629. } break;
  630. case 23: // A23 Preheat PLA
  631. // Ignore request if printing
  632. if (!isPrinting()) {
  633. // Temps defined in configuration.h
  634. setTargetTemp_celsius(PREHEAT_1_TEMP_BED, BED);
  635. setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, E0);
  636. SendtoTFTLN();
  637. hotbed_state = AC_heater_temp_set;
  638. hotend_state = AC_heater_temp_set;
  639. }
  640. break;
  641. case 24: // A24 Preheat ABS
  642. // Ignore request if printing
  643. if (!isPrinting()) {
  644. setTargetTemp_celsius(PREHEAT_2_TEMP_BED, BED);
  645. setTargetTemp_celsius(PREHEAT_2_TEMP_HOTEND, E0);
  646. SendtoTFTLN();
  647. hotbed_state = AC_heater_temp_set;
  648. hotend_state = AC_heater_temp_set;
  649. }
  650. break;
  651. case 25: // A25 Cool Down
  652. // Ignore request if printing
  653. if (!isPrinting()) {
  654. setTargetTemp_celsius(0, E0);
  655. setTargetTemp_celsius(0, BED);
  656. SendtoTFTLN(AC_msg_ready);
  657. hotbed_state = AC_heater_off;
  658. hotend_state = AC_heater_off;
  659. }
  660. break;
  661. case 26: // A26 Refresh SD
  662. if (card.isMounted())card.release();
  663. card.mount();
  664. safe_delay(500);
  665. filenavigator.reset();
  666. break;
  667. case 27: // A27 Servo Angles adjust
  668. break;
  669. case 28: // A28 Filament set A28 O/C
  670. // Ignore request if printing
  671. if (isPrinting()) break;
  672. SendtoTFTLN();
  673. break;
  674. }
  675. }
  676. void ChironTFT::PanelProcess(uint8_t req) {
  677. switch (req) {
  678. case 29: { // A29 Read Mesh Point A29 X1 Y1
  679. xy_uint8_t pos;
  680. float pos_z;
  681. pos.x = atoi(&panel_command[FindToken('X')+1]);
  682. pos.y = atoi(&panel_command[FindToken('Y')+1]);
  683. pos_z = getMeshPoint(pos);
  684. SendtoTFT(PSTR("A29V "));
  685. TFTSer.println(pos_z * 100);
  686. if (!isPrinting()) {
  687. setSoftEndstopState(true); // disable endstops
  688. // If the same meshpoint is selected twice in a row, move the head to that ready for adjustment
  689. if ((selectedmeshpoint.x == pos.x) && (selectedmeshpoint.y == pos.y)) {
  690. if (!isPositionKnown())
  691. injectCommands_P(G28_STR); // home
  692. if (isPositionKnown()) {
  693. #if ACDEBUG(AC_INFO)
  694. SERIAL_ECHOLNPGM("Moving to mesh point at x: ", pos.x, " y: ", pos.y, " z: ", pos_z);
  695. #endif
  696. // Go up before moving
  697. setAxisPosition_mm(3.0,Z);
  698. setAxisPosition_mm(17 + (93 * pos.x), X);
  699. setAxisPosition_mm(20 + (93 * pos.y), Y);
  700. setAxisPosition_mm(0.0, Z);
  701. #if ACDEBUG(AC_INFO)
  702. SERIAL_ECHOLNPGM("Current Z: ", getAxisPosition_mm(Z));
  703. #endif
  704. }
  705. }
  706. selectedmeshpoint.x = pos.x;
  707. selectedmeshpoint.y = pos.y;
  708. }
  709. } break;
  710. case 30: { // A30 Auto leveling
  711. if (FindToken('S') != -1) { // Start probing New panel adds spaces..
  712. // Ignore request if printing
  713. if (isPrinting())
  714. SendtoTFTLN(AC_msg_probing_not_allowed); // forbid auto leveling
  715. else {
  716. SendtoTFTLN(AC_msg_start_probing);
  717. injectCommands_P(PSTR("G28\nG29"));
  718. printer_state = AC_printer_probing;
  719. }
  720. }
  721. else {
  722. SendtoTFTLN(AC_msg_start_probing); // Just enter levelling menu
  723. }
  724. } break;
  725. case 31: { // A31 Adjust all Probe Points
  726. // The tokens can occur in different places on the new panel so we need to find it.
  727. if (FindToken('C') != -1) { // Restore and apply original offsets
  728. if (!isPrinting()) {
  729. injectCommands_P(PSTR("M501\nM420 S1"));
  730. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  731. SERIAL_ECHOLNF(AC_msg_mesh_changes_abandoned);
  732. }
  733. }
  734. else if (FindToken('D') != -1) { // Save Z Offset tables and restore leveling state
  735. if (!isPrinting()) {
  736. setAxisPosition_mm(1.0,Z); // Lift nozzle before any further movements are made
  737. injectCommands_P(PSTR("M500"));
  738. SERIAL_ECHOLNF(AC_msg_mesh_changes_saved);
  739. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  740. }
  741. }
  742. else if (FindToken('G') != -1) { // Get current offset
  743. SendtoTFT(PSTR("A31V "));
  744. // When printing use the live z Offset position
  745. // we will use babystepping to move the print head
  746. if (isPrinting())
  747. TFTSer.println(live_Zoffset);
  748. else {
  749. TFTSer.println(getZOffset_mm());
  750. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  751. }
  752. }
  753. else {
  754. int8_t tokenpos = FindToken('S');
  755. if (tokenpos != -1) { // Set offset (adjusts all points by value)
  756. float Zshift = atof(&panel_command[tokenpos+1]);
  757. setSoftEndstopState(false); // disable endstops
  758. // Allow temporary Z position nudging during print
  759. // From the leveling panel use the all points UI to adjust the print pos.
  760. if (isPrinting()) {
  761. #if ACDEBUG(AC_INFO)
  762. SERIAL_ECHOLNPGM("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift);
  763. #endif
  764. if (isAxisPositionKnown(Z)) {
  765. #if ACDEBUG(AC_INFO)
  766. const float currZpos = getAxisPosition_mm(Z);
  767. SERIAL_ECHOLNPGM("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
  768. #endif
  769. // Use babystepping to adjust the head position
  770. int16_t steps = mmToWholeSteps(constrain(Zshift,-0.05,0.05), Z);
  771. #if ACDEBUG(AC_INFO)
  772. SERIAL_ECHOLNPGM("Steps to move Z: ", steps);
  773. #endif
  774. babystepAxis_steps(steps, Z);
  775. live_Zoffset += Zshift;
  776. }
  777. SendtoTFT(PSTR("A31V "));
  778. TFTSer.println(live_Zoffset);
  779. }
  780. else {
  781. GRID_LOOP(x, y) {
  782. const xy_uint8_t pos { x, y };
  783. const float currval = getMeshPoint(pos);
  784. setMeshPoint(pos, constrain(currval + Zshift, AC_LOWEST_MESHPOINT_VAL, 2));
  785. #if ACDEBUG(AC_INFO)
  786. SERIAL_ECHOLNPGM("Change mesh point X", x," Y",y ," from ", currval, " to ", getMeshPoint(pos) );
  787. #endif
  788. }
  789. const float currZOffset = getZOffset_mm();
  790. #if ACDEBUG(AC_INFO)
  791. SERIAL_ECHOLNPGM("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift);
  792. #endif
  793. setZOffset_mm(currZOffset + Zshift);
  794. SendtoTFT(PSTR("A31V "));
  795. TFTSer.println(getZOffset_mm());
  796. if (isAxisPositionKnown(Z)) {
  797. // Move Z axis
  798. const float currZpos = getAxisPosition_mm(Z);
  799. #if ACDEBUG(AC_INFO)
  800. SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05));
  801. #endif
  802. setAxisPosition_mm(currZpos+constrain(Zshift,-0.05,0.05),Z);
  803. }
  804. }
  805. }
  806. }
  807. } break;
  808. case 32: { // A32 clean leveling beep flag
  809. // Ignore request if printing
  810. //if (isPrinting()) break;
  811. //injectCommands_P(PSTR("M500\nM420 S1\nG1 Z10 F240\nG1 X0 Y0 F6000"));
  812. //TFTSer.println();
  813. } break;
  814. // A33 firmware info request see PanelInfo()
  815. case 34: { // A34 Adjust single mesh point A34 C/S X1 Y1 V123
  816. if (panel_command[3] == 'C') { // Restore original offsets
  817. injectCommands_P(PSTR("M501\nM420 S1"));
  818. selectedmeshpoint.x = selectedmeshpoint.y = 99;
  819. //printer_state = AC_printer_idle;
  820. }
  821. else {
  822. xy_uint8_t pos;
  823. pos.x = atoi(&panel_command[5]);
  824. pos.y = atoi(&panel_command[8]);
  825. float currmesh = getMeshPoint(pos);
  826. float newval = atof(&panel_command[11])/100;
  827. #if ACDEBUG(AC_INFO)
  828. SERIAL_ECHOLNPGM("Change mesh point x:", pos.x, " y:", pos.y);
  829. SERIAL_ECHOLNPGM("from ", currmesh, " to ", newval);
  830. #endif
  831. // Update Meshpoint
  832. setMeshPoint(pos,newval);
  833. if (printer_state == AC_printer_idle || printer_state == AC_printer_probing /*!isPrinting()*/) {
  834. // if we are at the current mesh point indicated on the panel Move Z pos +/- 0.05mm
  835. // (The panel changes the mesh value by +/- 0.05mm on each button press)
  836. if (selectedmeshpoint.x == pos.x && selectedmeshpoint.y == pos.y) {
  837. setSoftEndstopState(false);
  838. float currZpos = getAxisPosition_mm(Z);
  839. #if ACDEBUG(AC_INFO)
  840. SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(newval - currmesh, -0.05, 0.05));
  841. #endif
  842. setAxisPosition_mm(currZpos + constrain(newval - currmesh, -0.05, 0.05), Z);
  843. }
  844. }
  845. }
  846. } break;
  847. case 36: // A36 Auto leveling for new TFT bet that was a typo in the panel code!
  848. SendtoTFTLN(AC_msg_start_probing);
  849. break;
  850. }
  851. }
  852. bool ChironTFT::GetLastError() {
  853. switch (last_error) {
  854. case AC_error_abnormal_temp_bed: SendtoTFTLN(AC_msg_error_bed_temp); break;
  855. case AC_error_abnormal_temp_t0: SendtoTFTLN(AC_msg_error_hotend_temp); break;
  856. case AC_error_noSD: SendtoTFTLN(AC_msg_error_sd_card); break;
  857. case AC_error_powerloss: SendtoTFTLN(AC_msg_power_loss); break;
  858. case AC_error_EEPROM: SendtoTFTLN(AC_msg_eeprom_version); break;
  859. case AC_error_filament_runout: SendtoTFTLN(AC_msg_filament_out); break;
  860. default: return false;
  861. }
  862. last_error = AC_error_none;
  863. return true;
  864. }
  865. } // Anycubic namespace
  866. #endif // ANYCUBIC_LCD_CHIRON