Skip to content

Commit

Permalink
[software] white led task / blink on error and communication
Browse files Browse the repository at this point in the history
  • Loading branch information
Kezii committed Sep 6, 2024
1 parent 2ddc522 commit 340101f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 40 additions & 1 deletion antani_sw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ enum TaskCommand {
IncreaseBrightness,
DecreaseBrightness,
ResetTime,
UsbActivity,
Error,
None,
}

Expand Down Expand Up @@ -315,7 +317,12 @@ async fn main(spawner: Spawner) {
)));

// white led
let _white_led = Output::new(p.PIN_20, embassy_rp::gpio::Level::Low);
let white_led = Output::new(p.PIN_20, embassy_rp::gpio::Level::Low);

unwrap!(spawner.spawn(white_led_task(
white_led,
MEGA_CHANNEL.subscriber().unwrap()
)));

// infrared stuff
let _ir_sens_0 = Input::new(p.PIN_9, Pull::None);
Expand Down Expand Up @@ -494,6 +501,8 @@ async fn main(spawner: Spawner) {
timer_offset = Instant::now().as_micros() as f64 / 1_000_000.0;
}

TaskCommand::UsbActivity | TaskCommand::Error => {}

TaskCommand::None => {}
}
}
Expand Down Expand Up @@ -625,6 +634,7 @@ async fn ir_blaster_tsk(
Status::Error => {
log::error!("Error in IR blaster");
enable_pwm(&mut ir_blaster, &mut pwm_cfg, false);
publisher.publish(crate::TaskCommand::Error).await;
break;
}
};
Expand All @@ -638,6 +648,35 @@ async fn ir_blaster_tsk(
}
}

#[embassy_executor::task]
async fn white_led_task(mut white_led: Output<'static>, mut subscriber: MegaSubscriber) {
loop {
match subscriber.next_message_pure().await {
TaskCommand::ReceivedIrNec(_, _, _)
| TaskCommand::MidiSetPixel(_, _, _, _)
| TaskCommand::UsbActivity => {
// communication state
white_led.set_high();
Timer::after(Duration::from_millis(200)).await;
white_led.set_low();
Timer::after(Duration::from_millis(200)).await;
}

TaskCommand::Error => {
// error state
for _ in 0..4 {
white_led.set_high();
Timer::after(Duration::from_millis(50)).await;
white_led.set_low();
Timer::after(Duration::from_millis(50)).await;
}
}

_ => {}
}
}
}

#[embassy_executor::task]
async fn temperature(
mut adc: adc::Adc<'static, adc::Async>,
Expand Down
3 changes: 3 additions & 0 deletions antani_sw/src/usb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ async fn usb_control<'d, T: Instance + 'd>(
mega_deserialization_buf.x.clear();

publisher.publish(command).await;
publisher.publish(crate::TaskCommand::UsbActivity).await;
}
Err(e) => match e.kind {
capnp::ErrorKind::MessageEndsPrematurely(_, _) => {
Expand All @@ -212,6 +213,8 @@ async fn usb_control<'d, T: Instance + 'd>(
e => {
error!("Error deserializing message: {:?}", e);

publisher.publish(crate::TaskCommand::Error).await;

mega_deserialization_buf.x.clear();
}
},
Expand Down

0 comments on commit 340101f

Please sign in to comment.