TM: Store only the last autotune result state

- Remove tm::valid and temp_model_valid as it's a duplicate of the
  calibrated() state.
- Add temp_model_autotune_result() for future use.
This commit is contained in:
Yuri D'Elia 2022-12-12 14:12:20 +01:00 committed by 3d-gussner
parent dac73c9582
commit f6c16455bb
3 changed files with 13 additions and 15 deletions

View File

@ -60,7 +60,6 @@ struct model_data
}; };
static bool enabled; // model check enabled static bool enabled; // model check enabled
static bool valid = false; // model is valid
static bool warn_beep = true; // beep on warning threshold static bool warn_beep = true; // beep on warning threshold
static model_data data; // default heater data static model_data data; // default heater data

View File

@ -2506,7 +2506,6 @@ static void temp_model_reset_enabled(bool enabled)
{ {
TempMgrGuard temp_mgr_guard; TempMgrGuard temp_mgr_guard;
temp_model::enabled = enabled; temp_model::enabled = enabled;
temp_model::valid = enabled;
temp_model::data.flag_bits.uninitialized = true; temp_model::data.flag_bits.uninitialized = true;
} }
@ -2517,19 +2516,11 @@ void temp_model_set_enabled(bool enabled)
TempMgrGuard temp_mgr_guard; TempMgrGuard temp_mgr_guard;
temp_model::enabled = enabled; temp_model::enabled = enabled;
temp_model::setup(); temp_model::setup();
temp_model::valid = true;
} }
// verify that the model has been enabled // verify that the model has been enabled
if(enabled && !temp_model::enabled) { if(enabled && !temp_model::enabled)
SERIAL_ECHOLNPGM("TM: invalid parameters, cannot enable"); SERIAL_ECHOLNPGM("TM: invalid parameters, cannot enable");
temp_model::valid = false;
}
}
bool temp_model_valid()
{
return temp_model::valid;
} }
void temp_model_set_warn_beep(bool enabled) void temp_model_set_warn_beep(bool enabled)
@ -2590,7 +2581,6 @@ void temp_model_reset_settings()
temp_model::data.err = TEMP_MODEL_E; temp_model::data.err = TEMP_MODEL_E;
temp_model::warn_beep = true; temp_model::warn_beep = true;
temp_model::enabled = true; temp_model::enabled = true;
temp_model::valid = false;
} }
void temp_model_load_settings() void temp_model_load_settings()
@ -2888,8 +2878,12 @@ static bool autotune(int16_t cal_temp)
} // namespace temp_model_cal } // namespace temp_model_cal
static bool temp_model_autotune_err = true;
void temp_model_autotune(int16_t temp, bool selftest) void temp_model_autotune(int16_t temp, bool selftest)
{ {
temp_model_autotune_err = true;
char tm_message[LCD_WIDTH+1]; char tm_message[LCD_WIDTH+1];
if(moves_planned() || printer_active()) { if(moves_planned() || printer_active()) {
sprintf_P(tm_message, PSTR("TM: Cal. NOT IDLE")); sprintf_P(tm_message, PSTR("TM: Cal. NOT IDLE"));
@ -2907,12 +2901,12 @@ void temp_model_autotune(int16_t temp, bool selftest)
temp_model_reset_enabled(selftest); temp_model_reset_enabled(selftest);
SERIAL_ECHOLNPGM("TM: calibration start"); SERIAL_ECHOLNPGM("TM: calibration start");
bool err = temp_model_cal::autotune(temp > 0 ? temp : TEMP_MODEL_CAL_Th); temp_model_autotune_err = temp_model_cal::autotune(temp > 0 ? temp : TEMP_MODEL_CAL_Th);
// always reset temperature // always reset temperature
disable_heater(); disable_heater();
if(err) { if(temp_model_autotune_err) {
sprintf_P(tm_message, PSTR("TM: calibr. failed!")); sprintf_P(tm_message, PSTR("TM: calibr. failed!"));
lcd_setstatus_serial(tm_message); lcd_setstatus_serial(tm_message);
if(temp_error_state.v) if(temp_error_state.v)
@ -2928,6 +2922,11 @@ void temp_model_autotune(int16_t temp, bool selftest)
menu_unset_block(MENU_BLOCK_TEMP_MODEL_AUTOTUNE); menu_unset_block(MENU_BLOCK_TEMP_MODEL_AUTOTUNE);
} }
bool temp_model_autotune_result()
{
return !temp_model_autotune_err;
}
#ifdef TEMP_MODEL_DEBUG #ifdef TEMP_MODEL_DEBUG
void temp_model_log_enable(bool enable) void temp_model_log_enable(bool enable)
{ {

View File

@ -218,7 +218,6 @@ void PID_autotune(float temp, int extruder, int ncycles);
#ifdef TEMP_MODEL #ifdef TEMP_MODEL
void temp_model_set_enabled(bool enabled); void temp_model_set_enabled(bool enabled);
bool temp_model_valid();
void temp_model_set_warn_beep(bool enabled); void temp_model_set_warn_beep(bool enabled);
void temp_model_set_params(float C = NAN, float P = NAN, float Ta_corr = NAN, float warn = NAN, float err = NAN); void temp_model_set_params(float C = NAN, float P = NAN, float Ta_corr = NAN, float warn = NAN, float err = NAN);
void temp_model_set_resistance(uint8_t index, float R); void temp_model_set_resistance(uint8_t index, float R);
@ -229,6 +228,7 @@ void temp_model_load_settings();
void temp_model_save_settings(); void temp_model_save_settings();
void temp_model_autotune(int16_t temp = 0, bool selftest = false); void temp_model_autotune(int16_t temp = 0, bool selftest = false);
bool temp_model_autotune_result(); // return true if the last autotune was complete and successful
#ifdef TEMP_MODEL_DEBUG #ifdef TEMP_MODEL_DEBUG
void temp_model_log_enable(bool enable); void temp_model_log_enable(bool enable);