tinkerforge_async/bindings/
analog_in_v3_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//! Measures DC voltage between 0V and 42V.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/AnalogInV3_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 AnalogInV3BrickletFunction {
24    GetVoltage,
25    SetVoltageCallbackConfiguration,
26    GetVoltageCallbackConfiguration,
27    SetOversampling,
28    GetOversampling,
29    SetCalibration,
30    GetCalibration,
31    GetSpitfpErrorCount,
32    SetBootloaderMode,
33    GetBootloaderMode,
34    SetWriteFirmwarePointer,
35    WriteFirmware,
36    SetStatusLedConfig,
37    GetStatusLedConfig,
38    GetChipTemperature,
39    Reset,
40    WriteUid,
41    ReadUid,
42    GetIdentity,
43    CallbackVoltage,
44}
45impl From<AnalogInV3BrickletFunction> for u8 {
46    fn from(fun: AnalogInV3BrickletFunction) -> Self {
47        match fun {
48            AnalogInV3BrickletFunction::GetVoltage => 1,
49            AnalogInV3BrickletFunction::SetVoltageCallbackConfiguration => 2,
50            AnalogInV3BrickletFunction::GetVoltageCallbackConfiguration => 3,
51            AnalogInV3BrickletFunction::SetOversampling => 5,
52            AnalogInV3BrickletFunction::GetOversampling => 6,
53            AnalogInV3BrickletFunction::SetCalibration => 7,
54            AnalogInV3BrickletFunction::GetCalibration => 8,
55            AnalogInV3BrickletFunction::GetSpitfpErrorCount => 234,
56            AnalogInV3BrickletFunction::SetBootloaderMode => 235,
57            AnalogInV3BrickletFunction::GetBootloaderMode => 236,
58            AnalogInV3BrickletFunction::SetWriteFirmwarePointer => 237,
59            AnalogInV3BrickletFunction::WriteFirmware => 238,
60            AnalogInV3BrickletFunction::SetStatusLedConfig => 239,
61            AnalogInV3BrickletFunction::GetStatusLedConfig => 240,
62            AnalogInV3BrickletFunction::GetChipTemperature => 242,
63            AnalogInV3BrickletFunction::Reset => 243,
64            AnalogInV3BrickletFunction::WriteUid => 248,
65            AnalogInV3BrickletFunction::ReadUid => 249,
66            AnalogInV3BrickletFunction::GetIdentity => 255,
67            AnalogInV3BrickletFunction::CallbackVoltage => 4,
68        }
69    }
70}
71pub const ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
72pub const ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
73pub const ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
74pub const ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
75pub const ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
76pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_32: u8 = 0;
77pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_64: u8 = 1;
78pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_128: u8 = 2;
79pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_256: u8 = 3;
80pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_512: u8 = 4;
81pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_1024: u8 = 5;
82pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_2048: u8 = 6;
83pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_4096: u8 = 7;
84pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_8192: u8 = 8;
85pub const ANALOG_IN_V3_BRICKLET_OVERSAMPLING_16384: u8 = 9;
86pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
87pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
88pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
89pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
90pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
91pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
92pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
93pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
94pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
95pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
96pub const ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
97pub const ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
98pub const ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
99pub const ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
100pub const ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
101
102#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
103pub struct VoltageCallbackConfiguration {
104    pub period: u32,
105    pub value_has_to_change: bool,
106    pub option: char,
107    pub min: u16,
108    pub max: u16,
109}
110impl FromByteSlice for VoltageCallbackConfiguration {
111    fn bytes_expected() -> usize {
112        10
113    }
114    fn from_le_byte_slice(bytes: &[u8]) -> VoltageCallbackConfiguration {
115        VoltageCallbackConfiguration {
116            period: <u32>::from_le_byte_slice(&bytes[0..4]),
117            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
118            option: <char>::from_le_byte_slice(&bytes[5..6]),
119            min: <u16>::from_le_byte_slice(&bytes[6..8]),
120            max: <u16>::from_le_byte_slice(&bytes[8..10]),
121        }
122    }
123}
124
125#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
126pub struct Calibration {
127    pub offset: i16,
128    pub multiplier: u16,
129    pub divisor: u16,
130}
131impl FromByteSlice for Calibration {
132    fn bytes_expected() -> usize {
133        6
134    }
135    fn from_le_byte_slice(bytes: &[u8]) -> Calibration {
136        Calibration {
137            offset: <i16>::from_le_byte_slice(&bytes[0..2]),
138            multiplier: <u16>::from_le_byte_slice(&bytes[2..4]),
139            divisor: <u16>::from_le_byte_slice(&bytes[4..6]),
140        }
141    }
142}
143
144#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
145pub struct SpitfpErrorCount {
146    pub error_count_ack_checksum: u32,
147    pub error_count_message_checksum: u32,
148    pub error_count_frame: u32,
149    pub error_count_overflow: u32,
150}
151impl FromByteSlice for SpitfpErrorCount {
152    fn bytes_expected() -> usize {
153        16
154    }
155    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
156        SpitfpErrorCount {
157            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
158            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
159            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
160            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
161        }
162    }
163}
164
165#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
166pub struct Identity {
167    pub uid: String,
168    pub connected_uid: String,
169    pub position: char,
170    pub hardware_version: [u8; 3],
171    pub firmware_version: [u8; 3],
172    pub device_identifier: u16,
173}
174impl FromByteSlice for Identity {
175    fn bytes_expected() -> usize {
176        25
177    }
178    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
179        Identity {
180            uid: <String>::from_le_byte_slice(&bytes[0..8]),
181            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
182            position: <char>::from_le_byte_slice(&bytes[16..17]),
183            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
184            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
185            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
186        }
187    }
188}
189
190/// Measures DC voltage between 0V and 42V
191#[derive(Clone)]
192pub struct AnalogInV3Bricklet {
193    device: Device,
194}
195impl AnalogInV3Bricklet {
196    pub const DEVICE_IDENTIFIER: u16 = 295;
197    pub const DEVICE_DISPLAY_NAME: &'static str = "Analog In Bricklet 3.0";
198    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
199    pub fn new(uid: Uid, connection: AsyncIpConnection) -> AnalogInV3Bricklet {
200        let mut result = AnalogInV3Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
201        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
202        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::SetVoltageCallbackConfiguration) as usize] =
203            ResponseExpectedFlag::True;
204        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetVoltageCallbackConfiguration) as usize] =
205            ResponseExpectedFlag::AlwaysTrue;
206        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::SetOversampling) as usize] = ResponseExpectedFlag::False;
207        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetOversampling) as usize] = ResponseExpectedFlag::AlwaysTrue;
208        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::SetCalibration) as usize] = ResponseExpectedFlag::False;
209        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetCalibration) as usize] = ResponseExpectedFlag::AlwaysTrue;
210        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetSpitfpErrorCount) as usize] =
211            ResponseExpectedFlag::AlwaysTrue;
212        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::SetBootloaderMode) as usize] =
213            ResponseExpectedFlag::AlwaysTrue;
214        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetBootloaderMode) as usize] =
215            ResponseExpectedFlag::AlwaysTrue;
216        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::SetWriteFirmwarePointer) as usize] =
217            ResponseExpectedFlag::False;
218        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
219        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
220        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetStatusLedConfig) as usize] =
221            ResponseExpectedFlag::AlwaysTrue;
222        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetChipTemperature) as usize] =
223            ResponseExpectedFlag::AlwaysTrue;
224        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
225        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
226        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
227        result.device.response_expected[u8::from(AnalogInV3BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
228        result
229    }
230
231    /// Returns the response expected flag for the function specified by the function ID parameter.
232    /// It is true if the function is expected to send a response, false otherwise.
233    ///
234    /// For getter functions this is enabled by default and cannot be disabled, because those
235    /// functions will always send a response. For callback configuration functions it is enabled
236    /// by default too, but can be disabled by [`set_response_expected`](crate::analog_in_v3_bricklet::AnalogInV3Bricklet::set_response_expected).
237    /// For setter functions it is disabled by default and can be enabled.
238    ///
239    /// Enabling the response expected flag for a setter function allows to detect timeouts
240    /// and other error conditions calls of this setter as well. The device will then send a response
241    /// for this purpose. If this flag is disabled for a setter function then no response is sent
242    /// and errors are silently ignored, because they cannot be detected.
243    ///
244    /// See [`set_response_expected`](crate::analog_in_v3_bricklet::AnalogInV3Bricklet::set_response_expected) for the list of function ID constants available for this function.
245    pub fn get_response_expected(&mut self, fun: AnalogInV3BrickletFunction) -> Result<bool, GetResponseExpectedError> {
246        self.device.get_response_expected(u8::from(fun))
247    }
248
249    /// Changes the response expected flag of the function specified by the function ID parameter.
250    /// This flag can only be changed for setter (default value: false) and callback configuration
251    /// functions (default value: true). For getter functions it is always enabled.
252    ///
253    /// Enabling the response expected flag for a setter function allows to detect timeouts and
254    /// other error conditions calls of this setter as well. The device will then send a response
255    /// for this purpose. If this flag is disabled for a setter function then no response is sent
256    /// and errors are silently ignored, because they cannot be detected.
257    pub fn set_response_expected(
258        &mut self,
259        fun: AnalogInV3BrickletFunction,
260        response_expected: bool,
261    ) -> Result<(), SetResponseExpectedError> {
262        self.device.set_response_expected(u8::from(fun), response_expected)
263    }
264
265    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
266    pub fn set_response_expected_all(&mut self, response_expected: bool) {
267        self.device.set_response_expected_all(response_expected)
268    }
269
270    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
271    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
272    pub fn get_api_version(&self) -> [u8; 3] {
273        self.device.api_version
274    }
275
276    /// This receiver is triggered periodically according to the configuration set by
277    /// [`set_voltage_callback_configuration`].
278    ///
279    /// The parameter is the same as [`get_voltage`].
280    ///
281    /// [`get_voltage`]: #method.get_voltage
282    /// [`set_voltage_callback_configuration`]: #method.set_voltage_callback_configuration
283    pub async fn get_voltage_callback_receiver(&mut self) -> impl Stream<Item = u16> {
284        self.device
285            .get_callback_receiver(u8::from(AnalogInV3BrickletFunction::CallbackVoltage))
286            .await
287            .map(|p| u16::from_le_byte_slice(p.body()))
288    }
289
290    /// Returns the measured voltage. The resolution is approximately 10mV to 1mV
291    /// depending on the oversampling configuration ([`set_oversampling`]).
292    ///
293    ///
294    /// If you want to get the value periodically, it is recommended to use the
295    /// [`get_voltage_callback_receiver`] receiver. You can set the receiver configuration
296    /// with [`set_voltage_callback_configuration`].
297    pub async fn get_voltage(&mut self) -> Result<u16, TinkerforgeError> {
298        let payload = [0; 0];
299
300        #[allow(unused_variables)]
301        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetVoltage), &payload).await?;
302        Ok(u16::from_le_byte_slice(result.body()))
303    }
304
305    /// The period is the period with which the [`get_voltage_callback_receiver`] receiver is triggered
306    /// periodically. A value of 0 turns the receiver off.
307    ///
308    /// If the `value has to change`-parameter is set to true, the receiver is only
309    /// triggered after the value has changed. If the value didn't change
310    /// within the period, the receiver is triggered immediately on change.
311    ///
312    /// If it is set to false, the receiver is continuously triggered with the period,
313    /// independent of the value.
314    ///
315    /// It is furthermore possible to constrain the receiver with thresholds.
316    ///
317    /// The `option`-parameter together with min/max sets a threshold for the [`get_voltage_callback_receiver`] receiver.
318    ///
319    /// The following options are possible:
320    ///
321    ///  Option| Description
322    ///  --- | ---
323    ///  'x'|    Threshold is turned off
324    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
325    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
326    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
327    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
328    ///
329    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
330    ///
331    /// Associated constants:
332    /// * ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_OFF
333    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_OUTSIDE
334    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_INSIDE
335    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_SMALLER
336    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_GREATER
337    pub async fn set_voltage_callback_configuration(
338        &mut self,
339        period: u32,
340        value_has_to_change: bool,
341        option: char,
342        min: u16,
343        max: u16,
344    ) -> Result<(), TinkerforgeError> {
345        let mut payload = [0; 10];
346        period.write_to_slice(&mut payload[0..4]);
347        value_has_to_change.write_to_slice(&mut payload[4..5]);
348        option.write_to_slice(&mut payload[5..6]);
349        min.write_to_slice(&mut payload[6..8]);
350        max.write_to_slice(&mut payload[8..10]);
351
352        #[allow(unused_variables)]
353        let result = self.device.set(u8::from(AnalogInV3BrickletFunction::SetVoltageCallbackConfiguration), &payload).await?;
354        Ok(())
355    }
356
357    /// Returns the receiver configuration as set by [`set_voltage_callback_configuration`].
358    ///
359    /// Associated constants:
360    /// * ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_OFF
361    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_OUTSIDE
362    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_INSIDE
363    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_SMALLER
364    ///	* ANALOG_IN_V3_BRICKLET_THRESHOLD_OPTION_GREATER
365    pub async fn get_voltage_callback_configuration(&mut self) -> Result<VoltageCallbackConfiguration, TinkerforgeError> {
366        let payload = [0; 0];
367
368        #[allow(unused_variables)]
369        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetVoltageCallbackConfiguration), &payload).await?;
370        Ok(VoltageCallbackConfiguration::from_le_byte_slice(result.body()))
371    }
372
373    /// Sets the oversampling between 32x and 16384x. The Bricklet
374    /// takes one 12bit sample every 17.5µs. Thus an oversampling
375    /// of 32x is equivalent to an integration time of 0.56ms and
376    /// a oversampling of 16384x is equivalent to an integration
377    /// time of 286ms.
378    ///
379    /// The oversampling uses the moving average principle. A
380    /// new value is always calculated once per millisecond.
381    ///
382    /// With increased oversampling the noise decreases. With decreased
383    /// oversampling the reaction time increases (changes in voltage will be
384    /// measured faster).
385    ///
386    /// Associated constants:
387    /// * ANALOG_IN_V3_BRICKLET_OVERSAMPLING_32
388    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_64
389    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_128
390    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_256
391    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_512
392    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_1024
393    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_2048
394    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_4096
395    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_8192
396    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_16384
397    pub async fn set_oversampling(&mut self, oversampling: u8) -> Result<(), TinkerforgeError> {
398        let mut payload = [0; 1];
399        oversampling.write_to_slice(&mut payload[0..1]);
400
401        #[allow(unused_variables)]
402        let result = self.device.set(u8::from(AnalogInV3BrickletFunction::SetOversampling), &payload).await?;
403        Ok(())
404    }
405
406    /// Returns the oversampling value as set by [`set_oversampling`].
407    ///
408    /// Associated constants:
409    /// * ANALOG_IN_V3_BRICKLET_OVERSAMPLING_32
410    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_64
411    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_128
412    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_256
413    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_512
414    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_1024
415    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_2048
416    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_4096
417    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_8192
418    ///	* ANALOG_IN_V3_BRICKLET_OVERSAMPLING_16384
419    pub async fn get_oversampling(&mut self) -> Result<u8, TinkerforgeError> {
420        let payload = [0; 0];
421
422        #[allow(unused_variables)]
423        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetOversampling), &payload).await?;
424        Ok(u8::from_le_byte_slice(result.body()))
425    }
426
427    /// Sets a calibration for the measured voltage value.
428    /// The formula for the calibration is as follows::
429    ///
430    ///  Calibrated Value = (Value + Offset) * Multiplier / Divisor
431    ///
432    /// We recommend that you use the Brick Viewer to calibrate
433    /// the Bricklet. The calibration will be saved internally and only
434    /// has to be done once.
435    pub async fn set_calibration(&mut self, offset: i16, multiplier: u16, divisor: u16) -> Result<(), TinkerforgeError> {
436        let mut payload = [0; 6];
437        offset.write_to_slice(&mut payload[0..2]);
438        multiplier.write_to_slice(&mut payload[2..4]);
439        divisor.write_to_slice(&mut payload[4..6]);
440
441        #[allow(unused_variables)]
442        let result = self.device.set(u8::from(AnalogInV3BrickletFunction::SetCalibration), &payload).await?;
443        Ok(())
444    }
445
446    /// Returns the calibration as set by [`set_calibration`].
447    pub async fn get_calibration(&mut self) -> Result<Calibration, TinkerforgeError> {
448        let payload = [0; 0];
449
450        #[allow(unused_variables)]
451        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetCalibration), &payload).await?;
452        Ok(Calibration::from_le_byte_slice(result.body()))
453    }
454
455    /// Returns the error count for the communication between Brick and Bricklet.
456    ///
457    /// The errors are divided into
458    ///
459    /// * ACK checksum errors,
460    /// * message checksum errors,
461    /// * framing errors and
462    /// * overflow errors.
463    ///
464    /// The errors counts are for errors that occur on the Bricklet side. All
465    /// Bricks have a similar function that returns the errors on the Brick side.
466    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
467        let payload = [0; 0];
468
469        #[allow(unused_variables)]
470        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetSpitfpErrorCount), &payload).await?;
471        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
472    }
473
474    /// Sets the bootloader mode and returns the status after the requested
475    /// mode change was instigated.
476    ///
477    /// You can change from bootloader mode to firmware mode and vice versa. A change
478    /// from bootloader mode to firmware mode will only take place if the entry function,
479    /// device identifier and CRC are present and correct.
480    ///
481    /// This function is used by Brick Viewer during flashing. It should not be
482    /// necessary to call it in a normal user program.
483    ///
484    /// Associated constants:
485    /// * ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
486    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE
487    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
488    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
489    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
490    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_OK
491    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
492    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
493    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
494    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
495    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
496    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
497        let mut payload = [0; 1];
498        mode.write_to_slice(&mut payload[0..1]);
499
500        #[allow(unused_variables)]
501        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::SetBootloaderMode), &payload).await?;
502        Ok(u8::from_le_byte_slice(result.body()))
503    }
504
505    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
506    ///
507    /// Associated constants:
508    /// * ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
509    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE
510    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
511    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
512    ///	* ANALOG_IN_V3_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
513    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
514        let payload = [0; 0];
515
516        #[allow(unused_variables)]
517        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetBootloaderMode), &payload).await?;
518        Ok(u8::from_le_byte_slice(result.body()))
519    }
520
521    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
522    /// to be increased by chunks of size 64. The data is written to flash
523    /// every 4 chunks (which equals to one page of size 256).
524    ///
525    /// This function is used by Brick Viewer during flashing. It should not be
526    /// necessary to call it in a normal user program.
527    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
528        let mut payload = [0; 4];
529        pointer.write_to_slice(&mut payload[0..4]);
530
531        #[allow(unused_variables)]
532        let result = self.device.set(u8::from(AnalogInV3BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
533        Ok(())
534    }
535
536    /// Writes 64 Bytes of firmware at the position as written by
537    /// [`set_write_firmware_pointer`] before. The firmware is written
538    /// to flash every 4 chunks.
539    ///
540    /// You can only write firmware in bootloader mode.
541    ///
542    /// This function is used by Brick Viewer during flashing. It should not be
543    /// necessary to call it in a normal user program.
544    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
545        let mut payload = [0; 64];
546        data.write_to_slice(&mut payload[0..64]);
547
548        #[allow(unused_variables)]
549        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::WriteFirmware), &payload).await?;
550        Ok(u8::from_le_byte_slice(result.body()))
551    }
552
553    /// Sets the status LED configuration. By default the LED shows
554    /// communication traffic between Brick and Bricklet, it flickers once
555    /// for every 10 received data packets.
556    ///
557    /// You can also turn the LED permanently on/off or show a heartbeat.
558    ///
559    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
560    ///
561    /// Associated constants:
562    /// * ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_OFF
563    ///	* ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_ON
564    ///	* ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
565    ///	* ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
566    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
567        let mut payload = [0; 1];
568        config.write_to_slice(&mut payload[0..1]);
569
570        #[allow(unused_variables)]
571        let result = self.device.set(u8::from(AnalogInV3BrickletFunction::SetStatusLedConfig), &payload).await?;
572        Ok(())
573    }
574
575    /// Returns the configuration as set by [`set_status_led_config`]
576    ///
577    /// Associated constants:
578    /// * ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_OFF
579    ///	* ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_ON
580    ///	* ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
581    ///	* ANALOG_IN_V3_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
582    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
583        let payload = [0; 0];
584
585        #[allow(unused_variables)]
586        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetStatusLedConfig), &payload).await?;
587        Ok(u8::from_le_byte_slice(result.body()))
588    }
589
590    /// Returns the temperature as measured inside the microcontroller. The
591    /// value returned is not the ambient temperature!
592    ///
593    /// The temperature is only proportional to the real temperature and it has bad
594    /// accuracy. Practically it is only useful as an indicator for
595    /// temperature changes.
596    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
597        let payload = [0; 0];
598
599        #[allow(unused_variables)]
600        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetChipTemperature), &payload).await?;
601        Ok(i16::from_le_byte_slice(result.body()))
602    }
603
604    /// Calling this function will reset the Bricklet. All configurations
605    /// will be lost.
606    ///
607    /// After a reset you have to create new device objects,
608    /// calling functions on the existing ones will result in
609    /// undefined behavior!
610    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
611        let payload = [0; 0];
612
613        #[allow(unused_variables)]
614        let result = self.device.set(u8::from(AnalogInV3BrickletFunction::Reset), &payload).await?;
615        Ok(())
616    }
617
618    /// Writes a new UID into flash. If you want to set a new UID
619    /// you have to decode the Base58 encoded UID string into an
620    /// integer first.
621    ///
622    /// We recommend that you use Brick Viewer to change the UID.
623    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
624        let mut payload = [0; 4];
625        uid.write_to_slice(&mut payload[0..4]);
626
627        #[allow(unused_variables)]
628        let result = self.device.set(u8::from(AnalogInV3BrickletFunction::WriteUid), &payload).await?;
629        Ok(())
630    }
631
632    /// Returns the current UID as an integer. Encode as
633    /// Base58 to get the usual string version.
634    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
635        let payload = [0; 0];
636
637        #[allow(unused_variables)]
638        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::ReadUid), &payload).await?;
639        Ok(u32::from_le_byte_slice(result.body()))
640    }
641
642    /// Returns the UID, the UID where the Bricklet is connected to,
643    /// the position, the hardware and firmware version as well as the
644    /// device identifier.
645    ///
646    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
647    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
648    /// position 'z'.
649    ///
650    /// The device identifier numbers can be found [here](device_identifier).
651    /// |device_identifier_constant|
652    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
653        let payload = [0; 0];
654
655        #[allow(unused_variables)]
656        let result = self.device.get(u8::from(AnalogInV3BrickletFunction::GetIdentity), &payload).await?;
657        Ok(Identity::from_le_byte_slice(result.body()))
658    }
659}