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