Skip to content

Commit 0f63ba4

Browse files
committed
Fix delay function for lower delays
The debounce feature expects the button to be held for a minimum amount of time to register a button press. This caused the delay function to always return 0 (no button presses) for very short delays. It will now return 1 for short delays iff the button was pressed/held during that time.
1 parent d5a4e34 commit 0f63ba4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib/user-io.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ uint8_t delay(uint16_t led_on_time_ms, uint16_t led_off_time_ms,
136136

137137
PORTB &= ~PORTB_LED;
138138

139+
if (delay_ms <= BUTTON_HOLD_TIME_MS) {
140+
/* The wait delay is lower than the minimum hold time, so
141+
get_tracked_presses will not return a correct number of press times.
142+
Instead, we just return 1 if the button was held at all. */
143+
144+
return (info.hold_time > 0) ? 1 : 0;
145+
}
146+
139147
/* Will wait for the button to be released */
140148
return get_tracked_presses(&info);
141149
}

0 commit comments

Comments
 (0)