fmt & clippy

This commit is contained in:
eraden 2024-10-01 05:34:16 +02:00
parent 14b63b5ad3
commit 09f4b17674
5 changed files with 24 additions and 35 deletions

View File

@ -0,0 +1 @@

View File

@ -38,15 +38,12 @@ impl MazeGame {
for x in 0..122 { for x in 0..122 {
for y in 0..122 { for y in 0..122 {
match self.map.at(x, y) { if self.map.at(x, y) == maze::MazePart::Wall {
maze::MazePart::Wall => { let p = Rectangle::new(
let p = Rectangle::new( Point::new(x as i32 + Self::X_OFFSET, y as i32 + Self::Y_OFFSET),
Point::new(x as i32 + Self::X_OFFSET, y as i32 + Self::Y_OFFSET), Size::new(1, 1),
Size::new(1, 1), );
); p.draw_styled(&wall_style, &mut ctx.epaper.display).unwrap();
p.draw_styled(&wall_style, &mut ctx.epaper.display).unwrap();
}
_ => {}
} }
} }
} }
@ -61,8 +58,8 @@ impl MazeGame {
let p = Rectangle::new( let p = Rectangle::new(
Point::new( Point::new(
self.player.x as i32 + Self::X_OFFSET, self.player.x + Self::X_OFFSET,
self.player.y as i32 + Self::Y_OFFSET, self.player.y + Self::Y_OFFSET,
), ),
Size::new(1, 1), Size::new(1, 1),
); );
@ -85,7 +82,7 @@ impl App for MazeGame {
return; return;
}; };
ctx.epaper.partial_update( ctx.epaper.partial_update(
old.clone(), *old,
Size { Size {
width: 0, width: 0,
height: 0, height: 0,
@ -99,7 +96,7 @@ impl App for MazeGame {
let Some(button) = ctx.button_pressed else { let Some(button) = ctx.button_pressed else {
return None; return None;
}; };
let player_old = self.player.clone(); let player_old = self.player;
match button { match button {
Button::Up if self.map.can_move(self.player_pos(), Direction::North) => { 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); self.old_player = Some(player_old);
Some(Action::PartialRender) Some(Action::PartialRender)
} }
Button::Back => return Some(Action::GoToMenu), Button::Back => Some(Action::GoToMenu),
_ => None, _ => None,
} }
} }

View File

@ -49,7 +49,7 @@ impl App for Menu {
}; };
match button { match button {
Button::Up => match self.selected { Button::Up => match self.selected {
MenuEntry::Labirynth => return None, MenuEntry::Labirynth => None,
MenuEntry::Pairs => { MenuEntry::Pairs => {
self.selected = MenuEntry::Labirynth; self.selected = MenuEntry::Labirynth;
Some(Action::Render) Some(Action::Render)
@ -63,8 +63,8 @@ impl App for Menu {
MenuEntry::Pairs => None, MenuEntry::Pairs => None,
}, },
Button::Circle => match self.selected { Button::Circle => match self.selected {
MenuEntry::Labirynth => return Some(Action::StartMaze), MenuEntry::Labirynth => Some(Action::StartMaze),
MenuEntry::Pairs => return Some(Action::StartPairs), MenuEntry::Pairs => Some(Action::StartPairs),
}, },
_ => None, _ => None,
} }

View File

@ -12,8 +12,7 @@ use epd_waveshare::prelude::*;
use esp_hal::{ use esp_hal::{
clock::Clocks, clock::Clocks,
delay::Delay, delay::Delay,
gpio::{Gpio18, Gpio19, Gpio20, Gpio21, Gpio22, Gpio23, Input, Io, Level, Output, NO_PIN}, gpio::{Gpio18, Gpio19, Gpio20, Gpio21, Gpio22, Gpio23, Input, Level, Output, NO_PIN},
peripherals::Peripherals,
prelude::*, prelude::*,
spi::{master::Spi, FullDuplexMode, SpiMode}, spi::{master::Spi, FullDuplexMode, SpiMode},
}; };
@ -82,7 +81,7 @@ impl<'d> Epaper<'d> {
spi: esp_hal::peripherals::SPI2, spi: esp_hal::peripherals::SPI2,
clocks: &'d Clocks, clocks: &'d Clocks,
) -> Self { ) -> 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( let spi_bus: SpiBus = Spi::new(spi, 4_000.kHz(), SpiMode::Mode0, clocks).with_pins(
Some(sclk), Some(sclk),

View File

@ -3,15 +3,8 @@
mod epaper; mod epaper;
use apps::{menu::Menu, Application}; use apps::Application;
use embedded_graphics::{ use embedded_graphics::Drawable;
geometry::{Point, Size},
mono_font::MonoTextStyleBuilder,
primitives::{Primitive, PrimitiveStyleBuilder, Rectangle, StyledDrawable},
text::{Baseline, Text, TextStyleBuilder},
Drawable,
};
use embedded_hal::delay::DelayNs;
use embedded_hal_bus::spi::ExclusiveDevice; use embedded_hal_bus::spi::ExclusiveDevice;
use epaper::Epaper; use epaper::Epaper;
use epd_waveshare::epd3in7::*; use epd_waveshare::epd3in7::*;
@ -21,13 +14,13 @@ use esp_hal::{
clock::ClockControl, clock::ClockControl,
delay::Delay, delay::Delay,
gpio::{ gpio::{
Gpio0, Gpio1, Gpio10, Gpio11, Gpio2, Gpio20, Gpio21, Gpio22, Gpio23, Gpio3, Gpio4, Gpio5, Gpio0, Gpio1, Gpio10, Gpio20, Gpio21, Gpio22, Gpio23, Gpio4, Gpio5,
Gpio6, Gpio7, Gpio8, Input, Io, Level, Output, OutputOpenDrain, Pull, NO_PIN, Gpio6, Gpio7, Gpio8, Input, Io, Level, Output, OutputOpenDrain, Pull,
}, },
peripherals::Peripherals, peripherals::Peripherals,
prelude::*, prelude::*,
rng::Trng, rng::Trng,
spi::{master::Spi, FullDuplexMode, SpiMode}, spi::{master::Spi, FullDuplexMode},
system::SystemControl, system::SystemControl,
}; };
use esp_println::println; use esp_println::println;
@ -100,7 +93,7 @@ fn main() -> ! {
loop { loop {
ctx.button_pressed = kbd.pressed(); ctx.button_pressed = kbd.pressed();
if !ctx.button_pressed.is_none() { if ctx.button_pressed.is_some() {
log::info!("Wake up!"); log::info!("Wake up!");
app.update_and_draw(&mut ctx, &mut trng); app.update_and_draw(&mut ctx, &mut trng);
} }
@ -205,8 +198,7 @@ impl<'d> Keypad<'d> {
} }
let c = res let c = res
.into_iter() .into_iter()
.map(|v| v.into_iter()) .flat_map(|v| v.into_iter())
.flatten()
.enumerate() .enumerate()
.find(|(_idx, b)| *b) .find(|(_idx, b)| *b)
.and_then(|(idx, _)| Button::from_idx(idx)); .and_then(|(idx, _)| Button::from_idx(idx));