tinkerforge_async/bindings/
oled_128x64_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//! 3.3cm (1.3") OLED display with 128x64 pixels.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/OLED128x64V2_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid,
17    byte_converter::*,
18    converting_receiver::{BrickletError, BrickletRecvTimeoutError},
19    device::*,
20    error::TinkerforgeError,
21    ip_connection::async_io::AsyncIpConnection,
22    low_level_traits::LowLevelRead,
23};
24#[allow(unused_imports)]
25use futures_core::Stream;
26#[allow(unused_imports)]
27use tokio_stream::StreamExt;
28pub enum Oled128x64V2BrickletFunction {
29    WritePixelsLowLevel,
30    ReadPixelsLowLevel,
31    ClearDisplay,
32    SetDisplayConfiguration,
33    GetDisplayConfiguration,
34    WriteLine,
35    DrawBufferedFrame,
36    GetSpitfpErrorCount,
37    SetBootloaderMode,
38    GetBootloaderMode,
39    SetWriteFirmwarePointer,
40    WriteFirmware,
41    SetStatusLedConfig,
42    GetStatusLedConfig,
43    GetChipTemperature,
44    Reset,
45    WriteUid,
46    ReadUid,
47    GetIdentity,
48}
49impl From<Oled128x64V2BrickletFunction> for u8 {
50    fn from(fun: Oled128x64V2BrickletFunction) -> Self {
51        match fun {
52            Oled128x64V2BrickletFunction::WritePixelsLowLevel => 1,
53            Oled128x64V2BrickletFunction::ReadPixelsLowLevel => 2,
54            Oled128x64V2BrickletFunction::ClearDisplay => 3,
55            Oled128x64V2BrickletFunction::SetDisplayConfiguration => 4,
56            Oled128x64V2BrickletFunction::GetDisplayConfiguration => 5,
57            Oled128x64V2BrickletFunction::WriteLine => 6,
58            Oled128x64V2BrickletFunction::DrawBufferedFrame => 7,
59            Oled128x64V2BrickletFunction::GetSpitfpErrorCount => 234,
60            Oled128x64V2BrickletFunction::SetBootloaderMode => 235,
61            Oled128x64V2BrickletFunction::GetBootloaderMode => 236,
62            Oled128x64V2BrickletFunction::SetWriteFirmwarePointer => 237,
63            Oled128x64V2BrickletFunction::WriteFirmware => 238,
64            Oled128x64V2BrickletFunction::SetStatusLedConfig => 239,
65            Oled128x64V2BrickletFunction::GetStatusLedConfig => 240,
66            Oled128x64V2BrickletFunction::GetChipTemperature => 242,
67            Oled128x64V2BrickletFunction::Reset => 243,
68            Oled128x64V2BrickletFunction::WriteUid => 248,
69            Oled128x64V2BrickletFunction::ReadUid => 249,
70            Oled128x64V2BrickletFunction::GetIdentity => 255,
71        }
72    }
73}
74pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
75pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
76pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
77pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
78pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
79pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
80pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
81pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
82pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
83pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
84pub const OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
85pub const OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
86pub const OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
87pub const OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
88pub const OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
89
90#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
91pub struct WritePixelsLowLevel {}
92impl FromByteSlice for WritePixelsLowLevel {
93    fn bytes_expected() -> usize {
94        0
95    }
96    fn from_le_byte_slice(_bytes: &[u8]) -> WritePixelsLowLevel {
97        WritePixelsLowLevel {}
98    }
99}
100
101#[derive(Clone, Copy)]
102pub struct ReadPixelsLowLevel {
103    pub pixels_length: u16,
104    pub pixels_chunk_offset: u16,
105    pub pixels_chunk_data: [bool; 480],
106}
107impl FromByteSlice for ReadPixelsLowLevel {
108    fn bytes_expected() -> usize {
109        64
110    }
111    fn from_le_byte_slice(bytes: &[u8]) -> ReadPixelsLowLevel {
112        ReadPixelsLowLevel {
113            pixels_length: <u16>::from_le_byte_slice(&bytes[0..2]),
114            pixels_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
115            pixels_chunk_data: <[bool; 480]>::from_le_byte_slice(&bytes[4..64]),
116        }
117    }
118}
119impl LowLevelRead<bool, ReadPixelsResult> for ReadPixelsLowLevel {
120    fn ll_message_length(&self) -> usize {
121        self.pixels_length as usize
122    }
123
124    fn ll_message_chunk_offset(&self) -> usize {
125        self.pixels_chunk_offset as usize
126    }
127
128    fn ll_message_chunk_data(&self) -> &[bool] {
129        &self.pixels_chunk_data
130    }
131
132    fn get_result(&self) -> ReadPixelsResult {
133        ReadPixelsResult {}
134    }
135}
136
137#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
138pub struct DisplayConfiguration {
139    pub contrast: u8,
140    pub invert: bool,
141    pub automatic_draw: bool,
142}
143impl FromByteSlice for DisplayConfiguration {
144    fn bytes_expected() -> usize {
145        3
146    }
147    fn from_le_byte_slice(bytes: &[u8]) -> DisplayConfiguration {
148        DisplayConfiguration {
149            contrast: <u8>::from_le_byte_slice(&bytes[0..1]),
150            invert: <bool>::from_le_byte_slice(&bytes[1..2]),
151            automatic_draw: <bool>::from_le_byte_slice(&bytes[2..3]),
152        }
153    }
154}
155
156#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
157pub struct SpitfpErrorCount {
158    pub error_count_ack_checksum: u32,
159    pub error_count_message_checksum: u32,
160    pub error_count_frame: u32,
161    pub error_count_overflow: u32,
162}
163impl FromByteSlice for SpitfpErrorCount {
164    fn bytes_expected() -> usize {
165        16
166    }
167    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
168        SpitfpErrorCount {
169            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
170            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
171            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
172            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
173        }
174    }
175}
176
177#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
178pub struct Identity {
179    pub uid: String,
180    pub connected_uid: String,
181    pub position: char,
182    pub hardware_version: [u8; 3],
183    pub firmware_version: [u8; 3],
184    pub device_identifier: u16,
185}
186impl FromByteSlice for Identity {
187    fn bytes_expected() -> usize {
188        25
189    }
190    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
191        Identity {
192            uid: <String>::from_le_byte_slice(&bytes[0..8]),
193            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
194            position: <char>::from_le_byte_slice(&bytes[16..17]),
195            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
196            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
197            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
198        }
199    }
200}
201
202#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
203pub struct WritePixelsResult {}
204
205#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
206pub struct ReadPixelsResult {}
207
208/// 3.3cm (1.3") OLED display with 128x64 pixels
209#[derive(Clone)]
210pub struct Oled128x64V2Bricklet {
211    device: Device,
212}
213impl Oled128x64V2Bricklet {
214    pub const DEVICE_IDENTIFIER: u16 = 2112;
215    pub const DEVICE_DISPLAY_NAME: &'static str = "OLED 128x64 Bricklet 2.0";
216    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
217    pub fn new(uid: Uid, connection: AsyncIpConnection) -> Oled128x64V2Bricklet {
218        let mut result = Oled128x64V2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
219        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::WritePixelsLowLevel) as usize] = ResponseExpectedFlag::True;
220        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::ReadPixelsLowLevel) as usize] =
221            ResponseExpectedFlag::AlwaysTrue;
222        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::ClearDisplay) as usize] = ResponseExpectedFlag::False;
223        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::SetDisplayConfiguration) as usize] =
224            ResponseExpectedFlag::False;
225        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::GetDisplayConfiguration) as usize] =
226            ResponseExpectedFlag::AlwaysTrue;
227        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::WriteLine) as usize] = ResponseExpectedFlag::False;
228        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::DrawBufferedFrame) as usize] = ResponseExpectedFlag::False;
229        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::GetSpitfpErrorCount) as usize] =
230            ResponseExpectedFlag::AlwaysTrue;
231        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::SetBootloaderMode) as usize] =
232            ResponseExpectedFlag::AlwaysTrue;
233        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::GetBootloaderMode) as usize] =
234            ResponseExpectedFlag::AlwaysTrue;
235        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::SetWriteFirmwarePointer) as usize] =
236            ResponseExpectedFlag::False;
237        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
238        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
239        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::GetStatusLedConfig) as usize] =
240            ResponseExpectedFlag::AlwaysTrue;
241        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::GetChipTemperature) as usize] =
242            ResponseExpectedFlag::AlwaysTrue;
243        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
244        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
245        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
246        result.device.response_expected[u8::from(Oled128x64V2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
247        result
248    }
249
250    /// Returns the response expected flag for the function specified by the function ID parameter.
251    /// It is true if the function is expected to send a response, false otherwise.
252    ///
253    /// For getter functions this is enabled by default and cannot be disabled, because those
254    /// functions will always send a response. For callback configuration functions it is enabled
255    /// by default too, but can be disabled by [`set_response_expected`](crate::oled_128x64_v2_bricklet::Oled128x64V2Bricklet::set_response_expected).
256    /// For setter functions it is disabled by default and can be enabled.
257    ///
258    /// Enabling the response expected flag for a setter function allows to detect timeouts
259    /// and other error conditions calls of this setter as well. The device will then send a response
260    /// for this purpose. If this flag is disabled for a setter function then no response is sent
261    /// and errors are silently ignored, because they cannot be detected.
262    ///
263    /// See [`set_response_expected`](crate::oled_128x64_v2_bricklet::Oled128x64V2Bricklet::set_response_expected) for the list of function ID constants available for this function.
264    pub fn get_response_expected(&mut self, fun: Oled128x64V2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
265        self.device.get_response_expected(u8::from(fun))
266    }
267
268    /// Changes the response expected flag of the function specified by the function ID parameter.
269    /// This flag can only be changed for setter (default value: false) and callback configuration
270    /// functions (default value: true). For getter functions it is always enabled.
271    ///
272    /// Enabling the response expected flag for a setter function allows to detect timeouts and
273    /// other error conditions calls of this setter as well. The device will then send a response
274    /// for this purpose. If this flag is disabled for a setter function then no response is sent
275    /// and errors are silently ignored, because they cannot be detected.
276    pub fn set_response_expected(
277        &mut self,
278        fun: Oled128x64V2BrickletFunction,
279        response_expected: bool,
280    ) -> Result<(), SetResponseExpectedError> {
281        self.device.set_response_expected(u8::from(fun), response_expected)
282    }
283
284    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
285    pub fn set_response_expected_all(&mut self, response_expected: bool) {
286        self.device.set_response_expected_all(response_expected)
287    }
288
289    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
290    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
291    pub fn get_api_version(&self) -> [u8; 3] {
292        self.device.api_version
293    }
294
295    /// Writes pixels to the specified window.
296    ///
297    /// The pixels are written into the window line by line top to bottom
298    /// and each line is written from left to right.
299    ///
300    /// If automatic draw is enabled (default) the pixels are directly written to
301    /// the screen. Only pixels that have actually changed are updated on the screen,
302    /// the rest stays the same.
303    ///
304    /// If automatic draw is disabled the pixels are written to an internal buffer and
305    /// the buffer is transferred to the display only after [`draw_buffered_frame`]
306    /// is called. This can be used to avoid flicker when drawing a complex frame in
307    /// multiple steps.
308    ///
309    /// Automatic draw can be configured with the [`set_display_configuration`]
310    /// function.
311    ///
312    /// [`set_display_configuration`]: #method.set_display_configuration
313    /// [`draw_buffered_frame`]: #method.draw_buffered_frame
314    pub async fn write_pixels_low_level(
315        &mut self,
316        x_start: u8,
317        y_start: u8,
318        x_end: u8,
319        y_end: u8,
320        pixels_length: u16,
321        pixels_chunk_offset: u16,
322        pixels_chunk_data: &[bool; 448],
323    ) -> Result<WritePixelsLowLevel, TinkerforgeError> {
324        let mut payload = [0; 64];
325        x_start.write_to_slice(&mut payload[0..1]);
326        y_start.write_to_slice(&mut payload[1..2]);
327        x_end.write_to_slice(&mut payload[2..3]);
328        y_end.write_to_slice(&mut payload[3..4]);
329        pixels_length.write_to_slice(&mut payload[4..6]);
330        pixels_chunk_offset.write_to_slice(&mut payload[6..8]);
331        pixels_chunk_data.write_to_slice(&mut payload[8..64]);
332
333        #[allow(unused_variables)]
334        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::WritePixelsLowLevel), &payload).await?.unwrap();
335        Ok(WritePixelsLowLevel::from_le_byte_slice(result.body()))
336    }
337
338    /// Reads pixels from the specified window.
339    ///
340    /// The pixels are read from the window line by line top to bottom
341    /// and each line is read from left to right.
342    ///
343    /// If automatic draw is enabled (default) the pixels that are read are always the
344    /// same that are shown on the display.
345    ///
346    /// If automatic draw is disabled the pixels are read from the internal buffer
347    /// (see [`draw_buffered_frame`]).
348    ///
349    /// Automatic draw can be configured with the [`set_display_configuration`]
350    /// function.
351    pub async fn read_pixels_low_level(
352        &mut self,
353        x_start: u8,
354        y_start: u8,
355        x_end: u8,
356        y_end: u8,
357    ) -> Result<ReadPixelsLowLevel, TinkerforgeError> {
358        let mut payload = [0; 4];
359        x_start.write_to_slice(&mut payload[0..1]);
360        y_start.write_to_slice(&mut payload[1..2]);
361        x_end.write_to_slice(&mut payload[2..3]);
362        y_end.write_to_slice(&mut payload[3..4]);
363
364        #[allow(unused_variables)]
365        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::ReadPixelsLowLevel), &payload).await?;
366        Ok(ReadPixelsLowLevel::from_le_byte_slice(result.body()))
367    }
368
369    /// Clears the complete content of the display.
370    ///
371    /// If automatic draw is enabled (default) the pixels are directly cleared.
372    ///
373    /// If automatic draw is disabled the the internal buffer is cleared and
374    /// the buffer is transferred to the display only after [`draw_buffered_frame`]
375    /// is called. This can be used to avoid flicker when drawing a complex frame in
376    /// multiple steps.
377    ///
378    /// Automatic draw can be configured with the [`set_display_configuration`]
379    /// function.
380    pub async fn clear_display(&mut self) -> Result<(), TinkerforgeError> {
381        let payload = [0; 0];
382
383        #[allow(unused_variables)]
384        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::ClearDisplay), &payload).await?;
385        Ok(())
386    }
387
388    /// Sets the configuration of the display.
389    ///
390    /// You can set a contrast value from 0 to 255 and you can invert the color
391    /// (white/black) of the display.
392    ///
393    /// If automatic draw is set to *true*, the display is automatically updated with every
394    /// call of [`write_pixels`] or [`write_line`]. If it is set to false, the
395    /// changes are written into an internal buffer and only shown on the display after
396    /// a call of [`draw_buffered_frame`].
397    pub async fn set_display_configuration(&mut self, contrast: u8, invert: bool, automatic_draw: bool) -> Result<(), TinkerforgeError> {
398        let mut payload = [0; 3];
399        contrast.write_to_slice(&mut payload[0..1]);
400        invert.write_to_slice(&mut payload[1..2]);
401        automatic_draw.write_to_slice(&mut payload[2..3]);
402
403        #[allow(unused_variables)]
404        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::SetDisplayConfiguration), &payload).await?;
405        Ok(())
406    }
407
408    /// Returns the configuration as set by [`set_display_configuration`].
409    pub async fn get_display_configuration(&mut self) -> Result<DisplayConfiguration, TinkerforgeError> {
410        let payload = [0; 0];
411
412        #[allow(unused_variables)]
413        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::GetDisplayConfiguration), &payload).await?;
414        Ok(DisplayConfiguration::from_le_byte_slice(result.body()))
415    }
416
417    /// Writes text to a specific line with a specific position.
418    /// The text can have a maximum of 22 characters.
419    ///
420    /// For example: (1, 10, Hello) will write *Hello* in the middle of the
421    /// second line of the display.
422    ///
423    /// The display uses a special 5x7 pixel charset. You can view the characters
424    /// of the charset in Brick Viewer.
425    ///
426    /// If automatic draw is enabled (default) the text is directly written to
427    /// the screen. Only pixels that have actually changed are updated on the screen,
428    /// the rest stays the same.
429    ///
430    /// If automatic draw is disabled the text is written to an internal buffer and
431    /// the buffer is transferred to the display only after [`draw_buffered_frame`]
432    /// is called. This can be used to avoid flicker when drawing a complex frame in
433    /// multiple steps.
434    ///
435    /// Automatic draw can be configured with the [`set_display_configuration`]
436    /// function.
437    ///
438    /// The font conforms to code page 437.
439    pub async fn write_line(&mut self, line: u8, position: u8, text: String) -> Result<(), TinkerforgeError> {
440        let mut payload = [0; 24];
441        line.write_to_slice(&mut payload[0..1]);
442        position.write_to_slice(&mut payload[1..2]);
443        text.try_write_to_slice(22, &mut payload)?;
444
445        #[allow(unused_variables)]
446        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::WriteLine), &payload).await?;
447        Ok(())
448    }
449
450    /// Draws the currently buffered frame. Normally each call of [`write_pixels`] and
451    /// [`write_line`] draws directly onto the display. If you turn automatic draw off
452    /// ([`set_display_configuration`]), the data is written in an internal buffer and
453    /// only transferred to the display by calling this function. This can be used to
454    /// avoid flicker when drawing a complex frame in multiple steps.
455    ///
456    /// Set the `force complete redraw` to *true* to redraw the whole display
457    /// instead of only the changed parts. Normally it should not be necessary to set this to
458    /// *true*. It may only become necessary in case of stuck pixels because of errors.
459    pub async fn draw_buffered_frame(&mut self, force_complete_redraw: bool) -> Result<(), TinkerforgeError> {
460        let mut payload = [0; 1];
461        force_complete_redraw.write_to_slice(&mut payload[0..1]);
462
463        #[allow(unused_variables)]
464        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::DrawBufferedFrame), &payload).await?;
465        Ok(())
466    }
467
468    /// Returns the error count for the communication between Brick and Bricklet.
469    ///
470    /// The errors are divided into
471    ///
472    /// * ACK checksum errors,
473    /// * message checksum errors,
474    /// * framing errors and
475    /// * overflow errors.
476    ///
477    /// The errors counts are for errors that occur on the Bricklet side. All
478    /// Bricks have a similar function that returns the errors on the Brick side.
479    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
480        let payload = [0; 0];
481
482        #[allow(unused_variables)]
483        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
484        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
485    }
486
487    /// Sets the bootloader mode and returns the status after the requested
488    /// mode change was instigated.
489    ///
490    /// You can change from bootloader mode to firmware mode and vice versa. A change
491    /// from bootloader mode to firmware mode will only take place if the entry function,
492    /// device identifier and CRC are present and correct.
493    ///
494    /// This function is used by Brick Viewer during flashing. It should not be
495    /// necessary to call it in a normal user program.
496    ///
497    /// Associated constants:
498    /// * OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
499    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
500    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
501    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
502    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
503    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_OK
504    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
505    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
506    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
507    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
508    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
509    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
510        let mut payload = [0; 1];
511        mode.write_to_slice(&mut payload[0..1]);
512
513        #[allow(unused_variables)]
514        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::SetBootloaderMode), &payload).await?;
515        Ok(u8::from_le_byte_slice(result.body()))
516    }
517
518    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
519    ///
520    /// Associated constants:
521    /// * OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
522    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
523    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
524    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
525    ///	* OLED_128X64_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
526    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
527        let payload = [0; 0];
528
529        #[allow(unused_variables)]
530        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::GetBootloaderMode), &payload).await?;
531        Ok(u8::from_le_byte_slice(result.body()))
532    }
533
534    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
535    /// to be increased by chunks of size 64. The data is written to flash
536    /// every 4 chunks (which equals to one page of size 256).
537    ///
538    /// This function is used by Brick Viewer during flashing. It should not be
539    /// necessary to call it in a normal user program.
540    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
541        let mut payload = [0; 4];
542        pointer.write_to_slice(&mut payload[0..4]);
543
544        #[allow(unused_variables)]
545        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
546        Ok(())
547    }
548
549    /// Writes 64 Bytes of firmware at the position as written by
550    /// [`set_write_firmware_pointer`] before. The firmware is written
551    /// to flash every 4 chunks.
552    ///
553    /// You can only write firmware in bootloader mode.
554    ///
555    /// This function is used by Brick Viewer during flashing. It should not be
556    /// necessary to call it in a normal user program.
557    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
558        let mut payload = [0; 64];
559        data.write_to_slice(&mut payload[0..64]);
560
561        #[allow(unused_variables)]
562        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::WriteFirmware), &payload).await?;
563        Ok(u8::from_le_byte_slice(result.body()))
564    }
565
566    /// Sets the status LED configuration. By default the LED shows
567    /// communication traffic between Brick and Bricklet, it flickers once
568    /// for every 10 received data packets.
569    ///
570    /// You can also turn the LED permanently on/off or show a heartbeat.
571    ///
572    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
573    ///
574    /// Associated constants:
575    /// * OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_OFF
576    ///	* OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_ON
577    ///	* OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
578    ///	* OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
579    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
580        let mut payload = [0; 1];
581        config.write_to_slice(&mut payload[0..1]);
582
583        #[allow(unused_variables)]
584        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::SetStatusLedConfig), &payload).await?;
585        Ok(())
586    }
587
588    /// Returns the configuration as set by [`set_status_led_config`]
589    ///
590    /// Associated constants:
591    /// * OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_OFF
592    ///	* OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_ON
593    ///	* OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
594    ///	* OLED_128X64_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
595    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
596        let payload = [0; 0];
597
598        #[allow(unused_variables)]
599        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::GetStatusLedConfig), &payload).await?;
600        Ok(u8::from_le_byte_slice(result.body()))
601    }
602
603    /// Returns the temperature as measured inside the microcontroller. The
604    /// value returned is not the ambient temperature!
605    ///
606    /// The temperature is only proportional to the real temperature and it has bad
607    /// accuracy. Practically it is only useful as an indicator for
608    /// temperature changes.
609    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
610        let payload = [0; 0];
611
612        #[allow(unused_variables)]
613        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::GetChipTemperature), &payload).await?;
614        Ok(i16::from_le_byte_slice(result.body()))
615    }
616
617    /// Calling this function will reset the Bricklet. All configurations
618    /// will be lost.
619    ///
620    /// After a reset you have to create new device objects,
621    /// calling functions on the existing ones will result in
622    /// undefined behavior!
623    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
624        let payload = [0; 0];
625
626        #[allow(unused_variables)]
627        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::Reset), &payload).await?;
628        Ok(())
629    }
630
631    /// Writes a new UID into flash. If you want to set a new UID
632    /// you have to decode the Base58 encoded UID string into an
633    /// integer first.
634    ///
635    /// We recommend that you use Brick Viewer to change the UID.
636    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
637        let mut payload = [0; 4];
638        uid.write_to_slice(&mut payload[0..4]);
639
640        #[allow(unused_variables)]
641        let result = self.device.set(u8::from(Oled128x64V2BrickletFunction::WriteUid), &payload).await?;
642        Ok(())
643    }
644
645    /// Returns the current UID as an integer. Encode as
646    /// Base58 to get the usual string version.
647    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
648        let payload = [0; 0];
649
650        #[allow(unused_variables)]
651        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::ReadUid), &payload).await?;
652        Ok(u32::from_le_byte_slice(result.body()))
653    }
654
655    /// Returns the UID, the UID where the Bricklet is connected to,
656    /// the position, the hardware and firmware version as well as the
657    /// device identifier.
658    ///
659    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
660    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
661    /// position 'z'.
662    ///
663    /// The device identifier numbers can be found [here](device_identifier).
664    /// |device_identifier_constant|
665    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
666        let payload = [0; 0];
667
668        #[allow(unused_variables)]
669        let result = self.device.get(u8::from(Oled128x64V2BrickletFunction::GetIdentity), &payload).await?;
670        Ok(Identity::from_le_byte_slice(result.body()))
671    }
672}