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 @@
+
@@ -71,6 +72,7 @@
+
@@ -88,6 +90,7 @@
+
@@ -118,6 +121,7 @@
+
@@ -188,6 +193,7 @@
+
@@ -215,6 +221,7 @@
+
@@ -232,6 +239,7 @@
+
@@ -262,6 +270,7 @@
+
diff --git a/esp-vent-main/.project b/esp-vent-main/.project
index 54e112e..83a2e6e 100644
--- a/esp-vent-main/.project
+++ b/esp-vent-main/.project
@@ -8,6 +8,7 @@
DigitalIoPin
LiquidCrystal
I2C
+ StateHandler
diff --git a/esp-vent-main/src/esp-vent-main.cpp b/esp-vent-main/src/esp-vent-main.cpp
index ed0f3ef..8bfcb9c 100644
--- a/esp-vent-main/src/esp-vent-main.cpp
+++ b/esp-vent-main/src/esp-vent-main.cpp
@@ -16,6 +16,9 @@
#endif
#endif
+#include "DigitalIoPin.h"
+#include "StateHandler.h"
+
#include
// TODO: insert other include files here
@@ -30,7 +33,7 @@ main (void)
// Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate ();
#if !defined(NO_BOARD_LIB)
- // Set up and initialize all required blocks and
+ // Set b_up_state and initialize all required blocks and
// functions related to the board hardware
Board_Init ();
// Set the LED to the state of "On"
@@ -38,8 +41,43 @@ main (void)
#endif
#endif
+ DigitalIoPin b_up ();
+ DigitalIoPin b_down ();
+ DigitalIoPin b_toggle ();
+ bool b_up_state = false, b_down_state = false, b_toggle_state = false;
+
+ StateHandler ventMachine;
+
while (1)
{
+ if (b_up.read ())
+ b_up_state = true;
+ if (!b_up.read () && b_up_state)
+ {
+ ventMachine.HandleState (Event (Event::eKey, BUTTON_CONTROL_UP));
+ b_up_state = false;
+ }
+ if (b_down.read ())
+ b_down_state = true;
+ if (!b_down.read () && b_down_state)
+ {
+ ventMachine.HandleState (Event (Event::eKey, BUTTON_CONTROL_DOWN));
+ b_down_state = false;
+ }
+ if (b_toggle.read ())
+ b_toggle_state = true;
+ if (!b_toggle.read () && b_toggle_state)
+ {
+ ventMachine.HandleState (
+ Event (Event::eKey, BUTTON_CONTROL_TOG_MODE));
+ b_toggle_state = false;
+ }
+
+ /**
+ * TODO:
+ * - Update current pressure to eTick
+ */
+ ventMachine.HandleState (Event (Event::eTick));
}
return 0;