tinkerforge_async/bindings/
industrial_analog_out_v2_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//! Generates configurable DC voltage and current, 0V to 10V and 4mA to 20mA.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/IndustrialAnalogOutV2_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 IndustrialAnalogOutV2BrickletFunction {
24    SetEnabled,
25    GetEnabled,
26    SetVoltage,
27    GetVoltage,
28    SetCurrent,
29    GetCurrent,
30    SetConfiguration,
31    GetConfiguration,
32    SetOutLedConfig,
33    GetOutLedConfig,
34    SetOutLedStatusConfig,
35    GetOutLedStatusConfig,
36    GetSpitfpErrorCount,
37    SetBootloaderMode,
38    GetBootloaderMode,
39    SetWriteFirmwarePointer,
40    WriteFirmware,
41    SetStatusLedConfig,
42    GetStatusLedConfig,
43    GetChipTemperature,
44    Reset,
45    WriteUid,
46    ReadUid,
47    GetIdentity,
48}
49impl From<IndustrialAnalogOutV2BrickletFunction> for u8 {
50    fn from(fun: IndustrialAnalogOutV2BrickletFunction) -> Self {
51        match fun {
52            IndustrialAnalogOutV2BrickletFunction::SetEnabled => 1,
53            IndustrialAnalogOutV2BrickletFunction::GetEnabled => 2,
54            IndustrialAnalogOutV2BrickletFunction::SetVoltage => 3,
55            IndustrialAnalogOutV2BrickletFunction::GetVoltage => 4,
56            IndustrialAnalogOutV2BrickletFunction::SetCurrent => 5,
57            IndustrialAnalogOutV2BrickletFunction::GetCurrent => 6,
58            IndustrialAnalogOutV2BrickletFunction::SetConfiguration => 7,
59            IndustrialAnalogOutV2BrickletFunction::GetConfiguration => 8,
60            IndustrialAnalogOutV2BrickletFunction::SetOutLedConfig => 9,
61            IndustrialAnalogOutV2BrickletFunction::GetOutLedConfig => 10,
62            IndustrialAnalogOutV2BrickletFunction::SetOutLedStatusConfig => 11,
63            IndustrialAnalogOutV2BrickletFunction::GetOutLedStatusConfig => 12,
64            IndustrialAnalogOutV2BrickletFunction::GetSpitfpErrorCount => 234,
65            IndustrialAnalogOutV2BrickletFunction::SetBootloaderMode => 235,
66            IndustrialAnalogOutV2BrickletFunction::GetBootloaderMode => 236,
67            IndustrialAnalogOutV2BrickletFunction::SetWriteFirmwarePointer => 237,
68            IndustrialAnalogOutV2BrickletFunction::WriteFirmware => 238,
69            IndustrialAnalogOutV2BrickletFunction::SetStatusLedConfig => 239,
70            IndustrialAnalogOutV2BrickletFunction::GetStatusLedConfig => 240,
71            IndustrialAnalogOutV2BrickletFunction::GetChipTemperature => 242,
72            IndustrialAnalogOutV2BrickletFunction::Reset => 243,
73            IndustrialAnalogOutV2BrickletFunction::WriteUid => 248,
74            IndustrialAnalogOutV2BrickletFunction::ReadUid => 249,
75            IndustrialAnalogOutV2BrickletFunction::GetIdentity => 255,
76        }
77    }
78}
79pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_VOLTAGE_RANGE_0_TO_5V: u8 = 0;
80pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_VOLTAGE_RANGE_0_TO_10V: u8 = 1;
81pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_4_TO_20MA: u8 = 0;
82pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_0_TO_20MA: u8 = 1;
83pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_0_TO_24MA: u8 = 2;
84pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_OFF: u8 = 0;
85pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_ON: u8 = 1;
86pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
87pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_SHOW_OUT_STATUS: u8 = 3;
88pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_STATUS_CONFIG_THRESHOLD: u8 = 0;
89pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_STATUS_CONFIG_INTENSITY: u8 = 1;
90pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
91pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
92pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
93pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
94pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
95pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
96pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
97pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
98pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
99pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
100pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
101pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
102pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
103pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
104pub const INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
105
106#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
107pub struct Configuration {
108    pub voltage_range: u8,
109    pub current_range: u8,
110}
111impl FromByteSlice for Configuration {
112    fn bytes_expected() -> usize {
113        2
114    }
115    fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
116        Configuration { voltage_range: <u8>::from_le_byte_slice(&bytes[0..1]), current_range: <u8>::from_le_byte_slice(&bytes[1..2]) }
117    }
118}
119
120#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
121pub struct OutLedStatusConfig {
122    pub min: u16,
123    pub max: u16,
124    pub config: u8,
125}
126impl FromByteSlice for OutLedStatusConfig {
127    fn bytes_expected() -> usize {
128        5
129    }
130    fn from_le_byte_slice(bytes: &[u8]) -> OutLedStatusConfig {
131        OutLedStatusConfig {
132            min: <u16>::from_le_byte_slice(&bytes[0..2]),
133            max: <u16>::from_le_byte_slice(&bytes[2..4]),
134            config: <u8>::from_le_byte_slice(&bytes[4..5]),
135        }
136    }
137}
138
139#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
140pub struct SpitfpErrorCount {
141    pub error_count_ack_checksum: u32,
142    pub error_count_message_checksum: u32,
143    pub error_count_frame: u32,
144    pub error_count_overflow: u32,
145}
146impl FromByteSlice for SpitfpErrorCount {
147    fn bytes_expected() -> usize {
148        16
149    }
150    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
151        SpitfpErrorCount {
152            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
153            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
154            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
155            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
156        }
157    }
158}
159
160#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
161pub struct Identity {
162    pub uid: String,
163    pub connected_uid: String,
164    pub position: char,
165    pub hardware_version: [u8; 3],
166    pub firmware_version: [u8; 3],
167    pub device_identifier: u16,
168}
169impl FromByteSlice for Identity {
170    fn bytes_expected() -> usize {
171        25
172    }
173    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
174        Identity {
175            uid: <String>::from_le_byte_slice(&bytes[0..8]),
176            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
177            position: <char>::from_le_byte_slice(&bytes[16..17]),
178            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
179            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
180            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
181        }
182    }
183}
184
185/// Generates configurable DC voltage and current, 0V to 10V and 4mA to 20mA
186#[derive(Clone)]
187pub struct IndustrialAnalogOutV2Bricklet {
188    device: Device,
189}
190impl IndustrialAnalogOutV2Bricklet {
191    pub const DEVICE_IDENTIFIER: u16 = 2116;
192    pub const DEVICE_DISPLAY_NAME: &'static str = "Industrial Analog Out Bricklet 2.0";
193    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
194    pub fn new(uid: Uid, connection: AsyncIpConnection) -> IndustrialAnalogOutV2Bricklet {
195        let mut result = IndustrialAnalogOutV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
196        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetEnabled) as usize] = ResponseExpectedFlag::False;
197        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetEnabled) as usize] =
198            ResponseExpectedFlag::AlwaysTrue;
199        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetVoltage) as usize] = ResponseExpectedFlag::False;
200        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetVoltage) as usize] =
201            ResponseExpectedFlag::AlwaysTrue;
202        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetCurrent) as usize] = ResponseExpectedFlag::False;
203        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetCurrent) as usize] =
204            ResponseExpectedFlag::AlwaysTrue;
205        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetConfiguration) as usize] =
206            ResponseExpectedFlag::False;
207        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetConfiguration) as usize] =
208            ResponseExpectedFlag::AlwaysTrue;
209        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetOutLedConfig) as usize] =
210            ResponseExpectedFlag::False;
211        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetOutLedConfig) as usize] =
212            ResponseExpectedFlag::AlwaysTrue;
213        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetOutLedStatusConfig) as usize] =
214            ResponseExpectedFlag::False;
215        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetOutLedStatusConfig) as usize] =
216            ResponseExpectedFlag::AlwaysTrue;
217        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetSpitfpErrorCount) as usize] =
218            ResponseExpectedFlag::AlwaysTrue;
219        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetBootloaderMode) as usize] =
220            ResponseExpectedFlag::AlwaysTrue;
221        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetBootloaderMode) as usize] =
222            ResponseExpectedFlag::AlwaysTrue;
223        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
224            ResponseExpectedFlag::False;
225        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::WriteFirmware) as usize] =
226            ResponseExpectedFlag::AlwaysTrue;
227        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::SetStatusLedConfig) as usize] =
228            ResponseExpectedFlag::False;
229        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetStatusLedConfig) as usize] =
230            ResponseExpectedFlag::AlwaysTrue;
231        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetChipTemperature) as usize] =
232            ResponseExpectedFlag::AlwaysTrue;
233        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
234        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
235        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::ReadUid) as usize] =
236            ResponseExpectedFlag::AlwaysTrue;
237        result.device.response_expected[u8::from(IndustrialAnalogOutV2BrickletFunction::GetIdentity) as usize] =
238            ResponseExpectedFlag::AlwaysTrue;
239        result
240    }
241
242    /// Returns the response expected flag for the function specified by the function ID parameter.
243    /// It is true if the function is expected to send a response, false otherwise.
244    ///
245    /// For getter functions this is enabled by default and cannot be disabled, because those
246    /// functions will always send a response. For callback configuration functions it is enabled
247    /// by default too, but can be disabled by [`set_response_expected`](crate::industrial_analog_out_v2_bricklet::IndustrialAnalogOutV2Bricklet::set_response_expected).
248    /// For setter functions it is disabled by default and can be enabled.
249    ///
250    /// Enabling the response expected flag for a setter function allows to detect timeouts
251    /// and other error conditions calls of this setter as well. The device will then send a response
252    /// for this purpose. If this flag is disabled for a setter function then no response is sent
253    /// and errors are silently ignored, because they cannot be detected.
254    ///
255    /// See [`set_response_expected`](crate::industrial_analog_out_v2_bricklet::IndustrialAnalogOutV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
256    pub fn get_response_expected(&mut self, fun: IndustrialAnalogOutV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
257        self.device.get_response_expected(u8::from(fun))
258    }
259
260    /// Changes the response expected flag of the function specified by the function ID parameter.
261    /// This flag can only be changed for setter (default value: false) and callback configuration
262    /// functions (default value: true). For getter functions it is always enabled.
263    ///
264    /// Enabling the response expected flag for a setter function allows to detect timeouts and
265    /// other error conditions calls of this setter as well. The device will then send a response
266    /// for this purpose. If this flag is disabled for a setter function then no response is sent
267    /// and errors are silently ignored, because they cannot be detected.
268    pub fn set_response_expected(
269        &mut self,
270        fun: IndustrialAnalogOutV2BrickletFunction,
271        response_expected: bool,
272    ) -> Result<(), SetResponseExpectedError> {
273        self.device.set_response_expected(u8::from(fun), response_expected)
274    }
275
276    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
277    pub fn set_response_expected_all(&mut self, response_expected: bool) {
278        self.device.set_response_expected_all(response_expected)
279    }
280
281    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
282    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
283    pub fn get_api_version(&self) -> [u8; 3] {
284        self.device.api_version
285    }
286
287    /// Enables/disables the output of voltage and current.
288    pub async fn set_enabled(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
289        let mut payload = [0; 1];
290        enabled.write_to_slice(&mut payload[0..1]);
291
292        #[allow(unused_variables)]
293        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetEnabled), &payload).await?;
294        Ok(())
295    }
296
297    /// Returns *true* if output of voltage and current is enabled, *false* otherwise.
298    pub async fn get_enabled(&mut self) -> Result<bool, TinkerforgeError> {
299        let payload = [0; 0];
300
301        #[allow(unused_variables)]
302        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetEnabled), &payload).await?;
303        Ok(bool::from_le_byte_slice(result.body()))
304    }
305
306    /// Sets the output voltage.
307    ///
308    /// The output voltage and output current are linked. Changing the output voltage
309    /// also changes the output current.
310    pub async fn set_voltage(&mut self, voltage: u16) -> Result<(), TinkerforgeError> {
311        let mut payload = [0; 2];
312        voltage.write_to_slice(&mut payload[0..2]);
313
314        #[allow(unused_variables)]
315        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetVoltage), &payload).await?;
316        Ok(())
317    }
318
319    /// Returns the voltage as set by [`set_voltage`].
320    pub async fn get_voltage(&mut self) -> Result<u16, TinkerforgeError> {
321        let payload = [0; 0];
322
323        #[allow(unused_variables)]
324        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetVoltage), &payload).await?;
325        Ok(u16::from_le_byte_slice(result.body()))
326    }
327
328    /// Sets the output current.
329    ///
330    /// The output current and output voltage are linked. Changing the output current
331    /// also changes the output voltage.
332    pub async fn set_current(&mut self, current: u16) -> Result<(), TinkerforgeError> {
333        let mut payload = [0; 2];
334        current.write_to_slice(&mut payload[0..2]);
335
336        #[allow(unused_variables)]
337        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetCurrent), &payload).await?;
338        Ok(())
339    }
340
341    /// Returns the current as set by [`set_current`].
342    pub async fn get_current(&mut self) -> Result<u16, TinkerforgeError> {
343        let payload = [0; 0];
344
345        #[allow(unused_variables)]
346        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetCurrent), &payload).await?;
347        Ok(u16::from_le_byte_slice(result.body()))
348    }
349
350    /// Configures the voltage and current range.
351    ///
352    /// Possible voltage ranges are:
353    ///
354    /// * 0V to 5V
355    /// * 0V to 10V
356    ///
357    /// Possible current ranges are:
358    ///
359    /// * 4mA to 20mA
360    /// * 0mA to 20mA
361    /// * 0mA to 24mA
362    ///
363    /// The resolution will always be 12 bit. This means, that the
364    /// precision is higher with a smaller range.
365    ///
366    /// Associated constants:
367    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_VOLTAGE_RANGE_0_TO_5V
368    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_VOLTAGE_RANGE_0_TO_10V
369    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_4_TO_20MA
370    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_0_TO_20MA
371    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_0_TO_24MA
372    pub async fn set_configuration(&mut self, voltage_range: u8, current_range: u8) -> Result<(), TinkerforgeError> {
373        let mut payload = [0; 2];
374        voltage_range.write_to_slice(&mut payload[0..1]);
375        current_range.write_to_slice(&mut payload[1..2]);
376
377        #[allow(unused_variables)]
378        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetConfiguration), &payload).await?;
379        Ok(())
380    }
381
382    /// Returns the configuration as set by [`set_configuration`].
383    ///
384    /// Associated constants:
385    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_VOLTAGE_RANGE_0_TO_5V
386    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_VOLTAGE_RANGE_0_TO_10V
387    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_4_TO_20MA
388    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_0_TO_20MA
389    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_CURRENT_RANGE_0_TO_24MA
390    pub async fn get_configuration(&mut self) -> Result<Configuration, TinkerforgeError> {
391        let payload = [0; 0];
392
393        #[allow(unused_variables)]
394        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetConfiguration), &payload).await?;
395        Ok(Configuration::from_le_byte_slice(result.body()))
396    }
397
398    /// You can turn the Out LED off, on or show a
399    /// heartbeat. You can also set the LED to Out Status. In this mode the
400    /// LED can either be turned on with a pre-defined threshold or the intensity
401    /// of the LED can change with the output value (voltage or current).
402    ///
403    /// You can configure the channel status behavior with [`set_out_led_status_config`].
404    ///
405    /// Associated constants:
406    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_OFF
407    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_ON
408    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_SHOW_HEARTBEAT
409    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_SHOW_OUT_STATUS
410    pub async fn set_out_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
411        let mut payload = [0; 1];
412        config.write_to_slice(&mut payload[0..1]);
413
414        #[allow(unused_variables)]
415        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetOutLedConfig), &payload).await?;
416        Ok(())
417    }
418
419    /// Returns the Out LED configuration as set by [`set_out_led_config`]
420    ///
421    /// Associated constants:
422    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_OFF
423    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_ON
424    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_SHOW_HEARTBEAT
425    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_CONFIG_SHOW_OUT_STATUS
426    pub async fn get_out_led_config(&mut self) -> Result<u8, TinkerforgeError> {
427        let payload = [0; 0];
428
429        #[allow(unused_variables)]
430        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetOutLedConfig), &payload).await?;
431        Ok(u8::from_le_byte_slice(result.body()))
432    }
433
434    /// Sets the Out LED status config. This config is used if the Out LED is
435    /// configured as Out Status, see [`set_out_led_config`].
436    ///
437    /// For each channel you can choose between threshold and intensity mode.
438    ///
439    /// In threshold mode you can define a positive or a negative threshold.
440    /// For a positive threshold set the min parameter to the threshold value in mV or
441    /// µA above which the LED should turn on and set the max parameter to 0. Example:
442    /// If you set a positive threshold of 5V, the LED will turn on as soon as the
443    /// output value exceeds 5V and turn off again if it goes below 5V.
444    /// For a negative threshold set the max parameter to the threshold value in mV or
445    /// µA below which the LED should turn on and set the min parameter to 0. Example:
446    /// If you set a negative threshold of 5V, the LED will turn on as soon as the
447    /// output value goes below 5V and the LED will turn off when the output value
448    /// exceeds 5V.
449    ///
450    /// In intensity mode you can define a range mV or µA that is used to scale the brightness
451    /// of the LED. Example with min=2V, max=8V: The LED is off at 2V and below, on at
452    /// 8V and above and the brightness is linearly scaled between the values 2V and 8V.
453    /// If the min value is greater than the max value, the LED brightness is scaled the
454    /// other way around.
455    ///
456    /// Associated constants:
457    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_STATUS_CONFIG_THRESHOLD
458    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_STATUS_CONFIG_INTENSITY
459    pub async fn set_out_led_status_config(&mut self, min: u16, max: u16, config: u8) -> Result<(), TinkerforgeError> {
460        let mut payload = [0; 5];
461        min.write_to_slice(&mut payload[0..2]);
462        max.write_to_slice(&mut payload[2..4]);
463        config.write_to_slice(&mut payload[4..5]);
464
465        #[allow(unused_variables)]
466        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetOutLedStatusConfig), &payload).await?;
467        Ok(())
468    }
469
470    /// Returns the Out LED status configuration as set by [`set_out_led_status_config`].
471    ///
472    /// Associated constants:
473    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_STATUS_CONFIG_THRESHOLD
474    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_OUT_LED_STATUS_CONFIG_INTENSITY
475    pub async fn get_out_led_status_config(&mut self) -> Result<OutLedStatusConfig, TinkerforgeError> {
476        let payload = [0; 0];
477
478        #[allow(unused_variables)]
479        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetOutLedStatusConfig), &payload).await?;
480        Ok(OutLedStatusConfig::from_le_byte_slice(result.body()))
481    }
482
483    /// Returns the error count for the communication between Brick and Bricklet.
484    ///
485    /// The errors are divided into
486    ///
487    /// * ACK checksum errors,
488    /// * message checksum errors,
489    /// * framing errors and
490    /// * overflow errors.
491    ///
492    /// The errors counts are for errors that occur on the Bricklet side. All
493    /// Bricks have a similar function that returns the errors on the Brick side.
494    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
495        let payload = [0; 0];
496
497        #[allow(unused_variables)]
498        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
499        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
500    }
501
502    /// Sets the bootloader mode and returns the status after the requested
503    /// mode change was instigated.
504    ///
505    /// You can change from bootloader mode to firmware mode and vice versa. A change
506    /// from bootloader mode to firmware mode will only take place if the entry function,
507    /// device identifier and CRC are present and correct.
508    ///
509    /// This function is used by Brick Viewer during flashing. It should not be
510    /// necessary to call it in a normal user program.
511    ///
512    /// Associated constants:
513    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
514    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
515    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
516    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
517    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
518    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_OK
519    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
520    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
521    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
522    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
523    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
524    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
525        let mut payload = [0; 1];
526        mode.write_to_slice(&mut payload[0..1]);
527
528        #[allow(unused_variables)]
529        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::SetBootloaderMode), &payload).await?;
530        Ok(u8::from_le_byte_slice(result.body()))
531    }
532
533    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
534    ///
535    /// Associated constants:
536    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
537    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
538    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
539    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
540    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
541    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
542        let payload = [0; 0];
543
544        #[allow(unused_variables)]
545        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetBootloaderMode), &payload).await?;
546        Ok(u8::from_le_byte_slice(result.body()))
547    }
548
549    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
550    /// to be increased by chunks of size 64. The data is written to flash
551    /// every 4 chunks (which equals to one page of size 256).
552    ///
553    /// This function is used by Brick Viewer during flashing. It should not be
554    /// necessary to call it in a normal user program.
555    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
556        let mut payload = [0; 4];
557        pointer.write_to_slice(&mut payload[0..4]);
558
559        #[allow(unused_variables)]
560        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
561        Ok(())
562    }
563
564    /// Writes 64 Bytes of firmware at the position as written by
565    /// [`set_write_firmware_pointer`] before. The firmware is written
566    /// to flash every 4 chunks.
567    ///
568    /// You can only write firmware in bootloader mode.
569    ///
570    /// This function is used by Brick Viewer during flashing. It should not be
571    /// necessary to call it in a normal user program.
572    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
573        let mut payload = [0; 64];
574        data.write_to_slice(&mut payload[0..64]);
575
576        #[allow(unused_variables)]
577        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::WriteFirmware), &payload).await?;
578        Ok(u8::from_le_byte_slice(result.body()))
579    }
580
581    /// Sets the status LED configuration. By default the LED shows
582    /// communication traffic between Brick and Bricklet, it flickers once
583    /// for every 10 received data packets.
584    ///
585    /// You can also turn the LED permanently on/off or show a heartbeat.
586    ///
587    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
588    ///
589    /// Associated constants:
590    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_OFF
591    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_ON
592    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
593    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
594    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
595        let mut payload = [0; 1];
596        config.write_to_slice(&mut payload[0..1]);
597
598        #[allow(unused_variables)]
599        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::SetStatusLedConfig), &payload).await?;
600        Ok(())
601    }
602
603    /// Returns the configuration as set by [`set_status_led_config`]
604    ///
605    /// Associated constants:
606    /// * INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_OFF
607    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_ON
608    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
609    ///	* INDUSTRIAL_ANALOG_OUT_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
610    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
611        let payload = [0; 0];
612
613        #[allow(unused_variables)]
614        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetStatusLedConfig), &payload).await?;
615        Ok(u8::from_le_byte_slice(result.body()))
616    }
617
618    /// Returns the temperature as measured inside the microcontroller. The
619    /// value returned is not the ambient temperature!
620    ///
621    /// The temperature is only proportional to the real temperature and it has bad
622    /// accuracy. Practically it is only useful as an indicator for
623    /// temperature changes.
624    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
625        let payload = [0; 0];
626
627        #[allow(unused_variables)]
628        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetChipTemperature), &payload).await?;
629        Ok(i16::from_le_byte_slice(result.body()))
630    }
631
632    /// Calling this function will reset the Bricklet. All configurations
633    /// will be lost.
634    ///
635    /// After a reset you have to create new device objects,
636    /// calling functions on the existing ones will result in
637    /// undefined behavior!
638    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
639        let payload = [0; 0];
640
641        #[allow(unused_variables)]
642        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::Reset), &payload).await?;
643        Ok(())
644    }
645
646    /// Writes a new UID into flash. If you want to set a new UID
647    /// you have to decode the Base58 encoded UID string into an
648    /// integer first.
649    ///
650    /// We recommend that you use Brick Viewer to change the UID.
651    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
652        let mut payload = [0; 4];
653        uid.write_to_slice(&mut payload[0..4]);
654
655        #[allow(unused_variables)]
656        let result = self.device.set(u8::from(IndustrialAnalogOutV2BrickletFunction::WriteUid), &payload).await?;
657        Ok(())
658    }
659
660    /// Returns the current UID as an integer. Encode as
661    /// Base58 to get the usual string version.
662    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
663        let payload = [0; 0];
664
665        #[allow(unused_variables)]
666        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::ReadUid), &payload).await?;
667        Ok(u32::from_le_byte_slice(result.body()))
668    }
669
670    /// Returns the UID, the UID where the Bricklet is connected to,
671    /// the position, the hardware and firmware version as well as the
672    /// device identifier.
673    ///
674    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
675    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
676    /// position 'z'.
677    ///
678    /// The device identifier numbers can be found [here](device_identifier).
679    /// |device_identifier_constant|
680    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
681        let payload = [0; 0];
682
683        #[allow(unused_variables)]
684        let result = self.device.get(u8::from(IndustrialAnalogOutV2BrickletFunction::GetIdentity), &payload).await?;
685        Ok(Identity::from_le_byte_slice(result.body()))
686    }
687}