Skip to main content

local_command/
local_command.rs

1use uf_dshot::{Command, DshotTx};
2
3fn print_frame(label: &str, frame: uf_dshot::EncodedFrame) {
4    println!(
5        "{label:<38} payload=0x{:04X} data_12=0x{:03X} crc=0x{:X}",
6        frame.payload,
7        frame.data_12(),
8        frame.crc_4()
9    );
10}
11
12fn main() {
13    // DShot Frame Encoder
14    let uni_tx = DshotTx::standard();
15
16    let uni_throttle = uni_tx.throttle(1000).expect("throttle in 0..=1999");
17    print_frame("unidirectional throttle", uni_throttle);
18
19    let uni_telem = uni_tx
20        .with_telemetry_request(true)
21        .throttle(1000)
22        .expect("throttle in 0..=1999");
23    print_frame("unidirectional throttle + telem", uni_telem);
24
25    let stop = uni_tx.command(Command::MotorStop);
26    print_frame("unidirectional command MotorStop", stop);
27
28    let stop = uni_tx.command(Command::Beep1);
29    print_frame("unidirectional command Beep1", stop);
30
31    // Bidirectional DShot Frame Encoder
32    let bidir_tx = DshotTx::bidirectional();
33    let bidir_throttle = bidir_tx.throttle(1000).expect("throttle in 0..=1999");
34    print_frame("bidirdirectional throttle", bidir_throttle);
35
36    let bidir_telem = bidir_tx
37        .with_telemetry_request(true)
38        .throttle(1000)
39        .expect("throttle in 0..=1999");
40    print_frame("bidirdirectional throttle + telem", bidir_telem);
41
42    let stop = bidir_tx.command(Command::MotorStop);
43    print_frame("bidirdirectional command MotorStop", stop);
44
45    let stop = bidir_tx.command(Command::Beep1);
46    print_frame("bidirdirectional command Beep1", stop);
47}