tinkerforge_async/bindings/
motion_detector_v2_bricklet.rs

1/* ***********************************************************
2 * This file was automatically generated on 2024-02-16.      *
3 *                                                           *
4 * Rust Bindings Version 2.0.20                              *
5 *                                                           *
6 * If you have a bugfix for this file and want to commit it, *
7 * please fix the bug in the generator. You can find a link  *
8 * to the generators git repository on tinkerforge.com       *
9 *************************************************************/
10
11//! Passive infrared (PIR) motion sensor with 12m range and dimmable backlight.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/MotionDetectorV2_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 MotionDetectorV2BrickletFunction {
24    GetMotionDetected,
25    SetSensitivity,
26    GetSensitivity,
27    SetIndicator,
28    GetIndicator,
29    GetSpitfpErrorCount,
30    SetBootloaderMode,
31    GetBootloaderMode,
32    SetWriteFirmwarePointer,
33    WriteFirmware,
34    SetStatusLedConfig,
35    GetStatusLedConfig,
36    GetChipTemperature,
37    Reset,
38    WriteUid,
39    ReadUid,
40    GetIdentity,
41    CallbackMotionDetected,
42    CallbackDetectionCycleEnded,
43}
44impl From<MotionDetectorV2BrickletFunction> for u8 {
45    fn from(fun: MotionDetectorV2BrickletFunction) -> Self {
46        match fun {
47            MotionDetectorV2BrickletFunction::GetMotionDetected => 1,
48            MotionDetectorV2BrickletFunction::SetSensitivity => 2,
49            MotionDetectorV2BrickletFunction::GetSensitivity => 3,
50            MotionDetectorV2BrickletFunction::SetIndicator => 4,
51            MotionDetectorV2BrickletFunction::GetIndicator => 5,
52            MotionDetectorV2BrickletFunction::GetSpitfpErrorCount => 234,
53            MotionDetectorV2BrickletFunction::SetBootloaderMode => 235,
54            MotionDetectorV2BrickletFunction::GetBootloaderMode => 236,
55            MotionDetectorV2BrickletFunction::SetWriteFirmwarePointer => 237,
56            MotionDetectorV2BrickletFunction::WriteFirmware => 238,
57            MotionDetectorV2BrickletFunction::SetStatusLedConfig => 239,
58            MotionDetectorV2BrickletFunction::GetStatusLedConfig => 240,
59            MotionDetectorV2BrickletFunction::GetChipTemperature => 242,
60            MotionDetectorV2BrickletFunction::Reset => 243,
61            MotionDetectorV2BrickletFunction::WriteUid => 248,
62            MotionDetectorV2BrickletFunction::ReadUid => 249,
63            MotionDetectorV2BrickletFunction::GetIdentity => 255,
64            MotionDetectorV2BrickletFunction::CallbackMotionDetected => 6,
65            MotionDetectorV2BrickletFunction::CallbackDetectionCycleEnded => 7,
66        }
67    }
68}
69pub const MOTION_DETECTOR_V2_BRICKLET_MOTION_NOT_DETECTED: u8 = 0;
70pub const MOTION_DETECTOR_V2_BRICKLET_MOTION_DETECTED: u8 = 1;
71pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
72pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
73pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
74pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
75pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
76pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
77pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
78pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
79pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
80pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
81pub const MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
82pub const MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
83pub const MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
84pub const MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
85pub const MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
86
87#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
88pub struct Indicator {
89    pub top_left: u8,
90    pub top_right: u8,
91    pub bottom: u8,
92}
93impl FromByteSlice for Indicator {
94    fn bytes_expected() -> usize {
95        3
96    }
97    fn from_le_byte_slice(bytes: &[u8]) -> Indicator {
98        Indicator {
99            top_left: <u8>::from_le_byte_slice(&bytes[0..1]),
100            top_right: <u8>::from_le_byte_slice(&bytes[1..2]),
101            bottom: <u8>::from_le_byte_slice(&bytes[2..3]),
102        }
103    }
104}
105
106#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
107pub struct SpitfpErrorCount {
108    pub error_count_ack_checksum: u32,
109    pub error_count_message_checksum: u32,
110    pub error_count_frame: u32,
111    pub error_count_overflow: u32,
112}
113impl FromByteSlice for SpitfpErrorCount {
114    fn bytes_expected() -> usize {
115        16
116    }
117    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
118        SpitfpErrorCount {
119            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
120            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
121            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
122            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
123        }
124    }
125}
126
127#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
128pub struct Identity {
129    pub uid: String,
130    pub connected_uid: String,
131    pub position: char,
132    pub hardware_version: [u8; 3],
133    pub firmware_version: [u8; 3],
134    pub device_identifier: u16,
135}
136impl FromByteSlice for Identity {
137    fn bytes_expected() -> usize {
138        25
139    }
140    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
141        Identity {
142            uid: <String>::from_le_byte_slice(&bytes[0..8]),
143            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
144            position: <char>::from_le_byte_slice(&bytes[16..17]),
145            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
146            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
147            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
148        }
149    }
150}
151
152/// Passive infrared (PIR) motion sensor with 12m range and dimmable backlight
153#[derive(Clone)]
154pub struct MotionDetectorV2Bricklet {
155    device: Device,
156}
157impl MotionDetectorV2Bricklet {
158    pub const DEVICE_IDENTIFIER: u16 = 292;
159    pub const DEVICE_DISPLAY_NAME: &'static str = "Motion Detector Bricklet 2.0";
160    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
161    pub fn new(uid: Uid, connection: AsyncIpConnection) -> MotionDetectorV2Bricklet {
162        let mut result = MotionDetectorV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
163        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetMotionDetected) as usize] =
164            ResponseExpectedFlag::AlwaysTrue;
165        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::SetSensitivity) as usize] = ResponseExpectedFlag::False;
166        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetSensitivity) as usize] =
167            ResponseExpectedFlag::AlwaysTrue;
168        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::SetIndicator) as usize] = ResponseExpectedFlag::False;
169        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetIndicator) as usize] =
170            ResponseExpectedFlag::AlwaysTrue;
171        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetSpitfpErrorCount) as usize] =
172            ResponseExpectedFlag::AlwaysTrue;
173        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::SetBootloaderMode) as usize] =
174            ResponseExpectedFlag::AlwaysTrue;
175        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetBootloaderMode) as usize] =
176            ResponseExpectedFlag::AlwaysTrue;
177        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
178            ResponseExpectedFlag::False;
179        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::WriteFirmware) as usize] =
180            ResponseExpectedFlag::AlwaysTrue;
181        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::SetStatusLedConfig) as usize] =
182            ResponseExpectedFlag::False;
183        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetStatusLedConfig) as usize] =
184            ResponseExpectedFlag::AlwaysTrue;
185        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetChipTemperature) as usize] =
186            ResponseExpectedFlag::AlwaysTrue;
187        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
188        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
189        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
190        result.device.response_expected[u8::from(MotionDetectorV2BrickletFunction::GetIdentity) as usize] =
191            ResponseExpectedFlag::AlwaysTrue;
192        result
193    }
194
195    /// Returns the response expected flag for the function specified by the function ID parameter.
196    /// It is true if the function is expected to send a response, false otherwise.
197    ///
198    /// For getter functions this is enabled by default and cannot be disabled, because those
199    /// functions will always send a response. For callback configuration functions it is enabled
200    /// by default too, but can be disabled by [`set_response_expected`](crate::motion_detector_v2_bricklet::MotionDetectorV2Bricklet::set_response_expected).
201    /// For setter functions it is disabled by default and can be enabled.
202    ///
203    /// Enabling the response expected flag for a setter function allows to detect timeouts
204    /// and other error conditions calls of this setter as well. The device will then send a response
205    /// for this purpose. If this flag is disabled for a setter function then no response is sent
206    /// and errors are silently ignored, because they cannot be detected.
207    ///
208    /// See [`set_response_expected`](crate::motion_detector_v2_bricklet::MotionDetectorV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
209    pub fn get_response_expected(&mut self, fun: MotionDetectorV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
210        self.device.get_response_expected(u8::from(fun))
211    }
212
213    /// Changes the response expected flag of the function specified by the function ID parameter.
214    /// This flag can only be changed for setter (default value: false) and callback configuration
215    /// functions (default value: true). For getter functions it is always enabled.
216    ///
217    /// Enabling the response expected flag for a setter function allows to detect timeouts and
218    /// other error conditions calls of this setter as well. The device will then send a response
219    /// for this purpose. If this flag is disabled for a setter function then no response is sent
220    /// and errors are silently ignored, because they cannot be detected.
221    pub fn set_response_expected(
222        &mut self,
223        fun: MotionDetectorV2BrickletFunction,
224        response_expected: bool,
225    ) -> Result<(), SetResponseExpectedError> {
226        self.device.set_response_expected(u8::from(fun), response_expected)
227    }
228
229    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
230    pub fn set_response_expected_all(&mut self, response_expected: bool) {
231        self.device.set_response_expected_all(response_expected)
232    }
233
234    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
235    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
236    pub fn get_api_version(&self) -> [u8; 3] {
237        self.device.api_version
238    }
239
240    /// This receiver is called after a motion was detected.
241    pub async fn get_motion_detected_callback_receiver(&mut self) -> impl Stream<Item = ()> {
242        self.device.get_callback_receiver(u8::from(MotionDetectorV2BrickletFunction::CallbackMotionDetected)).await.map(|_p| ())
243    }
244
245    /// This receiver is called when the detection cycle ended. When this
246    /// receiver is called, a new motion can be detected again after approximately 2
247    /// seconds.
248    pub async fn get_detection_cycle_ended_callback_receiver(&mut self) -> impl Stream<Item = ()> {
249        self.device.get_callback_receiver(u8::from(MotionDetectorV2BrickletFunction::CallbackDetectionCycleEnded)).await.map(|_p| ())
250    }
251
252    /// Returns 1 if a motion was detected. It returns 1 approx. for 1.8 seconds
253    /// until the sensor checks for a new movement.
254    ///
255    /// Associated constants:
256    /// * MOTION_DETECTOR_V2_BRICKLET_MOTION_NOT_DETECTED
257    ///	* MOTION_DETECTOR_V2_BRICKLET_MOTION_DETECTED
258    pub async fn get_motion_detected(&mut self) -> Result<u8, TinkerforgeError> {
259        let payload = [0; 0];
260
261        #[allow(unused_variables)]
262        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetMotionDetected), &payload).await?;
263        Ok(u8::from_le_byte_slice(result.body()))
264    }
265
266    /// Sets the sensitivity of the PIR sensor. At full
267    /// sensitivity (100), the Bricklet can detect motion in a range of approximately 12m.
268    ///
269    /// The actual range depends on many things in the environment (e.g. reflections) and the
270    /// size of the object to be detected. While a big person might be detected in a range
271    /// of 10m a cat may only be detected at 2m distance with the same setting.
272    ///
273    /// So you will have to find a good sensitivity for your application by trial and error.
274    pub async fn set_sensitivity(&mut self, sensitivity: u8) -> Result<(), TinkerforgeError> {
275        let mut payload = [0; 1];
276        sensitivity.write_to_slice(&mut payload[0..1]);
277
278        #[allow(unused_variables)]
279        let result = self.device.set(u8::from(MotionDetectorV2BrickletFunction::SetSensitivity), &payload).await?;
280        Ok(())
281    }
282
283    /// Returns the sensitivity as set by [`set_sensitivity`].
284    pub async fn get_sensitivity(&mut self) -> Result<u8, TinkerforgeError> {
285        let payload = [0; 0];
286
287        #[allow(unused_variables)]
288        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetSensitivity), &payload).await?;
289        Ok(u8::from_le_byte_slice(result.body()))
290    }
291
292    /// Sets the blue backlight of the fresnel lens. The backlight consists of
293    /// three LEDs. The brightness of each LED can be controlled with a 8-bit value
294    /// (0-255). A value of 0 turns the LED off and a value of 255 turns the LED
295    /// to full brightness.
296    pub async fn set_indicator(&mut self, top_left: u8, top_right: u8, bottom: u8) -> Result<(), TinkerforgeError> {
297        let mut payload = [0; 3];
298        top_left.write_to_slice(&mut payload[0..1]);
299        top_right.write_to_slice(&mut payload[1..2]);
300        bottom.write_to_slice(&mut payload[2..3]);
301
302        #[allow(unused_variables)]
303        let result = self.device.set(u8::from(MotionDetectorV2BrickletFunction::SetIndicator), &payload).await?;
304        Ok(())
305    }
306
307    /// Returns the indicator configuration as set by [`set_indicator`].
308    pub async fn get_indicator(&mut self) -> Result<Indicator, TinkerforgeError> {
309        let payload = [0; 0];
310
311        #[allow(unused_variables)]
312        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetIndicator), &payload).await?;
313        Ok(Indicator::from_le_byte_slice(result.body()))
314    }
315
316    /// Returns the error count for the communication between Brick and Bricklet.
317    ///
318    /// The errors are divided into
319    ///
320    /// * ACK checksum errors,
321    /// * message checksum errors,
322    /// * framing errors and
323    /// * overflow errors.
324    ///
325    /// The errors counts are for errors that occur on the Bricklet side. All
326    /// Bricks have a similar function that returns the errors on the Brick side.
327    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
328        let payload = [0; 0];
329
330        #[allow(unused_variables)]
331        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
332        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
333    }
334
335    /// Sets the bootloader mode and returns the status after the requested
336    /// mode change was instigated.
337    ///
338    /// You can change from bootloader mode to firmware mode and vice versa. A change
339    /// from bootloader mode to firmware mode will only take place if the entry function,
340    /// device identifier and CRC are present and correct.
341    ///
342    /// This function is used by Brick Viewer during flashing. It should not be
343    /// necessary to call it in a normal user program.
344    ///
345    /// Associated constants:
346    /// * MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
347    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
348    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
349    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
350    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
351    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_OK
352    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
353    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
354    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
355    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
356    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
357    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
358        let mut payload = [0; 1];
359        mode.write_to_slice(&mut payload[0..1]);
360
361        #[allow(unused_variables)]
362        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::SetBootloaderMode), &payload).await?;
363        Ok(u8::from_le_byte_slice(result.body()))
364    }
365
366    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
367    ///
368    /// Associated constants:
369    /// * MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
370    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
371    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
372    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
373    ///	* MOTION_DETECTOR_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
374    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
375        let payload = [0; 0];
376
377        #[allow(unused_variables)]
378        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetBootloaderMode), &payload).await?;
379        Ok(u8::from_le_byte_slice(result.body()))
380    }
381
382    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
383    /// to be increased by chunks of size 64. The data is written to flash
384    /// every 4 chunks (which equals to one page of size 256).
385    ///
386    /// This function is used by Brick Viewer during flashing. It should not be
387    /// necessary to call it in a normal user program.
388    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
389        let mut payload = [0; 4];
390        pointer.write_to_slice(&mut payload[0..4]);
391
392        #[allow(unused_variables)]
393        let result = self.device.set(u8::from(MotionDetectorV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
394        Ok(())
395    }
396
397    /// Writes 64 Bytes of firmware at the position as written by
398    /// [`set_write_firmware_pointer`] before. The firmware is written
399    /// to flash every 4 chunks.
400    ///
401    /// You can only write firmware in bootloader mode.
402    ///
403    /// This function is used by Brick Viewer during flashing. It should not be
404    /// necessary to call it in a normal user program.
405    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
406        let mut payload = [0; 64];
407        data.write_to_slice(&mut payload[0..64]);
408
409        #[allow(unused_variables)]
410        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::WriteFirmware), &payload).await?;
411        Ok(u8::from_le_byte_slice(result.body()))
412    }
413
414    /// Sets the status LED configuration. By default the LED shows
415    /// communication traffic between Brick and Bricklet, it flickers once
416    /// for every 10 received data packets.
417    ///
418    /// You can also turn the LED permanently on/off or show a heartbeat.
419    ///
420    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
421    ///
422    /// Associated constants:
423    /// * MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_OFF
424    ///	* MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_ON
425    ///	* MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
426    ///	* MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
427    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
428        let mut payload = [0; 1];
429        config.write_to_slice(&mut payload[0..1]);
430
431        #[allow(unused_variables)]
432        let result = self.device.set(u8::from(MotionDetectorV2BrickletFunction::SetStatusLedConfig), &payload).await?;
433        Ok(())
434    }
435
436    /// Returns the configuration as set by [`set_status_led_config`]
437    ///
438    /// Associated constants:
439    /// * MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_OFF
440    ///	* MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_ON
441    ///	* MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
442    ///	* MOTION_DETECTOR_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
443    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
444        let payload = [0; 0];
445
446        #[allow(unused_variables)]
447        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetStatusLedConfig), &payload).await?;
448        Ok(u8::from_le_byte_slice(result.body()))
449    }
450
451    /// Returns the temperature as measured inside the microcontroller. The
452    /// value returned is not the ambient temperature!
453    ///
454    /// The temperature is only proportional to the real temperature and it has bad
455    /// accuracy. Practically it is only useful as an indicator for
456    /// temperature changes.
457    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
458        let payload = [0; 0];
459
460        #[allow(unused_variables)]
461        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetChipTemperature), &payload).await?;
462        Ok(i16::from_le_byte_slice(result.body()))
463    }
464
465    /// Calling this function will reset the Bricklet. All configurations
466    /// will be lost.
467    ///
468    /// After a reset you have to create new device objects,
469    /// calling functions on the existing ones will result in
470    /// undefined behavior!
471    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
472        let payload = [0; 0];
473
474        #[allow(unused_variables)]
475        let result = self.device.set(u8::from(MotionDetectorV2BrickletFunction::Reset), &payload).await?;
476        Ok(())
477    }
478
479    /// Writes a new UID into flash. If you want to set a new UID
480    /// you have to decode the Base58 encoded UID string into an
481    /// integer first.
482    ///
483    /// We recommend that you use Brick Viewer to change the UID.
484    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
485        let mut payload = [0; 4];
486        uid.write_to_slice(&mut payload[0..4]);
487
488        #[allow(unused_variables)]
489        let result = self.device.set(u8::from(MotionDetectorV2BrickletFunction::WriteUid), &payload).await?;
490        Ok(())
491    }
492
493    /// Returns the current UID as an integer. Encode as
494    /// Base58 to get the usual string version.
495    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
496        let payload = [0; 0];
497
498        #[allow(unused_variables)]
499        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::ReadUid), &payload).await?;
500        Ok(u32::from_le_byte_slice(result.body()))
501    }
502
503    /// Returns the UID, the UID where the Bricklet is connected to,
504    /// the position, the hardware and firmware version as well as the
505    /// device identifier.
506    ///
507    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
508    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
509    /// position 'z'.
510    ///
511    /// The device identifier numbers can be found [here](device_identifier).
512    /// |device_identifier_constant|
513    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
514        let payload = [0; 0];
515
516        #[allow(unused_variables)]
517        let result = self.device.get(u8::from(MotionDetectorV2BrickletFunction::GetIdentity), &payload).await?;
518        Ok(Identity::from_le_byte_slice(result.body()))
519    }
520}