tinkerforge_async/bindings/
segment_display_4x7_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//! Four 7-segment displays with switchable dots.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/SegmentDisplay4x7V2_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 SegmentDisplay4x7V2BrickletFunction {
24    SetSegments,
25    GetSegments,
26    SetBrightness,
27    GetBrightness,
28    SetNumericValue,
29    SetSelectedSegment,
30    GetSelectedSegment,
31    StartCounter,
32    GetCounterValue,
33    GetSpitfpErrorCount,
34    SetBootloaderMode,
35    GetBootloaderMode,
36    SetWriteFirmwarePointer,
37    WriteFirmware,
38    SetStatusLedConfig,
39    GetStatusLedConfig,
40    GetChipTemperature,
41    Reset,
42    WriteUid,
43    ReadUid,
44    GetIdentity,
45    CallbackCounterFinished,
46}
47impl From<SegmentDisplay4x7V2BrickletFunction> for u8 {
48    fn from(fun: SegmentDisplay4x7V2BrickletFunction) -> Self {
49        match fun {
50            SegmentDisplay4x7V2BrickletFunction::SetSegments => 1,
51            SegmentDisplay4x7V2BrickletFunction::GetSegments => 2,
52            SegmentDisplay4x7V2BrickletFunction::SetBrightness => 3,
53            SegmentDisplay4x7V2BrickletFunction::GetBrightness => 4,
54            SegmentDisplay4x7V2BrickletFunction::SetNumericValue => 5,
55            SegmentDisplay4x7V2BrickletFunction::SetSelectedSegment => 6,
56            SegmentDisplay4x7V2BrickletFunction::GetSelectedSegment => 7,
57            SegmentDisplay4x7V2BrickletFunction::StartCounter => 8,
58            SegmentDisplay4x7V2BrickletFunction::GetCounterValue => 9,
59            SegmentDisplay4x7V2BrickletFunction::GetSpitfpErrorCount => 234,
60            SegmentDisplay4x7V2BrickletFunction::SetBootloaderMode => 235,
61            SegmentDisplay4x7V2BrickletFunction::GetBootloaderMode => 236,
62            SegmentDisplay4x7V2BrickletFunction::SetWriteFirmwarePointer => 237,
63            SegmentDisplay4x7V2BrickletFunction::WriteFirmware => 238,
64            SegmentDisplay4x7V2BrickletFunction::SetStatusLedConfig => 239,
65            SegmentDisplay4x7V2BrickletFunction::GetStatusLedConfig => 240,
66            SegmentDisplay4x7V2BrickletFunction::GetChipTemperature => 242,
67            SegmentDisplay4x7V2BrickletFunction::Reset => 243,
68            SegmentDisplay4x7V2BrickletFunction::WriteUid => 248,
69            SegmentDisplay4x7V2BrickletFunction::ReadUid => 249,
70            SegmentDisplay4x7V2BrickletFunction::GetIdentity => 255,
71            SegmentDisplay4x7V2BrickletFunction::CallbackCounterFinished => 10,
72        }
73    }
74}
75pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
76pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
77pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
78pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
79pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
80pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
81pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
82pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
83pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
84pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
85pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
86pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
87pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
88pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
89pub const SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
90
91#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
92pub struct Segments {
93    pub digit0: [bool; 8],
94    pub digit1: [bool; 8],
95    pub digit2: [bool; 8],
96    pub digit3: [bool; 8],
97    pub colon: [bool; 2],
98    pub tick: bool,
99}
100impl FromByteSlice for Segments {
101    fn bytes_expected() -> usize {
102        6
103    }
104    fn from_le_byte_slice(bytes: &[u8]) -> Segments {
105        Segments {
106            digit0: <[bool; 8]>::from_le_byte_slice(&bytes[0..1]),
107            digit1: <[bool; 8]>::from_le_byte_slice(&bytes[1..2]),
108            digit2: <[bool; 8]>::from_le_byte_slice(&bytes[2..3]),
109            digit3: <[bool; 8]>::from_le_byte_slice(&bytes[3..4]),
110            colon: <[bool; 2]>::from_le_byte_slice(&bytes[4..5]),
111            tick: <bool>::from_le_byte_slice(&bytes[5..6]),
112        }
113    }
114}
115
116#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
117pub struct SpitfpErrorCount {
118    pub error_count_ack_checksum: u32,
119    pub error_count_message_checksum: u32,
120    pub error_count_frame: u32,
121    pub error_count_overflow: u32,
122}
123impl FromByteSlice for SpitfpErrorCount {
124    fn bytes_expected() -> usize {
125        16
126    }
127    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
128        SpitfpErrorCount {
129            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
130            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
131            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
132            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
133        }
134    }
135}
136
137#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
138pub struct Identity {
139    pub uid: String,
140    pub connected_uid: String,
141    pub position: char,
142    pub hardware_version: [u8; 3],
143    pub firmware_version: [u8; 3],
144    pub device_identifier: u16,
145}
146impl FromByteSlice for Identity {
147    fn bytes_expected() -> usize {
148        25
149    }
150    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
151        Identity {
152            uid: <String>::from_le_byte_slice(&bytes[0..8]),
153            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
154            position: <char>::from_le_byte_slice(&bytes[16..17]),
155            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
156            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
157            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
158        }
159    }
160}
161
162/// Four 7-segment displays with switchable dots
163#[derive(Clone)]
164pub struct SegmentDisplay4x7V2Bricklet {
165    device: Device,
166}
167impl SegmentDisplay4x7V2Bricklet {
168    pub const DEVICE_IDENTIFIER: u16 = 2137;
169    pub const DEVICE_DISPLAY_NAME: &'static str = "Segment Display 4x7 Bricklet 2.0";
170    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
171    pub fn new(uid: Uid, connection: AsyncIpConnection) -> SegmentDisplay4x7V2Bricklet {
172        let mut result = SegmentDisplay4x7V2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
173        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::SetSegments) as usize] = ResponseExpectedFlag::False;
174        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetSegments) as usize] =
175            ResponseExpectedFlag::AlwaysTrue;
176        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::SetBrightness) as usize] =
177            ResponseExpectedFlag::False;
178        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetBrightness) as usize] =
179            ResponseExpectedFlag::AlwaysTrue;
180        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::SetNumericValue) as usize] =
181            ResponseExpectedFlag::False;
182        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::SetSelectedSegment) as usize] =
183            ResponseExpectedFlag::False;
184        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetSelectedSegment) as usize] =
185            ResponseExpectedFlag::AlwaysTrue;
186        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::StartCounter) as usize] = ResponseExpectedFlag::False;
187        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetCounterValue) as usize] =
188            ResponseExpectedFlag::AlwaysTrue;
189        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetSpitfpErrorCount) as usize] =
190            ResponseExpectedFlag::AlwaysTrue;
191        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::SetBootloaderMode) as usize] =
192            ResponseExpectedFlag::AlwaysTrue;
193        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetBootloaderMode) as usize] =
194            ResponseExpectedFlag::AlwaysTrue;
195        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::SetWriteFirmwarePointer) as usize] =
196            ResponseExpectedFlag::False;
197        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::WriteFirmware) as usize] =
198            ResponseExpectedFlag::AlwaysTrue;
199        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::SetStatusLedConfig) as usize] =
200            ResponseExpectedFlag::False;
201        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetStatusLedConfig) as usize] =
202            ResponseExpectedFlag::AlwaysTrue;
203        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetChipTemperature) as usize] =
204            ResponseExpectedFlag::AlwaysTrue;
205        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
206        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
207        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
208        result.device.response_expected[u8::from(SegmentDisplay4x7V2BrickletFunction::GetIdentity) as usize] =
209            ResponseExpectedFlag::AlwaysTrue;
210        result
211    }
212
213    /// Returns the response expected flag for the function specified by the function ID parameter.
214    /// It is true if the function is expected to send a response, false otherwise.
215    ///
216    /// For getter functions this is enabled by default and cannot be disabled, because those
217    /// functions will always send a response. For callback configuration functions it is enabled
218    /// by default too, but can be disabled by [`set_response_expected`](crate::segment_display_4x7_v2_bricklet::SegmentDisplay4x7V2Bricklet::set_response_expected).
219    /// For setter functions it is disabled by default and can be enabled.
220    ///
221    /// Enabling the response expected flag for a setter function allows to detect timeouts
222    /// and other error conditions calls of this setter as well. The device will then send a response
223    /// for this purpose. If this flag is disabled for a setter function then no response is sent
224    /// and errors are silently ignored, because they cannot be detected.
225    ///
226    /// See [`set_response_expected`](crate::segment_display_4x7_v2_bricklet::SegmentDisplay4x7V2Bricklet::set_response_expected) for the list of function ID constants available for this function.
227    pub fn get_response_expected(&mut self, fun: SegmentDisplay4x7V2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
228        self.device.get_response_expected(u8::from(fun))
229    }
230
231    /// Changes the response expected flag of the function specified by the function ID parameter.
232    /// This flag can only be changed for setter (default value: false) and callback configuration
233    /// functions (default value: true). For getter functions it is always enabled.
234    ///
235    /// Enabling the response expected flag for a setter function allows to detect timeouts and
236    /// other error conditions calls of this setter as well. The device will then send a response
237    /// for this purpose. If this flag is disabled for a setter function then no response is sent
238    /// and errors are silently ignored, because they cannot be detected.
239    pub fn set_response_expected(
240        &mut self,
241        fun: SegmentDisplay4x7V2BrickletFunction,
242        response_expected: bool,
243    ) -> Result<(), SetResponseExpectedError> {
244        self.device.set_response_expected(u8::from(fun), response_expected)
245    }
246
247    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
248    pub fn set_response_expected_all(&mut self, response_expected: bool) {
249        self.device.set_response_expected_all(response_expected)
250    }
251
252    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
253    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
254    pub fn get_api_version(&self) -> [u8; 3] {
255        self.device.api_version
256    }
257
258    /// This receiver is triggered when the counter (see [`start_counter`]) is
259    /// finished.
260    ///
261    /// [`start_counter`]: #method.start_counter
262    pub async fn get_counter_finished_callback_receiver(&mut self) -> impl Stream<Item = ()> {
263        self.device.get_callback_receiver(u8::from(SegmentDisplay4x7V2BrickletFunction::CallbackCounterFinished)).await.map(|_p| ())
264    }
265
266    /// Sets the segments of the Segment Display 4x7 Bricklet 2.0 segment-by-segment.
267    ///
268    /// The data is split into the four digits, two colon dots and the tick mark.
269    ///
270    /// The indices of the segments in the digit and colon parameters are as follows:
271    ///
272    /// .. image:: /Images/Bricklets/bricklet_segment_display_4x7_v2_segment_index.png
273    ///    :scale: 100 %
274    ///    :alt: Indices of segments
275    ///    :align: center
276    pub async fn set_segments(
277        &mut self,
278        digit0: &[bool; 8],
279        digit1: &[bool; 8],
280        digit2: &[bool; 8],
281        digit3: &[bool; 8],
282        colon: &[bool; 2],
283        tick: bool,
284    ) -> Result<(), TinkerforgeError> {
285        let mut payload = [0; 6];
286        digit0.write_to_slice(&mut payload[0..1]);
287        digit1.write_to_slice(&mut payload[1..2]);
288        digit2.write_to_slice(&mut payload[2..3]);
289        digit3.write_to_slice(&mut payload[3..4]);
290        colon.write_to_slice(&mut payload[4..5]);
291        tick.write_to_slice(&mut payload[5..6]);
292
293        #[allow(unused_variables)]
294        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::SetSegments), &payload).await?;
295        Ok(())
296    }
297
298    /// Returns the segment data as set by [`set_segments`].
299    pub async fn get_segments(&mut self) -> Result<Segments, TinkerforgeError> {
300        let payload = [0; 0];
301
302        #[allow(unused_variables)]
303        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetSegments), &payload).await?;
304        Ok(Segments::from_le_byte_slice(result.body()))
305    }
306
307    /// The brightness can be set between 0 (dark) and 7 (bright).
308    pub async fn set_brightness(&mut self, brightness: u8) -> Result<(), TinkerforgeError> {
309        let mut payload = [0; 1];
310        brightness.write_to_slice(&mut payload[0..1]);
311
312        #[allow(unused_variables)]
313        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::SetBrightness), &payload).await?;
314        Ok(())
315    }
316
317    /// Returns the brightness as set by [`set_brightness`].
318    pub async fn get_brightness(&mut self) -> Result<u8, TinkerforgeError> {
319        let payload = [0; 0];
320
321        #[allow(unused_variables)]
322        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetBrightness), &payload).await?;
323        Ok(u8::from_le_byte_slice(result.body()))
324    }
325
326    /// Sets a numeric value for each of the digits. They represent:
327    ///
328    /// * -2: minus sign
329    /// * -1: blank
330    /// * 0-9: 0-9
331    /// * 10: A
332    /// * 11: b
333    /// * 12: C
334    /// * 13: d
335    /// * 14: E
336    /// * 15: F
337    ///
338    /// Example: A call with [-2, -1, 4, 2] will result in a display of - 42.
339    pub async fn set_numeric_value(&mut self, value: &[i8; 4]) -> Result<(), TinkerforgeError> {
340        let mut payload = [0; 4];
341        value.write_to_slice(&mut payload[0..4]);
342
343        #[allow(unused_variables)]
344        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::SetNumericValue), &payload).await?;
345        Ok(())
346    }
347
348    /// Turns one specified segment on or off.
349    ///
350    /// The indices of the segments are as follows:
351    ///
352    /// .. image:: /Images/Bricklets/bricklet_segment_display_4x7_v2_selected_segment_index.png
353    ///    :scale: 100 %
354    ///    :alt: Indices of selected segments
355    ///    :align: center
356    pub async fn set_selected_segment(&mut self, segment: u8, value: bool) -> Result<(), TinkerforgeError> {
357        let mut payload = [0; 2];
358        segment.write_to_slice(&mut payload[0..1]);
359        value.write_to_slice(&mut payload[1..2]);
360
361        #[allow(unused_variables)]
362        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::SetSelectedSegment), &payload).await?;
363        Ok(())
364    }
365
366    /// Returns the value of a single segment.
367    pub async fn get_selected_segment(&mut self, segment: u8) -> Result<bool, TinkerforgeError> {
368        let mut payload = [0; 1];
369        segment.write_to_slice(&mut payload[0..1]);
370
371        #[allow(unused_variables)]
372        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetSelectedSegment), &payload).await?;
373        Ok(bool::from_le_byte_slice(result.body()))
374    }
375
376    /// Starts a counter with the *from* value that counts to the *to*
377    /// value with the each step incremented by *increment*.
378    /// *length* is the pause between each increment.
379    ///
380    /// Example: If you set *from* to 0, *to* to 100, *increment* to 1 and
381    /// *length* to 1000, a counter that goes from 0 to 100 with one second
382    /// pause between each increment will be started.
383    ///
384    /// Using a negative *increment* allows to count backwards.
385    ///
386    /// You can stop the counter at every time by calling [`set_segments`]
387    /// or [`set_numeric_value`].
388    pub async fn start_counter(&mut self, value_from: i16, value_to: i16, increment: i16, length: u32) -> Result<(), TinkerforgeError> {
389        let mut payload = [0; 10];
390        value_from.write_to_slice(&mut payload[0..2]);
391        value_to.write_to_slice(&mut payload[2..4]);
392        increment.write_to_slice(&mut payload[4..6]);
393        length.write_to_slice(&mut payload[6..10]);
394
395        #[allow(unused_variables)]
396        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::StartCounter), &payload).await?;
397        Ok(())
398    }
399
400    /// Returns the counter value that is currently shown on the display.
401    ///
402    /// If there is no counter running a 0 will be returned.
403    pub async fn get_counter_value(&mut self) -> Result<u16, TinkerforgeError> {
404        let payload = [0; 0];
405
406        #[allow(unused_variables)]
407        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetCounterValue), &payload).await?;
408        Ok(u16::from_le_byte_slice(result.body()))
409    }
410
411    /// Returns the error count for the communication between Brick and Bricklet.
412    ///
413    /// The errors are divided into
414    ///
415    /// * ACK checksum errors,
416    /// * message checksum errors,
417    /// * framing errors and
418    /// * overflow errors.
419    ///
420    /// The errors counts are for errors that occur on the Bricklet side. All
421    /// Bricks have a similar function that returns the errors on the Brick side.
422    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
423        let payload = [0; 0];
424
425        #[allow(unused_variables)]
426        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
427        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
428    }
429
430    /// Sets the bootloader mode and returns the status after the requested
431    /// mode change was instigated.
432    ///
433    /// You can change from bootloader mode to firmware mode and vice versa. A change
434    /// from bootloader mode to firmware mode will only take place if the entry function,
435    /// device identifier and CRC are present and correct.
436    ///
437    /// This function is used by Brick Viewer during flashing. It should not be
438    /// necessary to call it in a normal user program.
439    ///
440    /// Associated constants:
441    /// * SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
442    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
443    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
444    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
445    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
446    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_OK
447    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
448    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
449    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
450    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
451    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
452    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
453        let mut payload = [0; 1];
454        mode.write_to_slice(&mut payload[0..1]);
455
456        #[allow(unused_variables)]
457        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::SetBootloaderMode), &payload).await?;
458        Ok(u8::from_le_byte_slice(result.body()))
459    }
460
461    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
462    ///
463    /// Associated constants:
464    /// * SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
465    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
466    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
467    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
468    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
469    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
470        let payload = [0; 0];
471
472        #[allow(unused_variables)]
473        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetBootloaderMode), &payload).await?;
474        Ok(u8::from_le_byte_slice(result.body()))
475    }
476
477    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
478    /// to be increased by chunks of size 64. The data is written to flash
479    /// every 4 chunks (which equals to one page of size 256).
480    ///
481    /// This function is used by Brick Viewer during flashing. It should not be
482    /// necessary to call it in a normal user program.
483    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
484        let mut payload = [0; 4];
485        pointer.write_to_slice(&mut payload[0..4]);
486
487        #[allow(unused_variables)]
488        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
489        Ok(())
490    }
491
492    /// Writes 64 Bytes of firmware at the position as written by
493    /// [`set_write_firmware_pointer`] before. The firmware is written
494    /// to flash every 4 chunks.
495    ///
496    /// You can only write firmware in bootloader mode.
497    ///
498    /// This function is used by Brick Viewer during flashing. It should not be
499    /// necessary to call it in a normal user program.
500    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
501        let mut payload = [0; 64];
502        data.write_to_slice(&mut payload[0..64]);
503
504        #[allow(unused_variables)]
505        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::WriteFirmware), &payload).await?;
506        Ok(u8::from_le_byte_slice(result.body()))
507    }
508
509    /// Sets the status LED configuration. By default the LED shows
510    /// communication traffic between Brick and Bricklet, it flickers once
511    /// for every 10 received data packets.
512    ///
513    /// You can also turn the LED permanently on/off or show a heartbeat.
514    ///
515    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
516    ///
517    /// Associated constants:
518    /// * SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_OFF
519    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_ON
520    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
521    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
522    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
523        let mut payload = [0; 1];
524        config.write_to_slice(&mut payload[0..1]);
525
526        #[allow(unused_variables)]
527        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::SetStatusLedConfig), &payload).await?;
528        Ok(())
529    }
530
531    /// Returns the configuration as set by [`set_status_led_config`]
532    ///
533    /// Associated constants:
534    /// * SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_OFF
535    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_ON
536    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
537    ///	* SEGMENT_DISPLAY_4X7_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
538    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
539        let payload = [0; 0];
540
541        #[allow(unused_variables)]
542        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetStatusLedConfig), &payload).await?;
543        Ok(u8::from_le_byte_slice(result.body()))
544    }
545
546    /// Returns the temperature as measured inside the microcontroller. The
547    /// value returned is not the ambient temperature!
548    ///
549    /// The temperature is only proportional to the real temperature and it has bad
550    /// accuracy. Practically it is only useful as an indicator for
551    /// temperature changes.
552    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
553        let payload = [0; 0];
554
555        #[allow(unused_variables)]
556        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetChipTemperature), &payload).await?;
557        Ok(i16::from_le_byte_slice(result.body()))
558    }
559
560    /// Calling this function will reset the Bricklet. All configurations
561    /// will be lost.
562    ///
563    /// After a reset you have to create new device objects,
564    /// calling functions on the existing ones will result in
565    /// undefined behavior!
566    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
567        let payload = [0; 0];
568
569        #[allow(unused_variables)]
570        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::Reset), &payload).await?;
571        Ok(())
572    }
573
574    /// Writes a new UID into flash. If you want to set a new UID
575    /// you have to decode the Base58 encoded UID string into an
576    /// integer first.
577    ///
578    /// We recommend that you use Brick Viewer to change the UID.
579    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
580        let mut payload = [0; 4];
581        uid.write_to_slice(&mut payload[0..4]);
582
583        #[allow(unused_variables)]
584        let result = self.device.set(u8::from(SegmentDisplay4x7V2BrickletFunction::WriteUid), &payload).await?;
585        Ok(())
586    }
587
588    /// Returns the current UID as an integer. Encode as
589    /// Base58 to get the usual string version.
590    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
591        let payload = [0; 0];
592
593        #[allow(unused_variables)]
594        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::ReadUid), &payload).await?;
595        Ok(u32::from_le_byte_slice(result.body()))
596    }
597
598    /// Returns the UID, the UID where the Bricklet is connected to,
599    /// the position, the hardware and firmware version as well as the
600    /// device identifier.
601    ///
602    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
603    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
604    /// position 'z'.
605    ///
606    /// The device identifier numbers can be found [here](device_identifier).
607    /// |device_identifier_constant|
608    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
609        let payload = [0; 0];
610
611        #[allow(unused_variables)]
612        let result = self.device.get(u8::from(SegmentDisplay4x7V2BrickletFunction::GetIdentity), &payload).await?;
613        Ok(Identity::from_le_byte_slice(result.body()))
614    }
615}