fixed merge errors

This commit is contained in:
Djeeberjr 2025-05-05 13:04:00 +02:00
parent e14f703a76
commit 1ba74be096
7 changed files with 103 additions and 68 deletions

33
Cargo.lock generated
View File

@ -283,6 +283,22 @@ dependencies = [
"void",
]
[[package]]
name = "embedded-hal"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
[[package]]
name = "embedded-hal-nb"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
dependencies = [
"embedded-hal 1.0.0",
"nb 1.1.0",
]
[[package]]
name = "encoding_rs"
version = "0.8.35"
@ -1160,7 +1176,13 @@ version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ce3b019009cff02cb6b0e96e7cc2e5c5b90187dc1a490f8ef1521d0596b026"
dependencies = [
"embedded-hal 0.2.7",
"embedded-hal 1.0.0",
"embedded-hal-nb",
"libc",
"nb 0.1.3",
"spin_sleep",
"void",
]
[[package]]
@ -1385,6 +1407,15 @@ version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
[[package]]
name = "spin_sleep"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17db5ecef7e0bebeb8bf8bc4c4b554e05e0205d7008f10bb37787892e7a6507b"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "stable-pattern"
version = "0.1.0"
@ -2048,7 +2079,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6c2ba0d6c0ea9c117487411e93dc5dacaafc2c17698677a03d1c67901d4c70a"
dependencies = [
"embedded-hal",
"embedded-hal 0.2.7",
"nb 0.1.3",
"smart-leds-trait",
]

View File

@ -15,7 +15,7 @@ rust-embed = "8.7.0"
log = "0.4.27"
simplelog = "0.12.2"
rppal = "0.22.1"
rppal = { version = "0.22.1", features = ["hal"] }
smart-leds = "0.3"
ws2812-spi = "0.3"

View File

@ -1,49 +1,49 @@
pub mod buzzer {
use rppal::gpio::Gpio;
use std::{thread, time};
use rppal::gpio::Gpio;
use std::{thread, time};
/// 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();
/// 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();
let carrier_period =
time::Duration::from_micros((1_000_000.0 / carrier_hz as f64 / 2.0) as u64);
let mod_period = 1_000.0 / sound_hz as f64; // in ms
let total_cycles = duration_ms as f64 / mod_period;
let carrier_period = time::Duration::from_micros((1_000_000.0 / carrier_hz as f64 / 2.0) as u64);
let mod_period = 1_000.0 / sound_hz as f64; // in ms
let total_cycles = duration_ms as f64 / mod_period;
for _ in 0..total_cycles as u64 {
// 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();
thread::sleep(carrier_period);
pin.set_low();
thread::sleep(carrier_period);
}
// Modulation off: Carrier on for mod_period / 2
let pause = time::Duration::from_millis((mod_period / 2.0) as u64);
thread::sleep(pause);
for _ in 0..total_cycles as u64 {
// 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();
thread::sleep(carrier_period);
pin.set_low();
thread::sleep(carrier_period);
}
}
pub fn beep_ack() {
// 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, 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);
// 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, 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, 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);
}

View File

@ -29,11 +29,27 @@ impl From<NamedColor> for Color {
NamedColor::Red => Color { r: 255, g: 0, b: 0 },
NamedColor::Green => Color { r: 0, g: 255, b: 0 },
NamedColor::Blue => Color { r: 0, g: 0, b: 255 },
NamedColor::White => Color { r: 255, g: 255, b: 255 },
NamedColor::White => Color {
r: 255,
g: 255,
b: 255,
},
NamedColor::Off => Color { r: 0, g: 0, b: 0 },
NamedColor::Yellow => Color { r: 255, g: 255, b: 0 },
NamedColor::Cyan => Color { r: 0, g: 255, b: 255 },
NamedColor::Magenta => Color { r: 255, g: 0, b: 255 },
NamedColor::Yellow => Color {
r: 255,
g: 255,
b: 0,
},
NamedColor::Cyan => Color {
r: 0,
g: 255,
b: 255,
},
NamedColor::Magenta => Color {
r: 255,
g: 0,
b: 255,
},
}
}
}

View File

@ -5,10 +5,6 @@ use std::{
fmt::Display,
};
use crate::led::Led;
use tokio::fs;
use crate::led::Led;
use tokio::fs;
/// Represents the ID that is stored on the Tally
@ -135,12 +131,7 @@ impl AttendanceDay {
return false;
}
self.ids.push(id);
buzzer::beep_ack();
led.set_named_color_time(NamedColor::Green, 1); //led is green for 1 sec
return true;
true
}
}

View File

@ -1,10 +1,9 @@
use rppal::spi::{Bus, Mode, SlaveSelect, Spi};
use smart_leds::{SmartLedsWrite, RGB8};
use smart_leds::{RGB8, SmartLedsWrite};
use ws2812_spi::Ws2812;
pub struct Led {
controller: Ws2812<Spi>,
controller: Ws2812<Spi>,
}
impl Led {

View File

@ -1,3 +1,4 @@
use color::NamedColor;
use id_store::IDStore;
use log::{LevelFilter, error, info, warn};
use pm3::run_pm3;
@ -9,14 +10,13 @@ use tokio::{
};
use webserver::start_webserver;
mod buzzer;
mod color;
mod id_store;
mod led;
mod parser;
mod pm3;
mod webserver;
mod color;
mod led;
mod buzzer;
const STORE_PATH: &str = "./data.json";
@ -80,6 +80,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
{
info!("Added new id to current day");
// TODO: trigger the buzzer
buzzer::beep_ack();
// led.set_named_color_time(NamedColor::Green, 1); //led is green for 1 sec
if let Err(e) = channel_store.lock().await.export_json(STORE_PATH).await {
error!("Failed to save id store to file: {}", e);
@ -89,10 +91,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
});
tokio::spawn(async move {
})
match start_webserver(store.clone()).await {
Ok(()) => {}
Err(e) => {