Skip to content

Commit

Permalink
Added GPIO
Browse files Browse the repository at this point in the history
  • Loading branch information
JanOkul committed Nov 21, 2024
1 parent 543fa1b commit 020ce43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/control/src/pneumatics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hyped_core::types::DigitalSignal;
use hyped_io::gpio::GpioOutputPin;

/// A solenoid is either on or off
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -153,29 +154,37 @@ enum LateralSuspensionState {
struct Pneumatics {
brakes: BrakeState,
lateral_suspension: LateralSuspensionState,
brake_pin: GpioOutputPinStruct, //TODOLater Replace with GpioOutputPinStruct with an impl of GpioOutputPin
lateral_suspension_pin: GpioOutputPinStruct
}

impl Pneumatics {
fn new() -> Self {
Pneumatics {
brakes: BrakeState::Engaged,
lateral_suspension: LateralSuspensionState::Retracted,
brake_pin: 1, // TODOLater replace with initial values once implemented
lateral_suspension_pin: 0
}
}

fn engage_brakes(&mut self) {
self.brakes = BrakeState::Engaged;
self.brake_pin.set_high();
}

fn disengage_brakes(&mut self) {
self.brakes = BrakeState::Disengaged;
self.brake_pin.set_low();
}

fn deploy_lateral_suspension(&mut self) {
self.lateral_suspension = LateralSuspensionState::Deployed;
self.lateral_suspension_pin.set_high();
}

fn retract_lateral_suspension(&mut self) {
self.lateral_suspension = LateralSuspensionState::Retracted;
self.lateral_suspension_pin.set_low();
}
}
9 changes: 7 additions & 2 deletions lib/io/src/gpio.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/// Abstraction for a GPIO pin so that sensors can be tested with a mock GPIO pin
pub trait GpioPin {
pub trait GpioInputPin {
fn is_high(&mut self) -> bool;
}

pub trait GpioOutputPin {
fn set_high(&mut self);
fn set_low(&mut self);
}

pub mod mock_gpio {
use heapless::Vec;

Expand All @@ -12,7 +17,7 @@ pub mod mock_gpio {
next_values: Vec<bool, 10>,
}

impl crate::gpio::GpioPin for MockGpio {
impl crate::gpio::GpioInputPin for MockGpio {
fn is_high(&mut self) -> bool {
let next_value = self.next_values.pop().unwrap_or(self.current_value);
self.current_value = next_value;
Expand Down

0 comments on commit 020ce43

Please sign in to comment.