Skip to content

Commit 7e743bf

Browse files
MDr164claude
andcommitted
fix(application): address clippy warnings
- xtask: replace manual div_ceil expression with .div_ceil() - storage: remove blank line after doc comment; remove unused KEY_INIT constant - auth: suppress dead_code on AdminUser tuple field (inner AuthUser accessible via .0 for future use) - gpio: refactor gpio_task to accept [Output; 8] array instead of 8 individual arguments to satisfy clippy::too_many_arguments - main: add EthernetRunner type alias to resolve clippy::type_complexity on ethernet_task signature Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Marvin Drees <marvin.drees@9elements.com>
1 parent f10342d commit 7e743bf

File tree

5 files changed

+29
-90
lines changed

5 files changed

+29
-90
lines changed

application/src/auth.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ impl<'r> FromRequestParts<'r, ()> for AuthUser {
153153
// ── AdminUser ─────────────────────────────────────────────────────────────────
154154

155155
/// Wrapper extractor that requires the authenticated user to be an admin.
156+
/// The inner `AuthUser` is available for handlers that need it via `.0`.
157+
#[allow(dead_code)]
156158
pub struct AdminUser(pub AuthUser);
157159

158160
/// Returned when an authenticated-but-non-admin user tries to access an admin route.

application/src/gpio.rs

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,7 @@ pub static GPIO_STATES: Mutex<CriticalSectionRawMutex, [bool; 8]> = Mutex::new([
2525
/// Listens on `GPIO_SIGNAL` for commands and updates both the pin hardware
2626
/// and the shared `GPIO_STATES` mutex.
2727
#[embassy_executor::task]
28-
pub async fn gpio_task(
29-
mut pin0: Output<'static>,
30-
mut pin1: Output<'static>,
31-
mut pin2: Output<'static>,
32-
mut pin3: Output<'static>,
33-
mut pin4: Output<'static>,
34-
mut pin5: Output<'static>,
35-
mut pin6: Output<'static>,
36-
mut pin7: Output<'static>,
37-
) {
28+
pub async fn gpio_task(mut pins: [Output<'static>; 8]) {
3829
loop {
3930
let cmd = GPIO_SIGNAL.wait().await;
4031

@@ -58,65 +49,10 @@ pub async fn gpio_task(
5849
};
5950

6051
// Drive the hardware pin
61-
let set_high = new_state;
62-
match pin_index {
63-
0 => {
64-
if set_high {
65-
pin0.set_high();
66-
} else {
67-
pin0.set_low();
68-
}
69-
}
70-
1 => {
71-
if set_high {
72-
pin1.set_high();
73-
} else {
74-
pin1.set_low();
75-
}
76-
}
77-
2 => {
78-
if set_high {
79-
pin2.set_high();
80-
} else {
81-
pin2.set_low();
82-
}
83-
}
84-
3 => {
85-
if set_high {
86-
pin3.set_high();
87-
} else {
88-
pin3.set_low();
89-
}
90-
}
91-
4 => {
92-
if set_high {
93-
pin4.set_high();
94-
} else {
95-
pin4.set_low();
96-
}
97-
}
98-
5 => {
99-
if set_high {
100-
pin5.set_high();
101-
} else {
102-
pin5.set_low();
103-
}
104-
}
105-
6 => {
106-
if set_high {
107-
pin6.set_high();
108-
} else {
109-
pin6.set_low();
110-
}
111-
}
112-
7 => {
113-
if set_high {
114-
pin7.set_high();
115-
} else {
116-
pin7.set_low();
117-
}
118-
}
119-
_ => {}
52+
if new_state {
53+
pins[pin_index].set_high();
54+
} else {
55+
pins[pin_index].set_low();
12056
}
12157
}
12258
}

application/src/main.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ bind_interrupts!(struct Irqs {
5858

5959
// ── Ethernet task ──────────────────────────────────────────────────────────────
6060

61+
/// Type alias for the W5500 runner to avoid repeating the full generic signature.
62+
type EthernetRunner = Runner<
63+
'static,
64+
W5500,
65+
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static>, embassy_time::Delay>,
66+
Input<'static>,
67+
Output<'static>,
68+
>;
69+
6170
#[embassy_executor::task]
62-
async fn ethernet_task(
63-
runner: Runner<
64-
'static,
65-
W5500,
66-
ExclusiveDevice<Spi<'static, SPI0, Async>, Output<'static>, embassy_time::Delay>,
67-
Input<'static>,
68-
Output<'static>,
69-
>,
70-
) -> ! {
71+
async fn ethernet_task(runner: EthernetRunner) -> ! {
7172
runner.run().await
7273
}
7374

@@ -112,17 +113,19 @@ async fn main(spawner: Spawner) {
112113
web::init_db(db);
113114

114115
// 4. GPIO outputs for 8 relay outputs (PIN_0 – PIN_7)
115-
let pin0 = Output::new(p.PIN_0, Level::Low);
116-
let pin1 = Output::new(p.PIN_1, Level::Low);
117-
let pin2 = Output::new(p.PIN_2, Level::Low);
118-
let pin3 = Output::new(p.PIN_3, Level::Low);
119-
let pin4 = Output::new(p.PIN_4, Level::Low);
120-
let pin5 = Output::new(p.PIN_5, Level::Low);
121-
let pin6 = Output::new(p.PIN_6, Level::Low);
122-
let pin7 = Output::new(p.PIN_7, Level::Low);
116+
let relay_pins = [
117+
Output::new(p.PIN_0, Level::Low),
118+
Output::new(p.PIN_1, Level::Low),
119+
Output::new(p.PIN_2, Level::Low),
120+
Output::new(p.PIN_3, Level::Low),
121+
Output::new(p.PIN_4, Level::Low),
122+
Output::new(p.PIN_5, Level::Low),
123+
Output::new(p.PIN_6, Level::Low),
124+
Output::new(p.PIN_7, Level::Low),
125+
];
123126

124127
// 6. Spawn GPIO task
125-
spawner.spawn(gpio_task(pin0, pin1, pin2, pin3, pin4, pin5, pin6, pin7).unwrap());
128+
spawner.spawn(gpio_task(relay_pins).unwrap());
126129

127130
// 7. Init W5500 Ethernet (SPI0, DMA_CH0 TX, DMA_CH1 RX)
128131
let mut spi_cfg = SpiConfig::default();

application/src/storage.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ pub async fn init_database(
111111
// ── Schema key helpers ─────────────────────────────────────────────────────────
112112

113113
/// ekv key constants (sorted: "admin/..." < "init" < "p/..." < "u/...")
114-
115-
pub const KEY_INIT: &[u8] = b"init";
116114
pub const KEY_ADMIN_FIRST_LOGIN: &[u8] = b"admin/first_login";
117115

118116
/// Build port name key: `b"p/{port}/name"` (port 0–7)

xtask/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ const UF2_PAYLOAD_SIZE: usize = 256;
238238

239239
/// Convert a flat binary image to UF2 format for RP2040.
240240
fn binary_to_uf2(data: &[u8], base_addr: u32) -> Vec<u8> {
241-
let num_blocks = (data.len() + UF2_PAYLOAD_SIZE - 1) / UF2_PAYLOAD_SIZE;
241+
let num_blocks = data.len().div_ceil(UF2_PAYLOAD_SIZE);
242242
let mut uf2 = Vec::with_capacity(num_blocks * 512);
243243

244244
for (i, chunk) in data.chunks(UF2_PAYLOAD_SIZE).enumerate() {

0 commit comments

Comments
 (0)