From 020ce431ed71a8b67100a44ace3d1c0a2730509a Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 21 Nov 2024 20:23:13 +0000 Subject: [PATCH] Added GPIO --- lib/control/src/pneumatics.rs | 9 +++++++++ lib/io/src/gpio.rs | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/control/src/pneumatics.rs b/lib/control/src/pneumatics.rs index 50c585c..051d80f 100644 --- a/lib/control/src/pneumatics.rs +++ b/lib/control/src/pneumatics.rs @@ -1,4 +1,5 @@ use hyped_core::types::DigitalSignal; +use hyped_io::gpio::GpioOutputPin; /// A solenoid is either on or off #[derive(Debug, PartialEq)] @@ -153,6 +154,8 @@ 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 { @@ -160,22 +163,28 @@ impl Pneumatics { 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(); } } diff --git a/lib/io/src/gpio.rs b/lib/io/src/gpio.rs index 0829cda..f38e8f4 100644 --- a/lib/io/src/gpio.rs +++ b/lib/io/src/gpio.rs @@ -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; @@ -12,7 +17,7 @@ pub mod mock_gpio { next_values: Vec, } - 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;