implemented mocking of rpi hardware

buzzer,led & hotspot got traits and a mock version of it. Based on the
flag the real or mock version is used.
This commit is contained in:
2025-05-13 17:19:45 +02:00
parent 31f65261df
commit 64a50d434b
6 changed files with 271 additions and 117 deletions

45
src/mock.rs Normal file
View File

@@ -0,0 +1,45 @@
use log::debug;
use crate::{buzzer::Buzzer, hotspot::Hotspot, led::StatusLed};
pub struct MockBuzzer {}
impl Buzzer for MockBuzzer {
async fn beep_ack(&mut self) -> Result<(), rppal::pwm::Error> {
debug!("Mockbuzzer: ACK");
Ok(())
}
async fn beep_nak(&mut self) -> Result<(), rppal::pwm::Error> {
debug!("Mockbuzzer: NAK");
Ok(())
}
}
pub struct MockLed {}
impl StatusLed for MockLed {
async fn turn_green_on_1s(&mut self) -> Result<(), rppal::spi::Error> {
debug!("Mockled: Turn LED green for 1 sec");
Ok(())
}
async fn turn_red_on_1s(&mut self) -> Result<(), rppal::spi::Error> {
debug!("Mockled: Turn LED red for 1 sec");
Ok(())
}
}
pub struct MockHotspot {}
impl Hotspot for MockHotspot {
async fn enable_hotspot(&self) -> Result<(), crate::hotspot::HotspotError> {
debug!("Mockhotspot: Enable hotspot");
Ok(())
}
async fn disable_hotspot(&self) -> Result<(), crate::hotspot::HotspotError> {
debug!("Mockhotspot: Disable hotspot");
Ok(())
}
}