cargo fmt
This commit is contained in:
parent
26da6b39cc
commit
bfc3fbc6e1
@ -3,39 +3,39 @@ use std::process::Command;
|
||||
use vergen::EmitBuilder;
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=./src/src_webpack");
|
||||
Command::new("rm")
|
||||
.arg("./src/webserver/bundle.js")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
match Command::new("cmd").spawn() {
|
||||
Ok(_) => {
|
||||
println!("Assuming build on windows");
|
||||
let output = Command::new("cmd")
|
||||
.arg("/K")
|
||||
.arg("npx")
|
||||
.arg("webpack")
|
||||
.current_dir("./src_webpack")
|
||||
.output()
|
||||
.unwrap();
|
||||
println!("status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
assert!(output.status.success());
|
||||
}
|
||||
Err(_) => {
|
||||
println!("Assuming build on linux");
|
||||
let output = Command::new("npx")
|
||||
.arg("webpack")
|
||||
.current_dir("./src_webpack")
|
||||
.output()
|
||||
.unwrap();
|
||||
println!("status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
assert!(output.status.success());
|
||||
}
|
||||
Command::new("rm")
|
||||
.arg("./src/webserver/bundle.js")
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
match Command::new("cmd").spawn() {
|
||||
Ok(_) => {
|
||||
println!("Assuming build on windows");
|
||||
let output = Command::new("cmd")
|
||||
.arg("/K")
|
||||
.arg("npx")
|
||||
.arg("webpack")
|
||||
.current_dir("./src_webpack")
|
||||
.output()
|
||||
.unwrap();
|
||||
println!("status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
assert!(output.status.success());
|
||||
}
|
||||
Err(_) => {
|
||||
println!("Assuming build on linux");
|
||||
let output = Command::new("npx")
|
||||
.arg("webpack")
|
||||
.current_dir("./src_webpack")
|
||||
.output()
|
||||
.unwrap();
|
||||
println!("status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
assert!(output.status.success());
|
||||
}
|
||||
}
|
||||
|
||||
embuild::espidf::sysenv::output();
|
||||
let _ = EmitBuilder::builder().all_git().all_build().emit();
|
||||
|
@ -114,4 +114,4 @@ impl Default for PlantConfig {
|
||||
moisture_sensor_max_frequency: None, // No override by default
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,14 +268,11 @@ 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),
|
||||
}
|
||||
}
|
||||
|
||||
let timezone = match &config.timezone {
|
||||
let timezone = match &config.timezone {
|
||||
Some(tz_str) => tz_str.parse::<Tz>().unwrap_or_else(|_| {
|
||||
println!("Invalid timezone '{}', falling back to UTC", tz_str);
|
||||
UTC
|
||||
@ -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);
|
||||
@ -459,7 +449,7 @@ fn safe_main() -> Result<()> {
|
||||
(plant_id + 1) as u32,
|
||||
plant_config.pump_time_s as u32,
|
||||
&dry_run.to_string(),
|
||||
"",
|
||||
"",
|
||||
);
|
||||
board.store_last_pump_time(plant_id, cur);
|
||||
board.last_pump_time(plant_id);
|
||||
@ -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) => {
|
||||
@ -1109,7 +1096,7 @@ impl PlantCtrlBoard<'_> {
|
||||
String::from_utf8_lossy(message),
|
||||
message_id
|
||||
);
|
||||
Ok(())
|
||||
Ok(())
|
||||
}
|
||||
Err(err) => {
|
||||
println!(
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,4 +303,4 @@ pub struct PlantInfo<'a> {
|
||||
last_pump: Option<DateTime<Tz>>,
|
||||
/// next time when pump should activate
|
||||
next_pump: Option<DateTime<Tz>>,
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,4 @@ impl LimitPrecision for f32 {
|
||||
let factor = 10_f32.powi(precision);
|
||||
(self * factor).round() / factor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
@ -743,4 +738,4 @@ fn read_up_to_bytes_from_request(
|
||||
let allvec = data_store.concat();
|
||||
println!("Raw data {}", from_utf8(&allvec)?);
|
||||
Ok(allvec)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user