Compare commits
No commits in common. "81d452694d03146673803c4d533f4cc1425d4f4c" and "6cae7dbb0ef3929b420a7266dc0c6739c231daa0" have entirely different histories.
81d452694d
...
6cae7dbb0e
|
@ -17,7 +17,7 @@ use rp_pico::{
|
||||||
entry,
|
entry,
|
||||||
hal::{
|
hal::{
|
||||||
clocks::init_clocks_and_plls,
|
clocks::init_clocks_and_plls,
|
||||||
gpio::{FunctionSio, Pin, PinId, PullDown, PullUp, SioInput, SioOutput},
|
gpio::{FunctionSio, Pin, PinId, PullUp, SioInput},
|
||||||
pac::{CorePeripherals, Peripherals},
|
pac::{CorePeripherals, Peripherals},
|
||||||
spi::{Enabled, Spi, SpiDevice, ValidSpiPinout},
|
spi::{Enabled, Spi, SpiDevice, ValidSpiPinout},
|
||||||
watchdog::Watchdog,
|
watchdog::Watchdog,
|
||||||
|
@ -65,16 +65,12 @@ struct BikeUI<
|
||||||
RightId: PinId,
|
RightId: PinId,
|
||||||
PreviousId: PinId,
|
PreviousId: PinId,
|
||||||
NextId: PinId,
|
NextId: PinId,
|
||||||
BrakeId: PinId,
|
|
||||||
> {
|
> {
|
||||||
spi: RefCell<Spi<Enabled, D, P, 8>>,
|
spi: RefCell<Spi<Enabled, D, P, 8>>,
|
||||||
left_blinker_button: DebouncedButton<LeftId>,
|
left_blinker_button: DebouncedButton<LeftId>,
|
||||||
right_blinker_button: DebouncedButton<RightId>,
|
right_blinker_button: DebouncedButton<RightId>,
|
||||||
previous_animation_button: DebouncedButton<PreviousId>,
|
previous_animation_button: DebouncedButton<PreviousId>,
|
||||||
next_animation_button: DebouncedButton<NextId>,
|
next_animation_button: DebouncedButton<NextId>,
|
||||||
brake_sensor: Pin<BrakeId, FunctionSio<SioInput>, PullUp>,
|
|
||||||
|
|
||||||
brake_enabled: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
|
@ -84,8 +80,7 @@ impl<
|
||||||
RightId: PinId,
|
RightId: PinId,
|
||||||
PreviousId: PinId,
|
PreviousId: PinId,
|
||||||
NextId: PinId,
|
NextId: PinId,
|
||||||
BrakeId: PinId,
|
> BikeUI<D, P, LeftId, RightId, PreviousId, NextId>
|
||||||
> BikeUI<D, P, LeftId, RightId, PreviousId, NextId, BrakeId>
|
|
||||||
{
|
{
|
||||||
fn new(
|
fn new(
|
||||||
spi: Spi<Enabled, D, P, 8>,
|
spi: Spi<Enabled, D, P, 8>,
|
||||||
|
@ -93,7 +88,6 @@ impl<
|
||||||
right_blinker_button: Pin<RightId, FunctionSio<SioInput>, PullUp>,
|
right_blinker_button: Pin<RightId, FunctionSio<SioInput>, PullUp>,
|
||||||
previous_animation_button: Pin<PreviousId, FunctionSio<SioInput>, PullUp>,
|
previous_animation_button: Pin<PreviousId, FunctionSio<SioInput>, PullUp>,
|
||||||
next_animation_button: Pin<NextId, FunctionSio<SioInput>, PullUp>,
|
next_animation_button: Pin<NextId, FunctionSio<SioInput>, PullUp>,
|
||||||
brake_sensor: Pin<BrakeId, FunctionSio<SioInput>, PullUp>,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
spi: RefCell::new(spi),
|
spi: RefCell::new(spi),
|
||||||
|
@ -101,9 +95,6 @@ impl<
|
||||||
right_blinker_button: DebouncedButton::new(right_blinker_button),
|
right_blinker_button: DebouncedButton::new(right_blinker_button),
|
||||||
previous_animation_button: DebouncedButton::new(previous_animation_button),
|
previous_animation_button: DebouncedButton::new(previous_animation_button),
|
||||||
next_animation_button: DebouncedButton::new(next_animation_button),
|
next_animation_button: DebouncedButton::new(next_animation_button),
|
||||||
brake_sensor,
|
|
||||||
|
|
||||||
brake_enabled: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,17 +106,10 @@ impl<
|
||||||
RightId: PinId,
|
RightId: PinId,
|
||||||
PreviousId: PinId,
|
PreviousId: PinId,
|
||||||
NextId: PinId,
|
NextId: PinId,
|
||||||
BrakeId: PinId,
|
> UI for BikeUI<D, P, LeftId, RightId, PreviousId, NextId>
|
||||||
> UI for BikeUI<D, P, LeftId, RightId, PreviousId, NextId, BrakeId>
|
|
||||||
{
|
{
|
||||||
fn check_event(&mut self, current_time: Instant) -> Option<Event> {
|
fn check_event(&mut self, current_time: Instant) -> Option<Event> {
|
||||||
if self.brake_sensor.is_high().unwrap_or(true) && !self.brake_enabled {
|
if self.left_blinker_button.is_low(current_time) {
|
||||||
self.brake_enabled = true;
|
|
||||||
Some(Event::Brake)
|
|
||||||
} else if self.brake_sensor.is_low().unwrap_or(false) && self.brake_enabled {
|
|
||||||
self.brake_enabled = false;
|
|
||||||
Some(Event::BrakeRelease)
|
|
||||||
} else if self.left_blinker_button.is_low(current_time) {
|
|
||||||
self.left_blinker_button.set_debounce(current_time);
|
self.left_blinker_button.set_debounce(current_time);
|
||||||
Some(Event::LeftBlinker)
|
Some(Event::LeftBlinker)
|
||||||
} else if self.right_blinker_button.is_low(current_time) {
|
} else if self.right_blinker_button.is_low(current_time) {
|
||||||
|
@ -209,13 +193,10 @@ fn main() -> ! {
|
||||||
embedded_hal::spi::MODE_1,
|
embedded_hal::spi::MODE_1,
|
||||||
);
|
);
|
||||||
|
|
||||||
let left_blinker_button = pins.gpio16.into_pull_up_input();
|
let left_blinker_button = pins.gpio17.into_pull_up_input();
|
||||||
let right_blinker_button = pins.gpio17.into_pull_up_input();
|
let right_blinker_button = pins.gpio16.into_pull_up_input();
|
||||||
let previous_animation_button = pins.gpio27.into_pull_up_input();
|
let previous_animation_button = pins.gpio27.into_pull_up_input();
|
||||||
let next_animation_button = pins.gpio26.into_pull_up_input();
|
let next_animation_button = pins.gpio26.into_pull_up_input();
|
||||||
let brake_sensor = pins.gpio18.into_pull_up_input();
|
|
||||||
|
|
||||||
let mut led_pin = pins.led.into_push_pull_output();
|
|
||||||
|
|
||||||
let ui = BikeUI::new(
|
let ui = BikeUI::new(
|
||||||
spi,
|
spi,
|
||||||
|
@ -223,11 +204,11 @@ fn main() -> ! {
|
||||||
right_blinker_button,
|
right_blinker_button,
|
||||||
previous_animation_button,
|
previous_animation_button,
|
||||||
next_animation_button,
|
next_animation_button,
|
||||||
brake_sensor,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut app = App::new(Box::new(ui));
|
let mut app = App::new(Box::new(ui));
|
||||||
|
|
||||||
|
let mut led_pin = pins.led.into_push_pull_output();
|
||||||
led_pin.set_high();
|
led_pin.set_high();
|
||||||
|
|
||||||
let mut time = Instant::default();
|
let mut time = Instant::default();
|
||||||
|
|
Loading…
Reference in New Issue