ESP-Ventilation/esp-vent-main/src/SwitchController.cpp
2022-10-24 15:24:34 +03:00

41 lines
732 B
C++

/*
* SwitchController.cpp
*
* Created on: Oct 17, 2022
* Author: tylen
*/
#include "SwitchController.h"
SwitchController::SwitchController (DigitalIoPin *button,
StateHandler *handler, int button_mode)
{
b = button;
h = handler;
b_pressed = false;
b_mode = button_mode;
}
SwitchController::~SwitchController ()
{
// TODO Auto-generated destructor stub
}
void
SwitchController::listen ()
{
/** Button is pressed for the first time*/
if (b->read () && !b_pressed)
{
b_pressed = true;
}
/** Button is released before 2 seconds*/
if (!b->read () && b_pressed)
{
h->HandleState (Event (Event::eKey, b_mode));
b_pressed = false;
}
}