frclib_core/hal/rt/
station_interface.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
5pub enum EnabledState {
6 #[default]
8 Disabled,
9 EStopped,
11 Enabled,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
17pub enum Mode {
18 #[default]
20 Teleop,
21 Auto,
23 Test,
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Default)]
29pub struct JoystickData {
30 pub plugged_in: bool,
32 pub axies: [f32; 8],
35 pub buttons: [u8; 6],
39 pub povs: [i16; 3],
42}
43
44#[allow(missing_docs)]
46#[derive(Debug, Clone, Copy, Default)]
47pub struct StationData {
48 pub enabled_state: EnabledState,
49 pub mode: Mode,
50 pub station_attached: bool,
51 pub fms_attached: bool,
52 pub team_number: u16,
53 pub joysticks: [JoystickData; 8],
54}
55
56pub trait StationInterfaceDriver: 'static {
58 fn send_console_line_error(line: &str, location: &str, callstack: &str);
61
62 fn send_console_line_warn(line: &str, location: &str);
65
66 fn send_console_line_info(line: &str, location: &str);
69
70 fn send_console_line_debug(line: &str, location: &str);
73
74 fn refresh();
76
77 fn get_station_data() -> StationData;
79}
80
81#[derive(Debug, Clone, Copy)]
83pub struct StationInterfaceVTable {
84 pub(crate) send_console_line_error: fn(line: &str, location: &str, callstack: &str),
85 pub(crate) send_console_line_warn: fn(line: &str, location: &str),
86 pub(crate) send_console_line_info: fn(line: &str, location: &str),
87 pub(crate) send_console_line_debug: fn(line: &str, location: &str),
88 pub(crate) refresh: fn(),
89 pub(crate) get_station_data: fn() -> StationData,
90}
91
92impl StationInterfaceVTable {
93 pub(crate) fn from_driver<T: StationInterfaceDriver>() -> Self {
94 assert!(
95 std::mem::size_of::<T>() == 0,
96 "Station Interface Driver must be zero sized"
97 );
98 Self {
99 send_console_line_error: T::send_console_line_error,
100 send_console_line_warn: T::send_console_line_warn,
101 send_console_line_info: T::send_console_line_info,
102 send_console_line_debug: T::send_console_line_debug,
103 refresh: T::refresh,
104 get_station_data: T::get_station_data,
105 }
106 }
107
108 pub fn send_console_line_error(&self, line: &str, location: &str, callstack: &str) {
111 (self.send_console_line_error)(line, location, callstack);
112 }
113
114 pub fn send_console_line_warn(&self, line: &str, location: &str) {
117 (self.send_console_line_warn)(line, location);
118 }
119
120 pub fn send_console_line_info(&self, line: &str, location: &str) {
123 (self.send_console_line_info)(line, location);
124 }
125
126 pub fn send_console_line_debug(&self, line: &str, location: &str) {
129 (self.send_console_line_debug)(line, location);
130 }
131
132 pub fn refresh(&self) {
134 (self.refresh)();
135 }
136
137 #[must_use]
139 pub fn get_station_data(&self) -> StationData {
140 (self.get_station_data)()
141 }
142
143 #[must_use]
145 pub fn is_enabled(&self) -> bool {
146 self.get_station_data().enabled_state == EnabledState::Enabled
147 }
148
149 #[must_use]
151 pub fn is_disabled(&self) -> bool {
152 self.get_station_data().enabled_state == EnabledState::Disabled
153 }
154
155 #[must_use]
157 pub fn is_estopped(&self) -> bool {
158 self.get_station_data().enabled_state == EnabledState::EStopped
159 }
160
161 #[must_use]
163 pub fn is_teleop(&self) -> bool {
164 self.get_station_data().mode == Mode::Teleop
165 }
166
167 #[must_use]
169 pub fn is_auto(&self) -> bool {
170 self.get_station_data().mode == Mode::Auto
171 }
172
173 #[must_use]
175 pub fn is_test(&self) -> bool {
176 self.get_station_data().mode == Mode::Test
177 }
178
179 #[must_use]
181 pub fn is_fms_attached(&self) -> bool {
182 self.get_station_data().fms_attached
183 }
184
185 #[must_use]
187 pub fn is_station_attached(&self) -> bool {
188 self.get_station_data().station_attached
189 }
190
191 #[must_use]
193 pub fn get_station_team_number(&self) -> u16 {
194 self.get_station_data().team_number
195 }
196}