cargo fmt
This commit is contained in:
parent
26da6b39cc
commit
bfc3fbc6e1
@ -5,8 +5,8 @@ use std::{
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use chrono::{DateTime, Datelike, Timelike};
|
||||
use chrono_tz::Tz::UTC;
|
||||
use chrono_tz::Tz;
|
||||
use chrono_tz::Tz::UTC;
|
||||
use esp_idf_hal::delay::Delay;
|
||||
use esp_idf_sys::{
|
||||
esp_ota_get_app_partition_count, esp_ota_get_running_partition, esp_ota_get_state_partition,
|
||||
@ -196,9 +196,7 @@ fn safe_main() -> Result<()> {
|
||||
}
|
||||
|
||||
let config: PlantControllerConfig = match board.get_config() {
|
||||
Ok(valid) => {
|
||||
valid
|
||||
}
|
||||
Ok(valid) => valid,
|
||||
Err(err) => {
|
||||
log(
|
||||
LogMessage::ConfigModeMissingConfig,
|
||||
@ -270,10 +268,7 @@ fn safe_main() -> Result<()> {
|
||||
Ok(_) => {
|
||||
println!("Started ap, continuing")
|
||||
}
|
||||
Err(err) => println!(
|
||||
"Could not start config override ap mode due to {}",
|
||||
err
|
||||
),
|
||||
Err(err) => println!("Could not start config override ap mode due to {}", err),
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,7 +280,6 @@ fn safe_main() -> Result<()> {
|
||||
None => UTC, // Fallback to UTC if no timezone is set
|
||||
};
|
||||
|
||||
|
||||
let timezone_time = cur.with_timezone(&timezone);
|
||||
println!(
|
||||
"Running logic at utc {} and {} {}",
|
||||
@ -361,13 +355,9 @@ fn safe_main() -> Result<()> {
|
||||
&format!("{}", value),
|
||||
"",
|
||||
),
|
||||
TankError::BoardError(err) => log(
|
||||
LogMessage::TankSensorBoardError,
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
&err.to_string()
|
||||
),
|
||||
TankError::BoardError(err) => {
|
||||
log(LogMessage::TankSensorBoardError, 0, 0, "", &err.to_string())
|
||||
}
|
||||
}
|
||||
// disabled cannot trigger this because of wrapping if is_enabled
|
||||
board.general_fault(true);
|
||||
@ -624,7 +614,9 @@ fn wait_infinity(wait_type: WaitType, reboot_now: Arc<AtomicBool>) -> ! {
|
||||
drop(lock);
|
||||
vTaskDelay(delay);
|
||||
|
||||
if wait_type == WaitType::MqttConfig && !STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
if wait_type == WaitType::MqttConfig
|
||||
&& !STAY_ALIVE.load(std::sync::atomic::Ordering::Relaxed)
|
||||
{
|
||||
reboot_now.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
if reboot_now.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
|
@ -545,9 +545,7 @@ impl PlantCtrlBoard<'_> {
|
||||
}
|
||||
|
||||
pub fn consecutive_pump_count(&mut self, plant: usize) -> u32 {
|
||||
unsafe {
|
||||
CONSECUTIVE_WATERING_PLANT[plant]
|
||||
}
|
||||
unsafe { CONSECUTIVE_WATERING_PLANT[plant] }
|
||||
}
|
||||
|
||||
pub fn fault(&self, plant: usize, enable: bool) {
|
||||
@ -568,9 +566,7 @@ impl PlantCtrlBoard<'_> {
|
||||
}
|
||||
|
||||
pub fn low_voltage_in_cycle(&mut self) -> bool {
|
||||
unsafe {
|
||||
LOW_VOLTAGE_DETECTED
|
||||
}
|
||||
unsafe { LOW_VOLTAGE_DETECTED }
|
||||
}
|
||||
|
||||
pub fn any_pump(&mut self, enable: bool) -> Result<()> {
|
||||
@ -639,8 +635,7 @@ impl PlantCtrlBoard<'_> {
|
||||
self.sensor_multiplexer(sensor_channel)?;
|
||||
|
||||
self.shift_register.decompose()[MS_4].set_low()?;
|
||||
self.shift_register.decompose()[SENSOR_ON]
|
||||
.set_high()?;
|
||||
self.shift_register.decompose()[SENSOR_ON].set_high()?;
|
||||
|
||||
let delay = Delay::new_default();
|
||||
let measurement = 100; // TODO what is this scaling factor? what is its purpose?
|
||||
@ -652,8 +647,7 @@ impl PlantCtrlBoard<'_> {
|
||||
delay.delay_ms(measurement);
|
||||
self.signal_counter.counter_pause()?;
|
||||
self.shift_register.decompose()[MS_4].set_high()?;
|
||||
self.shift_register.decompose()[SENSOR_ON]
|
||||
.set_low()?;
|
||||
self.shift_register.decompose()[SENSOR_ON].set_low()?;
|
||||
delay.delay_ms(10);
|
||||
let unscaled = self.signal_counter.get_counter_value()? as i32;
|
||||
let hz = unscaled as f32 * factor;
|
||||
@ -804,7 +798,7 @@ impl PlantCtrlBoard<'_> {
|
||||
}
|
||||
|
||||
//destroy backup header
|
||||
let dummy : [u8;0] = [];
|
||||
let dummy: [u8; 0] = [];
|
||||
self.backup_config(&dummy)?;
|
||||
|
||||
Ok(())
|
||||
@ -812,9 +806,7 @@ impl PlantCtrlBoard<'_> {
|
||||
|
||||
pub fn get_rtc_time(&mut self) -> Result<DateTime<Utc>> {
|
||||
match self.rtc.datetime() {
|
||||
OkStd(rtc_time) => {
|
||||
Ok(rtc_time.and_utc())
|
||||
}
|
||||
OkStd(rtc_time) => Ok(rtc_time.and_utc()),
|
||||
Err(err) => {
|
||||
bail!("Error getting rtc time {:?}", err)
|
||||
}
|
||||
@ -1037,7 +1029,7 @@ impl PlantCtrlBoard<'_> {
|
||||
|
||||
let mut wait_for_roundtrip = 0;
|
||||
while wait_for_roundtrip < 100 {
|
||||
wait_for_roundtrip+=1;
|
||||
wait_for_roundtrip += 1;
|
||||
match round_trip_ok.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
true => {
|
||||
println!("Round trip registered, proceeding");
|
||||
@ -1094,12 +1086,7 @@ impl PlantCtrlBoard<'_> {
|
||||
println!("Some error assembling full_topic 2");
|
||||
bail!("Some error assembling full_topic 2")
|
||||
};
|
||||
let publish = client.publish(
|
||||
&full_topic,
|
||||
ExactlyOnce,
|
||||
true,
|
||||
message,
|
||||
);
|
||||
let publish = client.publish(&full_topic, ExactlyOnce, true, message);
|
||||
Delay::new(10).delay_ms(50);
|
||||
match publish {
|
||||
OkStd(message_id) => {
|
||||
|
@ -2,10 +2,7 @@ use chrono::{DateTime, TimeDelta, Utc};
|
||||
use chrono_tz::Tz;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
config::PlantConfig,
|
||||
in_time_range, plant_hal,
|
||||
};
|
||||
use crate::{config::PlantConfig, in_time_range, plant_hal};
|
||||
|
||||
const MOIST_SENSOR_MAX_FREQUENCY: f32 = 6500.; // 60kHz (500Hz margin)
|
||||
const MOIST_SENSOR_MIN_FREQUENCY: f32 = 150.; // this is really, really dry, think like cactus levels
|
||||
@ -239,9 +236,7 @@ impl PlantState {
|
||||
false
|
||||
}
|
||||
}
|
||||
PlantWateringMode::TimerOnly => {
|
||||
!self.pump_in_timeout(plant_conf, current_time)
|
||||
}
|
||||
PlantWateringMode::TimerOnly => !self.pump_in_timeout(plant_conf, current_time),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,10 +82,12 @@ fn get_time(
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
let native = board
|
||||
.time().map(|t| t.to_rfc3339())
|
||||
.time()
|
||||
.map(|t| t.to_rfc3339())
|
||||
.unwrap_or("error".to_string());
|
||||
let rtc = board
|
||||
.get_rtc_time().map(|t| t.to_rfc3339())
|
||||
.get_rtc_time()
|
||||
.map(|t| t.to_rfc3339())
|
||||
.unwrap_or("error".to_string());
|
||||
|
||||
let data = LoadData {
|
||||
@ -137,8 +139,6 @@ fn get_live_moisture(
|
||||
anyhow::Ok(Some(json))
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn get_config(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
@ -373,16 +373,12 @@ fn flash_bq(filename: &str, dryrun: bool) -> anyhow::Result<()> {
|
||||
anyhow::Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn query_param(uri: &str, param_name: &str) -> Option<std::string::String> {
|
||||
println!("{uri} get {param_name}");
|
||||
let parsed = Url::parse(&format!("http://127.0.0.1/{uri}")).unwrap();
|
||||
let value = parsed.query_pairs().find(|it| it.0 == param_name);
|
||||
match value {
|
||||
Some(found) => {
|
||||
Some(found.1.into_owned())
|
||||
}
|
||||
Some(found) => Some(found.1.into_owned()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
@ -678,7 +674,6 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
server
|
||||
}
|
||||
|
||||
|
||||
fn cors_response(
|
||||
request: Request<&mut EspHttpConnection>,
|
||||
status: u16,
|
||||
|
Loading…
x
Reference in New Issue
Block a user