From b2a29edc452ebe04caa84a11e1f9ffa3b349f77e Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Mon, 15 May 2023 10:12:24 +0300 Subject: [PATCH 1/4] menu:[#43] read/write setpoint within eeprom --- source/shoh/src/threads/manager/Menu.cpp | 16 ++++++++++++++++ source/shoh/src/threads/manager/Menu.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/source/shoh/src/threads/manager/Menu.cpp b/source/shoh/src/threads/manager/Menu.cpp index 0415721..4d17cf1 100644 --- a/source/shoh/src/threads/manager/Menu.cpp +++ b/source/shoh/src/threads/manager/Menu.cpp @@ -19,6 +19,7 @@ set_point_text("CURRENT %3d DESIRED[%3d] ") this->SetState(&Menu::sInitView); ext_temp.setCurrent(0); set_point.setCurrent(0); + readSetPointFromEEPROM(); } Menu::~Menu() @@ -26,6 +27,17 @@ Menu::~Menu() LOG_DEBUG("Deleting Menu"); } +void +Menu::readSetPointFromEEPROM (void) +{ + EventRawData *data = (EventRawData *)eeprom.read_from (EEPROM_START_ADDR, + sizeof(EventRawData)); + if ((*data) > 0 && (*data) < 120) + { + ext_temp.setCurrent(*data); + } +} + void Menu::HandleEventPair (Event::EventPair *ep) { switch(ep->et/*EventType*/) @@ -135,6 +147,7 @@ void Menu::sMainView(const MenuObjEvent &e) void Menu::sSetPointMod(const MenuObjEvent &e) { static char screen_text[64]; + EventRawData sp; switch (e.type) { case MenuObjEvent::eFocus: @@ -161,6 +174,9 @@ void Menu::sSetPointMod(const MenuObjEvent &e) break; case MenuObjEvent::eClick: LOG_DEBUG("click sSetPointMod"); + sp = set_point.getCurrent(); + // Write to EEPROM + eeprom.write_to(EEPROM_START_ADDR, (void*)&sp, sizeof(EventRawData)); this->SetState(&Menu::sMainView); break; case MenuObjEvent::eRefresh: diff --git a/source/shoh/src/threads/manager/Menu.h b/source/shoh/src/threads/manager/Menu.h index 676ceb0..76b1a22 100644 --- a/source/shoh/src/threads/manager/Menu.h +++ b/source/shoh/src/threads/manager/Menu.h @@ -11,6 +11,7 @@ #include "Counter.h" #include "MenuObjEvent.h" #include "ThreadCommon.h" +#include "EEPROMio.h" #include "Event.h" class Menu; @@ -29,6 +30,7 @@ private: p_state current; Counter ext_temp; Counter set_point; + EEPROMio eeprom; const char main_text[64]; const char set_point_text[64]; /* States */ @@ -39,6 +41,7 @@ private: void SetState (p_state new_state); void HandleObj (const MenuObjEvent &event); void NotifyAndRefreshUI (const char *str); + void readSetPointFromEEPROM (void); }; #endif /* THREADS_MANAGER_MENU_H_ */ From 7394202b51b43bedabdb7d4ed4676f5eccbd7b7a Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Mon, 15 May 2023 10:17:36 +0300 Subject: [PATCH 2/4] menu: [#43] send SetPoint to master on queue --- source/shoh/src/threads/manager/Menu.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/shoh/src/threads/manager/Menu.cpp b/source/shoh/src/threads/manager/Menu.cpp index 4d17cf1..61231df 100644 --- a/source/shoh/src/threads/manager/Menu.cpp +++ b/source/shoh/src/threads/manager/Menu.cpp @@ -148,6 +148,7 @@ void Menu::sSetPointMod(const MenuObjEvent &e) { static char screen_text[64]; EventRawData sp; + Event event_sp (Event::EventType::SetPoint, set_point.getCurrent()); switch (e.type) { case MenuObjEvent::eFocus: @@ -177,7 +178,12 @@ void Menu::sSetPointMod(const MenuObjEvent &e) sp = set_point.getCurrent(); // Write to EEPROM eeprom.write_to(EEPROM_START_ADDR, (void*)&sp, sizeof(EventRawData)); + + event_sp.setDataOf(Event::EventType::SetPoint, sp); + _qm->send(ThreadCommon::QueueManager::master_event_all, &event_sp, 1); + this->SetState(&Menu::sMainView); + break; case MenuObjEvent::eRefresh: LOG_DEBUG("refresh sSetPointMod"); From 27346abb47154882c07c5c2fc6ecd47da58295bf Mon Sep 17 00:00:00 2001 From: RedHawk Date: Mon, 15 May 2023 11:47:52 +0300 Subject: [PATCH 3/4] menu: [#43] Fix the stack size. --- source/shoh/src/threads/master/Master.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index 23d6536..e9f1204 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -92,7 +92,7 @@ void thread_master(void* pvParams) { ThreadCommon::QueueManager::logging_message_all); logging_queue = manager->qm->getQueue(ThreadCommon::QueueManager::logging_message_all); manager->tm->createTask(thread_logging, "logging", - configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL, + configMINIMAL_STACK_SIZE * 9,tskIDLE_PRIORITY + 1UL, static_cast(manager)); LOG_INFO("Logging Active"); @@ -117,16 +117,16 @@ void thread_master(void* pvParams) { LOG_INFO("Master is creating tasks"); manager->tm->createTask(thread_manager, "manager", - configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL, + configMINIMAL_STACK_SIZE * 15,tskIDLE_PRIORITY + 1UL, static_cast(manager)); manager->tm->createTask(thread_rotary, "rotary", - configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL, + configMINIMAL_STACK_SIZE * 9,tskIDLE_PRIORITY + 1UL, static_cast(manager)); manager->tm->createTask(thread_user_interface, "user_interface", - configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL, + configMINIMAL_STACK_SIZE * 9,tskIDLE_PRIORITY + 1UL, static_cast(manager)); manager->tm->createTask(thread_relay, "relay", - configMINIMAL_STACK_SIZE * 10,tskIDLE_PRIORITY + 1UL, + configMINIMAL_STACK_SIZE * 9,tskIDLE_PRIORITY + 1UL, static_cast(manager)); LOG_INFO("Master created tasks"); m.taskFunction(); From f6c7586bed606cfea61e3d27a0cc2635982dfa33 Mon Sep 17 00:00:00 2001 From: RedHawk Date: Mon, 15 May 2023 12:46:49 +0300 Subject: [PATCH 4/4] menu: [#43] Get the set_point from the EEPROM --- source/shoh/src/threads/manager/Menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/shoh/src/threads/manager/Menu.cpp b/source/shoh/src/threads/manager/Menu.cpp index 61231df..19d8593 100644 --- a/source/shoh/src/threads/manager/Menu.cpp +++ b/source/shoh/src/threads/manager/Menu.cpp @@ -34,7 +34,7 @@ Menu::readSetPointFromEEPROM (void) sizeof(EventRawData)); if ((*data) > 0 && (*data) < 120) { - ext_temp.setCurrent(*data); + set_point.setCurrent(*data); } }