tinkerforge_async/bindings/
humidity_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//! Measures relative humidity.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/HumidityV2_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 HumidityV2BrickletFunction {
24    GetHumidity,
25    SetHumidityCallbackConfiguration,
26    GetHumidityCallbackConfiguration,
27    GetTemperature,
28    SetTemperatureCallbackConfiguration,
29    GetTemperatureCallbackConfiguration,
30    SetHeaterConfiguration,
31    GetHeaterConfiguration,
32    SetMovingAverageConfiguration,
33    GetMovingAverageConfiguration,
34    SetSamplesPerSecond,
35    GetSamplesPerSecond,
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    CallbackHumidity,
49    CallbackTemperature,
50}
51impl From<HumidityV2BrickletFunction> for u8 {
52    fn from(fun: HumidityV2BrickletFunction) -> Self {
53        match fun {
54            HumidityV2BrickletFunction::GetHumidity => 1,
55            HumidityV2BrickletFunction::SetHumidityCallbackConfiguration => 2,
56            HumidityV2BrickletFunction::GetHumidityCallbackConfiguration => 3,
57            HumidityV2BrickletFunction::GetTemperature => 5,
58            HumidityV2BrickletFunction::SetTemperatureCallbackConfiguration => 6,
59            HumidityV2BrickletFunction::GetTemperatureCallbackConfiguration => 7,
60            HumidityV2BrickletFunction::SetHeaterConfiguration => 9,
61            HumidityV2BrickletFunction::GetHeaterConfiguration => 10,
62            HumidityV2BrickletFunction::SetMovingAverageConfiguration => 11,
63            HumidityV2BrickletFunction::GetMovingAverageConfiguration => 12,
64            HumidityV2BrickletFunction::SetSamplesPerSecond => 13,
65            HumidityV2BrickletFunction::GetSamplesPerSecond => 14,
66            HumidityV2BrickletFunction::GetSpitfpErrorCount => 234,
67            HumidityV2BrickletFunction::SetBootloaderMode => 235,
68            HumidityV2BrickletFunction::GetBootloaderMode => 236,
69            HumidityV2BrickletFunction::SetWriteFirmwarePointer => 237,
70            HumidityV2BrickletFunction::WriteFirmware => 238,
71            HumidityV2BrickletFunction::SetStatusLedConfig => 239,
72            HumidityV2BrickletFunction::GetStatusLedConfig => 240,
73            HumidityV2BrickletFunction::GetChipTemperature => 242,
74            HumidityV2BrickletFunction::Reset => 243,
75            HumidityV2BrickletFunction::WriteUid => 248,
76            HumidityV2BrickletFunction::ReadUid => 249,
77            HumidityV2BrickletFunction::GetIdentity => 255,
78            HumidityV2BrickletFunction::CallbackHumidity => 4,
79            HumidityV2BrickletFunction::CallbackTemperature => 8,
80        }
81    }
82}
83pub const HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
84pub const HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
85pub const HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
86pub const HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
87pub const HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
88pub const HUMIDITY_V2_BRICKLET_HEATER_CONFIG_DISABLED: u8 = 0;
89pub const HUMIDITY_V2_BRICKLET_HEATER_CONFIG_ENABLED: u8 = 1;
90pub const HUMIDITY_V2_BRICKLET_SPS_20: u8 = 0;
91pub const HUMIDITY_V2_BRICKLET_SPS_10: u8 = 1;
92pub const HUMIDITY_V2_BRICKLET_SPS_5: u8 = 2;
93pub const HUMIDITY_V2_BRICKLET_SPS_1: u8 = 3;
94pub const HUMIDITY_V2_BRICKLET_SPS_02: u8 = 4;
95pub const HUMIDITY_V2_BRICKLET_SPS_01: u8 = 5;
96pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
97pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
98pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
99pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
100pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
101pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
102pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
103pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
104pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
105pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
106pub const HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
107pub const HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
108pub const HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
109pub const HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
110pub const HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
111
112#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
113pub struct HumidityCallbackConfiguration {
114    pub period: u32,
115    pub value_has_to_change: bool,
116    pub option: char,
117    pub min: u16,
118    pub max: u16,
119}
120impl FromByteSlice for HumidityCallbackConfiguration {
121    fn bytes_expected() -> usize {
122        10
123    }
124    fn from_le_byte_slice(bytes: &[u8]) -> HumidityCallbackConfiguration {
125        HumidityCallbackConfiguration {
126            period: <u32>::from_le_byte_slice(&bytes[0..4]),
127            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
128            option: <char>::from_le_byte_slice(&bytes[5..6]),
129            min: <u16>::from_le_byte_slice(&bytes[6..8]),
130            max: <u16>::from_le_byte_slice(&bytes[8..10]),
131        }
132    }
133}
134
135#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
136pub struct TemperatureCallbackConfiguration {
137    pub period: u32,
138    pub value_has_to_change: bool,
139    pub option: char,
140    pub min: i16,
141    pub max: i16,
142}
143impl FromByteSlice for TemperatureCallbackConfiguration {
144    fn bytes_expected() -> usize {
145        10
146    }
147    fn from_le_byte_slice(bytes: &[u8]) -> TemperatureCallbackConfiguration {
148        TemperatureCallbackConfiguration {
149            period: <u32>::from_le_byte_slice(&bytes[0..4]),
150            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
151            option: <char>::from_le_byte_slice(&bytes[5..6]),
152            min: <i16>::from_le_byte_slice(&bytes[6..8]),
153            max: <i16>::from_le_byte_slice(&bytes[8..10]),
154        }
155    }
156}
157
158#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
159pub struct MovingAverageConfiguration {
160    pub moving_average_length_humidity: u16,
161    pub moving_average_length_temperature: u16,
162}
163impl FromByteSlice for MovingAverageConfiguration {
164    fn bytes_expected() -> usize {
165        4
166    }
167    fn from_le_byte_slice(bytes: &[u8]) -> MovingAverageConfiguration {
168        MovingAverageConfiguration {
169            moving_average_length_humidity: <u16>::from_le_byte_slice(&bytes[0..2]),
170            moving_average_length_temperature: <u16>::from_le_byte_slice(&bytes[2..4]),
171        }
172    }
173}
174
175#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
176pub struct SpitfpErrorCount {
177    pub error_count_ack_checksum: u32,
178    pub error_count_message_checksum: u32,
179    pub error_count_frame: u32,
180    pub error_count_overflow: u32,
181}
182impl FromByteSlice for SpitfpErrorCount {
183    fn bytes_expected() -> usize {
184        16
185    }
186    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
187        SpitfpErrorCount {
188            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
189            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
190            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
191            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
192        }
193    }
194}
195
196#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
197pub struct Identity {
198    pub uid: String,
199    pub connected_uid: String,
200    pub position: char,
201    pub hardware_version: [u8; 3],
202    pub firmware_version: [u8; 3],
203    pub device_identifier: u16,
204}
205impl FromByteSlice for Identity {
206    fn bytes_expected() -> usize {
207        25
208    }
209    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
210        Identity {
211            uid: <String>::from_le_byte_slice(&bytes[0..8]),
212            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
213            position: <char>::from_le_byte_slice(&bytes[16..17]),
214            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
215            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
216            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
217        }
218    }
219}
220
221/// Measures relative humidity
222#[derive(Clone)]
223pub struct HumidityV2Bricklet {
224    device: Device,
225}
226impl HumidityV2Bricklet {
227    pub const DEVICE_IDENTIFIER: u16 = 283;
228    pub const DEVICE_DISPLAY_NAME: &'static str = "Humidity Bricklet 2.0";
229    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
230    pub fn new(uid: Uid, connection: AsyncIpConnection) -> HumidityV2Bricklet {
231        let mut result = HumidityV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
232        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetHumidity) as usize] = ResponseExpectedFlag::AlwaysTrue;
233        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetHumidityCallbackConfiguration) as usize] =
234            ResponseExpectedFlag::True;
235        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetHumidityCallbackConfiguration) as usize] =
236            ResponseExpectedFlag::AlwaysTrue;
237        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
238        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetTemperatureCallbackConfiguration) as usize] =
239            ResponseExpectedFlag::True;
240        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetTemperatureCallbackConfiguration) as usize] =
241            ResponseExpectedFlag::AlwaysTrue;
242        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetHeaterConfiguration) as usize] =
243            ResponseExpectedFlag::False;
244        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetHeaterConfiguration) as usize] =
245            ResponseExpectedFlag::AlwaysTrue;
246        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetMovingAverageConfiguration) as usize] =
247            ResponseExpectedFlag::False;
248        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetMovingAverageConfiguration) as usize] =
249            ResponseExpectedFlag::AlwaysTrue;
250        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetSamplesPerSecond) as usize] = ResponseExpectedFlag::False;
251        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetSamplesPerSecond) as usize] =
252            ResponseExpectedFlag::AlwaysTrue;
253        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetSpitfpErrorCount) as usize] =
254            ResponseExpectedFlag::AlwaysTrue;
255        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetBootloaderMode) as usize] =
256            ResponseExpectedFlag::AlwaysTrue;
257        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetBootloaderMode) as usize] =
258            ResponseExpectedFlag::AlwaysTrue;
259        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
260            ResponseExpectedFlag::False;
261        result.device.response_expected[u8::from(HumidityV2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
262        result.device.response_expected[u8::from(HumidityV2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
263        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetStatusLedConfig) as usize] =
264            ResponseExpectedFlag::AlwaysTrue;
265        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetChipTemperature) as usize] =
266            ResponseExpectedFlag::AlwaysTrue;
267        result.device.response_expected[u8::from(HumidityV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
268        result.device.response_expected[u8::from(HumidityV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
269        result.device.response_expected[u8::from(HumidityV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
270        result.device.response_expected[u8::from(HumidityV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
271        result
272    }
273
274    /// Returns the response expected flag for the function specified by the function ID parameter.
275    /// It is true if the function is expected to send a response, false otherwise.
276    ///
277    /// For getter functions this is enabled by default and cannot be disabled, because those
278    /// functions will always send a response. For callback configuration functions it is enabled
279    /// by default too, but can be disabled by [`set_response_expected`](crate::humidity_v2_bricklet::HumidityV2Bricklet::set_response_expected).
280    /// For setter functions it is disabled by default and can be enabled.
281    ///
282    /// Enabling the response expected flag for a setter function allows to detect timeouts
283    /// and other error conditions calls of this setter as well. The device will then send a response
284    /// for this purpose. If this flag is disabled for a setter function then no response is sent
285    /// and errors are silently ignored, because they cannot be detected.
286    ///
287    /// See [`set_response_expected`](crate::humidity_v2_bricklet::HumidityV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
288    pub fn get_response_expected(&mut self, fun: HumidityV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
289        self.device.get_response_expected(u8::from(fun))
290    }
291
292    /// Changes the response expected flag of the function specified by the function ID parameter.
293    /// This flag can only be changed for setter (default value: false) and callback configuration
294    /// functions (default value: true). For getter functions it is always enabled.
295    ///
296    /// Enabling the response expected flag for a setter function allows to detect timeouts and
297    /// other error conditions calls of this setter as well. The device will then send a response
298    /// for this purpose. If this flag is disabled for a setter function then no response is sent
299    /// and errors are silently ignored, because they cannot be detected.
300    pub fn set_response_expected(
301        &mut self,
302        fun: HumidityV2BrickletFunction,
303        response_expected: bool,
304    ) -> Result<(), SetResponseExpectedError> {
305        self.device.set_response_expected(u8::from(fun), response_expected)
306    }
307
308    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
309    pub fn set_response_expected_all(&mut self, response_expected: bool) {
310        self.device.set_response_expected_all(response_expected)
311    }
312
313    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
314    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
315    pub fn get_api_version(&self) -> [u8; 3] {
316        self.device.api_version
317    }
318
319    /// This receiver is triggered periodically according to the configuration set by
320    /// [`set_humidity_callback_configuration`].
321    ///
322    /// The parameter is the same as [`get_humidity`].
323    ///
324    /// [`get_humidity`]: #method.get_humidity
325    /// [`set_humidity_callback_configuration`]: #method.set_humidity_callback_configuration
326    pub async fn get_humidity_callback_receiver(&mut self) -> impl Stream<Item = u16> {
327        self.device
328            .get_callback_receiver(u8::from(HumidityV2BrickletFunction::CallbackHumidity))
329            .await
330            .map(|p| u16::from_le_byte_slice(p.body()))
331    }
332
333    /// This receiver is triggered periodically according to the configuration set by
334    /// [`set_temperature_callback_configuration`].
335    ///
336    /// The parameter is the same as [`get_temperature`].
337    pub async fn get_temperature_callback_receiver(&mut self) -> impl Stream<Item = i16> {
338        self.device
339            .get_callback_receiver(u8::from(HumidityV2BrickletFunction::CallbackTemperature))
340            .await
341            .map(|p| i16::from_le_byte_slice(p.body()))
342    }
343
344    /// Returns the humidity measured by the sensor.
345    ///
346    ///
347    /// If you want to get the value periodically, it is recommended to use the
348    /// [`get_humidity_callback_receiver`] receiver. You can set the receiver configuration
349    /// with [`set_humidity_callback_configuration`].
350    pub async fn get_humidity(&mut self) -> Result<u16, TinkerforgeError> {
351        let payload = [0; 0];
352
353        #[allow(unused_variables)]
354        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetHumidity), &payload).await?;
355        Ok(u16::from_le_byte_slice(result.body()))
356    }
357
358    /// The period is the period with which the [`get_humidity_callback_receiver`] receiver is triggered
359    /// periodically. A value of 0 turns the receiver off.
360    ///
361    /// If the `value has to change`-parameter is set to true, the receiver is only
362    /// triggered after the value has changed. If the value didn't change
363    /// within the period, the receiver is triggered immediately on change.
364    ///
365    /// If it is set to false, the receiver is continuously triggered with the period,
366    /// independent of the value.
367    ///
368    /// It is furthermore possible to constrain the receiver with thresholds.
369    ///
370    /// The `option`-parameter together with min/max sets a threshold for the [`get_humidity_callback_receiver`] receiver.
371    ///
372    /// The following options are possible:
373    ///
374    ///  Option| Description
375    ///  --- | ---
376    ///  'x'|    Threshold is turned off
377    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
378    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
379    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
380    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
381    ///
382    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
383    ///
384    /// Associated constants:
385    /// * HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OFF
386    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
387    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
388    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
389    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_GREATER
390    pub async fn set_humidity_callback_configuration(
391        &mut self,
392        period: u32,
393        value_has_to_change: bool,
394        option: char,
395        min: u16,
396        max: u16,
397    ) -> Result<(), TinkerforgeError> {
398        let mut payload = [0; 10];
399        period.write_to_slice(&mut payload[0..4]);
400        value_has_to_change.write_to_slice(&mut payload[4..5]);
401        option.write_to_slice(&mut payload[5..6]);
402        min.write_to_slice(&mut payload[6..8]);
403        max.write_to_slice(&mut payload[8..10]);
404
405        #[allow(unused_variables)]
406        let result = self.device.set(u8::from(HumidityV2BrickletFunction::SetHumidityCallbackConfiguration), &payload).await?;
407        Ok(())
408    }
409
410    /// Returns the receiver configuration as set by [`set_humidity_callback_configuration`].
411    ///
412    /// Associated constants:
413    /// * HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OFF
414    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
415    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
416    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
417    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_GREATER
418    pub async fn get_humidity_callback_configuration(&mut self) -> Result<HumidityCallbackConfiguration, TinkerforgeError> {
419        let payload = [0; 0];
420
421        #[allow(unused_variables)]
422        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetHumidityCallbackConfiguration), &payload).await?;
423        Ok(HumidityCallbackConfiguration::from_le_byte_slice(result.body()))
424    }
425
426    /// Returns the temperature measured by the sensor.
427    ///
428    ///
429    /// If you want to get the value periodically, it is recommended to use the
430    /// [`get_temperature_callback_receiver`] receiver. You can set the receiver configuration
431    /// with [`set_temperature_callback_configuration`].
432    pub async fn get_temperature(&mut self) -> Result<i16, TinkerforgeError> {
433        let payload = [0; 0];
434
435        #[allow(unused_variables)]
436        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetTemperature), &payload).await?;
437        Ok(i16::from_le_byte_slice(result.body()))
438    }
439
440    /// The period is the period with which the [`get_temperature_callback_receiver`] receiver is triggered
441    /// periodically. A value of 0 turns the receiver off.
442    ///
443    /// If the `value has to change`-parameter is set to true, the receiver is only
444    /// triggered after the value has changed. If the value didn't change
445    /// within the period, the receiver is triggered immediately on change.
446    ///
447    /// If it is set to false, the receiver is continuously triggered with the period,
448    /// independent of the value.
449    ///
450    /// It is furthermore possible to constrain the receiver with thresholds.
451    ///
452    /// The `option`-parameter together with min/max sets a threshold for the [`get_temperature_callback_receiver`] receiver.
453    ///
454    /// The following options are possible:
455    ///
456    ///  Option| Description
457    ///  --- | ---
458    ///  'x'|    Threshold is turned off
459    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
460    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
461    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
462    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
463    ///
464    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
465    ///
466    /// Associated constants:
467    /// * HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OFF
468    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
469    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
470    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
471    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_GREATER
472    pub async fn set_temperature_callback_configuration(
473        &mut self,
474        period: u32,
475        value_has_to_change: bool,
476        option: char,
477        min: i16,
478        max: i16,
479    ) -> Result<(), TinkerforgeError> {
480        let mut payload = [0; 10];
481        period.write_to_slice(&mut payload[0..4]);
482        value_has_to_change.write_to_slice(&mut payload[4..5]);
483        option.write_to_slice(&mut payload[5..6]);
484        min.write_to_slice(&mut payload[6..8]);
485        max.write_to_slice(&mut payload[8..10]);
486
487        #[allow(unused_variables)]
488        let result = self.device.set(u8::from(HumidityV2BrickletFunction::SetTemperatureCallbackConfiguration), &payload).await?;
489        Ok(())
490    }
491
492    /// Returns the receiver configuration as set by [`set_temperature_callback_configuration`].
493    ///
494    /// Associated constants:
495    /// * HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OFF
496    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_OUTSIDE
497    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_INSIDE
498    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_SMALLER
499    ///	* HUMIDITY_V2_BRICKLET_THRESHOLD_OPTION_GREATER
500    pub async fn get_temperature_callback_configuration(&mut self) -> Result<TemperatureCallbackConfiguration, TinkerforgeError> {
501        let payload = [0; 0];
502
503        #[allow(unused_variables)]
504        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetTemperatureCallbackConfiguration), &payload).await?;
505        Ok(TemperatureCallbackConfiguration::from_le_byte_slice(result.body()))
506    }
507
508    /// Enables/disables the heater. The heater can be used to dry the sensor in
509    /// extremely wet conditions.
510    ///
511    /// Associated constants:
512    /// * HUMIDITY_V2_BRICKLET_HEATER_CONFIG_DISABLED
513    ///	* HUMIDITY_V2_BRICKLET_HEATER_CONFIG_ENABLED
514    pub async fn set_heater_configuration(&mut self, heater_config: u8) -> Result<(), TinkerforgeError> {
515        let mut payload = [0; 1];
516        heater_config.write_to_slice(&mut payload[0..1]);
517
518        #[allow(unused_variables)]
519        let result = self.device.set(u8::from(HumidityV2BrickletFunction::SetHeaterConfiguration), &payload).await?;
520        Ok(())
521    }
522
523    /// Returns the heater configuration as set by [`set_heater_configuration`].
524    ///
525    /// Associated constants:
526    /// * HUMIDITY_V2_BRICKLET_HEATER_CONFIG_DISABLED
527    ///	* HUMIDITY_V2_BRICKLET_HEATER_CONFIG_ENABLED
528    pub async fn get_heater_configuration(&mut self) -> Result<u8, TinkerforgeError> {
529        let payload = [0; 0];
530
531        #[allow(unused_variables)]
532        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetHeaterConfiguration), &payload).await?;
533        Ok(u8::from_le_byte_slice(result.body()))
534    }
535
536    /// Sets the length of a [moving averaging](https://en.wikipedia.org/wiki/Moving_average)__
537    /// for the humidity and temperature.
538    ///
539    /// Setting the length to 1 will turn the averaging off. With less
540    /// averaging, there is more noise on the data.
541    ///
542    /// New data is gathered every 50ms*. With a moving average of length 1000 the resulting
543    /// averaging window has a length of 50s. If you want to do long term measurements the longest
544    /// moving average will give the cleanest results.
545    ///
546    /// \* In firmware version 2.0.3 we added the [`set_samples_per_second`] function. It
547    /// configures the measurement frequency. Since high frequencies can result in self-heating
548    /// of th IC, changed the default value from 20 samples per second to 1. With 1 sample per second
549    /// a moving average length of 1000 would result in an averaging window of 1000 seconds!
550    pub async fn set_moving_average_configuration(
551        &mut self,
552        moving_average_length_humidity: u16,
553        moving_average_length_temperature: u16,
554    ) -> Result<(), TinkerforgeError> {
555        let mut payload = [0; 4];
556        moving_average_length_humidity.write_to_slice(&mut payload[0..2]);
557        moving_average_length_temperature.write_to_slice(&mut payload[2..4]);
558
559        #[allow(unused_variables)]
560        let result = self.device.set(u8::from(HumidityV2BrickletFunction::SetMovingAverageConfiguration), &payload).await?;
561        Ok(())
562    }
563
564    /// Returns the moving average configuration as set by [`set_moving_average_configuration`].
565    pub async fn get_moving_average_configuration(&mut self) -> Result<MovingAverageConfiguration, TinkerforgeError> {
566        let payload = [0; 0];
567
568        #[allow(unused_variables)]
569        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetMovingAverageConfiguration), &payload).await?;
570        Ok(MovingAverageConfiguration::from_le_byte_slice(result.body()))
571    }
572
573    /// Sets the samples per second that are gathered by the humidity/temperature sensor HDC1080.
574    ///
575    /// We added this function since we found out that a high measurement frequency can lead to
576    /// self-heating of the sensor. Which can distort the temperature measurement.
577    ///
578    /// If you don't need a lot of measurements, you can use the lowest available measurement
579    /// frequency of 0.1 samples per second for the least amount of self-heating.
580    ///
581    /// Before version 2.0.3 the default was 20 samples per second. The new default is 1 sample per second.
582    ///
583    ///
584    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
585    ///
586    /// Associated constants:
587    /// * HUMIDITY_V2_BRICKLET_SPS_20
588    ///	* HUMIDITY_V2_BRICKLET_SPS_10
589    ///	* HUMIDITY_V2_BRICKLET_SPS_5
590    ///	* HUMIDITY_V2_BRICKLET_SPS_1
591    ///	* HUMIDITY_V2_BRICKLET_SPS_02
592    ///	* HUMIDITY_V2_BRICKLET_SPS_01
593    pub async fn set_samples_per_second(&mut self, sps: u8) -> Result<(), TinkerforgeError> {
594        let mut payload = [0; 1];
595        sps.write_to_slice(&mut payload[0..1]);
596
597        #[allow(unused_variables)]
598        let result = self.device.set(u8::from(HumidityV2BrickletFunction::SetSamplesPerSecond), &payload).await?;
599        Ok(())
600    }
601
602    /// Returnes the samples per second, as set by [`set_samples_per_second`].
603    ///
604    ///
605    /// .. versionadded:: 2.0.3$nbsp;(Plugin)
606    ///
607    /// Associated constants:
608    /// * HUMIDITY_V2_BRICKLET_SPS_20
609    ///	* HUMIDITY_V2_BRICKLET_SPS_10
610    ///	* HUMIDITY_V2_BRICKLET_SPS_5
611    ///	* HUMIDITY_V2_BRICKLET_SPS_1
612    ///	* HUMIDITY_V2_BRICKLET_SPS_02
613    ///	* HUMIDITY_V2_BRICKLET_SPS_01
614    pub async fn get_samples_per_second(&mut self) -> Result<u8, TinkerforgeError> {
615        let payload = [0; 0];
616
617        #[allow(unused_variables)]
618        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetSamplesPerSecond), &payload).await?;
619        Ok(u8::from_le_byte_slice(result.body()))
620    }
621
622    /// Returns the error count for the communication between Brick and Bricklet.
623    ///
624    /// The errors are divided into
625    ///
626    /// * ACK checksum errors,
627    /// * message checksum errors,
628    /// * framing errors and
629    /// * overflow errors.
630    ///
631    /// The errors counts are for errors that occur on the Bricklet side. All
632    /// Bricks have a similar function that returns the errors on the Brick side.
633    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
634        let payload = [0; 0];
635
636        #[allow(unused_variables)]
637        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
638        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
639    }
640
641    /// Sets the bootloader mode and returns the status after the requested
642    /// mode change was instigated.
643    ///
644    /// You can change from bootloader mode to firmware mode and vice versa. A change
645    /// from bootloader mode to firmware mode will only take place if the entry function,
646    /// device identifier and CRC are present and correct.
647    ///
648    /// This function is used by Brick Viewer during flashing. It should not be
649    /// necessary to call it in a normal user program.
650    ///
651    /// Associated constants:
652    /// * HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
653    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
654    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
655    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
656    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
657    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_OK
658    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
659    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
660    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
661    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
662    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
663    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
664        let mut payload = [0; 1];
665        mode.write_to_slice(&mut payload[0..1]);
666
667        #[allow(unused_variables)]
668        let result = self.device.get(u8::from(HumidityV2BrickletFunction::SetBootloaderMode), &payload).await?;
669        Ok(u8::from_le_byte_slice(result.body()))
670    }
671
672    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
673    ///
674    /// Associated constants:
675    /// * HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
676    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
677    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
678    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
679    ///	* HUMIDITY_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
680    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
681        let payload = [0; 0];
682
683        #[allow(unused_variables)]
684        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetBootloaderMode), &payload).await?;
685        Ok(u8::from_le_byte_slice(result.body()))
686    }
687
688    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
689    /// to be increased by chunks of size 64. The data is written to flash
690    /// every 4 chunks (which equals to one page of size 256).
691    ///
692    /// This function is used by Brick Viewer during flashing. It should not be
693    /// necessary to call it in a normal user program.
694    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
695        let mut payload = [0; 4];
696        pointer.write_to_slice(&mut payload[0..4]);
697
698        #[allow(unused_variables)]
699        let result = self.device.set(u8::from(HumidityV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
700        Ok(())
701    }
702
703    /// Writes 64 Bytes of firmware at the position as written by
704    /// [`set_write_firmware_pointer`] before. The firmware is written
705    /// to flash every 4 chunks.
706    ///
707    /// You can only write firmware in bootloader mode.
708    ///
709    /// This function is used by Brick Viewer during flashing. It should not be
710    /// necessary to call it in a normal user program.
711    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
712        let mut payload = [0; 64];
713        data.write_to_slice(&mut payload[0..64]);
714
715        #[allow(unused_variables)]
716        let result = self.device.get(u8::from(HumidityV2BrickletFunction::WriteFirmware), &payload).await?;
717        Ok(u8::from_le_byte_slice(result.body()))
718    }
719
720    /// Sets the status LED configuration. By default the LED shows
721    /// communication traffic between Brick and Bricklet, it flickers once
722    /// for every 10 received data packets.
723    ///
724    /// You can also turn the LED permanently on/off or show a heartbeat.
725    ///
726    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
727    ///
728    /// Associated constants:
729    /// * HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_OFF
730    ///	* HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_ON
731    ///	* HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
732    ///	* HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
733    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
734        let mut payload = [0; 1];
735        config.write_to_slice(&mut payload[0..1]);
736
737        #[allow(unused_variables)]
738        let result = self.device.set(u8::from(HumidityV2BrickletFunction::SetStatusLedConfig), &payload).await?;
739        Ok(())
740    }
741
742    /// Returns the configuration as set by [`set_status_led_config`]
743    ///
744    /// Associated constants:
745    /// * HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_OFF
746    ///	* HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_ON
747    ///	* HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
748    ///	* HUMIDITY_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
749    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
750        let payload = [0; 0];
751
752        #[allow(unused_variables)]
753        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetStatusLedConfig), &payload).await?;
754        Ok(u8::from_le_byte_slice(result.body()))
755    }
756
757    /// Returns the temperature as measured inside the microcontroller. The
758    /// value returned is not the ambient temperature!
759    ///
760    /// The temperature is only proportional to the real temperature and it has bad
761    /// accuracy. Practically it is only useful as an indicator for
762    /// temperature changes.
763    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
764        let payload = [0; 0];
765
766        #[allow(unused_variables)]
767        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetChipTemperature), &payload).await?;
768        Ok(i16::from_le_byte_slice(result.body()))
769    }
770
771    /// Calling this function will reset the Bricklet. All configurations
772    /// will be lost.
773    ///
774    /// After a reset you have to create new device objects,
775    /// calling functions on the existing ones will result in
776    /// undefined behavior!
777    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
778        let payload = [0; 0];
779
780        #[allow(unused_variables)]
781        let result = self.device.set(u8::from(HumidityV2BrickletFunction::Reset), &payload).await?;
782        Ok(())
783    }
784
785    /// Writes a new UID into flash. If you want to set a new UID
786    /// you have to decode the Base58 encoded UID string into an
787    /// integer first.
788    ///
789    /// We recommend that you use Brick Viewer to change the UID.
790    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
791        let mut payload = [0; 4];
792        uid.write_to_slice(&mut payload[0..4]);
793
794        #[allow(unused_variables)]
795        let result = self.device.set(u8::from(HumidityV2BrickletFunction::WriteUid), &payload).await?;
796        Ok(())
797    }
798
799    /// Returns the current UID as an integer. Encode as
800    /// Base58 to get the usual string version.
801    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
802        let payload = [0; 0];
803
804        #[allow(unused_variables)]
805        let result = self.device.get(u8::from(HumidityV2BrickletFunction::ReadUid), &payload).await?;
806        Ok(u32::from_le_byte_slice(result.body()))
807    }
808
809    /// Returns the UID, the UID where the Bricklet is connected to,
810    /// the position, the hardware and firmware version as well as the
811    /// device identifier.
812    ///
813    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
814    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
815    /// position 'z'.
816    ///
817    /// The device identifier numbers can be found [here](device_identifier).
818    /// |device_identifier_constant|
819    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
820        let payload = [0; 0];
821
822        #[allow(unused_variables)]
823        let result = self.device.get(u8::from(HumidityV2BrickletFunction::GetIdentity), &payload).await?;
824        Ok(Identity::from_le_byte_slice(result.body()))
825    }
826}