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,16 +38,13 @@ impl MazeGame {
for x in 0..122 {
for y in 0..122 {
match self.map.at(x, y) {
maze::MazePart::Wall => {
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,
}
}

View File

@ -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,
}

View File

@ -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),

View File

@ -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));