OSCR
Open Source Cartridge Reader
Loading...
Searching...
No Matches
button.h
1/********************************************************************
2 * Open Source Cartridge Reader *
3 ********************************************************************/
4#pragma once
5#if !defined(OSCR_BUTTON_H_)
6# define OSCR_BUTTON_H_
7
8# include "common/Types.h"
9# include "common/OSCR.h"
10# include "common/PinControl.h"
11
12namespace OSCR::UI
13{
14 // ms required for a long press
15 constexpr uint32_t const kLongHold = 5000;
16 // ms required for a short press
17 constexpr uint32_t const kShortHold = 2000;
18 // max ms between clicks for a double click event
19 constexpr uint32_t const kDoubleClick = 250;
20 // ms debounce period to prevent flickering when pressing or releasing the button
21 constexpr uint32_t const kDebounceDelay = 20;
22
23 class Button
24 {
25 protected:
26 bool current = false;
27 bool clicked = false;
28
29 InterfaceInput lastEvent = InterfaceInput::kInterfaceInputIgnore;
30
31 uint32_t buttonTime = 0;
32 uint32_t clickedTime = 0;
33 uint32_t lastButtonEventTime = 0;
34
35 volatile uint8_t const & pinBank;
36 uint8_t const pinNumber;
37
38 public:
39 Button(OSCR::Hardware::PinBank buttonPinBank, uint8_t buttonPinNumber);
40 Button(volatile uint8_t& buttonPinBank, uint8_t buttonPinNumber);
41
42 bool read();
43
44 InterfaceInput check();
45
46 uint32_t lastEventTime();
47 uint32_t time();
48
49 bool state();
50 };
51}
52
53#endif /* !OSCR_BUTTON_H_ */
User interface methods.
Definition Types.h:118
InterfaceInput
Definition Types.h:137