1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
use binrw::binread;
use serde::Serialize;
#[cfg(target_arch = "wasm32")]
use tsify_next::Tsify;
use crate::utils::sub_byte_field;
#[binread]
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
#[br(little)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub struct VirtualStick {
#[br(temp)]
_bitpack1: u8,
#[br(calc(VirtualStickVerticalControlMode::from(sub_byte_field(_bitpack1, 0x30))))]
pub vertical_control_mode: VirtualStickVerticalControlMode,
#[br(calc(VirtualStickRollPitchControlMode::from(sub_byte_field(_bitpack1, 0xC0))))]
pub roll_pitch_control_mode: VirtualStickRollPitchControlMode,
#[br(calc(VirtualStickYawControlMode::from(sub_byte_field(_bitpack1, 0x08))))]
pub yaw_control_mode: VirtualStickYawControlMode,
#[br(calc(VirtualStickFlightCoordinateSystem::from(sub_byte_field(_bitpack1, 0x06))))]
pub coordinate_system: VirtualStickFlightCoordinateSystem,
/// Aircraft Roll. left and right panning [-30, 30] degrees
pub roll: f32,
/// Aircraft Pitch. forward or reverse [-30, 30] degrees.
pub pitch: f32,
/// Aircraft Yaw. left and right rotation [-180, 180] degrees
pub yaw: f32,
/// Aircraft throttle. Up or down [-5, 5]m/s
pub throttle: f32,
}
#[derive(Serialize, Debug)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub enum VirtualStickVerticalControlMode {
/// Sets the virtual stick vertical control values to be a vertical velocity.
/// Positive and negative vertical velocity is for the aircraft ascending and
/// descending respectively. Maximum vertical velocity is defined as 4 m/s. Minimum
/// vertical velocity is defined as -4 m/s.
Velocity,
/// Sets the virtual stick vertical control values to be an altitude. Maximum
/// position is defined as 500 m. Minimum position is defined as 0 m.
Position,
#[serde(untagged)]
Unknown(u8),
}
impl From<u8> for VirtualStickVerticalControlMode {
fn from(value: u8) -> Self {
match value {
0 => VirtualStickVerticalControlMode::Velocity,
1 => VirtualStickVerticalControlMode::Position,
_ => VirtualStickVerticalControlMode::Unknown(value),
}
}
}
#[derive(Serialize, Debug)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub enum VirtualStickRollPitchControlMode {
/// Sets the roll and pitch values to be an angle relative to a level aircraft. In
/// the body coordinate system, positive and negative pitch angle is for the
/// aircraft rotating about the y-axis in the positive direction or negative
/// direction, respectively. Positive and negative roll angle is the positive
/// direction or negative direction rotation angle about the x-axis, respectively.
/// However in the ground coordinate system, positive and negative pitch angle is
/// the angle value for the aircraft moving south and north, respectively. Positive
/// and negative roll angle is the angle when the aircraft is moving east and west,
/// respectively. Maximum angle is defined as 30 degrees. Minimum angle is defined
/// as -30 degrees.
Angle,
/// Sets the roll and pitch values to be a velocity. In the body coordinate system,
/// positive and negative pitch velocity is for the aircraft moving towards the
/// positive direction or negative direction along the pitch axis and y-axis,
/// respectively. Positive and negative roll velocity is when the aircraft is moving
/// towards the positive direction or negative direction along the roll axis and
/// x-axis, respectively. However, in the ground coordinate system, positive and
/// negative pitch velocity is for the aircraft moving east and west, respectively.
/// Positive and negative roll velocity is when the aircraft is moving north and
/// south, respectively. Maximum velocity is defined as 15 meters/s. Minimum
/// velocity is defined as -15 meters/s.
Velocity,
#[serde(untagged)]
Unknown(u8),
}
impl From<u8> for VirtualStickRollPitchControlMode {
fn from(value: u8) -> Self {
match value {
0 => VirtualStickRollPitchControlMode::Angle,
1 => VirtualStickRollPitchControlMode::Velocity,
_ => VirtualStickRollPitchControlMode::Unknown(value),
}
}
}
#[derive(Serialize, Debug)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub enum VirtualStickYawControlMode {
/// Sets the yaw values to be an angle relative to the north. Positive and negative
/// yaw angle is for the aircraft rotating clockwise and counterclockwise,
/// respectively. Maximum yaw angle is defined as 180 degrees. Minimum yaw angle is
/// defined as -180 degrees.
Angle,
/// Sets the yaw values to be an angular velocity. Positive and negative angular
/// velocity is for the aircraft rotating clockwise and counterclockwise,
/// respectively. Maximum yaw angular velocity is defined as 100 degrees/s. Minimum
/// yaw angular velocity is defined as -100 degrees/s.
Velocity,
#[serde(untagged)]
Unknown(u8),
}
impl From<u8> for VirtualStickYawControlMode {
fn from(value: u8) -> Self {
match value {
0 => VirtualStickYawControlMode::Angle,
1 => VirtualStickYawControlMode::Velocity,
_ => VirtualStickYawControlMode::Unknown(value),
}
}
}
#[derive(Serialize, Debug)]
#[cfg_attr(target_arch = "wasm32", derive(Tsify))]
pub enum VirtualStickFlightCoordinateSystem {
/// Ground coordinate system.
Ground,
/// Body coordinate system.
Body,
#[serde(untagged)]
Unknown(u8),
}
impl From<u8> for VirtualStickFlightCoordinateSystem {
fn from(value: u8) -> Self {
match value {
0 => VirtualStickFlightCoordinateSystem::Ground,
1 => VirtualStickFlightCoordinateSystem::Body,
_ => VirtualStickFlightCoordinateSystem::Unknown(value),
}
}
}