From 85c32a2bb628cd86b067ba5cf4c24bc5c05617d3 Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Wed, 6 Mar 2019 22:59:46 +0100 Subject: [PATCH 1/7] Fix Z movement on abort - Referencing #29 - Adding audio feedback to special menu M500 and M502 --- Marlin/AnycubicTFT.cpp | 45 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/Marlin/AnycubicTFT.cpp b/Marlin/AnycubicTFT.cpp index 61dab2d..ac37ffb 100644 --- a/Marlin/AnycubicTFT.cpp +++ b/Marlin/AnycubicTFT.cpp @@ -222,37 +222,30 @@ void AnycubicTFTClass::PausePrint(){ } void AnycubicTFTClass::StopPrint(){ + #ifdef SDSUPPORT card.stopSDPrint(); #endif clear_command_queue(); - if((current_position[Z_AXIS]<150)) - { - enqueue_and_echo_commands_P(PSTR("G91")); - enqueue_and_echo_commands_P(PSTR("G1 Z20 F240")); - enqueue_and_echo_commands_P(PSTR("G90")); - } - else if ((current_position[Z_AXIS]<190)) - { - enqueue_and_echo_commands_P(PSTR("G91")); - enqueue_and_echo_commands_P(PSTR("G1 Z10 F240")); - enqueue_and_echo_commands_P(PSTR("G90")); - } - else if ((current_position[Z_AXIS]<200)) - { - enqueue_and_echo_commands_P(PSTR("G91")); - enqueue_and_echo_commands_P(PSTR("G1 Z5 F240")); - enqueue_and_echo_commands_P(PSTR("G90")); - } - else if ((current_position[Z_AXIS]>=200)) - { - enqueue_and_echo_commands_P(PSTR("G91")); - enqueue_and_echo_commands_P(PSTR("G1 Z1 F240")); - enqueue_and_echo_commands_P(PSTR("G90")); - } quickstop_stepper(); print_job_timer.stop(); thermalManager.disable_all_heaters(); + if((current_position[Z_AXIS]<150)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z20 F240\nG90")); + } + else if ((current_position[Z_AXIS]<190)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z10 F240\nG90")); + } + else if ((current_position[Z_AXIS]<200)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z5 F240\nG90")); + } + else if ((current_position[Z_AXIS]>=200)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z1 F240\G90")); + } #if FAN_COUNT > 0 for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0; #endif @@ -303,10 +296,10 @@ void AnycubicTFTClass::HandleSpecialMenu() enqueue_and_echo_commands_P(PSTR("M303 E-1 S60 C6 U1")); } else if (strcmp(SelectedDirectory, "")==0) { SERIAL_PROTOCOLLNPGM("Special Menu: Save EEPROM"); - enqueue_and_echo_commands_P(PSTR("M500")); + enqueue_and_echo_commands_P(PSTR("M500\nM300 S1108 P105\nM300 S1661 P210")); } else if (strcmp(SelectedDirectory, "")==0) { SERIAL_PROTOCOLLNPGM("Special Menu: Load FW Defaults"); - enqueue_and_echo_commands_P(PSTR("M502")); + enqueue_and_echo_commands_P(PSTR("M502\nM300 S1661 P105\nM300 S1108 P210")); } else if (strcmp(SelectedDirectory, "")==0) { SERIAL_PROTOCOLLNPGM("Special Menu: Preheat Bed"); enqueue_and_echo_commands_P(PSTR("M140 S60")); From 90e27ff21b8f448c13b65ec3564a14670101dd5c Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Fri, 8 Mar 2019 01:25:21 +0100 Subject: [PATCH 2/7] Fix indentation Improve readability and fix #ifdef and #endif indentations --- Marlin/AnycubicTFT.cpp | 2168 ++++++++++++++++++++-------------------- 1 file changed, 1084 insertions(+), 1084 deletions(-) diff --git a/Marlin/AnycubicTFT.cpp b/Marlin/AnycubicTFT.cpp index ac37ffb..de5401a 100644 --- a/Marlin/AnycubicTFT.cpp +++ b/Marlin/AnycubicTFT.cpp @@ -1,21 +1,21 @@ /* - AnycubicTFT.cpp --- Support for Anycubic i3 Mega TFT - Created by Christian Hopp on 09.12.17. + AnycubicTFT.cpp --- Support for Anycubic i3 Mega TFT + Created by Christian Hopp on 09.12.17. - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ #include @@ -42,42 +42,42 @@ char _conv[8]; char *itostr2(const uint8_t &x) { - //sprintf(conv,"%5.1f",x); - int xx=x; - _conv[0]=(xx/10)%10+'0'; - _conv[1]=(xx)%10+'0'; - _conv[2]=0; - return _conv; + //sprintf(conv,"%5.1f",x); + int xx=x; + _conv[0]=(xx/10)%10+'0'; + _conv[1]=(xx)%10+'0'; + _conv[2]=0; + return _conv; } #ifndef ULTRA_LCD -#define DIGIT(n) ('0' + (n)) -#define DIGIMOD(n, f) DIGIT((n)/(f) % 10) -#define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ') -#define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-')) + #define DIGIT(n) ('0' + (n)) + #define DIGIMOD(n, f) DIGIT((n)/(f) % 10) + #define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ') + #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-')) -char* itostr3(const int x) { - int xx = x; - _conv[4] = MINUSOR(xx, RJDIGIT(xx, 100)); - _conv[5] = RJDIGIT(xx, 10); - _conv[6] = DIGIMOD(xx, 1); - return &_conv[4]; -} + char* itostr3(const int x) { + int xx = x; + _conv[4] = MINUSOR(xx, RJDIGIT(xx, 100)); + _conv[5] = RJDIGIT(xx, 10); + _conv[6] = DIGIMOD(xx, 1); + return &_conv[4]; + } -// Convert signed float to fixed-length string with 023.45 / -23.45 format + // Convert signed float to fixed-length string with 023.45 / -23.45 format -char *ftostr32(const float &x) { - long xx = x * 100; - _conv[1] = MINUSOR(xx, DIGIMOD(xx, 10000)); - _conv[2] = DIGIMOD(xx, 1000); - _conv[3] = DIGIMOD(xx, 100); - _conv[4] = '.'; - _conv[5] = DIGIMOD(xx, 10); - _conv[6] = DIGIMOD(xx, 1); - return &_conv[1]; -} + char *ftostr32(const float &x) { + long xx = x * 100; + _conv[1] = MINUSOR(xx, DIGIMOD(xx, 10000)); + _conv[2] = DIGIMOD(xx, 1000); + _conv[3] = DIGIMOD(xx, 100); + _conv[4] = '.'; + _conv[5] = DIGIMOD(xx, 10); + _conv[6] = DIGIMOD(xx, 1); + return &_conv[1]; + } #endif @@ -85,1160 +85,1160 @@ AnycubicTFTClass::AnycubicTFTClass() { } void AnycubicTFTClass::Setup() { - AnycubicSerial.begin(115200); - //ANYCUBIC_SERIAL_START(); - ANYCUBIC_SERIAL_PROTOCOLPGM("J17"); // J17 Main board reset - ANYCUBIC_SERIAL_ENTER(); - delay(10); - ANYCUBIC_SERIAL_PROTOCOLPGM("J12"); // J12 Ready - ANYCUBIC_SERIAL_ENTER(); + AnycubicSerial.begin(115200); + //ANYCUBIC_SERIAL_START(); + ANYCUBIC_SERIAL_PROTOCOLPGM("J17"); // J17 Main board reset + ANYCUBIC_SERIAL_ENTER(); + delay(10); + ANYCUBIC_SERIAL_PROTOCOLPGM("J12"); // J12 Ready + ANYCUBIC_SERIAL_ENTER(); -#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) - pinMode(SD_DETECT_PIN, INPUT); - WRITE(SD_DETECT_PIN, HIGH); -#endif + #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) + pinMode(SD_DETECT_PIN, INPUT); + WRITE(SD_DETECT_PIN, HIGH); + #endif -#if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR) - pinMode(FIL_RUNOUT_PIN,INPUT); - WRITE(FIL_RUNOUT_PIN,HIGH); - if(READ(FIL_RUNOUT_PIN)==true) - { - ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); -#endif - } -#endif + #if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR) + pinMode(FIL_RUNOUT_PIN,INPUT); + WRITE(FIL_RUNOUT_PIN,HIGH); + if(READ(FIL_RUNOUT_PIN)==true) + { + ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); + #endif + } + #endif - SelectedDirectory[0]=0; - SpecialMenu=false; + SelectedDirectory[0]=0; + SpecialMenu=false; } void AnycubicTFTClass::WriteOutageEEPromData() { - int pos=E2END-256; + int pos=E2END-256; } void AnycubicTFTClass::ReadOutageEEPromData() { - int pos=E2END-256; + int pos=E2END-256; } void AnycubicTFTClass::KillTFT() { - ANYCUBIC_SERIAL_PROTOCOLPGM("J11"); // J11 Kill - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Kill command... J11"); -#endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J11"); // J11 Kill + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Kill command... J11"); + #endif } void AnycubicTFTClass::StartPrint(){ - if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) { // resuming from SD pause - if((!PausedByRunout) && (!PausedByFilamentChange)) // was that a regular pause? - { - enqueue_and_echo_commands_P(PSTR("G91")); // relative mode - enqueue_and_echo_commands_P(PSTR("G1 Z-10 F240")); // lower nozzle again - enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode + if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) { // resuming from SD pause + if((!PausedByRunout) && (!PausedByFilamentChange)) // was that a regular pause? + { + enqueue_and_echo_commands_P(PSTR("G91")); // relative mode + enqueue_and_echo_commands_P(PSTR("G1 Z-10 F240")); // lower nozzle again + enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode - } - } - starttime=millis(); -#ifdef SDSUPPORT - if((!PausedByRunout) && (!PausedByFilamentChange)) // was that a regular pause? - { - card.startFileprint(); // start or resume regularly - } - else if((PausedByRunout) && (!PausedByFilamentChange)) // resuming from a pause that was caused by filament runout - { - enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle and resume -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: M24 Resume from Filament Runout"); -#endif - PausedByRunout=false; // clear flag -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag cleared"); -#endif - } - else if((!PausedByRunout) && (PausedByFilamentChange)) // was M600 called? - { - FilamentChangeResume(); // enter M108 routine -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Start M108 routine"); -#endif - PausedByFilamentChange=false; // clear flag -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Filament Change Flag cleared"); -#endif - } -#endif - TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; + } + } + starttime=millis(); + #ifdef SDSUPPORT + if((!PausedByRunout) && (!PausedByFilamentChange)) // was that a regular pause? + { + card.startFileprint(); // start or resume regularly + } + else if((PausedByRunout) && (!PausedByFilamentChange)) // resuming from a pause that was caused by filament runout + { + enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle and resume + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: M24 Resume from Filament Runout"); + #endif + PausedByRunout=false; // clear flag + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag cleared"); + #endif + } + else if((!PausedByRunout) && (PausedByFilamentChange)) // was M600 called? + { + FilamentChangeResume(); // enter M108 routine + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Start M108 routine"); + #endif + PausedByFilamentChange=false; // clear flag + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Filament Change Flag cleared"); + #endif + } + #endif + TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; } void AnycubicTFTClass::PausePrint(){ -#ifdef SDSUPPORT - if((!PausedByRunout)) // is this a regular pause? - { - card.pauseSDPrint(); // pause print regularly -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Regular Pause"); -#endif - } - else // pause caused by filament runout - { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Filament Runout Pause"); -#endif - enqueue_and_echo_commands_P(PSTR("M25")); // pause print and park nozzle -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: M25 sent, parking nozzle"); -#endif - ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 Show Filament Lack prompt on screen - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: J23 Show filament prompt"); -#endif - } -#endif - TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; -#ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR - if(FilamentTestStatus) { - ANYCUBIC_SERIAL_PROTOCOLPGM("J05");// J05 pausing - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused... J05"); -#endif - } else { - // Pause because of "out of filament" - ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 FILAMENT LACK with the prompt box don't disappear - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout while printing... J23"); -#endif - } -#endif + #ifdef SDSUPPORT + if((!PausedByRunout)) // is this a regular pause? + { + card.pauseSDPrint(); // pause print regularly + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Regular Pause"); + #endif + } + else // pause caused by filament runout + { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Filament Runout Pause"); + #endif + enqueue_and_echo_commands_P(PSTR("M25")); // pause print and park nozzle + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: M25 sent, parking nozzle"); + #endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 Show Filament Lack prompt on screen + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: J23 Show filament prompt"); + #endif + } + #endif + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; + #ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR + if(FilamentTestStatus) { + ANYCUBIC_SERIAL_PROTOCOLPGM("J05");// J05 pausing + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused... J05"); + #endif + } else { + // Pause because of "out of filament" + ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 FILAMENT LACK with the prompt box don't disappear + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout while printing... J23"); + #endif + } + #endif } void AnycubicTFTClass::StopPrint(){ -#ifdef SDSUPPORT - card.stopSDPrint(); -#endif - clear_command_queue(); - quickstop_stepper(); - print_job_timer.stop(); - thermalManager.disable_all_heaters(); - if((current_position[Z_AXIS]<150)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z20 F240\nG90")); - } - else if ((current_position[Z_AXIS]<190)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z10 F240\nG90")); - } - else if ((current_position[Z_AXIS]<200)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z5 F240\nG90")); - } - else if ((current_position[Z_AXIS]>=200)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z1 F240\G90")); - } - #if FAN_COUNT > 0 - for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0; + #ifdef SDSUPPORT + card.stopSDPrint(); #endif - TFTstate=ANYCUBIC_TFT_STATE_SDSTOP_REQ; + clear_command_queue(); + quickstop_stepper(); + print_job_timer.stop(); + thermalManager.disable_all_heaters(); + if((current_position[Z_AXIS]<150)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z20 F240\nG90")); + } + else if ((current_position[Z_AXIS]<190)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z10 F240\nG90")); + } + else if ((current_position[Z_AXIS]<200)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z5 F240\nG90")); + } + else if ((current_position[Z_AXIS]>=200)) + { + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z1 F240\G90")); + } + #if FAN_COUNT > 0 + for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0; + #endif + TFTstate=ANYCUBIC_TFT_STATE_SDSTOP_REQ; } void AnycubicTFTClass::FilamentChangeResume(){ - enqueue_and_echo_commands_P(PSTR("M108")); // call M108 to break out of M600 pause - HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e); // resume heating if timed out - wait_for_heatup = false; - wait_for_user = false; // remove waiting flags - card.startFileprint(); // resume with proper progress state -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: M108 Resume called"); -#endif + enqueue_and_echo_commands_P(PSTR("M108")); // call M108 to break out of M600 pause + HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e); // resume heating if timed out + wait_for_heatup = false; + wait_for_user = false; // remove waiting flags + card.startFileprint(); // resume with proper progress state + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: M108 Resume called"); + #endif } void AnycubicTFTClass::FilamentChangePause(){ - PausedByFilamentChange=true; - enqueue_and_echo_commands_P(PSTR("M600")); - TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; // set TFT state to paused -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: M600 Pause called"); -#endif + PausedByFilamentChange=true; + enqueue_and_echo_commands_P(PSTR("M600")); + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; // set TFT state to paused + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: M600 Pause called"); + #endif } float AnycubicTFTClass::CodeValue() { - return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], NULL)); + return (strtod(&TFTcmdbuffer[TFTbufindr][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindr] + 1], NULL)); } bool AnycubicTFTClass::CodeSeen(char code) { - TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code); - return (TFTstrchr_pointer != NULL); //Return True if a character was found + TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindr], code); + return (TFTstrchr_pointer != NULL); //Return True if a character was found } void AnycubicTFTClass::HandleSpecialMenu() { - if(strcmp(SelectedDirectory, "")==0) { - SpecialMenu=true; - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Auto Tune Hotend PID"); - enqueue_and_echo_commands_P(PSTR("M106 S204\nM303 E0 S210 C6 U1")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Auto Tune Hotbed Pid"); - enqueue_and_echo_commands_P(PSTR("M303 E-1 S60 C6 U1")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Save EEPROM"); - enqueue_and_echo_commands_P(PSTR("M500\nM300 S1108 P105\nM300 S1661 P210")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Load FW Defaults"); - enqueue_and_echo_commands_P(PSTR("M502\nM300 S1661 P105\nM300 S1108 P210")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Preheat Bed"); - enqueue_and_echo_commands_P(PSTR("M140 S60")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Start Mesh Leveling"); - enqueue_and_echo_commands_P(PSTR("G29 S1")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Next Mesh Point"); - enqueue_and_echo_commands_P(PSTR("G29 S2")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Z Up 0.1"); - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z+0.1\nG90")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Z Up 0.02"); - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z+0.02\nG90")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Z Down 0.02"); - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z-0.02\nG90")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: Z Down 0.1"); - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z-0.1\nG90")); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: FilamentChange Pause"); - FilamentChangePause(); - } else if (strcmp(SelectedDirectory, "")==0) { - SERIAL_PROTOCOLLNPGM("Special Menu: FilamentChange Resume"); - FilamentChangeResume(); - } else if (strcmp(SelectedDirectory, "")==0) { - SpecialMenu=false; - } + if(strcmp(SelectedDirectory, "")==0) { + SpecialMenu=true; + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Auto Tune Hotend PID"); + enqueue_and_echo_commands_P(PSTR("M106 S204\nM303 E0 S210 C6 U1")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Auto Tune Hotbed Pid"); + enqueue_and_echo_commands_P(PSTR("M303 E-1 S60 C6 U1")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Save EEPROM"); + enqueue_and_echo_commands_P(PSTR("M500\nM300 S1108 P105\nM300 S1661 P210")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Load FW Defaults"); + enqueue_and_echo_commands_P(PSTR("M502\nM300 S1661 P105\nM300 S1108 P210")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Preheat Bed"); + enqueue_and_echo_commands_P(PSTR("M140 S60")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Start Mesh Leveling"); + enqueue_and_echo_commands_P(PSTR("G29 S1")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Next Mesh Point"); + enqueue_and_echo_commands_P(PSTR("G29 S2")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Z Up 0.1"); + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z+0.1\nG90")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Z Up 0.02"); + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z+0.02\nG90")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Z Down 0.02"); + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z-0.02\nG90")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: Z Down 0.1"); + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z-0.1\nG90")); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: FilamentChange Pause"); + FilamentChangePause(); + } else if (strcmp(SelectedDirectory, "")==0) { + SERIAL_PROTOCOLLNPGM("Special Menu: FilamentChange Resume"); + FilamentChangeResume(); + } else if (strcmp(SelectedDirectory, "")==0) { + SpecialMenu=false; + } } void AnycubicTFTClass::Ls() { - if (SpecialMenu) { - switch (filenumber) { - case 0: // First Page - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - break; + if (SpecialMenu) { + switch (filenumber) { + case 0: // First Page + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + break; - case 4: // Second Page - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - break; + case 4: // Second Page + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + break; - case 8: // Third Page - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - break; + case 8: // Third Page + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + break; - case 12: // Fourth Page - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - break; + case 12: // Fourth Page + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + break; - default: - break; - } - } -#ifdef SDSUPPORT - else if(card.cardOK) + default: + break; + } + } + #ifdef SDSUPPORT + else if(card.cardOK) + { + uint16_t cnt=filenumber; + uint16_t max_files; + uint16_t dir_files=card.getnrfilenames(); + + if((dir_files-filenumber)<4) + { + max_files=dir_files; + } else { + max_files=filenumber+3; + } + + for(cnt=filenumber; cnt<=max_files; cnt++) + { + if (cnt==0) // Special Entry { - uint16_t cnt=filenumber; - uint16_t max_files; - uint16_t dir_files=card.getnrfilenames(); + if(strcmp(card.getWorkDirName(), "/") == 0) { + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + SERIAL_PROTOCOL(cnt); + SERIAL_PROTOCOLLNPGM(""); + } else { + ANYCUBIC_SERIAL_PROTOCOLLNPGM("/.."); + ANYCUBIC_SERIAL_PROTOCOLLNPGM("/.."); + SERIAL_PROTOCOL(cnt); + SERIAL_PROTOCOLLNPGM("/.."); + } + } else { + card.getfilename(cnt-1); + // card.getfilename(cnt); - if((dir_files-filenumber)<4) - { - max_files=dir_files; - } else { - max_files=filenumber+3; - } - - for(cnt=filenumber; cnt<=max_files; cnt++) - { - if (cnt==0) // Special Entry - { - if(strcmp(card.getWorkDirName(), "/") == 0) { - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - SERIAL_PROTOCOL(cnt); - SERIAL_PROTOCOLLNPGM(""); - } else { - ANYCUBIC_SERIAL_PROTOCOLLNPGM("/.."); - ANYCUBIC_SERIAL_PROTOCOLLNPGM("/.."); - SERIAL_PROTOCOL(cnt); - SERIAL_PROTOCOLLNPGM("/.."); - } - } else { - card.getfilename(cnt-1); -// card.getfilename(cnt); - - if(card.filenameIsDir) { - ANYCUBIC_SERIAL_PROTOCOLPGM("/"); - ANYCUBIC_SERIAL_PROTOCOLLN(card.filename); - ANYCUBIC_SERIAL_PROTOCOLPGM("/"); - ANYCUBIC_SERIAL_PROTOCOLLN(card.longFilename); - SERIAL_PROTOCOL(cnt); - SERIAL_PROTOCOLPGM("/"); - SERIAL_PROTOCOLLN(card.longFilename); - } else { - ANYCUBIC_SERIAL_PROTOCOLLN(card.filename); - ANYCUBIC_SERIAL_PROTOCOLLN(card.longFilename); - SERIAL_PROTOCOL(cnt); - SERIAL_PROTOCOLLN(card.longFilename); - } - } - } - } -#endif - else { - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); - ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + if(card.filenameIsDir) { + ANYCUBIC_SERIAL_PROTOCOLPGM("/"); + ANYCUBIC_SERIAL_PROTOCOLLN(card.filename); + ANYCUBIC_SERIAL_PROTOCOLPGM("/"); + ANYCUBIC_SERIAL_PROTOCOLLN(card.longFilename); + SERIAL_PROTOCOL(cnt); + SERIAL_PROTOCOLPGM("/"); + SERIAL_PROTOCOLLN(card.longFilename); + } else { + ANYCUBIC_SERIAL_PROTOCOLLN(card.filename); + ANYCUBIC_SERIAL_PROTOCOLLN(card.longFilename); + SERIAL_PROTOCOL(cnt); + SERIAL_PROTOCOLLN(card.longFilename); + } } + } + } + #endif + else { + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + ANYCUBIC_SERIAL_PROTOCOLLNPGM(""); + } } void AnycubicTFTClass::CheckSDCardChange() { -#ifdef SDSUPPORT - if (LastSDstatus != IS_SD_INSERTED()) - { - LastSDstatus = IS_SD_INSERTED(); + #ifdef SDSUPPORT + if (LastSDstatus != IS_SD_INSERTED()) + { + LastSDstatus = IS_SD_INSERTED(); - if (LastSDstatus) - { - card.initsd(); - ANYCUBIC_SERIAL_PROTOCOLPGM("J00"); // J00 SD Card inserted - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD card inserted... J00"); -#endif - } - else - { - ANYCUBIC_SERIAL_PROTOCOLPGM("J01"); // J01 SD Card removed - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD card removed... J01"); -#endif + if (LastSDstatus) + { + card.initsd(); + ANYCUBIC_SERIAL_PROTOCOLPGM("J00"); // J00 SD Card inserted + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD card inserted... J00"); + #endif + } + else + { + ANYCUBIC_SERIAL_PROTOCOLPGM("J01"); // J01 SD Card removed + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD card removed... J01"); + #endif - } - } -#endif + } + } + #endif } void AnycubicTFTClass::CheckHeaterError() { - if ((thermalManager.degHotend(0) < 5) || (thermalManager.degHotend(0) > 290)) - { - if (HeaterCheckCount > 60000) - { - HeaterCheckCount = 0; - ANYCUBIC_SERIAL_PROTOCOLPGM("J10"); // J10 Hotend temperature abnormal - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Hotend temperature abnormal... J20"); -#endif + if ((thermalManager.degHotend(0) < 5) || (thermalManager.degHotend(0) > 290)) + { + if (HeaterCheckCount > 60000) + { + HeaterCheckCount = 0; + ANYCUBIC_SERIAL_PROTOCOLPGM("J10"); // J10 Hotend temperature abnormal + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Hotend temperature abnormal... J20"); + #endif - } - else - { - HeaterCheckCount++; - } - } - else - { - HeaterCheckCount = 0; - } + } + else + { + HeaterCheckCount++; + } + } + else + { + HeaterCheckCount = 0; + } } void AnycubicTFTClass::StateHandler() { - switch (TFTstate) { - case ANYCUBIC_TFT_STATE_IDLE: -#ifdef SDSUPPORT - if(card.sdprinting) { - TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; - starttime=millis(); + switch (TFTstate) { + case ANYCUBIC_TFT_STATE_IDLE: + #ifdef SDSUPPORT + if(card.sdprinting) { + TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; + starttime=millis(); - // --> Send print info to display... most probably print started via gcode - } -#endif - break; - case ANYCUBIC_TFT_STATE_SDPRINT: -#ifdef SDSUPPORT - if(!card.sdprinting) { - // It seems that we are to printing anymore... pause or stopped? - if (card.isFileOpen()) { - // File is still open --> paused - TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE; - } else { - // File is closed --> stopped - TFTstate=ANYCUBIC_TFT_STATE_IDLE; - ANYCUBIC_SERIAL_PROTOCOLPGM("J14");// J14 print done - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD print done... J14"); -#endif - } - } -#endif - break; - case ANYCUBIC_TFT_STATE_SDPAUSE: - break; - case ANYCUBIC_TFT_STATE_SDPAUSE_OOF: -#ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR - if(!FilamentTestStatus) { - // We got filament again - TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE; - } -#endif - break; - case ANYCUBIC_TFT_STATE_SDPAUSE_REQ: -#ifdef SDSUPPORT - if((!card.sdprinting) && (!planner.movesplanned())) { - // We have to wait until the sd card printing has been settled - if((!PausedByRunout) && (!PausedByFilamentChange)) - { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Regular Pause requested"); -#endif - enqueue_and_echo_commands_P(PSTR("G91")); // relative mode - enqueue_and_echo_commands_P(PSTR("G1 E-2 F1800")); // retract 2mm - enqueue_and_echo_commands_P(PSTR("G1 Z10 F240")); // lift nozzle by 10mm - enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode - } else if((PausedByRunout)) - { - enqueue_and_echo_commands_P(PSTR("G91")); // relative mode - enqueue_and_echo_commands_P(PSTR("G1 E-3 F1800")); // retract 3mm - enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode - enqueue_and_echo_commands_P(PSTR("M300 S1567 P1000")); // alert user with beeps - enqueue_and_echo_commands_P(PSTR("M300 S2093 P3000")); - #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Filament runout - Retract, beep and park."); - #endif - } -#ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR - if(FilamentTestStatus) { - TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE; - } else { - // Pause because of "out of filament" - TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_OOF; - } -#endif - ANYCUBIC_SERIAL_PROTOCOLPGM("J18");// J18 pausing print done - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused done... J18"); -#endif - } -#endif - break; - case ANYCUBIC_TFT_STATE_SDSTOP_REQ: -#ifdef SDSUPPORT - if((!card.sdprinting) && (!planner.movesplanned())) { - ANYCUBIC_SERIAL_PROTOCOLPGM("J16");// J16 stop print - ANYCUBIC_SERIAL_ENTER(); - TFTstate=ANYCUBIC_TFT_STATE_IDLE; -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD print stopped... J16"); -#endif - enqueue_and_echo_commands_P(PSTR("M84")); - } -#endif - break; - default: - break; + // --> Send print info to display... most probably print started via gcode + } + #endif + break; + case ANYCUBIC_TFT_STATE_SDPRINT: + #ifdef SDSUPPORT + if(!card.sdprinting) { + // It seems that we are to printing anymore... pause or stopped? + if (card.isFileOpen()) { + // File is still open --> paused + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE; + } else { + // File is closed --> stopped + TFTstate=ANYCUBIC_TFT_STATE_IDLE; + ANYCUBIC_SERIAL_PROTOCOLPGM("J14");// J14 print done + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD print done... J14"); + #endif + } } + #endif + break; + case ANYCUBIC_TFT_STATE_SDPAUSE: + break; + case ANYCUBIC_TFT_STATE_SDPAUSE_OOF: + #ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR + if(!FilamentTestStatus) { + // We got filament again + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE; + } + #endif + break; + case ANYCUBIC_TFT_STATE_SDPAUSE_REQ: + #ifdef SDSUPPORT + if((!card.sdprinting) && (!planner.movesplanned())) { + // We have to wait until the sd card printing has been settled + if((!PausedByRunout) && (!PausedByFilamentChange)) + { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Regular Pause requested"); + #endif + enqueue_and_echo_commands_P(PSTR("G91")); // relative mode + enqueue_and_echo_commands_P(PSTR("G1 E-2 F1800")); // retract 2mm + enqueue_and_echo_commands_P(PSTR("G1 Z10 F240")); // lift nozzle by 10mm + enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode + } else if((PausedByRunout)) + { + enqueue_and_echo_commands_P(PSTR("G91")); // relative mode + enqueue_and_echo_commands_P(PSTR("G1 E-3 F1800")); // retract 3mm + enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode + enqueue_and_echo_commands_P(PSTR("M300 S1567 P1000")); // alert user with beeps + enqueue_and_echo_commands_P(PSTR("M300 S2093 P3000")); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Filament runout - Retract, beep and park."); + #endif + } + #ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR + if(FilamentTestStatus) { + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE; + } else { + // Pause because of "out of filament" + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_OOF; + } + #endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J18");// J18 pausing print done + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused done... J18"); + #endif + } + #endif + break; + case ANYCUBIC_TFT_STATE_SDSTOP_REQ: + #ifdef SDSUPPORT + if((!card.sdprinting) && (!planner.movesplanned())) { + ANYCUBIC_SERIAL_PROTOCOLPGM("J16");// J16 stop print + ANYCUBIC_SERIAL_ENTER(); + TFTstate=ANYCUBIC_TFT_STATE_IDLE; + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD print stopped... J16"); + #endif + enqueue_and_echo_commands_P(PSTR("M84")); + } + #endif + break; + default: + break; + } } void AnycubicTFTClass::FilamentRunout() { -#if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR) - FilamentTestStatus=READ(FIL_RUNOUT_PIN)&0xff; + #if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR) + FilamentTestStatus=READ(FIL_RUNOUT_PIN)&0xff; - if(FilamentTestStatus>FilamentTestLastStatus) - { - FilamentRunoutCounter++; - if(FilamentRunoutCounter>=31600) - { - FilamentRunoutCounter=0; -#ifdef SDSUPPORT - if((card.sdprinting==true)) - { - PausedByRunout=true; // set runout pause flag -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set"); -#endif - PausePrint(); - } - else if((card.sdprinting==false)) - { -#endif - ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); -#endif -#ifdef SDSUPPORT - } -#endif - FilamentTestLastStatus=FilamentTestStatus; - } - } - else if(FilamentTestStatus!=FilamentTestLastStatus) - { - FilamentRunoutCounter=0; - FilamentTestLastStatus=FilamentTestStatus; -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout recovered"); -#endif - } -#endif + if(FilamentTestStatus>FilamentTestLastStatus) + { + FilamentRunoutCounter++; + if(FilamentRunoutCounter>=31600) + { + FilamentRunoutCounter=0; + #ifdef SDSUPPORT + if((card.sdprinting==true)) + { + PausedByRunout=true; // set runout pause flag + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set"); + #endif + PausePrint(); + } + else if((card.sdprinting==false)) + { + #endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); + #endif + #ifdef SDSUPPORT + } + #endif + FilamentTestLastStatus=FilamentTestStatus; + } + } + else if(FilamentTestStatus!=FilamentTestLastStatus) + { + FilamentRunoutCounter=0; + FilamentTestLastStatus=FilamentTestStatus; + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout recovered"); + #endif + } + #endif } void AnycubicTFTClass::GetCommandFromTFT() { - char *starpos = NULL; - while( AnycubicSerial.available() > 0 && TFTbuflen < TFTBUFSIZE) - { - serial3_char = AnycubicSerial.read(); - if(serial3_char == '\n' || - serial3_char == '\r' || - serial3_char == ':' || - serial3_count >= (TFT_MAX_CMD_SIZE - 1) ) + char *starpos = NULL; + while( AnycubicSerial.available() > 0 && TFTbuflen < TFTBUFSIZE) + { + serial3_char = AnycubicSerial.read(); + if(serial3_char == '\n' || + serial3_char == '\r' || + serial3_char == ':' || + serial3_count >= (TFT_MAX_CMD_SIZE - 1) ) + { + if(!serial3_count) { //if empty line + return; + } + + TFTcmdbuffer[TFTbufindw][serial3_count] = 0; //terminate string + + if((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL)) { + int16_t a_command; + TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A'); + a_command=((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL)))); + + #ifdef ANYCUBIC_TFT_DEBUG + if ((a_command>7) && (a_command != 20)) // No debugging of status polls, please! + SERIAL_ECHOLNPAIR("TFT Serial Command: ", TFTcmdbuffer[TFTbufindw]); + #endif + + switch(a_command) { + + case 0: //A0 GET HOTEND TEMP + ANYCUBIC_SERIAL_PROTOCOLPGM("A0V "); + ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degHotend(0) + 0.5))); + ANYCUBIC_SERIAL_ENTER(); + break; + + case 1: //A1 GET HOTEND TARGET TEMP + ANYCUBIC_SERIAL_PROTOCOLPGM("A1V "); + ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degTargetHotend(0) + 0.5))); + ANYCUBIC_SERIAL_ENTER(); + break; + + case 2: //A2 GET HOTBED TEMP + ANYCUBIC_SERIAL_PROTOCOLPGM("A2V "); + ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degBed() + 0.5))); + ANYCUBIC_SERIAL_ENTER(); + break; + + case 3: //A3 GET HOTBED TARGET TEMP + ANYCUBIC_SERIAL_PROTOCOLPGM("A3V "); + ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degTargetBed() + 0.5))); + ANYCUBIC_SERIAL_ENTER(); + break; + + case 4://A4 GET FAN SPEED + { + unsigned int temp; + + temp=((fanSpeeds[0]*100)/255); + temp=constrain(temp,0,100); + + ANYCUBIC_SERIAL_PROTOCOLPGM("A4V "); + ANYCUBIC_SERIAL_PROTOCOL(temp); + ANYCUBIC_SERIAL_ENTER(); + } + break; + case 5:// A5 GET CURRENT COORDINATE + ANYCUBIC_SERIAL_PROTOCOLPGM("A5V"); + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_PROTOCOLPGM("X: "); + ANYCUBIC_SERIAL_PROTOCOL(current_position[X_AXIS]); + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_PROTOCOLPGM("Y: "); + ANYCUBIC_SERIAL_PROTOCOL(current_position[Y_AXIS]); + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_PROTOCOLPGM("Z: "); + ANYCUBIC_SERIAL_PROTOCOL(current_position[Z_AXIS]); + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_ENTER(); + break; + case 6: //A6 GET SD CARD PRINTING STATUS + #ifdef SDSUPPORT + if(card.sdprinting) { + ANYCUBIC_SERIAL_PROTOCOLPGM("A6V "); + if(card.cardOK) { - if(!serial3_count) { //if empty line - return; - } - - TFTcmdbuffer[TFTbufindw][serial3_count] = 0; //terminate string - - if((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL)) { - int16_t a_command; - TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A'); - a_command=((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL)))); - -#ifdef ANYCUBIC_TFT_DEBUG - if ((a_command>7) && (a_command != 20)) // No debugging of status polls, please! - SERIAL_ECHOLNPAIR("TFT Serial Command: ", TFTcmdbuffer[TFTbufindw]); -#endif - - switch(a_command) { - - case 0: //A0 GET HOTEND TEMP - ANYCUBIC_SERIAL_PROTOCOLPGM("A0V "); - ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degHotend(0) + 0.5))); - ANYCUBIC_SERIAL_ENTER(); - break; - - case 1: //A1 GET HOTEND TARGET TEMP - ANYCUBIC_SERIAL_PROTOCOLPGM("A1V "); - ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degTargetHotend(0) + 0.5))); - ANYCUBIC_SERIAL_ENTER(); - break; - - case 2: //A2 GET HOTBED TEMP - ANYCUBIC_SERIAL_PROTOCOLPGM("A2V "); - ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degBed() + 0.5))); - ANYCUBIC_SERIAL_ENTER(); - break; - - case 3: //A3 GET HOTBED TARGET TEMP - ANYCUBIC_SERIAL_PROTOCOLPGM("A3V "); - ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(thermalManager.degTargetBed() + 0.5))); - ANYCUBIC_SERIAL_ENTER(); - break; - - case 4://A4 GET FAN SPEED - { - unsigned int temp; - - temp=((fanSpeeds[0]*100)/255); - temp=constrain(temp,0,100); - - ANYCUBIC_SERIAL_PROTOCOLPGM("A4V "); - ANYCUBIC_SERIAL_PROTOCOL(temp); - ANYCUBIC_SERIAL_ENTER(); - } - break; - case 5:// A5 GET CURRENT COORDINATE - ANYCUBIC_SERIAL_PROTOCOLPGM("A5V"); - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_PROTOCOLPGM("X: "); - ANYCUBIC_SERIAL_PROTOCOL(current_position[X_AXIS]); - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_PROTOCOLPGM("Y: "); - ANYCUBIC_SERIAL_PROTOCOL(current_position[Y_AXIS]); - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_PROTOCOLPGM("Z: "); - ANYCUBIC_SERIAL_PROTOCOL(current_position[Z_AXIS]); - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_ENTER(); - break; - case 6: //A6 GET SD CARD PRINTING STATUS -#ifdef SDSUPPORT - if(card.sdprinting) { - ANYCUBIC_SERIAL_PROTOCOLPGM("A6V "); - if(card.cardOK) - { - ANYCUBIC_SERIAL_PROTOCOL(itostr3(card.percentDone())); - } - else - { - ANYCUBIC_SERIAL_PROTOCOLPGM("J02"); - } - } - else - ANYCUBIC_SERIAL_PROTOCOLPGM("A6V ---"); - ANYCUBIC_SERIAL_ENTER(); -#endif - break; - case 7://A7 GET PRINTING TIME - { - ANYCUBIC_SERIAL_PROTOCOLPGM("A7V "); - if(starttime != 0) // print time - { - uint16_t time = millis()/60000 - starttime/60000; - ANYCUBIC_SERIAL_PROTOCOL(itostr2(time/60)); - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_PROTOCOLPGM("H"); - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_PROTOCOL(itostr2(time%60)); - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_PROTOCOLPGM("M"); - }else{ - ANYCUBIC_SERIAL_SPACE(); - ANYCUBIC_SERIAL_PROTOCOLPGM("999:999"); - } - ANYCUBIC_SERIAL_ENTER(); - - break; - } - case 8: // A8 GET SD LIST -#ifdef SDSUPPORT - SelectedDirectory[0]=0; - if(!IS_SD_INSERTED()) - { - ANYCUBIC_SERIAL_PROTOCOLPGM("J02"); - ANYCUBIC_SERIAL_ENTER(); - } - else - { - if(CodeSeen('S')) - filenumber=CodeValue(); - - ANYCUBIC_SERIAL_PROTOCOLPGM("FN "); // Filelist start - ANYCUBIC_SERIAL_ENTER(); - Ls(); - ANYCUBIC_SERIAL_PROTOCOLPGM("END"); // Filelist stop - ANYCUBIC_SERIAL_ENTER(); - } -#endif - break; - case 9: // A9 pause sd print -#ifdef SDSUPPORT - if(card.sdprinting) - { - PausePrint(); - } - else - { - StopPrint(); - } -#endif - break; - case 10: // A10 resume sd print -#ifdef SDSUPPORT - if((TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) || (TFTstate==ANYCUBIC_TFT_STATE_SDOUTAGE)) - { - StartPrint(); - ANYCUBIC_SERIAL_PROTOCOLPGM("J04");// J04 printing form sd card now - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD print started... J04"); -#endif - } -#endif - break; - case 11: // A11 STOP SD PRINT -#ifdef SDSUPPORT - if((card.sdprinting) || (TFTstate==ANYCUBIC_TFT_STATE_SDOUTAGE)) - { - StopPrint(); - } -#endif - break; - case 12: // A12 kill - kill(PSTR(MSG_KILLED)); - break; - case 13: // A13 SELECTION FILE -#ifdef SDSUPPORT - //if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - if((TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) // allow special menu to be used while printing from USB - { - starpos = (strchr(TFTstrchr_pointer + 4,'*')); - if (TFTstrchr_pointer[4] == '/') { - strcpy(SelectedDirectory, TFTstrchr_pointer+5); - } else if (TFTstrchr_pointer[4] == '<') { - strcpy(SelectedDirectory, TFTstrchr_pointer+4); - } else { - SelectedDirectory[0]=0; - - if(starpos!=NULL) - *(starpos-1)='\0'; - card.openFile(TFTstrchr_pointer + 4,true); - if (card.isFileOpen()) { - ANYCUBIC_SERIAL_PROTOCOLPGM("J20"); // J20 Open successful - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: File open successful... J20"); -#endif - } else { - ANYCUBIC_SERIAL_PROTOCOLPGM("J21"); // J21 Open failed - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: File open failed... J21"); -#endif - } - } - ANYCUBIC_SERIAL_ENTER(); - } -#endif - break; - case 14: // A14 START PRINTING -#ifdef SDSUPPORT - if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE) && (card.isFileOpen())) - { - StartPrint(); - ANYCUBIC_SERIAL_PROTOCOLPGM("J04"); // J04 Starting Print - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Starting SD Print... J04"); -#endif - } -#endif - break; - case 15: // A15 RESUMING FROM OUTAGE - // if((!planner.movesplanned())&&(!TFTresumingflag)) - // { - // if(card.cardOK) - // FlagResumFromOutage=true; - // ResumingFlag=1; - // card.startFileprint(); - // starttime=millis(); - // ANYCUBIC_SERIAL_SUCC_START; - // } - // ANYCUBIC_SERIAL_ENTER(); - break; - case 16: // A16 set hotend temp - { - unsigned int tempvalue; - if(CodeSeen('S')) - { - tempvalue=constrain(CodeValue(),0,275); - thermalManager.setTargetHotend(tempvalue,0); - } - else if((CodeSeen('C'))&&(!planner.movesplanned())) - { - if((current_position[Z_AXIS]<10)) - enqueue_and_echo_commands_P(PSTR("G1 Z10")); //RASE Z AXIS - tempvalue=constrain(CodeValue(),0,275); - thermalManager.setTargetHotend(tempvalue,0); - } - } - // ANYCUBIC_SERIAL_ENTER(); - break; - case 17:// A17 set heated bed temp - { - unsigned int tempbed; - if(CodeSeen('S')) {tempbed=constrain(CodeValue(),0,150); - thermalManager.setTargetBed(tempbed);} - } - // ANYCUBIC_SERIAL_ENTER(); - break; - case 18:// A18 set fan speed - unsigned int temp; - if (CodeSeen('S')) - { - temp=(CodeValue()*255/100); - temp=constrain(temp,0,255); - fanSpeeds[0]=temp; - } - else fanSpeeds[0]=255; - ANYCUBIC_SERIAL_ENTER(); - break; - case 19: // A19 stop stepper drivers - if((!planner.movesplanned()) -#ifdef SDSUPPORT - &&(!card.sdprinting) -#endif - ) - { - quickstop_stepper(); - disable_X(); - disable_Y(); - disable_Z(); - disable_E0(); - } - ANYCUBIC_SERIAL_ENTER(); - break; - case 20:// A20 read printing speed - { - if(CodeSeen('S')) { - feedrate_percentage=constrain(CodeValue(),40,999); - } - else{ - ANYCUBIC_SERIAL_PROTOCOLPGM("A20V "); - ANYCUBIC_SERIAL_PROTOCOL(feedrate_percentage); - ANYCUBIC_SERIAL_ENTER(); - } - } - break; - case 21: // A21 all home - if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - { - if(CodeSeen('X')||CodeSeen('Y')||CodeSeen('Z')) - { - if(CodeSeen('X')) enqueue_and_echo_commands_P(PSTR("G28 X")); - if(CodeSeen('Y')) enqueue_and_echo_commands_P(PSTR("G28 Y")); - if(CodeSeen('Z')) enqueue_and_echo_commands_P(PSTR("G28 Z")); - } - else if(CodeSeen('C')) enqueue_and_echo_commands_P(PSTR("G28")); - } - break; - case 22: // A22 move X/Y/Z or extrude - if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - { - float coorvalue; - unsigned int movespeed=0; - char value[30]; - if(CodeSeen('F')) // Set feedrate - movespeed = CodeValue(); - - enqueue_and_echo_commands_P(PSTR("G91")); // relative coordinates - - if(CodeSeen('X')) // Move in X direction - { - coorvalue=CodeValue(); - if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 X0.1F%i"),movespeed);} - else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 X-0.1F%i"),movespeed);} - else {sprintf_P(value,PSTR("G1 X%iF%i"),int(coorvalue),movespeed);} - enqueue_and_echo_command(value); - } - else if(CodeSeen('Y')) // Move in Y direction - { - coorvalue=CodeValue(); - if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 Y0.1F%i"),movespeed);} - else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 Y-0.1F%i"),movespeed);} - else {sprintf_P(value,PSTR("G1 Y%iF%i"),int(coorvalue),movespeed);} - enqueue_and_echo_command(value); - } - else if(CodeSeen('Z')) // Move in Z direction - { - coorvalue=CodeValue(); - if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 Z0.1F%i"),movespeed);} - else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 Z-0.1F%i"),movespeed);} - else {sprintf_P(value,PSTR("G1 Z%iF%i"),int(coorvalue),movespeed);} - enqueue_and_echo_command(value); - } - else if(CodeSeen('E')) // Extrude - { - coorvalue=CodeValue(); - if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 E0.1F%i"),movespeed);} - else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 E-0.1F%i"),movespeed);} - else {sprintf_P(value,PSTR("G1 E%iF500"),int(coorvalue)); } - enqueue_and_echo_command(value); - } - enqueue_and_echo_commands_P(PSTR("G90")); // absolute coordinates - } - ANYCUBIC_SERIAL_ENTER(); - break; - case 23: // A23 preheat pla - if((!planner.movesplanned())&& (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - { - if((current_position[Z_AXIS]<10)) enqueue_and_echo_commands_P(PSTR("G1 Z10")); // RAISE Z AXIS - thermalManager.setTargetBed(50); - thermalManager.setTargetHotend(200, 0); - ANYCUBIC_SERIAL_SUCC_START; - ANYCUBIC_SERIAL_ENTER(); - } - break; - case 24:// A24 preheat abs - if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - { - if((current_position[Z_AXIS]<10)) enqueue_and_echo_commands_P(PSTR("G1 Z10")); //RAISE Z AXIS - thermalManager.setTargetBed(80); - thermalManager.setTargetHotend(240, 0); - - ANYCUBIC_SERIAL_SUCC_START; - ANYCUBIC_SERIAL_ENTER(); - } - break; - case 25: // A25 cool down - if((!planner.movesplanned())&& (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - { - thermalManager.setTargetHotend(0,0); - thermalManager.setTargetBed(0); - ANYCUBIC_SERIAL_PROTOCOLPGM("J12"); // J12 cool down - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Cooling down... J12"); -#endif - } - break; - case 26: // A26 refresh SD -#ifdef SDSUPPORT - if (SelectedDirectory[0]==0) { - card.initsd(); - } else { - if ((SelectedDirectory[0] == '.') && (SelectedDirectory[1] == '.')) { - card.updir(); - } else { - if (SelectedDirectory[0] == '<') { - HandleSpecialMenu(); - } else { - card.chdir(SelectedDirectory); - } - } - } - - SelectedDirectory[0]=0; - - if(!IS_SD_INSERTED()) - { - ANYCUBIC_SERIAL_PROTOCOLPGM("J02"); // J02 SD Card initilized - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD card initialized... J02"); -#endif - } -#endif - break; -#ifdef SERVO_ENDSTOPS - case 27: // A27 servos angles adjust - break; -#endif - case 28: // A28 filament test - { - if(CodeSeen('O')); - else if(CodeSeen('C')); - } - ANYCUBIC_SERIAL_ENTER(); - break; - case 29: // A29 Z PROBE OFFESET SET - break; - - case 30: // A30 assist leveling, the original function was canceled - if(CodeSeen('S')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Entering level menue..."); -#endif - } else if(CodeSeen('O')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Leveling started and movint to front left..."); -#endif - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z10 F240\nG90\nG28\nG29\nG1 X20 Y20 F6000\nG1 Z0 F240")); - } else if(CodeSeen('T')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Level checkpoint front right..."); -#endif - enqueue_and_echo_commands_P(PSTR("G1 Z5 F240\nG1 X190 Y20 F6000\nG1 Z0 F240")); - } else if(CodeSeen('C')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Level checkpoint back right..."); -#endif - enqueue_and_echo_commands_P(PSTR("G1 Z5 F240\nG1 X190 Y190 F6000\nG1 Z0 F240")); - } else if(CodeSeen('Q')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Level checkpoint back right..."); -#endif - enqueue_and_echo_commands_P(PSTR("G1 Z5 F240\nG1 X190 Y20 F6000\nG1 Z0 F240")); - } else if(CodeSeen('H')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Level check no heating..."); -#endif - // enqueue_and_echo_commands_P(PSTR("... TBD ...")); - ANYCUBIC_SERIAL_PROTOCOLPGM("J22"); // J22 Test print done - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Leveling print test done... J22"); -#endif - } else if(CodeSeen('L')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Level check heating..."); -#endif - // enqueue_and_echo_commands_P(PSTR("... TBD ...")); - ANYCUBIC_SERIAL_PROTOCOLPGM("J22"); // J22 Test print done - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Leveling print test with heating done... J22"); -#endif - } - ANYCUBIC_SERIAL_SUCC_START; - ANYCUBIC_SERIAL_ENTER(); - - break; - case 31: // A31 zoffset - if((!planner.movesplanned())&&(TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - { -#if HAS_BED_PROBE - char value[30]; - char *s_zoffset; - //if((current_position[Z_AXIS]<10)) - // z_offset_auto_test(); - - if(CodeSeen('S')) { - ANYCUBIC_SERIAL_PROTOCOLPGM("A9V "); - ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(zprobe_zoffset*100.00 + 0.5))); - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOPGM("TFT sending current z-probe offset data... <"); - SERIAL_ECHOPGM("A9V "); - SERIAL_ECHO(itostr3(int(zprobe_zoffset*100.00 + 0.5))); - SERIAL_ECHOLNPGM(">"); -#endif - } - if(CodeSeen('D')) - { - s_zoffset=ftostr32(float(CodeValue())/100.0); - sprintf_P(value,PSTR("M851 Z")); - strcat(value,s_zoffset); - enqueue_and_echo_command(value); // Apply Z-Probe offset - enqueue_and_echo_commands_P(PSTR("M500")); // Save to EEPROM - } -#endif - } - ANYCUBIC_SERIAL_ENTER(); - break; - case 32: // A32 clean leveling beep flag - if(CodeSeen('S')) { -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Level saving data..."); -#endif - enqueue_and_echo_commands_P(PSTR("M500\nM420 S1\nG1 Z10 F240\nG1 X0 Y0 F6000")); - ANYCUBIC_SERIAL_SUCC_START; - ANYCUBIC_SERIAL_ENTER(); - } - break; - case 33: // A33 get version info - { - ANYCUBIC_SERIAL_PROTOCOLPGM("J33 "); - ANYCUBIC_SERIAL_PROTOCOLPGM(MSG_MY_VERSION); - ANYCUBIC_SERIAL_ENTER(); - } - break; - default: break; - } - } - TFTbufindw = (TFTbufindw + 1)%TFTBUFSIZE; - TFTbuflen += 1; - serial3_count = 0; //clear buffer + ANYCUBIC_SERIAL_PROTOCOL(itostr3(card.percentDone())); } else { - TFTcmdbuffer[TFTbufindw][serial3_count++] = serial3_char; + ANYCUBIC_SERIAL_PROTOCOLPGM("J02"); } + } + else + ANYCUBIC_SERIAL_PROTOCOLPGM("A6V ---"); + ANYCUBIC_SERIAL_ENTER(); + #endif + break; + case 7://A7 GET PRINTING TIME + { + ANYCUBIC_SERIAL_PROTOCOLPGM("A7V "); + if(starttime != 0) // print time + { + uint16_t time = millis()/60000 - starttime/60000; + ANYCUBIC_SERIAL_PROTOCOL(itostr2(time/60)); + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_PROTOCOLPGM("H"); + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_PROTOCOL(itostr2(time%60)); + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_PROTOCOLPGM("M"); + }else{ + ANYCUBIC_SERIAL_SPACE(); + ANYCUBIC_SERIAL_PROTOCOLPGM("999:999"); + } + ANYCUBIC_SERIAL_ENTER(); + + break; + } + case 8: // A8 GET SD LIST + #ifdef SDSUPPORT + SelectedDirectory[0]=0; + if(!IS_SD_INSERTED()) + { + ANYCUBIC_SERIAL_PROTOCOLPGM("J02"); + ANYCUBIC_SERIAL_ENTER(); + } + else + { + if(CodeSeen('S')) + filenumber=CodeValue(); + + ANYCUBIC_SERIAL_PROTOCOLPGM("FN "); // Filelist start + ANYCUBIC_SERIAL_ENTER(); + Ls(); + ANYCUBIC_SERIAL_PROTOCOLPGM("END"); // Filelist stop + ANYCUBIC_SERIAL_ENTER(); + } + #endif + break; + case 9: // A9 pause sd print + #ifdef SDSUPPORT + if(card.sdprinting) + { + PausePrint(); + } + else + { + StopPrint(); + } + #endif + break; + case 10: // A10 resume sd print + #ifdef SDSUPPORT + if((TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) || (TFTstate==ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + StartPrint(); + ANYCUBIC_SERIAL_PROTOCOLPGM("J04");// J04 printing form sd card now + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD print started... J04"); + #endif + } + #endif + break; + case 11: // A11 STOP SD PRINT + #ifdef SDSUPPORT + if((card.sdprinting) || (TFTstate==ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + StopPrint(); + } + #endif + break; + case 12: // A12 kill + kill(PSTR(MSG_KILLED)); + break; + case 13: // A13 SELECTION FILE + #ifdef SDSUPPORT + //if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) + if((TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) // allow special menu to be used while printing from USB + { + starpos = (strchr(TFTstrchr_pointer + 4,'*')); + if (TFTstrchr_pointer[4] == '/') { + strcpy(SelectedDirectory, TFTstrchr_pointer+5); + } else if (TFTstrchr_pointer[4] == '<') { + strcpy(SelectedDirectory, TFTstrchr_pointer+4); + } else { + SelectedDirectory[0]=0; + + if(starpos!=NULL) + *(starpos-1)='\0'; + card.openFile(TFTstrchr_pointer + 4,true); + if (card.isFileOpen()) { + ANYCUBIC_SERIAL_PROTOCOLPGM("J20"); // J20 Open successful + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: File open successful... J20"); + #endif + } else { + ANYCUBIC_SERIAL_PROTOCOLPGM("J21"); // J21 Open failed + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: File open failed... J21"); + #endif + } + } + ANYCUBIC_SERIAL_ENTER(); + } + #endif + break; + case 14: // A14 START PRINTING + #ifdef SDSUPPORT + if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE) && (card.isFileOpen())) + { + StartPrint(); + ANYCUBIC_SERIAL_PROTOCOLPGM("J04"); // J04 Starting Print + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Starting SD Print... J04"); + #endif + } + #endif + break; + case 15: // A15 RESUMING FROM OUTAGE + //if((!planner.movesplanned())&&(!TFTresumingflag)) + // { + // if(card.cardOK) + // FlagResumFromOutage=true; + // ResumingFlag=1; + // card.startFileprint(); + // starttime=millis(); + // ANYCUBIC_SERIAL_SUCC_START; + // } + //ANYCUBIC_SERIAL_ENTER(); + break; + case 16: // A16 set hotend temp + { + unsigned int tempvalue; + if(CodeSeen('S')) + { + tempvalue=constrain(CodeValue(),0,275); + thermalManager.setTargetHotend(tempvalue,0); + } + else if((CodeSeen('C'))&&(!planner.movesplanned())) + { + if((current_position[Z_AXIS]<10)) + enqueue_and_echo_commands_P(PSTR("G1 Z10")); //RASE Z AXIS + tempvalue=constrain(CodeValue(),0,275); + thermalManager.setTargetHotend(tempvalue,0); + } + } + // ANYCUBIC_SERIAL_ENTER(); + break; + case 17:// A17 set heated bed temp + { + unsigned int tempbed; + if(CodeSeen('S')) {tempbed=constrain(CodeValue(),0,150); + thermalManager.setTargetBed(tempbed);} + } + // ANYCUBIC_SERIAL_ENTER(); + break; + case 18:// A18 set fan speed + unsigned int temp; + if (CodeSeen('S')) + { + temp=(CodeValue()*255/100); + temp=constrain(temp,0,255); + fanSpeeds[0]=temp; + } + else fanSpeeds[0]=255; + ANYCUBIC_SERIAL_ENTER(); + break; + case 19: // A19 stop stepper drivers + if((!planner.movesplanned()) + #ifdef SDSUPPORT + &&(!card.sdprinting) + #endif + ) + { + quickstop_stepper(); + disable_X(); + disable_Y(); + disable_Z(); + disable_E0(); + } + ANYCUBIC_SERIAL_ENTER(); + break; + case 20:// A20 read printing speed + { + if(CodeSeen('S')) { + feedrate_percentage=constrain(CodeValue(),40,999); + } + else{ + ANYCUBIC_SERIAL_PROTOCOLPGM("A20V "); + ANYCUBIC_SERIAL_PROTOCOL(feedrate_percentage); + ANYCUBIC_SERIAL_ENTER(); + } + } + break; + case 21: // A21 all home + if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + if(CodeSeen('X')||CodeSeen('Y')||CodeSeen('Z')) + { + if(CodeSeen('X')) enqueue_and_echo_commands_P(PSTR("G28 X")); + if(CodeSeen('Y')) enqueue_and_echo_commands_P(PSTR("G28 Y")); + if(CodeSeen('Z')) enqueue_and_echo_commands_P(PSTR("G28 Z")); + } + else if(CodeSeen('C')) enqueue_and_echo_commands_P(PSTR("G28")); + } + break; + case 22: // A22 move X/Y/Z or extrude + if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + float coorvalue; + unsigned int movespeed=0; + char value[30]; + if(CodeSeen('F')) // Set feedrate + movespeed = CodeValue(); + + enqueue_and_echo_commands_P(PSTR("G91")); // relative coordinates + + if(CodeSeen('X')) // Move in X direction + { + coorvalue=CodeValue(); + if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 X0.1F%i"),movespeed);} + else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 X-0.1F%i"),movespeed);} + else {sprintf_P(value,PSTR("G1 X%iF%i"),int(coorvalue),movespeed);} + enqueue_and_echo_command(value); + } + else if(CodeSeen('Y')) // Move in Y direction + { + coorvalue=CodeValue(); + if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 Y0.1F%i"),movespeed);} + else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 Y-0.1F%i"),movespeed);} + else {sprintf_P(value,PSTR("G1 Y%iF%i"),int(coorvalue),movespeed);} + enqueue_and_echo_command(value); + } + else if(CodeSeen('Z')) // Move in Z direction + { + coorvalue=CodeValue(); + if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 Z0.1F%i"),movespeed);} + else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 Z-0.1F%i"),movespeed);} + else {sprintf_P(value,PSTR("G1 Z%iF%i"),int(coorvalue),movespeed);} + enqueue_and_echo_command(value); + } + else if(CodeSeen('E')) // Extrude + { + coorvalue=CodeValue(); + if((coorvalue<=0.2)&&coorvalue>0) {sprintf_P(value,PSTR("G1 E0.1F%i"),movespeed);} + else if((coorvalue<=-0.1)&&coorvalue>-1) {sprintf_P(value,PSTR("G1 E-0.1F%i"),movespeed);} + else {sprintf_P(value,PSTR("G1 E%iF500"),int(coorvalue)); } + enqueue_and_echo_command(value); + } + enqueue_and_echo_commands_P(PSTR("G90")); // absolute coordinates + } + ANYCUBIC_SERIAL_ENTER(); + break; + case 23: // A23 preheat pla + if((!planner.movesplanned())&& (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + if((current_position[Z_AXIS]<10)) enqueue_and_echo_commands_P(PSTR("G1 Z10")); // RAISE Z AXIS + thermalManager.setTargetBed(50); + thermalManager.setTargetHotend(200, 0); + ANYCUBIC_SERIAL_SUCC_START; + ANYCUBIC_SERIAL_ENTER(); + } + break; + case 24:// A24 preheat abs + if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + if((current_position[Z_AXIS]<10)) enqueue_and_echo_commands_P(PSTR("G1 Z10")); //RAISE Z AXIS + thermalManager.setTargetBed(80); + thermalManager.setTargetHotend(240, 0); + + ANYCUBIC_SERIAL_SUCC_START; + ANYCUBIC_SERIAL_ENTER(); + } + break; + case 25: // A25 cool down + if((!planner.movesplanned())&& (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + thermalManager.setTargetHotend(0,0); + thermalManager.setTargetBed(0); + ANYCUBIC_SERIAL_PROTOCOLPGM("J12"); // J12 cool down + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Cooling down... J12"); + #endif + } + break; + case 26: // A26 refresh SD + #ifdef SDSUPPORT + if (SelectedDirectory[0]==0) { + card.initsd(); + } else { + if ((SelectedDirectory[0] == '.') && (SelectedDirectory[1] == '.')) { + card.updir(); + } else { + if (SelectedDirectory[0] == '<') { + HandleSpecialMenu(); + } else { + card.chdir(SelectedDirectory); + } + } + } + + SelectedDirectory[0]=0; + + if(!IS_SD_INSERTED()) + { + ANYCUBIC_SERIAL_PROTOCOLPGM("J02"); // J02 SD Card initilized + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: SD card initialized... J02"); + #endif + } + #endif + break; + #ifdef SERVO_ENDSTOPS + case 27: // A27 servos angles adjust + break; + #endif + case 28: // A28 filament test + { + if(CodeSeen('O')); + else if(CodeSeen('C')); + } + ANYCUBIC_SERIAL_ENTER(); + break; + case 29: // A29 Z PROBE OFFESET SET + break; + + case 30: // A30 assist leveling, the original function was canceled + if(CodeSeen('S')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Entering level menue..."); + #endif + } else if(CodeSeen('O')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Leveling started and movint to front left..."); + #endif + enqueue_and_echo_commands_P(PSTR("G91\nG1 Z10 F240\nG90\nG28\nG29\nG1 X20 Y20 F6000\nG1 Z0 F240")); + } else if(CodeSeen('T')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Level checkpoint front right..."); + #endif + enqueue_and_echo_commands_P(PSTR("G1 Z5 F240\nG1 X190 Y20 F6000\nG1 Z0 F240")); + } else if(CodeSeen('C')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Level checkpoint back right..."); + #endif + enqueue_and_echo_commands_P(PSTR("G1 Z5 F240\nG1 X190 Y190 F6000\nG1 Z0 F240")); + } else if(CodeSeen('Q')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Level checkpoint back right..."); + #endif + enqueue_and_echo_commands_P(PSTR("G1 Z5 F240\nG1 X190 Y20 F6000\nG1 Z0 F240")); + } else if(CodeSeen('H')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Level check no heating..."); + #endif + //enqueue_and_echo_commands_P(PSTR("... TBD ...")); + ANYCUBIC_SERIAL_PROTOCOLPGM("J22"); // J22 Test print done + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Leveling print test done... J22"); + #endif + } else if(CodeSeen('L')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Level check heating..."); + #endif + //enqueue_and_echo_commands_P(PSTR("... TBD ...")); + ANYCUBIC_SERIAL_PROTOCOLPGM("J22"); // J22 Test print done + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Leveling print test with heating done... J22"); + #endif + } + ANYCUBIC_SERIAL_SUCC_START; + ANYCUBIC_SERIAL_ENTER(); + + break; + case 31: // A31 zoffset + if((!planner.movesplanned())&&(TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) + { + #if HAS_BED_PROBE + char value[30]; + char *s_zoffset; + //if((current_position[Z_AXIS]<10)) + // z_offset_auto_test(); + + if(CodeSeen('S')) { + ANYCUBIC_SERIAL_PROTOCOLPGM("A9V "); + ANYCUBIC_SERIAL_PROTOCOL(itostr3(int(zprobe_zoffset*100.00 + 0.5))); + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOPGM("TFT sending current z-probe offset data... <"); + SERIAL_ECHOPGM("A9V "); + SERIAL_ECHO(itostr3(int(zprobe_zoffset*100.00 + 0.5))); + SERIAL_ECHOLNPGM(">"); + #endif + } + if(CodeSeen('D')) + { + s_zoffset=ftostr32(float(CodeValue())/100.0); + sprintf_P(value,PSTR("M851 Z")); + strcat(value,s_zoffset); + enqueue_and_echo_command(value); // Apply Z-Probe offset + enqueue_and_echo_commands_P(PSTR("M500")); // Save to EEPROM + } + #endif + } + ANYCUBIC_SERIAL_ENTER(); + break; + case 32: // A32 clean leveling beep flag + if(CodeSeen('S')) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Level saving data..."); + #endif + enqueue_and_echo_commands_P(PSTR("M500\nM420 S1\nG1 Z10 F240\nG1 X0 Y0 F6000")); + ANYCUBIC_SERIAL_SUCC_START; + ANYCUBIC_SERIAL_ENTER(); + } + break; + case 33: // A33 get version info + { + ANYCUBIC_SERIAL_PROTOCOLPGM("J33 "); + ANYCUBIC_SERIAL_PROTOCOLPGM(MSG_MY_VERSION); + ANYCUBIC_SERIAL_ENTER(); + } + break; + default: break; } + } + TFTbufindw = (TFTbufindw + 1)%TFTBUFSIZE; + TFTbuflen += 1; + serial3_count = 0; //clear buffer + } + else + { + TFTcmdbuffer[TFTbufindw][serial3_count++] = serial3_char; + } + } } void AnycubicTFTClass::CommandScan() { - CheckHeaterError(); - CheckSDCardChange(); - StateHandler(); + CheckHeaterError(); + CheckSDCardChange(); + StateHandler(); - if(TFTbuflen<(TFTBUFSIZE-1)) - GetCommandFromTFT(); - if(TFTbuflen) - { - TFTbuflen = (TFTbuflen-1); - TFTbufindr = (TFTbufindr + 1)%TFTBUFSIZE; - } + if(TFTbuflen<(TFTBUFSIZE-1)) + GetCommandFromTFT(); + if(TFTbuflen) + { + TFTbuflen = (TFTbuflen-1); + TFTbufindr = (TFTbufindr + 1)%TFTBUFSIZE; + } } void AnycubicTFTClass::HeatingStart() { - ANYCUBIC_SERIAL_PROTOCOLPGM("J06"); // J07 hotend heating start - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Nozzle is heating... J06"); -#endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J06"); // J07 hotend heating start + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Nozzle is heating... J06"); + #endif } void AnycubicTFTClass::HeatingDone() { - ANYCUBIC_SERIAL_PROTOCOLPGM("J07"); // J07 hotend heating done - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Nozzle heating is done... J07"); -#endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J07"); // J07 hotend heating done + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Nozzle heating is done... J07"); + #endif - if(TFTstate==ANYCUBIC_TFT_STATE_SDPRINT) - { - ANYCUBIC_SERIAL_PROTOCOLPGM("J04"); // J04 printing from sd card - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Continuing SD print after heating... J04"); -#endif - } + if(TFTstate==ANYCUBIC_TFT_STATE_SDPRINT) + { + ANYCUBIC_SERIAL_PROTOCOLPGM("J04"); // J04 printing from sd card + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Continuing SD print after heating... J04"); + #endif + } } void AnycubicTFTClass::BedHeatingStart() { - ANYCUBIC_SERIAL_PROTOCOLPGM("J08"); // J08 hotbed heating start - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Bed is heating... J08"); -#endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J08"); // J08 hotbed heating start + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Bed is heating... J08"); + #endif } void AnycubicTFTClass::BedHeatingDone() { - ANYCUBIC_SERIAL_PROTOCOLPGM("J09"); // J09 hotbed heating done - ANYCUBIC_SERIAL_ENTER(); -#ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Bed heating is done... J09"); -#endif + ANYCUBIC_SERIAL_PROTOCOLPGM("J09"); // J09 hotbed heating done + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Bed heating is done... J09"); + #endif } From cea54723e789608a9b8d7029c07d1dcec0b11203 Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Fri, 8 Mar 2019 16:05:54 +0100 Subject: [PATCH 3/7] Use realtime on filament sensor Instead of incrementing a variable on every iteration on the filament sensor trigger loop, we now use a real time macro that ensure better repeatability and is easier to customize. --- Marlin/AnycubicTFT.cpp | 32 ++++++++++++++++++++++++-------- Marlin/AnycubicTFT.h | 3 ++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Marlin/AnycubicTFT.cpp b/Marlin/AnycubicTFT.cpp index de5401a..f98ea72 100644 --- a/Marlin/AnycubicTFT.cpp +++ b/Marlin/AnycubicTFT.cpp @@ -33,6 +33,7 @@ #include "stepper.h" #include "serial.h" #include "printcounter.h" +#include "macros.h" #ifdef ANYCUBIC_TFT_MODEL #include "AnycubicTFT.h" @@ -598,10 +599,26 @@ void AnycubicTFTClass::FilamentRunout() if(FilamentTestStatus>FilamentTestLastStatus) { - FilamentRunoutCounter++; - if(FilamentRunoutCounter>=31600) - { - FilamentRunoutCounter=0; + // something changed! save current timestamp. + const millis_t fil_ms = millis(); + static millis_t fil_delay; + + // since this is inside a loop, only set delay time once + if (FilamentSetMillis){ + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Set filament trigger time"); + #endif + // set the delayed timestamp to 3000ms later + fil_delay = fil_ms + 3000UL; + // this doesn't need to run until the filament is recovered again + FilamentSetMillis=false; + } + + // have three seconds passed? + if ((FilamentTestStatus>FilamentTestLastStatus) && (fil_ms>fil_delay)) { + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: 3000ms delay done"); + #endif #ifdef SDSUPPORT if((card.sdprinting==true)) { @@ -613,21 +630,20 @@ void AnycubicTFTClass::FilamentRunout() } else if((card.sdprinting==false)) { - #endif ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); #endif - #ifdef SDSUPPORT + FilamentTestLastStatus=FilamentTestStatus; } #endif - FilamentTestLastStatus=FilamentTestStatus; } } else if(FilamentTestStatus!=FilamentTestLastStatus) { - FilamentRunoutCounter=0; + // set the timestamps on the next loop again + FilamentSetMillis=true; FilamentTestLastStatus=FilamentTestStatus; #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout recovered"); diff --git a/Marlin/AnycubicTFT.h b/Marlin/AnycubicTFT.h index 227be08..ef18789 100644 --- a/Marlin/AnycubicTFT.h +++ b/Marlin/AnycubicTFT.h @@ -107,7 +107,8 @@ private: #if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR) char FilamentTestStatus=false; char FilamentTestLastStatus=false; - long FilamentRunoutCounter=0; + bool FilamentSetMillis=true; + #endif }; From 1a5804f26072320ad438dd26ddbde8842d8b8a5b Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Fri, 8 Mar 2019 16:30:56 +0100 Subject: [PATCH 4/7] Implement nozzle reheating on timeout via display - Raise nozzle timeout to 10 minutes - Use continue button as reheat trigger - Manage nozzle_timed_out variable via display - Add PausedByNozzleTimeout flag to enter correct routine on display - Bump version to 1.4.3 --- Marlin/AnycubicTFT.cpp | 61 ++++++++++++++++++++++++++++++-------- Marlin/AnycubicTFT.h | 2 ++ Marlin/Configuration_adv.h | 2 +- Marlin/Marlin.h | 3 ++ Marlin/Marlin_main.cpp | 26 ++++++++++++++-- Marlin/Version.h | 4 +-- Marlin/language.h | 2 +- README.md | 20 ++++++++----- 8 files changed, 94 insertions(+), 26 deletions(-) diff --git a/Marlin/AnycubicTFT.cpp b/Marlin/AnycubicTFT.cpp index f98ea72..89414b1 100644 --- a/Marlin/AnycubicTFT.cpp +++ b/Marlin/AnycubicTFT.cpp @@ -138,7 +138,7 @@ void AnycubicTFTClass::KillTFT() void AnycubicTFTClass::StartPrint(){ if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) { // resuming from SD pause - if((!PausedByRunout) && (!PausedByFilamentChange)) // was that a regular pause? + if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was that a regular pause? { enqueue_and_echo_commands_P(PSTR("G91")); // relative mode enqueue_and_echo_commands_P(PSTR("G1 Z-10 F240")); // lower nozzle again @@ -148,11 +148,11 @@ void AnycubicTFTClass::StartPrint(){ } starttime=millis(); #ifdef SDSUPPORT - if((!PausedByRunout) && (!PausedByFilamentChange)) // was that a regular pause? + if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was that a regular pause? { card.startFileprint(); // start or resume regularly } - else if((PausedByRunout) && (!PausedByFilamentChange)) // resuming from a pause that was caused by filament runout + else if((PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // resuming from a pause that was caused by filament runout { enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle and resume #ifdef ANYCUBIC_TFT_DEBUG @@ -163,19 +163,30 @@ void AnycubicTFTClass::StartPrint(){ SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag cleared"); #endif } - else if((!PausedByRunout) && (PausedByFilamentChange)) // was M600 called? + else if((!PausedByRunout) && (PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was M600 called and the nozzle is not timed out? { - FilamentChangeResume(); // enter M108 routine #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Start M108 routine"); #endif - PausedByFilamentChange=false; // clear flag + FilamentChangeResume(); // enter M108 routine + PausedByFilamentChange=false; // clear flag #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Filament Change Flag cleared"); #endif } #endif - TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; + if (!PausedByNozzleTimeout) { + TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; + } else { + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Set Pause again because of timeout"); + #endif + PausedByNozzleTimeout=false; + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Nozzle timeout flag cleared"); + #endif + } } void AnycubicTFTClass::PausePrint(){ @@ -192,7 +203,7 @@ void AnycubicTFTClass::PausePrint(){ #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Filament Runout Pause"); #endif - enqueue_and_echo_commands_P(PSTR("M25")); // pause print and park nozzle + enqueue_and_echo_commands_P(PSTR("M25")); // pause print and park nozzle #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M25 sent, parking nozzle"); #endif @@ -251,16 +262,19 @@ void AnycubicTFTClass::StopPrint(){ for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0; #endif TFTstate=ANYCUBIC_TFT_STATE_SDSTOP_REQ; + enqueue_and_echo_commands_P(PSTR("M27")); // force report of SD status } void AnycubicTFTClass::FilamentChangeResume(){ enqueue_and_echo_commands_P(PSTR("M108")); // call M108 to break out of M600 pause - HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e); // resume heating if timed out + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: M108 called"); + #endif wait_for_heatup = false; wait_for_user = false; // remove waiting flags card.startFileprint(); // resume with proper progress state #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: M108 Resume called"); + SERIAL_ECHOLNPGM("DEBUG: M108 Resume done"); #endif } @@ -273,6 +287,24 @@ void AnycubicTFTClass::FilamentChangePause(){ #endif } +void AnycubicTFTClass::ReheatNozzle(){ + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Send reheat M108"); + #endif + enqueue_and_echo_commands_P(PSTR("M108")); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Resume heating"); + #endif + HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e); // resume heating if timed out + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Clear flags"); + #endif + nozzle_timed_out = false; + wait_for_user = false; + wait_for_heatup = false; + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; +} + float AnycubicTFTClass::CodeValue() { @@ -538,7 +570,7 @@ void AnycubicTFTClass::StateHandler() #ifdef SDSUPPORT if((!card.sdprinting) && (!planner.movesplanned())) { // We have to wait until the sd card printing has been settled - if((!PausedByRunout) && (!PausedByFilamentChange)) + if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) { #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Regular Pause requested"); @@ -602,7 +634,7 @@ void AnycubicTFTClass::FilamentRunout() // something changed! save current timestamp. const millis_t fil_ms = millis(); static millis_t fil_delay; - + // since this is inside a loop, only set delay time once if (FilamentSetMillis){ #ifdef ANYCUBIC_TFT_DEBUG @@ -814,7 +846,10 @@ void AnycubicTFTClass::GetCommandFromTFT() SERIAL_ECHOLNPGM("TFT Serial Debug: SD print started... J04"); #endif } - #endif + if (nozzle_timed_out) { + ReheatNozzle(); + } + #endif break; case 11: // A11 STOP SD PRINT #ifdef SDSUPPORT diff --git a/Marlin/AnycubicTFT.h b/Marlin/AnycubicTFT.h index ef18789..6ae359f 100644 --- a/Marlin/AnycubicTFT.h +++ b/Marlin/AnycubicTFT.h @@ -58,6 +58,7 @@ public: char TFTstate=ANYCUBIC_TFT_STATE_IDLE; bool PausedByRunout=false; bool PausedByFilamentChange=false; + bool PausedByNozzleTimeout=false; private: char TFTcmdbuffer[TFTBUFSIZE][TFT_MAX_CMD_SIZE]; @@ -100,6 +101,7 @@ private: void HandleSpecialMenu(); void FilamentChangePause(); void FilamentChangeResume(); + void ReheatNozzle(); char SelectedDirectory[30]; uint8_t SpecialMenu=false; diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 25fc2e4..e00380d 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1009,7 +1009,7 @@ #define FILAMENT_UNLOAD_DELAY 5000 // (ms) Delay for the filament to cool after retract. #define FILAMENT_UNLOAD_PURGE_LENGTH 8 // (mm) An unretract is done, then this length is purged. - #define PAUSE_PARK_NOZZLE_TIMEOUT 300 // (seconds) Time limit before the nozzle is turned off for safety. + #define PAUSE_PARK_NOZZLE_TIMEOUT 600 // (seconds) Time limit before the nozzle is turned off for safety. #define FILAMENT_CHANGE_ALERT_BEEPS 10 // Number of alert beeps to play when a response is needed. #define PAUSE_PARK_NO_STEPPER_TIMEOUT // Enable for XYZ steppers to stay powered on during filament change. diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 46037b8..e3f205a 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -271,6 +271,9 @@ FORCE_INLINE bool all_axes_known() { return (axis_known_position & xyz_bits) == extern volatile bool wait_for_heatup; +// Making sure this flag can be cleared by the Anycubic display +extern volatile bool nozzle_timed_out; + #if HAS_RESUME_CONTINUE extern volatile bool wait_for_user; #endif diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4ea80df..7a82655 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -519,6 +519,9 @@ static bool relative_mode; // = false; // For M109 and M190, this flag may be cleared (by M108) to exit the wait loop volatile bool wait_for_heatup = true; +// Making sure this flag can be cleared by the Anycubic display +volatile bool nozzle_timed_out = false; + // For M0/M1, this flag may be cleared (by M108) to exit the wait-for-user loop #if HAS_RESUME_CONTINUE volatile bool wait_for_user; // = false; @@ -7213,7 +7216,11 @@ inline void gcode_M17() { * Used by M125 and M600 */ static void wait_for_filament_reload(const int8_t max_beep_count=0) { - bool nozzle_timed_out = false; + nozzle_timed_out = false; + nozzle_timed_out = false; + #ifdef ANYCUBIC_TFT_MODEL + AnycubicTFT.PausedByNozzleTimeout = false; + #endif #if ENABLED(ULTIPANEL) lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_INSERT); @@ -7246,6 +7253,14 @@ inline void gcode_M17() { nozzle_timed_out |= thermalManager.is_heater_idle(e); if (nozzle_timed_out) { + + #ifdef ANYCUBIC_TFT_MODEL + AnycubicTFT.PausedByNozzleTimeout=true; + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Nozzle timeout flag set"); + #endif + #endif + #if ENABLED(ULTIPANEL) lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_CLICK_TO_HEAT_NOZZLE); #endif @@ -7287,6 +7302,9 @@ inline void gcode_M17() { wait_for_user = true; // Wait for user to load filament nozzle_timed_out = false; + #ifdef ANYCUBIC_TFT_DEBUG + AnycubicTFT.PausedByNozzleTimeout = false; + #endif #if HAS_BUZZER filament_change_beep(max_beep_count, true); @@ -7320,7 +7338,11 @@ inline void gcode_M17() { if (!did_pause_print) return; // Re-enable the heaters if they timed out - bool nozzle_timed_out = false; + nozzle_timed_out = false; + #ifdef ANYCUBIC_TFT_MODEL + AnycubicTFT.PausedByNozzleTimeout = false; + #endif + HOTEND_LOOP() { nozzle_timed_out |= thermalManager.is_heater_idle(e); thermalManager.reset_heater_idle_timer(e); diff --git a/Marlin/Version.h b/Marlin/Version.h index 514be4d..0da8739 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -41,7 +41,7 @@ * Defines the version of the Marlin-AI3M build. Not to be confused with * Marlin's own build number, e.g. 1.1.9. */ - #define CUSTOM_BUILD_VERSION "v1.4.2" + #define CUSTOM_BUILD_VERSION "v1.4.3" /** * Verbose version identifier which should contain a reference to the location @@ -54,7 +54,7 @@ * here we define this default string as the date where the latest release * version was tagged. */ - #define STRING_DISTRIBUTION_DATE "2019-02-24" + #define STRING_DISTRIBUTION_DATE "2019-03-06" /** * Required minimum Configuration.h and Configuration_adv.h file versions. diff --git a/Marlin/language.h b/Marlin/language.h index 8530ee9..d021a90 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -137,7 +137,7 @@ #define MSG_INVALID_EXTRUDER "Invalid extruder" #define MSG_INVALID_SOLENOID "Invalid solenoid" #define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature" -#define MSG_M115_REPORT "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID " MARLIN-AI3M_VERSION:" CUSTOM_BUILD_VERSION +#define MSG_M115_REPORT "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " MARLIN-AI3M_VERSION:" CUSTOM_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID #define MSG_MARLIN_AI3M "Marlin-AI3M" #define MSG_COUNT_X " Count X:" #define MSG_COUNT_A " Count A:" diff --git a/README.md b/README.md index 79bf250..04f5f5d 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,7 @@ Feel free to discuss issues and work with me further optimizing this firmware! I am running this version on an i3 Mega Ultrabase V3 (for distinction of the different versions, check [this Thingiverse thread](https://www.thingiverse.com/groups/anycubic-i3-mega/forums/general/topic:27064)). Basically, this should work on every Ultrabase version that has two Z-axis endstops. -The new **Mega-S** should work too, but you will need to enter those two commands to make the new extruder work: -``` -M92 E384 -M500 -``` -Afterwards, calibration is highly recommended as per the instructions on the [Wiki](https://github.com/davidramiro/Marlin-AI3M/wiki/Calibration/). +The new **Mega-S** should work too, but you will need to enter two additional commands after flashing the firmware, mentioned in the instructions below. Looking for a **BLtouch firmware**? Head [this way](https://github.com/MNieddu91/Marlin-AI3M-BLTouch)! Mounting and configuration instructions are included. @@ -26,7 +21,7 @@ A German translation of the instructions can be found [here](https://kore.cc/i3m ## Known issues: -- **Cura users: Please turn off jerk and acceleration control in your print settings (not visible by default, select advanced visibility to unlock them). Cura's high default jerk and acceleration might cause shifted layers if you use TMC2208.** +- Power outage support is not included - Estimated print times from your slicer might be slightly off. - Special characters on any file or folders name on the SD card will cause the file menu to freeze. Simply replace or remove every special character (Chinese, Arabic, Russian, accents, German & Scandinavian umlauts, ...) from the name. Symbols like dashes or underscores are no problem. **Important note: On the SD card that comes with the printer there is a folder with Chinese characters in it by default. Please rename or remove it.** @@ -78,6 +73,11 @@ I provided three different precompiled hex files: One for no modifications on th - `M502` - load hard coded default values - `M500` - save them to EEPROM +**If you are using this on a Mega-S, those two additional commands are necessary:** +- `M92 E384` - set correct steps for the new extruder +- `M500` - save them +- I highly recommend calibrating the extruder. + #### Calibration and other instructions have been moved to the [Wiki](https://github.com/davidramiro/Marlin-AI3M/wiki/Calibration). @@ -182,6 +182,9 @@ G26 C H200 P25 R25 - Place `M600` in your GCode at the desired layer or send it via terminal - Alternatively: Use `FilamentChange Pause` in the Special Menu - The nozzle will park and your printer will beep + - For safety reasons, the printer will turn off the hotend after 10 minutes. If you see the temperature being under the target: + - SD printing: Click `CONTINUE` **(only once!)** on the screen and wait for the hotend to heat up again. + - USB printing: Send `M108` and wait for the hotend to heat up again. - Remove the filament from the bowden tube - Insert the new filament right up to the nozzle, just until a bit of plastic oozes out - Remove the excess filament from the nozzle with tweezers @@ -199,6 +202,9 @@ G26 C H200 P25 R25 - Alternatively: Use `FilamentChange Pause` in the Special Menu - The nozzle will park - The printer will remove the filament right up to the extruder and beep when finished + - For safety reasons, the printer will turn off the hotend after 10 minutes. If you see the temperature being under the target: + - SD printing: Click `CONTINUE` **(only once!)** on the screen and wait for the hotend to heat up again. + - USB printing: Send `M108` and wait for the hotend to heat up again. - Insert the new filament just up to the end of the bowden fitting, as shown here: ![Load Filament][m600 load] From ee6094f39d0a09e56b42de85254e5d0eb43f23f2 Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Sun, 10 Mar 2019 22:40:35 +0100 Subject: [PATCH 5/7] Cleanup Improving and adding some comments to the code, updating a few details on the readme --- Marlin/AnycubicTFT.cpp | 136 ++++++++++++++++++++++------------------- README.md | 79 +++++++++++++++++------- 2 files changed, 130 insertions(+), 85 deletions(-) diff --git a/Marlin/AnycubicTFT.cpp b/Marlin/AnycubicTFT.cpp index 89414b1..4a70800 100644 --- a/Marlin/AnycubicTFT.cpp +++ b/Marlin/AnycubicTFT.cpp @@ -137,23 +137,23 @@ void AnycubicTFTClass::KillTFT() void AnycubicTFTClass::StartPrint(){ - if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) { // resuming from SD pause - if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was that a regular pause? - { + // are we resuming from a pause? + if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) { + // was that a regular pause? + if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) { enqueue_and_echo_commands_P(PSTR("G91")); // relative mode enqueue_and_echo_commands_P(PSTR("G1 Z-10 F240")); // lower nozzle again enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode - } } starttime=millis(); #ifdef SDSUPPORT - if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was that a regular pause? - { + // was that a regular pause? + if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) { card.startFileprint(); // start or resume regularly } - else if((PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // resuming from a pause that was caused by filament runout - { + // resuming from a pause that was caused by filament runout + else if((PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) { enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle and resume #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M24 Resume from Filament Runout"); @@ -163,43 +163,46 @@ void AnycubicTFTClass::StartPrint(){ SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag cleared"); #endif } - else if((!PausedByRunout) && (PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was M600 called and the nozzle is not timed out? - { + // was M600 called and the nozzle is not timed out? + else if((!PausedByRunout) && (PausedByFilamentChange) && (!PausedByNozzleTimeout)) { #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Start M108 routine"); #endif - FilamentChangeResume(); // enter M108 routine + FilamentChangeResume(); // enter display M108 routine PausedByFilamentChange=false; // clear flag #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Filament Change Flag cleared"); #endif } #endif - if (!PausedByNozzleTimeout) { - TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; - } else { + if (PausedByNozzleTimeout) { + // nozzle was timed out before, do not enter printing state yet TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Set Pause again because of timeout"); #endif + + // clear the timeout flag to ensure the print continues on the + // next push of CONTINUE PausedByNozzleTimeout=false; #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Nozzle timeout flag cleared"); #endif + } else { + // regular resume/start or all specific resume routines are done, + // set printing state again + TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; } } void AnycubicTFTClass::PausePrint(){ #ifdef SDSUPPORT - if((!PausedByRunout)) // is this a regular pause? - { - card.pauseSDPrint(); // pause print regularly + if((!PausedByRunout)) { // is this a regular pause? + card.pauseSDPrint(); // pause print regularly #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Regular Pause"); #endif - } - else // pause caused by filament runout - { + } else { // pause caused by filament runout #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Filament Runout Pause"); #endif @@ -207,7 +210,8 @@ void AnycubicTFTClass::PausePrint(){ #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M25 sent, parking nozzle"); #endif - ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 Show Filament Lack prompt on screen + // show filament runout prompt on screen + ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: J23 Show filament prompt"); @@ -216,15 +220,17 @@ void AnycubicTFTClass::PausePrint(){ #endif TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; #ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR + // regular pause if(FilamentTestStatus) { - ANYCUBIC_SERIAL_PROTOCOLPGM("J05");// J05 pausing + ANYCUBIC_SERIAL_PROTOCOLPGM("J05"); ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused... J05"); #endif + // pause because of filament sensor } else { - // Pause because of "out of filament" - ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 FILAMENT LACK with the prompt box don't disappear + // show filament runout prompt on screen + ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout while printing... J23"); @@ -266,22 +272,31 @@ void AnycubicTFTClass::StopPrint(){ } void AnycubicTFTClass::FilamentChangeResume(){ - enqueue_and_echo_commands_P(PSTR("M108")); // call M108 to break out of M600 pause + // call M108 to break out of M600 pause + #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: M108 called"); + SERIAL_ECHOLNPGM("DEBUG: M108 Resume called"); #endif + + // remove waiting flags wait_for_heatup = false; - wait_for_user = false; // remove waiting flags - card.startFileprint(); // resume with proper progress state + wait_for_user = false; + + // resume with proper progress state + card.startFileprint(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M108 Resume done"); #endif } void AnycubicTFTClass::FilamentChangePause(){ + // set filament change flag to ensure the M108 routine + // gets used when the user hits CONTINUE PausedByFilamentChange=true; + + // call M600 and set display state to paused enqueue_and_echo_commands_P(PSTR("M600")); - TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; // set TFT state to paused + TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M600 Pause called"); #endif @@ -295,13 +310,19 @@ void AnycubicTFTClass::ReheatNozzle(){ #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Resume heating"); #endif - HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e); // resume heating if timed out + + // enable heaters again + HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Clear flags"); #endif nozzle_timed_out = false; + + // clear waiting flags wait_for_user = false; wait_for_heatup = false; + + // set pause state to show CONTINUE button again TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; } @@ -570,8 +591,8 @@ void AnycubicTFTClass::StateHandler() #ifdef SDSUPPORT if((!card.sdprinting) && (!planner.movesplanned())) { // We have to wait until the sd card printing has been settled - if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) - { + if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) { + // no flags, this is a regular pause. #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Regular Pause requested"); #endif @@ -579,13 +600,12 @@ void AnycubicTFTClass::StateHandler() enqueue_and_echo_commands_P(PSTR("G1 E-2 F1800")); // retract 2mm enqueue_and_echo_commands_P(PSTR("G1 Z10 F240")); // lift nozzle by 10mm enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode - } else if((PausedByRunout)) - { + } else if((PausedByRunout)) { + // filament runout, retract and beep enqueue_and_echo_commands_P(PSTR("G91")); // relative mode enqueue_and_echo_commands_P(PSTR("G1 E-3 F1800")); // retract 3mm enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode - enqueue_and_echo_commands_P(PSTR("M300 S1567 P1000")); // alert user with beeps - enqueue_and_echo_commands_P(PSTR("M300 S2093 P3000")); + enqueue_and_echo_commands_P(PSTR("M300 S1567 P1000\nM300 S2093 P3000")); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Filament runout - Retract, beep and park."); #endif @@ -598,7 +618,7 @@ void AnycubicTFTClass::StateHandler() TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_OOF; } #endif - ANYCUBIC_SERIAL_PROTOCOLPGM("J18");// J18 pausing print done + ANYCUBIC_SERIAL_PROTOCOLPGM("J18"); // J18 pausing print done ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused done... J18"); @@ -629,14 +649,13 @@ void AnycubicTFTClass::FilamentRunout() #if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR) FilamentTestStatus=READ(FIL_RUNOUT_PIN)&0xff; - if(FilamentTestStatus>FilamentTestLastStatus) - { - // something changed! save current timestamp. + if(FilamentTestStatus>FilamentTestLastStatus) { + // filament sensor pin changed, save current timestamp. const millis_t fil_ms = millis(); static millis_t fil_delay; // since this is inside a loop, only set delay time once - if (FilamentSetMillis){ + if (FilamentSetMillis) { #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Set filament trigger time"); #endif @@ -646,36 +665,30 @@ void AnycubicTFTClass::FilamentRunout() FilamentSetMillis=false; } - // have three seconds passed? - if ((FilamentTestStatus>FilamentTestLastStatus) && (fil_ms>fil_delay)) { + // if three seconds passed and the sensor is still triggered, + // we trigger the filament runout status + if ((FilamentTestStatus>FilamentTestLastStatus) && (ELAPSED(fil_ms, fil_delay))) { #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: 3000ms delay done"); #endif - #ifdef SDSUPPORT - if((card.sdprinting==true)) - { - PausedByRunout=true; // set runout pause flag - #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set"); - #endif - PausePrint(); - } - else if((card.sdprinting==false)) - { + if((card.sdprinting==true)) { + PausedByRunout=true; // set runout pause flag + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set"); + #endif + PausePrint(); + } else if((card.sdprinting==false)) { ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); #endif FilamentTestLastStatus=FilamentTestStatus; - } - #endif + } } } - else if(FilamentTestStatus!=FilamentTestLastStatus) - { - // set the timestamps on the next loop again - FilamentSetMillis=true; + else if(FilamentTestStatus!=FilamentTestLastStatus) { + FilamentSetMillis=true; // set the timestamps on the next loop again FilamentTestLastStatus=FilamentTestStatus; #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout recovered"); @@ -864,8 +877,7 @@ void AnycubicTFTClass::GetCommandFromTFT() break; case 13: // A13 SELECTION FILE #ifdef SDSUPPORT - //if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) - if((TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) // allow special menu to be used while printing from USB + if((TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) { starpos = (strchr(TFTstrchr_pointer + 4,'*')); if (TFTstrchr_pointer[4] == '/') { diff --git a/README.md b/README.md index 04f5f5d..ea6150f 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ This is my slightly customized version of the [Marlin Firmware](https://github.c Feel free to discuss issues and work with me further optimizing this firmware! -I am running this version on an i3 Mega Ultrabase V3 (for distinction of the different versions, check [this Thingiverse thread](https://www.thingiverse.com/groups/anycubic-i3-mega/forums/general/topic:27064)). -Basically, this should work on every Ultrabase version that has two Z-axis endstops. +This firmware works on every i3 Mega that has two Z-axis endstops. If you have an older model with only one Z endstop, a small [adjustment](https://github.com/davidramiro/Marlin-AI3M/wiki/Customization-&-Compiling#single-z-endstop) is required. The new **Mega-S** should work too, but you will need to enter two additional commands after flashing the firmware, mentioned in the instructions below. @@ -19,13 +18,6 @@ Note: This is just a firmware, not magic. A big part of print quality still depe A German translation of the instructions can be found [here](https://kore.cc/i3mega/download/marlin-ai3m_german.pdf). -## Known issues: - -- Power outage support is not included -- Estimated print times from your slicer might be slightly off. -- Special characters on any file or folders name on the SD card will cause the file menu to freeze. Simply replace or remove every special character (Chinese, Arabic, Russian, accents, German & Scandinavian umlauts, ...) from the name. Symbols like dashes or underscores are no problem. -**Important note: On the SD card that comes with the printer there is a folder with Chinese characters in it by default. Please rename or remove it.** -- Cancelling prints after pausing may show an error. Simply resume the print before canceling. Protip: Switch to OctoPrint. ## Why use this? @@ -40,7 +32,16 @@ While the i3 Mega is a great printer for its price and produces fantastic result - Very loud stock stepper motor drivers, easily replaced by Watterott or FYSETC TMC2208. To do that, you'd usually have to flip the connectors on the board, this is not necessary using this firmware. - No need to slice and upload custom bed leveling tests, test it with a single GCode command - Easily start an auto PID tune or mesh bed leveling via the special menu (insert SD card, select special menu and press the round arrow) -- Filament change feature enabled: Switch colors/material mid print with `M600` (instructions below) +- Filament change feature enabled: Switch colors/material mid print (instructions below) and control it via display. +- The filament runout sensor functionality has been overhauled and improved: The hotend now parks and retracts automatically and purges after loading a new spool. + +## Known issues: + +- Power outage support is not included +- Estimated print times from your slicer might be slightly off. +- Special characters on any file or folders name on the SD card will cause the file menu to freeze. Simply replace or remove every special character (Chinese, Arabic, Russian, accents, German & Scandinavian umlauts, ...) from the name. Symbols like dashes or underscores are no problem. +**Important note: On the SD card that comes with the printer there is a folder with Chinese characters in it by default. Please rename or remove it.** +- Cancelling prints after pausing may show an error. Simply resume the print before canceling. Protip: Switch to OctoPrint. ## How to flash this? @@ -57,8 +58,9 @@ I provided three different precompiled hex files: One for no modifications on th ### Or compile it yourself: -- Download Arduino IDE +- Download and install [Arduino IDE](https://www.arduino.cc/en/main/software) - Clone or download this repo +- Browse into the Marlin folder and run `Marlin.ino` - In the IDE, under `Tools -> Board` select `Genuino Mega 2560` and `ATmega2560` - Open Marlin.ino in the Marlin directory of this repo - [Customize if needed](https://github.com/davidramiro/Marlin-AI3M/wiki/Customization-&-Compiling) (e.g. motor directions and type at line `559` to `566` and line `857` to `865` in `Configuration.h`) @@ -69,7 +71,7 @@ I provided three different precompiled hex files: One for no modifications on th - Flash the hex with Cura, OctoPrint or similar - Use a tool with a terminal (OctoPrint, Pronterface, Repetier Host, ...) to send commands to your printer. -- Connect to the printer and send the following commands: +- **Important** Connect to the printer and send the following commands: - `M502` - load hard coded default values - `M500` - save them to EEPROM @@ -80,7 +82,6 @@ I provided three different precompiled hex files: One for no modifications on th #### Calibration and other instructions have been moved to the [Wiki](https://github.com/davidramiro/Marlin-AI3M/wiki/Calibration). - ## Manual Mesh Bed Leveling If you have issues with an uneven bed, this is a great feature. @@ -103,7 +104,7 @@ If you have issues with an uneven bed, this is a great feature. - Your nozzle will now move to the first calibration position. - Don't adjust the bed itself with screws, only use software from here on! - Use a paper - I recommend using thermopaper like a receipt or baking paper -- Use the onscreen controls to lower or raise your nozzle until you feel a light resistance: (If you want to send the same command multiple times, select the item again, even though it is still marked red.) +- Use the onscreen controls to lower or raise your nozzle until you feel a light resistance: (**If you want to send the same command multiple times, select the item again, even though it is still marked red.**) ![Z axis controls][control] @@ -112,7 +113,7 @@ If you have issues with an uneven bed, this is a great feature. ![Next mesh point][next] - Repeat the last two steps until all 25 points are done. -- Your printer will beep, wait 20 seconds and then save: +- Your printer will beep, wait 20 seconds and then save (the printer will beep once more to confirm): ![Save to EEPROM][save] @@ -129,15 +130,14 @@ If you have issues with an uneven bed, this is a great feature. ### After leveling: -- Reboot the printer. - To ensure your mesh gets used on every print from now on, go into your slicer settings and look for the start GCode - Look for the Z-homing (either just `G28` or `G28 Z0`) command and insert these two right underneath it: ``` M501 M420 S1 ``` -- Enjoy never having to worry about an uneven bed again! - +- Your printer should now correctly print first layers even on a warped bed. +- When working on the printer, installing a new hotend or nozzle or the bed warping over time, a new Mesh Leveling procedure is recommended. #### Manual commands for use with OctoPrint etc.: @@ -156,6 +156,7 @@ G28 G26 C H200 P25 R25 ``` - To adjust your filament's needed temperature, change the number of the `H` parameter +- Default bed temperature is 60°C, if you need another temperature, add e.g. `B80` - If your leveling is good, you will have a complete pattern of your mesh on your bed that you can peel off in one piece - Don't worry if the test looks a bit messy, the important thing is just that the line width is the same all over the mesh - Optional: Hang it up on a wall to display it as a trophy of how great your leveling skills are. @@ -167,9 +168,9 @@ G26 C H200 P25 R25 [m600 demo]: https://kore.cc/i3mega/img/m600demo.jpg "M600 demo" -**Printing via USB is highly recommended for this.** +**BETA: This now also works without USB printing, via SD & display.** -#### Configuration: +#### Configuration (only needed once): - Send `M603 L0 U0` to use manual loading & unloading. - Send `M603 L538 U555` to use automatic loading & unloading - The `L` and `U` paramters define the load and unload length in mm. The values above work well on a stock setup, if you modded your extruder, bowden tube or hotend, you might need to adjust those. @@ -235,6 +236,11 @@ M304 After flashing the new version, issue a `M502` and `M500`. After that, enter every line you saved before and finish by saving with `M500`. +## Something went wrong? +No worries. You can easily go back to the default firmware and restore the default settings. +- Flash the hex file from the [manufacturer's website](http://www.anycubic3d.com/support/show/594016.html) (in case it's offline, I have uploaded the stock firmwares [here](https://kore.cc/i3mega/download/stockFW/) as well). +- After flashing, send `M502` and `M500`. Now your machine is exactly as it came out of the box. + ## Detailed changes: @@ -248,10 +254,14 @@ After flashing the new version, issue a `M502` and `M500`. After that, enter eve - G26 Mesh Validation enabled - Some redundant code removed to save memory - Minor tweaks on default jerk and acceleration -- Printcounter enabled (`M78`) +- Print statistics enabled (send `M78` to read them) - `M600` filament change feature enabled -- Screen resume for `M600` implemented -- Filament runout, stop and pause behaviour tweaked + - Implemented easy resume via display +- Filament runout behaviour tweaked + - Added purge and retract + - Move nozzle to park position on runout + - Prevent false positives by adding a small delay to the sensor +- Pause and stop behaviour tweaked ## Changes by [derhopp](https://github.com/derhopp/): @@ -337,3 +347,26 @@ Notable contributors include: ## License Marlin is published under the [GPLv3 license](https://github.com/MarlinFirmware/Marlin/blob/1.0.x/COPYING.md) because we believe in open development. The GPL comes with both rights and obligations. Whether you use Marlin firmware as the driver for your open or closed-source product, you must keep Marlin open, and you must provide your compatible Marlin source code to end users upon request. The most straightforward way to comply with the Marlin license is to make a fork of Marlin on Github, perform your modifications, and direct users to your modified fork. + +## Disclaimer + +``` +/* +* Flashing a custom firmware happens at your own risk. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS +* AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +``` From c1c2743452caa60eb14c78809c5998de8b0d25ab Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Tue, 12 Mar 2019 16:23:29 +0100 Subject: [PATCH 6/7] Rework pause, filament runout & abort - Park head with retract on pause and abort - Use native functions instead of Gcode - Loud beeps to alert user on runout - Fix potential looping issues by using flags - Fix "Stop failed" message on some occasions --- Marlin/AnycubicTFT.cpp | 157 ++++++++++++++++++++++++----------------- Marlin/AnycubicTFT.h | 2 + Marlin/Version.h | 6 +- README.md | 5 +- 4 files changed, 100 insertions(+), 70 deletions(-) diff --git a/Marlin/AnycubicTFT.cpp b/Marlin/AnycubicTFT.cpp index 4a70800..46bd506 100644 --- a/Marlin/AnycubicTFT.cpp +++ b/Marlin/AnycubicTFT.cpp @@ -34,6 +34,7 @@ #include "serial.h" #include "printcounter.h" #include "macros.h" +#include "buzzer.h" #ifdef ANYCUBIC_TFT_MODEL #include "AnycubicTFT.h" @@ -141,14 +142,16 @@ void AnycubicTFTClass::StartPrint(){ if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) { // was that a regular pause? if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) { - enqueue_and_echo_commands_P(PSTR("G91")); // relative mode - enqueue_and_echo_commands_P(PSTR("G1 Z-10 F240")); // lower nozzle again - enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode + enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: M24 Resume from regular pause"); + #endif + IsParked=false; // remove parked flag } } starttime=millis(); #ifdef SDSUPPORT - // was that a regular pause? + // was that a regular pause or are we starting a print? if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) { card.startFileprint(); // start or resume regularly } @@ -158,7 +161,7 @@ void AnycubicTFTClass::StartPrint(){ #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M24 Resume from Filament Runout"); #endif - PausedByRunout=false; // clear flag + PausedByRunout = IsParked = false; // clear flags #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag cleared"); #endif @@ -210,6 +213,7 @@ void AnycubicTFTClass::PausePrint(){ #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M25 sent, parking nozzle"); #endif + IsParked = true; // show filament runout prompt on screen ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); ANYCUBIC_SERIAL_ENTER(); @@ -240,40 +244,26 @@ void AnycubicTFTClass::PausePrint(){ } void AnycubicTFTClass::StopPrint(){ - - #ifdef SDSUPPORT - card.stopSDPrint(); - #endif + // stop print, disable heaters + card.stopSDPrint(); clear_command_queue(); - quickstop_stepper(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Stopped and cleared"); + #endif print_job_timer.stop(); thermalManager.disable_all_heaters(); - if((current_position[Z_AXIS]<150)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z20 F240\nG90")); - } - else if ((current_position[Z_AXIS]<190)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z10 F240\nG90")); - } - else if ((current_position[Z_AXIS]<200)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z5 F240\nG90")); - } - else if ((current_position[Z_AXIS]>=200)) - { - enqueue_and_echo_commands_P(PSTR("G91\nG1 Z1 F240\G90")); - } + IsParked = false; // we are not parked yet, do it in the display state routine + // turn off fan, cancel any heatups and set display state #if FAN_COUNT > 0 for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0; #endif + wait_for_heatup=false; TFTstate=ANYCUBIC_TFT_STATE_SDSTOP_REQ; - enqueue_and_echo_commands_P(PSTR("M27")); // force report of SD status } void AnycubicTFTClass::FilamentChangeResume(){ // call M108 to break out of M600 pause - + enqueue_and_echo_commands_P(PSTR("M108")); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: M108 Resume called"); #endif @@ -326,6 +316,23 @@ void AnycubicTFTClass::ReheatNozzle(){ TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; } +void AnycubicTFTClass::ParkAfterStop(){ + // only park the nozzle if homing was done before + if (!axis_unhomed_error()) { + // raize nozzle by 25mm respecting Z_MAX_POS + do_blocking_move_to_z(MIN(current_position[Z_AXIS] + 25, Z_MAX_POS), 5); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: SDSTOP: Park Z"); + #endif + // move bed and hotend to park position + do_blocking_move_to_xy((X_MIN_POS + 10), (Y_MAX_POS - 10), 100); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: SDSTOP: Park XY"); + #endif + } + enqueue_and_echo_commands_P(PSTR("M84")); // disable stepper motors + enqueue_and_echo_commands_P(PSTR("M27")); // force report of SD status +} float AnycubicTFTClass::CodeValue() { @@ -350,10 +357,14 @@ void AnycubicTFTClass::HandleSpecialMenu() enqueue_and_echo_commands_P(PSTR("M303 E-1 S60 C6 U1")); } else if (strcmp(SelectedDirectory, "")==0) { SERIAL_PROTOCOLLNPGM("Special Menu: Save EEPROM"); - enqueue_and_echo_commands_P(PSTR("M500\nM300 S1108 P105\nM300 S1661 P210")); + enqueue_and_echo_commands_P(PSTR("M500")); + buzzer.tone(105, 1108); + buzzer.tone(210, 1661); } else if (strcmp(SelectedDirectory, "")==0) { SERIAL_PROTOCOLLNPGM("Special Menu: Load FW Defaults"); - enqueue_and_echo_commands_P(PSTR("M502\nM300 S1661 P105\nM300 S1108 P210")); + enqueue_and_echo_commands_P(PSTR("M502")); + buzzer.tone(105, 1661); + buzzer.tone(210, 1108); } else if (strcmp(SelectedDirectory, "")==0) { SERIAL_PROTOCOLLNPGM("Special Menu: Preheat Bed"); enqueue_and_echo_commands_P(PSTR("M140 S60")); @@ -549,15 +560,15 @@ void AnycubicTFTClass::StateHandler() { switch (TFTstate) { case ANYCUBIC_TFT_STATE_IDLE: - #ifdef SDSUPPORT - if(card.sdprinting) { - TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; - starttime=millis(); + #ifdef SDSUPPORT + if(card.sdprinting) { + TFTstate=ANYCUBIC_TFT_STATE_SDPRINT; + starttime=millis(); - // --> Send print info to display... most probably print started via gcode - } - #endif - break; + // --> Send print info to display... most probably print started via gcode + } + #endif + break; case ANYCUBIC_TFT_STATE_SDPRINT: #ifdef SDSUPPORT if(!card.sdprinting) { @@ -588,6 +599,8 @@ void AnycubicTFTClass::StateHandler() #endif break; case ANYCUBIC_TFT_STATE_SDPAUSE_REQ: + ANYCUBIC_SERIAL_PROTOCOLPGM("J18"); + ANYCUBIC_SERIAL_ENTER(); #ifdef SDSUPPORT if((!card.sdprinting) && (!planner.movesplanned())) { // We have to wait until the sd card printing has been settled @@ -596,16 +609,21 @@ void AnycubicTFTClass::StateHandler() #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Regular Pause requested"); #endif - enqueue_and_echo_commands_P(PSTR("G91")); // relative mode - enqueue_and_echo_commands_P(PSTR("G1 E-2 F1800")); // retract 2mm - enqueue_and_echo_commands_P(PSTR("G1 Z10 F240")); // lift nozzle by 10mm - enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode + if(!IsParked) { + // park head and retract 2mm + enqueue_and_echo_commands_P(PSTR("M125 L2")); + IsParked = true; + } } else if((PausedByRunout)) { // filament runout, retract and beep enqueue_and_echo_commands_P(PSTR("G91")); // relative mode enqueue_and_echo_commands_P(PSTR("G1 E-3 F1800")); // retract 3mm enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode - enqueue_and_echo_commands_P(PSTR("M300 S1567 P1000\nM300 S2093 P3000")); + buzzer.tone(200, 1567); + buzzer.tone(200, 1174); + buzzer.tone(200, 1567); + buzzer.tone(200, 1174); + buzzer.tone(2000, 1567); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("DEBUG: Filament runout - Retract, beep and park."); #endif @@ -618,8 +636,6 @@ void AnycubicTFTClass::StateHandler() TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_OOF; } #endif - ANYCUBIC_SERIAL_PROTOCOLPGM("J18"); // J18 pausing print done - ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused done... J18"); #endif @@ -628,14 +644,20 @@ void AnycubicTFTClass::StateHandler() break; case ANYCUBIC_TFT_STATE_SDSTOP_REQ: #ifdef SDSUPPORT + ANYCUBIC_SERIAL_PROTOCOLPGM("J16");// J16 stop print + ANYCUBIC_SERIAL_ENTER(); if((!card.sdprinting) && (!planner.movesplanned())) { - ANYCUBIC_SERIAL_PROTOCOLPGM("J16");// J16 stop print - ANYCUBIC_SERIAL_ENTER(); + // enter idle display state TFTstate=ANYCUBIC_TFT_STATE_IDLE; #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: SD print stopped... J16"); + SERIAL_ECHOLNPGM("TFT Serial Debug: SD print stopped... J16"); #endif - enqueue_and_echo_commands_P(PSTR("M84")); + } + // did we park the hotend already? + if((!IsParked) && (!card.sdprinting) && (!planner.movesplanned())) { + enqueue_and_echo_commands_P(PSTR("G91\nG1 E-1 F1800\nG90")); //retract + ParkAfterStop(); + IsParked = true; } #endif break; @@ -668,24 +690,28 @@ void AnycubicTFTClass::FilamentRunout() // if three seconds passed and the sensor is still triggered, // we trigger the filament runout status if ((FilamentTestStatus>FilamentTestLastStatus) && (ELAPSED(fil_ms, fil_delay))) { - #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: 3000ms delay done"); - #endif - if((card.sdprinting==true)) { - PausedByRunout=true; // set runout pause flag + if (!IsParked){ #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set"); + SERIAL_ECHOLNPGM("DEBUG: 3000ms delay done"); #endif - PausePrint(); - } else if((card.sdprinting==false)) { - ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK - ANYCUBIC_SERIAL_ENTER(); - #ifdef ANYCUBIC_TFT_DEBUG - SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); - #endif - FilamentTestLastStatus=FilamentTestStatus; + if((card.sdprinting==true)) { + PausedByRunout=true; // set runout pause flag + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set"); + #endif + PausePrint(); + } else if((card.sdprinting==false)) { + ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK + ANYCUBIC_SERIAL_ENTER(); + #ifdef ANYCUBIC_TFT_DEBUG + SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout... J15"); + #endif + FilamentTestLastStatus=FilamentTestStatus; + } } + FilamentTestLastStatus=FilamentTestStatus; } + } else if(FilamentTestStatus!=FilamentTestLastStatus) { FilamentSetMillis=true; // set the timestamps on the next loop again @@ -869,6 +895,10 @@ void AnycubicTFTClass::GetCommandFromTFT() if((card.sdprinting) || (TFTstate==ANYCUBIC_TFT_STATE_SDOUTAGE)) { StopPrint(); + } else { + ANYCUBIC_SERIAL_PROTOCOLPGM("J16"); + ANYCUBIC_SERIAL_ENTER(); + TFTstate=ANYCUBIC_TFT_STATE_IDLE; } #endif break; @@ -913,6 +943,7 @@ void AnycubicTFTClass::GetCommandFromTFT() if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE) && (card.isFileOpen())) { StartPrint(); + IsParked = false; ANYCUBIC_SERIAL_PROTOCOLPGM("J04"); // J04 Starting Print ANYCUBIC_SERIAL_ENTER(); #ifdef ANYCUBIC_TFT_DEBUG diff --git a/Marlin/AnycubicTFT.h b/Marlin/AnycubicTFT.h index 6ae359f..76d7b96 100644 --- a/Marlin/AnycubicTFT.h +++ b/Marlin/AnycubicTFT.h @@ -75,6 +75,7 @@ private: uint8_t tmp_extruder=0; char LastSDstatus=0; uint16_t HeaterCheckCount=0; + bool IsParked = false; struct OutageDataStruct { char OutageDataVersion; @@ -102,6 +103,7 @@ private: void FilamentChangePause(); void FilamentChangeResume(); void ReheatNozzle(); + void ParkAfterStop(); char SelectedDirectory[30]; uint8_t SpecialMenu=false; diff --git a/Marlin/Version.h b/Marlin/Version.h index 0da8739..8e949da 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -41,20 +41,20 @@ * Defines the version of the Marlin-AI3M build. Not to be confused with * Marlin's own build number, e.g. 1.1.9. */ - #define CUSTOM_BUILD_VERSION "v1.4.3" + #define CUSTOM_BUILD_VERSION "v1.4.4" /** * Verbose version identifier which should contain a reference to the location * from where the binary was downloaded or the source code was compiled. */ - #define DETAILED_BUILD_VERSION SHORT_BUILD_VERSION "(Github, davidramiro)" + #define DETAILED_BUILD_VERSION SHORT_BUILD_VERSION " (Github, davidramiro)" /** * The STRING_DISTRIBUTION_DATE represents when the binary file was built, * here we define this default string as the date where the latest release * version was tagged. */ - #define STRING_DISTRIBUTION_DATE "2019-03-06" + #define STRING_DISTRIBUTION_DATE "2019-03-11" /** * Required minimum Configuration.h and Configuration_adv.h file versions. diff --git a/README.md b/README.md index ea6150f..ffc3b3e 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ Note: This is just a firmware, not magic. A big part of print quality still depe A German translation of the instructions can be found [here](https://kore.cc/i3mega/download/marlin-ai3m_german.pdf). - - ## Why use this? While the i3 Mega is a great printer for its price and produces fantastic results in stock, there are some issues that are easily addressed: @@ -33,7 +31,7 @@ While the i3 Mega is a great printer for its price and produces fantastic result - No need to slice and upload custom bed leveling tests, test it with a single GCode command - Easily start an auto PID tune or mesh bed leveling via the special menu (insert SD card, select special menu and press the round arrow) - Filament change feature enabled: Switch colors/material mid print (instructions below) and control it via display. -- The filament runout sensor functionality has been overhauled and improved: The hotend now parks and retracts automatically and purges after loading a new spool. +- The filament runout, pause and stop functionality have been overhauled and improved: The hotend now parks and retracts (on pause or stop) and purges automatically (on resume). ## Known issues: @@ -41,7 +39,6 @@ While the i3 Mega is a great printer for its price and produces fantastic result - Estimated print times from your slicer might be slightly off. - Special characters on any file or folders name on the SD card will cause the file menu to freeze. Simply replace or remove every special character (Chinese, Arabic, Russian, accents, German & Scandinavian umlauts, ...) from the name. Symbols like dashes or underscores are no problem. **Important note: On the SD card that comes with the printer there is a folder with Chinese characters in it by default. Please rename or remove it.** -- Cancelling prints after pausing may show an error. Simply resume the print before canceling. Protip: Switch to OctoPrint. ## How to flash this? From 79f559e9aff8f605b6ca20ba195eb8c41142fd48 Mon Sep 17 00:00:00 2001 From: David Ramiro Date: Wed, 13 Mar 2019 11:40:25 +0100 Subject: [PATCH 7/7] Implement heatbed cooldown routine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - M888: Cooldown routine for the Anycubic Ultrabase (EXPERIMENTAL): This is meant to be placed at the end Gcode of your slicer. It hovers over the print bed and does circular movements while running the fan. Works best with custom fan ducts. - T: Target bed temperature (min 15°C), 30°C if not specified - S: Fan speed between 0 and 255, full speed if not specified Thanks to @kulfuerst for the suggestion! --- Marlin/Marlin_main.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++ Marlin/Version.h | 2 +- README.md | 7 ++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7a82655..6611bc9 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -228,6 +228,7 @@ * M867 - Enable/disable or toggle error correction for position encoder modules. * M868 - Report or set position encoder module error correction threshold. * M869 - Report position encoder module error. + * M888 - Ultrabase cooldown: Let the parts cooling fan hover above the finished print to cool down the bed. EXPERIMENTAL FEATURE! * M900 - Get or Set Linear Advance K-factor. (Requires LIN_ADVANCE) * M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given. (Requires at least one _DRIVER_TYPE defined as TMC2130/TMC2208/TMC2660) * M907 - Set digital trimpot motor current using axis codes. (Requires a board with digital trimpots) @@ -11403,6 +11404,56 @@ inline void gcode_M502() { } #endif // MAX7219_GCODE + /** + * M888: Cooldown routine for the Anycubic Ultrabase (EXPERIMENTAL): + * This is meant to be placed at the end Gcode of your slicer. + * It hovers over the print bed and does circular movements while + * running the fan. Works best with custom fan ducts. + * + * T Target bed temperature (min 15°C), 30°C if not specified + * S Fan speed between 0 and 255, full speed if not specified + */ + inline void gcode_M888() { + // don't do this if the machine is not homed + if (axis_unhomed_error()) return; + + const float cooldown_arc[2] = { 50, 50 }; + const uint8_t cooldown_target = MAX((parser.ushortval('T', 30)), 15); + + // set hotbed temperate to zero + thermalManager.setTargetBed(0); + SERIAL_PROTOCOLLNPGM("Ultrabase cooldown started"); + + // set fan to speed , if undefined blast at full speed + uint8_t cooldown_fanspeed = parser.ushortval('S', 255); + fanSpeeds[0] = MIN(cooldown_fanspeed, 255U); + + // raise z by 2mm and move to X50, Y50 + do_blocking_move_to_z(MIN(current_position[Z_AXIS] + 2, Z_MAX_POS), 5); + do_blocking_move_to_xy(50, 50, 100); + + while ((thermalManager.degBed() > cooldown_target)) { + // queue arc movement + gcode_get_destination(); + plan_arc(destination, cooldown_arc, true); + SERIAL_PROTOCOLLNPGM("Target not reached, queued an arc"); + + // delay while arc is in progress + while (planner.movesplanned()) { + idle(); + } + idle(); + } + // the bed should be under now + fanSpeeds[0]=0; + do_blocking_move_to_xy(MAX(X_MIN_POS, 10), MIN(Y_MAX_POS, 190), 100); + BUZZ(100, 659); + BUZZ(150, 1318); + enqueue_and_echo_commands_P(PSTR("M84")); + SERIAL_PROTOCOLLNPGM("M888 cooldown routine done"); + } + + #if ENABLED(LIN_ADVANCE) /** * M900: Get or Set Linear Advance K-factor @@ -13138,6 +13189,8 @@ void process_parsed_command() { case 869: gcode_M869(); break; // M869: Report axis error #endif + case 888: gcode_M888(); break; // M888: Ultrabase cooldown (EXPERIMENTAL) + #if ENABLED(LIN_ADVANCE) case 900: gcode_M900(); break; // M900: Set Linear Advance K factor #endif diff --git a/Marlin/Version.h b/Marlin/Version.h index 8e949da..faa49fa 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -54,7 +54,7 @@ * here we define this default string as the date where the latest release * version was tagged. */ - #define STRING_DISTRIBUTION_DATE "2019-03-11" + #define STRING_DISTRIBUTION_DATE "2019-03-13" /** * Required minimum Configuration.h and Configuration_adv.h file versions. diff --git a/README.md b/README.md index ffc3b3e..ef7c8d1 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,12 @@ While the i3 Mega is a great printer for its price and produces fantastic result - Easily start an auto PID tune or mesh bed leveling via the special menu (insert SD card, select special menu and press the round arrow) - Filament change feature enabled: Switch colors/material mid print (instructions below) and control it via display. - The filament runout, pause and stop functionality have been overhauled and improved: The hotend now parks and retracts (on pause or stop) and purges automatically (on resume). +- Added `M888` cooldown routine for the Anycubic Ultrabase (EXPERIMENTAL): This is meant to be placed at the end Gcode of your slicer. It hovers over the print bed and does circular movements while running the fan. Works best with custom fan ducts. + - Optional parameters: + - `T`: Target bed temperature (min 15°C), 30°C if not specified (do not set this under room temperature) + - `S`: Fan speed between 0 and 255, full speed if not specified + - e.g. `M888 S191 T25`: run the fan at 75% until the bed has cooled down to 25°C + ## Known issues: @@ -259,6 +265,7 @@ No worries. You can easily go back to the default firmware and restore the defau - Move nozzle to park position on runout - Prevent false positives by adding a small delay to the sensor - Pause and stop behaviour tweaked +- Added `M888` cooldown routine for the Anycubic Ultrabase ## Changes by [derhopp](https://github.com/derhopp/):