From d8044b8e34e3fbc7ac0c94eb58788202a7b2d665 Mon Sep 17 00:00:00 2001 From: Empire Date: Thu, 25 Apr 2024 20:26:58 +0200 Subject: [PATCH] clippy adjustments --- rust/src/main.rs | 34 +++++++++++++++++----------------- rust/src/plant_hal.rs | 29 +++++++++++++++-------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/rust/src/main.rs b/rust/src/main.rs index b67ba30..d70b9f5 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -1123,24 +1123,24 @@ fn update_plant_state( } } let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/active", plant + 1).as_str(), state.active.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Sensor A", plant + 1).as_str(), option_to_string(state.a).as_bytes(), ); if plant_config.sensor_b { let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Sensor B", plant + 1).as_str(), option_to_string(state.b).as_bytes(), ); } else { let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Sensor B", plant + 1).as_str(), "disabled".as_bytes(), ); @@ -1148,70 +1148,70 @@ fn update_plant_state( if plant_config.sensor_p { let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Sensor P before", plant + 1).as_str(), option_to_string(state.p).as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Sensor P after", plant + 1).as_str(), option_to_string(state.after_p).as_bytes(), ); } else { let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Sensor P before", plant + 1).as_str(), "disabled".as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Sensor P after", plant + 1).as_str(), "disabled".as_bytes(), ); } let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Should water", plant + 1).as_str(), state.do_water.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Is frozen", plant + 1).as_str(), state.frozen.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Is dry", plant + 1).as_str(), state.dry.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Pump Error", plant + 1).as_str(), state.pump_error.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Pump Ineffective", plant + 1).as_str(), state.not_effective.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Is in Cooldown", plant + 1).as_str(), state.cooldown.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/No Water", plant + 1).as_str(), state.no_water.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/Out of Work Hour", plant + 1).as_str(), state.out_of_work_hour.to_string().as_bytes(), ); let _ = board.mqtt_publish( - &config, + config, format!("/plant{}/consecutive pump count", plant + 1).as_str(), state.consecutive_pump_count.to_string().as_bytes(), ); diff --git a/rust/src/plant_hal.rs b/rust/src/plant_hal.rs index a0076b0..7e6374b 100644 --- a/rust/src/plant_hal.rs +++ b/rust/src/plant_hal.rs @@ -42,7 +42,7 @@ use esp_idf_hal::prelude::Peripherals; use esp_idf_hal::reset::ResetReason; use esp_idf_svc::sntp::{self, SyncStatus}; use esp_idf_svc::systime::EspSystemTime; -use esp_idf_sys::{gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError}; +use esp_idf_sys::{esp, gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError}; use one_wire_bus::OneWire; use crate::config::{self, Config, WifiConfig}; @@ -676,7 +676,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> { } } } - embedded_svc::mqtt::client::EventPayload::Connected(session_present) => { + embedded_svc::mqtt::client::EventPayload::Connected{session_present: _} => { mqtt_connected_event_received_copy .store(true, std::sync::atomic::Ordering::Relaxed); mqtt_connected_event_ok_copy @@ -690,7 +690,8 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> { .store(false, std::sync::atomic::Ordering::Relaxed); println!("Mqtt disconnected"); } - embedded_svc::mqtt::client::EventPayload::Error(espError) => { + embedded_svc::mqtt::client::EventPayload::Error(esp_error) => { + println!("EspMqttError reported {:?}", esp_error); mqtt_connected_event_received_copy .store(true, std::sync::atomic::Ordering::Relaxed); mqtt_connected_event_ok_copy @@ -705,7 +706,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> { let wait_for_connections_event = 0; while wait_for_connections_event < 100 { - match true { //mqtt_connected_event_received.load(std::sync::atomic::Ordering::Relaxed) { + match mqtt_connected_event_received.load(std::sync::atomic::Ordering::Relaxed) { true => { println!("Mqtt connection callback received, progressing"); match mqtt_connected_event_ok.load(std::sync::atomic::Ordering::Relaxed) { @@ -961,8 +962,8 @@ impl CreatePlantHal<'_> for PlantHal { let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap(); - //let i2c_port = driver.port(); - //esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 2)}).unwrap(); + let i2c_port = driver.port(); + esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 2)}).unwrap(); let mut battery_driver: Bq34z100g1Driver = Bq34z100g1Driver { i2c: driver, @@ -1100,12 +1101,12 @@ impl CreatePlantHal<'_> for PlantHal { println!("After stuff"); - //let status = print_battery(&mut battery_driver); - //if status.is_err() { - // println!("Error communicating with battery!! {:?}", status.err()); - //} else { - // println!("Managed to comunnicate with battery"); - //} + let status = print_battery(&mut battery_driver); + if status.is_err() { + println!("Error communicating with battery!! {:?}", status.err()); + } else { + println!("Managed to comunnicate with battery"); + } let rv = Mutex::new(PlantCtrlBoard { shift_register, tank_driver, @@ -1120,8 +1121,8 @@ impl CreatePlantHal<'_> for PlantHal { signal_counter: counter_unit1, wifi_driver, mqtt_client: None, - battery_driver: None, - //Some(battery_driver), + //battery_driver: None, + battery_driver: Some(battery_driver) }); Ok(rv) }