Arduino Helpers
master
Utility library for Arduino
src
AH
Hardware
IncrementButton.cpp
Go to the documentation of this file.
1
#include "
IncrementButton.hpp
"
2
3
BEGIN_AH_NAMESPACE
4
5
IncrementButton::State
IncrementButton::updateImplementation
() {
6
Button::State
incrState =
button
.
update
();
7
8
if
(incrState ==
Button::Released
) {
9
// Button released, don't do anything
10
// This one is first to minimize overhead
11
// because most of the time, the button will
12
// be released
13
return
Nothing
;
14
}
else
if
(incrState ==
Button::Rising
) {
15
auto
res =
longPressState
==
LongPress
?
ReleasedLong
:
ReleasedShort
;
16
longPressState
=
Initial
;
17
return
res;
18
}
else
if
(incrState ==
Button::Falling
) {
19
return
IncrementShort
;
20
}
else
{
// if (incrState == Button::Pressed)
21
auto
now = millis();
22
if
(
longPressState
==
LongPress
) {
23
// still long pressed
24
if
(now -
longPressRepeat
>=
LONG_PRESS_REPEAT_DELAY
) {
25
longPressRepeat
+=
LONG_PRESS_REPEAT_DELAY
;
26
return
IncrementHold
;
27
}
28
}
else
if
(
button
.
stableTime
(now) >=
LONG_PRESS_DELAY
) {
29
// long press starts
30
longPressState
=
LongPress
;
31
longPressRepeat
= now;
32
return
IncrementLong
;
33
}
34
}
35
return
Nothing
;
36
}
37
38
END_AH_NAMESPACE
IncrementButton.hpp
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition:
NamespaceSettings.hpp:14
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition:
NamespaceSettings.hpp:11
LONG_PRESS_REPEAT_DELAY
constexpr unsigned long LONG_PRESS_REPEAT_DELAY
The time between increments/decremnets during a long press.
Definition:
Settings.hpp:87
LONG_PRESS_DELAY
constexpr unsigned long LONG_PRESS_DELAY
The time in milliseconds before a press is registered as a long press.
Definition:
Settings.hpp:84
Button::stableTime
unsigned long stableTime(unsigned long now) const
Return the time (in milliseconds) that the button has been stable for, compared to the given time poi...
Definition:
Button.cpp:50
Button::update
State update()
Read the button and return its new state.
Definition:
Button.cpp:11
Button::State
State
An enumeration of the different states a button can be in.
Definition:
Button.hpp:45
Button::Rising
@ Rising
Input went from low to high (0,1)
Definition:
Button.hpp:49
Button::Falling
@ Falling
Input went from high to low (1,0)
Definition:
Button.hpp:48
Button::Released
@ Released
Input went from high to high (1,1)
Definition:
Button.hpp:47
IncrementButton::Initial
@ Initial
Definition:
IncrementButton.hpp:69
IncrementButton::LongPress
@ LongPress
Definition:
IncrementButton.hpp:70
IncrementButton::State
State
An enumeration of the different actions to be performed by the counter.
Definition:
IncrementButton.hpp:38
IncrementButton::Nothing
@ Nothing
The counter must not be incremented.
Definition:
IncrementButton.hpp:39
IncrementButton::IncrementShort
@ IncrementShort
The counter must be incremented (after short press).
Definition:
IncrementButton.hpp:40
IncrementButton::IncrementHold
@ IncrementHold
The counter must be incremented (still pressed).
Definition:
IncrementButton.hpp:42
IncrementButton::ReleasedLong
@ ReleasedLong
The button was released after a long press.
Definition:
IncrementButton.hpp:44
IncrementButton::IncrementLong
@ IncrementLong
The counter must be incremented (after long press).
Definition:
IncrementButton.hpp:41
IncrementButton::ReleasedShort
@ ReleasedShort
The button was released after a short press.
Definition:
IncrementButton.hpp:43
IncrementButton::longPressRepeat
unsigned long longPressRepeat
Definition:
IncrementButton.hpp:72
IncrementButton::longPressState
enum IncrementButton::@0 longPressState
IncrementButton::button
Button button
Definition:
IncrementButton.hpp:66
IncrementButton::updateImplementation
State updateImplementation()
Definition:
IncrementButton.cpp:5
Generated by
1.9.4