From 7a0bf33b308bc45a07e229b99a7fb58c62f59712 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 2 Jul 2022 15:14:19 +0200 Subject: [PATCH] Add white LED blink after startup Previously, we removed the constant LED light. To make it clearer when the NK3 is powered, this patch adds a single white LED blink for 0.5 seconds after startup. This is consistent with the FIDO2 behavior. --- CHANGELOG.md | 3 ++- runners/lpc55/board/src/trussed.rs | 9 +++++---- runners/lpc55/board/src/ui.rs | 23 +++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40bb58f7..27d335ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Features -- Change the LED patterns so that the LED is off by default, blinks white during a user confirmation request and blinks blue when winking([#34][]) +- Change the LED patterns so that the LED is off by default, blinks white during a user confirmation request and blinks blue when winking ([#34][]) +- Add a single white LED blink for 0.5 seconds after startup ([#34][]) [#34]: https://github.com/Nitrokey/nitrokey-3-firmware/issues/34 diff --git a/runners/lpc55/board/src/trussed.rs b/runners/lpc55/board/src/trussed.rs index 29d7b117..3ae9423c 100644 --- a/runners/lpc55/board/src/trussed.rs +++ b/runners/lpc55/board/src/trussed.rs @@ -49,12 +49,13 @@ RGB: RgbLed, rgb: Option, provisioner: bool, ) -> Self { - let status = Default::default(); + let uptime = rtc.uptime(); + let status = Status::Startup(uptime); #[cfg(not(feature = "no-buttons"))] - let ui = Self { rtc, buttons: _buttons, status, rgb, provisioner }; + let mut ui = Self { rtc, buttons: _buttons, status, rgb, provisioner }; #[cfg(feature = "no-buttons")] - let ui = Self { rtc, buttons: None, status, rgb, provisioner }; - + let mut ui = Self { rtc, buttons: None, status, rgb, provisioner }; + ui.refresh_ui(uptime); ui } diff --git a/runners/lpc55/board/src/ui.rs b/runners/lpc55/board/src/ui.rs index 1b87fd5d..994e2fad 100644 --- a/runners/lpc55/board/src/ui.rs +++ b/runners/lpc55/board/src/ui.rs @@ -11,6 +11,7 @@ const TEAL: Intensities = Intensities { red: 0, green: u8::MAX, blue: 0x5a }; const WHITE: Intensities = Intensities { red: u8::MAX, green: u8::MAX, blue: u8::MAX }; pub enum Status { + Startup(Duration), Idle, Processing, WaitingForUserPresence(Duration), @@ -20,15 +21,22 @@ pub enum Status { impl Status { pub fn update(&mut self, status: ui::Status, uptime: Duration) { - if matches!(self, Self::Winking(_)) && status == ui::Status::Idle { - return; + if status == ui::Status::Idle { + if matches!(self, Self::Startup(_) | Self::Winking(_)) { + return; + } } *self = (status, uptime).into(); } pub fn refresh(&mut self, uptime: Duration) { - if let Self::Winking(ref range) = self { - if !range.contains(&uptime) { + let end = match self { + Self::Startup(ref start) => Some(*start + Duration::from_millis(500)), + Self::Winking(ref range) => Some(range.end), + _ => None, + }; + if let Some(end) = end { + if uptime > end { *self = Self::Idle; } } @@ -36,6 +44,7 @@ impl Status { pub fn led_mode(&self, is_provisioner: bool) -> LedMode { match self { + Self::Startup(_) => LedMode::constant(WHITE), Self::Idle => if is_provisioner { LedMode::constant(WHITE) } else { @@ -49,12 +58,6 @@ impl Status { } } -impl Default for Status { - fn default() -> Self { - Self::Idle - } -} - impl From<(ui::Status, Duration)> for Status { fn from((status, uptime): (ui::Status, Duration)) -> Self { match status {