Skip to content

Commit

Permalink
Merge pull request #7 from arduino/long-press-fix
Browse files Browse the repository at this point in the history
Fix long press not detected when on-press handler is absent
  • Loading branch information
sebromero authored Oct 25, 2024
2 parents 45ad786 + dc5fc29 commit 9fc1e9f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/modulino/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,24 @@ def update(self):
# Check for press and release
if(button_states_changed):

if(new_status[0] == 1 and previous_status[0] == 0 and self._on_button_a_press):
if(new_status[0] == 1 and previous_status[0] == 0):
self._last_press_timestamps[0] = ticks_ms()
self._on_button_a_press()
if(self._on_button_a_press):
self._on_button_a_press()
elif(new_status[0] == 0 and previous_status[0] == 1 and self._on_button_a_release):
self._on_button_a_release()

if(new_status[1] == 1 and previous_status[1] == 0 and self._on_button_b_press):
if(new_status[1] == 1 and previous_status[1] == 0):
self._last_press_timestamps[1] = ticks_ms()
self._on_button_b_press()
if(self._on_button_b_press):
self._on_button_b_press()
elif(new_status[1] == 0 and previous_status[1] == 1 and self._on_button_b_release):
self._on_button_b_release()

if(new_status[2] == 1 and previous_status[2] == 0 and self._on_button_c_press):
if(new_status[2] == 1 and previous_status[2] == 0):
self._last_press_timestamps[2] = ticks_ms()
self._on_button_c_press()
if(self._on_button_c_press):
self._on_button_c_press()
elif(new_status[2] == 0 and previous_status[2] == 1 and self._on_button_c_release):
self._on_button_c_release()

Expand Down

0 comments on commit 9fc1e9f

Please sign in to comment.