1use crate::{
15 byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
16 ip_connection::GetRequestSender,
17};
18pub enum Io4V2BrickletFunction {
19 SetValue,
20 GetValue,
21 SetSelectedValue,
22 SetConfiguration,
23 GetConfiguration,
24 SetInputValueCallbackConfiguration,
25 GetInputValueCallbackConfiguration,
26 SetAllInputValueCallbackConfiguration,
27 GetAllInputValueCallbackConfiguration,
28 SetMonoflop,
29 GetMonoflop,
30 GetEdgeCount,
31 SetEdgeCountConfiguration,
32 GetEdgeCountConfiguration,
33 SetPwmConfiguration,
34 GetPwmConfiguration,
35 GetSpitfpErrorCount,
36 SetBootloaderMode,
37 GetBootloaderMode,
38 SetWriteFirmwarePointer,
39 WriteFirmware,
40 SetStatusLedConfig,
41 GetStatusLedConfig,
42 GetChipTemperature,
43 Reset,
44 WriteUid,
45 ReadUid,
46 GetIdentity,
47 CallbackInputValue,
48 CallbackAllInputValue,
49 CallbackMonoflopDone,
50}
51impl From<Io4V2BrickletFunction> for u8 {
52 fn from(fun: Io4V2BrickletFunction) -> Self {
53 match fun {
54 Io4V2BrickletFunction::SetValue => 1,
55 Io4V2BrickletFunction::GetValue => 2,
56 Io4V2BrickletFunction::SetSelectedValue => 3,
57 Io4V2BrickletFunction::SetConfiguration => 4,
58 Io4V2BrickletFunction::GetConfiguration => 5,
59 Io4V2BrickletFunction::SetInputValueCallbackConfiguration => 6,
60 Io4V2BrickletFunction::GetInputValueCallbackConfiguration => 7,
61 Io4V2BrickletFunction::SetAllInputValueCallbackConfiguration => 8,
62 Io4V2BrickletFunction::GetAllInputValueCallbackConfiguration => 9,
63 Io4V2BrickletFunction::SetMonoflop => 10,
64 Io4V2BrickletFunction::GetMonoflop => 11,
65 Io4V2BrickletFunction::GetEdgeCount => 12,
66 Io4V2BrickletFunction::SetEdgeCountConfiguration => 13,
67 Io4V2BrickletFunction::GetEdgeCountConfiguration => 14,
68 Io4V2BrickletFunction::SetPwmConfiguration => 15,
69 Io4V2BrickletFunction::GetPwmConfiguration => 16,
70 Io4V2BrickletFunction::GetSpitfpErrorCount => 234,
71 Io4V2BrickletFunction::SetBootloaderMode => 235,
72 Io4V2BrickletFunction::GetBootloaderMode => 236,
73 Io4V2BrickletFunction::SetWriteFirmwarePointer => 237,
74 Io4V2BrickletFunction::WriteFirmware => 238,
75 Io4V2BrickletFunction::SetStatusLedConfig => 239,
76 Io4V2BrickletFunction::GetStatusLedConfig => 240,
77 Io4V2BrickletFunction::GetChipTemperature => 242,
78 Io4V2BrickletFunction::Reset => 243,
79 Io4V2BrickletFunction::WriteUid => 248,
80 Io4V2BrickletFunction::ReadUid => 249,
81 Io4V2BrickletFunction::GetIdentity => 255,
82 Io4V2BrickletFunction::CallbackInputValue => 17,
83 Io4V2BrickletFunction::CallbackAllInputValue => 18,
84 Io4V2BrickletFunction::CallbackMonoflopDone => 19,
85 }
86 }
87}
88pub const IO4_V2_BRICKLET_DIRECTION_IN: char = 'i';
89pub const IO4_V2_BRICKLET_DIRECTION_OUT: char = 'o';
90pub const IO4_V2_BRICKLET_EDGE_TYPE_RISING: u8 = 0;
91pub const IO4_V2_BRICKLET_EDGE_TYPE_FALLING: u8 = 1;
92pub const IO4_V2_BRICKLET_EDGE_TYPE_BOTH: u8 = 2;
93pub const IO4_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
94pub const IO4_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
95pub const IO4_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
96pub const IO4_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
97pub const IO4_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
98pub const IO4_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
99pub const IO4_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
100pub const IO4_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
101pub const IO4_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
102pub const IO4_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
103pub const IO4_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
104pub const IO4_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
105pub const IO4_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
106pub const IO4_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
107pub const IO4_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
108
109#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
110pub struct Configuration {
111 pub direction: char,
112 pub value: bool,
113}
114impl FromByteSlice for Configuration {
115 fn bytes_expected() -> usize { 2 }
116 fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
117 Configuration { direction: <char>::from_le_byte_slice(&bytes[0..1]), value: <bool>::from_le_byte_slice(&bytes[1..2]) }
118 }
119}
120
121#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
122pub struct InputValueCallbackConfiguration {
123 pub period: u32,
124 pub value_has_to_change: bool,
125}
126impl FromByteSlice for InputValueCallbackConfiguration {
127 fn bytes_expected() -> usize { 5 }
128 fn from_le_byte_slice(bytes: &[u8]) -> InputValueCallbackConfiguration {
129 InputValueCallbackConfiguration {
130 period: <u32>::from_le_byte_slice(&bytes[0..4]),
131 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
132 }
133 }
134}
135
136#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
137pub struct AllInputValueCallbackConfiguration {
138 pub period: u32,
139 pub value_has_to_change: bool,
140}
141impl FromByteSlice for AllInputValueCallbackConfiguration {
142 fn bytes_expected() -> usize { 5 }
143 fn from_le_byte_slice(bytes: &[u8]) -> AllInputValueCallbackConfiguration {
144 AllInputValueCallbackConfiguration {
145 period: <u32>::from_le_byte_slice(&bytes[0..4]),
146 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
147 }
148 }
149}
150
151#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
152pub struct Monoflop {
153 pub value: bool,
154 pub time: u32,
155 pub time_remaining: u32,
156}
157impl FromByteSlice for Monoflop {
158 fn bytes_expected() -> usize { 9 }
159 fn from_le_byte_slice(bytes: &[u8]) -> Monoflop {
160 Monoflop {
161 value: <bool>::from_le_byte_slice(&bytes[0..1]),
162 time: <u32>::from_le_byte_slice(&bytes[1..5]),
163 time_remaining: <u32>::from_le_byte_slice(&bytes[5..9]),
164 }
165 }
166}
167
168#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
169pub struct EdgeCountConfiguration {
170 pub edge_type: u8,
171 pub debounce: u8,
172}
173impl FromByteSlice for EdgeCountConfiguration {
174 fn bytes_expected() -> usize { 2 }
175 fn from_le_byte_slice(bytes: &[u8]) -> EdgeCountConfiguration {
176 EdgeCountConfiguration { edge_type: <u8>::from_le_byte_slice(&bytes[0..1]), debounce: <u8>::from_le_byte_slice(&bytes[1..2]) }
177 }
178}
179
180#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
181pub struct PwmConfiguration {
182 pub frequency: u32,
183 pub duty_cycle: u16,
184}
185impl FromByteSlice for PwmConfiguration {
186 fn bytes_expected() -> usize { 6 }
187 fn from_le_byte_slice(bytes: &[u8]) -> PwmConfiguration {
188 PwmConfiguration { frequency: <u32>::from_le_byte_slice(&bytes[0..4]), duty_cycle: <u16>::from_le_byte_slice(&bytes[4..6]) }
189 }
190}
191
192#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
193pub struct InputValueEvent {
194 pub channel: u8,
195 pub changed: bool,
196 pub value: bool,
197}
198impl FromByteSlice for InputValueEvent {
199 fn bytes_expected() -> usize { 3 }
200 fn from_le_byte_slice(bytes: &[u8]) -> InputValueEvent {
201 InputValueEvent {
202 channel: <u8>::from_le_byte_slice(&bytes[0..1]),
203 changed: <bool>::from_le_byte_slice(&bytes[1..2]),
204 value: <bool>::from_le_byte_slice(&bytes[2..3]),
205 }
206 }
207}
208
209#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
210pub struct AllInputValueEvent {
211 pub changed: [bool; 4],
212 pub value: [bool; 4],
213}
214impl FromByteSlice for AllInputValueEvent {
215 fn bytes_expected() -> usize { 2 }
216 fn from_le_byte_slice(bytes: &[u8]) -> AllInputValueEvent {
217 AllInputValueEvent { changed: <[bool; 4]>::from_le_byte_slice(&bytes[0..1]), value: <[bool; 4]>::from_le_byte_slice(&bytes[1..2]) }
218 }
219}
220
221#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
222pub struct MonoflopDoneEvent {
223 pub channel: u8,
224 pub value: bool,
225}
226impl FromByteSlice for MonoflopDoneEvent {
227 fn bytes_expected() -> usize { 2 }
228 fn from_le_byte_slice(bytes: &[u8]) -> MonoflopDoneEvent {
229 MonoflopDoneEvent { channel: <u8>::from_le_byte_slice(&bytes[0..1]), value: <bool>::from_le_byte_slice(&bytes[1..2]) }
230 }
231}
232
233#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
234pub struct SpitfpErrorCount {
235 pub error_count_ack_checksum: u32,
236 pub error_count_message_checksum: u32,
237 pub error_count_frame: u32,
238 pub error_count_overflow: u32,
239}
240impl FromByteSlice for SpitfpErrorCount {
241 fn bytes_expected() -> usize { 16 }
242 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
243 SpitfpErrorCount {
244 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
245 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
246 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
247 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
248 }
249 }
250}
251
252#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
253pub struct Identity {
254 pub uid: String,
255 pub connected_uid: String,
256 pub position: char,
257 pub hardware_version: [u8; 3],
258 pub firmware_version: [u8; 3],
259 pub device_identifier: u16,
260}
261impl FromByteSlice for Identity {
262 fn bytes_expected() -> usize { 25 }
263 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
264 Identity {
265 uid: <String>::from_le_byte_slice(&bytes[0..8]),
266 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
267 position: <char>::from_le_byte_slice(&bytes[16..17]),
268 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
269 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
270 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
271 }
272 }
273}
274
275#[derive(Clone)]
277pub struct Io4V2Bricklet {
278 device: Device,
279}
280impl Io4V2Bricklet {
281 pub const DEVICE_IDENTIFIER: u16 = 2111;
282 pub const DEVICE_DISPLAY_NAME: &'static str = "IO-4 Bricklet 2.0";
283 pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> Io4V2Bricklet {
285 let mut result = Io4V2Bricklet { device: Device::new([2, 0, 0], uid, req_sender, 0) };
286 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetValue) as usize] = ResponseExpectedFlag::False;
287 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetValue) as usize] = ResponseExpectedFlag::AlwaysTrue;
288 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetSelectedValue) as usize] = ResponseExpectedFlag::False;
289 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
290 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
291 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetInputValueCallbackConfiguration) as usize] =
292 ResponseExpectedFlag::True;
293 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetInputValueCallbackConfiguration) as usize] =
294 ResponseExpectedFlag::AlwaysTrue;
295 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetAllInputValueCallbackConfiguration) as usize] =
296 ResponseExpectedFlag::True;
297 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetAllInputValueCallbackConfiguration) as usize] =
298 ResponseExpectedFlag::AlwaysTrue;
299 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetMonoflop) as usize] = ResponseExpectedFlag::False;
300 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetMonoflop) as usize] = ResponseExpectedFlag::AlwaysTrue;
301 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetEdgeCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
302 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetEdgeCountConfiguration) as usize] = ResponseExpectedFlag::False;
303 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetEdgeCountConfiguration) as usize] =
304 ResponseExpectedFlag::AlwaysTrue;
305 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetPwmConfiguration) as usize] = ResponseExpectedFlag::False;
306 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetPwmConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
307 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
308 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
309 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
310 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
311 result.device.response_expected[u8::from(Io4V2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
312 result.device.response_expected[u8::from(Io4V2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
313 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
314 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
315 result.device.response_expected[u8::from(Io4V2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
316 result.device.response_expected[u8::from(Io4V2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
317 result.device.response_expected[u8::from(Io4V2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
318 result.device.response_expected[u8::from(Io4V2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
319 result
320 }
321
322 pub fn get_response_expected(&mut self, fun: Io4V2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
337 self.device.get_response_expected(u8::from(fun))
338 }
339
340 pub fn set_response_expected(&mut self, fun: Io4V2BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
349 self.device.set_response_expected(u8::from(fun), response_expected)
350 }
351
352 pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
354
355 pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
358
359 pub fn get_input_value_callback_receiver(&self) -> ConvertingCallbackReceiver<InputValueEvent> {
368 self.device.get_callback_receiver(u8::from(Io4V2BrickletFunction::CallbackInputValue))
369 }
370
371 pub fn get_all_input_value_callback_receiver(&self) -> ConvertingCallbackReceiver<AllInputValueEvent> {
378 self.device.get_callback_receiver(u8::from(Io4V2BrickletFunction::CallbackAllInputValue))
379 }
380
381 pub fn get_monoflop_done_callback_receiver(&self) -> ConvertingCallbackReceiver<MonoflopDoneEvent> {
385 self.device.get_callback_receiver(u8::from(Io4V2BrickletFunction::CallbackMonoflopDone))
386 }
387
388 pub fn set_value(&self, value: [bool; 4]) -> ConvertingReceiver<()> {
402 let mut payload = vec![0; 1];
403 payload[0..1].copy_from_slice(&<[bool; 4]>::to_le_byte_vec(value));
404
405 self.device.set(u8::from(Io4V2BrickletFunction::SetValue), payload)
406 }
407
408 pub fn get_value(&self) -> ConvertingReceiver<[bool; 4]> {
412 let payload = vec![0; 0];
413
414 self.device.get(u8::from(Io4V2BrickletFunction::GetValue), payload)
415 }
416
417 pub fn set_selected_value(&self, channel: u8, value: bool) -> ConvertingReceiver<()> {
426 let mut payload = vec![0; 2];
427 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
428 payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(value));
429
430 self.device.set(u8::from(Io4V2BrickletFunction::SetSelectedValue), payload)
431 }
432
433 pub fn set_configuration(&self, channel: u8, direction: char, value: bool) -> ConvertingReceiver<()> {
456 let mut payload = vec![0; 3];
457 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
458 payload[1..2].copy_from_slice(&<char>::to_le_byte_vec(direction));
459 payload[2..3].copy_from_slice(&<bool>::to_le_byte_vec(value));
460
461 self.device.set(u8::from(Io4V2BrickletFunction::SetConfiguration), payload)
462 }
463
464 pub fn get_configuration(&self, channel: u8) -> ConvertingReceiver<Configuration> {
470 let mut payload = vec![0; 1];
471 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
472
473 self.device.get(u8::from(Io4V2BrickletFunction::GetConfiguration), payload)
474 }
475
476 pub fn set_input_value_callback_configuration(&self, channel: u8, period: u32, value_has_to_change: bool) -> ConvertingReceiver<()> {
488 let mut payload = vec![0; 6];
489 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
490 payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(period));
491 payload[5..6].copy_from_slice(&<bool>::to_le_byte_vec(value_has_to_change));
492
493 self.device.set(u8::from(Io4V2BrickletFunction::SetInputValueCallbackConfiguration), payload)
494 }
495
496 pub fn get_input_value_callback_configuration(&self, channel: u8) -> ConvertingReceiver<InputValueCallbackConfiguration> {
499 let mut payload = vec![0; 1];
500 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
501
502 self.device.get(u8::from(Io4V2BrickletFunction::GetInputValueCallbackConfiguration), payload)
503 }
504
505 pub fn set_all_input_value_callback_configuration(&self, period: u32, value_has_to_change: bool) -> ConvertingReceiver<()> {
515 let mut payload = vec![0; 5];
516 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
517 payload[4..5].copy_from_slice(&<bool>::to_le_byte_vec(value_has_to_change));
518
519 self.device.set(u8::from(Io4V2BrickletFunction::SetAllInputValueCallbackConfiguration), payload)
520 }
521
522 pub fn get_all_input_value_callback_configuration(&self) -> ConvertingReceiver<AllInputValueCallbackConfiguration> {
525 let payload = vec![0; 0];
526
527 self.device.get(u8::from(Io4V2BrickletFunction::GetAllInputValueCallbackConfiguration), payload)
528 }
529
530 pub fn set_monoflop(&self, channel: u8, value: bool, time: u32) -> ConvertingReceiver<()> {
545 let mut payload = vec![0; 6];
546 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
547 payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(value));
548 payload[2..6].copy_from_slice(&<u32>::to_le_byte_vec(time));
549
550 self.device.set(u8::from(Io4V2BrickletFunction::SetMonoflop), payload)
551 }
552
553 pub fn get_monoflop(&self, channel: u8) -> ConvertingReceiver<Monoflop> {
559 let mut payload = vec![0; 1];
560 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
561
562 self.device.get(u8::from(Io4V2BrickletFunction::GetMonoflop), payload)
563 }
564
565 pub fn get_edge_count(&self, channel: u8, reset_counter: bool) -> ConvertingReceiver<u32> {
574 let mut payload = vec![0; 2];
575 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
576 payload[1..2].copy_from_slice(&<bool>::to_le_byte_vec(reset_counter));
577
578 self.device.get(u8::from(Io4V2BrickletFunction::GetEdgeCount), payload)
579 }
580
581 pub fn set_edge_count_configuration(&self, channel: u8, edge_type: u8, debounce: u8) -> ConvertingReceiver<()> {
603 let mut payload = vec![0; 3];
604 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
605 payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(edge_type));
606 payload[2..3].copy_from_slice(&<u8>::to_le_byte_vec(debounce));
607
608 self.device.set(u8::from(Io4V2BrickletFunction::SetEdgeCountConfiguration), payload)
609 }
610
611 pub fn get_edge_count_configuration(&self, channel: u8) -> ConvertingReceiver<EdgeCountConfiguration> {
622 let mut payload = vec![0; 1];
623 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
624
625 self.device.get(u8::from(Io4V2BrickletFunction::GetEdgeCountConfiguration), payload)
626 }
627
628 pub fn set_pwm_configuration(&self, channel: u8, frequency: u32, duty_cycle: u16) -> ConvertingReceiver<()> {
637 let mut payload = vec![0; 7];
638 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
639 payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(frequency));
640 payload[5..7].copy_from_slice(&<u16>::to_le_byte_vec(duty_cycle));
641
642 self.device.set(u8::from(Io4V2BrickletFunction::SetPwmConfiguration), payload)
643 }
644
645 pub fn get_pwm_configuration(&self, channel: u8) -> ConvertingReceiver<PwmConfiguration> {
647 let mut payload = vec![0; 1];
648 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(channel));
649
650 self.device.get(u8::from(Io4V2BrickletFunction::GetPwmConfiguration), payload)
651 }
652
653 pub fn get_spitfp_error_count(&self) -> ConvertingReceiver<SpitfpErrorCount> {
665 let payload = vec![0; 0];
666
667 self.device.get(u8::from(Io4V2BrickletFunction::GetSpitfpErrorCount), payload)
668 }
669
670 pub fn set_bootloader_mode(&self, mode: u8) -> ConvertingReceiver<u8> {
693 let mut payload = vec![0; 1];
694 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
695
696 self.device.get(u8::from(Io4V2BrickletFunction::SetBootloaderMode), payload)
697 }
698
699 pub fn get_bootloader_mode(&self) -> ConvertingReceiver<u8> {
708 let payload = vec![0; 0];
709
710 self.device.get(u8::from(Io4V2BrickletFunction::GetBootloaderMode), payload)
711 }
712
713 pub fn set_write_firmware_pointer(&self, pointer: u32) -> ConvertingReceiver<()> {
720 let mut payload = vec![0; 4];
721 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(pointer));
722
723 self.device.set(u8::from(Io4V2BrickletFunction::SetWriteFirmwarePointer), payload)
724 }
725
726 pub fn write_firmware(&self, data: [u8; 64]) -> ConvertingReceiver<u8> {
735 let mut payload = vec![0; 64];
736 payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));
737
738 self.device.get(u8::from(Io4V2BrickletFunction::WriteFirmware), payload)
739 }
740
741 pub fn set_status_led_config(&self, config: u8) -> ConvertingReceiver<()> {
755 let mut payload = vec![0; 1];
756 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
757
758 self.device.set(u8::from(Io4V2BrickletFunction::SetStatusLedConfig), payload)
759 }
760
761 pub fn get_status_led_config(&self) -> ConvertingReceiver<u8> {
769 let payload = vec![0; 0];
770
771 self.device.get(u8::from(Io4V2BrickletFunction::GetStatusLedConfig), payload)
772 }
773
774 pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
781 let payload = vec![0; 0];
782
783 self.device.get(u8::from(Io4V2BrickletFunction::GetChipTemperature), payload)
784 }
785
786 pub fn reset(&self) -> ConvertingReceiver<()> {
793 let payload = vec![0; 0];
794
795 self.device.set(u8::from(Io4V2BrickletFunction::Reset), payload)
796 }
797
798 pub fn write_uid(&self, uid: u32) -> ConvertingReceiver<()> {
804 let mut payload = vec![0; 4];
805 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(uid));
806
807 self.device.set(u8::from(Io4V2BrickletFunction::WriteUid), payload)
808 }
809
810 pub fn read_uid(&self) -> ConvertingReceiver<u32> {
813 let payload = vec![0; 0];
814
815 self.device.get(u8::from(Io4V2BrickletFunction::ReadUid), payload)
816 }
817
818 pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
829 let payload = vec![0; 0];
830
831 self.device.get(u8::from(Io4V2BrickletFunction::GetIdentity), payload)
832 }
833}