Skip to content

Commit e847b5d

Browse files
author
Philippe Ardit
committed
Add EASYBUTTON_DO_NOT_USE_SEQUENCES option to avoid no need RAM usage when "onSequence" is not used
1 parent f81a2b8 commit e847b5d

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

src/EasyButton.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ bool EasyButton::read()
6161
_pressed_callback();
6262
}
6363

64+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
6465
for (size_t i = 0; i < MAX_SEQUENCES; i++)
6566
{
6667
if (_sequences[i].newPress(read_started_ms))
@@ -69,6 +70,7 @@ bool EasyButton::read()
6970
function();
7071
}
7172
}
73+
#endif
7274
}
7375
// Button was not held.
7476
else

src/EasyButtonBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ void EasyButtonBase::onPressedFor(uint32_t duration, EasyButtonBase::callback_t
1818
_pressed_for_callback = callback;
1919
}
2020

21+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
2122
void EasyButtonBase::onSequence(uint8_t sequences, uint32_t duration, EasyButtonBase::callback_t callback)
2223
{
2324
if (_sequences_count < 5)
@@ -28,6 +29,7 @@ void EasyButtonBase::onSequence(uint8_t sequences, uint32_t duration, EasyButton
2829
_pressed_sequence_callbacks[_sequences_count++] = callback;
2930
}
3031
}
32+
#endif
3133

3234
bool EasyButtonBase::isPressed()
3335
{
@@ -67,11 +69,13 @@ void EasyButtonBase::_checkPressedTime()
6769
// Button has been pressed for at least the given time.
6870
_was_btn_held = true;
6971

72+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
7073
// Reset short presses counters.
7174
for (Sequence seq : _sequences)
7275
{
7376
seq.reset();
7477
}
78+
#endif
7579

7680
// Call the callback function for a long press event if it exist and if it has not been called yet.
7781
if (_pressed_for_callback && !_held_callback_called)

src/EasyButtonBase.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#include "FunctionalInterrupt.h"
2121
#endif
2222

23+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
2324
#define MAX_SEQUENCES 5
25+
#endif
2426

2527
class EasyButtonBase
2628
{
@@ -38,7 +40,9 @@ class EasyButtonBase
3840
virtual bool read() = 0; // Returns the current debounced button state, true for pressed, false for released.
3941
void onPressed(callback_t callback); // Call a callback function when the button has been pressed and released.
4042
void onPressedFor(uint32_t duration, callback_t callback); // Call a callback function when the button has been held for at least the given number of milliseconds.
43+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
4144
void onSequence(uint8_t sequences, uint32_t duration, callback_t callback); // Call a callback function when the given sequence has matched.
45+
#endif
4246

4347
bool isPressed(); // Returns true if the button state was pressed at the last read.
4448
bool isReleased(); // Returns true if the button state was released at the last read.
@@ -49,11 +53,15 @@ class EasyButtonBase
4953

5054
protected:
5155
// Common variables.
56+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
5257
Sequence _sequences[MAX_SEQUENCES];
5358
uint16_t _sequences_count;
59+
#endif
5460
uint32_t _held_threshold; // Held threshold.
5561

62+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
5663
callback_t _pressed_sequence_callbacks[MAX_SEQUENCES];
64+
#endif
5765
callback_t _pressed_callback; // Callback function for pressed events.
5866
callback_t _pressed_for_callback; // Callback function for pressedFor events.
5967
bool _held_callback_called; // Indicate if button long press has been notified.

src/EasyButtonVirtual.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ bool EasyButtonVirtual::read()
5353
_pressed_callback();
5454
}
5555

56+
#ifndef EASYBUTTON_DO_NOT_USE_SEQUENCES
5657
for (size_t i = 0; i < MAX_SEQUENCES; i++)
5758
{
5859
if (_sequences[i].newPress(read_started_ms))
@@ -61,6 +62,7 @@ bool EasyButtonVirtual::read()
6162
function();
6263
}
6364
}
65+
#endif
6466
}
6567
// Button was not held.
6668
else

0 commit comments

Comments
 (0)