-
Notifications
You must be signed in to change notification settings - Fork 1
/
button.hpp
63 lines (53 loc) · 1.29 KB
/
button.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <array>
#include <klib/units.hpp>
namespace input {
// pressed button marker
constexpr static klib::time::us pressed_marker = 0xffffffff;
/**
* @brief Button states
*
*/
enum state: uint8_t {
released = 0,
pressed = 1,
no_change = 2,
long_pressed = 3,
};
/**
* @brief Button information for the screens
*
*/
struct buttons {
// amount of buttons we have
constexpr static uint32_t amount = 3;
// state of the up button
state up;
// state of the enter button
state enter;
// state of the down button
state down;
};
/**
* @brief Get the button state using the raw input + old timing information
*
* @param delta
* @param flipped
* @param timing
* @param button0
* @param button1
* @param button2
* @return menu::buttons
*/
buttons get_state(
const klib::time::us delta, const bool flipped, std::array<klib::time::us, 3>& timing,
const std::array<bool, buttons::amount>& raw
);
/**
* @brief Returns if a button is long or short pressed
*
* @return true
* @return false
*/
bool is_pressed(const state button);
}