Backlash cleanup (#13659)
…And save backlash, fil. sensor, ExtUI userdata to EEPROM.
This commit is contained in:
committed by
Scott Lahteine
parent
0181e57417
commit
15357af67c
@@ -41,23 +41,19 @@
|
||||
* Copyright (c) 2017 Jason Nelson (xC0000005)
|
||||
*/
|
||||
|
||||
#include "../inc/MarlinConfig.h"
|
||||
#include "../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(MALYAN_LCD)
|
||||
|
||||
#include "extensible_ui/ui_api.h"
|
||||
|
||||
#include "ultralcd.h"
|
||||
#include "../module/temperature.h"
|
||||
#include "../module/planner.h"
|
||||
#include "../module/stepper.h"
|
||||
#include "../module/motion.h"
|
||||
#include "../module/probe.h"
|
||||
#include "../libs/duration_t.h"
|
||||
#include "../module/printcounter.h"
|
||||
#include "../gcode/gcode.h"
|
||||
#include "../gcode/queue.h"
|
||||
#include "../module/configuration_store.h"
|
||||
|
||||
#include "../Marlin.h"
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
#include "../sd/cardreader.h"
|
||||
@@ -412,78 +408,118 @@ void update_usb_status(const bool forceUpdate) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* - from printer on startup:
|
||||
* {SYS:STARTED}{VER:29}{SYS:STARTED}{R:UD}
|
||||
* The optimize attribute fixes a register Compile
|
||||
* error for amtel.
|
||||
*/
|
||||
void MarlinUI::update() {
|
||||
static char inbound_buffer[MAX_CURLY_COMMAND];
|
||||
namespace ExtUI {
|
||||
void onStartup() {
|
||||
/**
|
||||
* The Malyan LCD actually runs as a separate MCU on Serial 1.
|
||||
* This code's job is to siphon the weird curly-brace commands from
|
||||
* it and translate into gcode, which then gets injected into
|
||||
* the command queue where possible.
|
||||
*/
|
||||
inbound_count = 0;
|
||||
LCD_SERIAL.begin(500000);
|
||||
|
||||
// First report USB status.
|
||||
update_usb_status(false);
|
||||
// Signal init
|
||||
write_to_lcd_P(PSTR("{SYS:STARTED}\r\n"));
|
||||
|
||||
// now drain commands...
|
||||
while (LCD_SERIAL.available()) {
|
||||
const byte b = (byte)LCD_SERIAL.read() & 0x7F;
|
||||
inbound_buffer[inbound_count++] = b;
|
||||
if (b == '}' || inbound_count == sizeof(inbound_buffer) - 1) {
|
||||
inbound_buffer[inbound_count - 1] = '\0';
|
||||
process_lcd_command(inbound_buffer);
|
||||
inbound_count = 0;
|
||||
inbound_buffer[0] = 0;
|
||||
}
|
||||
// send a version that says "unsupported"
|
||||
write_to_lcd_P(PSTR("{VER:99}\r\n"));
|
||||
|
||||
// No idea why it does this twice.
|
||||
write_to_lcd_P(PSTR("{SYS:STARTED}\r\n"));
|
||||
update_usb_status(true);
|
||||
}
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
// The way last printing status works is simple:
|
||||
// The UI needs to see at least one TQ which is not 100%
|
||||
// and then when the print is complete, one which is.
|
||||
static uint8_t last_percent_done = 100;
|
||||
void onIdle() {
|
||||
/**
|
||||
* - from printer on startup:
|
||||
* {SYS:STARTED}{VER:29}{SYS:STARTED}{R:UD}
|
||||
* The optimize attribute fixes a register Compile
|
||||
* error for amtel.
|
||||
*/
|
||||
static char inbound_buffer[MAX_CURLY_COMMAND];
|
||||
|
||||
// If there was a print in progress, we need to emit the final
|
||||
// print status as {TQ:100}. Reset last percent done so a new print will
|
||||
// issue a percent of 0.
|
||||
const uint8_t percent_done = IS_SD_PRINTING() ? card.percentDone() : last_printing_status ? 100 : 0;
|
||||
if (percent_done != last_percent_done) {
|
||||
char message_buffer[10];
|
||||
sprintf_P(message_buffer, PSTR("{TQ:%03i}"), percent_done);
|
||||
write_to_lcd(message_buffer);
|
||||
last_percent_done = percent_done;
|
||||
last_printing_status = IS_SD_PRINTING();
|
||||
// First report USB status.
|
||||
update_usb_status(false);
|
||||
|
||||
// now drain commands...
|
||||
while (LCD_SERIAL.available()) {
|
||||
const byte b = (byte)LCD_SERIAL.read() & 0x7F;
|
||||
inbound_buffer[inbound_count++] = b;
|
||||
if (b == '}' || inbound_count == sizeof(inbound_buffer) - 1) {
|
||||
inbound_buffer[inbound_count - 1] = '\0';
|
||||
process_lcd_command(inbound_buffer);
|
||||
inbound_count = 0;
|
||||
inbound_buffer[0] = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* The Malyan LCD actually runs as a separate MCU on Serial 1.
|
||||
* This code's job is to siphon the weird curly-brace commands from
|
||||
* it and translate into gcode, which then gets injected into
|
||||
* the command queue where possible.
|
||||
*/
|
||||
void MarlinUI::init() {
|
||||
inbound_count = 0;
|
||||
LCD_SERIAL.begin(500000);
|
||||
#if ENABLED(SDSUPPORT)
|
||||
// The way last printing status works is simple:
|
||||
// The UI needs to see at least one TQ which is not 100%
|
||||
// and then when the print is complete, one which is.
|
||||
static uint8_t last_percent_done = 100;
|
||||
|
||||
// Signal init
|
||||
write_to_lcd_P(PSTR("{SYS:STARTED}\r\n"));
|
||||
// If there was a print in progress, we need to emit the final
|
||||
// print status as {TQ:100}. Reset last percent done so a new print will
|
||||
// issue a percent of 0.
|
||||
const uint8_t percent_done = IS_SD_PRINTING() ? card.percentDone() : last_printing_status ? 100 : 0;
|
||||
if (percent_done != last_percent_done) {
|
||||
char message_buffer[10];
|
||||
sprintf_P(message_buffer, PSTR("{TQ:%03i}"), percent_done);
|
||||
write_to_lcd(message_buffer);
|
||||
last_percent_done = percent_done;
|
||||
last_printing_status = IS_SD_PRINTING();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// send a version that says "unsupported"
|
||||
write_to_lcd_P(PSTR("{VER:99}\r\n"));
|
||||
void onPrinterKilled(PGM_P const msg) {}
|
||||
void onMediaInserted() {};
|
||||
void onMediaError() {};
|
||||
void onMediaRemoved() {};
|
||||
void onPlayTone(const uint16_t frequency, const uint16_t duration) {}
|
||||
void onPrintTimerStarted() {}
|
||||
void onPrintTimerPaused() {}
|
||||
void onPrintTimerStopped() {}
|
||||
void onFilamentRunout() {}
|
||||
void onUserConfirmRequired(const char * const msg) {}
|
||||
void onStatusChanged(const char * const msg) {
|
||||
write_to_lcd_P(PSTR("{E:"));
|
||||
write_to_lcd(msg);
|
||||
write_to_lcd_P("}");
|
||||
}
|
||||
void onFactoryReset() {}
|
||||
|
||||
// No idea why it does this twice.
|
||||
write_to_lcd_P(PSTR("{SYS:STARTED}\r\n"));
|
||||
update_usb_status(true);
|
||||
}
|
||||
void onStoreSettings(char *buff) {
|
||||
// This is called when saving to EEPROM (i.e. M500). If the ExtUI needs
|
||||
// permanent data to be stored, it can write up to eeprom_data_size bytes
|
||||
// into buff.
|
||||
|
||||
/**
|
||||
* Set an alert.
|
||||
*/
|
||||
void MarlinUI::set_alert_status_P(PGM_P const message) {
|
||||
write_to_lcd_P(PSTR("{E:"));
|
||||
write_to_lcd_P(message);
|
||||
write_to_lcd_P("}");
|
||||
// Example:
|
||||
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
|
||||
// memcpy(buff, &myDataStruct, sizeof(myDataStruct));
|
||||
}
|
||||
|
||||
void onLoadSettings(const char *buff) {
|
||||
// This is called while loading settings from EEPROM. If the ExtUI
|
||||
// needs to retrieve data, it should copy up to eeprom_data_size bytes
|
||||
// from buff
|
||||
|
||||
// Example:
|
||||
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
|
||||
// memcpy(&myDataStruct, buff, sizeof(myDataStruct));
|
||||
}
|
||||
|
||||
void onConfigurationStoreWritten(bool success) {
|
||||
// This is called after the entire EEPROM has been written,
|
||||
// whether successful or not.
|
||||
}
|
||||
|
||||
void onConfigurationStoreRead(bool success) {
|
||||
// This is called after the entire EEPROM has been read,
|
||||
// whether successful or not.
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MALYAN_LCD
|
||||
|
||||
Reference in New Issue
Block a user