mod combo_direct;
mod combo_pwm;
mod extended;
mod single_output;
pub(crate) use combo_direct::ComboDirectProtocol;
pub(crate) use combo_pwm::ComboPwmProtocol;
pub(crate) use extended::ExtendedProtocol;
pub(crate) use single_output::SingleOutputProtocol;
pub use combo_direct::{ComboDirectCommand, DirectState};
pub use combo_pwm::ComboPwmCommand;
pub use extended::ExtendedCommand;
pub use single_output::{SingleOutputCommand, SingleOutputDiscrete};
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Channel {
One = 0,
Two = 1,
Three = 2,
Four = 3,
}
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Output {
RED = 0, BLUE = 1, }
pub fn map_speed(speed: i8) -> u8 {
if speed == 0 || speed == 8 {
speed as u8
} else if speed > 0 {
if speed > 7 {
7
} else {
speed as u8
}
} else {
let s = (-speed) as u8;
if s > 7 {
9
} else {
16 - s
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_channel_output_values() {
assert_eq!(Channel::One as u8, 0);
assert_eq!(Output::RED as u8, 0);
}
#[test]
fn test_map_speed_values() {
assert_eq!(map_speed(0), 0);
assert_eq!(map_speed(8), 8);
assert_eq!(map_speed(1), 1);
assert_eq!(map_speed(-1), 15);
assert_eq!(map_speed(7), 7);
assert_eq!(map_speed(9), 7);
assert_eq!(map_speed(-6), 10);
assert_eq!(map_speed(-7), 9);
assert_eq!(map_speed(-8), 9);
}
#[test]
fn test_map_speed_extreme_values() {
assert_eq!(map_speed(100), 7); assert_eq!(map_speed(-100), 9); }
}