Skip to content

Commit

Permalink
Implement UI Menu configuration for PWM Power ramping
Browse files Browse the repository at this point in the history
 - add NVS variable to keep PWM ramping sate across reboots
 - add UI elents to confgigure it via "Power Supply" menu
  • Loading branch information
vortigont committed May 26, 2024
1 parent 43cf277 commit 0580e94
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 33 deletions.
2 changes: 1 addition & 1 deletion ESPIron/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class ironState_t {
boost, // heater temperature is increased for a short period of time
setup, // iron is configuration mode, i.e. working with screen menu, heater switches off
notip, // tip is missing or failed
PWRramp // controller is performing Power Ramping
ramping // power ramp in progress
};

// working temperature values
Expand Down
1 change: 1 addition & 0 deletions ESPIron/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ static constexpr const char* T_motionThr = "motionThr"; // motio
static constexpr const char* T_pdVolts = "pdVolts"; // PD trigger voltage
static constexpr const char* T_qcVolts = "qcVolts"; // QC trigger voltage
static constexpr const char* T_qcMode = "qcMode"; // QC Mode
static constexpr const char* T_PWMRamp = "PWMRamp"; // PWM Power ramping
5 changes: 5 additions & 0 deletions ESPIron/evtloop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// helper macro to reduce typing
#define EVT_POST(event_base, event_id) esp_event_post_to(evt::get_hndlr(), event_base, event_id, NULL, 0, portMAX_DELAY)
#define EVT_POST_DATA(event_base, event_id, event_data, data_size) esp_event_post_to(evt::get_hndlr(), event_base, event_id, event_data, data_size, portMAX_DELAY)
#define EVT_POST_ISR(event_base, event_id, tsk_awoken) esp_event_isr_post_to(evt::get_hndlr(), event_base, event_id, NULL, 0, tsk_awoken)

