Backlash cleanup (#13659)

…And save backlash, fil. sensor, ExtUI userdata to EEPROM.
This commit is contained in:
Marcio Teixeira
2019-05-03 22:53:15 -06:00
committed by Scott Lahteine
parent 0181e57417
commit 15357af67c
22 changed files with 645 additions and 293 deletions

View File

@ -1,6 +1,6 @@
/*************
* dummy.cpp *
*************/
/***************
* example.cpp *
***************/
/****************************************************************************
* Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
@ -21,7 +21,7 @@
#include "../../../inc/MarlinConfigPre.h"
#if ENABLED(EXTENSIBLE_UI)
#if BOTH(EXTUI_EXAMPLE, EXTENSIBLE_UI)
#include "../ui_api.h"
@ -58,8 +58,36 @@ namespace ExtUI {
void onUserConfirmRequired(const char * const msg) {}
void onStatusChanged(const char * const msg) {}
void onFactoryReset() {}
void onLoadSettings() {}
void onStoreSettings() {}
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.
// 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 // EXTENSIBLE_UI
#endif // EXTUI_EXAMPLE && EXTENSIBLE_UI

View File

@ -82,11 +82,7 @@
#include "ui_api.h"
#if ENABLED(BACKLASH_GCODE)
extern float backlash_distance_mm[XYZ];
extern uint8_t backlash_correction;
#ifdef BACKLASH_SMOOTHING_MM
extern float backlash_smoothing_mm;
#endif
#include "../../feature/backlash.h"
#endif
#if HAS_LEVELING
@ -111,7 +107,6 @@ static struct {
} flags;
namespace ExtUI {
#ifdef __SAM3X8E__
/**
* Implement a special millis() to allow time measurement
@ -517,13 +512,13 @@ namespace ExtUI {
bool getFilamentRunoutEnabled() { return runout.enabled; }
void setFilamentRunoutEnabled(const bool value) { runout.enabled = value; }
#if FILAMENT_RUNOUT_DISTANCE_MM > 0
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
float getFilamentRunoutDistance_mm() {
return RunoutResponseDelayed::runout_distance_mm;
return runout.runout_distance();
}
void setFilamentRunoutDistance_mm(const float value) {
RunoutResponseDelayed::runout_distance_mm = clamp(value, 0, 999);
runout.set_runout_distance(clamp(value, 0, 999));
}
#endif
#endif
@ -687,16 +682,16 @@ namespace ExtUI {
#endif // HAS_HOTEND_OFFSET
#if ENABLED(BACKLASH_GCODE)
float getAxisBacklash_mm(const axis_t axis) { return backlash_distance_mm[axis]; }
float getAxisBacklash_mm(const axis_t axis) { return backlash.distance_mm[axis]; }
void setAxisBacklash_mm(const float value, const axis_t axis)
{ backlash_distance_mm[axis] = clamp(value,0,5); }
{ backlash.distance_mm[axis] = clamp(value,0,5); }
float getBacklashCorrection_percent() { return ui8_to_percent(backlash_correction); }
void setBacklashCorrection_percent(const float value) { backlash_correction = map(clamp(value, 0, 100), 0, 100, 0, 255); }
float getBacklashCorrection_percent() { return ui8_to_percent(backlash.correction); }
void setBacklashCorrection_percent(const float value) { backlash.correction = map(clamp(value, 0, 100), 0, 100, 0, 255); }
#ifdef BACKLASH_SMOOTHING_MM
float getBacklashSmoothing_mm() { return backlash_smoothing_mm; }
void setBacklashSmoothing_mm(const float value) { backlash_smoothing_mm = clamp(value, 0, 999); }
float getBacklashSmoothing_mm() { return backlash.smoothing_mm; }
void setBacklashSmoothing_mm(const float value) { backlash.smoothing_mm = clamp(value, 0, 999); }
#endif
#endif
@ -750,7 +745,7 @@ namespace ExtUI {
}
bool commandsInQueue() { return (planner.movesplanned() || commands_in_queue); }
bool isAxisPositionKnown(const axis_t axis) {
return TEST(axis_known_position, axis);
}

View File

@ -46,6 +46,11 @@
#include "../../inc/MarlinConfig.h"
namespace ExtUI {
// The ExtUI implementation can store up to this many bytes
// in the EEPROM when the methods onStoreSettings and
// onLoadSettings are called.
static constexpr size_t eeprom_data_size = 48;
enum axis_t : uint8_t { X, Y, Z };
enum extruder_t : uint8_t { E0, E1, E2, E3, E4, E5 };
@ -207,7 +212,7 @@ namespace ExtUI {
bool getFilamentRunoutEnabled();
void setFilamentRunoutEnabled(const bool);
#if FILAMENT_RUNOUT_DISTANCE_MM > 0
#ifdef FILAMENT_RUNOUT_DISTANCE_MM
float getFilamentRunoutDistance_mm();
void setFilamentRunoutDistance_mm(const float);
#endif
@ -283,8 +288,10 @@ namespace ExtUI {
void onUserConfirmRequired(const char * const msg);
void onStatusChanged(const char * const msg);
void onFactoryReset();
void onStoreSettings();
void onLoadSettings();
void onStoreSettings(char *);
void onLoadSettings(const char *);
void onConfigurationStoreWritten(bool success);
void onConfigurationStoreRead(bool success);
};
/**

View File

@ -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

View File

@ -30,26 +30,21 @@
#include "menu.h"
extern float backlash_distance_mm[XYZ];
extern uint8_t backlash_correction;
#ifdef BACKLASH_SMOOTHING_MM
extern float backlash_smoothing_mm;
#endif
#include "../../feature/backlash.h"
void menu_backlash() {
START_MENU();
MENU_BACK(MSG_MAIN);
MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_BACKLASH_CORRECTION, &backlash_correction, all_off, all_on);
MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_BACKLASH_CORRECTION, &backlash.correction, all_off, all_on);
#define EDIT_BACKLASH_DISTANCE(N) MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_##N, &backlash_distance_mm[_AXIS(N)], 0.0f, 9.9f);
#define EDIT_BACKLASH_DISTANCE(N) MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_##N, &backlash.distance_mm[_AXIS(N)], 0.0f, 9.9f);
EDIT_BACKLASH_DISTANCE(A);
EDIT_BACKLASH_DISTANCE(B);
EDIT_BACKLASH_DISTANCE(C);
#ifdef BACKLASH_SMOOTHING_MM
MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_BACKLASH_SMOOTHING, &backlash_smoothing_mm, 0.0f, 9.9f);
MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_BACKLASH_SMOOTHING, &backlash.smoothing_mm, 0.0f, 9.9f);
#endif
END_MENU();

View File

@ -23,7 +23,7 @@
#include "../inc/MarlinConfigPre.h"
// These displays all share the MarlinUI class
#if HAS_SPI_LCD || EITHER(MALYAN_LCD, EXTENSIBLE_UI)
#if HAS_SPI_LCD || ENABLED(EXTENSIBLE_UI)
#include "ultralcd.h"
#include "fontutils.h"
MarlinUI ui;