|
@@ -117,17 +117,27 @@ void write_to_lcd(const char * const message) {
|
117
|
117
|
* the command portion begins after the :
|
118
|
118
|
*/
|
119
|
119
|
void process_lcd_c_command(const char* command) {
|
|
120
|
+ const int target_val = command[1] ? atoi(command + 1) : -1;
|
|
121
|
+ if (target_val < 0) {
|
|
122
|
+ DEBUG_ECHOLNPAIR("UNKNOWN C COMMAND ", command);
|
|
123
|
+ return;
|
|
124
|
+ }
|
120
|
125
|
switch (command[0]) {
|
121
|
126
|
case 'C': // Cope with both V1 early rev and later LCDs.
|
122
|
127
|
case 'S':
|
123
|
|
- feedrate_percentage = atoi(command + 1) * 10;
|
|
128
|
+ feedrate_percentage = target_val * 10;
|
124
|
129
|
LIMIT(feedrate_percentage, 10, 999);
|
125
|
130
|
break;
|
126
|
131
|
|
127
|
|
- case 'T': ExtUI::setTargetTemp_celsius(atoi(command + 1), ExtUI::extruder_t::E0); break;
|
|
132
|
+ case 'T':
|
|
133
|
+ // Sometimes the LCD will send commands to turn off both extruder and bed, though
|
|
134
|
+ // this should not happen since the printing screen is up. Better safe than sorry.
|
|
135
|
+ if (!print_job_timer.isRunning() || target_val > 0)
|
|
136
|
+ ExtUI::setTargetTemp_celsius(target_val, ExtUI::extruder_t::E0);
|
|
137
|
+ break;
|
128
|
138
|
|
129
|
139
|
#if HAS_HEATED_BED
|
130
|
|
- case 'P': ExtUI::setTargetTemp_celsius(atoi(command + 1), ExtUI::heater_t::BED); break;
|
|
140
|
+ case 'P': ExtUI::setTargetTemp_celsius(target_val, ExtUI::heater_t::BED); break;
|
131
|
141
|
#endif
|
132
|
142
|
|
133
|
143
|
default: DEBUG_ECHOLNPAIR("UNKNOWN C COMMAND ", command);
|
|
@@ -143,6 +153,7 @@ void process_lcd_c_command(const char* command) {
|
143
|
153
|
*/
|
144
|
154
|
void process_lcd_eb_command(const char* command) {
|
145
|
155
|
char elapsed_buffer[10];
|
|
156
|
+ static uint8_t iteration = 0;
|
146
|
157
|
duration_t elapsed;
|
147
|
158
|
switch (command[0]) {
|
148
|
159
|
case '0': {
|
|
@@ -150,6 +161,13 @@ void process_lcd_eb_command(const char* command) {
|
150
|
161
|
sprintf_P(elapsed_buffer, PSTR("%02u%02u%02u"), uint16_t(elapsed.hour()), uint16_t(elapsed.minute()) % 60, uint16_t(elapsed.second()) % 60);
|
151
|
162
|
|
152
|
163
|
char message_buffer[MAX_CURLY_COMMAND];
|
|
164
|
+ uint8_t done_pct = print_job_timer.isRunning() ? (iteration * 10) : 100;
|
|
165
|
+ iteration = (iteration + 1) % 10; // Provide progress animation
|
|
166
|
+ #if ENABLED(SDSUPPORT)
|
|
167
|
+ if (ExtUI::isPrintingFromMedia() || ExtUI::isPrintingFromMediaPaused())
|
|
168
|
+ done_pct = card.percentDone();
|
|
169
|
+ #endif
|
|
170
|
+
|
153
|
171
|
sprintf_P(message_buffer,
|
154
|
172
|
PSTR("{T0:%03i/%03i}{T1:000/000}{TP:%03i/%03i}{TQ:%03i}{TT:%s}"),
|
155
|
173
|
int(thermalManager.degHotend(0)), thermalManager.degTargetHotend(0),
|
|
@@ -159,7 +177,7 @@ void process_lcd_eb_command(const char* command) {
|
159
|
177
|
0, 0,
|
160
|
178
|
#endif
|
161
|
179
|
#if ENABLED(SDSUPPORT)
|
162
|
|
- card.percentDone(),
|
|
180
|
+ done_pct,
|
163
|
181
|
#else
|
164
|
182
|
0,
|
165
|
183
|
#endif
|
|
@@ -186,7 +204,7 @@ void process_lcd_j_command(const char* command) {
|
186
|
204
|
auto move_axis = [command](const auto axis) {
|
187
|
205
|
const float dist = atof(command + 1) / 10.0;
|
188
|
206
|
ExtUI::setAxisPosition_mm(ExtUI::getAxisPosition_mm(axis) + dist, axis);
|
189
|
|
- }
|
|
207
|
+ };
|
190
|
208
|
|
191
|
209
|
switch (command[0]) {
|
192
|
210
|
case 'E': break;
|
|
@@ -330,7 +348,6 @@ void process_lcd_s_command(const char* command) {
|
330
|
348
|
void process_lcd_command(const char* command) {
|
331
|
349
|
const char *current = command;
|
332
|
350
|
|
333
|
|
- current++; // skip the leading {. The trailing one is already gone.
|
334
|
351
|
byte command_code = *current++;
|
335
|
352
|
if (*current == ':') {
|
336
|
353
|
|
|
@@ -350,6 +367,31 @@ void process_lcd_command(const char* command) {
|
350
|
367
|
DEBUG_ECHOLNPAIR("UNKNOWN COMMAND FORMAT ", command);
|
351
|
368
|
}
|
352
|
369
|
|
|
370
|
+// Parse LCD commands mixed with G-Code
|
|
371
|
+void parse_lcd_byte(byte b) {
|
|
372
|
+ static bool parsing_lcd_cmd = false;
|
|
373
|
+ static char inbound_buffer[MAX_CURLY_COMMAND];
|
|
374
|
+
|
|
375
|
+ if (!parsing_lcd_cmd) {
|
|
376
|
+ if (b == '{' || b == '\n' || b == '\r') { // A line-ending or opening brace
|
|
377
|
+ parsing_lcd_cmd = b == '{'; // Brace opens an LCD command
|
|
378
|
+ if (inbound_count) { // Looks like a G-code is in the buffer
|
|
379
|
+ inbound_buffer[inbound_count] = '\0'; // Reset before processing
|
|
380
|
+ inbound_count = 0;
|
|
381
|
+ queue.enqueue_one_now(inbound_buffer); // Handle the G-code command
|
|
382
|
+ }
|
|
383
|
+ }
|
|
384
|
+ }
|
|
385
|
+ else if (b == '}') { // Closing brace on an LCD command
|
|
386
|
+ parsing_lcd_cmd = false; // Unflag and...
|
|
387
|
+ inbound_buffer[inbound_count] = '\0'; // reset before processing
|
|
388
|
+ inbound_count = 0;
|
|
389
|
+ process_lcd_command(inbound_buffer); // Handle the LCD command
|
|
390
|
+ }
|
|
391
|
+ else if (inbound_count < MAX_CURLY_COMMAND - 2)
|
|
392
|
+ inbound_buffer[inbound_count++] = b; // Buffer only if space remains
|
|
393
|
+}
|
|
394
|
+
|
353
|
395
|
/**
|
354
|
396
|
* UC means connected.
|
355
|
397
|
* UD means disconnected
|
|
@@ -360,8 +402,8 @@ void update_usb_status(const bool forceUpdate) {
|
360
|
402
|
// This is mildly different than stock, which
|
361
|
403
|
// appears to use the usb discovery status.
|
362
|
404
|
// This is more logical.
|
363
|
|
- if (last_usb_connected_status != Serial || forceUpdate) {
|
364
|
|
- last_usb_connected_status = Serial;
|
|
405
|
+ if (last_usb_connected_status != SerialUSB || forceUpdate) {
|
|
406
|
+ last_usb_connected_status = SerialUSB;
|
365
|
407
|
write_to_lcd_P(last_usb_connected_status ? PSTR("{R:UC}\r\n") : PSTR("{R:UD}\r\n"));
|
366
|
408
|
}
|
367
|
409
|
}
|
|
@@ -391,24 +433,14 @@ namespace ExtUI {
|
391
|
433
|
/**
|
392
|
434
|
* - from printer on startup:
|
393
|
435
|
* {SYS:STARTED}{VER:29}{SYS:STARTED}{R:UD}
|
394
|
|
- * The optimize attribute fixes a register Compile
|
395
|
|
- * error for amtel.
|
396
|
436
|
*/
|
397
|
|
- static char inbound_buffer[MAX_CURLY_COMMAND];
|
398
|
437
|
|
399
|
438
|
// First report USB status.
|
400
|
439
|
update_usb_status(false);
|
401
|
440
|
|
402
|
441
|
// now drain commands...
|
403
|
442
|
while (LCD_SERIAL.available()) {
|
404
|
|
- const byte b = (byte)LCD_SERIAL.read() & 0x7F;
|
405
|
|
- inbound_buffer[inbound_count++] = b;
|
406
|
|
- if (b == '}' || inbound_count == sizeof(inbound_buffer) - 1) {
|
407
|
|
- inbound_buffer[inbound_count - 1] = '\0';
|
408
|
|
- process_lcd_command(inbound_buffer);
|
409
|
|
- inbound_count = 0;
|
410
|
|
- inbound_buffer[0] = 0;
|
411
|
|
- }
|
|
443
|
+ parse_lcd_byte((byte)LCD_SERIAL.read() & 0x7F);
|
412
|
444
|
}
|
413
|
445
|
|
414
|
446
|
#if ENABLED(SDSUPPORT)
|
|
@@ -438,22 +470,23 @@ namespace ExtUI {
|
438
|
470
|
write_to_lcd_P("}");
|
439
|
471
|
}
|
440
|
472
|
|
|
473
|
+ void onPrintTimerStarted() { write_to_lcd_P(PSTR("{SYS:BUILD}")); }
|
|
474
|
+ void onPrintTimerPaused() {}
|
|
475
|
+ void onPrintTimerStopped() { write_to_lcd_P(PSTR("{TQ:100}")); }
|
|
476
|
+
|
441
|
477
|
// Not needed for Malyan LCD
|
442
|
|
- void onStatusChanged(const char * const msg) { UNUSED(msg); }
|
|
478
|
+ void onStatusChanged(const char * const) {}
|
443
|
479
|
void onMediaInserted() {};
|
444
|
480
|
void onMediaError() {};
|
445
|
481
|
void onMediaRemoved() {};
|
446
|
|
- void onPlayTone(const uint16_t frequency, const uint16_t duration) { UNUSED(frequency); UNUSED(duration); }
|
447
|
|
- void onPrintTimerStarted() {}
|
448
|
|
- void onPrintTimerPaused() {}
|
449
|
|
- void onPrintTimerStopped() {}
|
|
482
|
+ void onPlayTone(const uint16_t, const uint16_t) {}
|
450
|
483
|
void onFilamentRunout(const extruder_t extruder) {}
|
451
|
|
- void onUserConfirmRequired(const char * const msg) { UNUSED(msg); }
|
|
484
|
+ void onUserConfirmRequired(const char * const) {}
|
452
|
485
|
void onFactoryReset() {}
|
453
|
|
- void onStoreSettings(char *buff) { UNUSED(buff); }
|
454
|
|
- void onLoadSettings(const char *buff) { UNUSED(buff); }
|
455
|
|
- void onConfigurationStoreWritten(bool success) { UNUSED(success); }
|
456
|
|
- void onConfigurationStoreRead(bool success) { UNUSED(success); }
|
|
486
|
+ void onStoreSettings(char*) {}
|
|
487
|
+ void onLoadSettings(const char*) {}
|
|
488
|
+ void onConfigurationStoreWritten(bool) {}
|
|
489
|
+ void onConfigurationStoreRead(bool) {}
|
457
|
490
|
}
|
458
|
491
|
|
459
|
492
|
#endif // MALYAN_LCD
|