AbleButtons V0.2.0
Lightweight button library for Arduino.
 
Loading...
Searching...
No Matches
CheckList.cpp
Go to the documentation of this file.
1/**
2 * @file CheckList.cpp Check the ButtonList::all*() and ButtonList::any().
3 *
4 * @copyright Copyright (c) 2022 John Scott
5 */
6#include "Checks.h"
7#include "Utils.h"
8
9/**
10 * Check initial setup of the button list.
11 */
13 // Given the button list, when first setup, then...
14 assert(btnList.allPressed() == false); // ...not all pressed.
15 assert(btnList.allHeld() == false); // ...not all held.
16 assert(btnList.allIdle() == false); // ...not all idle.
17#if TESTABLE_CLASS >= TESTABLE_CLICKER
18 assert(btnList.allClicked() == false); // ...not all clicked
19#endif
20#if TESTABLE_CLASS >= TESTABLE_DOUBLECLICKER
21 assert(btnList.allDoubleClicked() == false); // ...not all double-clicked.
22#endif
23
24 assert(btnList.anyPressed() == false);
25 assert(btnList.anyHeld() == false);
26 assert(btnList.anyIdle() == false);
27#if TESTABLE_CLASS >= TESTABLE_CLICKER
28 assert(btnList.anyClicked() == false);
29#endif
30#if TESTABLE_CLASS >= TESTABLE_DOUBLECLICKER
32#endif
33}
34
35/**
36 * Check ButtonList when button just pressed.
37 *
38 * @param btn The button just pressed.
39 */
41 // Given the button just pressed, then...
42 if(btn == &btnA) {
43 assert(btnList.allPressed() == btnB.isPressed()); // ...all pressed if other pressed.
44 } else {
45 assert(btnList.allPressed() == btnA.isPressed()); // ...all pressed if other pressed.
46 }
47
48 assert(btnList.allHeld() == false); // ...cannot all be held.
49 assert(btnList.allIdle() == false); // ...cannot all be idle.
50
51 assert(btnList.anyPressed() == true); // ...any pressed is true.
52
53 if(btn == &btnA) {
56 } else {
59 }
60}
61
62/**
63 * Check ButtonList when button just released.
64 *
65 * @param btn The button just released.
66 */
68 // Given the button just released, then...
69 assert(btnList.allPressed() == false);
70 assert(btnList.allHeld() == false); // ...cannot all be held.
71 assert(btnList.allIdle() == false); // ...cannot all be idle.
72
73 if(btn == &btnA) {
77 } else {
81 }
82}
83
84/**
85 * Check ButtonList when button just held.
86 *
87 * @param btn The button just held.
88 */
90
91}
92
93/**
94 * Check ButtonList when button just idle.
95 *
96 * @param btn The button just idle.
97 */
99
100}
101
102/**
103 * Check ButtonList when button just clicked. *
104 *
105 * @param btn The button just clicked.
106 */
108
109}
110
111/**
112 * Check ButtonList when button just double-clicked.
113 *
114 * @param btn The button just double-clicked.
115 */
117
118}
119
120/**
121 * Check integrity of ButtonList invariants (always hold true).
122 */
124 // ButtonList::all*() accessors...
126 assert(btnList.allHeld() == (btnA.isHeld() && btnB.isHeld()));
127 assert(btnList.allIdle() == (btnA.isIdle() && btnB.isIdle()));
128# if TESTABLE_CLASS >= TESTABLE_CLICKER
130# endif
131# if TESTABLE_CLASS >= TESTABLE_DOUBLECLICKER
133# endif
134
135 // ButtonList::any*() accessors...
137 assert(btnList.anyHeld() == (btnA.isHeld() || btnB.isHeld()));
138 assert(btnList.anyIdle() == (btnA.isIdle() || btnB.isIdle()));
139# if TESTABLE_CLASS >= TESTABLE_CLICKER
141# endif
142# if TESTABLE_CLASS >= TESTABLE_DOUBLECLICKER
144# endif
145}
Button btn(BUTTON_PIN)
The button to check.
ButtonList btnList(btns)
List of button to control together.
Button btnA(BUTTON_A_PIN)
Primary button.
Button btnB(BUTTON_B_PIN)
Secondary button.
void checkButtonListJustDoubleClicked(Button *btn)
Check ButtonList when button just double-clicked.
Definition: CheckList.cpp:116
void checkButtonListIntegrity()
Check integrity of ButtonList invariants (always hold true).
Definition: CheckList.cpp:123
void checkButtonListJustClicked(Button *btn)
Check ButtonList when button just clicked.
Definition: CheckList.cpp:107
void checkButtonListSetup()
Check initial setup of the button list.
Definition: CheckList.cpp:12
void checkButtonListJustIdle(Button *btn)
Check ButtonList when button just idle.
Definition: CheckList.cpp:98
void checkButtonListJustHeld(Button *btn)
Check ButtonList when button just held.
Definition: CheckList.cpp:89
void checkButtonListJustReleased(Button *btn)
Check ButtonList when button just released.
Definition: CheckList.cpp:67
void checkButtonListJustPressed(Button *btn)
Check ButtonList when button just pressed.
Definition: CheckList.cpp:40
Declarations for the Checks module.
Utility function declarations.
#define assert(e)
Macro to assert using FlashStringHelper to reduce memory usage.
Definition: Utils.h:30
Core Button class.
Definition: Button.h:22
bool isClicked() const
Determine if the button is clicked.
Definition: Button.h:132
bool isHeld() const
Determine if the button is currently held down.
Definition: Button.h:112
bool isIdle() const
Determine if the button is currently idle (unpressed for a "long" time).
Definition: Button.h:121
bool isDoubleClicked() const
Determine if the button is double-clicked.
Definition: Button.h:144
bool isPressed() const
Determine if the button is currently pressed.
Definition: Button.h:103
bool allDoubleClicked() const
Determine if all of the buttons have been double-clicked.
Definition: ButtonList.h:258
bool allPressed() const
Determine if all of the buttons are currently pressed.
Definition: ButtonList.h:138
bool anyHeld() const
Determine if any of the buttons are currently held.
Definition: ButtonList.h:183
bool allHeld() const
Determine if all of the buttons are currently held.
Definition: ButtonList.h:168
bool anyDoubleClicked() const
Determine if any of the buttons have been double-clicked.
Definition: ButtonList.h:273
bool anyClicked() const
Determine if all of the buttons have been clicked.
Definition: ButtonList.h:243
bool anyPressed() const
Determine if any of the buttons are currently pressed.
Definition: ButtonList.h:153
bool anyIdle() const
Determine if any of the buttons are currently idle.
Definition: ButtonList.h:213
bool allIdle() const
Determine if all of the buttons are currently idle.
Definition: ButtonList.h:198
bool allClicked() const
Determine if all of the buttons have been clicked.
Definition: ButtonList.h:228