From 5621f17e61c0ac18a7e2303a772410b5928b7b73 Mon Sep 17 00:00:00 2001 From: ju6ge Date: Fri, 20 Jun 2025 21:31:12 +0200 Subject: [PATCH] fix all warnings --- rust/src/hal/battery.rs | 1 + rust/src/hal/mod.rs | 6 +----- rust/src/hal/v3_hal.rs | 6 +++--- rust/src/hal/v4_hal.rs | 8 ++++---- rust/src/main.rs | 15 +-------------- rust/src/plant_state.rs | 6 +++++- rust/src/webserver/webserver.rs | 2 +- 7 files changed, 16 insertions(+), 28 deletions(-) diff --git a/rust/src/hal/battery.rs b/rust/src/hal/battery.rs index 7e844ca..4ec9f4e 100644 --- a/rust/src/hal/battery.rs +++ b/rust/src/hal/battery.rs @@ -97,6 +97,7 @@ impl BatteryInteraction for NoBatteryMonitor { } //TODO implement this battery monitor kind once controller is complete +#[allow(dead_code)] pub struct WchI2cSlave {} pub struct BQ34Z100G1<'a> { diff --git a/rust/src/hal/mod.rs b/rust/src/hal/mod.rs index c000595..92d1a8b 100644 --- a/rust/src/hal/mod.rs +++ b/rust/src/hal/mod.rs @@ -51,11 +51,6 @@ const TANK_MULTI_SAMPLE: usize = 11; pub static I2C_DRIVER: Lazy>> = Lazy::new(PlantHal::create_i2c); -#[non_exhaustive] -struct V3Constants; - -impl V3Constants {} - const X25: crc::Crc = crc::Crc::::new(&crc::CRC_16_IBM_SDLC); fn deep_sleep(duration_in_ms: u64) -> ! { @@ -132,6 +127,7 @@ pub trait BoardInteraction<'a> { fn set_config(&mut self, config: PlantControllerConfig) -> Result<()>; } +#[allow(dead_code)] pub struct FreePeripherals { pub gpio0: Gpio0, pub gpio1: Gpio1, diff --git a/rust/src/hal/v3_hal.rs b/rust/src/hal/v3_hal.rs index cd07b2d..8961c60 100644 --- a/rust/src/hal/v3_hal.rs +++ b/rust/src/hal/v3_hal.rs @@ -84,7 +84,7 @@ pub struct V3<'a> { PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>, PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, InputOutput>, >, - shift_register_enable_invert: + _shift_register_enable_invert: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Output>, tank_channel: AdcChannelDriver<'a, Gpio5, AdcDriver<'a, esp_idf_hal::adc::ADC1>>, solar_is_day: PinDriver<'a, esp_idf_hal::gpio::AnyIOPin, esp_idf_hal::gpio::Input>, @@ -109,7 +109,7 @@ pub(crate) fn create_v3( esp: ESP<'static>, config: PlantControllerConfig, battery_monitor: Box, -) -> Result> { +) -> Result + Send>> { let mut clock = PinDriver::input_output(peripherals.gpio15.downgrade())?; clock.set_pull(Pull::Floating)?; let mut latch = PinDriver::input_output(peripherals.gpio3.downgrade())?; @@ -234,7 +234,7 @@ pub(crate) fn create_v3( battery_monitor, esp, shift_register, - shift_register_enable_invert, + _shift_register_enable_invert: shift_register_enable_invert, tank_channel, solar_is_day, light, diff --git a/rust/src/hal/v4_hal.rs b/rust/src/hal/v4_hal.rs index fd1e897..ab60976 100644 --- a/rust/src/hal/v4_hal.rs +++ b/rust/src/hal/v4_hal.rs @@ -38,7 +38,7 @@ const MS4: u8 = 2_u8; const SENSOR_ON: u8 = 5_u8; pub struct V4<'a> { - mppt_ina: SyncIna219>, UnCalibrated>, + _mppt_ina: SyncIna219>, UnCalibrated>, esp: ESP<'a>, battery_monitor: Box, config: PlantControllerConfig, @@ -63,12 +63,12 @@ pub struct V4<'a> { sensor_expander: Pca9535Immediate>>, } -pub(crate) fn create_v4( +pub(crate) fn create_v4<'a>( peripherals: FreePeripherals, esp: ESP<'static>, config: PlantControllerConfig, battery_monitor: Box, -) -> anyhow::Result> { +) -> anyhow::Result + Send>> { let mut awake = PinDriver::output(peripherals.gpio15.downgrade())?; awake.set_high()?; @@ -188,7 +188,7 @@ pub(crate) fn create_v4( println!("Shunt Current: {}", current); let v = V4 { - mppt_ina, + _mppt_ina: mppt_ina, esp, awake, tank_channel, diff --git a/rust/src/main.rs b/rust/src/main.rs index 06c8791..dfad2a7 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -20,11 +20,7 @@ use log::{log, LogMessage}; use once_cell::sync::Lazy; use plant_state::PlantState; use serde::{Deserialize, Serialize}; -use std::sync::MutexGuard; -use std::{ - fmt::Display, - sync::{atomic::AtomicBool, Arc, Mutex}, -}; +use std::sync::{atomic::AtomicBool, Arc, Mutex, MutexGuard}; use tank::*; mod config; @@ -841,15 +837,6 @@ fn main() { } } -fn to_string(value: anyhow::Result) -> String { - match value { - Ok(v) => v.to_string(), - Err(err) => { - format!("{:?}", err) - } - } -} - pub fn in_time_range(cur: &DateTime, start: u8, end: u8) -> bool { let curhour = cur.hour() as u8; //eg 10-14 diff --git a/rust/src/plant_state.rs b/rust/src/plant_state.rs index fd331e2..38204cf 100644 --- a/rust/src/plant_state.rs +++ b/rust/src/plant_state.rs @@ -239,7 +239,11 @@ impl PlantState { } } - pub fn to_mqtt_info(&self, plant_conf: &PlantConfig, current_time: &DateTime) -> PlantInfo { + pub fn to_mqtt_info( + &self, + plant_conf: &PlantConfig, + current_time: &DateTime, + ) -> PlantInfo<'_> { PlantInfo { sensor_a: &self.sensor_a, sensor_b: &self.sensor_b, diff --git a/rust/src/webserver/webserver.rs b/rust/src/webserver/webserver.rs index d6f168d..f52c713 100644 --- a/rust/src/webserver/webserver.rs +++ b/rust/src/webserver/webserver.rs @@ -214,7 +214,7 @@ fn set_config( let config: PlantControllerConfig = serde_json::from_slice(&all)?; let mut board = BOARD_ACCESS.lock().expect("board access"); - board.board_hal.set_config(config); + let _ = board.board_hal.set_config(config); anyhow::Ok(Some("saved".to_owned())) }