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