InfiniTime.git

ref: fdc89f1a20889c0295534f58dc2e82ce8c55a18b

src/buttonhandler/ButtonHandler.h


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once

#include "buttonhandler/ButtonActions.h"
#include "systemtask/SystemTask.h"
#include <FreeRTOS.h>
#include <timers.h>

namespace Pinetime {
  namespace Controllers {
    class ButtonHandler {
    public:
      enum class Events : uint8_t { Press, Release, Timer };
      void Init(Pinetime::System::SystemTask* systemTask);
      ButtonActions HandleEvent(Events event);

    private:
      enum class States : uint8_t { Idle, Pressed, Holding, LongHeld };
      TickType_t releaseTime = 0;
      TimerHandle_t buttonTimer;
      bool buttonPressed = false;
      States state = States::Idle;
    };
  }
}