diff --git a/SwitchController/.cproject b/SwitchController/.cproject
new file mode 100644
index 0000000..7a489da
--- /dev/null
+++ b/SwitchController/.cproject
@@ -0,0 +1,268 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <?xml version="1.0" encoding="UTF-8"?>
+<TargetConfig>
+<Properties property_2="LPC15xx_256K.cfx" property_3="NXP" property_4="LPC1549" property_count="5" version="100300"/>
+<infoList vendor="NXP">
+<info chip="LPC1549" connectscript="LPC15RunBootRomConnect.scp" flash_driver="LPC15xx_256K.cfx" match_id="0x0" name="LPC1549" resetscript="LPC15RunBootRomReset.scp" stub="crt_emu_cm3_gen">
+<chip>
+<name>LPC1549</name>
+<family>LPC15xx</family>
+<vendor>NXP (formerly Philips)</vendor>
+<reset board="None" core="Real" sys="Real"/>
+<clock changeable="TRUE" freq="12MHz" is_accurate="TRUE"/>
+<memory can_program="true" id="Flash" is_ro="true" type="Flash"/>
+<memory id="RAM" type="RAM"/>
+<memory id="Periph" is_volatile="true" type="Peripheral"/>
+<memoryInstance derived_from="Flash" id="MFlash256" location="0x0" size="0x40000"/>
+<memoryInstance derived_from="RAM" id="Ram0_16" location="0x2000000" size="0x4000"/>
+<memoryInstance derived_from="RAM" id="Ram1_16" location="0x2004000" size="0x4000"/>
+<memoryInstance derived_from="RAM" id="Ram2_4" location="0x2008000" size="0x1000"/>
+</chip>
+<processor>
+<name gcc_name="cortex-m3">Cortex-M3</name>
+<family>Cortex-M</family>
+</processor>
+</info>
+</infoList>
+</TargetConfig>
+
+
+
+ LPCXpresso1549
+
+
+
\ No newline at end of file
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
new file mode 100644
index 0000000..18427c4
--- /dev/null
+++ b/SwitchController/.project
@@ -0,0 +1,32 @@
+
+
+ SwitchController
+
+
+ lpc_chip_15xx
+ DigitalIoPin
+ Timer
+ StateHandler
+ LiquidCrystal
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.core.ccnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
diff --git a/SwitchController/inc/SwitchController.h b/SwitchController/inc/SwitchController.h
new file mode 100644
index 0000000..cdede07
--- /dev/null
+++ b/SwitchController/inc/SwitchController.h
@@ -0,0 +1,33 @@
+/*
+ * SwitchController.h
+ *
+ * Created on: Oct 17, 2022
+ * Author: tylen
+ */
+
+#ifndef SWITCHCONTROLLER_H_
+#define SWITCHCONTROLLER_H_
+
+#include "DigitalIoPin.h"
+#include "StateHandler.h"
+#include "Timer.h"
+
+class SwitchController
+{
+public:
+ SwitchController (DigitalIoPin *button, Timer *timer, StateHandler *handler,
+ int button_mode);
+ virtual ~SwitchController ();
+ /** Listen to switch button
+ */
+ void listen ();
+
+private:
+ DigitalIoPin *b;
+ Timer *t;
+ StateHandler *h;
+ bool b_state;
+ int b_mode;
+};
+
+#endif /* SWITCHCONTROLLER_H_ */
diff --git a/SwitchController/liblinks.xml b/SwitchController/liblinks.xml
new file mode 100644
index 0000000..1dc1803
--- /dev/null
+++ b/SwitchController/liblinks.xml
@@ -0,0 +1,32 @@
+
+
+
+
+ ${MacroStart}workspace_loc:/${ProjName}/inc${MacroEnd}
+
+
+ ${MacroStart}workspace_loc:/${ProjName}/inc${MacroEnd}
+
+
+ ${ProjName}
+
+
+ ${MacroStart}workspace_loc:/${ProjName}/Debug${MacroEnd}
+
+
+ ${MacroStart}workspace_loc:/${ProjName}/Release${MacroEnd}
+
+
+ ${ProjName}
+
+
+
diff --git a/SwitchController/src/SwitchController.cpp b/SwitchController/src/SwitchController.cpp
new file mode 100644
index 0000000..53fac52
--- /dev/null
+++ b/SwitchController/src/SwitchController.cpp
@@ -0,0 +1,37 @@
+/*
+ * SwitchController.cpp
+ *
+ * Created on: Oct 17, 2022
+ * Author: tylen
+ */
+
+#include
+
+SwitchController::SwitchController (DigitalIoPin *button, Timer *timer,
+ StateHandler *handler, int button_mode)
+{
+ b = button;
+ t = timer;
+ h = handler;
+ b_state = false;
+ b_mode = button_mode;
+}
+
+SwitchController::~SwitchController ()
+{
+ // TODO Auto-generated destructor stub
+}
+
+void
+SwitchController::listen ()
+{
+ if (b->read ())
+ {
+ b_state = true;
+ }
+ if (!b->read () && b_state)
+ {
+ h->HandleState (Event (Event::eKey, b_mode));
+ b_state = false;
+ }
+}
\ No newline at end of file
diff --git a/esp-vent-main/.cproject b/esp-vent-main/.cproject
index 208bd18..dc71f86 100644
--- a/esp-vent-main/.cproject
+++ b/esp-vent-main/.cproject
@@ -46,7 +46,7 @@
-
+
@@ -76,7 +76,7 @@
-
+
@@ -96,7 +96,8 @@
-
+
+
@@ -129,7 +130,7 @@
-
+
@@ -205,7 +206,7 @@
-
+
@@ -235,7 +236,7 @@
-
+
@@ -255,7 +256,7 @@
-
+
@@ -288,7 +289,7 @@
-
+
diff --git a/esp-vent-main/.project b/esp-vent-main/.project
index 3788bea..02d3d3f 100644
--- a/esp-vent-main/.project
+++ b/esp-vent-main/.project
@@ -10,7 +10,7 @@
I2C
StateHandler
Timer
- PressureWrapper
+ SwitchController
diff --git a/esp-vent-main/src/esp-vent-main.cpp b/esp-vent-main/src/esp-vent-main.cpp
index 0ce01c3..4f6422e 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 "PressureWrapper.h"
#include "I2C.h"
@@ -46,6 +47,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);
@@ -60,11 +62,15 @@ 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);
// NVIC_DisableIRQ(I2C0_IRQn);
@@ -75,45 +81,18 @@ main (void)
PRESSURE_DATA *pressure;
pressure = sens.getPressure();
- 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->rBuffer[1]));
- glob_time.tickCounter(1);
+ ventMachine.HandleState (Event (Event::eTick, pressure));
+ glob_time.tickCounter (1);
}
return 0;