// ESP32 event loop defines
ESP_EVENT_DECLARE_BASE(SENSOR_DATA); // events coming from different sensors, i.e. temperature, voltage, orientation, etc...
Expand Down Expand Up @@ -61,6 +62,8 @@ enum class iron_t:int32_t {

reloadTemp, // reload temperature configuration
reloadTimeouts, // reload timeouts configuration
enablePWMRamp, // PWM ramping on
disablePWMRamp, // PWM ramping off

// Commands - power control
pdVoltage, // switch PD trigger, arg uint32_t in V
Expand All @@ -78,6 +81,8 @@ enum class iron_t:int32_t {
stateBoost, // iron controller switched to 'Boost' mode, parameter uint32_t - seconds left to disable boost mode
stateSetup, // enter in menu confgiration mode
stateNoTip,
statePWRRampStart, // Iron has started power ramping
statePWRRampCmplt, // Iron has completed power ramping
tipEject, // sent by heater when it looses the tip sense
tipInsert, // sent by heater when detect tip sensor

Expand Down
12 changes: 11 additions & 1 deletion ESPIron/heater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "const.h"
#include "evtloop.hpp"
#include "heater.hpp"
#include "main.h"
//#include "main.h"
#include "log.h"

#define HEATER_TASK_PRIO tskIDLE_PRIORITY+1 // task priority
Expand Down Expand Up @@ -322,6 +322,16 @@ void TipHeater::rampUp(){
_state = HeaterState_t::active;
}

bool TipHeater::_cb_ledc_fade_end_event(const ledc_cb_param_t *param, void *arg){
// do not care what was the event, I need to unblock heater control anyway
// if (param->event == LEDC_FADE_END_EVT)

BaseType_t task_awoken;
// notify that rampUp has been complete
EVT_POST_ISR(IRON_NOTIFY, e2int(evt::iron_t::statePWRRampCmplt), &task_awoken);
task_awoken |= xTaskResumeFromISR(static_cast<TipHeater*>(arg)->_task_hndlr);
return task_awoken;
}


// 对32个ADC读数进行平均以降噪
Expand Down
6 changes: 1 addition & 5 deletions ESPIron/heater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ class TipHeater {
// static wrapper for _runner Task to call handling class member
static inline void _runner(void* pvParams){ ((TipHeater*)pvParams)->_heaterControl(); }

static IRAM_ATTR bool _cb_ledc_fade_end_event(const ledc_cb_param_t *param, void *arg){
// do not care what was the event, I need to unblock heater control anyway
// if (param->event == LEDC_FADE_END_EVT)
return xTaskResumeFromISR(static_cast<TipHeater*>(arg)->_task_hndlr) == pdTRUE;
}
static IRAM_ATTR bool _cb_ledc_fade_end_event(const ledc_cb_param_t *param, void *arg);

};
56 changes: 47 additions & 9 deletions ESPIron/hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,19 @@ void ViSet_MainScreen::drawScreen(){
u8g2.print(dictionary[D_idle]);
break;
case ironState_t::working :
u8g2.print(dictionary[D_heating]);
u8g2.print(dictionary[D_Heating]);
break;
case ironState_t::standby :
u8g2.print(dictionary[D_standby]);
u8g2.print(dictionary[D_Standby]);
break;
case ironState_t::boost :
u8g2.print(dictionary[D_boost]);
u8g2.print(dictionary[D_Boost]);
break;
case ironState_t::notip :
u8g2.print(dictionary[D_notip]);
u8g2.print(dictionary[D_NoTip]);
break;
case ironState_t::ramping :
u8g2.print(dictionary[D_Ramping]);
break;

default:;
Expand Down Expand Up @@ -468,16 +471,22 @@ void ViSet_MainScreen::_evt_notify(int32_t id, void* data){
switch(static_cast<evt::iron_t>(id)){
case evt::iron_t::stateIdle :
_state = ironState_t::idle;
break;
break;
case evt::iron_t::stateWorking :
_state = ironState_t::working;
break;
break;
case evt::iron_t::stateStandby :
_state = ironState_t::standby;
break;
break;
case evt::iron_t::stateBoost :
_state = ironState_t::boost;
break;
break;
case evt::iron_t::statePWRRampStart :
_state = ironState_t::ramping;
break;
case evt::iron_t::statePWRRampCmplt :
_state = ironState_t::working;
break;
}
}

Expand Down Expand Up @@ -982,13 +991,14 @@ ViSet_PwrSetup::ViSet_PwrSetup(GPIOButton<ESPEventPolicy> &button, PseudoRotaryE
// go back to prev viset on exit
parentvs = viset_evt_t::goBack;

// load PD voltage values from NVS
// load settings values from NVS
esp_err_t err;
std::unique_ptr<nvs::NVSHandle> handle = nvs::open_nvs_handle(T_IRON, NVS_READONLY, &err);
if (err == ESP_OK) {
handle->get_item(T_pdVolts, _volts_pd);
handle->get_item(T_qcVolts, _volts_qc);
handle->get_item(T_qcMode, _qc_mode);
handle->get_item(T_PWMRamp, _pwm_ramp);
}

// set our iterator to selected voltage option
Expand Down Expand Up @@ -1019,7 +1029,11 @@ ViSet_PwrSetup::~ViSet_PwrSetup(){
handle->set_item(T_pdVolts, _volts_pd);
handle->set_item(T_qcVolts, _volts_qc);
handle->set_item(T_qcMode, _qc_mode);
handle->set_item(T_PWMRamp, _pwm_ramp);
}

// command for PWM ramping
EVT_POST(IRON_SET_EVT, _pwm_ramp ? e2int(iron_t::enablePWMRamp) : e2int(iron_t::disablePWMRamp) );
}

void ViSet_PwrSetup::_buildMenu(){
Expand Down Expand Up @@ -1153,6 +1167,30 @@ void ViSet_PwrSetup::_buildMenu(){
);


// **************************************
// ***** Page "Power Supply->PWM Ramp
muiItemId pwmramp_page = makePage(menu_PwrControlOpts.at(2), root_page);

// Page Title
addItemToPage(ptitle_idx, pwmramp_page);

// create checkbox item
addMuippItem(
new MuiItem_U8g2_CheckBox(u8g2, nextIndex(), dictionary[D_PwrRamp_label], _pwm_ramp, [&](size_t idx){ _pwm_ramp = idx; }, PAGE_TITLE_FONT, 0, SMALL_TEXT_FONT_Y_OFFSET+PAGE_TITLE_FONT_Y_OFFSET),
pwmramp_page
);

// create text hint
addMuippItem(
new MuiItem_U8g2_StaticText(u8g2, nextIndex(), dictionary[D_PwrRamp_hint], SMALL_TEXT_FONT, 0, 2*SMALL_TEXT_FONT_Y_OFFSET + PAGE_TITLE_FONT_Y_OFFSET),
pwmramp_page
);

// add back button on a warn page, it will lead to the root page
addItemToPage(bb_idx, pwmramp_page);



// start menu from root page
menuStart(root_page);
}
Expand Down
2 changes: 2 additions & 0 deletions ESPIron/hid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ class ViSet_PwrSetup : public MuiMenu {
// selected QC mode (index for menu_QCFunctionOpts array)
uint32_t _qc_mode{0};

bool _pwm_ramp{false};

// containters for string data that will be printed on-screen
// selected PD/QC voltage
std::string _pdv_s, _qcv_s;
Expand Down
19 changes: 15 additions & 4 deletions ESPIron/ironcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ void IronController::init(){

if (err != ESP_OK) return;

// restore PWM Ramping option
handle->get_item(T_PWMRamp, _pwm_ramp);

// init PD trigger
handle->get_item(T_pdVolts, _voltage);
_pd_trigger_init();
Expand Down Expand Up @@ -243,10 +246,9 @@ void IronController::_evt_commands(esp_event_base_t base, int32_t id, void* data
LOGI(T_CTRL, println, "switch to working mode");
// set heater to work temperature
EVT_POST_DATA(IRON_HEATER, e2int(iron_t::heaterTargetT), &_temp.working, sizeof(_temp.working));
// enable heater
EVT_POST(IRON_HEATER, e2int(iron_t::heaterEnable));
//EVT_POST(IRON_HEATER, e2int(iron_t::heaterRampUp));
EVT_POST(IRON_NOTIFY, e2int(iron_t::stateWorking)); // mode change notification
// enable heater either with PWM ramping or plain
EVT_POST(IRON_HEATER, _pwm_ramp ? e2int(iron_t::heaterRampUp) : e2int(iron_t::heaterEnable));
EVT_POST(IRON_NOTIFY, _pwm_ramp ? e2int(iron_t::statePWRRampStart) : e2int(iron_t::stateWorking)); // mode change notification
break;

case ironState_t::boost :
Expand Down Expand Up @@ -358,6 +360,15 @@ void IronController::_evt_commands(esp_event_base_t base, int32_t id, void* data
if(_qc) _qc->setQCV (*reinterpret_cast<uint32_t*>(data));
break;

// PWM ramp control
case evt::iron_t::enablePWMRamp :
_pwm_ramp = true;
break;

case evt::iron_t::disablePWMRamp :
_pwm_ramp = false;
break;

/*
// switch QC trigger modes
case evt::iron_t::qcDisable :
Expand Down
3 changes: 3 additions & 0 deletions ESPIron/ironcontroller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class IronController {
// working voltage, set default to 20v to let PD trigger select if no value set in NVS
uint32_t _voltage{20};

// Use PWM power ramping
bool _pwm_ramp{false};

// Mode Switcher timer
TimerHandle_t _tmr_mode = nullptr;

Expand Down
15 changes: 9 additions & 6 deletions ESPIron/lang/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define MENU_MAIN_CFG_SIZE 6
#define MENU_TEMPERATURE_CFG_SIZE 5
#define MENU_TIMEOUTS_CFG_SIZE 5
#define MENU_PWR_CONTROL_CFG_SIZE 3
#define MENU_PWR_CONTROL_CFG_SIZE 4

/*
// List of available translations
Expand All @@ -34,15 +34,18 @@ enum lang_index : uint32_t {
* the order of enums MUST match with elements in dictionary array
*/
enum dict_index {
D_boost = (0),
D_error,
D_Boost = (0),
D_Error,
D_Disabled,
D_heating,
D_Heating,
D_idle,
D_min,
D_none,
D_notip,
D_NoTip,
D_OK,
D_Ramping,
D_PwrRamp_label,
D_PwrRamp_hint,
D_return,
D_PDVoltage,
D_QCMode,
Expand All @@ -52,7 +55,7 @@ enum dict_index {
D_SaveLast_hint,
D_Settings,
D_set_t,
D_standby,
D_Standby,
// Notes goes below
D_Note_QCWarn,
D_Temp_SaveLastWrkDescr,
Expand Down
25 changes: 18 additions & 7 deletions ESPIron/lang/lang_en_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

// 11x15 nice bold font
#define PAGE_TITLE_FONT u8g2_font_bauhaus2015_tr
#define PAGE_TITLE_FONT_Y_OFFSET 15

// 12x16 wrong? small gothic font
#define PAGE_TITLE_FONT_SMALL u8g2_font_glasstown_nbp_t_all
Expand Down Expand Up @@ -60,22 +61,25 @@
// EN-US
namespace lang_en_us {

// EN US
// Iron Modes (On main screen)
static constexpr const char* T_Idle = "Idle"; // state display
static constexpr const char* T_Heating = "Heating"; // state display
static constexpr const char* T_Standby = "Standby"; // state display in 'Standby'
static constexpr const char* T_Boost = "Boost"; // state display
static constexpr const char* T_Ramping = "Ramping!"; // state display power ramp
static constexpr const char* T_NoTip = "No tip!"; // state display when tip is missing

// Others
static constexpr const char* T_Disabled = "Disabled"; // disabled option
static constexpr const char* T_Error = "Error";
static constexpr const char* T_Heating = "Heating"; // state display
static constexpr const char* T_Idle = "Idle"; // state display
static constexpr const char* T_min = "min."; // short for 'minutes'
static constexpr const char* T_none = "none"; // none option
static constexpr const char* T_NoTip = "No tip!"; // state display when tip is missing
static constexpr const char* T_OK = "OK"; // OK label/message
static constexpr const char* T_PDVoltage = "PD Voltage:"; // PowerDelivery trigger voltage
static constexpr const char* T_QCMode = "QC Mode:"; // QC trigger mode
static constexpr const char* T_QCVoltage = "QC Voltage:"; // QC trigger voltage
static constexpr const char* T_sec = "sec."; // short for 'seconds'
static constexpr const char* T_setT = "Set:"; // Target temperature on main screen
static constexpr const char* T_standby = "Standby"; // state display in 'Standby'
static constexpr const char* T_return = "<Back"; // return back in menu's

// Menu Page names
Expand Down Expand Up @@ -107,15 +111,18 @@ static constexpr const char* T_TimeBoost = "Boost timeout";
// Power Supply settings menu
static constexpr const char* T_PwrPD = "PD Trigger";
static constexpr const char* T_PwrQC = "QC Trigger";
static constexpr const char* T_PwrRamp = "Power Ramp";


// **** Descriptions and Notes ****

// Temp settings descr
static constexpr const char* T_Temp_SaveLastWrkDescr = "Save last work Temperature";

// QC feature warning
static constexpr const char* T_Note_QCWarn = "QC trigger is experimental!!!\nMight work unstable! Do unplug 'n replug the Iron on QC-mode change!";
// PWM Ramping settings hints
static constexpr const char* T_PwrRamp_label = "Use PWM Ramp";
static constexpr const char* T_PwrRamp_hint = "Smooth power-up to prevent PSU protection kick-in";



Expand All @@ -136,6 +143,9 @@ static constexpr std::array<const char *, DICT___SIZE> dictionary = {
lang_en_us::T_none,
lang_en_us::T_NoTip,
lang_en_us::T_OK,
lang_en_us::T_Ramping,
lang_en_us::T_PwrRamp_label,
lang_en_us::T_PwrRamp_hint,
lang_en_us::T_return,
lang_en_us::T_PDVoltage,
lang_en_us::T_QCMode,
Expand All @@ -145,7 +155,7 @@ static constexpr std::array<const char *, DICT___SIZE> dictionary = {
lang_en_us::T_SaveLast_hint,
lang_en_us::T_Settings,
lang_en_us::T_setT,
lang_en_us::T_standby,
lang_en_us::T_Standby,
// Notes goes below
lang_en_us::T_Note_QCWarn,
lang_en_us::T_Temp_SaveLastWrkDescr
Expand Down Expand Up @@ -183,6 +193,7 @@ static constexpr std::array<const char *, MENU_TIMEOUTS_CFG_SIZE> menu_TimeoutOp
static constexpr std::array<const char *, MENU_PWR_CONTROL_CFG_SIZE> menu_PwrControlOpts = {
lang_en_us::T_PwrPD,
lang_en_us::T_PwrQC,
lang_en_us::T_PwrRamp,
lang_en_us::T_return
};

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Menu navigation demo capture.
| :floppy_disk: (optionaly) save/restore last used temperature | :white_check_mark: done |
| PD Configuration | :white_check_mark: done |
| QC2/QC3 trigger | :white_check_mark: done (experimental) |
| :mountain_cableway: PWM Power ramping | :white_check_mark: done |
| :straight_ruler: Tip calibration | :x: Planned |
| :memo: Tip profiles | :x: Planned |
| :wavy_dash: Power profile | :x: Planned |
Expand Down

0 comments on commit 0580e94

Please sign in to comment.