mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2026-04-30 18:49:09 +00:00
Compare commits
6 Commits
a63aacdc4e
...
db7e22f45d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db7e22f45d | ||
|
|
c91f290c31 | ||
| becdd43738 | |||
|
|
453b653ac5 | ||
| cc3605b75d | |||
| 57ccc0cc8b |
BIN
3d_print/printfiles/fw-anwesenheit-enclousure-top.3mf
Normal file
BIN
3d_print/printfiles/fw-anwesenheit-enclousure-top.3mf
Normal file
Binary file not shown.
@@ -49,7 +49,11 @@
|
|||||||
"conflict_shadows",
|
"conflict_shadows",
|
||||||
"shapes"
|
"shapes"
|
||||||
],
|
],
|
||||||
|
<<<<<<< HEAD
|
||||||
"visible_layers": "00000000_00000000_0fffffff_fffff8aa",
|
"visible_layers": "00000000_00000000_0fffffff_fffff8aa",
|
||||||
|
=======
|
||||||
|
"visible_layers": "00000000_00000000_0fffffff_fffff8ab",
|
||||||
|
>>>>>>> 15c64e4 (updated enclousure top 3mf)
|
||||||
"zone_display_mode": 0
|
"zone_display_mode": 0
|
||||||
},
|
},
|
||||||
"git": {
|
"git": {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use embassy_time::{Duration, Timer};
|
|||||||
use esp_hal::{Async, uart::Uart};
|
use esp_hal::{Async, uart::Uart};
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
|
|
||||||
use crate::TallyPublisher;
|
use crate::{TallyPublisher, store::TallyID};
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn rfid_reader_task(mut uart_device: Uart<'static, Async>, chan: TallyPublisher) {
|
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();
|
core::fmt::Write::write_fmt(&mut hex_str, format_args!("{:02X} ", byte)).ok();
|
||||||
}
|
}
|
||||||
info!("Read {n} bytes from UART: {hex_str}");
|
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) => {
|
Err(e) => {
|
||||||
log::error!("Error reading from UART: {e}");
|
log::error!("Error reading from UART: {e}");
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ use log::{debug, error, info};
|
|||||||
|
|
||||||
use crate::FEEDBACK_STATE;
|
use crate::FEEDBACK_STATE;
|
||||||
use crate::init::network;
|
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::init::wifi;
|
||||||
use crate::store::AttendanceDay;
|
use crate::store::AttendanceDay;
|
||||||
use crate::store::persistence::Persistence;
|
use crate::store::persistence::Persistence;
|
||||||
@@ -79,6 +79,7 @@ pub async fn hardware_init(
|
|||||||
SmartLedsAdapterAsync<ConstChannelAccess<esp_hal::rmt::Tx, 0>, LED_BUFFER_SIZE>,
|
SmartLedsAdapterAsync<ConstChannelAccess<esp_hal::rmt::Tx, 0>, LED_BUFFER_SIZE>,
|
||||||
GPIO21<'static>,
|
GPIO21<'static>,
|
||||||
GPIO0<'static>,
|
GPIO0<'static>,
|
||||||
|
SDCardPersistence,
|
||||||
) {
|
) {
|
||||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||||
let peripherals = esp_hal::init(config);
|
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 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(
|
let spi_bus = setup_spi(
|
||||||
peripherals.SPI2,
|
peripherals.SPI2,
|
||||||
@@ -119,7 +120,7 @@ pub async fn hardware_init(
|
|||||||
OutputConfig::default(),
|
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;
|
let buzzer_gpio = peripherals.GPIO21;
|
||||||
|
|
||||||
@@ -136,6 +137,7 @@ pub async fn hardware_init(
|
|||||||
led,
|
led,
|
||||||
buzzer_gpio,
|
buzzer_gpio,
|
||||||
sd_det_gpio,
|
sd_det_gpio,
|
||||||
|
vol_mgr,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,13 +42,16 @@ impl Persistence for SDCardPersistence {
|
|||||||
async fn load_day(&mut self, day: crate::store::Date) -> Option<AttendanceDay> {
|
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 vol_0 = self.vol_mgr.open_volume(VolumeIdx(0)).unwrap();
|
||||||
let mut root_dir = vol_0.open_root_dir().unwrap();
|
let mut root_dir = vol_0.open_root_dir().unwrap();
|
||||||
let mut file = root_dir
|
let mut file = root_dir.open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadOnly);
|
||||||
.open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadOnly)
|
|
||||||
.unwrap();
|
if let Err(e) = file {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let mut open_file = file.unwrap();
|
||||||
|
|
||||||
let mut read_buffer: [u8; 1024] = [0; 1024];
|
let mut read_buffer: [u8; 1024] = [0; 1024];
|
||||||
let read = file.read(&mut read_buffer).unwrap();
|
let read = open_file.read(&mut read_buffer).unwrap();
|
||||||
file.close().unwrap();
|
open_file.close().unwrap();
|
||||||
|
|
||||||
let day: AttendanceDay = serde_json::from_slice(&read_buffer[..read]).unwrap();
|
let day: AttendanceDay = serde_json::from_slice(&read_buffer[..read]).unwrap();
|
||||||
|
|
||||||
|
|||||||
30
src/main.rs
30
src/main.rs
@@ -20,7 +20,7 @@ use esp_hal::{gpio::InputConfig, peripherals};
|
|||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use static_cell::make_static;
|
use static_cell::make_static;
|
||||||
|
|
||||||
use crate::store::TallyID;
|
use crate::store::{IDStore, TallyID};
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ type TallyPublisher = Publisher<'static, NoopRawMutex, TallyID, 8, 2, 1>;
|
|||||||
|
|
||||||
#[esp_hal_embassy::main]
|
#[esp_hal_embassy::main]
|
||||||
async fn main(mut spawner: Spawner) {
|
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;
|
init::hardware::hardware_init(&mut spawner).await;
|
||||||
|
|
||||||
wait_for_stack_up(stack).await;
|
wait_for_stack_up(stack).await;
|
||||||
@@ -71,23 +71,29 @@ async fn main(mut spawner: Spawner) {
|
|||||||
debug!("everything spawned");
|
debug!("everything spawned");
|
||||||
FEEDBACK_STATE.signal(feedback::FeedbackState::Startup);
|
FEEDBACK_STATE.signal(feedback::FeedbackState::Startup);
|
||||||
|
|
||||||
loop {
|
let mut store = IDStore::new_from_storage(persistence_layer).await;
|
||||||
rtc.get_time().await;
|
|
||||||
info!("Current RTC time: {}", rtc.get_time().await);
|
|
||||||
Timer::after(Duration::from_millis(1000)).await;
|
|
||||||
|
|
||||||
// let wait_result = sub.next_message().await;
|
loop {
|
||||||
// match wait_result {
|
let wait_result = sub.next_message().await;
|
||||||
// Lagged(_) => debug!("Lagged"),
|
match wait_result {
|
||||||
// Message(msg) => debug!("Got message: {msg:?}"),
|
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]
|
#[embassy_executor::task]
|
||||||
async fn sd_detect_task(sd_det_gpio: peripherals::GPIO0<'static>) {
|
async fn sd_detect_task(sd_det_gpio: peripherals::GPIO0<'static>) {
|
||||||
let mut sd_det = Input::new(sd_det_gpio, InputConfig::default());
|
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 {
|
loop {
|
||||||
sd_det.wait_for_any_edge().await;
|
sd_det.wait_for_any_edge().await;
|
||||||
|
|||||||
@@ -41,10 +41,10 @@ pub struct IDStore<T: Persistence> {
|
|||||||
|
|
||||||
impl<T: Persistence> IDStore<T> {
|
impl<T: Persistence> IDStore<T> {
|
||||||
pub async fn new_from_storage(mut persistence_layer: T) -> Self {
|
pub async fn new_from_storage(mut persistence_layer: T) -> Self {
|
||||||
let mapping = match persistence_layer.load_mapping().await {
|
// let mapping = match persistence_layer.load_mapping().await {
|
||||||
Some(map) => map,
|
// Some(map) => map,
|
||||||
None => IDMapping::new(),
|
// None => IDMapping::new(),
|
||||||
};
|
// };
|
||||||
|
|
||||||
let current_date: Date = 1;
|
let current_date: Date = 1;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ impl<T: Persistence> IDStore<T> {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
current_day: day,
|
current_day: day,
|
||||||
mapping,
|
mapping: IDMapping::new(),
|
||||||
persistence_layer,
|
persistence_layer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user