mirror of
				https://github.com/Djeeberjr/fw-anwesenheit.git
				synced 2025-11-03 23:24:10 +00:00 
			
		
		
		
	workday ending
This commit is contained in:
		
							parent
							
								
									d18b967f39
								
							
						
					
					
						commit
						880e8f24a7
					
				@ -1,7 +1,7 @@
 | 
			
		||||
use rppal::gpio::Gpio;
 | 
			
		||||
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) {
 | 
			
		||||
    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();
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
        for _ in 0..cycles_on {
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 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);
 | 
			
		||||
        thread::sleep(pause);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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, 700, 500);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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, 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)]
 | 
			
		||||
pub struct TellyID(pub String);
 | 
			
		||||
pub struct TallyID(pub String);
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize, Serialize)]
 | 
			
		||||
pub struct AttendanceDay {
 | 
			
		||||
    date: String,
 | 
			
		||||
    ids: Vec<TellyID>,
 | 
			
		||||
    ids: Vec<TallyID>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize, Serialize)]
 | 
			
		||||
@ -31,7 +31,7 @@ impl IDStore {
 | 
			
		||||
        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();
 | 
			
		||||
 | 
			
		||||
        day.add_id(id);
 | 
			
		||||
@ -59,7 +59,7 @@ impl IDStore {
 | 
			
		||||
 | 
			
		||||
    pub fn export_csv(&self) -> Result<String, Box<dyn Error>> {
 | 
			
		||||
        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 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();
 | 
			
		||||
 | 
			
		||||
        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) {
 | 
			
		||||
            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 tokio::sync::mpsc;
 | 
			
		||||
use tokio::sync::{mpsc, Mutex};
 | 
			
		||||
use webserver::start_webserver;
 | 
			
		||||
 | 
			
		||||
mod id_store;
 | 
			
		||||
@ -12,7 +15,7 @@ async fn main() {
 | 
			
		||||
    let (tx, mut rx) = mpsc::channel::<String>(32);
 | 
			
		||||
 | 
			
		||||
    tokio::spawn(async move {
 | 
			
		||||
        match pm3_mock(tx).await {
 | 
			
		||||
        match run_pm3(tx).await {
 | 
			
		||||
            Ok(()) => {
 | 
			
		||||
                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 {
 | 
			
		||||
        while let Some(line) = rx.recv().await {
 | 
			
		||||
            println!("Got from channel: {}", line);
 | 
			
		||||
        while let Some(tally_id_string) = rx.recv().await {
 | 
			
		||||
            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 rust_embed::Embed;
 | 
			
		||||
use std::borrow::Cow;
 | 
			
		||||
use std::ffi::OsStr;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[derive(Embed)]
 | 
			
		||||
#[folder = "web/dist"]
 | 
			
		||||
struct Asset;
 | 
			
		||||
 | 
			
		||||
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])
 | 
			
		||||
        .launch()
 | 
			
		||||
        .await?;
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[get("/")]
 | 
			
		||||
fn index() -> Option<RawHtml<Cow<'static, [u8]>>> {
 | 
			
		||||
    let asset = Asset::get("index.html")?;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user