split rtc module out to reduce repreated exactly same code
This commit is contained in:
@@ -81,7 +81,10 @@ fn write_time(
|
||||
tv_usec: 0,
|
||||
};
|
||||
unsafe { settimeofday(&now, core::ptr::null_mut()) };
|
||||
board.board_hal.set_rtc_time(&parsed.to_utc())?;
|
||||
board
|
||||
.board_hal
|
||||
.get_rtc_module()
|
||||
.set_rtc_time(&parsed.to_utc())?;
|
||||
anyhow::Ok(None)
|
||||
}
|
||||
|
||||
@@ -97,6 +100,7 @@ fn get_time(
|
||||
.unwrap_or("error".to_string());
|
||||
let rtc = board
|
||||
.board_hal
|
||||
.get_rtc_module()
|
||||
.get_rtc_time()
|
||||
.map(|t| t.to_rfc3339())
|
||||
.unwrap_or("error".to_string());
|
||||
@@ -170,7 +174,9 @@ fn backup_config(
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let all = read_up_to_bytes_from_request(request, Some(3072))?;
|
||||
let mut board = BOARD_ACCESS.lock().expect("board access");
|
||||
board.board_hal.backup_config(&all)?;
|
||||
|
||||
//TODO how to handle progress here? prior versions animated the fault leds while running
|
||||
board.board_hal.get_rtc_module().backup_config(&all)?;
|
||||
anyhow::Ok(Some("saved".to_owned()))
|
||||
}
|
||||
|
||||
@@ -178,7 +184,7 @@ fn get_backup_config(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().expect("board access");
|
||||
let json = match board.board_hal.get_backup_config() {
|
||||
let json = match board.board_hal.get_rtc_module().get_backup_config() {
|
||||
Ok(config) => from_utf8(&config)?.to_owned(),
|
||||
Err(err) => {
|
||||
println!("Error get backup config {:?}", err);
|
||||
@@ -192,7 +198,7 @@ fn backup_info(
|
||||
_request: &mut Request<&mut EspHttpConnection>,
|
||||
) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.lock().expect("Should never fail");
|
||||
let header = board.board_hal.get_backup_info();
|
||||
let header = board.board_hal.get_rtc_module().get_backup_info();
|
||||
let json = match header {
|
||||
Ok(h) => {
|
||||
let timestamp = DateTime::from_timestamp_millis(h.timestamp).unwrap();
|
||||
@@ -341,7 +347,7 @@ fn ota(
|
||||
|
||||
let iter = (total_read / 1024) % 8;
|
||||
if iter != lastiter {
|
||||
board.board_hal.general_fault(iter%5==0);
|
||||
board.board_hal.general_fault(iter % 5 == 0);
|
||||
for i in 0..PLANT_COUNT {
|
||||
let _ = board.board_hal.fault(i, iter == i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user