tinkerforge_async/bindings/
industrial_counter_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 counter up to 4MHz.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/IndustrialCounter_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 IndustrialCounterBrickletFunction {
24    GetCounter,
25    GetAllCounter,
26    SetCounter,
27    SetAllCounter,
28    GetSignalData,
29    GetAllSignalData,
30    SetCounterActive,
31    SetAllCounterActive,
32    GetCounterActive,
33    GetAllCounterActive,
34    SetCounterConfiguration,
35    GetCounterConfiguration,
36    SetAllCounterCallbackConfiguration,
37    GetAllCounterCallbackConfiguration,
38    SetAllSignalDataCallbackConfiguration,
39    GetAllSignalDataCallbackConfiguration,
40    SetChannelLedConfig,
41    GetChannelLedConfig,
42    GetSpitfpErrorCount,
43    SetBootloaderMode,
44    GetBootloaderMode,
45    SetWriteFirmwarePointer,
46    WriteFirmware,
47    SetStatusLedConfig,
48    GetStatusLedConfig,
49    GetChipTemperature,
50    Reset,
51    WriteUid,
52    ReadUid,
53    GetIdentity,
54    CallbackAllCounter,
55    CallbackAllSignalData,
56}
57impl From<IndustrialCounterBrickletFunction> for u8 {
58    fn from(fun: IndustrialCounterBrickletFunction) -> Self {
59        match fun {
60            IndustrialCounterBrickletFunction::GetCounter => 1,
61            IndustrialCounterBrickletFunction::GetAllCounter => 2,
62            IndustrialCounterBrickletFunction::SetCounter => 3,
63            IndustrialCounterBrickletFunction::SetAllCounter => 4,
64            IndustrialCounterBrickletFunction::GetSignalData => 5,
65            IndustrialCounterBrickletFunction::GetAllSignalData => 6,
66            IndustrialCounterBrickletFunction::SetCounterActive => 7,
67            IndustrialCounterBrickletFunction::SetAllCounterActive => 8,
68            IndustrialCounterBrickletFunction::GetCounterActive => 9,
69            IndustrialCounterBrickletFunction::GetAllCounterActive => 10,
70            IndustrialCounterBrickletFunction::SetCounterConfiguration => 11,
71            IndustrialCounterBrickletFunction::GetCounterConfiguration => 12,
72            IndustrialCounterBrickletFunction::SetAllCounterCallbackConfiguration => 13,
73            IndustrialCounterBrickletFunction::GetAllCounterCallbackConfiguration => 14,
74            IndustrialCounterBrickletFunction::SetAllSignalDataCallbackConfiguration => 15,
75            IndustrialCounterBrickletFunction::GetAllSignalDataCallbackConfiguration => 16,
76            IndustrialCounterBrickletFunction::SetChannelLedConfig => 17,
77            IndustrialCounterBrickletFunction::GetChannelLedConfig => 18,
78            IndustrialCounterBrickletFunction::GetSpitfpErrorCount => 234,
79            IndustrialCounterBrickletFunction::SetBootloaderMode => 235,
80            IndustrialCounterBrickletFunction::GetBootloaderMode => 236,
81            IndustrialCounterBrickletFunction::SetWriteFirmwarePointer => 237,
82            IndustrialCounterBrickletFunction::WriteFirmware => 238,
83            IndustrialCounterBrickletFunction::SetStatusLedConfig => 239,
84            IndustrialCounterBrickletFunction::GetStatusLedConfig => 240,
85            IndustrialCounterBrickletFunction::GetChipTemperature => 242,
86            IndustrialCounterBrickletFunction::Reset => 243,
87            IndustrialCounterBrickletFunction::WriteUid => 248,
88            IndustrialCounterBrickletFunction::ReadUid => 249,
89            IndustrialCounterBrickletFunction::GetIdentity => 255,
90            IndustrialCounterBrickletFunction::CallbackAllCounter => 19,
91            IndustrialCounterBrickletFunction::CallbackAllSignalData => 20,
92        }
93    }
94}
95pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0: u8 = 0;
96pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1: u8 = 1;
97pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2: u8 = 2;
98pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3: u8 = 3;
99pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_RISING: u8 = 0;
100pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_FALLING: u8 = 1;
101pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_BOTH: u8 = 2;
102pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_UP: u8 = 0;
103pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_DOWN: u8 = 1;
104pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_UP: u8 = 2;
105pub const INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_DOWN: u8 = 3;
106pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1: u8 = 0;
107pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2: u8 = 1;
108pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4: u8 = 2;
109pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8: u8 = 3;
110pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16: u8 = 4;
111pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32: u8 = 5;
112pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_64: u8 = 6;
113pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_128: u8 = 7;
114pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_256: u8 = 8;
115pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_512: u8 = 9;
116pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1024: u8 = 10;
117pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2048: u8 = 11;
118pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4096: u8 = 12;
119pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8192: u8 = 13;
120pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16384: u8 = 14;
121pub const INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32768: u8 = 15;
122pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_128_MS: u8 = 0;
123pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_256_MS: u8 = 1;
124pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_512_MS: u8 = 2;
125pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_1024_MS: u8 = 3;
126pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_2048_MS: u8 = 4;
127pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_4096_MS: u8 = 5;
128pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_8192_MS: u8 = 6;
129pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_16384_MS: u8 = 7;
130pub const INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_32768_MS: u8 = 8;
131pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_OFF: u8 = 0;
132pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_ON: u8 = 1;
133pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
134pub const INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS: u8 = 3;
135pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
136pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
137pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
138pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
139pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
140pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
141pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
142pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
143pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
144pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
145pub const INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
146pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
147pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
148pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
149pub const INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
150
151#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
152pub struct SignalData {
153    pub duty_cycle: u16,
154    pub period: u64,
155    pub frequency: u32,
156    pub value: bool,
157}
158impl FromByteSlice for SignalData {
159    fn bytes_expected() -> usize {
160        15
161    }
162    fn from_le_byte_slice(bytes: &[u8]) -> SignalData {
163        SignalData {
164            duty_cycle: <u16>::from_le_byte_slice(&bytes[0..2]),
165            period: <u64>::from_le_byte_slice(&bytes[2..10]),
166            frequency: <u32>::from_le_byte_slice(&bytes[10..14]),
167            value: <bool>::from_le_byte_slice(&bytes[14..15]),
168        }
169    }
170}
171
172#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
173pub struct AllSignalData {
174    pub duty_cycle: [u16; 4],
175    pub period: [u64; 4],
176    pub frequency: [u32; 4],
177    pub value: [bool; 4],
178}
179impl FromByteSlice for AllSignalData {
180    fn bytes_expected() -> usize {
181        57
182    }
183    fn from_le_byte_slice(bytes: &[u8]) -> AllSignalData {
184        AllSignalData {
185            duty_cycle: <[u16; 4]>::from_le_byte_slice(&bytes[0..8]),
186            period: <[u64; 4]>::from_le_byte_slice(&bytes[8..40]),
187            frequency: <[u32; 4]>::from_le_byte_slice(&bytes[40..56]),
188            value: <[bool; 4]>::from_le_byte_slice(&bytes[56..57]),
189        }
190    }
191}
192
193#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
194pub struct CounterConfiguration {
195    pub count_edge: u8,
196    pub count_direction: u8,
197    pub duty_cycle_prescaler: u8,
198    pub frequency_integration_time: u8,
199}
200impl FromByteSlice for CounterConfiguration {
201    fn bytes_expected() -> usize {
202        4
203    }
204    fn from_le_byte_slice(bytes: &[u8]) -> CounterConfiguration {
205        CounterConfiguration {
206            count_edge: <u8>::from_le_byte_slice(&bytes[0..1]),
207            count_direction: <u8>::from_le_byte_slice(&bytes[1..2]),
208            duty_cycle_prescaler: <u8>::from_le_byte_slice(&bytes[2..3]),
209            frequency_integration_time: <u8>::from_le_byte_slice(&bytes[3..4]),
210        }
211    }
212}
213
214#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
215pub struct AllCounterCallbackConfiguration {
216    pub period: u32,
217    pub value_has_to_change: bool,
218}
219impl FromByteSlice for AllCounterCallbackConfiguration {
220    fn bytes_expected() -> usize {
221        5
222    }
223    fn from_le_byte_slice(bytes: &[u8]) -> AllCounterCallbackConfiguration {
224        AllCounterCallbackConfiguration {
225            period: <u32>::from_le_byte_slice(&bytes[0..4]),
226            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
227        }
228    }
229}
230
231#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
232pub struct AllSignalDataCallbackConfiguration {
233    pub period: u32,
234    pub value_has_to_change: bool,
235}
236impl FromByteSlice for AllSignalDataCallbackConfiguration {
237    fn bytes_expected() -> usize {
238        5
239    }
240    fn from_le_byte_slice(bytes: &[u8]) -> AllSignalDataCallbackConfiguration {
241        AllSignalDataCallbackConfiguration {
242            period: <u32>::from_le_byte_slice(&bytes[0..4]),
243            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
244        }
245    }
246}
247
248#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
249pub struct AllSignalDataEvent {
250    pub duty_cycle: [u16; 4],
251    pub period: [u64; 4],
252    pub frequency: [u32; 4],
253    pub value: [bool; 4],
254}
255impl FromByteSlice for AllSignalDataEvent {
256    fn bytes_expected() -> usize {
257        57
258    }
259    fn from_le_byte_slice(bytes: &[u8]) -> AllSignalDataEvent {
260        AllSignalDataEvent {
261            duty_cycle: <[u16; 4]>::from_le_byte_slice(&bytes[0..8]),
262            period: <[u64; 4]>::from_le_byte_slice(&bytes[8..40]),
263            frequency: <[u32; 4]>::from_le_byte_slice(&bytes[40..56]),
264            value: <[bool; 4]>::from_le_byte_slice(&bytes[56..57]),
265        }
266    }
267}
268
269#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
270pub struct SpitfpErrorCount {
271    pub error_count_ack_checksum: u32,
272    pub error_count_message_checksum: u32,
273    pub error_count_frame: u32,
274    pub error_count_overflow: u32,
275}
276impl FromByteSlice for SpitfpErrorCount {
277    fn bytes_expected() -> usize {
278        16
279    }
280    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
281        SpitfpErrorCount {
282            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
283            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
284            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
285            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
286        }
287    }
288}
289
290#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
291pub struct Identity {
292    pub uid: String,
293    pub connected_uid: String,
294    pub position: char,
295    pub hardware_version: [u8; 3],
296    pub firmware_version: [u8; 3],
297    pub device_identifier: u16,
298}
299impl FromByteSlice for Identity {
300    fn bytes_expected() -> usize {
301        25
302    }
303    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
304        Identity {
305            uid: <String>::from_le_byte_slice(&bytes[0..8]),
306            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
307            position: <char>::from_le_byte_slice(&bytes[16..17]),
308            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
309            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
310            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
311        }
312    }
313}
314
315/// 4 channel counter up to 4MHz
316#[derive(Clone)]
317pub struct IndustrialCounterBricklet {
318    device: Device,
319}
320impl IndustrialCounterBricklet {
321    pub const DEVICE_IDENTIFIER: u16 = 293;
322    pub const DEVICE_DISPLAY_NAME: &'static str = "Industrial Counter Bricklet";
323    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
324    pub fn new(uid: Uid, connection: AsyncIpConnection) -> IndustrialCounterBricklet {
325        let mut result = IndustrialCounterBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
326        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetCounter) as usize] =
327            ResponseExpectedFlag::AlwaysTrue;
328        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllCounter) as usize] =
329            ResponseExpectedFlag::AlwaysTrue;
330        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetCounter) as usize] = ResponseExpectedFlag::False;
331        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllCounter) as usize] = ResponseExpectedFlag::False;
332        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetSignalData) as usize] =
333            ResponseExpectedFlag::AlwaysTrue;
334        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllSignalData) as usize] =
335            ResponseExpectedFlag::AlwaysTrue;
336        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetCounterActive) as usize] =
337            ResponseExpectedFlag::False;
338        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllCounterActive) as usize] =
339            ResponseExpectedFlag::False;
340        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetCounterActive) as usize] =
341            ResponseExpectedFlag::AlwaysTrue;
342        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllCounterActive) as usize] =
343            ResponseExpectedFlag::AlwaysTrue;
344        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetCounterConfiguration) as usize] =
345            ResponseExpectedFlag::False;
346        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetCounterConfiguration) as usize] =
347            ResponseExpectedFlag::AlwaysTrue;
348        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllCounterCallbackConfiguration) as usize] =
349            ResponseExpectedFlag::True;
350        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllCounterCallbackConfiguration) as usize] =
351            ResponseExpectedFlag::AlwaysTrue;
352        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetAllSignalDataCallbackConfiguration) as usize] =
353            ResponseExpectedFlag::True;
354        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetAllSignalDataCallbackConfiguration) as usize] =
355            ResponseExpectedFlag::AlwaysTrue;
356        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetChannelLedConfig) as usize] =
357            ResponseExpectedFlag::False;
358        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetChannelLedConfig) as usize] =
359            ResponseExpectedFlag::AlwaysTrue;
360        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetSpitfpErrorCount) as usize] =
361            ResponseExpectedFlag::AlwaysTrue;
362        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetBootloaderMode) as usize] =
363            ResponseExpectedFlag::AlwaysTrue;
364        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetBootloaderMode) as usize] =
365            ResponseExpectedFlag::AlwaysTrue;
366        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetWriteFirmwarePointer) as usize] =
367            ResponseExpectedFlag::False;
368        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::WriteFirmware) as usize] =
369            ResponseExpectedFlag::AlwaysTrue;
370        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::SetStatusLedConfig) as usize] =
371            ResponseExpectedFlag::False;
372        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetStatusLedConfig) as usize] =
373            ResponseExpectedFlag::AlwaysTrue;
374        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetChipTemperature) as usize] =
375            ResponseExpectedFlag::AlwaysTrue;
376        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
377        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
378        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
379        result.device.response_expected[u8::from(IndustrialCounterBrickletFunction::GetIdentity) as usize] =
380            ResponseExpectedFlag::AlwaysTrue;
381        result
382    }
383
384    /// Returns the response expected flag for the function specified by the function ID parameter.
385    /// It is true if the function is expected to send a response, false otherwise.
386    ///
387    /// For getter functions this is enabled by default and cannot be disabled, because those
388    /// functions will always send a response. For callback configuration functions it is enabled
389    /// by default too, but can be disabled by [`set_response_expected`](crate::industrial_counter_bricklet::IndustrialCounterBricklet::set_response_expected).
390    /// For setter functions it is disabled by default and can be enabled.
391    ///
392    /// Enabling the response expected flag for a setter function allows to detect timeouts
393    /// and other error conditions calls of this setter as well. The device will then send a response
394    /// for this purpose. If this flag is disabled for a setter function then no response is sent
395    /// and errors are silently ignored, because they cannot be detected.
396    ///
397    /// See [`set_response_expected`](crate::industrial_counter_bricklet::IndustrialCounterBricklet::set_response_expected) for the list of function ID constants available for this function.
398    pub fn get_response_expected(&mut self, fun: IndustrialCounterBrickletFunction) -> Result<bool, GetResponseExpectedError> {
399        self.device.get_response_expected(u8::from(fun))
400    }
401
402    /// Changes the response expected flag of the function specified by the function ID parameter.
403    /// This flag can only be changed for setter (default value: false) and callback configuration
404    /// functions (default value: true). For getter functions it is always enabled.
405    ///
406    /// Enabling the response expected flag for a setter function allows to detect timeouts and
407    /// other error conditions calls of this setter as well. The device will then send a response
408    /// for this purpose. If this flag is disabled for a setter function then no response is sent
409    /// and errors are silently ignored, because they cannot be detected.
410    pub fn set_response_expected(
411        &mut self,
412        fun: IndustrialCounterBrickletFunction,
413        response_expected: bool,
414    ) -> Result<(), SetResponseExpectedError> {
415        self.device.set_response_expected(u8::from(fun), response_expected)
416    }
417
418    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
419    pub fn set_response_expected_all(&mut self, response_expected: bool) {
420        self.device.set_response_expected_all(response_expected)
421    }
422
423    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
424    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
425    pub fn get_api_version(&self) -> [u8; 3] {
426        self.device.api_version
427    }
428
429    /// This receiver is triggered periodically according to the configuration set by
430    /// [`set_all_counter_callback_configuration`].
431    ///
432    /// The parameters are the same as [`get_all_counter`].
433    ///
434    /// [`get_all_counter`]: #method.get_all_counter
435    /// [`set_all_counter_callback_configuration`]: #method.set_all_counter_callback_configuration
436    pub async fn get_all_counter_callback_receiver(&mut self) -> impl Stream<Item = [i64; 4]> {
437        self.device
438            .get_callback_receiver(u8::from(IndustrialCounterBrickletFunction::CallbackAllCounter))
439            .await
440            .map(|p| <[i64; 4]>::from_le_byte_slice(p.body()))
441    }
442
443    /// This receiver is triggered periodically according to the configuration set by
444    /// [`set_all_signal_data_callback_configuration`].
445    ///
446    /// The parameters are the same as [`get_all_signal_data`].
447    pub async fn get_all_signal_data_callback_receiver(&mut self) -> impl Stream<Item = AllSignalDataEvent> {
448        self.device
449            .get_callback_receiver(u8::from(IndustrialCounterBrickletFunction::CallbackAllSignalData))
450            .await
451            .map(|p| AllSignalDataEvent::from_le_byte_slice(p.body()))
452    }
453
454    /// Returns the current counter value for the given channel.
455    ///
456    /// Associated constants:
457    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
458    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
459    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
460    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
461    pub async fn get_counter(&mut self, channel: u8) -> Result<i64, TinkerforgeError> {
462        let mut payload = [0; 1];
463        channel.write_to_slice(&mut payload[0..1]);
464
465        #[allow(unused_variables)]
466        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetCounter), &payload).await?;
467        Ok(i64::from_le_byte_slice(result.body()))
468    }
469
470    /// Returns the current counter values for all four channels.
471    pub async fn get_all_counter(&mut self) -> Result<Box<[i64; 4]>, TinkerforgeError> {
472        let payload = [0; 0];
473
474        #[allow(unused_variables)]
475        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllCounter), &payload).await?;
476        Ok(Box::<[i64; 4]>::from_le_byte_slice(result.body()))
477    }
478
479    /// Sets the counter value for the given channel.
480    ///
481    /// The default value for the counters on startup is 0.
482    ///
483    /// Associated constants:
484    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
485    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
486    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
487    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
488    pub async fn set_counter(&mut self, channel: u8, counter: i64) -> Result<(), TinkerforgeError> {
489        let mut payload = [0; 9];
490        channel.write_to_slice(&mut payload[0..1]);
491        counter.write_to_slice(&mut payload[1..9]);
492
493        #[allow(unused_variables)]
494        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetCounter), &payload).await?;
495        Ok(())
496    }
497
498    /// Sets the counter values for all four channels.
499    ///
500    /// The default value for the counters on startup is 0.
501    pub async fn set_all_counter(&mut self, counter: &[i64; 4]) -> Result<(), TinkerforgeError> {
502        let mut payload = [0; 32];
503        counter.write_to_slice(&mut payload[0..32]);
504
505        #[allow(unused_variables)]
506        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllCounter), &payload).await?;
507        Ok(())
508    }
509
510    /// Returns the signal data (duty cycle, period, frequency and value) for the
511    /// given channel.
512    ///
513    /// Associated constants:
514    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
515    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
516    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
517    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
518    pub async fn get_signal_data(&mut self, channel: u8) -> Result<SignalData, TinkerforgeError> {
519        let mut payload = [0; 1];
520        channel.write_to_slice(&mut payload[0..1]);
521
522        #[allow(unused_variables)]
523        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetSignalData), &payload).await?;
524        Ok(SignalData::from_le_byte_slice(result.body()))
525    }
526
527    /// Returns the signal data (duty cycle, period, frequency and value) for all four
528    /// channels.
529    pub async fn get_all_signal_data(&mut self) -> Result<AllSignalData, TinkerforgeError> {
530        let payload = [0; 0];
531
532        #[allow(unused_variables)]
533        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllSignalData), &payload).await?;
534        Ok(AllSignalData::from_le_byte_slice(result.body()))
535    }
536
537    /// Activates/deactivates the counter of the given channel.
538    ///
539    /// true = activate, false = deactivate.
540    ///
541    /// By default all channels are activated.
542    ///
543    /// Associated constants:
544    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
545    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
546    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
547    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
548    pub async fn set_counter_active(&mut self, channel: u8, active: bool) -> Result<(), TinkerforgeError> {
549        let mut payload = [0; 2];
550        channel.write_to_slice(&mut payload[0..1]);
551        active.write_to_slice(&mut payload[1..2]);
552
553        #[allow(unused_variables)]
554        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetCounterActive), &payload).await?;
555        Ok(())
556    }
557
558    /// Activates/deactivates the counter of all four channels.
559    ///
560    /// true = activate, false = deactivate.
561    ///
562    /// By default all channels are activated.
563    pub async fn set_all_counter_active(&mut self, active: &[bool; 4]) -> Result<(), TinkerforgeError> {
564        let mut payload = [0; 1];
565        active.write_to_slice(&mut payload[0..1]);
566
567        #[allow(unused_variables)]
568        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllCounterActive), &payload).await?;
569        Ok(())
570    }
571
572    /// Returns the activation state of the given channel.
573    ///
574    /// true = activated, false = deactivated.
575    ///
576    /// Associated constants:
577    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
578    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
579    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
580    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
581    pub async fn get_counter_active(&mut self, channel: u8) -> Result<bool, TinkerforgeError> {
582        let mut payload = [0; 1];
583        channel.write_to_slice(&mut payload[0..1]);
584
585        #[allow(unused_variables)]
586        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetCounterActive), &payload).await?;
587        Ok(bool::from_le_byte_slice(result.body()))
588    }
589
590    /// Returns the activation state of all four channels.
591    ///
592    /// true = activated, false = deactivated.
593    pub async fn get_all_counter_active(&mut self) -> Result<Box<[bool; 4]>, TinkerforgeError> {
594        let payload = [0; 0];
595
596        #[allow(unused_variables)]
597        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllCounterActive), &payload).await?;
598        Ok(Box::<[bool; 4]>::from_le_byte_slice(result.body()))
599    }
600
601    /// Sets the counter configuration for the given channel.
602    ///
603    /// * Count Edge: Counter can count on rising, falling or both edges.
604    /// * Count Direction: Counter can count up or down. You can also use
605    ///   another channel as direction input, see
606    ///   [here](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Counter.html#external-count-direction)__
607    ///   for details.
608    /// * Duty Cycle Prescaler: Sets a divider for the internal clock. See
609    ///   [here](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Counter.html#duty-cycle-prescaler-and-frequency-integration-time)__
610    ///   for details.
611    /// * Frequency Integration Time: Sets the integration time for the
612    ///   frequency measurement. See
613    ///   [here](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Industrial_Counter.html#duty-cycle-prescaler-and-frequency-integration-time)__
614    ///   for details.
615    ///
616    /// Associated constants:
617    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
618    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
619    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
620    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
621    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_RISING
622    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_FALLING
623    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_BOTH
624    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_UP
625    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_DOWN
626    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_UP
627    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_DOWN
628    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1
629    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2
630    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4
631    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8
632    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16
633    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32
634    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_64
635    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_128
636    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_256
637    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_512
638    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1024
639    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2048
640    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4096
641    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8192
642    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16384
643    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32768
644    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_128_MS
645    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_256_MS
646    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_512_MS
647    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_1024_MS
648    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_2048_MS
649    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_4096_MS
650    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_8192_MS
651    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_16384_MS
652    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_32768_MS
653    pub async fn set_counter_configuration(
654        &mut self,
655        channel: u8,
656        count_edge: u8,
657        count_direction: u8,
658        duty_cycle_prescaler: u8,
659        frequency_integration_time: u8,
660    ) -> Result<(), TinkerforgeError> {
661        let mut payload = [0; 5];
662        channel.write_to_slice(&mut payload[0..1]);
663        count_edge.write_to_slice(&mut payload[1..2]);
664        count_direction.write_to_slice(&mut payload[2..3]);
665        duty_cycle_prescaler.write_to_slice(&mut payload[3..4]);
666        frequency_integration_time.write_to_slice(&mut payload[4..5]);
667
668        #[allow(unused_variables)]
669        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetCounterConfiguration), &payload).await?;
670        Ok(())
671    }
672
673    /// Returns the counter configuration as set by [`set_counter_configuration`].
674    ///
675    /// Associated constants:
676    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
677    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
678    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
679    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
680    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_RISING
681    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_FALLING
682    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_EDGE_BOTH
683    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_UP
684    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_DOWN
685    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_UP
686    ///	* INDUSTRIAL_COUNTER_BRICKLET_COUNT_DIRECTION_EXTERNAL_DOWN
687    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1
688    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2
689    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4
690    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8
691    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16
692    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32
693    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_64
694    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_128
695    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_256
696    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_512
697    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_1024
698    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_2048
699    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_4096
700    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_8192
701    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_16384
702    ///	* INDUSTRIAL_COUNTER_BRICKLET_DUTY_CYCLE_PRESCALER_32768
703    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_128_MS
704    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_256_MS
705    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_512_MS
706    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_1024_MS
707    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_2048_MS
708    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_4096_MS
709    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_8192_MS
710    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_16384_MS
711    ///	* INDUSTRIAL_COUNTER_BRICKLET_FREQUENCY_INTEGRATION_TIME_32768_MS
712    pub async fn get_counter_configuration(&mut self, channel: u8) -> Result<CounterConfiguration, TinkerforgeError> {
713        let mut payload = [0; 1];
714        channel.write_to_slice(&mut payload[0..1]);
715
716        #[allow(unused_variables)]
717        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetCounterConfiguration), &payload).await?;
718        Ok(CounterConfiguration::from_le_byte_slice(result.body()))
719    }
720
721    /// The period is the period with which the [`get_all_counter_callback_receiver`]
722    /// receiver is triggered periodically. A value of 0 turns the receiver off.
723    ///
724    /// If the `value has to change`-parameter is set to true, the receiver is only
725    /// triggered after the value has changed. If the value didn't change within the
726    /// period, the receiver is triggered immediately on change.
727    ///
728    /// If it is set to false, the receiver is continuously triggered with the period,
729    /// independent of the value.
730    pub async fn set_all_counter_callback_configuration(&mut self, period: u32, value_has_to_change: bool) -> Result<(), TinkerforgeError> {
731        let mut payload = [0; 5];
732        period.write_to_slice(&mut payload[0..4]);
733        value_has_to_change.write_to_slice(&mut payload[4..5]);
734
735        #[allow(unused_variables)]
736        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllCounterCallbackConfiguration), &payload).await?;
737        Ok(())
738    }
739
740    /// Returns the receiver configuration as set by
741    /// [`set_all_counter_callback_configuration`].
742    pub async fn get_all_counter_callback_configuration(&mut self) -> Result<AllCounterCallbackConfiguration, TinkerforgeError> {
743        let payload = [0; 0];
744
745        #[allow(unused_variables)]
746        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllCounterCallbackConfiguration), &payload).await?;
747        Ok(AllCounterCallbackConfiguration::from_le_byte_slice(result.body()))
748    }
749
750    /// The period is the period with which the [`get_all_signal_data_callback_receiver`]
751    /// receiver is triggered periodically. A value of 0 turns the receiver off.
752    ///
753    /// If the `value has to change`-parameter is set to true, the receiver is only
754    /// triggered after the value has changed. If the value didn't change within the
755    /// period, the receiver is triggered immediately on change.
756    ///
757    /// If it is set to false, the receiver is continuously triggered with the period,
758    /// independent of the value.
759    pub async fn set_all_signal_data_callback_configuration(
760        &mut self,
761        period: u32,
762        value_has_to_change: bool,
763    ) -> Result<(), TinkerforgeError> {
764        let mut payload = [0; 5];
765        period.write_to_slice(&mut payload[0..4]);
766        value_has_to_change.write_to_slice(&mut payload[4..5]);
767
768        #[allow(unused_variables)]
769        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetAllSignalDataCallbackConfiguration), &payload).await?;
770        Ok(())
771    }
772
773    /// Returns the receiver configuration as set by
774    /// [`set_all_signal_data_callback_configuration`].
775    pub async fn get_all_signal_data_callback_configuration(&mut self) -> Result<AllSignalDataCallbackConfiguration, TinkerforgeError> {
776        let payload = [0; 0];
777
778        #[allow(unused_variables)]
779        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetAllSignalDataCallbackConfiguration), &payload).await?;
780        Ok(AllSignalDataCallbackConfiguration::from_le_byte_slice(result.body()))
781    }
782
783    /// Each channel has a corresponding LED. You can turn the LED off, on or show a
784    /// heartbeat. You can also set the LED to Channel Status. In this mode the
785    /// LED is on if the channel is high and off otherwise.
786    ///
787    /// Associated constants:
788    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
789    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
790    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
791    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
792    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_OFF
793    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_ON
794    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT
795    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS
796    pub async fn set_channel_led_config(&mut self, channel: u8, config: u8) -> Result<(), TinkerforgeError> {
797        let mut payload = [0; 2];
798        channel.write_to_slice(&mut payload[0..1]);
799        config.write_to_slice(&mut payload[1..2]);
800
801        #[allow(unused_variables)]
802        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetChannelLedConfig), &payload).await?;
803        Ok(())
804    }
805
806    /// Returns the channel LED configuration as set by [`set_channel_led_config`]
807    ///
808    /// Associated constants:
809    /// * INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_0
810    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_1
811    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_2
812    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_3
813    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_OFF
814    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_ON
815    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_HEARTBEAT
816    ///	* INDUSTRIAL_COUNTER_BRICKLET_CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS
817    pub async fn get_channel_led_config(&mut self, channel: u8) -> Result<u8, TinkerforgeError> {
818        let mut payload = [0; 1];
819        channel.write_to_slice(&mut payload[0..1]);
820
821        #[allow(unused_variables)]
822        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetChannelLedConfig), &payload).await?;
823        Ok(u8::from_le_byte_slice(result.body()))
824    }
825
826    /// Returns the error count for the communication between Brick and Bricklet.
827    ///
828    /// The errors are divided into
829    ///
830    /// * ACK checksum errors,
831    /// * message checksum errors,
832    /// * framing errors and
833    /// * overflow errors.
834    ///
835    /// The errors counts are for errors that occur on the Bricklet side. All
836    /// Bricks have a similar function that returns the errors on the Brick side.
837    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
838        let payload = [0; 0];
839
840        #[allow(unused_variables)]
841        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetSpitfpErrorCount), &payload).await?;
842        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
843    }
844
845    /// Sets the bootloader mode and returns the status after the requested
846    /// mode change was instigated.
847    ///
848    /// You can change from bootloader mode to firmware mode and vice versa. A change
849    /// from bootloader mode to firmware mode will only take place if the entry function,
850    /// device identifier and CRC are present and correct.
851    ///
852    /// This function is used by Brick Viewer during flashing. It should not be
853    /// necessary to call it in a normal user program.
854    ///
855    /// Associated constants:
856    /// * INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
857    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE
858    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
859    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
860    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
861    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_OK
862    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
863    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
864    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
865    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
866    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
867    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
868        let mut payload = [0; 1];
869        mode.write_to_slice(&mut payload[0..1]);
870
871        #[allow(unused_variables)]
872        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::SetBootloaderMode), &payload).await?;
873        Ok(u8::from_le_byte_slice(result.body()))
874    }
875
876    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
877    ///
878    /// Associated constants:
879    /// * INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
880    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE
881    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
882    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
883    ///	* INDUSTRIAL_COUNTER_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
884    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
885        let payload = [0; 0];
886
887        #[allow(unused_variables)]
888        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetBootloaderMode), &payload).await?;
889        Ok(u8::from_le_byte_slice(result.body()))
890    }
891
892    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
893    /// to be increased by chunks of size 64. The data is written to flash
894    /// every 4 chunks (which equals to one page of size 256).
895    ///
896    /// This function is used by Brick Viewer during flashing. It should not be
897    /// necessary to call it in a normal user program.
898    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
899        let mut payload = [0; 4];
900        pointer.write_to_slice(&mut payload[0..4]);
901
902        #[allow(unused_variables)]
903        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
904        Ok(())
905    }
906
907    /// Writes 64 Bytes of firmware at the position as written by
908    /// [`set_write_firmware_pointer`] before. The firmware is written
909    /// to flash every 4 chunks.
910    ///
911    /// You can only write firmware in bootloader mode.
912    ///
913    /// This function is used by Brick Viewer during flashing. It should not be
914    /// necessary to call it in a normal user program.
915    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
916        let mut payload = [0; 64];
917        data.write_to_slice(&mut payload[0..64]);
918
919        #[allow(unused_variables)]
920        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::WriteFirmware), &payload).await?;
921        Ok(u8::from_le_byte_slice(result.body()))
922    }
923
924    /// Sets the status LED configuration. By default the LED shows
925    /// communication traffic between Brick and Bricklet, it flickers once
926    /// for every 10 received data packets.
927    ///
928    /// You can also turn the LED permanently on/off or show a heartbeat.
929    ///
930    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
931    ///
932    /// Associated constants:
933    /// * INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_OFF
934    ///	* INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_ON
935    ///	* INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
936    ///	* INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
937    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
938        let mut payload = [0; 1];
939        config.write_to_slice(&mut payload[0..1]);
940
941        #[allow(unused_variables)]
942        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::SetStatusLedConfig), &payload).await?;
943        Ok(())
944    }
945
946    /// Returns the configuration as set by [`set_status_led_config`]
947    ///
948    /// Associated constants:
949    /// * INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_OFF
950    ///	* INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_ON
951    ///	* INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
952    ///	* INDUSTRIAL_COUNTER_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
953    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
954        let payload = [0; 0];
955
956        #[allow(unused_variables)]
957        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetStatusLedConfig), &payload).await?;
958        Ok(u8::from_le_byte_slice(result.body()))
959    }
960
961    /// Returns the temperature as measured inside the microcontroller. The
962    /// value returned is not the ambient temperature!
963    ///
964    /// The temperature is only proportional to the real temperature and it has bad
965    /// accuracy. Practically it is only useful as an indicator for
966    /// temperature changes.
967    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
968        let payload = [0; 0];
969
970        #[allow(unused_variables)]
971        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetChipTemperature), &payload).await?;
972        Ok(i16::from_le_byte_slice(result.body()))
973    }
974
975    /// Calling this function will reset the Bricklet. All configurations
976    /// will be lost.
977    ///
978    /// After a reset you have to create new device objects,
979    /// calling functions on the existing ones will result in
980    /// undefined behavior!
981    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
982        let payload = [0; 0];
983
984        #[allow(unused_variables)]
985        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::Reset), &payload).await?;
986        Ok(())
987    }
988
989    /// Writes a new UID into flash. If you want to set a new UID
990    /// you have to decode the Base58 encoded UID string into an
991    /// integer first.
992    ///
993    /// We recommend that you use Brick Viewer to change the UID.
994    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
995        let mut payload = [0; 4];
996        uid.write_to_slice(&mut payload[0..4]);
997
998        #[allow(unused_variables)]
999        let result = self.device.set(u8::from(IndustrialCounterBrickletFunction::WriteUid), &payload).await?;
1000        Ok(())
1001    }
1002
1003    /// Returns the current UID as an integer. Encode as
1004    /// Base58 to get the usual string version.
1005    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
1006        let payload = [0; 0];
1007
1008        #[allow(unused_variables)]
1009        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::ReadUid), &payload).await?;
1010        Ok(u32::from_le_byte_slice(result.body()))
1011    }
1012
1013    /// Returns the UID, the UID where the Bricklet is connected to,
1014    /// the position, the hardware and firmware version as well as the
1015    /// device identifier.
1016    ///
1017    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
1018    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
1019    /// position 'z'.
1020    ///
1021    /// The device identifier numbers can be found [here](device_identifier).
1022    /// |device_identifier_constant|
1023    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
1024        let payload = [0; 0];
1025
1026        #[allow(unused_variables)]
1027        let result = self.device.get(u8::from(IndustrialCounterBrickletFunction::GetIdentity), &payload).await?;
1028        Ok(Identity::from_le_byte_slice(result.body()))
1029    }
1030}