f1_api/packet/
telemetry.rs1use bitflags::bitflags;
8use derive_new::new;
9use getset::{CopyGetters, Getters};
10
11use crate::packet::header::Header;
12use crate::types::CornerProperty;
13
14bitflags! {
15 pub struct Button: u32 {
20 const NONE = 0x0;
21 const CROSS_OR_A = 0x0001;
22 const TRIANGLE_OR_Y = 0x0002;
23 const CIRCLE_OR_B = 0x0004;
24 const SQUARE_OR_X = 0x0008;
25 const DPAD_LEFT = 0x0010;
26 const DPAD_RIGHT = 0x0020;
27 const DPAD_UP = 0x0040;
28 const DPAD_DOWN = 0x0080;
29 const OPTIONS_OR_MENU = 0x0100;
30 const L1_OR_LB = 0x0200;
31 const R1_OR_RB = 0x0400;
32 const L2_OR_LT = 0x0800;
33 const R2_OR_RT = 0x1000;
34 const LEFT_STICK_CLICK = 0x2000;
35 const RIGHT_STICK_CLICK =0x4000;
36 }
37}
38
39impl Default for Button {
40 fn default() -> Self {
41 Button::NONE
42 }
43}
44
45#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
47pub enum Gear {
48 Reverse = -1,
49 Neutral = 0,
50 First = 1,
51 Second = 2,
52 Third = 3,
53 Fourth = 4,
54 Fifth = 5,
55 Sixth = 6,
56 Seventh = 7,
57 Eighth = 8,
58}
59
60impl Default for Gear {
61 fn default() -> Self {
62 Gear::Neutral
63 }
64}
65
66#[derive(Debug, PartialEq, Copy, Clone, Eq, Ord, PartialOrd, Hash)]
68pub enum Surface {
69 Tarmac = 0,
70 RumbleStrip = 1,
71 Concrete = 2,
72 Rock = 3,
73 Gravel = 4,
74 Mud = 5,
75 Sand = 6,
76 Grass = 7,
77 Water = 8,
78 Cobblestone = 9,
79 Metal = 10,
80 Ridged = 11,
81}
82
83impl Default for Surface {
84 fn default() -> Self {
85 Surface::Tarmac
86 }
87}
88
89#[derive(new, Debug, CopyGetters, Getters, PartialEq, Copy, Clone, PartialOrd, Default)]
94#[allow(clippy::too_many_arguments)]
95pub struct Telemetry {
96 #[getset(get_copy = "pub")]
98 speed: u16,
99
100 #[getset(get_copy = "pub")]
102 throttle: f32,
103
104 #[getset(get_copy = "pub")]
108 steering: f32,
109
110 #[getset(get_copy = "pub")]
112 brake: f32,
113
114 #[getset(get_copy = "pub")]
116 clutch: u8,
117
118 #[getset(get_copy = "pub")]
120 gear: Gear,
121
122 #[getset(get_copy = "pub")]
124 engine_rpm: u16,
125
126 #[getset(get_copy = "pub")]
128 drs: bool,
129
130 #[getset(get_copy = "pub")]
132 rev_lights: u8,
133
134 #[getset(get = "pub")]
136 brake_temperature: CornerProperty<u16>,
137
138 #[getset(get = "pub")]
140 tyre_surface_temperature: CornerProperty<u16>,
141
142 #[getset(get = "pub")]
144 tyre_inner_temperature: CornerProperty<u16>,
145
146 #[getset(get_copy = "pub")]
148 engine_temperature: u16,
149
150 #[getset(get = "pub")]
152 tyre_pressure: CornerProperty<f32>,
153
154 #[getset(get = "pub")]
156 surface_type: CornerProperty<Surface>,
157}
158
159#[derive(new, Debug, CopyGetters, Getters, PartialEq, Clone, PartialOrd)]
164pub struct TelemetryPacket {
165 #[getset(get = "pub")]
167 header: Header,
168
169 #[getset(get = "pub")]
171 telemetry: Vec<Telemetry>,
172
173 #[getset(get_copy = "pub")]
175 button_status: Button,
176}