Skip to content

Commit e8eb7f6

Browse files
committed
added blackout functionality
removed Reset
1 parent fa9bc7b commit e8eb7f6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

include/EZButton.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class EZButton
2727

2828
~EZButton();
2929

30-
void Reset();
30+
void Blackout(unsigned long milis);
3131
void CheckButtons();
3232
void Subscribe(int index, void (*event)(), EventTypes type);
3333

@@ -37,6 +37,7 @@ class EZButton
3737
unsigned long *_buttonDownMillis;
3838
unsigned int *_lastHoldInterval;
3939
bool *_buttonLastState;
40+
unsigned long _blackoutTime = 0;
4041

4142
typedef void (*Event)(); // Type alias for function pointer
4243
Event *_events;

src/EZButton.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ EZButton::EZButton(int buttonCount,
1717
for (int i = 0; i < _numButtons * EVENT_COUNT; i++)
1818
_events[i] = nullptr;
1919

20-
Reset();
20+
Blackout(0);
2121
}
2222

2323
EZButton::~EZButton()
@@ -28,18 +28,22 @@ EZButton::~EZButton()
2828
delete[] _events;
2929
}
3030

31-
void EZButton::Reset()
31+
void EZButton::Blackout(unsigned long milis)
3232
{
3333
for (int i = 0; i < _numButtons; i++)
3434
{
3535
_buttonDownMillis[i] = 0;
3636
_buttonLastState[i] = false;
3737
_lastHoldInterval[i] = 0;
3838
}
39+
_blackoutTime = millis() + milis;
3940
}
4041

4142
void EZButton::CheckButtons()
4243
{
44+
if (_blackoutTime > millis())
45+
return;
46+
4347
bool *buttonStates = new bool[_numButtons];
4448
_readButtons(buttonStates, _numButtons);
4549

@@ -103,7 +107,8 @@ void EZButton::CallEvent(int index, EventTypes type)
103107
_events[i]();
104108
}
105109

106-
int EZButton::EventIndex(int index, EventTypes type){
110+
int EZButton::EventIndex(int index, EventTypes type)
111+
{
107112
return index + type * _numButtons;
108113
}
109114

0 commit comments

Comments
 (0)