Skip to main content

cu_bdshot/
messages.rs

1use bincode::{Decode, Encode};
2use cu29::prelude::*;
3use serde::{Deserialize, Serialize};
4
5/// Telemetry payload decoded from a DSHOT ESC.
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, Reflect)]
7pub enum DShotTelemetry {
8    EncodingError,
9    Erpm(u16),
10    Temp(u8),
11    Voltage(u8),
12    Amps(u8),
13    Debug1(u8),
14    Debug2(u8),
15    Debug3(u8),
16    Event(u8),
17}
18
19/// Command sent from Copper into the ESC bridge.
20#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, Reflect)]
21pub struct EscCommand {
22    /// Raw throttle value (0 - 2047). Values >= 48 arm the ESC per DSHOT spec.
23    pub throttle: u16,
24    /// Whether the bridge should request telemetry for this frame.
25    pub request_telemetry: bool,
26}
27
28impl Default for EscCommand {
29    fn default() -> Self {
30        Self {
31            throttle: 0,
32            request_telemetry: true,
33        }
34    }
35}
36
37impl EscCommand {
38    pub fn disarm() -> Self {
39        Self::default()
40    }
41}
42
43/// Telemetry sample received from the ESC bridge.
44#[derive(
45    Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, Reflect,
46)]
47pub struct EscTelemetry {
48    pub sample: Option<DShotTelemetry>,
49}