Compare commits

...

6 Commits

Author SHA1 Message Date
Philipp_EndevourOS
db7e22f45d new file will be created when sd card is empty 2025-10-01 18:58:08 +02:00
Philipp_EndevourOS
c91f290c31 removed dummy data and pass read tally id 2025-10-01 18:56:37 +02:00
becdd43738 connect RFID reader with IDStore 2025-10-01 18:00:45 +02:00
Philipp
453b653ac5 updated enclousure top 3mf 2025-10-01 17:56:30 +02:00
cc3605b75d return sdcard from hardware init 2025-10-01 17:54:54 +02:00
57ccc0cc8b fixed missing await 2025-10-01 17:51:51 +02:00
7 changed files with 42 additions and 27 deletions

Binary file not shown.

View File

@@ -49,7 +49,11 @@
"conflict_shadows",
"shapes"
],
<<<<<<< HEAD
"visible_layers": "00000000_00000000_0fffffff_fffff8aa",
=======
"visible_layers": "00000000_00000000_0fffffff_fffff8ab",
>>>>>>> 15c64e4 (updated enclousure top 3mf)
"zone_display_mode": 0
},
"git": {

View File

@@ -2,7 +2,7 @@ use embassy_time::{Duration, Timer};
use esp_hal::{Async, uart::Uart};
use log::{debug, info};
use crate::TallyPublisher;
use crate::{TallyPublisher, store::TallyID};
#[embassy_executor::task]
pub async fn rfid_reader_task(mut uart_device: Uart<'static, Async>, chan: TallyPublisher) {
@@ -17,7 +17,7 @@ pub async fn rfid_reader_task(mut uart_device: Uart<'static, Async>, chan: Tally
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;
chan.publish(uart_buffer[..8].try_into().unwrap()).await;
}
Err(e) => {
log::error!("Error reading from UART: {e}");

View File

@@ -34,7 +34,7 @@ use log::{debug, error, info};
use crate::FEEDBACK_STATE;
use crate::init::network;
use crate::init::sd_card::setup_sdcard;
use crate::init::sd_card::{setup_sdcard, SDCardPersistence};
use crate::init::wifi;
use crate::store::AttendanceDay;
use crate::store::persistence::Persistence;
@@ -79,6 +79,7 @@ pub async fn hardware_init(
SmartLedsAdapterAsync<ConstChannelAccess<esp_hal::rmt::Tx, 0>, LED_BUFFER_SIZE>,
GPIO21<'static>,
GPIO0<'static>,
SDCardPersistence,
) {
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
@@ -104,7 +105,7 @@ pub async fn hardware_init(
let i2c_device = setup_i2c(peripherals.I2C0, peripherals.GPIO22, peripherals.GPIO23);
let mut sd_det_gpio = peripherals.GPIO0;
let sd_det_gpio = peripherals.GPIO0;
let spi_bus = setup_spi(
peripherals.SPI2,
@@ -119,7 +120,7 @@ pub async fn hardware_init(
OutputConfig::default(),
);
let mut vol_mgr = setup_sdcard(spi_bus, sd_cs_pin);
let vol_mgr = setup_sdcard(spi_bus, sd_cs_pin);
let buzzer_gpio = peripherals.GPIO21;
@@ -136,6 +137,7 @@ pub async fn hardware_init(
led,
buzzer_gpio,
sd_det_gpio,
vol_mgr,
)
}

View File

@@ -42,13 +42,16 @@ impl Persistence for SDCardPersistence {
async fn load_day(&mut self, day: crate::store::Date) -> Option<AttendanceDay> {
let mut vol_0 = self.vol_mgr.open_volume(VolumeIdx(0)).unwrap();
let mut root_dir = vol_0.open_root_dir().unwrap();
let mut file = root_dir
.open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadOnly)
.unwrap();
let mut file = root_dir.open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadOnly);
if let Err(e) = file {
return None;
}
let mut open_file = file.unwrap();
let mut read_buffer: [u8; 1024] = [0; 1024];
let read = file.read(&mut read_buffer).unwrap();
file.close().unwrap();
let read = open_file.read(&mut read_buffer).unwrap();
open_file.close().unwrap();
let day: AttendanceDay = serde_json::from_slice(&read_buffer[..read]).unwrap();

View File

@@ -20,7 +20,7 @@ use esp_hal::{gpio::InputConfig, peripherals};
use log::{debug, info};
use static_cell::make_static;
use crate::store::TallyID;
use crate::store::{IDStore, TallyID};
extern crate alloc;
@@ -37,7 +37,7 @@ type TallyPublisher = Publisher<'static, NoopRawMutex, TallyID, 8, 2, 1>;
#[esp_hal_embassy::main]
async fn main(mut spawner: Spawner) {
let (uart_device, stack, _i2c, _led, buzzer_gpio, sd_det_gpio) =
let (uart_device, stack, _i2c, _led, buzzer_gpio, sd_det_gpio, persistence_layer) =
init::hardware::hardware_init(&mut spawner).await;
wait_for_stack_up(stack).await;
@@ -71,23 +71,29 @@ async fn main(mut spawner: Spawner) {
debug!("everything spawned");
FEEDBACK_STATE.signal(feedback::FeedbackState::Startup);
loop {
rtc.get_time().await;
info!("Current RTC time: {}", rtc.get_time().await);
Timer::after(Duration::from_millis(1000)).await;
let mut store = IDStore::new_from_storage(persistence_layer).await;
// let wait_result = sub.next_message().await;
// match wait_result {
// Lagged(_) => debug!("Lagged"),
// Message(msg) => debug!("Got message: {msg:?}"),
// }
loop {
let wait_result = sub.next_message().await;
match wait_result {
Lagged(_) => debug!("Lagged"),
Message(msg) => {
debug!("Got message: {msg:?}");
let added = store.add_id(msg).await;
if added {
FEEDBACK_STATE.signal(feedback::FeedbackState::Ack);
}
}
}
}
}
#[embassy_executor::task]
async fn sd_detect_task(sd_det_gpio: peripherals::GPIO0<'static>) {
let mut sd_det = Input::new(sd_det_gpio, InputConfig::default());
sd_det.wait_for(esp_hal::gpio::Event::AnyEdge);
sd_det.wait_for(esp_hal::gpio::Event::AnyEdge).await;
loop {
sd_det.wait_for_any_edge().await;

View File

@@ -41,10 +41,10 @@ pub struct IDStore<T: Persistence> {
impl<T: Persistence> IDStore<T> {
pub async fn new_from_storage(mut persistence_layer: T) -> Self {
let mapping = match persistence_layer.load_mapping().await {
Some(map) => map,
None => IDMapping::new(),
};
// let mapping = match persistence_layer.load_mapping().await {
// Some(map) => map,
// None => IDMapping::new(),
// };
let current_date: Date = 1;
@@ -55,7 +55,7 @@ impl<T: Persistence> IDStore<T> {
Self {
current_day: day,
mapping,
mapping: IDMapping::new(),
persistence_layer,
}
}