From d2bfe422f1100b77409b02134e0ead60dad3aaca Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 24 Feb 2022 10:29:43 +0100 Subject: [PATCH] Separate runout and enabled settings --- Firmware/Filament_sensor.h | 20 +++++- Firmware/eeprom.h | 8 +-- Firmware/messages.cpp | 5 +- Firmware/messages.h | 1 + Firmware/ultralcd.cpp | 123 +++++++++++++++++++------------------ 5 files changed, 87 insertions(+), 70 deletions(-) diff --git a/Firmware/Filament_sensor.h b/Firmware/Filament_sensor.h index ac2d397df..3b1d6b9be 100644 --- a/Firmware/Filament_sensor.h +++ b/Firmware/Filament_sensor.h @@ -24,8 +24,8 @@ public: enum class State : uint8_t { disabled = 0, - ready, initializing, + ready, error, }; @@ -35,6 +35,11 @@ public: _Undef = EEPROM_EMPTY_VALUE }; + void setEnabled(bool enabled) { + state = enabled ? State::initializing : State::disabled; + eeprom_update_byte((uint8_t *)EEPROM_FSENSOR, enabled); + } + void setAutoLoadEnabled(bool state, bool updateEEPROM = false) { autoLoadEnabled = state; if (updateEEPROM) { @@ -49,7 +54,7 @@ public: void setRunoutEnabled(bool state, bool updateEEPROM = false) { runoutEnabled = state; if (updateEEPROM) { - eeprom_update_byte((uint8_t *)EEPROM_FSENSOR, state); + eeprom_update_byte((uint8_t *)EEPROM_FSENS_RUNOUT_ENABLED, state); } } @@ -80,10 +85,19 @@ public: return state == State::ready; } + bool isEnabled() { + return state != State::disabled; + } + protected: void settings_init() { + bool enabled = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); + if ((state != State::disabled) != enabled) { + state = enabled ? State::initializing : State::disabled; + } + autoLoadEnabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); - runoutEnabled = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); + runoutEnabled = eeprom_read_byte((uint8_t*)EEPROM_FSENS_RUNOUT_ENABLED); sensorActionOnError = (SensorActionOnError)eeprom_read_byte((uint8_t*)EEPROM_FSENSOR_ACTION_NA); if (sensorActionOnError == SensorActionOnError::_Undef) { sensorActionOnError = SensorActionOnError::_Continue; diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 2d9e2fec8..23c42e1bc 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -218,8 +218,8 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | ^ | ^ | ^ | 03h 1 | ^ | Sound mode: __assist__ | ^ | ^ | 0x0ED6 3798 | bool | EEPROM_AUTO_DEPLETE | 01h 1 | ffh 255 | MMU2/s autodeplete: __on__ | ??? | D3 Ax0ed6 C1 | ^ | ^ | ^ | 00h 0 | ^ | MMU2/s autodeplete: __off__ | ^ | ^ -| 0x0ED5 3797 | bool | EEPROM_FSENS_OQ_MEASS_ENABLED | ??? | ffh 255 | PAT1925 ??? | ??? | D3 Ax0ed5 C1 -| ^ | ^ | ^ | ??? | ^ | PAT1925 ??? | ^ | ^ +| 0x0ED5 3797 | bool | EEPROM_FSENS_RUNOUT_ENABLED | 01h 1 | ffh 255 __P__ | Filament runout: __enabled__ | LCD menu | D3 Ax0ed5 C1 +| ^ | ^ | ^ | 00h 0 | ^ | Filament runout: __disabled__ | LCD menu | ^ | 0x0ED3 3795 | uint16 | EEPROM_MMU_FAIL_TOT | ??? | ff ffh 65535 __S/P__ | MMU2/s total failures | ??? | D3 Ax0ed3 C2 | 0x0ED2 3794 | uint8 | EEPROM_MMU_FAIL | ??? | ffh 255 __S/P__ | MMU2/s fails during print | ??? | D3 Ax0ed2 C1 | 0x0ED0 3792 | uint16 | EEPROM_MMU_LOAD_FAIL_TOT | ??? | ff ffh 65535 __S/P__ | MMU2/s total load failures | ??? | D3 Ax0ed0 C2 @@ -494,9 +494,9 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP #define EEPROM_SOUND_MODE (EEPROM_UVLO_TARGET_HOTEND-1) // uint8 #define EEPROM_AUTO_DEPLETE (EEPROM_SOUND_MODE-1) //bool -#define EEPROM_FSENS_OQ_MEASS_ENABLED (EEPROM_AUTO_DEPLETE - 1) //bool +#define EEPROM_FSENS_RUNOUT_ENABLED (EEPROM_AUTO_DEPLETE - 1) //bool -#define EEPROM_MMU_FAIL_TOT (EEPROM_FSENS_OQ_MEASS_ENABLED - 2) //uint16_t +#define EEPROM_MMU_FAIL_TOT (EEPROM_FSENS_RUNOUT_ENABLED - 2) //uint16_t #define EEPROM_MMU_FAIL (EEPROM_MMU_FAIL_TOT - 1) //uint8_t #define EEPROM_MMU_LOAD_FAIL_TOT (EEPROM_MMU_FAIL - 2) //uint16_t diff --git a/Firmware/messages.cpp b/Firmware/messages.cpp index efa71c5b0..cca96a6e1 100644 --- a/Firmware/messages.cpp +++ b/Firmware/messages.cpp @@ -41,6 +41,7 @@ const char MSG_FIND_BED_OFFSET_AND_SKEW_LINE1[] PROGMEM_I1 = ISTR("Searching bed const char MSG_FINISHING_MOVEMENTS[] PROGMEM_I1 = ISTR("Finishing movements"); ////MSG_FINISHING_MOVEMENTS c=20 const char MSG_FOLLOW_CALIBRATION_FLOW[] PROGMEM_I1 = ISTR("Printer has not been calibrated yet. Please follow the manual, chapter First steps, section Calibration flow."); ////MSG_FOLLOW_CALIBRATION_FLOW c=20 r=8 const char MSG_FOLLOW_Z_CALIBRATION_FLOW[] PROGMEM_I1 = ISTR("There is still a need to make Z calibration. Please follow the manual, chapter First steps, section Calibration flow."); ////MSG_FOLLOW_Z_CALIBRATION_FLOW c=20 r=9 +const char MSG_FSENSOR_RUNOUT[] PROGMEM_I1 = ISTR("F. runout"); ////c=13 const char MSG_FSENSOR_AUTOLOAD[] PROGMEM_I1 = ISTR("F. autoload"); ////MSG_FSENSOR_AUTOLOAD c=13 const char MSG_FSENSOR[] PROGMEM_I1 = ISTR("Fil. sensor"); ////MSG_FSENSOR c=12 const char MSG_HEATING[] PROGMEM_I1 = ISTR("Heating"); ////MSG_HEATING c=20 @@ -108,8 +109,8 @@ const char MSG_STOP_PRINT[] PROGMEM_I1 = ISTR("Stop print"); ////MSG_STOP_PRINT const char MSG_STOPPED[] PROGMEM_I1 = ISTR("STOPPED."); ////MSG_STOPPED c=20 const char MSG_PINDA_CALIBRATION[] PROGMEM_I1 = ISTR("PINDA cal."); ////MSG_PINDA_CALIBRATION c=13 const char MSG_PINDA_CALIBRATION_DONE[] PROGMEM_I1 = ISTR("PINDA calibration is finished and active. It can be disabled in menu Settings->PINDA cal."); ////MSG_PINDA_CALIBRATION_DONE c=20 r=8 -const char MSG_UNLOAD_FILAMENT[] PROGMEM_I1 = ISTR("Unload filament"); ////MSG_UNLOAD_FILAMENT c=18 -const char MSG_UNLOADING_FILAMENT[] PROGMEM_I1 = ISTR("Unloading filament"); ////MSG_UNLOADING_FILAMENT c=20 +const char MSG_UNLOAD_FILAMENT[] PROGMEM_I1 = ISTR("Unload filament"); ////Number 1 to 5 is added behind text e.g. "Unload filament" c=16 +const char MSG_UNLOADING_FILAMENT[] PROGMEM_I1 = ISTR("Unloading filament"); ////c=20 const char MSG_INFO_SCREEN[] PROGMEM_I1 = ISTR("Info screen"); ////MSG_INFO_SCREEN c=18 const char MSG_WIZARD_CALIBRATION_FAILED[] PROGMEM_I1 = ISTR("Please check our handbook and fix the problem. Then resume the Wizard by rebooting the printer."); ////MSG_WIZARD_CALIBRATION_FAILED c=20 r=8 const char MSG_WIZARD_DONE[] PROGMEM_I1 = ISTR("All is done. Happy printing!"); ////MSG_WIZARD_DONE c=20 r=3 diff --git a/Firmware/messages.h b/Firmware/messages.h index 68859940e..379fc5095 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -47,6 +47,7 @@ extern const char MSG_FIND_BED_OFFSET_AND_SKEW_LINE1[]; extern const char MSG_FINISHING_MOVEMENTS[]; extern const char MSG_FOLLOW_CALIBRATION_FLOW[]; extern const char MSG_FOLLOW_Z_CALIBRATION_FLOW[]; +extern const char MSG_FSENSOR_RUNOUT[]; extern const char MSG_FSENSOR_AUTOLOAD[]; extern const char MSG_FSENSOR[]; extern const char MSG_HEATING[]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 7d7d674d1..4a33acafa 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3600,17 +3600,6 @@ static void crash_mode_switch() else menu_goto(lcd_settings_menu, 9, true, true); } #endif //TMC2130 - - -#ifdef FILAMENT_SENSOR -static void lcd_fsensor_runout_set() { - fsensor.setRunoutEnabled(!fsensor.getRunoutEnabled(), true); -} - -static void lcd_fsensor_autoload_set() { - fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled(), true); -} -#endif //FILAMENT_SENSOR #if (LANG_MODE != 0) @@ -4176,21 +4165,69 @@ void lcd_settings_linearity_correction_menu(void) #ifdef FILAMENT_SENSOR -void fsensor_reinit() { +static void fsensor_reinit() { fsensor.init(); } -#define SETTINGS_FILAMENT_SENSOR \ -do {\ - if (fsensor.isError()) {\ - MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), _T(MSG_NA), fsensor_reinit);\ - MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_NA), fsensor_reinit);\ - }\ - else {\ - MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), fsensor.getRunoutEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_runout_set);\ - MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), fsensor.getAutoLoadEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_autoload_set);\ - }\ -} while(0) +static void lcd_fsensor_enabled_set(void) { + fsensor.setEnabled(!fsensor.isEnabled()); +} + +static void lcd_fsensor_runout_set() { + fsensor.setRunoutEnabled(!fsensor.getRunoutEnabled(), true); +} + +static void lcd_fsensor_autoload_set() { + fsensor.setAutoLoadEnabled(!fsensor.getAutoLoadEnabled(), true); +} + +static void lcd_fsensor_actionNA_set(void) +{ + Filament_sensor::SensorActionOnError act = fsensor.getActionOnError(); + switch(act) { + case Filament_sensor::SensorActionOnError::_Continue: + act = Filament_sensor::SensorActionOnError::_Pause; + break; + case Filament_sensor::SensorActionOnError::_Pause: + act = Filament_sensor::SensorActionOnError::_Continue; + break; + default: + act = Filament_sensor::SensorActionOnError::_Continue; + } + fsensor.setActionOnError(act, true); +} + +static void lcd_fsensor_settings_menu() { + MENU_BEGIN(); + MENU_ITEM_BACK_P(_T(MSG_BACK)); + + MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR), fsensor.isEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_enabled_set); + + if (fsensor.isEnabled()) { + if (fsensor.isError()) { + MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), _T(MSG_NA), fsensor_reinit); + MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), _T(MSG_NA), fsensor_reinit); + } + else { + MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_RUNOUT), fsensor.getRunoutEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_runout_set); + MENU_ITEM_TOGGLE_P(_T(MSG_FSENSOR_AUTOLOAD), fsensor.getAutoLoadEnabled() ? _T(MSG_ON) : _T(MSG_OFF), lcd_fsensor_autoload_set); + } + + switch(fsensor.getActionOnError()) { + case Filament_sensor::SensorActionOnError::_Continue: + MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_CONTINUE), lcd_fsensor_actionNA_set); + break; + case Filament_sensor::SensorActionOnError::_Pause: + MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_PAUSE), lcd_fsensor_actionNA_set); + break; + default: + lcd_fsensor_actionNA_set(); + } + } + + MENU_END(); +} + #endif //FILAMENT_SENSOR static void auto_deplete_switch() @@ -4604,36 +4641,6 @@ SETTINGS_VERSION; MENU_END(); } -static void lcd_fsensor_actionNA_set(void) -{ - Filament_sensor::SensorActionOnError act = fsensor.getActionOnError(); - switch(act) { - case Filament_sensor::SensorActionOnError::_Continue: - act = Filament_sensor::SensorActionOnError::_Pause; - break; - case Filament_sensor::SensorActionOnError::_Pause: - act = Filament_sensor::SensorActionOnError::_Continue; - break; - default: - act = Filament_sensor::SensorActionOnError::_Continue; - } - fsensor.setActionOnError(act, true); -} - -#define FSENSOR_ACTION_NA \ -do {\ - switch(fsensor.getActionOnError()) {\ - case Filament_sensor::SensorActionOnError::_Continue:\ - MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_CONTINUE), lcd_fsensor_actionNA_set);\ - break;\ - case Filament_sensor::SensorActionOnError::_Pause:\ - MENU_ITEM_TOGGLE_P(_T(MSG_FS_ACTION), _T(MSG_FS_PAUSE), lcd_fsensor_actionNA_set);\ - break;\ - default:\ - lcd_fsensor_actionNA_set();\ - }\ -} while (0) - template static void select_sheet_menu() { @@ -4723,10 +4730,7 @@ static void lcd_settings_menu() } #ifdef FILAMENT_SENSOR - SETTINGS_FILAMENT_SENSOR; -#ifdef IR_SENSOR_ANALOG - FSENSOR_ACTION_NA; -#endif //IR_SENSOR_ANALOG + MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu); #endif //FILAMENT_SENSOR SETTINGS_AUTO_DEPLETE; @@ -5659,10 +5663,7 @@ static void lcd_tune_menu() #endif #ifdef FILAMENT_SENSOR - SETTINGS_FILAMENT_SENSOR; -#ifdef IR_SENSOR_ANALOG - FSENSOR_ACTION_NA; -#endif //IR_SENSOR_ANALOG + MENU_ITEM_SUBMENU_P(_T(MSG_FSENSOR), lcd_fsensor_settings_menu); #endif //FILAMENT_SENSOR SETTINGS_AUTO_DEPLETE;