protoflight 0.1.2

Protoflight flight controller.
#![cfg(feature = "vtx")]
use {
    sequential_storage::map::PostcardValue,
    serde::{Deserialize, Serialize},
};

#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize)]
pub struct VtxConfig {
    pub frequency_mhz: u16,          // sets freq in MHz if band=0
    pub pit_mode_frequency_mhz: u16, // sets out-of-range pit mode frequency
    pub band: u8,                    // 1=A, 2=B, 3=E, 4=F(Airwaves/Fatshark), 5=Raceband
    pub channel: u8,                 // 1-8
    pub power: u8,                   // 0 = lowest
    pub low_power_disarm: u8,        // min power while disarmed, from vtxLowerPowerDisarm_e
    pub softserial_alt: u8,          // prepend 0xff before sending frame even with SOFTSERIAL
}

impl VtxConfig {
    pub const fn new() -> Self {
        Self {
            frequency_mhz: 5740,
            pit_mode_frequency_mhz: 0,
            band: 4,
            channel: 1,
            power: 1,
            low_power_disarm: 1,
            softserial_alt: 0,
        }
    }
}

impl PostcardValue<'_> for VtxConfig {}

impl Default for VtxConfig {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn _is_normal<T: Sized + Send + Sync + Unpin>() {}
    fn is_full<T: Sized + Send + Sync + Unpin + Copy + Clone + Default + PartialEq>() {}
    fn is_config<T: Serialize + for<'a> Deserialize<'a> + for<'a> PostcardValue<'a>>() {}

    #[test]
    fn normal_types() {
        is_full::<VtxConfig>();
        is_config::<VtxConfig>();
    }
    #[test]
    fn test_new() {
        let config = VtxConfig::new();
        assert_eq!(5740, config.frequency_mhz);
    }
}