2021-10-25 09:53:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-01-16 19:45:57 +00:00
|
|
|
#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);
|
2021-10-25 13:57:29 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|