switch-controller: add basic functionality to main

This commit is contained in:
Vasily Davydov
2022-10-17 09:27:44 +03:00
parent 0bf20552cf
commit 6155ac7089
7 changed files with 32 additions and 35 deletions

View File

@@ -19,6 +19,7 @@
#include "DigitalIoPin.h"
#include "LiquidCrystal.h"
#include "StateHandler.h"
#include "SwitchController.h"
#include "Timer.h"
#include <cr_section_macros.h>
@@ -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;