chore: cargo fmt
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
|
||||
use crate::hal::battery::BatteryInteraction;
|
||||
use crate::{
|
||||
determine_tank_state, get_version, log::LogMessage,
|
||||
plant_state::PlantState, BOARD_ACCESS,
|
||||
determine_tank_state, get_version, log::LogMessage, plant_state::PlantState, BOARD_ACCESS,
|
||||
};
|
||||
use anyhow::bail;
|
||||
use chrono::DateTime;
|
||||
@@ -83,11 +82,14 @@ fn get_time(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().expect("board access");
|
||||
let native = board.board_hal.get_esp()
|
||||
let native = board
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.time()
|
||||
.map(|t| t.to_rfc3339())
|
||||
.unwrap_or("error".to_string());
|
||||
let rtc = board.board_hal
|
||||
let rtc = board
|
||||
.board_hal
|
||||
.get_rtc_time()
|
||||
.map(|t| t.to_rfc3339())
|
||||
.unwrap_or("error".to_string());
|
||||
@@ -116,35 +118,28 @@ fn get_live_moisture(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().expect("Should never fail");
|
||||
let plant_state = Vec::from_iter(
|
||||
(0..PLANT_COUNT).map(|i| PlantState::read_hardware_state(i, &mut board)),
|
||||
);
|
||||
let a = Vec::from_iter(
|
||||
plant_state
|
||||
.iter()
|
||||
.map(|s| {
|
||||
match &s.sensor_a {
|
||||
MoistureSensorState::Disabled => "disabled".to_string(),
|
||||
MoistureSensorState::MoistureValue {raw_hz, moisture_percent } => {
|
||||
format!("{moisture_percent:.2}% {raw_hz}hz",)
|
||||
}
|
||||
MoistureSensorState::SensorError(err) => format!("{err:?}"),
|
||||
}
|
||||
})
|
||||
);
|
||||
let b = Vec::from_iter(
|
||||
plant_state
|
||||
.iter()
|
||||
.map(|s| {
|
||||
match &s.sensor_b {
|
||||
MoistureSensorState::Disabled => "disabled".to_string(),
|
||||
MoistureSensorState::MoistureValue {raw_hz, moisture_percent } => {
|
||||
format!("{moisture_percent:.2}% {raw_hz}hz",)
|
||||
}
|
||||
MoistureSensorState::SensorError(err) => format!("{err:?}"),
|
||||
}
|
||||
})
|
||||
);
|
||||
let plant_state =
|
||||
Vec::from_iter((0..PLANT_COUNT).map(|i| PlantState::read_hardware_state(i, &mut board)));
|
||||
let a = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_a {
|
||||
MoistureSensorState::Disabled => "disabled".to_string(),
|
||||
MoistureSensorState::MoistureValue {
|
||||
raw_hz,
|
||||
moisture_percent,
|
||||
} => {
|
||||
format!("{moisture_percent:.2}% {raw_hz}hz",)
|
||||
}
|
||||
MoistureSensorState::SensorError(err) => format!("{err:?}"),
|
||||
}));
|
||||
let b = Vec::from_iter(plant_state.iter().map(|s| match &s.sensor_b {
|
||||
MoistureSensorState::Disabled => "disabled".to_string(),
|
||||
MoistureSensorState::MoistureValue {
|
||||
raw_hz,
|
||||
moisture_percent,
|
||||
} => {
|
||||
format!("{moisture_percent:.2}% {raw_hz}hz",)
|
||||
}
|
||||
MoistureSensorState::SensorError(err) => format!("{err:?}"),
|
||||
}));
|
||||
|
||||
let data = Moistures {
|
||||
moisture_a: a,
|
||||
@@ -267,9 +262,10 @@ fn tank_info(
|
||||
let tank_info = determine_tank_state(&mut board);
|
||||
//should be multsampled
|
||||
let water_temp = board.board_hal.water_temperature_c();
|
||||
Ok(Some(serde_json::to_string(
|
||||
&tank_info.as_mqtt_info(&board.board_hal.get_config().tank, &water_temp),
|
||||
)?))
|
||||
Ok(Some(serde_json::to_string(&tank_info.as_mqtt_info(
|
||||
&board.board_hal.get_config().tank,
|
||||
&water_temp,
|
||||
))?))
|
||||
}
|
||||
|
||||
fn night_lamp_test(
|
||||
@@ -297,7 +293,9 @@ fn wifi_scan(
|
||||
fn list_files(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().expect("It should be possible to lock the board for exclusive fs access");
|
||||
let mut board = BOARD_ACCESS
|
||||
.lock()
|
||||
.expect("It should be possible to lock the board for exclusive fs access");
|
||||
let result = board.board_hal.get_esp().list_files();
|
||||
let file_list_json = serde_json::to_string(&result)?;
|
||||
anyhow::Ok(Some(file_list_json))
|
||||
@@ -469,7 +467,12 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
let reboot_now_for_reboot = reboot_now.clone();
|
||||
server
|
||||
.fn_handler("/reboot", Method::Post, move |_| {
|
||||
BOARD_ACCESS.lock().unwrap().board_hal.get_esp().set_restart_to_conf(true);
|
||||
BOARD_ACCESS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.set_restart_to_conf(true);
|
||||
reboot_now_for_reboot.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
anyhow::Ok(())
|
||||
})
|
||||
@@ -490,7 +493,8 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||
let file_handle = BOARD_ACCESS
|
||||
.lock()
|
||||
.unwrap()
|
||||
.board_hal.get_esp()
|
||||
.board_hal
|
||||
.get_esp()
|
||||
.get_file_handle(&filename, false);
|
||||
match file_handle {
|
||||
Ok(mut file_handle) => {
|
||||
|
Reference in New Issue
Block a user