Add original anycubic stuff for tft serial handling including serial flush in case of error.
This commit is contained in:
@@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
|
|
||||||
|
millis_t previous_cmd_ms = 0;
|
||||||
|
|
||||||
// Define constants and variables for buffering incoming serial data. We're
|
// 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
|
// 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
|
// 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);
|
HardwareSerialClass HardwareSerial(&rx_buffer_ajg, &tx_buffer_ajg, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
|
||||||
#endif
|
#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
|
||||||
|
|
||||||
#endif // whole file
|
#endif // whole file
|
||||||
|
@@ -141,4 +141,7 @@ FORCE_INLINE void HardwareSerialprintPGM(const char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NEWFlushSerialRequestResend();
|
||||||
|
void NEWClearToSend();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -55,7 +55,7 @@ unsigned char ResumingFlag = 0;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#define MAX_PRINTABLE_FILENAME_LEN 21
|
//#define MAX_PRINTABLE_FILENAME_LEN 21
|
||||||
#define MAX_PRINTABLE_FILENAME_LEN 22
|
#define MAX_PRINTABLE_FILENAME_LEN 24
|
||||||
|
|
||||||
void setup_OutageTestPin()
|
void setup_OutageTestPin()
|
||||||
{
|
{
|
||||||
@@ -437,6 +437,7 @@ void AnycubicTouchscreenClass::HandleSpecialMenu()
|
|||||||
SERIAL_ECHOPAIR(" DEBUG: Special Menu Selection: ", currentTouchscreenSelection);
|
SERIAL_ECHOPAIR(" DEBUG: Special Menu Selection: ", currentTouchscreenSelection);
|
||||||
SERIAL_EOL();
|
SERIAL_EOL();
|
||||||
#endif
|
#endif
|
||||||
|
delay(10);
|
||||||
if (strcasestr(currentTouchscreenSelection, "<Special Menu>") != NULL)
|
if (strcasestr(currentTouchscreenSelection, "<Special Menu>") != NULL)
|
||||||
{
|
{
|
||||||
SpecialMenu = true;
|
SpecialMenu = true;
|
||||||
@@ -608,9 +609,10 @@ void AnycubicTouchscreenClass::PrintList()
|
|||||||
else if (card.isMounted())
|
else if (card.isMounted())
|
||||||
{
|
{
|
||||||
uint16_t count = filenumber;
|
uint16_t count = filenumber;
|
||||||
uint16_t max_files = 0;
|
uint16_t max_files;
|
||||||
uint16_t dir_files = card.countFilesInWorkDir();
|
uint16_t dir_files = card.countFilesInWorkDir();
|
||||||
|
|
||||||
|
delay(10);
|
||||||
// What is this shit? What if there are exactely 3 files+folders?
|
// What is this shit? What if there are exactely 3 files+folders?
|
||||||
// TODO: find something better than this crap.
|
// TODO: find something better than this crap.
|
||||||
if ((dir_files - filenumber) < 4)
|
if ((dir_files - filenumber) < 4)
|
||||||
@@ -671,32 +673,19 @@ void AnycubicTouchscreenClass::PrintList()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outputString[fileNameLen] = '\0';
|
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)
|
if (card.flag.filenameIsDir)
|
||||||
{
|
{
|
||||||
/*
|
HARDWARE_SERIAL_PROTOCOL("/");
|
||||||
HARDWARE_SERIAL_PROTOCOLPGM("/");
|
|
||||||
HARDWARE_SERIAL_PROTOCOLLN(card.filename);
|
HARDWARE_SERIAL_PROTOCOLLN(card.filename);
|
||||||
HARDWARE_SERIAL_PROTOCOLPGM("/");
|
HARDWARE_SERIAL_PROTOCOL("DIR_");
|
||||||
HARDWARE_SERIAL_PROTOCOLLN(outputString);
|
HARDWARE_SERIAL_PROTOCOL(outputString);
|
||||||
|
HARDWARE_SERIAL_PROTOCOLLN(".gcode");
|
||||||
SERIAL_ECHO(count);
|
SERIAL_ECHO(count);
|
||||||
SERIAL_ECHOPGM(": /");
|
SERIAL_ECHOPGM(": /");
|
||||||
SERIAL_ECHOLN(outputString);
|
SERIAL_ECHOLN(outputString);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -710,11 +699,6 @@ void AnycubicTouchscreenClass::PrintList()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
|
||||||
{
|
|
||||||
//HARDWARE_SERIAL_PROTOCOLLN("<Special Menu>.gcode");
|
|
||||||
//HARDWARE_SERIAL_PROTOCOLLN("<Special Menu>.gcode");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnycubicTouchscreenClass::CheckSDCardChange()
|
void AnycubicTouchscreenClass::CheckSDCardChange()
|
||||||
@@ -959,36 +943,88 @@ void AnycubicTouchscreenClass::FilamentRunout()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static boolean TFTcomment_mode = false;
|
||||||
|
|
||||||
void AnycubicTouchscreenClass::GetCommandFromTFT()
|
void AnycubicTouchscreenClass::GetCommandFromTFT()
|
||||||
{
|
{
|
||||||
|
|
||||||
char *starpos = NULL;
|
char *starpos = NULL;
|
||||||
while (HardwareSerial.available() > 0 && TFTbuflen < TFTBUFSIZE)
|
while( HardwareSerial.available() > 0 && TFTbuflen < TFTBUFSIZE)
|
||||||
{
|
{
|
||||||
serial3_char = HardwareSerial.read();
|
serial3_char = HardwareSerial.read();
|
||||||
if (serial3_char == '\n' ||
|
if(serial3_char == '\n' || serial3_char == '\r' || (serial3_char == ':' && TFTcomment_mode == false) || serial3_count >= (TFT_MAX_CMD_SIZE - 1) )
|
||||||
serial3_char == '\r' ||
|
|
||||||
serial3_char == ':' ||
|
|
||||||
serial3_count >= (TFT_MAX_CMD_SIZE - 1))
|
|
||||||
{
|
{
|
||||||
if (!serial3_count)
|
if(!serial3_count) { //if empty line
|
||||||
{ //if empty line
|
TFTcomment_mode = false; //for new command
|
||||||
return;
|
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
|
HARDWARE_SERIAL_ERROR_START;
|
||||||
|
NEWFlushSerialRequestResend();
|
||||||
if ((strchr(TFTcmdbuffer[TFTbufindw], 'A') != NULL))
|
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');
|
TFTstrchr_pointer = strchr(TFTcmdbuffer[TFTbufindw], 'A');
|
||||||
a_command = ((int)((strtod(&TFTcmdbuffer[TFTbufindw][TFTstrchr_pointer - TFTcmdbuffer[TFTbufindw] + 1], NULL))));
|
switch((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
|
case 0: //A0 GET HOTEND TEMP
|
||||||
@@ -1093,8 +1129,10 @@ void AnycubicTouchscreenClass::GetCommandFromTFT()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (CodeSeen('S'))
|
if (CodeSeen('S')) {
|
||||||
filenumber = CodeValue();
|
filenumber = CodeValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HARDWARE_SERIAL_PROTOCOLPGM("FN "); // Filelist start
|
HARDWARE_SERIAL_PROTOCOLPGM("FN "); // Filelist start
|
||||||
HARDWARE_SERIAL_ENTER();
|
HARDWARE_SERIAL_ENTER();
|
||||||
@@ -1510,19 +1548,22 @@ void AnycubicTouchscreenClass::GetCommandFromTFT()
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TFTbufindw = (TFTbufindw + 1) % TFTBUFSIZE;
|
TFTbufindw = (TFTbufindw + 1)%TFTBUFSIZE;
|
||||||
TFTbuflen += 1;
|
TFTbuflen += 1;
|
||||||
serial3_count = 0;
|
}
|
||||||
}
|
serial3_count = 0; //clear buffer
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
TFTcmdbuffer[TFTbufindw][serial3_count++] = serial3_char;
|
{
|
||||||
}
|
if(serial3_char == ';') TFTcomment_mode = true;
|
||||||
}
|
if(!TFTcomment_mode) TFTcmdbuffer[TFTbufindw][serial3_count++] = serial3_char;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AnycubicTouchscreenClass::CommandScan()
|
void AnycubicTouchscreenClass::CommandScan()
|
||||||
{
|
{
|
||||||
CheckHeaterError();
|
CheckHeaterError();
|
||||||
|
@@ -33,7 +33,7 @@ char *ftostr32(const float &);
|
|||||||
|
|
||||||
#define TFTBUFSIZE 4
|
#define TFTBUFSIZE 4
|
||||||
#define TFT_MAX_CMD_SIZE 96
|
#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_IDLE 0
|
||||||
#define ANYCUBIC_TFT_STATE_SDPRINT 1
|
#define ANYCUBIC_TFT_STATE_SDPRINT 1
|
||||||
@@ -119,6 +119,7 @@ private:
|
|||||||
char currentFileOrDirectory[30];
|
char currentFileOrDirectory[30];
|
||||||
uint8_t SpecialMenu = false;
|
uint8_t SpecialMenu = false;
|
||||||
uint8_t FilamentSensorEnabled = true;
|
uint8_t FilamentSensorEnabled = true;
|
||||||
|
|
||||||
|
|
||||||
#if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR)
|
#if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR)
|
||||||
char FilamentTestStatus = false;
|
char FilamentTestStatus = false;
|
||||||
|
Reference in New Issue
Block a user