Skip to content

Commit

Permalink
Switch clippy to pedantic and fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Sep 9, 2024
1 parent 941c20e commit ae7bbb1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions firmware/src/pn532.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
1 change: 1 addition & 0 deletions firmware/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use u8g2_fonts::{fonts, FontRenderer};

/// Touch 'n Drink bi-color logo
#[rustfmt::skip]
#[allow(clippy::unreadable_literal)]
static LOGO: ImageRaw<BinaryColor> = 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,
Expand Down
8 changes: 7 additions & 1 deletion firmware/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -142,6 +145,7 @@ impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> 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),
Expand Down Expand Up @@ -181,7 +185,9 @@ impl<'a, I2C: I2c, IRQ: Wait<Error = Infallible>> 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
Expand Down
8 changes: 6 additions & 2 deletions firmware/src/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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...");
Expand Down

0 comments on commit ae7bbb1

Please sign in to comment.