state-handler: create eKey fucntionality

This commit introduces buttonHandling of esp-vent
within the StateHandler class and main().
This commit is contained in:
Vasily Davydov
2022-10-14 13:53:00 +03:00
parent 736d8aa1b7
commit acb1b73b9a
7 changed files with 97 additions and 31 deletions

View File

@@ -16,6 +16,9 @@
#endif
#endif
#include "DigitalIoPin.h"
#include "StateHandler.h"
#include <cr_section_macros.h>
// 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;