Skip to content

Commit

Permalink
fixes on idle temperature control
Browse files Browse the repository at this point in the history
idle temp was displayed incorrectly on main screen always showing default temp instead of configured one
  • Loading branch information
vortigont committed Aug 25, 2024
1 parent 1a5352c commit 7e8d341
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion ESPIron/heater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ void TipHeater::_evt_picker(esp_event_base_t base, int32_t id, void* data){
case evt::iron_t::heaterTargetT : {
// change heater temp
setTargetTemp(*reinterpret_cast<int32_t*>(data));
LOGD(T_HEAT, printf, "set target T:%d\n", _t.target);
return;
}

Expand Down Expand Up @@ -127,6 +126,10 @@ void TipHeater::_evt_picker(esp_event_base_t base, int32_t id, void* data){
}
}

void TipHeater::setTargetTemp(int32_t t){
_t.target = t;
LOGD(T_HEAT, printf, "set target T:%d\n", _t.target);
};

void TipHeater::_start_runner(){
// Prepare and then apply the LEDC PWM timer configuration
Expand Down
2 changes: 1 addition & 1 deletion ESPIron/heater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class TipHeater {
*
* @param t
*/
void setTargetTemp(int32_t t){ _t.target = t; };
void setTargetTemp(int32_t t);

/**
* @brief Get the Target heater temperature
Expand Down
5 changes: 5 additions & 0 deletions ESPIron/hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ ViSet_MainScreen::ViSet_MainScreen(GPIOButton<ESPEventPolicy> &button, PseudoRot
encdr.setCounter(TEMP_DEFAULT, TEMP_STEP, TEMP_MIN, TEMP_MAX);
encdr.setMultiplyFactor(2);

// load configured temperatures
nvs_blob_read(T_IRON, T_temperatures, static_cast<void*>(&_temp), sizeof(Temperatures));

// request working temperature from IronController
EVT_POST(IRON_GET_EVT, e2int(iron_t::workTemp));
}
Expand Down Expand Up @@ -491,12 +494,14 @@ void ViSet_MainScreen::_evt_notify(int32_t id, void* data){
}

void ViSet_MainScreen::_evt_cmd(int32_t id, void* data){
/* not used currently
switch(static_cast<evt::iron_t>(id)){
case evt::iron_t::workTemp :
_temp.working = *reinterpret_cast<int32_t*>(data);
encdr.setCounter(_temp.working, TEMP_STEP, TEMP_MIN, TEMP_MAX);
break;
}
*/
}

void ViSet_MainScreen::_evt_state(int32_t id, void* data){
Expand Down
17 changes: 12 additions & 5 deletions ESPIron/ironcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void IronController::_mode_switcher(){
_state = ironState_t::standby;
LOGI(T_CTRL, printf, "Engage standby mode due to sleep timeout of %u ms. Temp:%u\n", _timeout.standby, _temp.standby);
// switch heater temperature to standby value
EVT_POST_DATA(IRON_SET_EVT, e2int(iron_t::heaterTargetT), &_temp.standby, sizeof(_temp.standby));
EVT_POST_DATA(IRON_HEATER, e2int(iron_t::heaterTargetT), &_temp.standby, sizeof(_temp.standby));
// notify other componets that we are switching to 'standby' mode
EVT_POST(IRON_NOTIFY, e2int(iron_t::stateStandby));
}
Expand All @@ -156,13 +156,18 @@ void IronController::_mode_switcher(){
LOGI(T_CTRL, printf, "Engage idle mode due to idle timeout of %u ms\n", _timeout.idle);
// notify other componets that we are switching to 'idle' mode
EVT_POST(IRON_NOTIFY, e2int(iron_t::stateIdle));
// disable heater
EVT_POST(IRON_HEATER, e2int(iron_t::heaterDisable));
} else if (pdTICKS_TO_MS(xTaskGetTickCount()) - pdTICKS_TO_MS(_xTicks.motion) < _timeout.standby){
// standby cancelled
_state = ironState_t::working;
LOGI(T_CTRL, println, "cancel Standby mode");
// notify other componets that we are switching to 'work' mode
EVT_POST(IRON_NOTIFY, e2int(iron_t::stateWorking));
EVT_POST_DATA(IRON_SET_EVT, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
// switch on heater
EVT_POST(IRON_HEATER, e2int(iron_t::heaterEnable));
// set target T for heater
EVT_POST_DATA(IRON_HEATER, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
}
return;
}
Expand Down Expand Up @@ -197,6 +202,8 @@ void IronController::_mode_switcher(){
// notify other componets that we are switching to 'working' mode
EVT_POST(IRON_NOTIFY, e2int(iron_t::stateWorking));
LOGI(T_CTRL, printf, "Engage work mode due to boost timeout of %u ms\n", _timeout.boost);
// set target T for heater
EVT_POST_DATA(IRON_HEATER, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
} else {
// send notification with time left till boost is disabled (in seconds)
unsigned time_left = _timeout.boost - t;
Expand Down Expand Up @@ -287,7 +294,7 @@ void IronController::_evt_commands(esp_event_base_t base, int32_t id, void* data
EVT_POST_DATA(IRON_NOTIFY, e2int(iron_t::stateBoost), &_timeout.boost, sizeof(_timeout.boost));
// set heater to boost temperature
int32_t t = _temp.working + _temp.boost;
EVT_POST_DATA(IRON_SET_EVT, e2int(iron_t::heaterTargetT), &t, sizeof(t));
EVT_POST_DATA(IRON_HEATER, e2int(iron_t::heaterTargetT), &t, sizeof(t));
_xTicks.boost = xTaskGetTickCount();
break;
}
Expand All @@ -298,7 +305,7 @@ void IronController::_evt_commands(esp_event_base_t base, int32_t id, void* data
// notify other components
LOGI(T_CTRL, println, "switch to Work mode");
EVT_POST(IRON_NOTIFY, e2int(iron_t::stateWorking));
EVT_POST_DATA(IRON_SET_EVT, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
EVT_POST_DATA(IRON_HEATER, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
break;
}
break;
Expand Down Expand Up @@ -327,7 +334,7 @@ void IronController::_evt_commands(esp_event_base_t base, int32_t id, void* data
nvs_blob_write(T_IRON, T_temperatures, static_cast<void*>(&_temp), sizeof(Temperatures));
}
if (_state == ironState_t::working)
EVT_POST_DATA(IRON_SET_EVT, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
EVT_POST_DATA(IRON_HEATER, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
break;
}

Expand Down

0 comments on commit 7e8d341

Please sign in to comment.