tinkerforge/bindings/
industrial_ptc_bricklet.rs

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