mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-10-13 15:06:39 +00:00
fixed many warning by removing unused imports
Removed a lot of imports — believe me, so many imports were totally unnecessary. Nobody’s seen imports like these. Cleaned up the code, made it faster, smarter, the best code. People are talking about it! Tremendous work by me. Some say i am the best at it. It may be true.
This commit is contained in:
parent
9dd2f88cbc
commit
0f5ca88ae4
@ -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, store::TallyID};
|
use crate::TallyPublisher;
|
||||||
|
|
||||||
#[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) {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use chrono::{TimeZone, Utc};
|
||||||
use ds3231::{
|
use ds3231::{
|
||||||
Config, DS3231, DS3231Error, InterruptControl, Oscillator, SquareWaveFrequency,
|
Config, DS3231, DS3231Error, InterruptControl, Oscillator, SquareWaveFrequency,
|
||||||
TimeRepresentation,
|
TimeRepresentation,
|
||||||
@ -9,7 +10,6 @@ use esp_hal::{
|
|||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
|
|
||||||
use crate::{FEEDBACK_STATE, drivers, feedback, store::Date};
|
use crate::{FEEDBACK_STATE, drivers, feedback, store::Date};
|
||||||
use chrono::{TimeZone, Utc};
|
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/build_time.rs"));
|
include!(concat!(env!("OUT_DIR"), "/build_time.rs"));
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ impl RTCClock {
|
|||||||
pub async fn get_date(&mut self) -> Date {
|
pub async fn get_date(&mut self) -> Date {
|
||||||
let (year, month, day) = unix_to_ymd_string(self.get_time().await);
|
let (year, month, day) = unix_to_ymd_string(self.get_time().await);
|
||||||
|
|
||||||
let mut buffer: Date = [0; 10] ;
|
let mut buffer: Date = [0; 10];
|
||||||
|
|
||||||
// Write YYYY
|
// Write YYYY
|
||||||
buffer[0] = b'0' + ((year / 1000) % 10) as u8;
|
buffer[0] = b'0' + ((year / 1000) % 10) as u8;
|
||||||
@ -70,35 +70,34 @@ impl RTCClock {
|
|||||||
|
|
||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unix_to_ymd_string(timestamp: u64) -> (u16, u8, u8) {
|
fn unix_to_ymd_string(timestamp: u64) -> (u16, u8, u8) {
|
||||||
// Apply UTC+1 offset
|
// Apply UTC+1 offset
|
||||||
let ts = timestamp + UTC_PLUS_ONE;
|
let ts = timestamp + UTC_PLUS_ONE;
|
||||||
|
|
||||||
// Convert to total days since UNIX epoch
|
// Convert to total days since UNIX epoch
|
||||||
let days_since_epoch = ts / SECS_PER_DAY;
|
let days_since_epoch = ts / SECS_PER_DAY;
|
||||||
|
|
||||||
// Convert to proleptic Gregorian date
|
// Convert to proleptic Gregorian date
|
||||||
civil_from_days(days_since_epoch as i64 + UNIX_OFFSET_DAYS as i64)
|
civil_from_days(days_since_epoch as i64 + UNIX_OFFSET_DAYS as i64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function returns (year, month, day).
|
// This function returns (year, month, day).
|
||||||
// Based on the algorithm by Howard Hinnant.
|
// Based on the algorithm by Howard Hinnant.
|
||||||
fn civil_from_days(z: i64) -> (u16, u8, u8) {
|
fn civil_from_days(z: i64) -> (u16, u8, u8) {
|
||||||
let mut z = z;
|
let mut z = z;
|
||||||
z -= 60; // shift epoch for algorithm
|
z -= 60; // shift epoch for algorithm
|
||||||
let era = (z >= 0).then_some(z).unwrap_or(z - 146096) / 146097;
|
let era = (z >= 0).then_some(z).unwrap_or(z - 146096) / 146097;
|
||||||
let doe = z - era * 146097; // [0, 146096]
|
let doe = z - era * 146097; // [0, 146096]
|
||||||
let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; // [0, 399]
|
let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; // [0, 399]
|
||||||
let y = yoe + era * 400;
|
let y = yoe + era * 400;
|
||||||
let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); // [0, 365]
|
let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); // [0, 365]
|
||||||
let mp = (5 * doy + 2) / 153; // [0, 11]
|
let mp = (5 * doy + 2) / 153; // [0, 11]
|
||||||
let d = doy - (153 * mp + 2) / 5 + 1; // [1, 31]
|
let d = doy - (153 * mp + 2) / 5 + 1; // [1, 31]
|
||||||
let m = mp + (if mp < 10 { 3 } else { -9 }); // [1, 12]
|
let m = mp + (if mp < 10 { 3 } else { -9 }); // [1, 12]
|
||||||
((y + (m <= 2) as i64) as u16, m as u8, d as u8)
|
((y + (m <= 2) as i64) as u16, m as u8, d as u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn rtc_config(i2c: I2c<'static, Async>) -> DS3231<I2c<'static, Async>> {
|
pub async fn rtc_config(i2c: I2c<'static, Async>) -> DS3231<I2c<'static, Async>> {
|
||||||
let mut rtc: DS3231<I2c<'static, Async>> = DS3231::new(i2c, RTC_ADDRESS);
|
let mut rtc: DS3231<I2c<'static, Async>> = DS3231::new(i2c, RTC_ADDRESS);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use embassy_time::{Delay, Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use esp_hal::{delay, gpio::Output, peripherals, rmt::ConstChannelAccess};
|
use esp_hal::{peripherals, rmt::ConstChannelAccess};
|
||||||
use esp_hal_smartled::SmartLedsAdapterAsync;
|
use esp_hal_smartled::SmartLedsAdapterAsync;
|
||||||
use init::hardware;
|
use log::debug;
|
||||||
use log::{debug, error, info};
|
|
||||||
use smart_leds::SmartLedsWriteAsync;
|
use smart_leds::SmartLedsWriteAsync;
|
||||||
use smart_leds::colors::{BLACK, GREEN, RED, YELLOW};
|
use smart_leds::colors::{BLACK, GREEN, RED, YELLOW};
|
||||||
use smart_leds::{brightness, colors::BLUE};
|
use smart_leds::{brightness, colors::BLUE};
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
|
||||||
use bleps::att::Att;
|
|
||||||
use critical_section::Mutex;
|
use critical_section::Mutex;
|
||||||
use ds3231::InterruptControl;
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_net::Stack;
|
use embassy_net::Stack;
|
||||||
|
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use esp_hal::gpio::{Input, InputConfig};
|
use esp_hal::Blocking;
|
||||||
|
use esp_hal::gpio::Input;
|
||||||
use esp_hal::i2c::master::Config;
|
use esp_hal::i2c::master::Config;
|
||||||
use esp_hal::peripherals::{
|
use esp_hal::peripherals::{
|
||||||
GPIO0, GPIO1, GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23, I2C0, RMT, SPI2,
|
GPIO0, GPIO1, GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23, I2C0, RMT, SPI2,
|
||||||
@ -15,8 +12,6 @@ use esp_hal::peripherals::{
|
|||||||
};
|
};
|
||||||
use esp_hal::rmt::{ConstChannelAccess, Rmt};
|
use esp_hal::rmt::{ConstChannelAccess, Rmt};
|
||||||
use esp_hal::spi::master::{Config as Spi_config, Spi};
|
use esp_hal::spi::master::{Config as Spi_config, Spi};
|
||||||
|
|
||||||
use esp_hal::Blocking;
|
|
||||||
use esp_hal::time::Rate;
|
use esp_hal::time::Rate;
|
||||||
use esp_hal::timer::timg::TimerGroup;
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
use esp_hal::{
|
use esp_hal::{
|
||||||
@ -28,16 +23,12 @@ use esp_hal::{
|
|||||||
uart::Uart,
|
uart::Uart,
|
||||||
};
|
};
|
||||||
use esp_hal_smartled::{SmartLedsAdapterAsync, buffer_size_async};
|
use esp_hal_smartled::{SmartLedsAdapterAsync, buffer_size_async};
|
||||||
use esp_println::dbg;
|
|
||||||
use esp_println::logger::init_logger;
|
use esp_println::logger::init_logger;
|
||||||
use log::{debug, error, info};
|
use log::{debug, error};
|
||||||
|
|
||||||
use crate::FEEDBACK_STATE;
|
|
||||||
use crate::init::network;
|
use crate::init::network;
|
||||||
use crate::init::sd_card::{setup_sdcard, SDCardPersistence};
|
use crate::init::sd_card::{SDCardPersistence, setup_sdcard};
|
||||||
use crate::init::wifi;
|
use crate::init::wifi;
|
||||||
use crate::store::AttendanceDay;
|
|
||||||
use crate::store::persistence::Persistence;
|
|
||||||
|
|
||||||
/*************************************************
|
/*************************************************
|
||||||
* GPIO Pinout Xiao Esp32c6
|
* GPIO Pinout Xiao Esp32c6
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use core::{net::Ipv4Addr, str::FromStr};
|
use core::{net::Ipv4Addr, str::FromStr};
|
||||||
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_net::{Ipv4Cidr, Runner, Stack, StackResources, StaticConfigV4};
|
use embassy_net::{Ipv4Cidr, Runner, Stack, StackResources, StaticConfigV4};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
|
@ -21,14 +21,14 @@ use esp_hal::{gpio::InputConfig, peripherals};
|
|||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use static_cell::make_static;
|
use static_cell::make_static;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
init::sd_card::SDCardPersistence,
|
init::sd_card::SDCardPersistence,
|
||||||
store::{Date, IDStore, TallyID},
|
store::{Date, IDStore, TallyID},
|
||||||
webserver::start_webserver,
|
webserver::start_webserver,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern crate alloc;
|
|
||||||
|
|
||||||
mod drivers;
|
mod drivers;
|
||||||
mod feedback;
|
mod feedback;
|
||||||
mod init;
|
mod init;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use super::TallyID;
|
|
||||||
use alloc::collections::BTreeMap;
|
use alloc::collections::BTreeMap;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use super::TallyID;
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct Name {
|
pub struct Name {
|
||||||
pub first: String,
|
pub first: String,
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use crate::drivers::rtc;
|
use alloc::vec::Vec;
|
||||||
use crate::drivers::rtc::RTCClock;
|
use serde::Deserialize;
|
||||||
use crate::store::persistence::Persistence;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::Date;
|
use super::Date;
|
||||||
use super::IDMapping;
|
use super::IDMapping;
|
||||||
use super::TallyID;
|
use super::TallyID;
|
||||||
use alloc::vec::Vec;
|
use crate::store::persistence::Persistence;
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize, Debug)]
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||||
pub struct AttendanceDay {
|
pub struct AttendanceDay {
|
||||||
@ -16,7 +14,7 @@ pub struct AttendanceDay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AttendanceDay {
|
impl AttendanceDay {
|
||||||
pub fn new(date: Date) -> Self {
|
pub fn new(date: Date) -> Self {
|
||||||
Self {
|
Self {
|
||||||
date,
|
date,
|
||||||
ids: Vec::new(),
|
ids: Vec::new(),
|
||||||
@ -47,7 +45,7 @@ impl<T: Persistence> IDStore<T> {
|
|||||||
// Some(map) => map,
|
// Some(map) => map,
|
||||||
// None => IDMapping::new(),
|
// None => IDMapping::new(),
|
||||||
// };
|
// };
|
||||||
|
|
||||||
let current_date: Date = [0; 10];
|
let current_date: Date = [0; 10];
|
||||||
|
|
||||||
let day = persistence_layer
|
let day = persistence_layer
|
||||||
@ -75,7 +73,6 @@ impl<T: Persistence> IDStore<T> {
|
|||||||
/// Add a new id for the current day
|
/// Add a new id for the current day
|
||||||
/// Returns false if ID is already present at the current day.
|
/// Returns false if ID is already present at the current day.
|
||||||
pub async fn add_id(&mut self, id: TallyID, current_date: Date) -> bool {
|
pub async fn add_id(&mut self, id: TallyID, current_date: Date) -> bool {
|
||||||
|
|
||||||
if self.current_day.date == current_date {
|
if self.current_day.date == current_date {
|
||||||
let changed = self.current_day.add_id(id);
|
let changed = self.current_day.add_id(id);
|
||||||
if changed {
|
if changed {
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
|
use heapless::String;
|
||||||
|
|
||||||
|
pub use id_mapping::{IDMapping, Name};
|
||||||
|
pub use id_store::{IDStore,AttendanceDay};
|
||||||
|
|
||||||
mod id_mapping;
|
mod id_mapping;
|
||||||
pub mod persistence;
|
pub mod persistence;
|
||||||
mod id_store;
|
mod id_store;
|
||||||
|
|
||||||
use heapless::String;
|
|
||||||
pub use id_mapping::{IDMapping, Name};
|
|
||||||
pub use id_store::{IDStore,AttendanceDay};
|
|
||||||
|
|
||||||
pub type TallyID = [u8; 6];
|
pub type TallyID = [u8; 6];
|
||||||
pub type Date = [u8; 10];
|
pub type Date = [u8; 10];
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ use picoserve::{
|
|||||||
response::{self, IntoResponse},
|
response::{self, IntoResponse},
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
store::{Name, hex_string_to_tally_id},
|
store::{Name, hex_string_to_tally_id},
|
||||||
webserver::{app::AppState, sse::IDEvents},
|
webserver::{app::AppState, sse::IDEvents},
|
||||||
@ -40,6 +41,6 @@ pub async fn add_mapping(
|
|||||||
store.mapping.add_mapping(tally_id, data.name);
|
store.mapping.add_mapping(tally_id, data.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_idevent(State(state): State<AppState>) -> impl IntoResponse{
|
pub async fn get_idevent(State(state): State<AppState>) -> impl IntoResponse {
|
||||||
response::EventStream(IDEvents(state.chan.subscriber().unwrap()))
|
response::EventStream(IDEvents(state.chan.subscriber().unwrap()))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user