bugfixes and performance improvements
switched try me button to a different pin after the joint failed and added a 8 ms debounce set a timeout on music reads to fix system failure on partial hardware failure
This commit is contained in:
parent
46527362d7
commit
43fedd11bf
3 changed files with 20 additions and 7 deletions
|
@ -37,7 +37,7 @@ use embassy_net::{Config, IpEndpoint, Ipv4Address, StackResources};
|
|||
use embassy_rp::{bind_interrupts, interrupt};
|
||||
use embassy_rp::clocks::RoscRng;
|
||||
use embassy_rp::gpio::{AnyPin, Input, InterruptTrigger, Level, Output};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIN_22, PIO0, UART1, USB};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIN_22, PIN_4, PIO0, UART1, USB};
|
||||
use embassy_rp::pio::{InterruptHandler, Pio};
|
||||
use embassy_rp::usb::Driver;
|
||||
use embassy_time::{Timer};
|
||||
|
@ -141,17 +141,22 @@ async fn main(spawner: Spawner) {
|
|||
spawner.spawn(data_extractor()).unwrap();
|
||||
spawn_poller(p.CORE1, p.PIN_17, p.PIN_16);
|
||||
spawner.spawn(send_badge(CHANNEL.receiver(),stack)).unwrap();
|
||||
spawner.spawn(button_manager(p.PIN_22)).unwrap();
|
||||
spawner.spawn(button_manager(p.PIN_4)).unwrap();
|
||||
spawner.spawn(wiggle_manager(p.PWM_SLICE5, p.PIN_26, p.PIN_27)).unwrap();
|
||||
spawner.spawn(server_task(stack)).unwrap();
|
||||
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn button_manager(pin: PIN_22) -> ! {
|
||||
async fn button_manager(pin: PIN_4) -> ! {
|
||||
let mut button = Input::new(pin, embassy_rp::gpio::Pull::Up);
|
||||
loop {
|
||||
button.wait_for_rising_edge().await;
|
||||
Timer::after_millis(8).await;
|
||||
if button.is_low() {
|
||||
continue;
|
||||
}
|
||||
|
||||
COMMANDS.send(music::MusicCommand::Button()).await;
|
||||
Timer::after_millis(800).await;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,10 @@ use embassy_rp::clocks::RoscRng;
|
|||
use embassy_rp::uart;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::channel::Channel;
|
||||
use embassy_time::Duration;
|
||||
use embassy_time::Instant;
|
||||
use embassy_time::Timer;
|
||||
use embassy_time::WithTimeout;
|
||||
use embedded_io_async::Read;
|
||||
use embedded_io_async::Write;
|
||||
use rand::RngCore;
|
||||
|
@ -163,7 +166,7 @@ async fn play_song<'a>(prefix: &str, index: Option<u8>, uart: &mut BufferedUart<
|
|||
info!("len: {}", output.trim());
|
||||
|
||||
if let Ok(length) = output.trim().parse::<u64>() {
|
||||
//WAGS.store((length as u8) * 2 + 1, core::sync::atomic::Ordering::SeqCst);
|
||||
WAGS.store((length as u8) * 2 + 1, core::sync::atomic::Ordering::SeqCst);
|
||||
Timer::after_secs(length.max(1)).await;
|
||||
} else {
|
||||
Timer::after_secs(1).await;
|
||||
|
@ -173,8 +176,9 @@ async fn play_song<'a>(prefix: &str, index: Option<u8>, uart: &mut BufferedUart<
|
|||
|
||||
async fn read_line<'a, 'b>(buffer: &'b mut [u8], uart: &mut BufferedUart<'a, UART1>) -> &'b str {
|
||||
let mut pos = 0;
|
||||
let start = Instant::now();
|
||||
loop {
|
||||
if let Ok(len) = uart.read(&mut buffer[pos..]).await {
|
||||
if let Ok(Ok(len)) = uart.read(&mut buffer[pos..]).with_timeout(Duration::from_millis(150)).await {
|
||||
let to_print = unsafe { core::str::from_utf8_unchecked(&buffer[..(pos + len)]) };
|
||||
|
||||
if to_print.contains("\r\n") {
|
||||
|
@ -183,6 +187,10 @@ async fn read_line<'a, 'b>(buffer: &'b mut [u8], uart: &mut BufferedUart<'a, UAR
|
|||
break;
|
||||
}
|
||||
|
||||
if start.elapsed().as_millis() > 800 {
|
||||
break;
|
||||
}
|
||||
|
||||
pos += len;
|
||||
} else {
|
||||
break;
|
||||
|
|
|
@ -38,7 +38,7 @@ pub async fn wiggle_manager(pwm: PWM_SLICE5, head: PIN_26, tail: PIN_27) -> ! {
|
|||
break;
|
||||
}
|
||||
|
||||
c.compare_b = 6248;
|
||||
c.compare_a = 6248;
|
||||
pwm.set_config(&c);
|
||||
|
||||
Timer::after_millis(500).await;
|
||||
|
@ -51,7 +51,7 @@ pub async fn wiggle_manager(pwm: PWM_SLICE5, head: PIN_26, tail: PIN_27) -> ! {
|
|||
for _ in 0..wags {
|
||||
|
||||
let idx = rng.next_u32();
|
||||
c.compare_b = positions[idx as usize % positions.len()];
|
||||
c.compare_a = positions[idx as usize % positions.len()];
|
||||
pwm.set_config(&c);
|
||||
|
||||
Timer::after_millis(idx as u64 % 600).await;
|
||||
|
|
Loading…
Reference in a new issue