mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-30 21:44:16 +00:00
implemented channel for TallyIDs
This commit is contained in:
parent
a97e9c8080
commit
23bb1126a6
@ -5,16 +5,28 @@
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::Stack;
|
||||
use embassy_sync::{
|
||||
blocking_mutex::raw::NoopRawMutex,
|
||||
pubsub::{
|
||||
PubSubChannel, Publisher,
|
||||
WaitResult::{Lagged, Message},
|
||||
},
|
||||
};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use esp_alloc::psram_allocator;
|
||||
use esp_hal::Async;
|
||||
use esp_hal::uart::Uart;
|
||||
use log::{debug, info};
|
||||
use static_cell::make_static;
|
||||
|
||||
use crate::webserver::start_webserver;
|
||||
use crate::{store::TallyID, webserver::start_webserver};
|
||||
|
||||
mod init;
|
||||
mod webserver;
|
||||
mod store;
|
||||
mod webserver;
|
||||
|
||||
type TallyChannel = PubSubChannel<NoopRawMutex, TallyID, 8, 2, 1>;
|
||||
type TallyPublisher = Publisher<'static, NoopRawMutex, TallyID, 8, 2, 1>;
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(mut spawner: Spawner) {
|
||||
@ -22,8 +34,22 @@ async fn main(mut spawner: Spawner) {
|
||||
|
||||
wait_for_stack_up(stack).await;
|
||||
|
||||
let chan: &'static mut TallyChannel = make_static!(PubSubChannel::new());
|
||||
|
||||
start_webserver(&mut spawner, stack);
|
||||
spawner.must_spawn(rfid_reader_task(uart_device));
|
||||
|
||||
let publisher = chan.publisher().unwrap();
|
||||
|
||||
spawner.must_spawn(rfid_reader_task(uart_device, publisher));
|
||||
|
||||
let mut sub = chan.subscriber().unwrap();
|
||||
loop {
|
||||
let wait_result = sub.next_message().await;
|
||||
match wait_result {
|
||||
Lagged(_) => debug!("Lagged"),
|
||||
Message(msg) => debug!("Got message: {msg:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn wait_for_stack_up(stack: Stack<'static>) {
|
||||
@ -40,7 +66,7 @@ async fn wait_for_stack_up(stack: Stack<'static>) {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn rfid_reader_task(mut uart_device: Uart<'static, Async>) {
|
||||
async fn rfid_reader_task(mut uart_device: Uart<'static, Async>, chan: TallyPublisher) {
|
||||
let mut uart_buffer = [0u8; 64];
|
||||
|
||||
loop {
|
||||
@ -52,6 +78,7 @@ async fn rfid_reader_task(mut uart_device: Uart<'static, Async>) {
|
||||
core::fmt::Write::write_fmt(&mut hex_str, format_args!("{:02X} ", byte)).ok();
|
||||
}
|
||||
info!("Read {n} bytes from UART: {hex_str}");
|
||||
chan.publish([1, 0, 2, 5, 0, 8, 12, 15]).await;
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Error reading from UART: {e}");
|
||||
|
Loading…
x
Reference in New Issue
Block a user