tinkerforge_async/bindings/
hat_zero_brick.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//! HAT for Raspberry Pi Zero with 4 Bricklets ports.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricks/HATZero_Brick_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 HatZeroBrickFunction {
24    GetUsbVoltage,
25    SetUsbVoltageCallbackConfiguration,
26    GetUsbVoltageCallbackConfiguration,
27    GetSpitfpErrorCount,
28    SetBootloaderMode,
29    GetBootloaderMode,
30    SetWriteFirmwarePointer,
31    WriteFirmware,
32    SetStatusLedConfig,
33    GetStatusLedConfig,
34    GetChipTemperature,
35    Reset,
36    WriteUid,
37    ReadUid,
38    GetIdentity,
39    CallbackUsbVoltage,
40}
41impl From<HatZeroBrickFunction> for u8 {
42    fn from(fun: HatZeroBrickFunction) -> Self {
43        match fun {
44            HatZeroBrickFunction::GetUsbVoltage => 1,
45            HatZeroBrickFunction::SetUsbVoltageCallbackConfiguration => 2,
46            HatZeroBrickFunction::GetUsbVoltageCallbackConfiguration => 3,
47            HatZeroBrickFunction::GetSpitfpErrorCount => 234,
48            HatZeroBrickFunction::SetBootloaderMode => 235,
49            HatZeroBrickFunction::GetBootloaderMode => 236,
50            HatZeroBrickFunction::SetWriteFirmwarePointer => 237,
51            HatZeroBrickFunction::WriteFirmware => 238,
52            HatZeroBrickFunction::SetStatusLedConfig => 239,
53            HatZeroBrickFunction::GetStatusLedConfig => 240,
54            HatZeroBrickFunction::GetChipTemperature => 242,
55            HatZeroBrickFunction::Reset => 243,
56            HatZeroBrickFunction::WriteUid => 248,
57            HatZeroBrickFunction::ReadUid => 249,
58            HatZeroBrickFunction::GetIdentity => 255,
59            HatZeroBrickFunction::CallbackUsbVoltage => 4,
60        }
61    }
62}
63pub const HAT_ZERO_BRICK_THRESHOLD_OPTION_OFF: char = 'x';
64pub const HAT_ZERO_BRICK_THRESHOLD_OPTION_OUTSIDE: char = 'o';
65pub const HAT_ZERO_BRICK_THRESHOLD_OPTION_INSIDE: char = 'i';
66pub const HAT_ZERO_BRICK_THRESHOLD_OPTION_SMALLER: char = '<';
67pub const HAT_ZERO_BRICK_THRESHOLD_OPTION_GREATER: char = '>';
68pub const HAT_ZERO_BRICK_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
69pub const HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
70pub const HAT_ZERO_BRICK_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
71pub const HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
72pub const HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
73pub const HAT_ZERO_BRICK_BOOTLOADER_STATUS_OK: u8 = 0;
74pub const HAT_ZERO_BRICK_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
75pub const HAT_ZERO_BRICK_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
76pub const HAT_ZERO_BRICK_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
77pub const HAT_ZERO_BRICK_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
78pub const HAT_ZERO_BRICK_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
79pub const HAT_ZERO_BRICK_STATUS_LED_CONFIG_OFF: u8 = 0;
80pub const HAT_ZERO_BRICK_STATUS_LED_CONFIG_ON: u8 = 1;
81pub const HAT_ZERO_BRICK_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
82pub const HAT_ZERO_BRICK_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
83
84#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
85pub struct UsbVoltageCallbackConfiguration {
86    pub period: u32,
87    pub value_has_to_change: bool,
88    pub option: char,
89    pub min: u16,
90    pub max: u16,
91}
92impl FromByteSlice for UsbVoltageCallbackConfiguration {
93    fn bytes_expected() -> usize {
94        10
95    }
96    fn from_le_byte_slice(bytes: &[u8]) -> UsbVoltageCallbackConfiguration {
97        UsbVoltageCallbackConfiguration {
98            period: <u32>::from_le_byte_slice(&bytes[0..4]),
99            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
100            option: <char>::from_le_byte_slice(&bytes[5..6]),
101            min: <u16>::from_le_byte_slice(&bytes[6..8]),
102            max: <u16>::from_le_byte_slice(&bytes[8..10]),
103        }
104    }
105}
106
107#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
108pub struct SpitfpErrorCount {
109    pub error_count_ack_checksum: u32,
110    pub error_count_message_checksum: u32,
111    pub error_count_frame: u32,
112    pub error_count_overflow: u32,
113}
114impl FromByteSlice for SpitfpErrorCount {
115    fn bytes_expected() -> usize {
116        16
117    }
118    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
119        SpitfpErrorCount {
120            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
121            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
122            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
123            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
124        }
125    }
126}
127
128#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
129pub struct Identity {
130    pub uid: String,
131    pub connected_uid: String,
132    pub position: char,
133    pub hardware_version: [u8; 3],
134    pub firmware_version: [u8; 3],
135    pub device_identifier: u16,
136}
137impl FromByteSlice for Identity {
138    fn bytes_expected() -> usize {
139        25
140    }
141    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
142        Identity {
143            uid: <String>::from_le_byte_slice(&bytes[0..8]),
144            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
145            position: <char>::from_le_byte_slice(&bytes[16..17]),
146            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
147            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
148            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
149        }
150    }
151}
152
153/// HAT for Raspberry Pi Zero with 4 Bricklets ports
154#[derive(Clone)]
155pub struct HatZeroBrick {
156    device: Device,
157}
158impl HatZeroBrick {
159    pub const DEVICE_IDENTIFIER: u16 = 112;
160    pub const DEVICE_DISPLAY_NAME: &'static str = "HAT Zero Brick";
161    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
162    pub fn new(uid: Uid, connection: AsyncIpConnection) -> HatZeroBrick {
163        let mut result = HatZeroBrick { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
164        result.device.response_expected[u8::from(HatZeroBrickFunction::GetUsbVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
165        result.device.response_expected[u8::from(HatZeroBrickFunction::SetUsbVoltageCallbackConfiguration) as usize] =
166            ResponseExpectedFlag::True;
167        result.device.response_expected[u8::from(HatZeroBrickFunction::GetUsbVoltageCallbackConfiguration) as usize] =
168            ResponseExpectedFlag::AlwaysTrue;
169        result.device.response_expected[u8::from(HatZeroBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
170        result.device.response_expected[u8::from(HatZeroBrickFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
171        result.device.response_expected[u8::from(HatZeroBrickFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
172        result.device.response_expected[u8::from(HatZeroBrickFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
173        result.device.response_expected[u8::from(HatZeroBrickFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
174        result.device.response_expected[u8::from(HatZeroBrickFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
175        result.device.response_expected[u8::from(HatZeroBrickFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
176        result.device.response_expected[u8::from(HatZeroBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
177        result.device.response_expected[u8::from(HatZeroBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
178        result.device.response_expected[u8::from(HatZeroBrickFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
179        result.device.response_expected[u8::from(HatZeroBrickFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
180        result.device.response_expected[u8::from(HatZeroBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
181        result
182    }
183
184    /// Returns the response expected flag for the function specified by the function ID parameter.
185    /// It is true if the function is expected to send a response, false otherwise.
186    ///
187    /// For getter functions this is enabled by default and cannot be disabled, because those
188    /// functions will always send a response. For callback configuration functions it is enabled
189    /// by default too, but can be disabled by [`set_response_expected`](crate::hat_zero_brick::HatZeroBrick::set_response_expected).
190    /// For setter functions it is disabled by default and can be enabled.
191    ///
192    /// Enabling the response expected flag for a setter function allows to detect timeouts
193    /// and other error conditions calls of this setter as well. The device will then send a response
194    /// for this purpose. If this flag is disabled for a setter function then no response is sent
195    /// and errors are silently ignored, because they cannot be detected.
196    ///
197    /// See [`set_response_expected`](crate::hat_zero_brick::HatZeroBrick::set_response_expected) for the list of function ID constants available for this function.
198    pub fn get_response_expected(&mut self, fun: HatZeroBrickFunction) -> Result<bool, GetResponseExpectedError> {
199        self.device.get_response_expected(u8::from(fun))
200    }
201
202    /// Changes the response expected flag of the function specified by the function ID parameter.
203    /// This flag can only be changed for setter (default value: false) and callback configuration
204    /// functions (default value: true). For getter functions it is always enabled.
205    ///
206    /// Enabling the response expected flag for a setter function allows to detect timeouts and
207    /// other error conditions calls of this setter as well. The device will then send a response
208    /// for this purpose. If this flag is disabled for a setter function then no response is sent
209    /// and errors are silently ignored, because they cannot be detected.
210    pub fn set_response_expected(&mut self, fun: HatZeroBrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
211        self.device.set_response_expected(u8::from(fun), response_expected)
212    }
213
214    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
215    pub fn set_response_expected_all(&mut self, response_expected: bool) {
216        self.device.set_response_expected_all(response_expected)
217    }
218
219    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
220    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
221    pub fn get_api_version(&self) -> [u8; 3] {
222        self.device.api_version
223    }
224
225    /// This receiver is triggered periodically according to the configuration set by
226    /// [`set_usb_voltage_callback_configuration`].
227    ///
228    /// The parameter is the same as [`get_usb_voltage`].
229    ///
230    /// [`get_usb_voltage`]: #method.get_usb_voltage
231    /// [`set_usb_voltage_callback_configuration`]: #method.set_usb_voltage_callback_configuration
232    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
233    pub async fn get_usb_voltage_callback_receiver(&mut self) -> impl Stream<Item = u16> {
234        self.device
235            .get_callback_receiver(u8::from(HatZeroBrickFunction::CallbackUsbVoltage))
236            .await
237            .map(|p| u16::from_le_byte_slice(p.body()))
238    }
239
240    /// Returns the USB supply voltage of the Raspberry Pi.
241    ///
242    ///
243    /// If you want to get the value periodically, it is recommended to use the
244    /// [`get_usb_voltage_callback_receiver`] receiver. You can set the receiver configuration
245    /// with [`set_usb_voltage_callback_configuration`].
246    pub async fn get_usb_voltage(&mut self) -> Result<u16, TinkerforgeError> {
247        let payload = [0; 0];
248
249        #[allow(unused_variables)]
250        let result = self.device.get(u8::from(HatZeroBrickFunction::GetUsbVoltage), &payload).await?;
251        Ok(u16::from_le_byte_slice(result.body()))
252    }
253
254    /// The period is the period with which the [`get_usb_voltage_callback_receiver`] receiver is triggered
255    /// periodically. A value of 0 turns the receiver off.
256    ///
257    /// If the `value has to change`-parameter is set to true, the receiver is only
258    /// triggered after the value has changed. If the value didn't change
259    /// within the period, the receiver is triggered immediately on change.
260    ///
261    /// If it is set to false, the receiver is continuously triggered with the period,
262    /// independent of the value.
263    ///
264    /// It is furthermore possible to constrain the receiver with thresholds.
265    ///
266    /// The `option`-parameter together with min/max sets a threshold for the [`get_usb_voltage_callback_receiver`] receiver.
267    ///
268    /// The following options are possible:
269    ///
270    ///  Option| Description
271    ///  --- | ---
272    ///  'x'|    Threshold is turned off
273    ///  'o'|    Threshold is triggered when the value is *outside* the min and max values
274    ///  'i'|    Threshold is triggered when the value is *inside* or equal to the min and max values
275    ///  '<'|    Threshold is triggered when the value is smaller than the min value (max is ignored)
276    ///  '>'|    Threshold is triggered when the value is greater than the min value (max is ignored)
277    ///
278    /// If the option is set to 'x' (threshold turned off) the receiver is triggered with the fixed period.
279    ///
280    ///
281    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
282    ///
283    /// Associated constants:
284    /// * HAT_ZERO_BRICK_THRESHOLD_OPTION_OFF
285    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_OUTSIDE
286    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_INSIDE
287    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_SMALLER
288    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_GREATER
289    pub async fn set_usb_voltage_callback_configuration(
290        &mut self,
291        period: u32,
292        value_has_to_change: bool,
293        option: char,
294        min: u16,
295        max: u16,
296    ) -> Result<(), TinkerforgeError> {
297        let mut payload = [0; 10];
298        period.write_to_slice(&mut payload[0..4]);
299        value_has_to_change.write_to_slice(&mut payload[4..5]);
300        option.write_to_slice(&mut payload[5..6]);
301        min.write_to_slice(&mut payload[6..8]);
302        max.write_to_slice(&mut payload[8..10]);
303
304        #[allow(unused_variables)]
305        let result = self.device.set(u8::from(HatZeroBrickFunction::SetUsbVoltageCallbackConfiguration), &payload).await?;
306        Ok(())
307    }
308
309    /// Returns the receiver configuration as set by [`set_usb_voltage_callback_configuration`].
310    ///
311    ///
312    /// .. versionadded:: 2.0.1$nbsp;(Firmware)
313    ///
314    /// Associated constants:
315    /// * HAT_ZERO_BRICK_THRESHOLD_OPTION_OFF
316    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_OUTSIDE
317    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_INSIDE
318    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_SMALLER
319    ///	* HAT_ZERO_BRICK_THRESHOLD_OPTION_GREATER
320    pub async fn get_usb_voltage_callback_configuration(&mut self) -> Result<UsbVoltageCallbackConfiguration, TinkerforgeError> {
321        let payload = [0; 0];
322
323        #[allow(unused_variables)]
324        let result = self.device.get(u8::from(HatZeroBrickFunction::GetUsbVoltageCallbackConfiguration), &payload).await?;
325        Ok(UsbVoltageCallbackConfiguration::from_le_byte_slice(result.body()))
326    }
327
328    /// Returns the error count for the communication between Brick and Bricklet.
329    ///
330    /// The errors are divided into
331    ///
332    /// * ACK checksum errors,
333    /// * message checksum errors,
334    /// * framing errors and
335    /// * overflow errors.
336    ///
337    /// The errors counts are for errors that occur on the Bricklet side. All
338    /// Bricks have a similar function that returns the errors on the Brick side.
339    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
340        let payload = [0; 0];
341
342        #[allow(unused_variables)]
343        let result = self.device.get(u8::from(HatZeroBrickFunction::GetSpitfpErrorCount), &payload).await?;
344        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
345    }
346
347    /// Sets the bootloader mode and returns the status after the requested
348    /// mode change was instigated.
349    ///
350    /// You can change from bootloader mode to firmware mode and vice versa. A change
351    /// from bootloader mode to firmware mode will only take place if the entry function,
352    /// device identifier and CRC are present and correct.
353    ///
354    /// This function is used by Brick Viewer during flashing. It should not be
355    /// necessary to call it in a normal user program.
356    ///
357    /// Associated constants:
358    /// * HAT_ZERO_BRICK_BOOTLOADER_MODE_BOOTLOADER
359    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE
360    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
361    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
362    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
363    ///	* HAT_ZERO_BRICK_BOOTLOADER_STATUS_OK
364    ///	* HAT_ZERO_BRICK_BOOTLOADER_STATUS_INVALID_MODE
365    ///	* HAT_ZERO_BRICK_BOOTLOADER_STATUS_NO_CHANGE
366    ///	* HAT_ZERO_BRICK_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
367    ///	* HAT_ZERO_BRICK_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
368    ///	* HAT_ZERO_BRICK_BOOTLOADER_STATUS_CRC_MISMATCH
369    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
370        let mut payload = [0; 1];
371        mode.write_to_slice(&mut payload[0..1]);
372
373        #[allow(unused_variables)]
374        let result = self.device.get(u8::from(HatZeroBrickFunction::SetBootloaderMode), &payload).await?;
375        Ok(u8::from_le_byte_slice(result.body()))
376    }
377
378    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
379    ///
380    /// Associated constants:
381    /// * HAT_ZERO_BRICK_BOOTLOADER_MODE_BOOTLOADER
382    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE
383    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
384    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
385    ///	* HAT_ZERO_BRICK_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
386    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
387        let payload = [0; 0];
388
389        #[allow(unused_variables)]
390        let result = self.device.get(u8::from(HatZeroBrickFunction::GetBootloaderMode), &payload).await?;
391        Ok(u8::from_le_byte_slice(result.body()))
392    }
393
394    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
395    /// to be increased by chunks of size 64. The data is written to flash
396    /// every 4 chunks (which equals to one page of size 256).
397    ///
398    /// This function is used by Brick Viewer during flashing. It should not be
399    /// necessary to call it in a normal user program.
400    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
401        let mut payload = [0; 4];
402        pointer.write_to_slice(&mut payload[0..4]);
403
404        #[allow(unused_variables)]
405        let result = self.device.set(u8::from(HatZeroBrickFunction::SetWriteFirmwarePointer), &payload).await?;
406        Ok(())
407    }
408
409    /// Writes 64 Bytes of firmware at the position as written by
410    /// [`set_write_firmware_pointer`] before. The firmware is written
411    /// to flash every 4 chunks.
412    ///
413    /// You can only write firmware in bootloader mode.
414    ///
415    /// This function is used by Brick Viewer during flashing. It should not be
416    /// necessary to call it in a normal user program.
417    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
418        let mut payload = [0; 64];
419        data.write_to_slice(&mut payload[0..64]);
420
421        #[allow(unused_variables)]
422        let result = self.device.get(u8::from(HatZeroBrickFunction::WriteFirmware), &payload).await?;
423        Ok(u8::from_le_byte_slice(result.body()))
424    }
425
426    /// Sets the status LED configuration. By default the LED shows
427    /// communication traffic between Brick and Bricklet, it flickers once
428    /// for every 10 received data packets.
429    ///
430    /// You can also turn the LED permanently on/off or show a heartbeat.
431    ///
432    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
433    ///
434    /// Associated constants:
435    /// * HAT_ZERO_BRICK_STATUS_LED_CONFIG_OFF
436    ///	* HAT_ZERO_BRICK_STATUS_LED_CONFIG_ON
437    ///	* HAT_ZERO_BRICK_STATUS_LED_CONFIG_SHOW_HEARTBEAT
438    ///	* HAT_ZERO_BRICK_STATUS_LED_CONFIG_SHOW_STATUS
439    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
440        let mut payload = [0; 1];
441        config.write_to_slice(&mut payload[0..1]);
442
443        #[allow(unused_variables)]
444        let result = self.device.set(u8::from(HatZeroBrickFunction::SetStatusLedConfig), &payload).await?;
445        Ok(())
446    }
447
448    /// Returns the configuration as set by [`set_status_led_config`]
449    ///
450    /// Associated constants:
451    /// * HAT_ZERO_BRICK_STATUS_LED_CONFIG_OFF
452    ///	* HAT_ZERO_BRICK_STATUS_LED_CONFIG_ON
453    ///	* HAT_ZERO_BRICK_STATUS_LED_CONFIG_SHOW_HEARTBEAT
454    ///	* HAT_ZERO_BRICK_STATUS_LED_CONFIG_SHOW_STATUS
455    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
456        let payload = [0; 0];
457
458        #[allow(unused_variables)]
459        let result = self.device.get(u8::from(HatZeroBrickFunction::GetStatusLedConfig), &payload).await?;
460        Ok(u8::from_le_byte_slice(result.body()))
461    }
462
463    /// Returns the temperature as measured inside the microcontroller. The
464    /// value returned is not the ambient temperature!
465    ///
466    /// The temperature is only proportional to the real temperature and it has bad
467    /// accuracy. Practically it is only useful as an indicator for
468    /// temperature changes.
469    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
470        let payload = [0; 0];
471
472        #[allow(unused_variables)]
473        let result = self.device.get(u8::from(HatZeroBrickFunction::GetChipTemperature), &payload).await?;
474        Ok(i16::from_le_byte_slice(result.body()))
475    }
476
477    /// Calling this function will reset the Bricklet. All configurations
478    /// will be lost.
479    ///
480    /// After a reset you have to create new device objects,
481    /// calling functions on the existing ones will result in
482    /// undefined behavior!
483    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
484        let payload = [0; 0];
485
486        #[allow(unused_variables)]
487        let result = self.device.set(u8::from(HatZeroBrickFunction::Reset), &payload).await?;
488        Ok(())
489    }
490
491    /// Writes a new UID into flash. If you want to set a new UID
492    /// you have to decode the Base58 encoded UID string into an
493    /// integer first.
494    ///
495    /// We recommend that you use Brick Viewer to change the UID.
496    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
497        let mut payload = [0; 4];
498        uid.write_to_slice(&mut payload[0..4]);
499
500        #[allow(unused_variables)]
501        let result = self.device.set(u8::from(HatZeroBrickFunction::WriteUid), &payload).await?;
502        Ok(())
503    }
504
505    /// Returns the current UID as an integer. Encode as
506    /// Base58 to get the usual string version.
507    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
508        let payload = [0; 0];
509
510        #[allow(unused_variables)]
511        let result = self.device.get(u8::from(HatZeroBrickFunction::ReadUid), &payload).await?;
512        Ok(u32::from_le_byte_slice(result.body()))
513    }
514
515    /// Returns the UID, the UID where the HAT is connected to
516    /// (typically '0' as the HAT is the root device in the topology),
517    /// the position, the hardware and firmware version as well as the
518    /// device identifier.
519    ///
520    /// The HAT (Zero) Brick is always at position 'i'.
521    ///
522    /// The device identifier numbers can be found [here](device_identifier).
523    /// |device_identifier_constant|
524    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
525        let payload = [0; 0];
526
527        #[allow(unused_variables)]
528        let result = self.device.get(u8::from(HatZeroBrickFunction::GetIdentity), &payload).await?;
529        Ok(Identity::from_le_byte_slice(result.body()))
530    }
531}