Skip to content

Commit e986a73

Browse files
committed
Add skipping processing button when there are no callbacks attached and removes delay after first tap if there is no handlers for double and triple tap
1 parent bcc665a commit e986a73

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/QuantumButton.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ void Button::setMaxDelayBetweenTaps(uint16_t _delay_between_taps)
156156

157157
uint8_t Button::process_button()
158158
{
159+
if (!_onTap && !_on2Tap && !_on3Tap && !_onLTap && !_onHold)
160+
return None;
159161
bool pin_state = digitalRead(_pin) == _active_state;
160162
unsigned long current_time = millis();
161163
if (pin_state == LOW && logical_state == BS_HOLDED_WAIT_FOR_RELEASING)
@@ -167,7 +169,7 @@ uint8_t Button::process_button()
167169
logical_state = BS_TAP1_PRESSING_BEGIN;
168170
tap_time = current_time;
169171
}
170-
else if ((pin_state == LOW && current_time - tap_time > delay_between_taps) || current_time - tap_time > delay_between_taps + very_long_tap_time)
172+
else if ((pin_state == LOW && (current_time - tap_time > delay_between_taps || (_on2Tap == NULL && _on3Tap == NULL))) || current_time - tap_time > delay_between_taps + very_long_tap_time)
171173
{
172174
ButtonEvent result = None;
173175
if (logical_state == BS_TAP1_RELEASING_END)
@@ -192,11 +194,11 @@ uint8_t Button::process_button()
192194
else if (logical_state == BS_TAP2_PRESSING_BEGIN)
193195
logical_state = BS_TAP2_PRESSING_END;
194196
else if (logical_state == BS_TAP2_RELEASING_BEGIN)
195-
logical_state = BS_TAP2_RELEASING_END; // Кнопка отпущена второй раз
197+
logical_state = BS_TAP2_RELEASING_END;
196198
else if (logical_state == BS_TAP3_PRESSING_BEGIN)
197-
logical_state = BS_TAP3_PRESSING_END; // Кнопка нажата второй раз
199+
logical_state = BS_TAP3_PRESSING_END;
198200
else if (logical_state == BS_TAP3_RELEASING_BEGIN)
199-
logical_state = BS_TAP3_RELEASING_END; // Кнопка отпущена второй раз
201+
logical_state = BS_TAP3_RELEASING_END;
200202
}
201203
if (logical_state == BS_TAP1_PRESSING_END)
202204
{
@@ -206,7 +208,7 @@ uint8_t Button::process_button()
206208
logical_state = BS_RELEASED; // Fake tap
207209
else if (current_time - tap_time < single_tap_time)
208210
{
209-
logical_state = BS_TAP1_RELEASING_BEGIN; // Отпускание кнопки
211+
logical_state = BS_TAP1_RELEASING_BEGIN;
210212
tap_time = current_time;
211213
}
212214
}

0 commit comments

Comments
 (0)