Minor refactor of vehicle and servo to simplify traits
This commit is contained in:
@@ -10,9 +10,11 @@ pub trait Servo {
|
||||
fn set_frequency(&self, frequency: f64);
|
||||
}
|
||||
|
||||
pub trait Vehicle<T: Servo> {
|
||||
fn get_throttle_servo() -> T;
|
||||
fn get_steering_servo() -> T;
|
||||
pub trait Vehicle {
|
||||
fn get_throttle(&self) -> f64;
|
||||
fn set_throttle(&self, throttle: f64);
|
||||
fn get_steering(&self) -> f64;
|
||||
fn set_steering(&self, steering: f64);
|
||||
}
|
||||
#[cfg(feature = "rppal")]
|
||||
pub mod rppal {
|
||||
@@ -63,6 +65,12 @@ pub struct Esp32SerialPwmServo<T: SerialPort> {
|
||||
serial_port: T,
|
||||
}
|
||||
|
||||
impl<T: SerialPort> Esp32SerialPwmServo<T> {
|
||||
pub fn new(serial_port: T) -> Esp32SerialPwmServo<T> {
|
||||
Esp32SerialPwmServo { serial_port }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: SerialPort> Servo for Esp32SerialPwmServo<T> {
|
||||
fn get_duty_cycle(&self) -> f64 {
|
||||
todo!()
|
||||
@@ -80,3 +88,31 @@ impl<T: SerialPort> Servo for Esp32SerialPwmServo<T> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ServoVehicle<T: Servo> {
|
||||
servo: T,
|
||||
}
|
||||
|
||||
impl<T: Servo> ServoVehicle<T> {
|
||||
pub fn new(servo: T) -> ServoVehicle<T> {
|
||||
ServoVehicle { servo }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Servo> Vehicle for ServoVehicle<T> {
|
||||
fn get_throttle(&self) -> f64 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_throttle(&self, throttle: f64) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_steering(&self) -> f64 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_steering(&self, steering: f64) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user