AbleButtons V0.4.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
Checks.h
Go to the documentation of this file.
1/**
2 * @file Checks.h Declarations for the Checks module.
3 *
4 * @copyright Copyright (c) 2022 John Scott
5 */
6#pragma once
7#include "Config.h"
8
9/**
10 * Structure for remembering the state of each button. Used to compare to the
11 * current state to track different checks.
12 */
13struct ButtonState {
14 bool isPressed; ///< Button is pressed.
15 bool isHeld; ///< Button is held.
16 bool isIdle; ///< Button is idle.
17# if TESTABLE_CLASS >= TESTABLE_CLICKER
18 bool isClicked; ///< Button clicked (pressed+released).
19# endif
20# if TESTABLE_CLASS >= TESTABLE_DOUBLECLICKER
21 bool isSingleClicked; ///< Button single-clicked.
22 bool isDoubleClicked; ///< Button double-clicked.
23# endif
24# if TESTABLE_CALLBACK
25 bool wasStarted; ///< Button received begin callback.
26 bool wasPressed; ///< Button received pressed callback.
27 bool wasReleased; ///< Button received released callback.
28 bool wasHeld; ///< Button received held callback.
29 bool wasIdle; ///< Button received idle callback.
30# if TESTABLE_CLASS >= TESTABLE_CLICKER
31 bool wasClicked; ///< Button received clicked callback.
32# endif
33# if TESTABLE_CLASS >= TESTABLE_DOUBLECLICKER
34 bool wasSingleClicked; ///< Button received single-clicked callback.
35 bool resetSingleClicked;
36 bool wasDoubleClicked; ///< Button received double-clicked callback.
37 bool resetDoubleClicked;
38# endif
39# endif
40};
41
42extern struct ButtonState btnState[NUM_BUTTONS];
43
44//
45// Definitions of Button checks...
46//
55void checkButtonIntegrity(Button *btn, ButtonState &state);
56
57//
58// Display any changes to button status...
59//
60void displayButtonChanges(int index);
61
62//
63// Definitions of ButtonList checks...
64//
Button btn(BUTTON_PIN)
The button to check.
void checkButtonJustSingleClicked(Button *btn)
Check button that has just been single-clicked.
Definition: Checks.cpp:167
void checkButtonJustClicked(Button *btn)
Check button that has just been clicked.
Definition: Checks.cpp:142
void checkButtonListIntegrity()
Check integrity of ButtonList invariants (always hold true).
Definition: Checks.cpp:286
void checkButtonJustReleased(Button *btn)
Check button that has just been released.
Definition: Checks.cpp:67
void checkButtonJustHeld(Button *btn)
Check button that has just been held.
Definition: Checks.cpp:92
void checkButtonIntegrity(Button *btn, ButtonState &state)
Check integrity of Button invariants (always hold true).
Definition: Checks.cpp:202
void checkButtonJustIdle(Button *btn)
Check button that has just become or remains idle.
Definition: Checks.cpp:117
void checkButtonSetup(Button *btn)
Check the state of an individual button just setup.
Definition: Checks.cpp:17
void displayButtonChanges(int index)
Display button changes to Serial.
Definition: Checks.cpp:347
struct ButtonState btnState[NUM_BUTTONS]
Previous state for each button.
Definition: Checks.cpp:9
void checkButtonJustDoubleClicked(Button *btn)
Check button that has just been double-clicked.
Definition: Checks.cpp:177
void checkButtonJustPressed(Button *btn)
Check state of a pressed button just pressed.
Definition: Checks.cpp:42
Declarations to select which buttons we use.
#define NUM_BUTTONS
The number of buttons to connect for testing.
Definition: Config.h:13
Core Button class.
Definition: Button.h:22