drs_0x01/
message.rs

1use addr::ReadableEEPAddr;
2use addr::ReadableRamAddr;
3use addr::WritableEEPAddr;
4use addr::WritableRamAddr;
5
6use arrayvec::ArrayVec;
7
8pub enum RegisterRequest {
9    EEPWrite(WritableEEPAddr),
10    EEPRead(ReadableEEPAddr),
11    RamWrite(WritableRamAddr),
12    RamRead(ReadableRamAddr),
13}
14
15pub(crate) struct SJogRequest {
16    pub(crate) data: ArrayVec<[SJogData; 10]>,
17    pub(crate) playtime: u8,
18}
19
20pub(crate) type IJogRequest = ArrayVec<[IJogData; 10]>;
21
22#[derive(Debug)]
23pub enum SpecialRequest {
24    Stat,
25    Rollback { skip_id: u8, skip_baud: u8 },
26    Reboot,
27}
28
29#[derive(Clone, Copy)]
30pub enum Rollback {
31    SkipId,
32    SkipBaud,
33    SkipBoth,
34    SkipNone,
35}
36
37/// This represent the rotation sense of the servomotor while controlled in `Speed`.
38#[derive(Debug)]
39pub enum Rotation {
40    /// CounterClockwise rotation, which is the default rotation sense.
41    CounterClockwise,
42    /// Clockwise rotation, representing the inverted rotation.
43    Clockwise,
44}
45
46/// This represent the servomotor control mode.
47/// The servomotor is either controlled in `Position` or `Speed`.
48#[derive(Debug)]
49pub enum JogMode {
50    /// Control the servomotor by position.
51    /// Make sure that the position is in range for your servomotor.
52    Normal {
53        /// The calibrated position.
54        /// The value must be in the 0..1023 range
55        position: u16,
56    },
57    /// Control the servomotor by speed.
58    /// Make sur that you respect the maximum speed.
59    /// The 14th bit represent the sign, if it set the servomotor will rotate the other way.
60    Continuous {
61        /// The desired PWM value.
62        /// The value must be in the 0..1023 range
63        speed: u16,
64        /// Inverts the rotation sense of the servo by modifying the 14th bit.
65        rotation: Rotation,
66    },
67}
68
69impl JogMode {
70    pub(crate) fn associated_data(&self) -> u16 {
71        match *self {
72            JogMode::Normal { position } => position,
73            JogMode::Continuous { speed, rotation: Rotation::Clockwise } => 0x4000 | speed,
74            JogMode::Continuous { speed, rotation: Rotation::CounterClockwise } => speed,
75        }
76    }
77}
78
79impl Default for JogMode {
80    fn default() -> Self {
81        JogMode::Normal { position: 0 }
82    }
83}
84
85/// The color of the LED of the servomotor.
86#[derive(Debug)]
87pub enum JogColor {
88    /// Red
89    Red,
90    /// Green
91    Green,
92    /// Blue
93    Blue,
94}
95
96impl Default for JogColor {
97    fn default() -> Self {
98        JogColor::Green
99    }
100}
101
102#[derive(Default, Debug)]
103pub(crate) struct SJogData {
104    pub mode: JogMode,
105    pub color: JogColor,
106    pub id: u8,
107}
108
109impl SJogData {
110    pub(crate) fn new(mode: JogMode, color: JogColor, id: u8) -> Self {
111        SJogData { mode, color, id }
112    }
113}
114
115#[derive(Default, Debug)]
116pub(crate) struct IJogData {
117    pub mode: JogMode,
118    pub color: JogColor,
119    pub playtime: u8,
120    pub id: u8,
121}
122
123impl IJogData {
124    pub(crate) fn new(mode: JogMode, color: JogColor, playtime: u8, id: u8) -> Self {
125        IJogData {
126            mode,
127            color,
128            id,
129            playtime,
130        }
131    }
132}