1#[allow(unused_imports)]
15use crate::{
16 base58::Uid, byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection,
17 low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum Io16V2BrickletFunction {
24 SetValue,
25 GetValue,
26 SetSelectedValue,
27 SetConfiguration,
28 GetConfiguration,
29 SetInputValueCallbackConfiguration,
30 GetInputValueCallbackConfiguration,
31 SetAllInputValueCallbackConfiguration,
32 GetAllInputValueCallbackConfiguration,
33 SetMonoflop,
34 GetMonoflop,
35 GetEdgeCount,
36 SetEdgeCountConfiguration,
37 GetEdgeCountConfiguration,
38 GetSpitfpErrorCount,
39 SetBootloaderMode,
40 GetBootloaderMode,
41 SetWriteFirmwarePointer,
42 WriteFirmware,
43 SetStatusLedConfig,
44 GetStatusLedConfig,
45 GetChipTemperature,
46 Reset,
47 WriteUid,
48 ReadUid,
49 GetIdentity,
50 CallbackInputValue,
51 CallbackAllInputValue,
52 CallbackMonoflopDone,
53}
54impl From<Io16V2BrickletFunction> for u8 {
55 fn from(fun: Io16V2BrickletFunction) -> Self {
56 match fun {
57 Io16V2BrickletFunction::SetValue => 1,
58 Io16V2BrickletFunction::GetValue => 2,
59 Io16V2BrickletFunction::SetSelectedValue => 3,
60 Io16V2BrickletFunction::SetConfiguration => 4,
61 Io16V2BrickletFunction::GetConfiguration => 5,
62 Io16V2BrickletFunction::SetInputValueCallbackConfiguration => 6,
63 Io16V2BrickletFunction::GetInputValueCallbackConfiguration => 7,
64 Io16V2BrickletFunction::SetAllInputValueCallbackConfiguration => 8,
65 Io16V2BrickletFunction::GetAllInputValueCallbackConfiguration => 9,
66 Io16V2BrickletFunction::SetMonoflop => 10,
67 Io16V2BrickletFunction::GetMonoflop => 11,
68 Io16V2BrickletFunction::GetEdgeCount => 12,
69 Io16V2BrickletFunction::SetEdgeCountConfiguration => 13,
70 Io16V2BrickletFunction::GetEdgeCountConfiguration => 14,
71 Io16V2BrickletFunction::GetSpitfpErrorCount => 234,
72 Io16V2BrickletFunction::SetBootloaderMode => 235,
73 Io16V2BrickletFunction::GetBootloaderMode => 236,
74 Io16V2BrickletFunction::SetWriteFirmwarePointer => 237,
75 Io16V2BrickletFunction::WriteFirmware => 238,
76 Io16V2BrickletFunction::SetStatusLedConfig => 239,
77 Io16V2BrickletFunction::GetStatusLedConfig => 240,
78 Io16V2BrickletFunction::GetChipTemperature => 242,
79 Io16V2BrickletFunction::Reset => 243,
80 Io16V2BrickletFunction::WriteUid => 248,
81 Io16V2BrickletFunction::ReadUid => 249,
82 Io16V2BrickletFunction::GetIdentity => 255,
83 Io16V2BrickletFunction::CallbackInputValue => 15,
84 Io16V2BrickletFunction::CallbackAllInputValue => 16,
85 Io16V2BrickletFunction::CallbackMonoflopDone => 17,
86 }
87 }
88}
89pub const IO16_V2_BRICKLET_DIRECTION_IN: char = 'i';
90pub const IO16_V2_BRICKLET_DIRECTION_OUT: char = 'o';
91pub const IO16_V2_BRICKLET_EDGE_TYPE_RISING: u8 = 0;
92pub const IO16_V2_BRICKLET_EDGE_TYPE_FALLING: u8 = 1;
93pub const IO16_V2_BRICKLET_EDGE_TYPE_BOTH: u8 = 2;
94pub const IO16_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
95pub const IO16_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
96pub const IO16_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
97pub const IO16_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
98pub const IO16_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
99pub const IO16_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
100pub const IO16_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
101pub const IO16_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
102pub const IO16_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
103pub const IO16_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
104pub const IO16_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
105pub const IO16_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
106pub const IO16_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
107pub const IO16_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
108pub const IO16_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
109
110#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
111pub struct Configuration {
112 pub direction: char,
113 pub value: bool,
114}
115impl FromByteSlice for Configuration {
116 fn bytes_expected() -> usize {
117 2
118 }
119 fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
120 Configuration { direction: <char>::from_le_byte_slice(&bytes[0..1]), value: <bool>::from_le_byte_slice(&bytes[1..2]) }
121 }
122}
123
124#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
125pub struct InputValueCallbackConfiguration {
126 pub period: u32,
127 pub value_has_to_change: bool,
128}
129impl FromByteSlice for InputValueCallbackConfiguration {
130 fn bytes_expected() -> usize {
131 5
132 }
133 fn from_le_byte_slice(bytes: &[u8]) -> InputValueCallbackConfiguration {
134 InputValueCallbackConfiguration {
135 period: <u32>::from_le_byte_slice(&bytes[0..4]),
136 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
137 }
138 }
139}
140
141#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
142pub struct AllInputValueCallbackConfiguration {
143 pub period: u32,
144 pub value_has_to_change: bool,
145}
146impl FromByteSlice for AllInputValueCallbackConfiguration {
147 fn bytes_expected() -> usize {
148 5
149 }
150 fn from_le_byte_slice(bytes: &[u8]) -> AllInputValueCallbackConfiguration {
151 AllInputValueCallbackConfiguration {
152 period: <u32>::from_le_byte_slice(&bytes[0..4]),
153 value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
154 }
155 }
156}
157
158#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
159pub struct Monoflop {
160 pub value: bool,
161 pub time: u32,
162 pub time_remaining: u32,
163}
164impl FromByteSlice for Monoflop {
165 fn bytes_expected() -> usize {
166 9
167 }
168 fn from_le_byte_slice(bytes: &[u8]) -> Monoflop {
169 Monoflop {
170 value: <bool>::from_le_byte_slice(&bytes[0..1]),
171 time: <u32>::from_le_byte_slice(&bytes[1..5]),
172 time_remaining: <u32>::from_le_byte_slice(&bytes[5..9]),
173 }
174 }
175}
176
177#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
178pub struct EdgeCountConfiguration {
179 pub edge_type: u8,
180 pub debounce: u8,
181}
182impl FromByteSlice for EdgeCountConfiguration {
183 fn bytes_expected() -> usize {
184 2
185 }
186 fn from_le_byte_slice(bytes: &[u8]) -> EdgeCountConfiguration {
187 EdgeCountConfiguration { edge_type: <u8>::from_le_byte_slice(&bytes[0..1]), debounce: <u8>::from_le_byte_slice(&bytes[1..2]) }
188 }
189}
190
191#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
192pub struct InputValueEvent {
193 pub channel: u8,
194 pub changed: bool,
195 pub value: bool,
196}
197impl FromByteSlice for InputValueEvent {
198 fn bytes_expected() -> usize {
199 3
200 }
201 fn from_le_byte_slice(bytes: &[u8]) -> InputValueEvent {
202 InputValueEvent {
203 channel: <u8>::from_le_byte_slice(&bytes[0..1]),
204 changed: <bool>::from_le_byte_slice(&bytes[1..2]),
205 value: <bool>::from_le_byte_slice(&bytes[2..3]),
206 }
207 }
208}
209
210#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
211pub struct AllInputValueEvent {
212 pub changed: [bool; 16],
213 pub value: [bool; 16],
214}
215impl FromByteSlice for AllInputValueEvent {
216 fn bytes_expected() -> usize {
217 4
218 }
219 fn from_le_byte_slice(bytes: &[u8]) -> AllInputValueEvent {
220 AllInputValueEvent {
221 changed: <[bool; 16]>::from_le_byte_slice(&bytes[0..2]),
222 value: <[bool; 16]>::from_le_byte_slice(&bytes[2..4]),
223 }
224 }
225}
226
227#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
228pub struct MonoflopDoneEvent {
229 pub channel: u8,
230 pub value: bool,
231}
232impl FromByteSlice for MonoflopDoneEvent {
233 fn bytes_expected() -> usize {
234 2
235 }
236 fn from_le_byte_slice(bytes: &[u8]) -> MonoflopDoneEvent {
237 MonoflopDoneEvent { channel: <u8>::from_le_byte_slice(&bytes[0..1]), value: <bool>::from_le_byte_slice(&bytes[1..2]) }
238 }
239}
240
241#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
242pub struct SpitfpErrorCount {
243 pub error_count_ack_checksum: u32,
244 pub error_count_message_checksum: u32,
245 pub error_count_frame: u32,
246 pub error_count_overflow: u32,
247}
248impl FromByteSlice for SpitfpErrorCount {
249 fn bytes_expected() -> usize {
250 16
251 }
252 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
253 SpitfpErrorCount {
254 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
255 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
256 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
257 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
258 }
259 }
260}
261
262#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
263pub struct Identity {
264 pub uid: String,
265 pub connected_uid: String,
266 pub position: char,
267 pub hardware_version: [u8; 3],
268 pub firmware_version: [u8; 3],
269 pub device_identifier: u16,
270}
271impl FromByteSlice for Identity {
272 fn bytes_expected() -> usize {
273 25
274 }
275 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
276 Identity {
277 uid: <String>::from_le_byte_slice(&bytes[0..8]),
278 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
279 position: <char>::from_le_byte_slice(&bytes[16..17]),
280 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
281 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
282 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
283 }
284 }
285}
286
287#[derive(Clone)]
289pub struct Io16V2Bricklet {
290 device: Device,
291}
292impl Io16V2Bricklet {
293 pub const DEVICE_IDENTIFIER: u16 = 2114;
294 pub const DEVICE_DISPLAY_NAME: &'static str = "IO-16 Bricklet 2.0";
295 pub fn new(uid: Uid, connection: AsyncIpConnection) -> Io16V2Bricklet {
297 let mut result = Io16V2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
298 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetValue) as usize] = ResponseExpectedFlag::False;
299 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetValue) as usize] = ResponseExpectedFlag::AlwaysTrue;
300 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetSelectedValue) as usize] = ResponseExpectedFlag::False;
301 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
302 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
303 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetInputValueCallbackConfiguration) as usize] =
304 ResponseExpectedFlag::True;
305 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetInputValueCallbackConfiguration) as usize] =
306 ResponseExpectedFlag::AlwaysTrue;
307 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetAllInputValueCallbackConfiguration) as usize] =
308 ResponseExpectedFlag::True;
309 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetAllInputValueCallbackConfiguration) as usize] =
310 ResponseExpectedFlag::AlwaysTrue;
311 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetMonoflop) as usize] = ResponseExpectedFlag::False;
312 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetMonoflop) as usize] = ResponseExpectedFlag::AlwaysTrue;
313 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetEdgeCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
314 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetEdgeCountConfiguration) as usize] = ResponseExpectedFlag::False;
315 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetEdgeCountConfiguration) as usize] =
316 ResponseExpectedFlag::AlwaysTrue;
317 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
318 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
319 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
320 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
321 result.device.response_expected[u8::from(Io16V2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
322 result.device.response_expected[u8::from(Io16V2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
323 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
324 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
325 result.device.response_expected[u8::from(Io16V2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
326 result.device.response_expected[u8::from(Io16V2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
327 result.device.response_expected[u8::from(Io16V2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
328 result.device.response_expected[u8::from(Io16V2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
329 result
330 }
331
332 pub fn get_response_expected(&mut self, fun: Io16V2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
347 self.device.get_response_expected(u8::from(fun))
348 }
349
350 pub fn set_response_expected(&mut self, fun: Io16V2BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
359 self.device.set_response_expected(u8::from(fun), response_expected)
360 }
361
362 pub fn set_response_expected_all(&mut self, response_expected: bool) {
364 self.device.set_response_expected_all(response_expected)
365 }
366
367 pub fn get_api_version(&self) -> [u8; 3] {
370 self.device.api_version
371 }
372
373 pub async fn get_input_value_callback_receiver(&mut self) -> impl Stream<Item = InputValueEvent> {
382 self.device
383 .get_callback_receiver(u8::from(Io16V2BrickletFunction::CallbackInputValue))
384 .await
385 .map(|p| InputValueEvent::from_le_byte_slice(p.body()))
386 }
387
388 pub async fn get_all_input_value_callback_receiver(&mut self) -> impl Stream<Item = AllInputValueEvent> {
395 self.device
396 .get_callback_receiver(u8::from(Io16V2BrickletFunction::CallbackAllInputValue))
397 .await
398 .map(|p| AllInputValueEvent::from_le_byte_slice(p.body()))
399 }
400
401 pub async fn get_monoflop_done_callback_receiver(&mut self) -> impl Stream<Item = MonoflopDoneEvent> {
405 self.device
406 .get_callback_receiver(u8::from(Io16V2BrickletFunction::CallbackMonoflopDone))
407 .await
408 .map(|p| MonoflopDoneEvent::from_le_byte_slice(p.body()))
409 }
410
411 pub async fn set_value(&mut self, value: &[bool; 16]) -> Result<(), TinkerforgeError> {
425 let mut payload = [0; 2];
426 value.write_to_slice(&mut payload[0..2]);
427
428 #[allow(unused_variables)]
429 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetValue), &payload).await?;
430 Ok(())
431 }
432
433 pub async fn get_value(&mut self) -> Result<Box<[bool; 16]>, TinkerforgeError> {
437 let payload = [0; 0];
438
439 #[allow(unused_variables)]
440 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetValue), &payload).await?;
441 Ok(Box::<[bool; 16]>::from_le_byte_slice(result.body()))
442 }
443
444 pub async fn set_selected_value(&mut self, channel: u8, value: bool) -> Result<(), TinkerforgeError> {
453 let mut payload = [0; 2];
454 channel.write_to_slice(&mut payload[0..1]);
455 value.write_to_slice(&mut payload[1..2]);
456
457 #[allow(unused_variables)]
458 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetSelectedValue), &payload).await?;
459 Ok(())
460 }
461
462 pub async fn set_configuration(&mut self, channel: u8, direction: char, value: bool) -> Result<(), TinkerforgeError> {
485 let mut payload = [0; 3];
486 channel.write_to_slice(&mut payload[0..1]);
487 direction.write_to_slice(&mut payload[1..2]);
488 value.write_to_slice(&mut payload[2..3]);
489
490 #[allow(unused_variables)]
491 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetConfiguration), &payload).await?;
492 Ok(())
493 }
494
495 pub async fn get_configuration(&mut self, channel: u8) -> Result<Configuration, TinkerforgeError> {
501 let mut payload = [0; 1];
502 channel.write_to_slice(&mut payload[0..1]);
503
504 #[allow(unused_variables)]
505 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetConfiguration), &payload).await?;
506 Ok(Configuration::from_le_byte_slice(result.body()))
507 }
508
509 pub async fn set_input_value_callback_configuration(
521 &mut self,
522 channel: u8,
523 period: u32,
524 value_has_to_change: bool,
525 ) -> Result<(), TinkerforgeError> {
526 let mut payload = [0; 6];
527 channel.write_to_slice(&mut payload[0..1]);
528 period.write_to_slice(&mut payload[1..5]);
529 value_has_to_change.write_to_slice(&mut payload[5..6]);
530
531 #[allow(unused_variables)]
532 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetInputValueCallbackConfiguration), &payload).await?;
533 Ok(())
534 }
535
536 pub async fn get_input_value_callback_configuration(
539 &mut self,
540 channel: u8,
541 ) -> Result<InputValueCallbackConfiguration, TinkerforgeError> {
542 let mut payload = [0; 1];
543 channel.write_to_slice(&mut payload[0..1]);
544
545 #[allow(unused_variables)]
546 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetInputValueCallbackConfiguration), &payload).await?;
547 Ok(InputValueCallbackConfiguration::from_le_byte_slice(result.body()))
548 }
549
550 pub async fn set_all_input_value_callback_configuration(
560 &mut self,
561 period: u32,
562 value_has_to_change: bool,
563 ) -> Result<(), TinkerforgeError> {
564 let mut payload = [0; 5];
565 period.write_to_slice(&mut payload[0..4]);
566 value_has_to_change.write_to_slice(&mut payload[4..5]);
567
568 #[allow(unused_variables)]
569 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetAllInputValueCallbackConfiguration), &payload).await?;
570 Ok(())
571 }
572
573 pub async fn get_all_input_value_callback_configuration(&mut self) -> Result<AllInputValueCallbackConfiguration, TinkerforgeError> {
576 let payload = [0; 0];
577
578 #[allow(unused_variables)]
579 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetAllInputValueCallbackConfiguration), &payload).await?;
580 Ok(AllInputValueCallbackConfiguration::from_le_byte_slice(result.body()))
581 }
582
583 pub async fn set_monoflop(&mut self, channel: u8, value: bool, time: u32) -> Result<(), TinkerforgeError> {
601 let mut payload = [0; 6];
602 channel.write_to_slice(&mut payload[0..1]);
603 value.write_to_slice(&mut payload[1..2]);
604 time.write_to_slice(&mut payload[2..6]);
605
606 #[allow(unused_variables)]
607 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetMonoflop), &payload).await?;
608 Ok(())
609 }
610
611 pub async fn get_monoflop(&mut self, channel: u8) -> Result<Monoflop, TinkerforgeError> {
617 let mut payload = [0; 1];
618 channel.write_to_slice(&mut payload[0..1]);
619
620 #[allow(unused_variables)]
621 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetMonoflop), &payload).await?;
622 Ok(Monoflop::from_le_byte_slice(result.body()))
623 }
624
625 pub async fn get_edge_count(&mut self, channel: u8, reset_counter: bool) -> Result<u32, TinkerforgeError> {
631 let mut payload = [0; 2];
632 channel.write_to_slice(&mut payload[0..1]);
633 reset_counter.write_to_slice(&mut payload[1..2]);
634
635 #[allow(unused_variables)]
636 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetEdgeCount), &payload).await?;
637 Ok(u32::from_le_byte_slice(result.body()))
638 }
639
640 pub async fn set_edge_count_configuration(&mut self, channel: u8, edge_type: u8, debounce: u8) -> Result<(), TinkerforgeError> {
659 let mut payload = [0; 3];
660 channel.write_to_slice(&mut payload[0..1]);
661 edge_type.write_to_slice(&mut payload[1..2]);
662 debounce.write_to_slice(&mut payload[2..3]);
663
664 #[allow(unused_variables)]
665 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetEdgeCountConfiguration), &payload).await?;
666 Ok(())
667 }
668
669 pub async fn get_edge_count_configuration(&mut self, channel: u8) -> Result<EdgeCountConfiguration, TinkerforgeError> {
677 let mut payload = [0; 1];
678 channel.write_to_slice(&mut payload[0..1]);
679
680 #[allow(unused_variables)]
681 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetEdgeCountConfiguration), &payload).await?;
682 Ok(EdgeCountConfiguration::from_le_byte_slice(result.body()))
683 }
684
685 pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
697 let payload = [0; 0];
698
699 #[allow(unused_variables)]
700 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
701 Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
702 }
703
704 pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
727 let mut payload = [0; 1];
728 mode.write_to_slice(&mut payload[0..1]);
729
730 #[allow(unused_variables)]
731 let result = self.device.get(u8::from(Io16V2BrickletFunction::SetBootloaderMode), &payload).await?;
732 Ok(u8::from_le_byte_slice(result.body()))
733 }
734
735 pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
744 let payload = [0; 0];
745
746 #[allow(unused_variables)]
747 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetBootloaderMode), &payload).await?;
748 Ok(u8::from_le_byte_slice(result.body()))
749 }
750
751 pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
758 let mut payload = [0; 4];
759 pointer.write_to_slice(&mut payload[0..4]);
760
761 #[allow(unused_variables)]
762 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
763 Ok(())
764 }
765
766 pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
775 let mut payload = [0; 64];
776 data.write_to_slice(&mut payload[0..64]);
777
778 #[allow(unused_variables)]
779 let result = self.device.get(u8::from(Io16V2BrickletFunction::WriteFirmware), &payload).await?;
780 Ok(u8::from_le_byte_slice(result.body()))
781 }
782
783 pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
797 let mut payload = [0; 1];
798 config.write_to_slice(&mut payload[0..1]);
799
800 #[allow(unused_variables)]
801 let result = self.device.set(u8::from(Io16V2BrickletFunction::SetStatusLedConfig), &payload).await?;
802 Ok(())
803 }
804
805 pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
813 let payload = [0; 0];
814
815 #[allow(unused_variables)]
816 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetStatusLedConfig), &payload).await?;
817 Ok(u8::from_le_byte_slice(result.body()))
818 }
819
820 pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
827 let payload = [0; 0];
828
829 #[allow(unused_variables)]
830 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetChipTemperature), &payload).await?;
831 Ok(i16::from_le_byte_slice(result.body()))
832 }
833
834 pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
841 let payload = [0; 0];
842
843 #[allow(unused_variables)]
844 let result = self.device.set(u8::from(Io16V2BrickletFunction::Reset), &payload).await?;
845 Ok(())
846 }
847
848 pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
854 let mut payload = [0; 4];
855 uid.write_to_slice(&mut payload[0..4]);
856
857 #[allow(unused_variables)]
858 let result = self.device.set(u8::from(Io16V2BrickletFunction::WriteUid), &payload).await?;
859 Ok(())
860 }
861
862 pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
865 let payload = [0; 0];
866
867 #[allow(unused_variables)]
868 let result = self.device.get(u8::from(Io16V2BrickletFunction::ReadUid), &payload).await?;
869 Ok(u32::from_le_byte_slice(result.body()))
870 }
871
872 pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
883 let payload = [0; 0];
884
885 #[allow(unused_variables)]
886 let result = self.device.get(u8::from(Io16V2BrickletFunction::GetIdentity), &payload).await?;
887 Ok(Identity::from_le_byte_slice(result.body()))
888 }
889}