From ef83fefce11adb366fded3fcb17031128f256926 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 17 Nov 2022 13:36:00 +0100 Subject: [PATCH] More optimization --- Firmware/Prusa_farm.cpp | 8 ++------ Firmware/eeprom.cpp | 4 ++++ Firmware/eeprom.h | 1 + Firmware/mesh_bed_calibration.cpp | 6 +----- Firmware/ultralcd.cpp | 19 ++----------------- Firmware/ultralcd.h | 1 - 6 files changed, 10 insertions(+), 29 deletions(-) diff --git a/Firmware/Prusa_farm.cpp b/Firmware/Prusa_farm.cpp index b6fca0f52..71c180d86 100644 --- a/Firmware/Prusa_farm.cpp +++ b/Firmware/Prusa_farm.cpp @@ -390,12 +390,8 @@ void prusa_statistics_update_from_lcd_update() { } void farm_mode_init() { - farm_mode = eeprom_read_byte((uint8_t*)EEPROM_FARM_MODE); - if (farm_mode == 0xFF) { - farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode - eeprom_update_byte((uint8_t*)EEPROM_FARM_MODE, farm_mode); - } - else if (farm_mode) { + farm_mode = eeprom_init_default_byte((uint8_t*)EEPROM_FARM_MODE, 0); + if (farm_mode) { no_response = true; //we need confirmation by recieving PRUSA thx prusa_statistics(8); #ifdef HAS_SECOND_SERIAL_PORT diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index df0b89694..dd0be69cb 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -153,6 +153,10 @@ void eeprom_update_block_P(const void *__src, void *__dst, size_t __n) { } } +void eeprom_toggle(uint8_t *__p) { + eeprom_write_byte(__p, !eeprom_read_byte(__p)); +} + void __attribute__((noinline)) eeprom_increment_byte(uint8_t *__p) { eeprom_write_byte(__p, eeprom_read_byte(__p) + 1); } diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 42d3a242c..901bee73e 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -615,6 +615,7 @@ bool eeprom_is_sheet_initialized(uint8_t sheet_num); bool eeprom_is_initialized_block(const void *__p, size_t __n); void eeprom_update_block_P(const void *__src, void *__dst, size_t __n); +void eeprom_toggle(uint8_t *__p); void eeprom_increment_byte(uint8_t *__p); void eeprom_increment_word(uint16_t *__p); diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 2a7a380e3..1c6b37d1d 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -3125,11 +3125,7 @@ void mbl_settings_init() { //magnet elimination: use aaproximate Z-coordinate instead of measured values for points which are near magnets eeprom_init_default_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, 1); eeprom_init_default_byte((uint8_t*)EEPROM_MBL_POINTS_NR, 3); - mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR); - if (mbl_z_probe_nr == 0xFF) { - mbl_z_probe_nr = 3; - eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, mbl_z_probe_nr); - } + mbl_z_probe_nr = eeprom_init_default_byte((uint8_t*)EEPROM_MBL_PROBE_NR, 3); } //parameter ix: index of mesh bed leveling point in X-axis (for meas_points == 7 is valid range from 0 to 6; for meas_points == 3 is valid range from 0 to 2 ) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 315d0a02c..f2653d07b 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4605,12 +4605,7 @@ void lcd_hw_setup_menu(void) // can not be "static" if (_md->status == 0 || lcd_draw_update) { _md->status = 1; - _md->experimental_menu_visibility = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY); - if (_md->experimental_menu_visibility == EEPROM_EMPTY_VALUE) - { - _md->experimental_menu_visibility = 0; - eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, _md->experimental_menu_visibility); - } + _md->experimental_menu_visibility = eeprom_init_default_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, 0); } @@ -7527,7 +7522,7 @@ void menu_lcd_longpress_func(void) { // only toggle the experimental menu visibility flag lcd_quick_feedback(); - lcd_experimental_toggle(); + eeprom_toggle((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY); return; } @@ -7690,16 +7685,6 @@ void lcd_crash_detect_disable() } #endif -void lcd_experimental_toggle() -{ - uint8_t oldVal = eeprom_read_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY); - if (oldVal == EEPROM_EMPTY_VALUE) - oldVal = 0; - else - oldVal = !oldVal; - eeprom_update_byte((uint8_t *)EEPROM_EXPERIMENTAL_VISIBILITY, oldVal); -} - #ifdef TMC2130 void UserECool_toggle(){ // this is only called when the experimental menu is visible, thus the first condition for enabling of the ECool mode is met in this place diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index e9c7ec98a..a3944bb34 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -244,7 +244,6 @@ enum class WizState : uint8_t void lcd_wizard(WizState state); -extern void lcd_experimental_toggle(); extern void lcd_experimental_menu(); uint8_t lcdui_print_extruder(void);