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