Skip to content

Commit

Permalink
Improve logging of user interface main flow
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Aug 26, 2024
1 parent 39cc6ae commit 5586d66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,12 @@ async fn main(_spawner: Spawner) {
match ui.run().await {
// Success: start over again
Ok(()) => (),
// Timeout or cancel: start over again
Err(ui::Error::Cancel | ui::Error::Timeout) => (),
// TODO: Handle errors
Err(_err) => panic!("Unhandled ERROR"),
// Cancel: start over again
Err(ui::Error::Cancel) => info!("User cancelled, starting over..."),
// Timeout: start over again
Err(ui::Error::Timeout) => info!("Timeout waiting for user, starting over..."),
// TODO: Display error to user and start over again
Err(err) => panic!("Unhandled Error: {:?}", err),
}
}
}
12 changes: 11 additions & 1 deletion firmware/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> Ui<'a, I2C, IRQ> {
/// Save power by turning off devices not needed during idle
pub fn power_save(&mut self) -> Result<(), Error> {
info!("UI: Power saving...");

self.display.turn_off()?;
Ok(())
}
Expand All @@ -99,6 +100,8 @@ impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> Ui<'a, I2C, IRQ> {

/// Wait for id card and verify identification
pub async fn read_id_card(&mut self) -> Result<Uid, Error> {
info!("UI: Waiting for NFC card...");

self.display.screen(&screen::ScanId)?;
let mut saving_power = false;
loop {
Expand All @@ -112,7 +115,7 @@ impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> Ui<'a, I2C, IRQ> {
}
Err(TimeoutError) => continue,
};
info!("UI: Detected NFC UID: {}", uid);
info!("UI: Detected NFC card: {}", uid);
let _ = self.buzzer.short_confirmation().await;
// TODO: Verify identification and return user information
return Ok(uid);
Expand All @@ -121,6 +124,8 @@ impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> Ui<'a, I2C, IRQ> {

/// Ask for number of drinks
pub async fn get_number_of_drinks(&mut self) -> Result<usize, Error> {
info!("UI: Asking for number of drinks...");

self.display.screen(&screen::NumberOfDrinks)?;
loop {
match with_timeout(USER_TIMEOUT, self.keypad.read()).await? {
Expand All @@ -138,6 +143,11 @@ impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> Ui<'a, I2C, IRQ> {

/// Confirm purchase
pub async fn checkout(&mut self, num_drinks: usize, total_price: f32) -> Result<(), Error> {
info!(
"UI: Asking for checkout of {} drinks, {:.02} EUR...",
num_drinks, total_price
);

self.display
.screen(&screen::Checkout::new(num_drinks, total_price))?;
loop {
Expand Down

0 comments on commit 5586d66

Please sign in to comment.