mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-03 01:24:17 +00:00
workday ending
This commit is contained in:
parent
d18b967f39
commit
880e8f24a7
@ -1,7 +1,7 @@
|
|||||||
use rppal::gpio::Gpio;
|
use rppal::gpio::Gpio;
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
/// Gibt einen Ton auf einem passiven Buzzer aus.
|
/// Emits a sound on a passive buzzer.
|
||||||
pub fn modulated_tone(pin_num: u8, carrier_hz: u32, sound_hz: u32, duration_ms: u64) {
|
pub fn modulated_tone(pin_num: u8, carrier_hz: u32, sound_hz: u32, duration_ms: u64) {
|
||||||
let gpio = Gpio::new().expect("GPIO konnte nicht initialisiert werden");
|
let gpio = Gpio::new().expect("GPIO konnte nicht initialisiert werden");
|
||||||
let mut pin = gpio.get(pin_num).expect("Pin konnte nicht geöffnet werden").into_output();
|
let mut pin = gpio.get(pin_num).expect("Pin konnte nicht geöffnet werden").into_output();
|
||||||
@ -11,7 +11,7 @@ pub fn modulated_tone(pin_num: u8, carrier_hz: u32, sound_hz: u32, duration_ms:
|
|||||||
let total_cycles = duration_ms as f64 / mod_period;
|
let total_cycles = duration_ms as f64 / mod_period;
|
||||||
|
|
||||||
for _ in 0..total_cycles as u64 {
|
for _ in 0..total_cycles as u64 {
|
||||||
// Modulations-Ein: Träger an für mod_period / 2
|
// Modulation on: Carrier on for mod_period / 2
|
||||||
let cycles_on = (carrier_hz as f64 * (mod_period / 2.0) / 1000.0) as u64;
|
let cycles_on = (carrier_hz as f64 * (mod_period / 2.0) / 1000.0) as u64;
|
||||||
for _ in 0..cycles_on {
|
for _ in 0..cycles_on {
|
||||||
pin.set_high();
|
pin.set_high();
|
||||||
@ -20,21 +20,27 @@ pub fn modulated_tone(pin_num: u8, carrier_hz: u32, sound_hz: u32, duration_ms:
|
|||||||
thread::sleep(carrier_period);
|
thread::sleep(carrier_period);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modulations-Aus: Träger aus für mod_period / 2
|
// Modulation off: Carrier on for mod_period / 2
|
||||||
let pause = time::Duration::from_millis((mod_period / 2.0) as u64);
|
let pause = time::Duration::from_millis((mod_period / 2.0) as u64);
|
||||||
thread::sleep(pause);
|
thread::sleep(pause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn beep_ack() {
|
pub fn beep_ack() {
|
||||||
// GPIO 17, Träger = 2300 Hz, Ton = 440 Hz, Dauer = 1 Sekunde
|
// GPIO 17, carrier = 2300 Hz, sound = 440 Hz, Dauer = 1 sec
|
||||||
modulated_tone(4, 2300, 500, 500);
|
modulated_tone(4, 2300, 500, 500);
|
||||||
modulated_tone(4, 2300, 700, 500);
|
modulated_tone(4, 2300, 700, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn beep_nak() {
|
pub fn beep_nak() {
|
||||||
// GPIO 17, Träger = 2300 Hz, Ton = 440 Hz, Dauer = 1 Sekunde
|
// GPIO 17, carrier = 2300 Hz, sound = 440 Hz, duration = 1 sec
|
||||||
modulated_tone(4, 2300, 700, 500);
|
modulated_tone(4, 2300, 700, 500);
|
||||||
modulated_tone(4, 2300, 500, 500);
|
modulated_tone(4, 2300, 500, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn beep_unnkown(){
|
||||||
|
modulated_tone(4, 2300, 500, 500);
|
||||||
|
modulated_tone(4, 2300, 500, 500);
|
||||||
|
modulated_tone(4, 2300, 500, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,12 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Deserialize, Serialize, Hash, Clone, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, Deserialize, Serialize, Hash, Clone, PartialOrd, Ord)]
|
||||||
pub struct TellyID(pub String);
|
pub struct TallyID(pub String);
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct AttendanceDay {
|
pub struct AttendanceDay {
|
||||||
date: String,
|
date: String,
|
||||||
ids: Vec<TellyID>,
|
ids: Vec<TallyID>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
@ -31,7 +31,7 @@ impl IDStore {
|
|||||||
Ok(serde_json::from_str(&readed_string)?)
|
Ok(serde_json::from_str(&readed_string)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_id(&mut self, id: TellyID) {
|
pub fn add_id(&mut self, id: TallyID) {
|
||||||
let day = self.get_current_day();
|
let day = self.get_current_day();
|
||||||
|
|
||||||
day.add_id(id);
|
day.add_id(id);
|
||||||
@ -59,7 +59,7 @@ impl IDStore {
|
|||||||
|
|
||||||
pub fn export_csv(&self) -> Result<String, Box<dyn Error>> {
|
pub fn export_csv(&self) -> Result<String, Box<dyn Error>> {
|
||||||
let seperator = ";";
|
let seperator = ";";
|
||||||
let mut user_ids: HashSet<TellyID> = HashSet::new();
|
let mut user_ids: HashSet<TallyID> = HashSet::new();
|
||||||
|
|
||||||
for day in self.days.values() {
|
for day in self.days.values() {
|
||||||
for id in day.ids.iter() {
|
for id in day.ids.iter() {
|
||||||
@ -67,7 +67,7 @@ impl IDStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut user_ids: Vec<TellyID> = user_ids.into_iter().collect();
|
let mut user_ids: Vec<TallyID> = user_ids.into_iter().collect();
|
||||||
user_ids.sort();
|
user_ids.sort();
|
||||||
|
|
||||||
let mut days: Vec<String> = self.days.keys().cloned().collect();
|
let mut days: Vec<String> = self.days.keys().cloned().collect();
|
||||||
@ -102,7 +102,7 @@ impl AttendanceDay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_id(&mut self, id: TellyID) {
|
fn add_id(&mut self, id: TallyID) {
|
||||||
if self.ids.contains(&id) {
|
if self.ids.contains(&id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -1,5 +1,8 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use id_store::IDStore;
|
||||||
use pm3::{pm3_mock, run_pm3};
|
use pm3::{pm3_mock, run_pm3};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::{mpsc, Mutex};
|
||||||
use webserver::start_webserver;
|
use webserver::start_webserver;
|
||||||
|
|
||||||
mod id_store;
|
mod id_store;
|
||||||
@ -12,7 +15,7 @@ async fn main() {
|
|||||||
let (tx, mut rx) = mpsc::channel::<String>(32);
|
let (tx, mut rx) = mpsc::channel::<String>(32);
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
match pm3_mock(tx).await {
|
match run_pm3(tx).await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
println!("PM3 exited with an zero error code");
|
println!("PM3 exited with an zero error code");
|
||||||
}
|
}
|
||||||
@ -22,9 +25,12 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let store:Arc<Mutex<IDStore>> = Arc::new(Mutex::new(id_store::IDStore::new()));
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(line) = rx.recv().await {
|
while let Some(tally_id_string) = rx.recv().await {
|
||||||
println!("Got from channel: {}", line);
|
println!("Got from channel: {}", tally_id_string);
|
||||||
|
store.lock().await.add_id(id_store::TallyID(tally_id_string));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,20 +1,29 @@
|
|||||||
|
use rocket::Config;
|
||||||
use rocket::{get, http::ContentType, response::content::RawHtml, routes};
|
use rocket::{get, http::ContentType, response::content::RawHtml, routes};
|
||||||
use rust_embed::Embed;
|
use rust_embed::Embed;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Embed)]
|
#[derive(Embed)]
|
||||||
#[folder = "web/dist"]
|
#[folder = "web/dist"]
|
||||||
struct Asset;
|
struct Asset;
|
||||||
|
|
||||||
pub async fn start_webserver() -> Result<(), rocket::Error> {
|
pub async fn start_webserver() -> Result<(), rocket::Error> {
|
||||||
rocket::build()
|
let config = Config {
|
||||||
|
address: "0.0.0.0".parse().unwrap(), // Listen on all interfaces
|
||||||
|
port: 8000,
|
||||||
|
..Config::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
rocket::custom(config)
|
||||||
.mount("/", routes![static_files,index])
|
.mount("/", routes![static_files,index])
|
||||||
.launch()
|
.launch()
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> Option<RawHtml<Cow<'static, [u8]>>> {
|
fn index() -> Option<RawHtml<Cow<'static, [u8]>>> {
|
||||||
let asset = Asset::get("index.html")?;
|
let asset = Asset::get("index.html")?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user