Skip to content

Commit

Permalink
start end events and dont disable
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed Jun 4, 2024
1 parent 7261c53 commit c8c35c9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
47 changes: 32 additions & 15 deletions src/core0_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ pub fn audio_task(
if !do_recording && take_test_rec {
duration = 10;
}
event_logger.log_event(
LoggerEvent::new(
LoggerEventKind::StartedRecording,
synced_date_time.get_timestamp_micros(&timer),
),
&mut flash_storage,
);
let recorded = microphone.record_for_n_seconds(
duration,
dma_channels.ch3,
Expand Down Expand Up @@ -297,6 +304,14 @@ pub fn audio_task(
loop {
nop();
}
} else {
event_logger.log_event(
LoggerEvent::new(
LoggerEventKind::EndedRecording,
synced_date_time.get_timestamp_micros(&timer),
),
&mut flash_storage,
);
}
}
if do_recording && !take_test_rec {
Expand Down Expand Up @@ -390,23 +405,25 @@ pub fn audio_task(
watchdog.feed();
if should_sleep {
if let Ok(pi_is_powered_down) = shared_i2c.pi_is_powered_down(&mut delay, true) {
if pi_is_powered_down && alarm_time.is_some() {
let until_alarm = (alarm_time.unwrap()
- synced_date_time.get_adjusted_dt(timer))
.num_minutes();

if until_alarm < 1 {
// otherwise the alarm could trigger between here and sleeping
should_sleep = false;
info!("Alarm is scheduled in {} so not sleeping", until_alarm);
if until_alarm <= 0 {
watchdog.start(100.micros());
loop {
// Wait to be reset and become thermal device
nop();
if pi_is_powered_down {
if alarm_time.is_some() {
let until_alarm = (alarm_time.unwrap()
- synced_date_time.get_adjusted_dt(timer))
.num_minutes();

if until_alarm < 1 {
// otherwise the alarm could trigger between here and sleeping
should_sleep = false;
info!("Alarm is scheduled in {} so not sleeping", until_alarm);
if until_alarm <= 0 {
watchdog.start(100.micros());
loop {
// Wait to be reset and become thermal device
nop();
}
}
continue;
}
continue;
}
info!("Ask Attiny to power down rp2040");
event_logger.log_event(
Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ fn main() -> ! {
if alarm_woke_us {
shared_i2c.clear_alarm(&mut delay);
}
let disabled_alarm = shared_i2c.disable_alarm(&mut delay);
if disabled_alarm.is_err() {
error!("{}", disabled_alarm.unwrap());
if !is_audio {
let disabled_alarm = shared_i2c.disable_alarm(&mut delay);
if disabled_alarm.is_err() {
error!("{}", disabled_alarm.unwrap());
}
}
let (i2c1, unlocked_pin) = shared_i2c.free();

Expand Down

0 comments on commit c8c35c9

Please sign in to comment.