From 0a0f55a07908f3dd756e3a774a79728049478d08 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Mon, 10 Oct 2022 15:06:47 +0300 Subject: [PATCH 1/6] state-handler: add printout in displaySet Create printouts on lcd for both manual and auto modes. --- StateHandler/inc/StateHandler.h | 2 +- StateHandler/src/StateHandler.cpp | 48 ++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/StateHandler/inc/StateHandler.h b/StateHandler/inc/StateHandler.h index d22a914..7a847a3 100644 --- a/StateHandler/inc/StateHandler.h +++ b/StateHandler/inc/StateHandler.h @@ -96,7 +96,7 @@ private: * @param newstate new state to be set to current */ void SetState (state_pointer newstate); - bool current_mode; + uint8_t current_mode; Counter value[2] = { { 0, 100 }, { 0, 120 } }; LiquidCrystal *_lcd; diff --git a/StateHandler/src/StateHandler.cpp b/StateHandler/src/StateHandler.cpp index a4518c7..c464a8f 100644 --- a/StateHandler/src/StateHandler.cpp +++ b/StateHandler/src/StateHandler.cpp @@ -21,19 +21,41 @@ StateHandler::~StateHandler () void StateHandler::displaySet (unsigned int value1, unsigned int value2) { - // TODO - /** - * MANUAL MODE: - * ---------------- - * SPEED: 20% - * PRESSURE: XXPa - * ---------------- - * AUTO MODE: - * ---------------- - * PRESSURE SET: 35Pa - * PRESSURE CUR: XXPa - * ---------------- - */ + char line_up[16] = { 0 }; + char line_down[16] = { 0 }; + + switch (current_mode) + { + /* + * MANUAL MODE: + * ---------------- + * SPEED: 20% + * PRESSURE: XXPa + * ---------------- + */ + case MANUAL: + snprintf (line_up, 16, "SPEED: %02d%", value1); + snprintf (line_down, 16, "PRESSURE: %02dPa", value2); + break; + /* + * AUTO MODE: + * ---------------- + * PRESSURE SET: 35Pa + * PRESSURE CUR: XXPa + * ---------------- + */ + case AUTO: + snprintf (line_up, 16, "P. SET: %02dPa", value1); + snprintf (line_down, 16, "P. CURR: %02dPa", value2); + break; + default: + break; + } + _lcd->clear (); + _lcd->setCursor (0, 0); + _lcd->print (line_up); + _lcd->setCursor (0, 1); + _lcd->print (line_down); } unsigned int From 885b23b8320554af2feee1b26696b2ab59f7d8c7 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Fri, 14 Oct 2022 12:44:14 +0300 Subject: [PATCH 2/6] state-handler: add buttonHandler --- StateHandler/inc/StateHandler.h | 6 ++++++ StateHandler/src/StateHandler.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/StateHandler/inc/StateHandler.h b/StateHandler/inc/StateHandler.h index 7a847a3..1c73f9d 100644 --- a/StateHandler/inc/StateHandler.h +++ b/StateHandler/inc/StateHandler.h @@ -124,6 +124,12 @@ private: * @param event */ void stateAuto (const Event &event); + + /** Hnadle button presses + * + * @param button current button + */ + void handleControlButtons (uint8_t button); }; #endif /* STATE_HANDLER_H_ */ diff --git a/StateHandler/src/StateHandler.cpp b/StateHandler/src/StateHandler.cpp index c464a8f..d2202d8 100644 --- a/StateHandler/src/StateHandler.cpp +++ b/StateHandler/src/StateHandler.cpp @@ -130,4 +130,23 @@ stateAuto (const Event &event) case Event::eTick: break; } +} + +void +handleControlButtons (uint8_t button) +{ + switch (button) + { + case BUTTON_CONTROL_DOWN: + /* code */ + break; + case BUTTON_CONTROL_UP: + /* code */ + break; + case BUTTON_CONTROL_TOG_MODE: + /* code */ + break; + default: + break; + } } \ No newline at end of file From acb1b73b9a734cc7c254e85c0fedd76ba32bde2c Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Fri, 14 Oct 2022 13:53:00 +0300 Subject: [PATCH 3/6] state-handler: create eKey fucntionality This commit introduces buttonHandling of esp-vent within the StateHandler class and main(). --- .../info.properties | 2 +- StateHandler/inc/Event.h | 4 +- StateHandler/inc/StateHandler.h | 2 +- StateHandler/src/StateHandler.cpp | 69 ++++++++++++------- esp-vent-main/.cproject | 10 +++ esp-vent-main/.project | 1 + esp-vent-main/src/esp-vent-main.cpp | 40 ++++++++++- 7 files changed, 97 insertions(+), 31 deletions(-) diff --git a/.mcuxpressoide_packages_support/info.properties b/.mcuxpressoide_packages_support/info.properties index 0eacd38..2d68962 100644 --- a/.mcuxpressoide_packages_support/info.properties +++ b/.mcuxpressoide_packages_support/info.properties @@ -1,5 +1,5 @@ #MCUXpresso IDE -#Wed Sep 14 11:02:46 EEST 2022 +#Fri Oct 14 12:50:11 EEST 2022 product.name=MCUXpresso IDE v11.5.0 [Build 7232] [2022-01-11] product.version=11.5.0 product.build=7232 diff --git a/StateHandler/inc/Event.h b/StateHandler/inc/Event.h index 6785bad..9bf7e45 100644 --- a/StateHandler/inc/Event.h +++ b/StateHandler/inc/Event.h @@ -23,10 +23,10 @@ class Event { /** Time event */ eTick }; - Event(eventType e = eTick, int b = 0, int t = 0) + Event(eventType e = eTick, uint8_t b = 0, int t = 0) : type(e), button(b), temp(t){}; eventType type; - int button; + uint8_t button; int temp; }; diff --git a/StateHandler/inc/StateHandler.h b/StateHandler/inc/StateHandler.h index 1c73f9d..bd38137 100644 --- a/StateHandler/inc/StateHandler.h +++ b/StateHandler/inc/StateHandler.h @@ -96,7 +96,7 @@ private: * @param newstate new state to be set to current */ void SetState (state_pointer newstate); - uint8_t current_mode; + bool current_mode; Counter value[2] = { { 0, 100 }, { 0, 120 } }; LiquidCrystal *_lcd; diff --git a/StateHandler/src/StateHandler.cpp b/StateHandler/src/StateHandler.cpp index d2202d8..9186236 100644 --- a/StateHandler/src/StateHandler.cpp +++ b/StateHandler/src/StateHandler.cpp @@ -10,7 +10,9 @@ StateHandler::StateHandler (LiquidCrystal *lcd) { this->_lcd = lcd; - // TODO + current = &StateHandler::stateInit; + (this->*current) (Event (Event::eEnter)); + current_mode = MANUAL; } StateHandler::~StateHandler () @@ -40,8 +42,8 @@ StateHandler::displaySet (unsigned int value1, unsigned int value2) /* * AUTO MODE: * ---------------- - * PRESSURE SET: 35Pa - * PRESSURE CUR: XXPa + * P. SET: 35Pa + * P. CURR: XXPa * ---------------- */ case AUTO: @@ -85,15 +87,43 @@ StateHandler::SetState (state_pointer newstate) } void -stateInit (const Event &event) +StateHandler::stateInit (const Event &event) { switch (event.type) { case Event::eEnter: break; case Event::eExit: + _lcd->clear (); break; case Event::eKey: + handleControlButtons (event.button); + break; + case Event::eTick: + if (current_mode == MANUAL) + { + SetState (&StateHandler::stateManual); + } + else + { + SetState (&StateHandler::stateAuto); + } + break; + } +} + +void +StateHandler::stateManual (const Event &event) +{ + switch (event.type) + { + case Event::eEnter: + break; + case Event::eExit: + _lcd->clear (); + break; + case Event::eKey: + handleControlButtons (event.button); break; case Event::eTick: break; @@ -101,15 +131,17 @@ stateInit (const Event &event) } void -stateManual (const Event &event) +StateHandler::stateAuto (const Event &event) { switch (event.type) { case Event::eEnter: break; case Event::eExit: + _lcd->clear (); break; case Event::eKey: + handleControlButtons (event.button); break; case Event::eTick: break; @@ -117,36 +149,21 @@ stateManual (const Event &event) } void -stateAuto (const Event &event) -{ - switch (event.type) - { - case Event::eEnter: - break; - case Event::eExit: - break; - case Event::eKey: - break; - case Event::eTick: - break; - } -} - -void -handleControlButtons (uint8_t button) +StateHandler::handleControlButtons (uint8_t button) { switch (button) { case BUTTON_CONTROL_DOWN: - /* code */ + this->value[(current_mode) ? AUTO : MANUAL].dec (); break; case BUTTON_CONTROL_UP: - /* code */ + this->value[(current_mode) ? AUTO : MANUAL].inc (); break; case BUTTON_CONTROL_TOG_MODE: - /* code */ + current_mode = !current_mode; + SetState (&StateHandler::stateInit); break; default: break; } -} \ No newline at end of file +} diff --git a/esp-vent-main/.cproject b/esp-vent-main/.cproject index 56d571c..424e11a 100644 --- a/esp-vent-main/.cproject +++ b/esp-vent-main/.cproject @@ -44,6 +44,7 @@ + @@ -118,6 +121,7 @@ + @@ -262,6 +270,7 @@ +