From 09f4b176747e7ee757eb6a70ad3cfef91eb99e56 Mon Sep 17 00:00:00 2001 From: eraden Date: Tue, 1 Oct 2024 05:34:16 +0200 Subject: [PATCH] fmt & clippy --- src/apps/guess_game.rs | 1 + src/apps/maze_game.rs | 25 +++++++++++-------------- src/apps/menu.rs | 6 +++--- src/epaper.rs | 5 ++--- src/main.rs | 22 +++++++--------------- 5 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/apps/guess_game.rs b/src/apps/guess_game.rs index e69de29..8b13789 100644 --- a/src/apps/guess_game.rs +++ b/src/apps/guess_game.rs @@ -0,0 +1 @@ + diff --git a/src/apps/maze_game.rs b/src/apps/maze_game.rs index eb91b81..13af8bf 100644 --- a/src/apps/maze_game.rs +++ b/src/apps/maze_game.rs @@ -38,15 +38,12 @@ impl MazeGame { for x in 0..122 { for y in 0..122 { - match self.map.at(x, y) { - maze::MazePart::Wall => { - let p = Rectangle::new( - Point::new(x as i32 + Self::X_OFFSET, y as i32 + Self::Y_OFFSET), - Size::new(1, 1), - ); - p.draw_styled(&wall_style, &mut ctx.epaper.display).unwrap(); - } - _ => {} + if self.map.at(x, y) == maze::MazePart::Wall { + let p = Rectangle::new( + Point::new(x as i32 + Self::X_OFFSET, y as i32 + Self::Y_OFFSET), + Size::new(1, 1), + ); + p.draw_styled(&wall_style, &mut ctx.epaper.display).unwrap(); } } } @@ -61,8 +58,8 @@ impl MazeGame { let p = Rectangle::new( Point::new( - self.player.x as i32 + Self::X_OFFSET, - self.player.y as i32 + Self::Y_OFFSET, + self.player.x + Self::X_OFFSET, + self.player.y + Self::Y_OFFSET, ), Size::new(1, 1), ); @@ -85,7 +82,7 @@ impl App for MazeGame { return; }; ctx.epaper.partial_update( - old.clone(), + *old, Size { width: 0, height: 0, @@ -99,7 +96,7 @@ impl App for MazeGame { let Some(button) = ctx.button_pressed else { return None; }; - let player_old = self.player.clone(); + let player_old = self.player; match button { Button::Up if self.map.can_move(self.player_pos(), Direction::North) => { @@ -122,7 +119,7 @@ impl App for MazeGame { self.old_player = Some(player_old); Some(Action::PartialRender) } - Button::Back => return Some(Action::GoToMenu), + Button::Back => Some(Action::GoToMenu), _ => None, } } diff --git a/src/apps/menu.rs b/src/apps/menu.rs index 1e15dab..e1e0abe 100644 --- a/src/apps/menu.rs +++ b/src/apps/menu.rs @@ -49,7 +49,7 @@ impl App for Menu { }; match button { Button::Up => match self.selected { - MenuEntry::Labirynth => return None, + MenuEntry::Labirynth => None, MenuEntry::Pairs => { self.selected = MenuEntry::Labirynth; Some(Action::Render) @@ -63,8 +63,8 @@ impl App for Menu { MenuEntry::Pairs => None, }, Button::Circle => match self.selected { - MenuEntry::Labirynth => return Some(Action::StartMaze), - MenuEntry::Pairs => return Some(Action::StartPairs), + MenuEntry::Labirynth => Some(Action::StartMaze), + MenuEntry::Pairs => Some(Action::StartPairs), }, _ => None, } diff --git a/src/epaper.rs b/src/epaper.rs index fe23636..967d7fe 100644 --- a/src/epaper.rs +++ b/src/epaper.rs @@ -12,8 +12,7 @@ use epd_waveshare::prelude::*; use esp_hal::{ clock::Clocks, delay::Delay, - gpio::{Gpio18, Gpio19, Gpio20, Gpio21, Gpio22, Gpio23, Input, Io, Level, Output, NO_PIN}, - peripherals::Peripherals, + gpio::{Gpio18, Gpio19, Gpio20, Gpio21, Gpio22, Gpio23, Input, Level, Output, NO_PIN}, prelude::*, spi::{master::Spi, FullDuplexMode, SpiMode}, }; @@ -82,7 +81,7 @@ impl<'d> Epaper<'d> { spi: esp_hal::peripherals::SPI2, clocks: &'d Clocks, ) -> Self { - let mut delay = Delay::new(&clocks); + let mut delay = Delay::new(clocks); let spi_bus: SpiBus = Spi::new(spi, 4_000.kHz(), SpiMode::Mode0, clocks).with_pins( Some(sclk), diff --git a/src/main.rs b/src/main.rs index 4067ce3..b3b1f1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,15 +3,8 @@ mod epaper; -use apps::{menu::Menu, Application}; -use embedded_graphics::{ - geometry::{Point, Size}, - mono_font::MonoTextStyleBuilder, - primitives::{Primitive, PrimitiveStyleBuilder, Rectangle, StyledDrawable}, - text::{Baseline, Text, TextStyleBuilder}, - Drawable, -}; -use embedded_hal::delay::DelayNs; +use apps::Application; +use embedded_graphics::Drawable; use embedded_hal_bus::spi::ExclusiveDevice; use epaper::Epaper; use epd_waveshare::epd3in7::*; @@ -21,13 +14,13 @@ use esp_hal::{ clock::ClockControl, delay::Delay, gpio::{ - Gpio0, Gpio1, Gpio10, Gpio11, Gpio2, Gpio20, Gpio21, Gpio22, Gpio23, Gpio3, Gpio4, Gpio5, - Gpio6, Gpio7, Gpio8, Input, Io, Level, Output, OutputOpenDrain, Pull, NO_PIN, + Gpio0, Gpio1, Gpio10, Gpio20, Gpio21, Gpio22, Gpio23, Gpio4, Gpio5, + Gpio6, Gpio7, Gpio8, Input, Io, Level, Output, OutputOpenDrain, Pull, }, peripherals::Peripherals, prelude::*, rng::Trng, - spi::{master::Spi, FullDuplexMode, SpiMode}, + spi::{master::Spi, FullDuplexMode}, system::SystemControl, }; use esp_println::println; @@ -100,7 +93,7 @@ fn main() -> ! { loop { ctx.button_pressed = kbd.pressed(); - if !ctx.button_pressed.is_none() { + if ctx.button_pressed.is_some() { log::info!("Wake up!"); app.update_and_draw(&mut ctx, &mut trng); } @@ -205,8 +198,7 @@ impl<'d> Keypad<'d> { } let c = res .into_iter() - .map(|v| v.into_iter()) - .flatten() + .flat_map(|v| v.into_iter()) .enumerate() .find(|(_idx, b)| *b) .and_then(|(idx, _)| Button::from_idx(idx));