InfiniTime/src/buttonhandler/ButtonHandler.h

25 lines
620 B
C
Raw Normal View History

2021-10-25 09:53:14 +00:00
#pragma once
#include "buttonhandler/ButtonActions.h"
2021-10-25 09:53:14 +00:00
#include "systemtask/SystemTask.h"
#include <FreeRTOS.h>
#include <timers.h>
namespace Pinetime {
namespace Controllers {
class ButtonHandler {
public:
2021-10-25 10:40:43 +00:00
enum class Events : uint8_t { Press, Release, Timer };
2021-10-25 09:53:14 +00:00
void Init(Pinetime::System::SystemTask* systemTask);
ButtonActions HandleEvent(Events event);
2021-10-25 09:53:14 +00:00
private:
2021-10-25 10:40:43 +00:00
enum class States : uint8_t { Idle, Pressed, Holding, LongHeld };
2021-10-25 09:53:14 +00:00
TickType_t releaseTime = 0;
TimerHandle_t buttonTimer;
bool buttonPressed = false;
2021-10-25 10:40:43 +00:00
States state = States::Idle;
2021-10-25 09:53:14 +00:00
};
}
}