removed #[repr(u8)] from many structs across the project, I found out that rust by default makes small structs u8s, it is uneeded to do it manually.

This commit is contained in:
2026-05-23 19:58:13 -05:00
parent a72efcfead
commit 450ea8da91
5 changed files with 48 additions and 42 deletions
+7 -21
View File
@@ -11,6 +11,8 @@ pub struct MotorDriverShaftSpeed {
}
impl MotorDriverShaftSpeed {
///This returns the current shaft speed as an RPM Value, which is the default for display.
/// It will be 0.0 if the data is none
pub fn speed_as_rpm(&self) -> f32 {
match self.shaft_speed {
Some(mut speed) => {
@@ -34,37 +36,21 @@ impl MotorDriverShaftSpeed {
impl Display for MotorDriverShaftSpeed {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self.shaft_speed {
Some(speed) => {
let unit = match self.unit {
Unit::Radians => "rad",
Unit::Rotations => "R",
_ => "",
};
write!(f, "")
}
None => {write!(f, "No Given Speeds")}
}
write!(f, "Motor Shaft Speed: {}", self.speed_as_rpm())
}
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[repr(u8)]
pub enum Unit {
Unknown = 0,
Rotations = 1,
Radians = 2,
Rotations,
Radians,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[repr(u8)]
pub enum TimeScale {
Unknown = 0,
PerSecond = 1,
PerMinute = 2,
PerSecond,
PerMinute,
}
+1
View File
@@ -6,3 +6,4 @@ pub mod communication;
pub mod logic;
pub mod positional;
pub mod motor;
+37
View File
@@ -0,0 +1,37 @@
pub enum Direction {
CCW,
CW
}
pub trait Driver {
///Spins in the provided direction
///This is best not called manually, use set_speed_and_direction_raw instead
fn spin(&mut self, dir: Direction);
///Commands the motor to stop
fn stop(&mut self);
///This method uses a full u16 to set the motor speed. This does not change spin direction, if already spinning
///Uses a number between 0 and 65535
///This is best to not call manually, use set_speed_and_direction_raw instead
fn set_speed_raw(&mut self, speed: u16);
///Commands the motors to use the speed and spin in the same command.
///Uses a number between 0 and 65535
///This should be used in most cases, unless the motor has the core::logic::motor::controller Trait, then the the methods from that should be used instead.
fn set_speed_and_direction_raw(&mut self, speed: u16, dir: Direction) {
//Set direction before speed, so it won't start spinning in one direction, then snap to the other.
//Most MCUs should execute these two lines of code so fast, that it should be neglible though.
self.spin(dir);
self.set_speed_raw(speed);
}
}
pub trait Sensor {
fn get_speed(&self) -> f32;
fn get_current(&self) -> Option<u32>;
fn get_voltage(&self) -> Option<u32>;
fn get_angle(&self) -> Option<f32>;
}
+2 -19
View File
@@ -113,7 +113,6 @@ impl Display for XYZPos {
Unit::Meters => {"m"}
Unit::Radians => {"rad"}
Unit::Custom => {"custom"}
_ => {return write!(f, "Unknown Data");}
};
write!(f, "[X: {:?}{unit_str} | Y: {:?}{unit_str} | Z: {:?}{unit_str}]", self.x, self.y, self.z)
@@ -126,7 +125,6 @@ impl Display for XYZVel {
Unit::Meters => {"m"}
Unit::Radians => {"rad"}
Unit::Custom => {"custom"}
_ => {return write!(f, "Unknown Data");}
};
write!(f, "[X: {:?}{unit_str}/s | Y: {:?}{unit_str}/s | Z: {:?}{unit_str}/s]", self.x, self.y, self.z)
@@ -139,7 +137,6 @@ impl Display for XYZAccel {
Unit::Meters => {"m"}
Unit::Radians => {"rad"}
Unit::Custom => {"custom"}
_ => {return write!(f, "Unknown Data");}
};
write!(f, "[X: {:?}{unit_str}/s^2 | Y: {:?}{unit_str}/s^2 | Z: {:?}{unit_str}/s^2]", self.x, self.y, self.z)
@@ -241,25 +238,11 @@ impl XYZData for XYZDataBucket {
}
///Represents the unit this position struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contatains
/// A value of 0 or Unknown means the data is malformed or something is was wrong on the sending side, it should be treated a failure case.
/// If you need to send a unit not listed here please use Unit::Custom instead of Unit::Unknown
///Represents the unit this position struct is carrying. Combining the Unit + Trait it impls lets you determine what this message contains
/// If you need to send a unit not listed here please use Unit::Custom
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, )]
#[repr(u8)]
pub enum Unit {
Unknown = 0,
Meters = 1,
Radians = 2,
Custom = 3,
}
impl From<u8> for Unit {
fn from(value: u8) -> Self {
match value {
1 => {Self::Meters}
2 => {Self::Radians}
3 => {Self::Custom}
_ => {Self::Unknown}
}
}
}
-1
View File
@@ -5,4 +5,3 @@ compile_error!(
Please use '--no-default-features --features embassy' to build for MCU\n\
or verify that you have not included a different feature that requires'std'"
);