From 5b265885627d3c077e2f125071626649c3aac99a Mon Sep 17 00:00:00 2001 From: gferraro Date: Tue, 28 May 2024 09:13:25 +1200 Subject: [PATCH] add time for missed alarm --- src/event_logger.rs | 13 +++++++++---- src/main.rs | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/event_logger.rs b/src/event_logger.rs index abb2286..261e1ad 100644 --- a/src/event_logger.rs +++ b/src/event_logger.rs @@ -21,7 +21,7 @@ pub enum LoggerEventKind { Rp2040WokenByAlarm, RtcCommError, AttinyCommError, - Rp2040MissedAudioAlarm, + Rp2040MissedAudioAlarm(u64), } impl Into for LoggerEventKind { @@ -47,7 +47,7 @@ impl Into for LoggerEventKind { Rp2040WokenByAlarm => 17, RtcCommError => 18, AttinyCommError => 19, - Rp2040MissedAudioAlarm => 20, + Rp2040MissedAudioAlarm(_) => 20, } } } @@ -77,7 +77,7 @@ impl TryFrom for LoggerEventKind { 17 => Ok(Rp2040WokenByAlarm), 18 => Ok(RtcCommError), 19 => Ok(AttinyCommError), - 20 => Ok(Rp2040MissedAudioAlarm), + 20 => Ok(Rp2040MissedAudioAlarm(0)), _ => Err(()), } } @@ -106,7 +106,12 @@ impl LoggerEvent { .push_param(format!(r#"{{ "alarm-time": {} }}"#, alarm * 1000)) .unwrap(); // Microseconds to nanoseconds call.body.push_param("SetAlarm").unwrap(); - } else { + }else if let LoggerEventKind::Rp2040MissedAudioAlarm(alarm) = self.event { + call.body + .push_param(format!(r#"{{ "alarm-time": {} }}"#, alarm * 1000)) + .unwrap(); // Microseconds to nanoseconds + call.body.push_param("Rp2040MissedAudioAlarm").unwrap(); + } else { call.body .push_param(json_payload.unwrap_or(String::from("{}"))) .unwrap(); diff --git a/src/main.rs b/src/main.rs index d8b8a28..549062a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1012,6 +1012,12 @@ fn main() { } else { warn!("Wakeup alarm from event was invalid {}", event_payload); } + }else if let LoggerEventKind::Rp2040MissedAudioAlarm(alarm_time) = &mut event_kind { + if NaiveDateTime::from_timestamp_micros(event_payload as i64).is_some() { + *alarm_time = event_payload; + } else { + warn!("Missed alarm from event was invalid {}", event_payload); + } } let payload_json = if let LoggerEventKind::SavedNewConfig = event_kind { // If we get saved new config, the rp2040 would have just been