tinkerforge_async/bindings/
io4_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! 4-channel digital input/output.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/IO4_Bricklet_Rust.html).
14#[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 Io4BrickletFunction {
24    SetValue,
25    GetValue,
26    SetConfiguration,
27    GetConfiguration,
28    SetDebouncePeriod,
29    GetDebouncePeriod,
30    SetInterrupt,
31    GetInterrupt,
32    SetMonoflop,
33    GetMonoflop,
34    SetSelectedValues,
35    GetEdgeCount,
36    SetEdgeCountConfig,
37    GetEdgeCountConfig,
38    GetIdentity,
39    CallbackInterrupt,
40    CallbackMonoflopDone,
41}
42impl From<Io4BrickletFunction> for u8 {
43    fn from(fun: Io4BrickletFunction) -> Self {
44        match fun {
45            Io4BrickletFunction::SetValue => 1,
46            Io4BrickletFunction::GetValue => 2,
47            Io4BrickletFunction::SetConfiguration => 3,
48            Io4BrickletFunction::GetConfiguration => 4,
49            Io4BrickletFunction::SetDebouncePeriod => 5,
50            Io4BrickletFunction::GetDebouncePeriod => 6,
51            Io4BrickletFunction::SetInterrupt => 7,
52            Io4BrickletFunction::GetInterrupt => 8,
53            Io4BrickletFunction::SetMonoflop => 10,
54            Io4BrickletFunction::GetMonoflop => 11,
55            Io4BrickletFunction::SetSelectedValues => 13,
56            Io4BrickletFunction::GetEdgeCount => 14,
57            Io4BrickletFunction::SetEdgeCountConfig => 15,
58            Io4BrickletFunction::GetEdgeCountConfig => 16,
59            Io4BrickletFunction::GetIdentity => 255,
60            Io4BrickletFunction::CallbackInterrupt => 9,
61            Io4BrickletFunction::CallbackMonoflopDone => 12,
62        }
63    }
64}
65pub const IO4_BRICKLET_DIRECTION_IN: char = 'i';
66pub const IO4_BRICKLET_DIRECTION_OUT: char = 'o';
67pub const IO4_BRICKLET_EDGE_TYPE_RISING: u8 = 0;
68pub const IO4_BRICKLET_EDGE_TYPE_FALLING: u8 = 1;
69pub const IO4_BRICKLET_EDGE_TYPE_BOTH: u8 = 2;
70
71#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
72pub struct Configuration {
73    pub direction_mask: u8,
74    pub value_mask: u8,
75}
76impl FromByteSlice for Configuration {
77    fn bytes_expected() -> usize {
78        2
79    }
80    fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
81        Configuration { direction_mask: <u8>::from_le_byte_slice(&bytes[0..1]), value_mask: <u8>::from_le_byte_slice(&bytes[1..2]) }
82    }
83}
84
85#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
86pub struct InterruptEvent {
87    pub interrupt_mask: u8,
88    pub value_mask: u8,
89}
90impl FromByteSlice for InterruptEvent {
91    fn bytes_expected() -> usize {
92        2
93    }
94    fn from_le_byte_slice(bytes: &[u8]) -> InterruptEvent {
95        InterruptEvent { interrupt_mask: <u8>::from_le_byte_slice(&bytes[0..1]), value_mask: <u8>::from_le_byte_slice(&bytes[1..2]) }
96    }
97}
98
99#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
100pub struct Monoflop {
101    pub value: u8,
102    pub time: u32,
103    pub time_remaining: u32,
104}
105impl FromByteSlice for Monoflop {
106    fn bytes_expected() -> usize {
107        9
108    }
109    fn from_le_byte_slice(bytes: &[u8]) -> Monoflop {
110        Monoflop {
111            value: <u8>::from_le_byte_slice(&bytes[0..1]),
112            time: <u32>::from_le_byte_slice(&bytes[1..5]),
113            time_remaining: <u32>::from_le_byte_slice(&bytes[5..9]),
114        }
115    }
116}
117
118#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
119pub struct MonoflopDoneEvent {
120    pub selection_mask: u8,
121    pub value_mask: u8,
122}
123impl FromByteSlice for MonoflopDoneEvent {
124    fn bytes_expected() -> usize {
125        2
126    }
127    fn from_le_byte_slice(bytes: &[u8]) -> MonoflopDoneEvent {
128        MonoflopDoneEvent { selection_mask: <u8>::from_le_byte_slice(&bytes[0..1]), value_mask: <u8>::from_le_byte_slice(&bytes[1..2]) }
129    }
130}
131
132#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
133pub struct EdgeCountConfig {
134    pub edge_type: u8,
135    pub debounce: u8,
136}
137impl FromByteSlice for EdgeCountConfig {
138    fn bytes_expected() -> usize {
139        2
140    }
141    fn from_le_byte_slice(bytes: &[u8]) -> EdgeCountConfig {
142        EdgeCountConfig { edge_type: <u8>::from_le_byte_slice(&bytes[0..1]), debounce: <u8>::from_le_byte_slice(&bytes[1..2]) }
143    }
144}
145
146#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
147pub struct Identity {
148    pub uid: String,
149    pub connected_uid: String,
150    pub position: char,
151    pub hardware_version: [u8; 3],
152    pub firmware_version: [u8; 3],
153    pub device_identifier: u16,
154}
155impl FromByteSlice for Identity {
156    fn bytes_expected() -> usize {
157        25
158    }
159    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
160        Identity {
161            uid: <String>::from_le_byte_slice(&bytes[0..8]),
162            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
163            position: <char>::from_le_byte_slice(&bytes[16..17]),
164            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
165            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
166            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
167        }
168    }
169}
170
171/// 4-channel digital input/output
172#[derive(Clone)]
173pub struct Io4Bricklet {
174    device: Device,
175}
176impl Io4Bricklet {
177    pub const DEVICE_IDENTIFIER: u16 = 29;
178    pub const DEVICE_DISPLAY_NAME: &'static str = "IO-4 Bricklet";
179    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
180    pub fn new(uid: Uid, connection: AsyncIpConnection) -> Io4Bricklet {
181        let mut result = Io4Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
182        result.device.response_expected[u8::from(Io4BrickletFunction::SetValue) as usize] = ResponseExpectedFlag::False;
183        result.device.response_expected[u8::from(Io4BrickletFunction::GetValue) as usize] = ResponseExpectedFlag::AlwaysTrue;
184        result.device.response_expected[u8::from(Io4BrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
185        result.device.response_expected[u8::from(Io4BrickletFunction::GetConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
186        result.device.response_expected[u8::from(Io4BrickletFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
187        result.device.response_expected[u8::from(Io4BrickletFunction::GetDebouncePeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
188        result.device.response_expected[u8::from(Io4BrickletFunction::SetInterrupt) as usize] = ResponseExpectedFlag::True;
189        result.device.response_expected[u8::from(Io4BrickletFunction::GetInterrupt) as usize] = ResponseExpectedFlag::AlwaysTrue;
190        result.device.response_expected[u8::from(Io4BrickletFunction::SetMonoflop) as usize] = ResponseExpectedFlag::False;
191        result.device.response_expected[u8::from(Io4BrickletFunction::GetMonoflop) as usize] = ResponseExpectedFlag::AlwaysTrue;
192        result.device.response_expected[u8::from(Io4BrickletFunction::SetSelectedValues) as usize] = ResponseExpectedFlag::False;
193        result.device.response_expected[u8::from(Io4BrickletFunction::GetEdgeCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
194        result.device.response_expected[u8::from(Io4BrickletFunction::SetEdgeCountConfig) as usize] = ResponseExpectedFlag::False;
195        result.device.response_expected[u8::from(Io4BrickletFunction::GetEdgeCountConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
196        result.device.response_expected[u8::from(Io4BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
197        result
198    }
199
200    /// Returns the response expected flag for the function specified by the function ID parameter.
201    /// It is true if the function is expected to send a response, false otherwise.
202    ///
203    /// For getter functions this is enabled by default and cannot be disabled, because those
204    /// functions will always send a response. For callback configuration functions it is enabled
205    /// by default too, but can be disabled by [`set_response_expected`](crate::io4_bricklet::Io4Bricklet::set_response_expected).
206    /// For setter functions it is disabled by default and can be enabled.
207    ///
208    /// Enabling the response expected flag for a setter function allows to detect timeouts
209    /// and other error conditions calls of this setter as well. The device will then send a response
210    /// for this purpose. If this flag is disabled for a setter function then no response is sent
211    /// and errors are silently ignored, because they cannot be detected.
212    ///
213    /// See [`set_response_expected`](crate::io4_bricklet::Io4Bricklet::set_response_expected) for the list of function ID constants available for this function.
214    pub fn get_response_expected(&mut self, fun: Io4BrickletFunction) -> Result<bool, GetResponseExpectedError> {
215        self.device.get_response_expected(u8::from(fun))
216    }
217
218    /// Changes the response expected flag of the function specified by the function ID parameter.
219    /// This flag can only be changed for setter (default value: false) and callback configuration
220    /// functions (default value: true). For getter functions it is always enabled.
221    ///
222    /// Enabling the response expected flag for a setter function allows to detect timeouts and
223    /// other error conditions calls of this setter as well. The device will then send a response
224    /// for this purpose. If this flag is disabled for a setter function then no response is sent
225    /// and errors are silently ignored, because they cannot be detected.
226    pub fn set_response_expected(&mut self, fun: Io4BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
227        self.device.set_response_expected(u8::from(fun), response_expected)
228    }
229
230    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
231    pub fn set_response_expected_all(&mut self, response_expected: bool) {
232        self.device.set_response_expected_all(response_expected)
233    }
234
235    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
236    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
237    pub fn get_api_version(&self) -> [u8; 3] {
238        self.device.api_version
239    }
240
241    /// This receiver is triggered whenever a change of the voltage level is detected
242    /// on pins where the interrupt was activated with [`set_interrupt`].
243    ///
244    /// The values are a bitmask that specifies which interrupts occurred
245    /// and the current value bitmask.
246    ///
247    /// For example:
248    ///
249    /// * (1, 1) or (0b0001, 0b0001) means that an interrupt on pin 0 occurred and
250    ///   currently pin 0 is high and pins 1-3 are low.
251    /// * (9, 14) or (0b1001, 0b1110) means that interrupts on pins 0 and 3
252    ///   occurred and currently pin 0 is low and pins 1-3 are high.
253    ///
254    /// [`set_interrupt`]: #method.set_interrupt
255    pub async fn get_interrupt_callback_receiver(&mut self) -> impl Stream<Item = InterruptEvent> {
256        self.device
257            .get_callback_receiver(u8::from(Io4BrickletFunction::CallbackInterrupt))
258            .await
259            .map(|p| InterruptEvent::from_le_byte_slice(p.body()))
260    }
261
262    /// This receiver is triggered whenever a monoflop timer reaches 0. The
263    /// parameters contain the involved pins and the current value of the pins
264    /// (the value after the monoflop).
265    pub async fn get_monoflop_done_callback_receiver(&mut self) -> impl Stream<Item = MonoflopDoneEvent> {
266        self.device
267            .get_callback_receiver(u8::from(Io4BrickletFunction::CallbackMonoflopDone))
268            .await
269            .map(|p| MonoflopDoneEvent::from_le_byte_slice(p.body()))
270    }
271
272    /// Sets the output value (high or low) with a bitmask (4bit). A 1 in the bitmask
273    /// means high and a 0 in the bitmask means low.
274    ///
275    /// For example: The value 3 or 0b0011 will turn the pins 0-1 high and the
276    /// pins 2-3 low.
277    ///
278    /// All running monoflop timers will be aborted if this function is called.
279    ///
280    /// # Note
281    ///  This function does nothing for pins that are configured as input.
282    ///  Pull-up resistors can be switched on with [`set_configuration`].
283    pub async fn set_value(&mut self, value_mask: u8) -> Result<(), TinkerforgeError> {
284        let mut payload = [0; 1];
285        value_mask.write_to_slice(&mut payload[0..1]);
286
287        #[allow(unused_variables)]
288        let result = self.device.set(u8::from(Io4BrickletFunction::SetValue), &payload).await?;
289        Ok(())
290    }
291
292    /// Returns a bitmask of the values that are currently measured.
293    /// This function works if the pin is configured to input
294    /// as well as if it is configured to output.
295    pub async fn get_value(&mut self) -> Result<u8, TinkerforgeError> {
296        let payload = [0; 0];
297
298        #[allow(unused_variables)]
299        let result = self.device.get(u8::from(Io4BrickletFunction::GetValue), &payload).await?;
300        Ok(u8::from_le_byte_slice(result.body()))
301    }
302
303    /// Configures the value and direction of the specified pins. Possible directions
304    /// are 'i' and 'o' for input and output.
305    ///
306    /// If the direction is configured as output, the value is either high or low
307    /// (set as *true* or *false*).
308    ///
309    /// If the direction is configured as input, the value is either pull-up or
310    /// default (set as *true* or *false*).
311    ///
312    /// For example:
313    ///
314    /// * (15, 'i', true) or (0b1111, 'i', true) will set all pins of as input pull-up.
315    /// * (8, 'i', false) or (0b1000, 'i', false) will set pin 3 of as input default (floating if nothing is connected).
316    /// * (3, 'o', false) or (0b0011, 'o', false) will set pins 0 and 1 as output low.
317    /// * (4, 'o', true) or (0b0100, 'o', true) will set pin 2 of as output high.
318    ///
319    /// Running monoflop timers for the specified pins will be aborted if this
320    /// function is called.
321    ///
322    /// Associated constants:
323    /// * IO4_BRICKLET_DIRECTION_IN
324    ///	* IO4_BRICKLET_DIRECTION_OUT
325    pub async fn set_configuration(&mut self, selection_mask: u8, direction: char, value: bool) -> Result<(), TinkerforgeError> {
326        let mut payload = [0; 3];
327        selection_mask.write_to_slice(&mut payload[0..1]);
328        direction.write_to_slice(&mut payload[1..2]);
329        value.write_to_slice(&mut payload[2..3]);
330
331        #[allow(unused_variables)]
332        let result = self.device.set(u8::from(Io4BrickletFunction::SetConfiguration), &payload).await?;
333        Ok(())
334    }
335
336    /// Returns a value bitmask and a direction bitmask. A 1 in the direction bitmask
337    /// means input and a 0 in the bitmask means output.
338    ///
339    /// For example: A return value of (3, 5) or (0b0011, 0b0101) for direction and
340    /// value means that:
341    ///
342    /// * pin 0 is configured as input pull-up,
343    /// * pin 1 is configured as input default,
344    /// * pin 2 is configured as output high and
345    /// * pin 3 is are configured as output low.
346    pub async fn get_configuration(&mut self) -> Result<Configuration, TinkerforgeError> {
347        let payload = [0; 0];
348
349        #[allow(unused_variables)]
350        let result = self.device.get(u8::from(Io4BrickletFunction::GetConfiguration), &payload).await?;
351        Ok(Configuration::from_le_byte_slice(result.body()))
352    }
353
354    /// Sets the debounce period of the [`get_interrupt_callback_receiver`] receiver.
355    ///
356    /// For example: If you set this value to 100, you will get the interrupt
357    /// maximal every 100ms. This is necessary if something that bounces is
358    /// connected to the IO-4 Bricklet, such as a button.
359    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
360        let mut payload = [0; 4];
361        debounce.write_to_slice(&mut payload[0..4]);
362
363        #[allow(unused_variables)]
364        let result = self.device.set(u8::from(Io4BrickletFunction::SetDebouncePeriod), &payload).await?;
365        Ok(())
366    }
367
368    /// Returns the debounce period as set by [`set_debounce_period`].
369    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
370        let payload = [0; 0];
371
372        #[allow(unused_variables)]
373        let result = self.device.get(u8::from(Io4BrickletFunction::GetDebouncePeriod), &payload).await?;
374        Ok(u32::from_le_byte_slice(result.body()))
375    }
376
377    /// Sets the pins on which an interrupt is activated with a bitmask.
378    /// Interrupts are triggered on changes of the voltage level of the pin,
379    /// i.e. changes from high to low and low to high.
380    ///
381    /// For example: An interrupt bitmask of 10 or 0b1010 will enable the interrupt for
382    /// pins 1 and 3.
383    ///
384    /// The interrupt is delivered with the [`get_interrupt_callback_receiver`] receiver.
385    pub async fn set_interrupt(&mut self, interrupt_mask: u8) -> Result<(), TinkerforgeError> {
386        let mut payload = [0; 1];
387        interrupt_mask.write_to_slice(&mut payload[0..1]);
388
389        #[allow(unused_variables)]
390        let result = self.device.set(u8::from(Io4BrickletFunction::SetInterrupt), &payload).await?;
391        Ok(())
392    }
393
394    /// Returns the interrupt bitmask as set by [`set_interrupt`].
395    pub async fn get_interrupt(&mut self) -> Result<u8, TinkerforgeError> {
396        let payload = [0; 0];
397
398        #[allow(unused_variables)]
399        let result = self.device.get(u8::from(Io4BrickletFunction::GetInterrupt), &payload).await?;
400        Ok(u8::from_le_byte_slice(result.body()))
401    }
402
403    /// Configures a monoflop of the pins specified by the first parameter as 4 bit
404    /// long bitmask. The specified pins must be configured for output. Non-output
405    /// pins will be ignored.
406    ///
407    /// The second parameter is a bitmask with the desired value of the specified
408    /// output pins. A 1 in the bitmask means high and a 0 in the bitmask means low.
409    ///
410    /// The third parameter indicates the time that the pins should hold
411    /// the value.
412    ///
413    /// If this function is called with the parameters (9, 1, 1500) or
414    /// (0b1001, 0b0001, 1500): Pin 0 will get high and pin 3 will get low. In 1.5s pin
415    /// 0 will get low and pin 3 will get high again.
416    ///
417    /// A monoflop can be used as a fail-safe mechanism. For example: Lets assume you
418    /// have a RS485 bus and an IO-4 Bricklet connected to one of the slave
419    /// stacks. You can now call this function every second, with a time parameter
420    /// of two seconds and pin 0 set to high. Pin 0 will be high all the time. If now
421    /// the RS485 connection is lost, then pin 0 will get low in at most two seconds.
422    pub async fn set_monoflop(&mut self, selection_mask: u8, value_mask: u8, time: u32) -> Result<(), TinkerforgeError> {
423        let mut payload = [0; 6];
424        selection_mask.write_to_slice(&mut payload[0..1]);
425        value_mask.write_to_slice(&mut payload[1..2]);
426        time.write_to_slice(&mut payload[2..6]);
427
428        #[allow(unused_variables)]
429        let result = self.device.set(u8::from(Io4BrickletFunction::SetMonoflop), &payload).await?;
430        Ok(())
431    }
432
433    /// Returns (for the given pin) the current value and the time as set by
434    /// [`set_monoflop`] as well as the remaining time until the value flips.
435    ///
436    /// If the timer is not running currently, the remaining time will be returned
437    /// as 0.
438    pub async fn get_monoflop(&mut self, pin: u8) -> Result<Monoflop, TinkerforgeError> {
439        let mut payload = [0; 1];
440        pin.write_to_slice(&mut payload[0..1]);
441
442        #[allow(unused_variables)]
443        let result = self.device.get(u8::from(Io4BrickletFunction::GetMonoflop), &payload).await?;
444        Ok(Monoflop::from_le_byte_slice(result.body()))
445    }
446
447    /// Sets the output value (high or low) with a bitmask, according to
448    /// the selection mask. The bitmask is 4 bit long, *true* refers to high
449    /// and *false* refers to low.
450    ///
451    /// For example: The parameters (9, 4) or (0b0110, 0b0100) will turn
452    /// pin 1 low and pin 2 high, pin 0 and 3 will remain untouched.
453    ///
454    /// Running monoflop timers for the selected pins will be aborted if this
455    /// function is called.
456    ///
457    /// # Note
458    ///  This function does nothing for pins that are configured as input.
459    ///  Pull-up resistors can be switched on with [`set_configuration`].
460    pub async fn set_selected_values(&mut self, selection_mask: u8, value_mask: u8) -> Result<(), TinkerforgeError> {
461        let mut payload = [0; 2];
462        selection_mask.write_to_slice(&mut payload[0..1]);
463        value_mask.write_to_slice(&mut payload[1..2]);
464
465        #[allow(unused_variables)]
466        let result = self.device.set(u8::from(Io4BrickletFunction::SetSelectedValues), &payload).await?;
467        Ok(())
468    }
469
470    /// Returns the current value of the edge counter for the selected pin. You can
471    /// configure the edges that are counted with [`set_edge_count_config`].
472    ///
473    /// If you set the reset counter to *true*, the count is set back to 0
474    /// directly after it is read.
475    ///
476    ///
477    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
478    pub async fn get_edge_count(&mut self, pin: u8, reset_counter: bool) -> Result<u32, TinkerforgeError> {
479        let mut payload = [0; 2];
480        pin.write_to_slice(&mut payload[0..1]);
481        reset_counter.write_to_slice(&mut payload[1..2]);
482
483        #[allow(unused_variables)]
484        let result = self.device.get(u8::from(Io4BrickletFunction::GetEdgeCount), &payload).await?;
485        Ok(u32::from_le_byte_slice(result.body()))
486    }
487
488    /// Configures the edge counter for the selected pins.
489    ///
490    /// The edge type parameter configures if rising edges, falling edges or
491    /// both are counted if the pin is configured for input. Possible edge types are:
492    ///
493    /// * 0 = rising (default)
494    /// * 1 = falling
495    /// * 2 = both
496    ///
497    /// Configuring an edge counter resets its value to 0.
498    ///
499    /// If you don't know what any of this means, just leave it at default. The
500    /// default configuration is very likely OK for you.
501    ///
502    ///
503    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
504    ///
505    /// Associated constants:
506    /// * IO4_BRICKLET_EDGE_TYPE_RISING
507    ///	* IO4_BRICKLET_EDGE_TYPE_FALLING
508    ///	* IO4_BRICKLET_EDGE_TYPE_BOTH
509    pub async fn set_edge_count_config(&mut self, selection_mask: u8, edge_type: u8, debounce: u8) -> Result<(), TinkerforgeError> {
510        let mut payload = [0; 3];
511        selection_mask.write_to_slice(&mut payload[0..1]);
512        edge_type.write_to_slice(&mut payload[1..2]);
513        debounce.write_to_slice(&mut payload[2..3]);
514
515        #[allow(unused_variables)]
516        let result = self.device.set(u8::from(Io4BrickletFunction::SetEdgeCountConfig), &payload).await?;
517        Ok(())
518    }
519
520    /// Returns the edge type and debounce time for the selected pin as set by
521    /// [`set_edge_count_config`].
522    ///
523    ///
524    /// .. versionadded:: 2.0.1$nbsp;(Plugin)
525    ///
526    /// Associated constants:
527    /// * IO4_BRICKLET_EDGE_TYPE_RISING
528    ///	* IO4_BRICKLET_EDGE_TYPE_FALLING
529    ///	* IO4_BRICKLET_EDGE_TYPE_BOTH
530    pub async fn get_edge_count_config(&mut self, pin: u8) -> Result<EdgeCountConfig, TinkerforgeError> {
531        let mut payload = [0; 1];
532        pin.write_to_slice(&mut payload[0..1]);
533
534        #[allow(unused_variables)]
535        let result = self.device.get(u8::from(Io4BrickletFunction::GetEdgeCountConfig), &payload).await?;
536        Ok(EdgeCountConfig::from_le_byte_slice(result.body()))
537    }
538
539    /// Returns the UID, the UID where the Bricklet is connected to,
540    /// the position, the hardware and firmware version as well as the
541    /// device identifier.
542    ///
543    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
544    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
545    /// position 'z'.
546    ///
547    /// The device identifier numbers can be found [here](device_identifier).
548    /// |device_identifier_constant|
549    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
550        let payload = [0; 0];
551
552        #[allow(unused_variables)]
553        let result = self.device.get(u8::from(Io4BrickletFunction::GetIdentity), &payload).await?;
554        Ok(Identity::from_le_byte_slice(result.body()))
555    }
556}