diff --git a/SwitchController/.cproject b/SwitchController/.cproject
index ecc1363..7a489da 100644
--- a/SwitchController/.cproject
+++ b/SwitchController/.cproject
@@ -50,6 +50,7 @@
+
@@ -75,6 +76,7 @@
+
@@ -93,6 +95,7 @@
+
@@ -157,6 +160,7 @@
+
@@ -183,6 +187,7 @@
+
@@ -201,6 +206,7 @@
+
diff --git a/SwitchController/.gitignore b/SwitchController/.gitignore
new file mode 100644
index 0000000..3df573f
--- /dev/null
+++ b/SwitchController/.gitignore
@@ -0,0 +1 @@
+/Debug/
diff --git a/SwitchController/.project b/SwitchController/.project
index 17e1cd4..18427c4 100644
--- a/SwitchController/.project
+++ b/SwitchController/.project
@@ -7,6 +7,7 @@
DigitalIoPin
Timer
StateHandler
+ LiquidCrystal
diff --git a/SwitchController/src/SwitchController.cpp b/SwitchController/src/SwitchController.cpp
index 3beb520..53fac52 100644
--- a/SwitchController/src/SwitchController.cpp
+++ b/SwitchController/src/SwitchController.cpp
@@ -15,7 +15,6 @@ SwitchController::SwitchController (DigitalIoPin *button, Timer *timer,
h = handler;
b_state = false;
b_mode = button_mode;
- t->resetCounter ();
}
SwitchController::~SwitchController ()
diff --git a/esp-vent-main/.cproject b/esp-vent-main/.cproject
index 521b9f6..534fcb6 100644
--- a/esp-vent-main/.cproject
+++ b/esp-vent-main/.cproject
@@ -46,6 +46,7 @@
+
@@ -75,6 +76,7 @@
+
@@ -94,6 +96,7 @@
+
@@ -126,6 +129,7 @@
+
@@ -200,6 +205,7 @@
+
@@ -229,6 +235,7 @@
+
@@ -248,6 +255,7 @@
+
@@ -280,6 +288,7 @@
+
diff --git a/esp-vent-main/.project b/esp-vent-main/.project
index e653829..02d3d3f 100644
--- a/esp-vent-main/.project
+++ b/esp-vent-main/.project
@@ -10,6 +10,7 @@
I2C
StateHandler
Timer
+ SwitchController
diff --git a/esp-vent-main/src/esp-vent-main.cpp b/esp-vent-main/src/esp-vent-main.cpp
index 31c9f59..1ec0f05 100644
--- a/esp-vent-main/src/esp-vent-main.cpp
+++ b/esp-vent-main/src/esp-vent-main.cpp
@@ -19,6 +19,7 @@
#include "DigitalIoPin.h"
#include "LiquidCrystal.h"
#include "StateHandler.h"
+#include "SwitchController.h"
#include "Timer.h"
#include
@@ -44,6 +45,7 @@ main (void)
#endif
/** Lcd & stateHandler */
Chip_RIT_Init (LPC_RITIMER);
+ Timer glob_time;
DigitalIoPin rs (0, 29, false, true, false);
DigitalIoPin en (0, 9, false, true, false);
DigitalIoPin d4 (0, 10, false, true, false);
@@ -58,53 +60,30 @@ main (void)
/** Common pins */
DigitalIoPin b_up (0, 7, true, true, true); // A5
- bool b_up_state = false;
+ SwitchController sw_up (&b_up, &glob_time, &ventMachine, BUTTON_CONTROL_UP);
+
DigitalIoPin b_down (0, 6, true, true, true); // A4
- bool b_down_state = false;
+ SwitchController sw_down (&b_down, &glob_time, &ventMachine,
+ BUTTON_CONTROL_DOWN);
+
DigitalIoPin b_toggle (0, 5, true, true, true); // A3
- bool b_toggle_state = false;
+ SwitchController sw_toggle (&b_toggle, &glob_time, &ventMachine,
+ BUTTON_CONTROL_TOG_MODE);
int16_t pressure = 1;
- Timer glob_time;
-
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;
- }
+ sw_up.listen ();
+ sw_down.listen ();
+ sw_toggle.listen ();
/**
* TODO:
* - Update current pressure to eTick
*/
ventMachine.HandleState (Event (Event::eTick, pressure));
- glob_time.tickCounter(1);
+ glob_time.tickCounter (1);
}
return 0;