diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..97da8e0
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,5 @@
+{
+ "C_Cpp.autocompleteAddParentheses": true,
+ "files.autoSave": "onFocusChange",
+ "C_Cpp.codeAnalysis.clangTidy.enabled": true
+}
\ No newline at end of file
diff --git a/StateHandler/.cproject b/StateHandler/.cproject
index 7731589..dce4dd8 100644
--- a/StateHandler/.cproject
+++ b/StateHandler/.cproject
@@ -48,6 +48,7 @@
+
@@ -71,6 +72,7 @@
+
@@ -87,6 +89,7 @@
+
@@ -149,6 +152,7 @@
+
@@ -173,6 +177,7 @@
+
@@ -189,6 +194,7 @@
+
diff --git a/StateHandler/.project b/StateHandler/.project
index ca7ae8f..428ff80 100644
--- a/StateHandler/.project
+++ b/StateHandler/.project
@@ -5,6 +5,7 @@
lpc_chip_15xx
DigitalIoPin
+ LiquidCrystal
diff --git a/StateHandler/Debug/src/StateHandler.su b/StateHandler/Debug/src/StateHandler.su
index 6b60dbb..5f05996 100644
--- a/StateHandler/Debug/src/StateHandler.su
+++ b/StateHandler/Debug/src/StateHandler.su
@@ -1,5 +1,10 @@
-../src/StateHandler.cpp:10:1:StateHandler::StateHandler(EVENT_HANDL) 16 static
-../src/StateHandler.cpp:15:1:StateHandler::~StateHandler() 16 static
-../src/StateHandler.cpp:15:1:virtual StateHandler::~StateHandler() 16 static
-../src/StateHandler.cpp:19:5:int StateHandler::getSetPresuure() 16 static
-../src/StateHandler.cpp:24:5:int StateHandler::getSetSpeed() 16 static
+/home/tylen/Desktop/Programming/Projects_Metropolia/ESP-Ventilation/StateHandler/inc/Event.h:13:11:Event::~Event() 16 static
+/home/tylen/Desktop/Programming/Projects_Metropolia/ESP-Ventilation/StateHandler/inc/Event.h:13:11:virtual Event::~Event() 16 static
+/home/tylen/Desktop/Programming/Projects_Metropolia/ESP-Ventilation/StateHandler/inc/Event.h:26:3:Event::Event(Event::eventType, int, int) 24 static
+../src/StateHandler.cpp:10:1:StateHandler::StateHandler() 16 static
+../src/StateHandler.cpp:14:1:StateHandler::~StateHandler() 16 static
+../src/StateHandler.cpp:14:1:virtual StateHandler::~StateHandler() 16 static
+../src/StateHandler.cpp:18:14:unsigned int StateHandler::getSetPressure() 16 static
+../src/StateHandler.cpp:22:14:unsigned int StateHandler::getSetSpeed() 16 static
+../src/StateHandler.cpp:26:6:void StateHandler::HandleState(const Event&) 16 static
+../src/StateHandler.cpp:30:6:void StateHandler::SetState(state_pointer) 64 static
diff --git a/StateHandler/inc/Counter.h b/StateHandler/inc/Counter.h
index 1c6e89f..b402f32 100644
--- a/StateHandler/inc/Counter.h
+++ b/StateHandler/inc/Counter.h
@@ -14,7 +14,7 @@ public:
Counter(int i, int up);
void inc();
void dec();
- int getInit();
+ int getCurrent();
void setInit(int i);
~Counter() = default;
diff --git a/StateHandler/inc/StateHandler.h b/StateHandler/inc/StateHandler.h
index ac0b385..d22a914 100644
--- a/StateHandler/inc/StateHandler.h
+++ b/StateHandler/inc/StateHandler.h
@@ -15,43 +15,115 @@
#ifndef STATE_HANDLER_H_
#define STATE_HANDLER_H_
-#include "DigitalIoPin.h"
#include "Counter.h"
+#include "DigitalIoPin.h"
#include "Event.h"
+#include "LiquidCrystal.h"
/** Buttons enumeration
- *
- * Current switch state is being passed
- * from main to StateHandler through
+ *
+ * Current switch state is being passed
+ * from main to StateHandler through
* a keyEvent. Enumeration determines the state
- * of the particular button.
+ * of the particular button.
* */
-enum _buttons {
- /** Raises the bar up */
- BUTTON_CONTROL_UP,
- /** Raises the bar down */
- BUTTON_CONTROL_DOWN,
- /** Toggles the mode between auto and
- * manual, which changes the state */
- BUTTON_CONTROL_TOG_MODE,
- /** Optional button to toggle the
- * activation of the current setting.
- * Not compulsory to be used. */
- BUTTON_CONTROL_TOG_ACTIVE
+enum _buttons
+{
+ /** Raises the bar up */
+ BUTTON_CONTROL_UP,
+ /** Raises the bar down */
+ BUTTON_CONTROL_DOWN,
+ /** Toggles the mode between auto and
+ * manual, which changes the state */
+ BUTTON_CONTROL_TOG_MODE,
+ /** Optional button to toggle the
+ * activation of the current setting.
+ * Not compulsory to be used. */
+ BUTTON_CONTROL_TOG_ACTIVE
};
-class StateHandler {
-public:
- StateHandler();
- virtual ~StateHandler();
- int getSetPresuure(); // Get currently set pressure 0-100%
- int getSetSpeed(); //Get currently set FanSpeed 0-100%
-private:
- bool mode;
- Counter * bar_pressure;
- Counter * bar_speed;
+enum _bars
+{
+ /** 0-100 % */
+ FAN_SPEED,
+ /** 0-120 Pa */
+ PRESSURE
+};
+enum _mode
+{
+ MANUAL,
+ AUTO
+};
+
+class StateHandler;
+typedef void (StateHandler::*state_pointer) (const Event &);
+
+class StateHandler
+{
+public:
+ StateHandler (LiquidCrystal *lcd);
+ virtual ~StateHandler ();
+
+ /** Get currently set pressure
+ *
+ * @return pressure in range of 0-120
+ */
+ unsigned int getSetPressure ();
+
+ /** Get currently set FanSpeed
+ *
+ * @return speed in range of 0-100
+ */
+ unsigned int getSetSpeed ();
+
+ /** Display values on LCD depending on current mode
+ *
+ * @param value1 value to be displayed on LCD line 0
+ * @param value2 value to be displayed on LCD line 1
+ */
+ void displaySet (unsigned int value1, unsigned int value2);
+
+ /** Handle the given event of the current state
+ * @param event event to be handled in the current state
+ */
+ void HandleState (const Event &event);
+
+private:
+ state_pointer current;
+ /** Set a new curremt state
+ * @param newstate new state to be set to current
+ */
+ void SetState (state_pointer newstate);
+ bool current_mode;
+ Counter value[2] = { { 0, 100 }, { 0, 120 } };
+ LiquidCrystal *_lcd;
+
+ /** Initialization state
+ *
+ * @param event event of the state
+ */
+ void stateInit (const Event &event);
+
+ /** Manual state
+ *
+ * - set current speed
+ * - print current pressure
+ *
+ * @param event event of the state
+ */
+ void stateManual (const Event &event);
+
+ /** Automated state
+ *
+ * - print current pressure
+ * - print set pressure
+ * - inc/dec fan speed
+ *
+ * @param event
+ */
+ void stateAuto (const Event &event);
};
#endif /* STATE_HANDLER_H_ */
diff --git a/StateHandler/src/Counter.cpp b/StateHandler/src/Counter.cpp
index 3b44778..0b53145 100644
--- a/StateHandler/src/Counter.cpp
+++ b/StateHandler/src/Counter.cpp
@@ -24,7 +24,7 @@ void Counter::dec() {
}
-int Counter::getInit(){
+int Counter::getCurrent(){
return this->init;
}
diff --git a/StateHandler/src/StateHandler.cpp b/StateHandler/src/StateHandler.cpp
index 13286c7..a4518c7 100644
--- a/StateHandler/src/StateHandler.cpp
+++ b/StateHandler/src/StateHandler.cpp
@@ -7,21 +7,105 @@
#include
-StateHandler::StateHandler(EVENT_HANDL btns) {
- // TODO Auto-generated constructor stub
-
+StateHandler::StateHandler (LiquidCrystal *lcd)
+{
+ this->_lcd = lcd;
+ // TODO
}
-StateHandler::~StateHandler() {
- // TODO Auto-generated destructor stub
+StateHandler::~StateHandler ()
+{
+ // TODO Auto-generated destructor stub
}
-int StateHandler::getSetPresuure(){
- //TODO
- return 0;
+void
+StateHandler::displaySet (unsigned int value1, unsigned int value2)
+{
+ // TODO
+ /**
+ * MANUAL MODE:
+ * ----------------
+ * SPEED: 20%
+ * PRESSURE: XXPa
+ * ----------------
+ * AUTO MODE:
+ * ----------------
+ * PRESSURE SET: 35Pa
+ * PRESSURE CUR: XXPa
+ * ----------------
+ */
}
-int StateHandler::getSetSpeed(){
- // TODO
- return 0;
+unsigned int
+StateHandler::getSetPressure ()
+{
+ return (unsigned int)this->value[PRESSURE].getCurrent ();
}
+
+unsigned int
+StateHandler::getSetSpeed ()
+{
+ return (unsigned int)this->value[FAN_SPEED].getCurrent ();
+}
+
+void
+StateHandler::HandleState (const Event &event)
+{
+ (this->*current) (event);
+}
+
+void
+StateHandler::SetState (state_pointer newstate)
+{
+ (this->*current) (Event (Event::eExit));
+ current = newstate;
+ (this->*current) (Event (Event::eEnter));
+}
+
+void
+stateInit (const Event &event)
+{
+ switch (event.type)
+ {
+ case Event::eEnter:
+ break;
+ case Event::eExit:
+ break;
+ case Event::eKey:
+ break;
+ case Event::eTick:
+ break;
+ }
+}
+
+void
+stateManual (const Event &event)
+{
+ switch (event.type)
+ {
+ case Event::eEnter:
+ break;
+ case Event::eExit:
+ break;
+ case Event::eKey:
+ break;
+ case Event::eTick:
+ break;
+ }
+}
+
+void
+stateAuto (const Event &event)
+{
+ switch (event.type)
+ {
+ case Event::eEnter:
+ break;
+ case Event::eExit:
+ break;
+ case Event::eKey:
+ break;
+ case Event::eTick:
+ break;
+ }
+}
\ No newline at end of file