mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-02 01:04:16 +00:00
fixed buzzer use in tokio thread
This commit is contained in:
parent
b416b41040
commit
01454a018d
@ -1,5 +1,5 @@
|
||||
use rppal::gpio::{Gpio, OutputPin};
|
||||
use std::time;
|
||||
use std::{error::Error, time};
|
||||
use tokio::time::sleep;
|
||||
|
||||
pub struct GPIOBuzzer {
|
||||
@ -7,7 +7,7 @@ pub struct GPIOBuzzer {
|
||||
}
|
||||
|
||||
impl GPIOBuzzer {
|
||||
pub fn new(pin_num: u8) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
pub fn new(pin_num: u8) -> Result<Self, Box<dyn Error>> {
|
||||
let gpio = Gpio::new()?;
|
||||
let pin = gpio.get(pin_num)?.into_output();
|
||||
|
||||
|
@ -4,7 +4,6 @@ use std::{
|
||||
error::Error,
|
||||
fmt::Display,
|
||||
};
|
||||
|
||||
use tokio::fs;
|
||||
|
||||
/// Represents the ID that is stored on the Tally
|
||||
@ -67,7 +66,7 @@ impl IDStore {
|
||||
}
|
||||
|
||||
/// Writes the store to a json file
|
||||
pub async fn export_json(&self, filepath: &str) -> Result<(), Box<dyn Error>> {
|
||||
pub async fn export_json(&self, filepath: &str) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
fs::write(filepath, serde_json::to_string(&self)?).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use buzzer::GPIOBuzzer;
|
||||
use color::NamedColor;
|
||||
use id_store::IDStore;
|
||||
use log::{LevelFilter, error, info, warn};
|
||||
@ -69,8 +70,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
};
|
||||
|
||||
let store: Arc<Mutex<IDStore>> = Arc::new(Mutex::new(raw_store));
|
||||
|
||||
let mut gpio_buzzer = buzzer::GPIOBuzzer::new(4)?;
|
||||
let gpio_buzzer: Arc<Mutex<GPIOBuzzer>> = Arc::new(Mutex::new(buzzer::GPIOBuzzer::new(4)?));
|
||||
|
||||
let channel_store = store.clone();
|
||||
tokio::spawn(async move {
|
||||
@ -82,11 +82,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
{
|
||||
info!("Added new id to current day");
|
||||
// led.set_named_color_time(NamedColor::Green, 1); //led is green for 1 sec
|
||||
gpio_buzzer.beep_ack().await;
|
||||
gpio_buzzer.lock().await.beep_ack().await;
|
||||
|
||||
if let Err(e) = channel_store.lock().await.export_json(STORE_PATH).await {
|
||||
error!("Failed to save id store to file: {}", e);
|
||||
// TODO: How to handle a failure to save ?
|
||||
gpio_buzzer.lock().await.beep_nak().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user