-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor / bugfix] Simplify HardwareButtons
#655
base: dev
Are you sure you want to change the base?
Conversation
Tested ACK (I think, at least it all seems to be working) as of 9efb700, Currently, this is:
I will be using this new pi0 image as my default (as I have done with 0.8.5-rc1 for the past weeks) until further prs (like pr_651 which was only awaiting this fix) have been merged for a new internal rc2. |
src/seedsigner/hardware/buttons.py
Outdated
for key in HardwareButtonsConstants.ALL_KEYS: | ||
if self.GPIO.input(key) == GPIO.LOW: | ||
return True | ||
return False | ||
|
||
|
||
# class used as short hand for static button/channel lookup values | ||
# TODO: Implement `release_lock` functionality as a global somewhere. Mixes up design |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer a TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good eyes. Removed!
Description
Two main issues are addressed:
HardwareButtons
.Death to
release_lock
The main change is around eliminating the
release_lock
and related concepts inHardwareButtons
. It's extremely difficult to reason through in its current (dev
, i.e. before this PR) state. From what I can discern, it's meant to track the status of a button (or joystick direction) being physically released (press a button down, then release it to let it return to its normal resting position).So think of it like javascript's onMouseUp event.
However, if you look at how our code reacts to user input, we only react on the PRESS, not on the release.
We only need
HardwareButtons
to react to individual inputs (joystick movement, button press) and be savvy about short-press vs long-press/sustained hold (e.g. holding the joystick to continuously scan across a keyboard). It doesn't care at all if we clicked some super-important OKAY button that we categorized as arelease_key
.So if we start to unwind the
release_lock
concept, a number of methods can be totally deleted:check_release
andrelease_keys
input params onwait_for()
force_release()
rising_callback()
handleradd_events()
initializer to set that handlertrigger_override()
now doesn't need any reference torelease_lock
Issue #654: In my testing, this was caused by this line:
seedsigner/src/seedsigner/hardware/buttons.py
Line 106 in 9bfb7b2
If I moved that to after the override is handled, the issue was resolved (sort of -- I had a lot of changes in place by then, but moving that line was the big breakthrough as far as I could tell).
Completely eliminating the
release_lock
(thankfully) also fixed the bug.Simplify
trigger_override
The current (
dev
) version ofwait_for()
has an absolutely nightmarishif
statement AND an incomprehensible follow up comment (that I think I wrote, unfortunately):The above
release_lock
changes help us out a ton here. We can eliminate all of theif
statement mess. The last complication is in how we process thetrigger_override()
. This now becomes simple: We triggered the override to break us out of thewait_for()
loop. So move that check to the beginning of the loop and keep its logic completely separate.Remaining changes
wait_for()
input params.BaseScreen.display()
.try
/finally
to add guarantees about theBruteForceAddressVerificationThread
being shut down.Tips for testing
Any screen that involves user input, especially if there are other threads or atypical input handling:
This pull request is categorized as a:
Checklist
pytest
and made sure all unit tests pass before sumbitting the PRIf you modified or added functionality/workflow, did you add new unit tests?
I have tested this PR on the following platforms/os: