Scott Lahteine 2020-04-22 22:02:31 -05:00
parent 76efba686b
commit d5b791a26a

View file

@ -71,7 +71,7 @@
#define MAX_CURLY_COMMAND (32 + LONG_FILENAME_LENGTH) * 2
// Track incoming command bytes from the LCD
int inbound_count;
uint16_t inbound_count;
// For sending print completion messages
bool last_printing_status = false;
@ -361,29 +361,38 @@ void process_lcd_command(const char* command) {
DEBUG_ECHOLNPAIR("UNKNOWN COMMAND FORMAT ", command);
}
//
// Parse LCD commands mixed with G-Code
void parse_lcd_byte(byte b) {
static bool parsing_lcd_cmd = false;
//
void parse_lcd_byte(const byte b) {
static char inbound_buffer[MAX_CURLY_COMMAND];
if (!parsing_lcd_cmd) {
if (b == '{' || b == '\n' || b == '\r') { // A line-ending or opening brace
parsing_lcd_cmd = b == '{'; // Brace opens an LCD command
if (inbound_count) { // Looks like a G-code is in the buffer
inbound_buffer[inbound_count] = '\0'; // Reset before processing
inbound_count = 0;
static uint8_t parsing = 0; // Parsing state
static bool prevcr = false; // Was the last c a CR?
const char c = b & 0x7F;
if (parsing) {
const bool is_lcd = parsing == 1; // 1 for LCD
if ( ( is_lcd && c == '}') // Closing brace on LCD command
|| (!is_lcd && c == '\n') // LF on a G-code command
) {
inbound_buffer[inbound_count] = '\0'; // Reset before processing
parsing = 0; // Unflag and...
inbound_count = 0; // Reset buffer index
if (parsing == 1)
process_lcd_command(inbound_buffer); // Handle the LCD command
else
queue.enqueue_one_now(inbound_buffer); // Handle the G-code command
}
}
else if (inbound_count < MAX_CURLY_COMMAND - 2)
inbound_buffer[inbound_count++] = is_lcd ? c : b; // Buffer while space remains
}
else if (b == '}') { // Closing brace on an LCD command
parsing_lcd_cmd = false; // Unflag and...
inbound_buffer[inbound_count] = '\0'; // reset before processing
inbound_count = 0;
process_lcd_command(inbound_buffer); // Handle the LCD command
else {
if (c == '{') parsing = 1; // Brace opens an LCD command
else if (prevcr && c == '\n') parsing = 2; // CRLF indicates G-code
prevcr = (c == '\r'); // Remember if it was a CR
}
else if (inbound_count < MAX_CURLY_COMMAND - 2)
inbound_buffer[inbound_count++] = b; // Buffer only if space remains
}
/**
@ -433,9 +442,8 @@ namespace ExtUI {
update_usb_status(false);
// now drain commands...
while (LCD_SERIAL.available()) {
parse_lcd_byte((byte)LCD_SERIAL.read() & 0x7F);
}
while (LCD_SERIAL.available())
parse_lcd_byte((byte)LCD_SERIAL.read());
#if ENABLED(SDSUPPORT)
// The way last printing status works is simple: