diff --git a/firmware/CHANGELOG.md b/firmware/CHANGELOG.md index fccecf4..069b4e7 100644 --- a/firmware/CHANGELOG.md +++ b/firmware/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Show random greetings to user + ## 0.1.0 - 2024-10-30 - Showcased on general meeting diff --git a/firmware/src/main.rs b/firmware/src/main.rs index b7c4276..ef22159 100644 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -214,6 +214,7 @@ async fn main(spawner: Spawner) { // Create UI let mut ui = ui::Ui::new( + rng, &mut display, &mut keypad, &mut nfc, diff --git a/firmware/src/screen.rs b/firmware/src/screen.rs index d79ed42..1bd45c1 100644 --- a/firmware/src/screen.rs +++ b/firmware/src/screen.rs @@ -4,6 +4,7 @@ use embedded_graphics::draw_target::DrawTarget; use embedded_graphics::image::{Image, ImageRaw}; use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; +use rand_core::RngCore; use u8g2_fonts::types::{FontColor, HorizontalAlignment, VerticalPosition}; use u8g2_fonts::{fonts, FontRenderer}; @@ -173,12 +174,16 @@ impl Screen for ScanId { /// Prompt to ask for number of drinks pub struct NumberOfDrinks { + greeting: u32, name: N, } impl NumberOfDrinks { - pub fn new(name: N) -> Self { - Self { name } + pub fn new(rng: &mut RNG, name: N) -> Self { + Self { + greeting: rng.next_u32(), + name, + } } } @@ -187,8 +192,16 @@ impl Screen for NumberOfDrinks { &self, target: &mut D, ) -> Result<(), Error> { + static GREETINGS: [&str; 9] = [ + "Hallo", "Hi", "Hey", "Tach", "Servus", "Moin", "Hej", "Olá", "Ciao", + ]; + MEDIUM_FONT.render_aligned( - format_args!("Hallo {}", self.name), + format_args!( + "{} {}", + GREETINGS[self.greeting as usize % GREETINGS.len()], + self.name + ), Point::new(63, 8), VerticalPosition::Baseline, HorizontalAlignment::Center, diff --git a/firmware/src/ui.rs b/firmware/src/ui.rs index 1706af4..cbca30b 100644 --- a/firmware/src/ui.rs +++ b/firmware/src/ui.rs @@ -16,6 +16,7 @@ use embassy_time::{with_timeout, Duration, TimeoutError, Timer}; use embedded_hal_async::digital::Wait; use embedded_hal_async::i2c::I2c; use log::info; +use rand_core::RngCore; /// How long to show the splash screen if no key is pressed const SPLASH_TIMEOUT: Duration = Duration::from_secs(5); @@ -36,7 +37,8 @@ const IDLE_TIMEOUT: Duration = Duration::from_secs(300); const IDLE_TIMEOUT: Duration = Duration::from_secs(10); /// User interface -pub struct Ui<'a, I2C, IRQ> { +pub struct Ui<'a, RNG, I2C, IRQ> { + rng: RNG, display: &'a mut Display, keypad: &'a mut Keypad<'a, 3, 4>, nfc: &'a mut Nfc, @@ -47,10 +49,11 @@ pub struct Ui<'a, I2C, IRQ> { users: &'a mut Users, } -impl<'a, I2C: I2c, IRQ: Wait> Ui<'a, I2C, IRQ> { +impl<'a, RNG: RngCore, I2C: I2c, IRQ: Wait> Ui<'a, RNG, I2C, IRQ> { /// Create user interface with given human interface devices #[allow(clippy::too_many_arguments)] pub fn new( + rng: RNG, display: &'a mut Display, keypad: &'a mut Keypad<'a, 3, 4>, nfc: &'a mut Nfc, @@ -61,6 +64,7 @@ impl<'a, I2C: I2c, IRQ: Wait> Ui<'a, I2C, IRQ> { users: &'a mut Users, ) -> Self { Self { + rng, display, keypad, nfc, @@ -213,7 +217,7 @@ impl<'a, I2C: I2c, IRQ: Wait> Ui<'a, I2C, IRQ> { } } -impl<'a, I2C: I2c, IRQ: Wait> Ui<'a, I2C, IRQ> { +impl<'a, RNG: RngCore, I2C: I2c, IRQ: Wait> Ui<'a, RNG, I2C, IRQ> { /// Authentication: wait for id card, read it and look up the associated user. On idle timeout, /// enter power saving (turn off display). Any key pressed leaves power saving (turn on /// display). @@ -265,7 +269,7 @@ impl<'a, I2C: I2c, IRQ: Wait> Ui<'a, I2C, IRQ> { info!("UI: Asking for number of drinks..."); self.display - .screen(&screen::NumberOfDrinks::new(name)) + .screen(&screen::NumberOfDrinks::new(&mut self.rng, name)) .await?; loop { #[allow(clippy::match_same_arms)]