update: refactor and enhance CAN sensor initialization, reorganize GPIO assignments, improve error detection and logging, and streamline TWAI handling
This commit is contained in:
@@ -18,9 +18,7 @@ use crate::webserver::get_json::{
|
||||
use crate::webserver::get_log::get_log;
|
||||
use crate::webserver::get_static::{serve_bundle, serve_favicon, serve_index};
|
||||
use crate::webserver::ota::ota_operations;
|
||||
use crate::webserver::post_json::{
|
||||
board_test, detect_sensors, night_lamp_test, pump_test, set_config, wifi_scan, write_time,
|
||||
};
|
||||
use crate::webserver::post_json::{board_test, can_power, detect_sensors, night_lamp_test, pump_test, set_config, wifi_scan, write_time};
|
||||
use crate::{bail, BOARD_ACCESS};
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::{String, ToString};
|
||||
@@ -103,6 +101,7 @@ impl Handler for HTTPRequestRouter {
|
||||
"/time" => Some(write_time(conn).await),
|
||||
"/backup_config" => Some(backup_config(conn).await),
|
||||
"/pumptest" => Some(pump_test(conn).await),
|
||||
"/can_power" => Some(can_power(conn).await),
|
||||
"/lamptest" => Some(night_lamp_test(conn).await),
|
||||
"/boardtest" => Some(board_test().await),
|
||||
"/detect_sensors" => Some(detect_sensors().await),
|
||||
|
||||
@@ -29,6 +29,11 @@ pub struct TestPump {
|
||||
pump: usize,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct CanPower {
|
||||
state: bool,
|
||||
}
|
||||
|
||||
pub(crate) async fn wifi_scan<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
) -> FatResult<Option<String>> {
|
||||
@@ -117,3 +122,22 @@ where
|
||||
board.board_hal.set_config(config);
|
||||
Ok(Some("Ok".to_string()))
|
||||
}
|
||||
|
||||
pub(crate) async fn can_power<T, const N: usize>(
|
||||
request: &mut Connection<'_, T, N>,
|
||||
) -> FatResult<Option<String>>
|
||||
where
|
||||
T: Read + Write,
|
||||
{
|
||||
let actual_data = read_up_to_bytes_from_request(request, None).await?;
|
||||
let pump_test: CanPower = serde_json::from_slice(&actual_data)?;
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
|
||||
let config = &board.board_hal.can_power(pump_test.state).await?;
|
||||
let enable = pump_test.state;
|
||||
info!(
|
||||
"set can power to {enable}"
|
||||
);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user