gopro_controller/
command.rs

1use crate::services::Sendable;
2///Represents a command that can be sent to a GoPro device
3///
4/// ### NOTE ###
5///
6/// The byte arrays in this enum were taken directly from the GoPro Open Spec:
7///
8/// <https://gopro.github.io/OpenGoPro/ble_2_0#commands-quick-reference>
9pub enum GoProCommand {
10    ShutterStart,
11    ShutterStop,
12    Sleep,
13    AddHilightDuringEncoding,
14    VideoMode,
15    PhotoMode,
16    TimelapseMode,
17}
18
19///Implement AsRef for GoProCommands so that relevant functions
20///can take a GoProCommand by reference or by value
21impl AsRef<GoProCommand> for GoProCommand {
22    fn as_ref(&self) -> &GoProCommand {
23        self
24    }
25}
26
27use GoProCommand as GPC; //alias for conciseness
28
29///Implement Sendable for all GoProCommands generically
30///to avoid the duplicate code of also implementing it
31///for references to GoProCommands
32///
33///
34///NOTE: The byte arrays in this implementation were taken directly from the GoPro Open Spec:
35///<https://gopro.github.io/OpenGoPro/ble_2_0#commands-quick-reference>
36impl Sendable for GPC {
37    fn as_bytes(&self) -> &'static [u8] {
38        match self.as_ref() {
39            GPC::ShutterStart => &[0x03, 0x01, 0x01, 0x01],
40            GPC::ShutterStop => &[0x03, 0x01, 0x01, 0x00],
41            GPC::Sleep => &[0x01, 0x05],
42            GPC::AddHilightDuringEncoding => &[0x01, 0x18],
43            GPC::VideoMode => &[0x04, 0x3E, 0x02, 0x03, 0xE8],
44            GPC::PhotoMode => &[0x04, 0x3E, 0x02, 0x03, 0xE9],
45            GPC::TimelapseMode => &[0x04, 0x3E, 0x02, 0x03, 0xEA],
46        }
47    }
48    fn response_value_bytes(&self) -> &'static [u8] {
49        match self.as_ref() {
50            GPC::ShutterStart => &[0x02, 0x01, 0x00],
51            GPC::ShutterStop => &[0x02, 0x01, 0x00],
52            GPC::Sleep => &[0x02, 0x05, 0x00],
53            GPC::AddHilightDuringEncoding => &[0x02, 0x18, 0x00],
54            GPC::VideoMode => &[0x02, 0x3E, 0x00],
55            GPC::PhotoMode => &[0x02, 0x3E, 0x00],
56            GPC::TimelapseMode => &[0x02, 0x3E, 0x00],
57        }
58    }
59}