diff --git a/Marlin/src/lcd/HardwareSerial.cpp b/Marlin/src/lcd/HardwareSerial.cpp index 2727125e..ab029414 100755 --- a/Marlin/src/lcd/HardwareSerial.cpp +++ b/Marlin/src/lcd/HardwareSerial.cpp @@ -37,6 +37,8 @@ #include "HardwareSerial.h" +millis_t previous_cmd_ms = 0; + // Define constants and variables for buffering incoming serial data. We're // using a ring buffer (I think), in which head is the index of the location // to which to write the next incoming character and tail is the index of the @@ -310,6 +312,33 @@ HardwareSerialClass::operator bool() HardwareSerialClass HardwareSerial(&rx_buffer_ajg, &tx_buffer_ajg, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3); #endif +void Newok_to_send() { + previous_cmd_ms = millis(); + /* + if (!send_ok[cmd_queue_index_r]) return; + // SERIAL_PROTOCOLPGM(MSG_OK); + #if ENABLED(ADVANCED_OK) + char* p = command_queue[cmd_queue_index_r]; + if (*p == 'N') { + SERIAL_PROTOCOL(' '); + SERIAL_ECHO(*p++); + while (NUMERIC_SIGNED(*p)) + SERIAL_ECHO(*p++); + } + SERIAL_PROTOCOLPGM(" P"); SERIAL_PROTOCOL(int(BLOCK_BUFFER_SIZE - planner.movesplanned() - 1)); + SERIAL_PROTOCOLPGM(" B"); SERIAL_PROTOCOL(BUFSIZE - commands_in_queue); + #endif + SERIAL_EOL; + */ +} +void NEWFlushSerialRequestResend() { + //char command_queue[cmd_queue_index_r][100]="Resend:"; + HardwareSerial.flush(); + // SERIAL_PROTOCOLPGM(MSG_RESEND); +// SERIAL_PROTOCOLLN(gcode_LastN + 1); + Newok_to_send(); +} + #endif #endif // whole file diff --git a/Marlin/src/lcd/HardwareSerial.h b/Marlin/src/lcd/HardwareSerial.h index b8048ed7..de91bd1f 100755 --- a/Marlin/src/lcd/HardwareSerial.h +++ b/Marlin/src/lcd/HardwareSerial.h @@ -141,4 +141,7 @@ FORCE_INLINE void HardwareSerialprintPGM(const char *str) } } +void NEWFlushSerialRequestResend(); +void NEWClearToSend(); + #endif diff --git a/Marlin/src/lcd/anycubic_touchscreen.cpp b/Marlin/src/lcd/anycubic_touchscreen.cpp index d5afbea6..7cb8b15f 100755 --- a/Marlin/src/lcd/anycubic_touchscreen.cpp +++ b/Marlin/src/lcd/anycubic_touchscreen.cpp @@ -55,7 +55,7 @@ unsigned char ResumingFlag = 0; #endif //#define MAX_PRINTABLE_FILENAME_LEN 21 -#define MAX_PRINTABLE_FILENAME_LEN 22 +#define MAX_PRINTABLE_FILENAME_LEN 24 void setup_OutageTestPin() { @@ -437,6 +437,7 @@ void AnycubicTouchscreenClass::HandleSpecialMenu() SERIAL_ECHOPAIR(" DEBUG: Special Menu Selection: ", currentTouchscreenSelection); SERIAL_EOL(); #endif + delay(10); if (strcasestr(currentTouchscreenSelection, "") != NULL) { SpecialMenu = true; @@ -608,9 +609,10 @@ void AnycubicTouchscreenClass::PrintList() else if (card.isMounted()) { uint16_t count = filenumber; - uint16_t max_files = 0; + uint16_t max_files; uint16_t dir_files = card.countFilesInWorkDir(); + delay(10); // What is this shit? What if there are exactely 3 files+folders? // TODO: find something better than this crap. if ((dir_files - filenumber) < 4) @@ -671,32 +673,19 @@ void AnycubicTouchscreenClass::PrintList() } } } + outputString[fileNameLen] = '\0'; - if (strcasestr(outputString, ".gcode") == NULL) { - outputString[MAX_PRINTABLE_FILENAME_LEN - 7] = '.'; - outputString[MAX_PRINTABLE_FILENAME_LEN - 6] = 'g'; - outputString[MAX_PRINTABLE_FILENAME_LEN - 5] = 'c'; - outputString[MAX_PRINTABLE_FILENAME_LEN - 4] = 'o'; - outputString[MAX_PRINTABLE_FILENAME_LEN - 3] = 'd'; - outputString[MAX_PRINTABLE_FILENAME_LEN - 2] = 'e'; - outputString[MAX_PRINTABLE_FILENAME_LEN - 1] = '\0'; - } - - - - if (card.flag.filenameIsDir) { - /* - HARDWARE_SERIAL_PROTOCOLPGM("/"); + HARDWARE_SERIAL_PROTOCOL("/"); HARDWARE_SERIAL_PROTOCOLLN(card.filename); - HARDWARE_SERIAL_PROTOCOLPGM("/"); - HARDWARE_SERIAL_PROTOCOLLN(outputString); + HARDWARE_SERIAL_PROTOCOL("DIR_"); + HARDWARE_SERIAL_PROTOCOL(outputString); + HARDWARE_SERIAL_PROTOCOLLN(".gcode"); SERIAL_ECHO(count); SERIAL_ECHOPGM(": /"); SERIAL_ECHOLN(outputString); - */ } else { @@ -710,11 +699,6 @@ void AnycubicTouchscreenClass::PrintList() } } #endif - else - { - //HARDWARE_SERIAL_PROTOCOLLN(".gcode"); - //HARDWARE_SERIAL_PROTOCOLLN(".gcode"); - } } void AnycubicTouchscreenClass::CheckSDCardChange() @@ -959,36 +943,88 @@ void AnycubicTouchscreenClass::FilamentRunout() } } + +static boolean TFTcomment_mode = false; + void AnycubicTouchscreenClass::GetCommandFromTFT() { + char *starpos = NULL; - while (HardwareSerial.available() > 0 && TFTbuflen < TFTBUFSIZE) - { - serial3_char = HardwareSerial.read(); - if (serial3_char == '\n' || - serial3_char == '\r' || - serial3_char == ':' || - serial3_count >= (TFT_MAX_CMD_SIZE - 1)) + while( HardwareSerial.available() > 0 && TFTbuflen < TFTBUFSIZE) + { + serial3_char = HardwareSerial.read(); + if(serial3_char == '\n' || serial3_char == '\r' || (serial3_char == ':' && TFTcomment_mode == false) || serial3_count >= (TFT_MAX_CMD_SIZE - 1) ) { - if (!serial3_count) - { //if empty line + if(!serial3_count) { //if empty line + TFTcomment_mode = false; //for new command return; - } + } + + TFTcmdbuffer[TFTbufindw][serial3_count] = 0; //terminate string + if(!TFTcomment_mode) + { + TFTcomment_mode = false; //for new command + + //TFTfromsd[TFTbufindw] = false; + + if(strchr(TFTcmdbuffer[TFTbufindw], 'N') != NULL) + { + /* + TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'N'); + gcode_N = (strtol(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL, 10)); + if(gcode_N != gcode_LastN+1 && (strstr_P(TFTcmdbuffer[TFTbufindw], PSTR("M110")) == NULL) ) + { + HARDWARE_SERIAL_ERROR_START; + NEWFlushSerialRequestResend(); + serial3_count = 0; + return; + } + */ + + if(strchr(TFTcmdbuffer[TFTbufindw], '*') != NULL) + { + byte checksum = 0; + byte count = 0; + while(TFTcmdbuffer[TFTbufindw][count] != '*') checksum = checksum^TFTcmdbuffer[TFTbufindw][count++]; + TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], '*'); + + if( (int)(strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL)) != checksum) + { + HARDWARE_SERIAL_ERROR_START; + NEWFlushSerialRequestResend(); - TFTcmdbuffer[TFTbufindw][serial3_count] = 0; //terminate string - - if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL)) + HARDWARE_SERIAL_ERROR_START; + NEWFlushSerialRequestResend(); + serial3_count = 0; + return; + } + //if no errors, continue parsing + } + else + { + HARDWARE_SERIAL_ERROR_START; + NEWFlushSerialRequestResend(); + serial3_count = 0; + return; + } + //gcode_LastN = gcode_N; + //if no errors, continue parsing + } + else // if we don't receive 'N' but still see '*' + { + if((strchr(TFTcmdbuffer[TFTbufindw], '*') != NULL)) + { + HARDWARE_SERIAL_ERROR_START; + serial3_count = 0; + return; + } + } + + + 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) + switch((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL)))) { case 0: //A0 GET HOTEND TEMP @@ -1093,8 +1129,10 @@ void AnycubicTouchscreenClass::GetCommandFromTFT() } else { - if (CodeSeen('S')) + if (CodeSeen('S')) { filenumber = CodeValue(); + } + HARDWARE_SERIAL_PROTOCOLPGM("FN "); // Filelist start HARDWARE_SERIAL_ENTER(); @@ -1510,19 +1548,22 @@ void AnycubicTouchscreenClass::GetCommandFromTFT() break; default: break; - } - } - TFTbufindw = (TFTbufindw + 1) % TFTBUFSIZE; - TFTbuflen += 1; - serial3_count = 0; - } - else - { - TFTcmdbuffer[TFTbufindw][serial3_count++] = serial3_char; - } - } + } + } + TFTbufindw = (TFTbufindw + 1)%TFTBUFSIZE; + TFTbuflen += 1; + } + serial3_count = 0; //clear buffer + } + else + { + if(serial3_char == ';') TFTcomment_mode = true; + if(!TFTcomment_mode) TFTcmdbuffer[TFTbufindw][serial3_count++] = serial3_char; + } + } } + void AnycubicTouchscreenClass::CommandScan() { CheckHeaterError(); diff --git a/Marlin/src/lcd/anycubic_touchscreen.h b/Marlin/src/lcd/anycubic_touchscreen.h index 0d5a1bc3..53de777c 100755 --- a/Marlin/src/lcd/anycubic_touchscreen.h +++ b/Marlin/src/lcd/anycubic_touchscreen.h @@ -33,7 +33,7 @@ char *ftostr32(const float &); #define TFTBUFSIZE 4 #define TFT_MAX_CMD_SIZE 96 -#define MSG_MY_VERSION "Knutwurst-1.0.5" +#define MSG_MY_VERSION "Knutwurst-1.0.7" #define ANYCUBIC_TFT_STATE_IDLE 0 #define ANYCUBIC_TFT_STATE_SDPRINT 1 @@ -119,6 +119,7 @@ private: char currentFileOrDirectory[30]; uint8_t SpecialMenu = false; uint8_t FilamentSensorEnabled = true; + #if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR) char FilamentTestStatus = false;