54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
/// An enum of all commands passed into and out of the microcontroller
|
|
|
|
use strum_macros::EnumCount as EnumCountMacro;
|
|
use std::mem::discriminant;
|
|
use std::sync::Arc;
|
|
|
|
#[derive(Clone, EnumCountMacro, Debug)]
|
|
pub enum Commands {
|
|
|
|
// Inputs sent from the PIC microcontroller
|
|
PicRecvUp,
|
|
PicRecvDown,
|
|
PicRecvStop,
|
|
|
|
// Inputs from bluetooth
|
|
BluetoothUp {data: u8},
|
|
BluetoothDown {data: u8},
|
|
BluetoothStop {_data: u8}, // There is no state where releasing the stop button induces a change.
|
|
BluetoothName { data: Arc<String>},
|
|
|
|
// Internal messages
|
|
StopTimerExpired, // Sent when the 2 second stop sequence is complete
|
|
StopTimerRestart,
|
|
StopTimerClear,
|
|
ButtonTimerExpired,
|
|
ButtonTimerRestart,
|
|
ButtonTimerClear,
|
|
PairTimerExpired,
|
|
AllowPairing, // Also serves as the timer restart command
|
|
PairTimerClear,
|
|
|
|
NotifyMotorUp {data: u8},
|
|
NotifyMotorDown {data: u8},
|
|
NotifyMotorStop {data: u8},
|
|
|
|
EraseBleBonds,
|
|
}
|
|
|
|
#[non_exhaustive]
|
|
pub struct Button;
|
|
|
|
impl Button {
|
|
pub const PRESSED: u8 = 0x1;
|
|
pub const RELEASED: u8 = 0x0;
|
|
}
|
|
|
|
pub type CmdType = std::mem::Discriminant<Commands>;
|
|
|
|
/// Consider commands equal if they have the same command type, but different values
|
|
impl PartialEq for Commands {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
discriminant(self) == discriminant(other)
|
|
}
|
|
} |