From ae7bbb1974c3d8cc4110ccf9ec47f89ff2855c0f Mon Sep 17 00:00:00 2001 From: Andreas Neuhaus Date: Mon, 9 Sep 2024 16:54:39 +0200 Subject: [PATCH] Switch clippy to pedantic and fix some warnings --- firmware/Cargo.toml | 3 +++ firmware/src/pn532.rs | 8 ++++++++ firmware/src/screen.rs | 1 + firmware/src/ui.rs | 8 +++++++- firmware/src/wifi.rs | 8 ++++++-- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/firmware/Cargo.toml b/firmware/Cargo.toml index ff7ab76..2f7b4cc 100644 --- a/firmware/Cargo.toml +++ b/firmware/Cargo.toml @@ -12,6 +12,9 @@ name = "touch-n-drink" test = false bench = false +[lints.clippy] +pedantic = "warn" + [profile.dev] # Rust debug code is slow, so always build with some optimization opt-level = "s" diff --git a/firmware/src/pn532.rs b/firmware/src/pn532.rs index 8e0b2b5..8783cd7 100644 --- a/firmware/src/pn532.rs +++ b/firmware/src/pn532.rs @@ -1,3 +1,11 @@ +// Mute pedantic clippy warnings caused by original code copied from pn532 crate +#![allow( + clippy::cast_possible_truncation, + clippy::if_not_else, + clippy::items_after_statements, + clippy::range_plus_one +)] + use core::convert::Infallible; use core::fmt::Debug; use embassy_time::{with_timeout, Duration}; diff --git a/firmware/src/screen.rs b/firmware/src/screen.rs index 1a92fda..20a7e1e 100644 --- a/firmware/src/screen.rs +++ b/firmware/src/screen.rs @@ -8,6 +8,7 @@ use u8g2_fonts::{fonts, FontRenderer}; /// Touch 'n Drink bi-color logo #[rustfmt::skip] +#[allow(clippy::unreadable_literal)] static LOGO: ImageRaw = ImageRaw::new(&[ 0b11111111, 0b11000111, 0b11100011, 0b11001111, 0b00011111, 0b10001111, 0b00011110, 0b00111101, 0b11110011, 0b11000011, 0b11111100, 0b01111111, 0b10001111, 0b01111100, 0b11110111, 0b10001111, 0b10000000, 0b01001100, 0b00110010, 0b01001001, 0b00110000, 0b11001001, 0b00010010, 0b00100101, 0b00010010, 0b01000011, 0b11111110, 0b01111111, 0b11001111, 0b01111100, 0b11110111, 0b10001111, diff --git a/firmware/src/ui.rs b/firmware/src/ui.rs index e5b1fc1..edf9b4e 100644 --- a/firmware/src/ui.rs +++ b/firmware/src/ui.rs @@ -10,6 +10,9 @@ use embedded_hal_async::digital::Wait; use embedded_hal_async::i2c::I2c; use log::info; +/// Price for a drink +const PRICE: f32 = 1.0; + /// How long to show the splash screen if no key is pressed const SPLASH_TIMEOUT: Duration = Duration::from_secs(5); @@ -142,6 +145,7 @@ impl<'a, I2C: I2c, IRQ: Wait> Ui<'a, I2C, IRQ> { self.display.screen(&screen::NumberOfDrinks).await?; loop { + #[allow(clippy::match_same_arms)] match with_timeout(USER_TIMEOUT, self.keypad.read()).await? { // Any digit 1..=9 selects number of drinks Key::Digit(n) if (1..=9).contains(&n) => return Ok(n as usize), @@ -181,7 +185,9 @@ impl<'a, I2C: I2c, IRQ: Wait> Ui<'a, I2C, IRQ> { pub async fn run(&mut self) -> Result<(), Error> { let _uid = self.read_id_card().await?; let num_drinks = self.get_number_of_drinks().await?; - let total_price = 1.0 * num_drinks as f32; + // It's ok to cast num_drinks to f32 as it's always a small number + #[allow(clippy::cast_precision_loss)] + let total_price = PRICE * num_drinks as f32; self.checkout(num_drinks, total_price).await?; // TODO: Process payment diff --git a/firmware/src/wifi.rs b/firmware/src/wifi.rs index 9f1fb97..25d7973 100644 --- a/firmware/src/wifi.rs +++ b/firmware/src/wifi.rs @@ -3,7 +3,9 @@ use embassy_time::{Duration, Timer}; use esp_hal::clock::Clocks; use esp_hal::peripherals; use esp_hal::rng::Rng; -use esp_wifi::wifi::{self, WifiController, WifiDevice, WifiEvent, WifiStaDevice, WifiState}; +use esp_wifi::wifi::{ + self, ClientConfiguration, WifiController, WifiDevice, WifiEvent, WifiStaDevice, WifiState, +}; use esp_wifi::{EspWifiInitFor, EspWifiInitialization, EspWifiTimerSource}; use log::{debug, info, warn}; @@ -36,7 +38,9 @@ impl<'d> Wifi<'d> { debug!("Wifi: Static configuration: {:?}", esp_wifi::CONFIG); let init = esp_wifi::initialize(EspWifiInitFor::Wifi, timer, rng, radio_clocks, clocks)?; - let client_config = Default::default(); + let client_config = ClientConfiguration { + ..Default::default() + }; let (device, mut controller) = wifi::new_with_config(&init, wifi, client_config)?; debug!("Wifi: Starting controller...");