diff --git a/src/buzzer.rs b/src/buzzer.rs index d00b608..cc709f7 100644 --- a/src/buzzer.rs +++ b/src/buzzer.rs @@ -1,6 +1,6 @@ -use rppal::pwm::{Pwm, Channel, Polarity}; +use rppal::pwm::{Channel, Error, Polarity, Pwm}; use tokio::time::sleep; -use std::{error::Error, time::Duration}; +use std::time::Duration; pub struct GPIOBuzzer { pwm: Pwm, @@ -11,7 +11,7 @@ impl GPIOBuzzer { /// 0.5 duty cyle /// # Arguments /// * "channel" - PWM channel for buzzer PWM0 = GPIO 12 / PWM1 = GPIO 13 - pub fn new(channel: Channel) -> Result> { + pub fn new(channel: Channel) -> Result { // Enable with dummy values; we'll set frequency/duty in the tone method let duty_cycle:f64 = 0.5; let pwm = Pwm::with_frequency(channel, 1000.0, duty_cycle, Polarity::Normal, true)?; @@ -25,7 +25,7 @@ impl GPIOBuzzer { /// # Arguments /// * `frequency` - Frequency in Hz. /// * `duration_ms` - Duration in milliseconds. - async fn modulated_tone(&mut self, frequency: f64, duration_ms: u64) -> Result<(), Box> { + async fn modulated_tone(&mut self, frequency: f64, duration_ms: u64) -> Result<(), Error> { self.pwm.set_frequency(frequency, 0.5)?; // 50% duty cycle (square wave) self.pwm.enable()?; sleep(Duration::from_millis(duration_ms)).await; @@ -33,7 +33,7 @@ impl GPIOBuzzer { Ok(()) } - pub async fn beep_ack(&mut self) -> Result<(), Box>{ + pub async fn beep_ack(&mut self) -> Result<(), Error>{ let sleep_ms: u64 = 10; self.modulated_tone(1200.0, 100).await?; @@ -42,7 +42,7 @@ impl GPIOBuzzer { Ok(()) } - pub async fn beep_nak(&mut self) -> Result<(), Box>{ + pub async fn beep_nak(&mut self) -> Result<(), Error>{ let sleep_ms: u64 = 100; self.modulated_tone(600.0, 150).await?; @@ -51,7 +51,7 @@ impl GPIOBuzzer { Ok(()) } - pub async fn beep_unnkown(&mut self) -> Result<(), Box>{ + pub async fn beep_unnkown(&mut self) -> Result<(), Error>{ let sleep_ms: u64 = 100; self.modulated_tone(750.0, 100).await?; diff --git a/src/led.rs b/src/led.rs index c322eac..c018906 100644 --- a/src/led.rs +++ b/src/led.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use rppal::spi::{Bus, Mode, SlaveSelect, Spi}; +use rppal::spi::{Bus, Error, Mode, SlaveSelect, Spi}; use smart_leds::SmartLedsWrite; use tokio::time::sleep; use ws2812_spi::Ws2812; @@ -14,27 +14,27 @@ pub struct Led { const STATUS_DURATION: Duration = Duration::from_secs(1); // 1s sleep for all status led signals impl Led { - pub fn new() -> Result> { + pub fn new() -> Result { let spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 3_800_000, Mode::Mode0)?; let controller = Ws2812::new(spi); Ok(Led { controller }) } - pub async fn turn_green_on_1s(&mut self) -> Result<(), Box> { + pub async fn turn_green_on_1s(&mut self) -> Result<(), Error> { self.controller.write(NamedColor::Green.into_iter())?; sleep(STATUS_DURATION).await; - self.controller.write(NamedColor::Off.into_iter())?; + self.turn_off()?; Ok(()) } - pub async fn turn_red_on_1s(&mut self) -> Result<(), Box> { + pub async fn turn_red_on_1s(&mut self) -> Result<(), Error> { self.controller.write(NamedColor::Red.into_iter())?; sleep(STATUS_DURATION).await; - self.controller.write(NamedColor::Off.into_iter())?; + self.turn_off()?; Ok(()) } - pub fn turn_off(&mut self) -> Result<(), Box> { + pub fn turn_off(&mut self) -> Result<(), Error> { self.controller.write(NamedColor::Off.into_iter())?; Ok(()) }