Skip to content

Commit

Permalink
nk3am: Remove blocking UP check
Browse files Browse the repository at this point in the history
Since this commit [0] that changed the threshold from 3 to 1, the
blocking loop in the user presence check for the NK3AM does no longer
have any functional effect.  But it has undesired side effects, for
example skipping the UI update for a second so that the blinking effect
is not triggered, and delaying the handling of cancelled requests.

This patch removes the unnecessary blocking loop.  The button
implementation still requires 100 ticks to trigger a button press.

Fixes: #93

[0] 35dac8d
  • Loading branch information
robin-nitrokey committed Mar 4, 2024
1 parent 079a6e8 commit 55d8517
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions components/boards/src/nk3am/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,7 @@ impl HardwareButtons {

impl UserPresence for HardwareButtons {
fn check_user_presence(&mut self, clock: &mut dyn Clock) -> consent::Level {
// essentially a blocking call for up to ~30secs
// this outer loop accumulates *presses* from the
// inner loop & maintains (loading) delays.

let mut counter: u8 = 0;
let threshold: u8 = 1;

let start_time = clock.uptime();
let timeout_at = start_time + Duration::from_millis(1_000);
let mut next_check = start_time + Duration::from_millis(25);

loop {
let cur_time = clock.uptime();

// timeout reached
if cur_time > timeout_at {
break;
}
// loop until next check shall be done
if cur_time < next_check {
continue;
}

if self.is_pressed(Button::A) {
counter += 1;
// with press -> delay 25ms
next_check = cur_time + Duration::from_millis(25);
} else {
// w/o press -> delay 100ms
next_check = cur_time + Duration::from_millis(100);
}

if counter >= threshold {
break;
}
}

// consent, if we've counted 3 "presses"
if counter >= threshold {
if self.is_pressed(Button::A) {
consent::Level::Normal
} else {
consent::Level::None
Expand Down

0 comments on commit 55d8517

Please sign in to comment.