tinkerforge_async/bindings/
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/PTC_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 PtcBrickletFunction {
24    GetTemperature,
25    GetResistance,
26    SetTemperatureCallbackPeriod,
27    GetTemperatureCallbackPeriod,
28    SetResistanceCallbackPeriod,
29    GetResistanceCallbackPeriod,
30    SetTemperatureCallbackThreshold,
31    GetTemperatureCallbackThreshold,
32    SetResistanceCallbackThreshold,
33    GetResistanceCallbackThreshold,
34    SetDebouncePeriod,
35    GetDebouncePeriod,
36    SetNoiseRejectionFilter,
37    GetNoiseRejectionFilter,
38    IsSensorConnected,
39    SetWireMode,
40    GetWireMode,
41    SetSensorConnectedCallbackConfiguration,
42    GetSensorConnectedCallbackConfiguration,
43    GetIdentity,
44    CallbackTemperature,
45    CallbackTemperatureReached,
46    CallbackResistance,
47    CallbackResistanceReached,
48    CallbackSensorConnected,
49}
50impl From<PtcBrickletFunction> for u8 {
51    fn from(fun: PtcBrickletFunction) -> Self {
52        match fun {
53            PtcBrickletFunction::GetTemperature => 1,
54            PtcBrickletFunction::GetResistance => 2,
55            PtcBrickletFunction::SetTemperatureCallbackPeriod => 3,
56            PtcBrickletFunction::GetTemperatureCallbackPeriod => 4,
57            PtcBrickletFunction::SetResistanceCallbackPeriod => 5,
58            PtcBrickletFunction::GetResistanceCallbackPeriod => 6,
59            PtcBrickletFunction::SetTemperatureCallbackThreshold => 7,
60            PtcBrickletFunction::GetTemperatureCallbackThreshold => 8,
61            PtcBrickletFunction::SetResistanceCallbackThreshold => 9,
62            PtcBrickletFunction::GetResistanceCallbackThreshold => 10,
63            PtcBrickletFunction::SetDebouncePeriod => 11,
64            PtcBrickletFunction::GetDebouncePeriod => 12,
65            PtcBrickletFunction::SetNoiseRejectionFilter => 17,
66            PtcBrickletFunction::GetNoiseRejectionFilter => 18,
67            PtcBrickletFunction::IsSensorConnected => 19,
68            PtcBrickletFunction::SetWireMode => 20,
69            PtcBrickletFunction::GetWireMode => 21,
70            PtcBrickletFunction::SetSensorConnectedCallbackConfiguration => 22,
71            PtcBrickletFunction::GetSensorConnectedCallbackConfiguration => 23,
72            PtcBrickletFunction::GetIdentity => 255,
73            PtcBrickletFunction::CallbackTemperature => 13,
74            PtcBrickletFunction::CallbackTemperatureReached => 14,
75            PtcBrickletFunction::CallbackResistance => 15,
76            PtcBrickletFunction::CallbackResistanceReached => 16,
77            PtcBrickletFunction::CallbackSensorConnected => 24,
78        }
79    }
80}
81pub const PTC_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
82pub const PTC_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
83pub const PTC_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
84pub const PTC_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
85pub const PTC_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
86pub const PTC_BRICKLET_FILTER_OPTION_50HZ: u8 = 0;
87pub const PTC_BRICKLET_FILTER_OPTION_60HZ: u8 = 1;
88pub const PTC_BRICKLET_WIRE_MODE_2: u8 = 2;
89pub const PTC_BRICKLET_WIRE_MODE_3: u8 = 3;
90pub const PTC_BRICKLET_WIRE_MODE_4: u8 = 4;
91
92#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
93pub struct TemperatureCallbackThreshold {
94    pub option: char,
95    pub min: i32,
96    pub max: i32,
97}
98impl FromByteSlice for TemperatureCallbackThreshold {
99    fn bytes_expected() -> usize {
100        9
101    }
102    fn from_le_byte_slice(bytes: &[u8]) -> TemperatureCallbackThreshold {
103        TemperatureCallbackThreshold {
104            option: <char>::from_le_byte_slice(&bytes[0..1]),
105            min: <i32>::from_le_byte_slice(&bytes[1..5]),
106            max: <i32>::from_le_byte_slice(&bytes[5..9]),
107        }
108    }
109}
110
111#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
112pub struct ResistanceCallbackThreshold {
113    pub option: char,
114    pub min: i32,
115    pub max: i32,
116}
117impl FromByteSlice for ResistanceCallbackThreshold {
118    fn bytes_expected() -> usize {
119        9
120    }
121    fn from_le_byte_slice(bytes: &[u8]) -> ResistanceCallbackThreshold {
122        ResistanceCallbackThreshold {
123            option: <char>::from_le_byte_slice(&bytes[0..1]),
124            min: <i32>::from_le_byte_slice(&bytes[1..5]),
125            max: <i32>::from_le_byte_slice(&bytes[5..9]),
126        }
127    }
128}
129
130#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
131pub struct Identity {
132    pub uid: String,
133    pub connected_uid: String,
134    pub position: char,
135    pub hardware_version: [u8; 3],
136    pub firmware_version: [u8; 3],
137    pub device_identifier: u16,
138}
139impl FromByteSlice for Identity {
140    fn bytes_expected() -> usize {
141        25
142    }
143    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
144        Identity {
145            uid: <String>::from_le_byte_slice(&bytes[0..8]),
146            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
147            position: <char>::from_le_byte_slice(&bytes[16..17]),
148            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
149            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
150            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
151        }
152    }
153}
154
155/// Reads temperatures from Pt100 und Pt1000 sensors
156#[derive(Clone)]
157pub struct PtcBricklet {
158    device: Device,
159}
160impl PtcBricklet {
161    pub const DEVICE_IDENTIFIER: u16 = 226;
162    pub const DEVICE_DISPLAY_NAME: &'static str = "PTC Bricklet";
163    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
164    pub fn new(uid: Uid, connection: AsyncIpConnection) -> PtcBricklet {
165        let mut result = PtcBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
166        result.device.response_expected[u8::from(PtcBrickletFunction::GetTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
167        result.device.response_expected[u8::from(PtcBrickletFunction::GetResistance) as usize] = ResponseExpectedFlag::AlwaysTrue;
168        result.device.response_expected[u8::from(PtcBrickletFunction::SetTemperatureCallbackPeriod) as usize] = ResponseExpectedFlag::True;
169        result.device.response_expected[u8::from(PtcBrickletFunction::GetTemperatureCallbackPeriod) as usize] =
170            ResponseExpectedFlag::AlwaysTrue;
171        result.device.response_expected[u8::from(PtcBrickletFunction::SetResistanceCallbackPeriod) as usize] = ResponseExpectedFlag::True;
172        result.device.response_expected[u8::from(PtcBrickletFunction::GetResistanceCallbackPeriod) as usize] =
173            ResponseExpectedFlag::AlwaysTrue;
174        result.device.response_expected[u8::from(PtcBrickletFunction::SetTemperatureCallbackThreshold) as usize] =
175            ResponseExpectedFlag::True;
176        result.device.response_expected[u8::from(PtcBrickletFunction::GetTemperatureCallbackThreshold) as usize] =
177            ResponseExpectedFlag::AlwaysTrue;
178        result.device.response_expected[u8::from(PtcBrickletFunction::SetResistanceCallbackThreshold) as usize] =
179            ResponseExpectedFlag::True;
180        result.device.response_expected[u8::from(PtcBrickletFunction::GetResistanceCallbackThreshold) as usize] =
181            ResponseExpectedFlag::AlwaysTrue;
182        result.device.response_expected[u8::from(PtcBrickletFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
183        result.device.response_expected[u8::from(PtcBrickletFunction::GetDebouncePeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
184        result.device.response_expected[u8::from(PtcBrickletFunction::SetNoiseRejectionFilter) as usize] = ResponseExpectedFlag::False;
185        result.device.response_expected[u8::from(PtcBrickletFunction::GetNoiseRejectionFilter) as usize] = ResponseExpectedFlag::AlwaysTrue;
186        result.device.response_expected[u8::from(PtcBrickletFunction::IsSensorConnected) as usize] = ResponseExpectedFlag::AlwaysTrue;
187        result.device.response_expected[u8::from(PtcBrickletFunction::SetWireMode) as usize] = ResponseExpectedFlag::False;
188        result.device.response_expected[u8::from(PtcBrickletFunction::GetWireMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
189        result.device.response_expected[u8::from(PtcBrickletFunction::SetSensorConnectedCallbackConfiguration) as usize] =
190            ResponseExpectedFlag::True;
191        result.device.response_expected[u8::from(PtcBrickletFunction::GetSensorConnectedCallbackConfiguration) as usize] =
192            ResponseExpectedFlag::AlwaysTrue;
193        result.device.response_expected[u8::from(PtcBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
194        result
195    }
196
197    /// Returns the response expected flag for the function specified by the function ID parameter.
198    /// It is true if the function is expected to send a response, false otherwise.
199    ///
200    /// For getter functions this is enabled by default and cannot be disabled, because those
201    /// functions will always send a response. For callback configuration functions it is enabled
202    /// by default too, but can be disabled by [`set_response_expected`](crate::ptc_bricklet::PtcBricklet::set_response_expected).
203    /// For setter functions it is disabled by default and can be enabled.
204    ///
205    /// Enabling the response expected flag for a setter function allows to detect timeouts
206    /// and other error conditions calls of this setter as well. The device will then send a response
207    /// for this purpose. If this flag is disabled for a setter function then no response is sent
208    /// and errors are silently ignored, because they cannot be detected.
209    ///
210    /// See [`set_response_expected`](crate::ptc_bricklet::PtcBricklet::set_response_expected) for the list of function ID constants available for this function.
211    pub fn get_response_expected(&mut self, fun: PtcBrickletFunction) -> Result<bool, GetResponseExpectedError> {
212        self.device.get_response_expected(u8::from(fun))
213    }
214
215    /// Changes the response expected flag of the function specified by the function ID parameter.
216    /// This flag can only be changed for setter (default value: false) and callback configuration
217    /// functions (default value: true). For getter functions it is always enabled.
218    ///
219    /// Enabling the response expected flag for a setter function allows to detect timeouts and
220    /// other error conditions calls of this setter as well. The device will then send a response
221    /// for this purpose. If this flag is disabled for a setter function then no response is sent
222    /// and errors are silently ignored, because they cannot be detected.
223    pub fn set_response_expected(&mut self, fun: PtcBrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
224        self.device.set_response_expected(u8::from(fun), response_expected)
225    }
226
227    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
228    pub fn set_response_expected_all(&mut self, response_expected: bool) {
229        self.device.set_response_expected_all(response_expected)
230    }
231
232    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
233    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
234    pub fn get_api_version(&self) -> [u8; 3] {
235        self.device.api_version
236    }
237
238    /// This receiver is triggered periodically with the period that is set by
239    /// [`set_temperature_callback_period`]. The parameter is the
240    /// temperature of the connected sensor.
241    ///
242    /// The [`get_temperature_callback_receiver`] receiver is only triggered if the temperature has changed
243    /// since the last triggering.
244    ///
245    /// [`set_temperature_callback_period`]: #method.set_temperature_callback_period
246    /// [`get_temperature_callback_receiver`]: #method.get_temperature_callback_receiver
247    pub async fn get_temperature_callback_receiver(&mut self) -> impl Stream<Item = i32> {
248        self.device
249            .get_callback_receiver(u8::from(PtcBrickletFunction::CallbackTemperature))
250            .await
251            .map(|p| i32::from_le_byte_slice(p.body()))
252    }
253
254    /// This receiver is triggered when the threshold as set by
255    /// [`set_temperature_callback_threshold`] is reached.
256    /// The parameter is the temperature of the connected sensor.
257    ///
258    /// If the threshold keeps being reached, the receiver is triggered periodically
259    /// with the period as set by [`set_debounce_period`].
260    pub async fn get_temperature_reached_callback_receiver(&mut self) -> impl Stream<Item = i32> {
261        self.device
262            .get_callback_receiver(u8::from(PtcBrickletFunction::CallbackTemperatureReached))
263            .await
264            .map(|p| i32::from_le_byte_slice(p.body()))
265    }
266
267    /// This receiver is triggered periodically with the period that is set by
268    /// [`set_resistance_callback_period`]. The parameter is the resistance
269    /// of the connected sensor.
270    ///
271    /// The [`get_resistance_callback_receiver`] receiver is only triggered if the resistance has changed
272    /// since the last triggering.
273    pub async fn get_resistance_callback_receiver(&mut self) -> impl Stream<Item = i32> {
274        self.device
275            .get_callback_receiver(u8::from(PtcBrickletFunction::CallbackResistance))
276            .await
277            .map(|p| i32::from_le_byte_slice(p.body()))
278    }
279
280    /// This receiver is triggered when the threshold as set by
281    /// [`set_resistance_callback_threshold`] is reached.
282    /// The parameter is the resistance of the connected sensor.
283    ///
284    /// If the threshold keeps being reached, the receiver is triggered periodically
285    /// with the period as set by [`set_debounce_period`].
286    pub async fn get_resistance_reached_callback_receiver(&mut self) -> impl Stream<Item = i32> {
287        self.device
288            .get_callback_receiver(u8::from(PtcBrickletFunction::CallbackResistanceReached))
289            .await
290            .map(|p| i32::from_le_byte_slice(p.body()))
291    }
292
293    /// This receiver is triggered periodically according to the configuration set by
294    /// [`set_sensor_connected_callback_configuration`].
295    ///
296    /// The parameter is the same as [`is_sensor_connected`].
297    ///
298    ///
299    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
300    pub async fn get_sensor_connected_callback_receiver(&mut self) -> impl Stream<Item = bool> {
301        self.device
302            .get_callback_receiver(u8::from(PtcBrickletFunction::CallbackSensorConnected))
303            .await
304            .map(|p| bool::from_le_byte_slice(p.body()))
305    }
306
307    /// Returns the temperature of connected sensor.
308    ///
309    /// If you want to get the temperature periodically, it is recommended
310    /// to use the [`get_temperature_callback_receiver`] receiver and set the period with
311    /// [`set_temperature_callback_period`].
312    pub async fn get_temperature(&mut self) -> Result<i32, TinkerforgeError> {
313        let payload = [0; 0];
314
315        #[allow(unused_variables)]
316        let result = self.device.get(u8::from(PtcBrickletFunction::GetTemperature), &payload).await?;
317        Ok(i32::from_le_byte_slice(result.body()))
318    }
319
320    /// Returns the value as measured by the MAX31865 precision delta-sigma ADC.
321    ///
322    /// The value can be converted with the following formulas:
323    ///
324    /// * Pt100:  resistance = (value * 390) / 32768
325    /// * Pt1000: resistance = (value * 3900) / 32768
326    ///
327    /// If you want to get the resistance periodically, it is recommended
328    /// to use the [`get_resistance_callback_receiver`] receiver and set the period with
329    /// [`set_resistance_callback_period`].
330    pub async fn get_resistance(&mut self) -> Result<i32, TinkerforgeError> {
331        let payload = [0; 0];
332
333        #[allow(unused_variables)]
334        let result = self.device.get(u8::from(PtcBrickletFunction::GetResistance), &payload).await?;
335        Ok(i32::from_le_byte_slice(result.body()))
336    }
337
338    /// Sets the period with which the [`get_temperature_callback_receiver`] receiver is triggered
339    /// periodically. A value of 0 turns the receiver off.
340    ///
341    /// The [`get_temperature_callback_receiver`] receiver is only triggered if the temperature has
342    /// changed since the last triggering.
343    pub async fn set_temperature_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
344        let mut payload = [0; 4];
345        period.write_to_slice(&mut payload[0..4]);
346
347        #[allow(unused_variables)]
348        let result = self.device.set(u8::from(PtcBrickletFunction::SetTemperatureCallbackPeriod), &payload).await?;
349        Ok(())
350    }
351
352    /// Returns the period as set by [`set_temperature_callback_period`].
353    pub async fn get_temperature_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
354        let payload = [0; 0];
355
356        #[allow(unused_variables)]
357        let result = self.device.get(u8::from(PtcBrickletFunction::GetTemperatureCallbackPeriod), &payload).await?;
358        Ok(u32::from_le_byte_slice(result.body()))
359    }
360
361    /// Sets the period with which the [`get_resistance_callback_receiver`] receiver is triggered
362    /// periodically. A value of 0 turns the receiver off.
363    ///
364    /// The [`get_resistance_callback_receiver`] receiver is only triggered if the resistance has changed
365    /// since the last triggering.
366    pub async fn set_resistance_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
367        let mut payload = [0; 4];
368        period.write_to_slice(&mut payload[0..4]);
369
370        #[allow(unused_variables)]
371        let result = self.device.set(u8::from(PtcBrickletFunction::SetResistanceCallbackPeriod), &payload).await?;
372        Ok(())
373    }
374
375    /// Returns the period as set by [`set_resistance_callback_period`].
376    pub async fn get_resistance_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
377        let payload = [0; 0];
378
379        #[allow(unused_variables)]
380        let result = self.device.get(u8::from(PtcBrickletFunction::GetResistanceCallbackPeriod), &payload).await?;
381        Ok(u32::from_le_byte_slice(result.body()))
382    }
383
384    /// Sets the thresholds for the [`get_temperature_reached_callback_receiver`] receiver.
385    ///
386    /// The following options are possible:
387    ///
388    ///  Option| Description
389    ///  --- | ---
390    ///  'x'|    Receiver is turned off
391    ///  'o'|    Receiver is triggered when the temperature is *outside* the min and max values
392    ///  'i'|    Receiver is triggered when the temperature is *inside* the min and max values
393    ///  '<'|    Receiver is triggered when the temperature is smaller than the min value (max is ignored)
394    ///  '>'|    Receiver is triggered when the temperature is greater than the min value (max is ignored)
395    ///
396    /// Associated constants:
397    /// * PTC_BRICKLET_THRESHOLD_OPTION_OFF
398    ///	* PTC_BRICKLET_THRESHOLD_OPTION_OUTSIDE
399    ///	* PTC_BRICKLET_THRESHOLD_OPTION_INSIDE
400    ///	* PTC_BRICKLET_THRESHOLD_OPTION_SMALLER
401    ///	* PTC_BRICKLET_THRESHOLD_OPTION_GREATER
402    pub async fn set_temperature_callback_threshold(&mut self, option: char, min: i32, max: i32) -> Result<(), TinkerforgeError> {
403        let mut payload = [0; 9];
404        option.write_to_slice(&mut payload[0..1]);
405        min.write_to_slice(&mut payload[1..5]);
406        max.write_to_slice(&mut payload[5..9]);
407
408        #[allow(unused_variables)]
409        let result = self.device.set(u8::from(PtcBrickletFunction::SetTemperatureCallbackThreshold), &payload).await?;
410        Ok(())
411    }
412
413    /// Returns the threshold as set by [`set_temperature_callback_threshold`].
414    ///
415    /// Associated constants:
416    /// * PTC_BRICKLET_THRESHOLD_OPTION_OFF
417    ///	* PTC_BRICKLET_THRESHOLD_OPTION_OUTSIDE
418    ///	* PTC_BRICKLET_THRESHOLD_OPTION_INSIDE
419    ///	* PTC_BRICKLET_THRESHOLD_OPTION_SMALLER
420    ///	* PTC_BRICKLET_THRESHOLD_OPTION_GREATER
421    pub async fn get_temperature_callback_threshold(&mut self) -> Result<TemperatureCallbackThreshold, TinkerforgeError> {
422        let payload = [0; 0];
423
424        #[allow(unused_variables)]
425        let result = self.device.get(u8::from(PtcBrickletFunction::GetTemperatureCallbackThreshold), &payload).await?;
426        Ok(TemperatureCallbackThreshold::from_le_byte_slice(result.body()))
427    }
428
429    /// Sets the thresholds for the [`get_resistance_reached_callback_receiver`] receiver.
430    ///
431    /// The following options are possible:
432    ///
433    ///  Option| Description
434    ///  --- | ---
435    ///  'x'|    Receiver is turned off
436    ///  'o'|    Receiver is triggered when the temperature is *outside* the min and max values
437    ///  'i'|    Receiver is triggered when the temperature is *inside* the min and max values
438    ///  '<'|    Receiver is triggered when the temperature is smaller than the min value (max is ignored)
439    ///  '>'|    Receiver is triggered when the temperature is greater than the min value (max is ignored)
440    ///
441    /// Associated constants:
442    /// * PTC_BRICKLET_THRESHOLD_OPTION_OFF
443    ///	* PTC_BRICKLET_THRESHOLD_OPTION_OUTSIDE
444    ///	* PTC_BRICKLET_THRESHOLD_OPTION_INSIDE
445    ///	* PTC_BRICKLET_THRESHOLD_OPTION_SMALLER
446    ///	* PTC_BRICKLET_THRESHOLD_OPTION_GREATER
447    pub async fn set_resistance_callback_threshold(&mut self, option: char, min: i32, max: i32) -> Result<(), TinkerforgeError> {
448        let mut payload = [0; 9];
449        option.write_to_slice(&mut payload[0..1]);
450        min.write_to_slice(&mut payload[1..5]);
451        max.write_to_slice(&mut payload[5..9]);
452
453        #[allow(unused_variables)]
454        let result = self.device.set(u8::from(PtcBrickletFunction::SetResistanceCallbackThreshold), &payload).await?;
455        Ok(())
456    }
457
458    /// Returns the threshold as set by [`set_resistance_callback_threshold`].
459    ///
460    /// Associated constants:
461    /// * PTC_BRICKLET_THRESHOLD_OPTION_OFF
462    ///	* PTC_BRICKLET_THRESHOLD_OPTION_OUTSIDE
463    ///	* PTC_BRICKLET_THRESHOLD_OPTION_INSIDE
464    ///	* PTC_BRICKLET_THRESHOLD_OPTION_SMALLER
465    ///	* PTC_BRICKLET_THRESHOLD_OPTION_GREATER
466    pub async fn get_resistance_callback_threshold(&mut self) -> Result<ResistanceCallbackThreshold, TinkerforgeError> {
467        let payload = [0; 0];
468
469        #[allow(unused_variables)]
470        let result = self.device.get(u8::from(PtcBrickletFunction::GetResistanceCallbackThreshold), &payload).await?;
471        Ok(ResistanceCallbackThreshold::from_le_byte_slice(result.body()))
472    }
473
474    /// Sets the period with which the threshold receiver
475    ///
476    /// * [`get_temperature_reached_callback_receiver`],
477    /// * [`get_resistance_reached_callback_receiver`]
478    ///
479    /// is triggered, if the threshold
480    ///
481    /// * [`set_temperature_callback_threshold`],
482    /// * [`set_resistance_callback_threshold`]
483    ///
484    /// keeps being reached.
485    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
486        let mut payload = [0; 4];
487        debounce.write_to_slice(&mut payload[0..4]);
488
489        #[allow(unused_variables)]
490        let result = self.device.set(u8::from(PtcBrickletFunction::SetDebouncePeriod), &payload).await?;
491        Ok(())
492    }
493
494    /// Returns the debounce period as set by [`set_debounce_period`].
495    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
496        let payload = [0; 0];
497
498        #[allow(unused_variables)]
499        let result = self.device.get(u8::from(PtcBrickletFunction::GetDebouncePeriod), &payload).await?;
500        Ok(u32::from_le_byte_slice(result.body()))
501    }
502
503    /// Sets the noise rejection filter to either 50Hz (0) or 60Hz (1).
504    /// Noise from 50Hz or 60Hz power sources (including
505    /// harmonics of the AC power's fundamental frequency) is
506    /// attenuated by 82dB.
507    ///
508    /// Associated constants:
509    /// * PTC_BRICKLET_FILTER_OPTION_50HZ
510    ///	* PTC_BRICKLET_FILTER_OPTION_60HZ
511    pub async fn set_noise_rejection_filter(&mut self, filter: u8) -> Result<(), TinkerforgeError> {
512        let mut payload = [0; 1];
513        filter.write_to_slice(&mut payload[0..1]);
514
515        #[allow(unused_variables)]
516        let result = self.device.set(u8::from(PtcBrickletFunction::SetNoiseRejectionFilter), &payload).await?;
517        Ok(())
518    }
519
520    /// Returns the noise rejection filter option as set by
521    /// [`set_noise_rejection_filter`]
522    ///
523    /// Associated constants:
524    /// * PTC_BRICKLET_FILTER_OPTION_50HZ
525    ///	* PTC_BRICKLET_FILTER_OPTION_60HZ
526    pub async fn get_noise_rejection_filter(&mut self) -> Result<u8, TinkerforgeError> {
527        let payload = [0; 0];
528
529        #[allow(unused_variables)]
530        let result = self.device.get(u8::from(PtcBrickletFunction::GetNoiseRejectionFilter), &payload).await?;
531        Ok(u8::from_le_byte_slice(result.body()))
532    }
533
534    /// Returns *true* if the sensor is connected correctly.
535    ///
536    /// If this function
537    /// returns *false*, there is either no Pt100 or Pt1000 sensor connected,
538    /// the sensor is connected incorrectly or the sensor itself is faulty.
539    pub async fn is_sensor_connected(&mut self) -> Result<bool, TinkerforgeError> {
540        let payload = [0; 0];
541
542        #[allow(unused_variables)]
543        let result = self.device.get(u8::from(PtcBrickletFunction::IsSensorConnected), &payload).await?;
544        Ok(bool::from_le_byte_slice(result.body()))
545    }
546
547    /// Sets the wire mode of the sensor. Possible values are 2, 3 and 4 which
548    /// correspond to 2-, 3- and 4-wire sensors. The value has to match the jumper
549    /// configuration on the Bricklet.
550    ///
551    /// Associated constants:
552    /// * PTC_BRICKLET_WIRE_MODE_2
553    ///	* PTC_BRICKLET_WIRE_MODE_3
554    ///	* PTC_BRICKLET_WIRE_MODE_4
555    pub async fn set_wire_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
556        let mut payload = [0; 1];
557        mode.write_to_slice(&mut payload[0..1]);
558
559        #[allow(unused_variables)]
560        let result = self.device.set(u8::from(PtcBrickletFunction::SetWireMode), &payload).await?;
561        Ok(())
562    }
563
564    /// Returns the wire mode as set by [`set_wire_mode`]
565    ///
566    /// Associated constants:
567    /// * PTC_BRICKLET_WIRE_MODE_2
568    ///	* PTC_BRICKLET_WIRE_MODE_3
569    ///	* PTC_BRICKLET_WIRE_MODE_4
570    pub async fn get_wire_mode(&mut self) -> Result<u8, TinkerforgeError> {
571        let payload = [0; 0];
572
573        #[allow(unused_variables)]
574        let result = self.device.get(u8::from(PtcBrickletFunction::GetWireMode), &payload).await?;
575        Ok(u8::from_le_byte_slice(result.body()))
576    }
577
578    /// If you enable this receiver, the [`get_sensor_connected_callback_receiver`] receiver is triggered
579    /// every time a Pt sensor is connected/disconnected.
580    ///
581    ///
582    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
583    pub async fn set_sensor_connected_callback_configuration(&mut self, enabled: bool) -> Result<(), TinkerforgeError> {
584        let mut payload = [0; 1];
585        enabled.write_to_slice(&mut payload[0..1]);
586
587        #[allow(unused_variables)]
588        let result = self.device.set(u8::from(PtcBrickletFunction::SetSensorConnectedCallbackConfiguration), &payload).await?;
589        Ok(())
590    }
591
592    /// Returns the configuration as set by [`set_sensor_connected_callback_configuration`].
593    ///
594    ///
595    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
596    pub async fn get_sensor_connected_callback_configuration(&mut self) -> Result<bool, TinkerforgeError> {
597        let payload = [0; 0];
598
599        #[allow(unused_variables)]
600        let result = self.device.get(u8::from(PtcBrickletFunction::GetSensorConnectedCallbackConfiguration), &payload).await?;
601        Ok(bool::from_le_byte_slice(result.body()))
602    }
603
604    /// Returns the UID, the UID where the Bricklet is connected to,
605    /// the position, the hardware and firmware version as well as the
606    /// device identifier.
607    ///
608    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
609    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
610    /// position 'z'.
611    ///
612    /// The device identifier numbers can be found [here](device_identifier).
613    /// |device_identifier_constant|
614    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
615        let payload = [0; 0];
616
617        #[allow(unused_variables)]
618        let result = self.device.get(u8::from(PtcBrickletFunction::GetIdentity), &payload).await?;
619        Ok(Identity::from_le_byte_slice(result.body()))
620    }
621}