mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-02 01:04:16 +00:00
moved TallyID into it's own file
Tally id now ignores tha case since it's basicly a hex value as a string. Reason for that is that if a user inputs an id.
This commit is contained in:
parent
b6b66a7e5b
commit
47f19f3c54
@ -2,19 +2,10 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
error::Error,
|
error::Error,
|
||||||
fmt::Display,
|
|
||||||
};
|
};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
|
|
||||||
/// Represents the ID that is stored on the Tally
|
use crate::tally_id::TallyID;
|
||||||
#[derive(PartialEq, Eq, Deserialize, Serialize, Hash, Clone, PartialOrd, Ord)]
|
|
||||||
pub struct TallyID(pub String);
|
|
||||||
|
|
||||||
impl Display for TallyID {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Represents a single day that IDs can attend
|
/// Represents a single day that IDs can attend
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use buzzer::GPIOBuzzer;
|
use buzzer::GPIOBuzzer;
|
||||||
use id_store::{IDStore, TallyID};
|
use id_store::IDStore;
|
||||||
use led::Led;
|
use led::Led;
|
||||||
use log::{LevelFilter, debug, error, info, warn};
|
use log::{LevelFilter, debug, error, info, warn};
|
||||||
use pm3::run_pm3;
|
use pm3::run_pm3;
|
||||||
use rppal::pwm::Channel;
|
use rppal::pwm::Channel;
|
||||||
use simplelog::{ConfigBuilder, SimpleLogger};
|
use simplelog::{ConfigBuilder, SimpleLogger};
|
||||||
use std::{env, error::Error, sync::Arc};
|
use std::{env, error::Error, sync::Arc};
|
||||||
|
use tally_id::TallyID;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs,
|
fs,
|
||||||
sync::{Mutex, mpsc},
|
sync::{Mutex, mpsc},
|
||||||
@ -19,6 +20,7 @@ mod id_store;
|
|||||||
mod led;
|
mod led;
|
||||||
mod parser;
|
mod parser;
|
||||||
mod pm3;
|
mod pm3;
|
||||||
|
mod tally_id;
|
||||||
mod webserver;
|
mod webserver;
|
||||||
|
|
||||||
const STORE_PATH: &str = "./data.json";
|
const STORE_PATH: &str = "./data.json";
|
||||||
@ -92,7 +94,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let channel_store = store.clone();
|
let channel_store = store.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(tally_id_string) = rx.recv().await {
|
while let Some(tally_id_string) = rx.recv().await {
|
||||||
let tally_id = id_store::TallyID(tally_id_string);
|
let tally_id = TallyID(tally_id_string);
|
||||||
|
|
||||||
if hotspot_ids.contains(&tally_id) {
|
if hotspot_ids.contains(&tally_id) {
|
||||||
info!("Enableing hotspot");
|
info!("Enableing hotspot");
|
||||||
|
45
src/tally_id.rs
Normal file
45
src/tally_id.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use std::{
|
||||||
|
cmp::Ordering,
|
||||||
|
fmt::Display,
|
||||||
|
hash::{Hash, Hasher},
|
||||||
|
};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Represents the ID that is stored on the Tally
|
||||||
|
/// Is case-insensitive.
|
||||||
|
/// While any string can be a ID, most IDs are going to be a hex string.
|
||||||
|
#[derive(Deserialize, Serialize, Clone)]
|
||||||
|
pub struct TallyID(pub String);
|
||||||
|
|
||||||
|
impl PartialEq for TallyID {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.0.eq_ignore_ascii_case(&other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Hash for TallyID {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.0.to_uppercase().hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Eq for TallyID {}
|
||||||
|
|
||||||
|
impl Ord for TallyID {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
self.0.to_uppercase().cmp(&other.0.to_uppercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for TallyID {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for TallyID {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.0.to_uppercase())
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user