tinkerforge_async/bindings/
rgb_led_matrix_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//! RGB LED Matrix with 8x8 pixel.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/RGBLEDMatrix_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 RgbLedMatrixBrickletFunction {
24    SetRed,
25    GetRed,
26    SetGreen,
27    GetGreen,
28    SetBlue,
29    GetBlue,
30    SetFrameDuration,
31    GetFrameDuration,
32    DrawFrame,
33    GetSupplyVoltage,
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    CallbackFrameStarted,
47}
48impl From<RgbLedMatrixBrickletFunction> for u8 {
49    fn from(fun: RgbLedMatrixBrickletFunction) -> Self {
50        match fun {
51            RgbLedMatrixBrickletFunction::SetRed => 1,
52            RgbLedMatrixBrickletFunction::GetRed => 2,
53            RgbLedMatrixBrickletFunction::SetGreen => 3,
54            RgbLedMatrixBrickletFunction::GetGreen => 4,
55            RgbLedMatrixBrickletFunction::SetBlue => 5,
56            RgbLedMatrixBrickletFunction::GetBlue => 6,
57            RgbLedMatrixBrickletFunction::SetFrameDuration => 7,
58            RgbLedMatrixBrickletFunction::GetFrameDuration => 8,
59            RgbLedMatrixBrickletFunction::DrawFrame => 9,
60            RgbLedMatrixBrickletFunction::GetSupplyVoltage => 10,
61            RgbLedMatrixBrickletFunction::GetSpitfpErrorCount => 234,
62            RgbLedMatrixBrickletFunction::SetBootloaderMode => 235,
63            RgbLedMatrixBrickletFunction::GetBootloaderMode => 236,
64            RgbLedMatrixBrickletFunction::SetWriteFirmwarePointer => 237,
65            RgbLedMatrixBrickletFunction::WriteFirmware => 238,
66            RgbLedMatrixBrickletFunction::SetStatusLedConfig => 239,
67            RgbLedMatrixBrickletFunction::GetStatusLedConfig => 240,
68            RgbLedMatrixBrickletFunction::GetChipTemperature => 242,
69            RgbLedMatrixBrickletFunction::Reset => 243,
70            RgbLedMatrixBrickletFunction::WriteUid => 248,
71            RgbLedMatrixBrickletFunction::ReadUid => 249,
72            RgbLedMatrixBrickletFunction::GetIdentity => 255,
73            RgbLedMatrixBrickletFunction::CallbackFrameStarted => 11,
74        }
75    }
76}
77pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
78pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
79pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
80pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
81pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
82pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
83pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
84pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
85pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
86pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
87pub const RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
88pub const RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
89pub const RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
90pub const RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
91pub const RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
92
93#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
94pub struct SpitfpErrorCount {
95    pub error_count_ack_checksum: u32,
96    pub error_count_message_checksum: u32,
97    pub error_count_frame: u32,
98    pub error_count_overflow: u32,
99}
100impl FromByteSlice for SpitfpErrorCount {
101    fn bytes_expected() -> usize {
102        16
103    }
104    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
105        SpitfpErrorCount {
106            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
107            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
108            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
109            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
110        }
111    }
112}
113
114#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
115pub struct Identity {
116    pub uid: String,
117    pub connected_uid: String,
118    pub position: char,
119    pub hardware_version: [u8; 3],
120    pub firmware_version: [u8; 3],
121    pub device_identifier: u16,
122}
123impl FromByteSlice for Identity {
124    fn bytes_expected() -> usize {
125        25
126    }
127    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
128        Identity {
129            uid: <String>::from_le_byte_slice(&bytes[0..8]),
130            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
131            position: <char>::from_le_byte_slice(&bytes[16..17]),
132            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
133            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
134            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
135        }
136    }
137}
138
139/// RGB LED Matrix with 8x8 pixel
140#[derive(Clone)]
141pub struct RgbLedMatrixBricklet {
142    device: Device,
143}
144impl RgbLedMatrixBricklet {
145    pub const DEVICE_IDENTIFIER: u16 = 272;
146    pub const DEVICE_DISPLAY_NAME: &'static str = "RGB LED Matrix Bricklet";
147    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
148    pub fn new(uid: Uid, connection: AsyncIpConnection) -> RgbLedMatrixBricklet {
149        let mut result = RgbLedMatrixBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
150        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::SetRed) as usize] = ResponseExpectedFlag::False;
151        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetRed) as usize] = ResponseExpectedFlag::AlwaysTrue;
152        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::SetGreen) as usize] = ResponseExpectedFlag::False;
153        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetGreen) as usize] = ResponseExpectedFlag::AlwaysTrue;
154        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::SetBlue) as usize] = ResponseExpectedFlag::False;
155        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetBlue) as usize] = ResponseExpectedFlag::AlwaysTrue;
156        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::SetFrameDuration) as usize] = ResponseExpectedFlag::False;
157        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetFrameDuration) as usize] =
158            ResponseExpectedFlag::AlwaysTrue;
159        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::DrawFrame) as usize] = ResponseExpectedFlag::False;
160        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetSupplyVoltage) as usize] =
161            ResponseExpectedFlag::AlwaysTrue;
162        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetSpitfpErrorCount) as usize] =
163            ResponseExpectedFlag::AlwaysTrue;
164        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::SetBootloaderMode) as usize] =
165            ResponseExpectedFlag::AlwaysTrue;
166        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetBootloaderMode) as usize] =
167            ResponseExpectedFlag::AlwaysTrue;
168        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::SetWriteFirmwarePointer) as usize] =
169            ResponseExpectedFlag::False;
170        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
171        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
172        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetStatusLedConfig) as usize] =
173            ResponseExpectedFlag::AlwaysTrue;
174        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetChipTemperature) as usize] =
175            ResponseExpectedFlag::AlwaysTrue;
176        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
177        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
178        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
179        result.device.response_expected[u8::from(RgbLedMatrixBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
180        result
181    }
182
183    /// Returns the response expected flag for the function specified by the function ID parameter.
184    /// It is true if the function is expected to send a response, false otherwise.
185    ///
186    /// For getter functions this is enabled by default and cannot be disabled, because those
187    /// functions will always send a response. For callback configuration functions it is enabled
188    /// by default too, but can be disabled by [`set_response_expected`](crate::rgb_led_matrix_bricklet::RgbLedMatrixBricklet::set_response_expected).
189    /// For setter functions it is disabled by default and can be enabled.
190    ///
191    /// Enabling the response expected flag for a setter function allows to detect timeouts
192    /// and other error conditions calls of this setter as well. The device will then send a response
193    /// for this purpose. If this flag is disabled for a setter function then no response is sent
194    /// and errors are silently ignored, because they cannot be detected.
195    ///
196    /// See [`set_response_expected`](crate::rgb_led_matrix_bricklet::RgbLedMatrixBricklet::set_response_expected) for the list of function ID constants available for this function.
197    pub fn get_response_expected(&mut self, fun: RgbLedMatrixBrickletFunction) -> Result<bool, GetResponseExpectedError> {
198        self.device.get_response_expected(u8::from(fun))
199    }
200
201    /// Changes the response expected flag of the function specified by the function ID parameter.
202    /// This flag can only be changed for setter (default value: false) and callback configuration
203    /// functions (default value: true). For getter functions it is always enabled.
204    ///
205    /// Enabling the response expected flag for a setter function allows to detect timeouts and
206    /// other error conditions calls of this setter as well. The device will then send a response
207    /// for this purpose. If this flag is disabled for a setter function then no response is sent
208    /// and errors are silently ignored, because they cannot be detected.
209    pub fn set_response_expected(
210        &mut self,
211        fun: RgbLedMatrixBrickletFunction,
212        response_expected: bool,
213    ) -> Result<(), SetResponseExpectedError> {
214        self.device.set_response_expected(u8::from(fun), response_expected)
215    }
216
217    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
218    pub fn set_response_expected_all(&mut self, response_expected: bool) {
219        self.device.set_response_expected_all(response_expected)
220    }
221
222    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
223    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
224    pub fn get_api_version(&self) -> [u8; 3] {
225        self.device.api_version
226    }
227
228    /// This receiver is triggered as soon as a new frame write is started.
229    /// The LED values are double buffered, so you can send the LED values
230    /// for the next frame directly after this receiver is triggered.
231    pub async fn get_frame_started_callback_receiver(&mut self) -> impl Stream<Item = u32> {
232        self.device
233            .get_callback_receiver(u8::from(RgbLedMatrixBrickletFunction::CallbackFrameStarted))
234            .await
235            .map(|p| u32::from_le_byte_slice(p.body()))
236    }
237
238    /// Sets the 64 red LED values of the matrix.
239    pub async fn set_red(&mut self, red: &[u8; 64]) -> Result<(), TinkerforgeError> {
240        let mut payload = [0; 64];
241        red.write_to_slice(&mut payload[0..64]);
242
243        #[allow(unused_variables)]
244        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::SetRed), &payload).await?;
245        Ok(())
246    }
247
248    /// Returns the red LED values as set by [`set_red`].
249    pub async fn get_red(&mut self) -> Result<Box<[u8; 64]>, TinkerforgeError> {
250        let payload = [0; 0];
251
252        #[allow(unused_variables)]
253        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetRed), &payload).await?;
254        Ok(Box::<[u8; 64]>::from_le_byte_slice(result.body()))
255    }
256
257    /// Sets the 64 green LED values of the matrix.
258    pub async fn set_green(&mut self, green: &[u8; 64]) -> Result<(), TinkerforgeError> {
259        let mut payload = [0; 64];
260        green.write_to_slice(&mut payload[0..64]);
261
262        #[allow(unused_variables)]
263        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::SetGreen), &payload).await?;
264        Ok(())
265    }
266
267    /// Returns the green LED values as set by [`set_green`].
268    pub async fn get_green(&mut self) -> Result<Box<[u8; 64]>, TinkerforgeError> {
269        let payload = [0; 0];
270
271        #[allow(unused_variables)]
272        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetGreen), &payload).await?;
273        Ok(Box::<[u8; 64]>::from_le_byte_slice(result.body()))
274    }
275
276    /// Sets the 64 blue LED values of the matrix.
277    pub async fn set_blue(&mut self, blue: &[u8; 64]) -> Result<(), TinkerforgeError> {
278        let mut payload = [0; 64];
279        blue.write_to_slice(&mut payload[0..64]);
280
281        #[allow(unused_variables)]
282        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::SetBlue), &payload).await?;
283        Ok(())
284    }
285
286    /// Returns the blue LED values as set by [`set_blue`].
287    pub async fn get_blue(&mut self) -> Result<Box<[u8; 64]>, TinkerforgeError> {
288        let payload = [0; 0];
289
290        #[allow(unused_variables)]
291        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetBlue), &payload).await?;
292        Ok(Box::<[u8; 64]>::from_le_byte_slice(result.body()))
293    }
294
295    /// Sets the frame duration.
296    ///
297    /// Example: If you want to achieve 20 frames per second, you should
298    /// set the frame duration to 50ms (50ms * 20 = 1 second).
299    ///
300    /// Set this value to 0 to turn the automatic frame write mechanism off.
301    ///
302    /// Approach:
303    ///
304    /// * Call [`set_frame_duration`] with value > 0.
305    /// * Set LED values for first frame with [`set_red`], [`set_green`], [`set_blue`].
306    /// * Wait for [`get_frame_started_callback_receiver`] receiver.
307    /// * Set LED values for second frame with [`set_red`], [`set_green`], [`set_blue`].
308    /// * Wait for [`get_frame_started_callback_receiver`] receiver.
309    /// * and so on.
310    ///
311    /// For frame duration of 0 see [`draw_frame`].
312    pub async fn set_frame_duration(&mut self, frame_duration: u16) -> Result<(), TinkerforgeError> {
313        let mut payload = [0; 2];
314        frame_duration.write_to_slice(&mut payload[0..2]);
315
316        #[allow(unused_variables)]
317        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::SetFrameDuration), &payload).await?;
318        Ok(())
319    }
320
321    /// Returns the frame duration as set by [`set_frame_duration`].
322    pub async fn get_frame_duration(&mut self) -> Result<u16, TinkerforgeError> {
323        let payload = [0; 0];
324
325        #[allow(unused_variables)]
326        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetFrameDuration), &payload).await?;
327        Ok(u16::from_le_byte_slice(result.body()))
328    }
329
330    /// If you set the frame duration to 0 (see [`set_frame_duration`]), you can use this
331    /// function to transfer the frame to the matrix.
332    ///
333    /// Approach:
334    ///
335    /// * Call [`set_frame_duration`] with 0.
336    /// * Set LED values for first frame with [`set_red`], [`set_green`], [`set_blue`].
337    /// * Call [`draw_frame`].
338    /// * Wait for [`get_frame_started_callback_receiver`] receiver.
339    /// * Set LED values for second frame with [`set_red`], [`set_green`], [`set_blue`].
340    /// * Call [`draw_frame`].
341    /// * Wait for [`get_frame_started_callback_receiver`] receiver.
342    /// * and so on.
343    pub async fn draw_frame(&mut self) -> Result<(), TinkerforgeError> {
344        let payload = [0; 0];
345
346        #[allow(unused_variables)]
347        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::DrawFrame), &payload).await?;
348        Ok(())
349    }
350
351    /// Returns the current supply voltage of the Bricklet.
352    pub async fn get_supply_voltage(&mut self) -> Result<u16, TinkerforgeError> {
353        let payload = [0; 0];
354
355        #[allow(unused_variables)]
356        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetSupplyVoltage), &payload).await?;
357        Ok(u16::from_le_byte_slice(result.body()))
358    }
359
360    /// Returns the error count for the communication between Brick and Bricklet.
361    ///
362    /// The errors are divided into
363    ///
364    /// * ACK checksum errors,
365    /// * message checksum errors,
366    /// * framing errors and
367    /// * overflow errors.
368    ///
369    /// The errors counts are for errors that occur on the Bricklet side. All
370    /// Bricks have a similar function that returns the errors on the Brick side.
371    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
372        let payload = [0; 0];
373
374        #[allow(unused_variables)]
375        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetSpitfpErrorCount), &payload).await?;
376        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
377    }
378
379    /// Sets the bootloader mode and returns the status after the requested
380    /// mode change was instigated.
381    ///
382    /// You can change from bootloader mode to firmware mode and vice versa. A change
383    /// from bootloader mode to firmware mode will only take place if the entry function,
384    /// device identifier and CRC are present and correct.
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    ///
389    /// Associated constants:
390    /// * RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
391    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE
392    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
393    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
394    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
395    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_OK
396    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
397    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
398    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
399    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
400    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
401    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
402        let mut payload = [0; 1];
403        mode.write_to_slice(&mut payload[0..1]);
404
405        #[allow(unused_variables)]
406        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::SetBootloaderMode), &payload).await?;
407        Ok(u8::from_le_byte_slice(result.body()))
408    }
409
410    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
411    ///
412    /// Associated constants:
413    /// * RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
414    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE
415    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
416    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
417    ///	* RGB_LED_MATRIX_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
418    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
419        let payload = [0; 0];
420
421        #[allow(unused_variables)]
422        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetBootloaderMode), &payload).await?;
423        Ok(u8::from_le_byte_slice(result.body()))
424    }
425
426    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
427    /// to be increased by chunks of size 64. The data is written to flash
428    /// every 4 chunks (which equals to one page of size 256).
429    ///
430    /// This function is used by Brick Viewer during flashing. It should not be
431    /// necessary to call it in a normal user program.
432    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
433        let mut payload = [0; 4];
434        pointer.write_to_slice(&mut payload[0..4]);
435
436        #[allow(unused_variables)]
437        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
438        Ok(())
439    }
440
441    /// Writes 64 Bytes of firmware at the position as written by
442    /// [`set_write_firmware_pointer`] before. The firmware is written
443    /// to flash every 4 chunks.
444    ///
445    /// You can only write firmware in bootloader mode.
446    ///
447    /// This function is used by Brick Viewer during flashing. It should not be
448    /// necessary to call it in a normal user program.
449    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
450        let mut payload = [0; 64];
451        data.write_to_slice(&mut payload[0..64]);
452
453        #[allow(unused_variables)]
454        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::WriteFirmware), &payload).await?;
455        Ok(u8::from_le_byte_slice(result.body()))
456    }
457
458    /// Sets the status LED configuration. By default the LED shows
459    /// communication traffic between Brick and Bricklet, it flickers once
460    /// for every 10 received data packets.
461    ///
462    /// You can also turn the LED permanently on/off or show a heartbeat.
463    ///
464    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
465    ///
466    /// Associated constants:
467    /// * RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_OFF
468    ///	* RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_ON
469    ///	* RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
470    ///	* RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
471    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
472        let mut payload = [0; 1];
473        config.write_to_slice(&mut payload[0..1]);
474
475        #[allow(unused_variables)]
476        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::SetStatusLedConfig), &payload).await?;
477        Ok(())
478    }
479
480    /// Returns the configuration as set by [`set_status_led_config`]
481    ///
482    /// Associated constants:
483    /// * RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_OFF
484    ///	* RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_ON
485    ///	* RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
486    ///	* RGB_LED_MATRIX_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
487    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
488        let payload = [0; 0];
489
490        #[allow(unused_variables)]
491        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetStatusLedConfig), &payload).await?;
492        Ok(u8::from_le_byte_slice(result.body()))
493    }
494
495    /// Returns the temperature as measured inside the microcontroller. The
496    /// value returned is not the ambient temperature!
497    ///
498    /// The temperature is only proportional to the real temperature and it has bad
499    /// accuracy. Practically it is only useful as an indicator for
500    /// temperature changes.
501    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
502        let payload = [0; 0];
503
504        #[allow(unused_variables)]
505        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetChipTemperature), &payload).await?;
506        Ok(i16::from_le_byte_slice(result.body()))
507    }
508
509    /// Calling this function will reset the Bricklet. All configurations
510    /// will be lost.
511    ///
512    /// After a reset you have to create new device objects,
513    /// calling functions on the existing ones will result in
514    /// undefined behavior!
515    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
516        let payload = [0; 0];
517
518        #[allow(unused_variables)]
519        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::Reset), &payload).await?;
520        Ok(())
521    }
522
523    /// Writes a new UID into flash. If you want to set a new UID
524    /// you have to decode the Base58 encoded UID string into an
525    /// integer first.
526    ///
527    /// We recommend that you use Brick Viewer to change the UID.
528    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
529        let mut payload = [0; 4];
530        uid.write_to_slice(&mut payload[0..4]);
531
532        #[allow(unused_variables)]
533        let result = self.device.set(u8::from(RgbLedMatrixBrickletFunction::WriteUid), &payload).await?;
534        Ok(())
535    }
536
537    /// Returns the current UID as an integer. Encode as
538    /// Base58 to get the usual string version.
539    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
540        let payload = [0; 0];
541
542        #[allow(unused_variables)]
543        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::ReadUid), &payload).await?;
544        Ok(u32::from_le_byte_slice(result.body()))
545    }
546
547    /// Returns the UID, the UID where the Bricklet is connected to,
548    /// the position, the hardware and firmware version as well as the
549    /// device identifier.
550    ///
551    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
552    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
553    /// position 'z'.
554    ///
555    /// The device identifier numbers can be found [here](device_identifier).
556    /// |device_identifier_constant|
557    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
558        let payload = [0; 0];
559
560        #[allow(unused_variables)]
561        let result = self.device.get(u8::from(RgbLedMatrixBrickletFunction::GetIdentity), &payload).await?;
562        Ok(Identity::from_le_byte_slice(result.body()))
563    }
564}