mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-08-22 16:04:18 +00:00
LED is working and implement in feedback
This commit is contained in:
parent
593d98df74
commit
3117c55b1c
@ -1,6 +1,11 @@
|
|||||||
use embassy_time::{Delay, Duration, Timer};
|
use embassy_time::{Delay, Duration, Timer};
|
||||||
use esp_hal::{delay, gpio::Output, peripherals};
|
use esp_hal::{delay, gpio::Output, peripherals, rmt::ConstChannelAccess};
|
||||||
|
use esp_hal_smartled::SmartLedsAdapterAsync;
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
|
use init::hardware;
|
||||||
|
use smart_leds::colors::{BLACK, GREEN, RED, YELLOW};
|
||||||
|
use smart_leds::{brightness, colors::BLUE};
|
||||||
|
use smart_leds::SmartLedsWriteAsync;
|
||||||
|
|
||||||
use crate::{FEEDBACK_STATE, init};
|
use crate::{FEEDBACK_STATE, init};
|
||||||
|
|
||||||
@ -10,23 +15,28 @@ pub enum FeedbackState {
|
|||||||
Nak,
|
Nak,
|
||||||
Error,
|
Error,
|
||||||
Startup,
|
Startup,
|
||||||
|
WIFI,
|
||||||
Idle,
|
Idle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LED_LEVEL: u8 = 255;
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn feedback_task(buzzer: peripherals::GPIO21<'static>) {
|
pub async fn feedback_task(mut led: SmartLedsAdapterAsync<ConstChannelAccess<esp_hal::rmt::Tx, 0>, { init::hardware::LED_BUFFER_SIZE }>, buzzer: peripherals::GPIO21<'static>) {
|
||||||
debug!("Starting feedback task");
|
debug!("Starting feedback task");
|
||||||
let mut buzzer = init::hardware::setup_buzzer(buzzer);
|
let mut buzzer = init::hardware::setup_buzzer(buzzer);
|
||||||
loop {
|
loop {
|
||||||
let feedback_state = FEEDBACK_STATE.wait().await;
|
let feedback_state = FEEDBACK_STATE.wait().await;
|
||||||
match feedback_state {
|
match feedback_state {
|
||||||
FeedbackState::Ack => {
|
FeedbackState::Ack => {
|
||||||
|
led.write(brightness([GREEN; init::hardware::NUM_LEDS].into_iter(), LED_LEVEL)).await.unwrap();
|
||||||
buzzer.set_high();
|
buzzer.set_high();
|
||||||
Timer::after(Duration::from_millis(100)).await;
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
buzzer.set_low();
|
buzzer.set_low();
|
||||||
Timer::after(Duration::from_millis(50)).await;
|
Timer::after(Duration::from_millis(50)).await;
|
||||||
}
|
}
|
||||||
FeedbackState::Nak => {
|
FeedbackState::Nak => {
|
||||||
|
led.write(brightness([YELLOW; init::hardware::NUM_LEDS].into_iter(), LED_LEVEL)).await.unwrap();
|
||||||
buzzer.set_high();
|
buzzer.set_high();
|
||||||
Timer::after(Duration::from_millis(100)).await;
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
buzzer.set_low();
|
buzzer.set_low();
|
||||||
@ -34,8 +44,10 @@ pub async fn feedback_task(buzzer: peripherals::GPIO21<'static>) {
|
|||||||
buzzer.set_high();
|
buzzer.set_high();
|
||||||
Timer::after(Duration::from_millis(100)).await;
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
buzzer.set_low();
|
buzzer.set_low();
|
||||||
|
led.write(brightness([BLACK; init::hardware::NUM_LEDS].into_iter(), LED_LEVEL)).await.unwrap();
|
||||||
}
|
}
|
||||||
FeedbackState::Error => {
|
FeedbackState::Error => {
|
||||||
|
led.write(brightness([RED; init::hardware::NUM_LEDS].into_iter(), LED_LEVEL)).await.unwrap();
|
||||||
buzzer.set_high();
|
buzzer.set_high();
|
||||||
Timer::after(Duration::from_millis(500)).await;
|
Timer::after(Duration::from_millis(500)).await;
|
||||||
buzzer.set_low();
|
buzzer.set_low();
|
||||||
@ -45,6 +57,7 @@ pub async fn feedback_task(buzzer: peripherals::GPIO21<'static>) {
|
|||||||
buzzer.set_low();
|
buzzer.set_low();
|
||||||
}
|
}
|
||||||
FeedbackState::Startup => {
|
FeedbackState::Startup => {
|
||||||
|
led.write(brightness([GREEN; init::hardware::NUM_LEDS].into_iter(), LED_LEVEL)).await.unwrap();
|
||||||
buzzer.set_high();
|
buzzer.set_high();
|
||||||
Timer::after(Duration::from_millis(10)).await;
|
Timer::after(Duration::from_millis(10)).await;
|
||||||
buzzer.set_low();
|
buzzer.set_low();
|
||||||
@ -56,6 +69,10 @@ pub async fn feedback_task(buzzer: peripherals::GPIO21<'static>) {
|
|||||||
buzzer.set_high();
|
buzzer.set_high();
|
||||||
Timer::after(Duration::from_millis(100)).await;
|
Timer::after(Duration::from_millis(100)).await;
|
||||||
buzzer.set_low();
|
buzzer.set_low();
|
||||||
|
led.write(brightness([BLACK; init::hardware::NUM_LEDS].into_iter(), LED_LEVEL)).await.unwrap();
|
||||||
|
}
|
||||||
|
FeedbackState::WIFI => {
|
||||||
|
led.write(brightness([BLUE; init::hardware::NUM_LEDS].into_iter(), LED_LEVEL)).await.unwrap();
|
||||||
}
|
}
|
||||||
FeedbackState::Idle => {
|
FeedbackState::Idle => {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
@ -65,6 +82,7 @@ pub async fn feedback_task(buzzer: peripherals::GPIO21<'static>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// async fn beep_ack() {
|
// async fn beep_ack() {
|
||||||
// buzzer.set_high();
|
// buzzer.set_high();
|
||||||
// buzzer.set_low();
|
// buzzer.set_low();
|
||||||
|
@ -55,8 +55,8 @@ use crate::init::wifi;
|
|||||||
*
|
*
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
const NUM_LEDS: usize = 66;
|
pub const NUM_LEDS: usize = 66;
|
||||||
const LED_BUFFER_SIZE: usize = NUM_LEDS * 25;
|
pub const LED_BUFFER_SIZE: usize = NUM_LEDS * 25;
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &core::panic::PanicInfo) -> ! {
|
fn panic(info: &core::panic::PanicInfo) -> ! {
|
||||||
@ -116,10 +116,6 @@ pub async fn hardware_init(
|
|||||||
|
|
||||||
debug!("hardware init done");
|
debug!("hardware init done");
|
||||||
|
|
||||||
let level = 255;
|
|
||||||
|
|
||||||
led.write(brightness([BLUE; NUM_LEDS].into_iter(), level)).await.unwrap();
|
|
||||||
|
|
||||||
(uart_device, stack, i2c_device, led, buzzer_gpio)
|
(uart_device, stack, i2c_device, led, buzzer_gpio)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ async fn main(mut spawner: Spawner) {
|
|||||||
));
|
));
|
||||||
|
|
||||||
debug!("spawing feedback task..");
|
debug!("spawing feedback task..");
|
||||||
spawner.must_spawn(feedback::feedback_task(buzzer_gpio));
|
spawner.must_spawn(feedback::feedback_task(_led, buzzer_gpio));
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
let mut sub = chan.subscriber().unwrap();
|
let mut sub = chan.subscriber().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user