Skip to content

Commit

Permalink
Merge branch 'led-startup'
Browse files Browse the repository at this point in the history
Adds a single white LED blink for 0.5 seconds after startup

Fixes #53
  • Loading branch information
szszszsz committed Jul 4, 2022
2 parents 0395723 + 7a0bf33 commit b23a680
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions runners/lpc55/board/src/trussed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ RGB: RgbLed,
rgb: Option<RGB>,
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
}

Expand Down
23 changes: 13 additions & 10 deletions runners/lpc55/board/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -20,22 +21,30 @@ 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;
}
}
}

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 {
Expand All @@ -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 {
Expand Down

0 comments on commit b23a680

Please sign in to comment.