Skip to content

Commit

Permalink
Pass HID resources as references to UI flow
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Oct 4, 2024
1 parent f0674f0 commit e2aaf21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async fn main(spawner: Spawner) {
let _ = display.screen(&screen::Splash).await;

// Initialize keypad
let keypad = keypad::Keypad::new(
let mut keypad = keypad::Keypad::new(
[
AnyInput::new(io.pins.gpio5, Pull::Up),
AnyInput::new(io.pins.gpio6, Pull::Up),
Expand All @@ -157,7 +157,7 @@ async fn main(spawner: Spawner) {

// Initialize NFC reader
let nfc_irq = AnyInput::new(io.pins.gpio20, Pull::Up);
let nfc = match nfc::Nfc::new(I2cDevice::new(&i2c), nfc_irq).await {
let mut nfc = match nfc::Nfc::new(I2cDevice::new(&i2c), nfc_irq).await {
Ok(nfc) => nfc,
// Panic on failure since an initialization error indicates a serious error
Err(err) => panic!("NFC reader initialization failed: {:?}", err),
Expand Down Expand Up @@ -188,7 +188,7 @@ async fn main(spawner: Spawner) {
let _ = buzzer.startup().await;

// Create UI
let mut ui = ui::Ui::new(display, keypad, nfc, buzzer, wifi);
let mut ui = ui::Ui::new(&mut display, &mut keypad, &mut nfc, &mut buzzer, &wifi);

// Show splash screen for a while, ignore any error
let _ = ui.show_splash().await;
Expand Down
20 changes: 10 additions & 10 deletions firmware/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ const IDLE_TIMEOUT: Duration = Duration::from_secs(10);

/// User interface
pub struct Ui<'a, I2C, IRQ> {
display: Display<I2C>,
keypad: Keypad<'a, 3, 4>,
nfc: Nfc<I2C, IRQ>,
buzzer: Buzzer<'a>,
wifi: Wifi,
display: &'a mut Display<I2C>,
keypad: &'a mut Keypad<'a, 3, 4>,
nfc: &'a mut Nfc<I2C, IRQ>,
buzzer: &'a mut Buzzer<'a>,
wifi: &'a Wifi,
}

impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> Ui<'a, I2C, IRQ> {
/// Create user interface with given human interface devices
pub fn new(
display: Display<I2C>,
keypad: Keypad<'a, 3, 4>,
nfc: Nfc<I2C, IRQ>,
buzzer: Buzzer<'a>,
wifi: Wifi,
display: &'a mut Display<I2C>,
keypad: &'a mut Keypad<'a, 3, 4>,
nfc: &'a mut Nfc<I2C, IRQ>,
buzzer: &'a mut Buzzer<'a>,
wifi: &'a Wifi,
) -> Self {
Self {
display,
Expand Down

0 comments on commit e2aaf21

Please sign in to comment.