Scott Lahteine 5 years ago
parent
commit
d5b791a26a
  1. 48
      Marlin/src/lcd/extui_malyan_lcd.cpp

48
Marlin/src/lcd/extui_malyan_lcd.cpp

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

Loading…
Cancel
Save