Skip to content

Commit

Permalink
Merge pull request #17 from realroot2185/main
Browse files Browse the repository at this point in the history
Add support for vibration
  • Loading branch information
lulf authored Feb 9, 2025
2 parents f8630ca + 7c9197b commit 195cd57
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
21 changes: 21 additions & 0 deletions firmware/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Device<'a> {
pub touchpad: Touchpad<'static>,
pub hrs: Hrs<'static>,
pub firmware_validator: FirmwareValidator<'static>,
pub vibrator: Vibrator<'static>,
}

impl<'a> Device<'a> {}
Expand Down Expand Up @@ -78,6 +79,26 @@ impl<'a> Battery<'a> {
}
}

pub struct Vibrator<'a> {
motor: Output<'a>,
}

impl<'a> Vibrator<'a> {
pub fn new(motor: Output<'a>) -> Self {
Self { motor }
}

pub async fn on_for(&mut self, ms: u64) {
self.motor.set_low();
Timer::after(Duration::from_millis(ms)).await;
self.motor.set_high();
}

pub fn off(&mut self) {
self.motor.set_high();
}
}

pub enum BacklightLevel {
Low,
Medium,
Expand Down
9 changes: 7 additions & 2 deletions firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod device;
mod firmware_validator;
mod state;
use crate::clock::clock;
use crate::device::{Battery, Button, Device, Hrs, Screen};
use crate::device::{Battery, Button, Device, Hrs, Screen, Vibrator};
use crate::state::WatchState;

bind_interrupts!(struct Irqs {
Expand Down Expand Up @@ -197,7 +197,11 @@ async fn main(s: Spawner) {

// BLE
ble::start(s, sdc, dfu_config);


// Vibration
let motor = Output::new(p.P0_16, Level::High, OutputDrive::Standard0Disconnect1);
let vibrator = Vibrator::new(motor);

// Display
let backlight = Backlight::new(p.P0_14.degrade(), p.P0_22.degrade(), p.P0_23.degrade());
let rst = Output::new(p.P0_26, Level::Low, OutputDrive::Standard);
Expand All @@ -222,6 +226,7 @@ async fn main(s: Spawner) {
touchpad,
hrs,
firmware_validator,
vibrator,
};

let mut state = WatchState::default();
Expand Down
5 changes: 3 additions & 2 deletions firmware/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use defmt::info;
use embassy_futures::select::{select, select3, Either, Either3};
use embassy_time::{Duration, Instant, Timer};
use embassy_time::{Duration, Instant, Ticker, Timer};
use embedded_graphics::prelude::*;
use watchful_ui::{FirmwareDetails, MenuAction, MenuView, TimeView, WorkoutView};

Expand Down Expand Up @@ -244,6 +244,7 @@ impl WorkoutState {
let screen = &mut device.screen;
let button = &mut device.button;
let hrs = &mut device.hrs;
let mut ticker = Ticker::every(Duration::from_secs(2));
hrs.init().unwrap();
hrs.enable_hrs().unwrap();
hrs.enable_oscillator().unwrap();
Expand All @@ -256,7 +257,7 @@ impl WorkoutState {
.draw(screen.display())
.unwrap();
screen.on();
Timer::after(Duration::from_secs(2)).await;
ticker.next().await;
seconds += 2;
}
};
Expand Down

0 comments on commit 195cd57

Please # to comment.