tinkerforge_async/bindings/
one_wire_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//! Communicates with up 64 1-Wire devices.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/OneWire_Bricklet_Rust.html).
14#[allow(unused_imports)]
15use crate::{
16    base58::Uid, byte_converter::*, converting_receiver::BrickletRecvTimeoutError, device::*, error::TinkerforgeError,
17    ip_connection::async_io::AsyncIpConnection, low_level_traits::LowLevelRead,
18};
19#[allow(unused_imports)]
20use futures_core::Stream;
21#[allow(unused_imports)]
22use tokio_stream::StreamExt;
23pub enum OneWireBrickletFunction {
24    SearchBusLowLevel,
25    ResetBus,
26    Write,
27    Read,
28    WriteCommand,
29    SetCommunicationLedConfig,
30    GetCommunicationLedConfig,
31    GetSpitfpErrorCount,
32    SetBootloaderMode,
33    GetBootloaderMode,
34    SetWriteFirmwarePointer,
35    WriteFirmware,
36    SetStatusLedConfig,
37    GetStatusLedConfig,
38    GetChipTemperature,
39    Reset,
40    WriteUid,
41    ReadUid,
42    GetIdentity,
43}
44impl From<OneWireBrickletFunction> for u8 {
45    fn from(fun: OneWireBrickletFunction) -> Self {
46        match fun {
47            OneWireBrickletFunction::SearchBusLowLevel => 1,
48            OneWireBrickletFunction::ResetBus => 2,
49            OneWireBrickletFunction::Write => 3,
50            OneWireBrickletFunction::Read => 4,
51            OneWireBrickletFunction::WriteCommand => 5,
52            OneWireBrickletFunction::SetCommunicationLedConfig => 6,
53            OneWireBrickletFunction::GetCommunicationLedConfig => 7,
54            OneWireBrickletFunction::GetSpitfpErrorCount => 234,
55            OneWireBrickletFunction::SetBootloaderMode => 235,
56            OneWireBrickletFunction::GetBootloaderMode => 236,
57            OneWireBrickletFunction::SetWriteFirmwarePointer => 237,
58            OneWireBrickletFunction::WriteFirmware => 238,
59            OneWireBrickletFunction::SetStatusLedConfig => 239,
60            OneWireBrickletFunction::GetStatusLedConfig => 240,
61            OneWireBrickletFunction::GetChipTemperature => 242,
62            OneWireBrickletFunction::Reset => 243,
63            OneWireBrickletFunction::WriteUid => 248,
64            OneWireBrickletFunction::ReadUid => 249,
65            OneWireBrickletFunction::GetIdentity => 255,
66        }
67    }
68}
69pub const ONE_WIRE_BRICKLET_STATUS_OK: u8 = 0;
70pub const ONE_WIRE_BRICKLET_STATUS_BUSY: u8 = 1;
71pub const ONE_WIRE_BRICKLET_STATUS_NO_PRESENCE: u8 = 2;
72pub const ONE_WIRE_BRICKLET_STATUS_TIMEOUT: u8 = 3;
73pub const ONE_WIRE_BRICKLET_STATUS_ERROR: u8 = 4;
74pub const ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_OFF: u8 = 0;
75pub const ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_ON: u8 = 1;
76pub const ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
77pub const ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION: u8 = 3;
78pub const ONE_WIRE_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
79pub const ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
80pub const ONE_WIRE_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
81pub const ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
82pub const ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
83pub const ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
84pub const ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
85pub const ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
86pub const ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
87pub const ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
88pub const ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
89pub const ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
90pub const ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
91pub const ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
92pub const ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
93
94#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
95pub struct SearchBusLowLevel {
96    pub identifier_length: u16,
97    pub identifier_chunk_offset: u16,
98    pub identifier_chunk_data: [u64; 7],
99    pub status: u8,
100}
101impl FromByteSlice for SearchBusLowLevel {
102    fn bytes_expected() -> usize {
103        61
104    }
105    fn from_le_byte_slice(bytes: &[u8]) -> SearchBusLowLevel {
106        SearchBusLowLevel {
107            identifier_length: <u16>::from_le_byte_slice(&bytes[0..2]),
108            identifier_chunk_offset: <u16>::from_le_byte_slice(&bytes[2..4]),
109            identifier_chunk_data: <[u64; 7]>::from_le_byte_slice(&bytes[4..60]),
110            status: <u8>::from_le_byte_slice(&bytes[60..61]),
111        }
112    }
113}
114impl LowLevelRead<u64, SearchBusResult> for SearchBusLowLevel {
115    fn ll_message_length(&self) -> usize {
116        self.identifier_length as usize
117    }
118
119    fn ll_message_chunk_offset(&self) -> usize {
120        self.identifier_chunk_offset as usize
121    }
122
123    fn ll_message_chunk_data(&self) -> &[u64] {
124        &self.identifier_chunk_data
125    }
126
127    fn get_result(&self) -> SearchBusResult {
128        SearchBusResult { status: self.status }
129    }
130}
131
132#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
133pub struct Read {
134    pub data: u8,
135    pub status: u8,
136}
137impl FromByteSlice for Read {
138    fn bytes_expected() -> usize {
139        2
140    }
141    fn from_le_byte_slice(bytes: &[u8]) -> Read {
142        Read { data: <u8>::from_le_byte_slice(&bytes[0..1]), status: <u8>::from_le_byte_slice(&bytes[1..2]) }
143    }
144}
145
146#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
147pub struct SpitfpErrorCount {
148    pub error_count_ack_checksum: u32,
149    pub error_count_message_checksum: u32,
150    pub error_count_frame: u32,
151    pub error_count_overflow: u32,
152}
153impl FromByteSlice for SpitfpErrorCount {
154    fn bytes_expected() -> usize {
155        16
156    }
157    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
158        SpitfpErrorCount {
159            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
160            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
161            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
162            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
163        }
164    }
165}
166
167#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
168pub struct Identity {
169    pub uid: String,
170    pub connected_uid: String,
171    pub position: char,
172    pub hardware_version: [u8; 3],
173    pub firmware_version: [u8; 3],
174    pub device_identifier: u16,
175}
176impl FromByteSlice for Identity {
177    fn bytes_expected() -> usize {
178        25
179    }
180    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
181        Identity {
182            uid: <String>::from_le_byte_slice(&bytes[0..8]),
183            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
184            position: <char>::from_le_byte_slice(&bytes[16..17]),
185            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
186            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
187            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
188        }
189    }
190}
191
192#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
193pub struct SearchBusResult {
194    pub status: u8,
195}
196
197/// Communicates with up 64 1-Wire devices
198#[derive(Clone)]
199pub struct OneWireBricklet {
200    device: Device,
201}
202impl OneWireBricklet {
203    pub const DEVICE_IDENTIFIER: u16 = 2123;
204    pub const DEVICE_DISPLAY_NAME: &'static str = "One Wire Bricklet";
205    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
206    pub fn new(uid: Uid, connection: AsyncIpConnection) -> OneWireBricklet {
207        let mut result = OneWireBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
208        result.device.response_expected[u8::from(OneWireBrickletFunction::SearchBusLowLevel) as usize] = ResponseExpectedFlag::AlwaysTrue;
209        result.device.response_expected[u8::from(OneWireBrickletFunction::ResetBus) as usize] = ResponseExpectedFlag::AlwaysTrue;
210        result.device.response_expected[u8::from(OneWireBrickletFunction::Write) as usize] = ResponseExpectedFlag::AlwaysTrue;
211        result.device.response_expected[u8::from(OneWireBrickletFunction::Read) as usize] = ResponseExpectedFlag::AlwaysTrue;
212        result.device.response_expected[u8::from(OneWireBrickletFunction::WriteCommand) as usize] = ResponseExpectedFlag::AlwaysTrue;
213        result.device.response_expected[u8::from(OneWireBrickletFunction::SetCommunicationLedConfig) as usize] =
214            ResponseExpectedFlag::False;
215        result.device.response_expected[u8::from(OneWireBrickletFunction::GetCommunicationLedConfig) as usize] =
216            ResponseExpectedFlag::AlwaysTrue;
217        result.device.response_expected[u8::from(OneWireBrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
218        result.device.response_expected[u8::from(OneWireBrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
219        result.device.response_expected[u8::from(OneWireBrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
220        result.device.response_expected[u8::from(OneWireBrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
221        result.device.response_expected[u8::from(OneWireBrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
222        result.device.response_expected[u8::from(OneWireBrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
223        result.device.response_expected[u8::from(OneWireBrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
224        result.device.response_expected[u8::from(OneWireBrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
225        result.device.response_expected[u8::from(OneWireBrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
226        result.device.response_expected[u8::from(OneWireBrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
227        result.device.response_expected[u8::from(OneWireBrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
228        result.device.response_expected[u8::from(OneWireBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
229        result
230    }
231
232    /// Returns the response expected flag for the function specified by the function ID parameter.
233    /// It is true if the function is expected to send a response, false otherwise.
234    ///
235    /// For getter functions this is enabled by default and cannot be disabled, because those
236    /// functions will always send a response. For callback configuration functions it is enabled
237    /// by default too, but can be disabled by [`set_response_expected`](crate::one_wire_bricklet::OneWireBricklet::set_response_expected).
238    /// For setter functions it is disabled by default and can be enabled.
239    ///
240    /// Enabling the response expected flag for a setter function allows to detect timeouts
241    /// and other error conditions calls of this setter as well. The device will then send a response
242    /// for this purpose. If this flag is disabled for a setter function then no response is sent
243    /// and errors are silently ignored, because they cannot be detected.
244    ///
245    /// See [`set_response_expected`](crate::one_wire_bricklet::OneWireBricklet::set_response_expected) for the list of function ID constants available for this function.
246    pub fn get_response_expected(&mut self, fun: OneWireBrickletFunction) -> Result<bool, GetResponseExpectedError> {
247        self.device.get_response_expected(u8::from(fun))
248    }
249
250    /// Changes the response expected flag of the function specified by the function ID parameter.
251    /// This flag can only be changed for setter (default value: false) and callback configuration
252    /// functions (default value: true). For getter functions it is always enabled.
253    ///
254    /// Enabling the response expected flag for a setter function allows to detect timeouts and
255    /// other error conditions calls of this setter as well. The device will then send a response
256    /// for this purpose. If this flag is disabled for a setter function then no response is sent
257    /// and errors are silently ignored, because they cannot be detected.
258    pub fn set_response_expected(&mut self, fun: OneWireBrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
259        self.device.set_response_expected(u8::from(fun), response_expected)
260    }
261
262    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
263    pub fn set_response_expected_all(&mut self, response_expected: bool) {
264        self.device.set_response_expected_all(response_expected)
265    }
266
267    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
268    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
269    pub fn get_api_version(&self) -> [u8; 3] {
270        self.device.api_version
271    }
272
273    /// Returns a list of up to 64 identifiers of the connected 1-Wire devices.
274    /// Each identifier is 64-bit and consists of 8-bit family code, 48-bit ID and
275    /// 8-bit CRC.
276    ///
277    /// To get these identifiers the Bricklet runs the
278    /// [SEARCH ROM algorithm](https://www.maximintegrated.com/en/app-notes/index.mvp/id/187)__,
279    /// as defined by Maxim.
280    ///
281    /// Associated constants:
282    /// * ONE_WIRE_BRICKLET_STATUS_OK
283    ///	* ONE_WIRE_BRICKLET_STATUS_BUSY
284    ///	* ONE_WIRE_BRICKLET_STATUS_NO_PRESENCE
285    ///	* ONE_WIRE_BRICKLET_STATUS_TIMEOUT
286    ///	* ONE_WIRE_BRICKLET_STATUS_ERROR
287    pub async fn search_bus_low_level(&mut self) -> Result<SearchBusLowLevel, TinkerforgeError> {
288        let payload = [0; 0];
289
290        #[allow(unused_variables)]
291        let result = self.device.get(u8::from(OneWireBrickletFunction::SearchBusLowLevel), &payload).await?;
292        Ok(SearchBusLowLevel::from_le_byte_slice(result.body()))
293    }
294
295    /// Resets the bus with the 1-Wire reset operation.
296    ///
297    /// Associated constants:
298    /// * ONE_WIRE_BRICKLET_STATUS_OK
299    ///	* ONE_WIRE_BRICKLET_STATUS_BUSY
300    ///	* ONE_WIRE_BRICKLET_STATUS_NO_PRESENCE
301    ///	* ONE_WIRE_BRICKLET_STATUS_TIMEOUT
302    ///	* ONE_WIRE_BRICKLET_STATUS_ERROR
303    pub async fn reset_bus(&mut self) -> Result<u8, TinkerforgeError> {
304        let payload = [0; 0];
305
306        #[allow(unused_variables)]
307        let result = self.device.get(u8::from(OneWireBrickletFunction::ResetBus), &payload).await?;
308        Ok(u8::from_le_byte_slice(result.body()))
309    }
310
311    /// Writes a byte of data to the 1-Wire bus.
312    ///
313    /// Associated constants:
314    /// * ONE_WIRE_BRICKLET_STATUS_OK
315    ///	* ONE_WIRE_BRICKLET_STATUS_BUSY
316    ///	* ONE_WIRE_BRICKLET_STATUS_NO_PRESENCE
317    ///	* ONE_WIRE_BRICKLET_STATUS_TIMEOUT
318    ///	* ONE_WIRE_BRICKLET_STATUS_ERROR
319    pub async fn write(&mut self, data: u8) -> Result<u8, TinkerforgeError> {
320        let mut payload = [0; 1];
321        data.write_to_slice(&mut payload[0..1]);
322
323        #[allow(unused_variables)]
324        let result = self.device.get(u8::from(OneWireBrickletFunction::Write), &payload).await?;
325        Ok(u8::from_le_byte_slice(result.body()))
326    }
327
328    /// Reads a byte of data from the 1-Wire bus.
329    ///
330    /// Associated constants:
331    /// * ONE_WIRE_BRICKLET_STATUS_OK
332    ///	* ONE_WIRE_BRICKLET_STATUS_BUSY
333    ///	* ONE_WIRE_BRICKLET_STATUS_NO_PRESENCE
334    ///	* ONE_WIRE_BRICKLET_STATUS_TIMEOUT
335    ///	* ONE_WIRE_BRICKLET_STATUS_ERROR
336    pub async fn read(&mut self) -> Result<Read, TinkerforgeError> {
337        let payload = [0; 0];
338
339        #[allow(unused_variables)]
340        let result = self.device.get(u8::from(OneWireBrickletFunction::Read), &payload).await?;
341        Ok(Read::from_le_byte_slice(result.body()))
342    }
343
344    /// Writes a command to the 1-Wire device with the given identifier. You can obtain
345    /// the identifier by calling [`search_bus`]. The MATCH ROM operation is used to
346    /// write the command.
347    ///
348    /// If you only have one device connected or want to broadcast to all devices
349    /// you can set the identifier to 0. In this case the SKIP ROM operation is used to
350    /// write the command.
351    ///
352    /// Associated constants:
353    /// * ONE_WIRE_BRICKLET_STATUS_OK
354    ///	* ONE_WIRE_BRICKLET_STATUS_BUSY
355    ///	* ONE_WIRE_BRICKLET_STATUS_NO_PRESENCE
356    ///	* ONE_WIRE_BRICKLET_STATUS_TIMEOUT
357    ///	* ONE_WIRE_BRICKLET_STATUS_ERROR
358    pub async fn write_command(&mut self, identifier: u64, command: u8) -> Result<u8, TinkerforgeError> {
359        let mut payload = [0; 9];
360        identifier.write_to_slice(&mut payload[0..8]);
361        command.write_to_slice(&mut payload[8..9]);
362
363        #[allow(unused_variables)]
364        let result = self.device.get(u8::from(OneWireBrickletFunction::WriteCommand), &payload).await?;
365        Ok(u8::from_le_byte_slice(result.body()))
366    }
367
368    /// Sets the communication LED configuration. By default the LED shows 1-wire
369    /// communication traffic by flickering.
370    ///
371    /// You can also turn the LED permanently on/off or show a heartbeat.
372    ///
373    /// If the Bricklet is in bootloader mode, the LED is off.
374    ///
375    /// Associated constants:
376    /// * ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_OFF
377    ///	* ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_ON
378    ///	* ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT
379    ///	* ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION
380    pub async fn set_communication_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
381        let mut payload = [0; 1];
382        config.write_to_slice(&mut payload[0..1]);
383
384        #[allow(unused_variables)]
385        let result = self.device.set(u8::from(OneWireBrickletFunction::SetCommunicationLedConfig), &payload).await?;
386        Ok(())
387    }
388
389    /// Returns the configuration as set by [`set_communication_led_config`]
390    ///
391    /// Associated constants:
392    /// * ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_OFF
393    ///	* ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_ON
394    ///	* ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_HEARTBEAT
395    ///	* ONE_WIRE_BRICKLET_COMMUNICATION_LED_CONFIG_SHOW_COMMUNICATION
396    pub async fn get_communication_led_config(&mut self) -> Result<u8, TinkerforgeError> {
397        let payload = [0; 0];
398
399        #[allow(unused_variables)]
400        let result = self.device.get(u8::from(OneWireBrickletFunction::GetCommunicationLedConfig), &payload).await?;
401        Ok(u8::from_le_byte_slice(result.body()))
402    }
403
404    /// Returns the error count for the communication between Brick and Bricklet.
405    ///
406    /// The errors are divided into
407    ///
408    /// * ACK checksum errors,
409    /// * message checksum errors,
410    /// * framing errors and
411    /// * overflow errors.
412    ///
413    /// The errors counts are for errors that occur on the Bricklet side. All
414    /// Bricks have a similar function that returns the errors on the Brick side.
415    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
416        let payload = [0; 0];
417
418        #[allow(unused_variables)]
419        let result = self.device.get(u8::from(OneWireBrickletFunction::GetSpitfpErrorCount), &payload).await?;
420        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
421    }
422
423    /// Sets the bootloader mode and returns the status after the requested
424    /// mode change was instigated.
425    ///
426    /// You can change from bootloader mode to firmware mode and vice versa. A change
427    /// from bootloader mode to firmware mode will only take place if the entry function,
428    /// device identifier and CRC are present and correct.
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    ///
433    /// Associated constants:
434    /// * ONE_WIRE_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
435    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE
436    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
437    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
438    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
439    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_OK
440    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
441    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
442    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
443    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
444    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
445    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
446        let mut payload = [0; 1];
447        mode.write_to_slice(&mut payload[0..1]);
448
449        #[allow(unused_variables)]
450        let result = self.device.get(u8::from(OneWireBrickletFunction::SetBootloaderMode), &payload).await?;
451        Ok(u8::from_le_byte_slice(result.body()))
452    }
453
454    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
455    ///
456    /// Associated constants:
457    /// * ONE_WIRE_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
458    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE
459    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
460    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
461    ///	* ONE_WIRE_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
462    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
463        let payload = [0; 0];
464
465        #[allow(unused_variables)]
466        let result = self.device.get(u8::from(OneWireBrickletFunction::GetBootloaderMode), &payload).await?;
467        Ok(u8::from_le_byte_slice(result.body()))
468    }
469
470    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
471    /// to be increased by chunks of size 64. The data is written to flash
472    /// every 4 chunks (which equals to one page of size 256).
473    ///
474    /// This function is used by Brick Viewer during flashing. It should not be
475    /// necessary to call it in a normal user program.
476    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
477        let mut payload = [0; 4];
478        pointer.write_to_slice(&mut payload[0..4]);
479
480        #[allow(unused_variables)]
481        let result = self.device.set(u8::from(OneWireBrickletFunction::SetWriteFirmwarePointer), &payload).await?;
482        Ok(())
483    }
484
485    /// Writes 64 Bytes of firmware at the position as written by
486    /// [`set_write_firmware_pointer`] before. The firmware is written
487    /// to flash every 4 chunks.
488    ///
489    /// You can only write firmware in bootloader mode.
490    ///
491    /// This function is used by Brick Viewer during flashing. It should not be
492    /// necessary to call it in a normal user program.
493    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
494        let mut payload = [0; 64];
495        data.write_to_slice(&mut payload[0..64]);
496
497        #[allow(unused_variables)]
498        let result = self.device.get(u8::from(OneWireBrickletFunction::WriteFirmware), &payload).await?;
499        Ok(u8::from_le_byte_slice(result.body()))
500    }
501
502    /// Sets the status LED configuration. By default the LED shows
503    /// communication traffic between Brick and Bricklet, it flickers once
504    /// for every 10 received data packets.
505    ///
506    /// You can also turn the LED permanently on/off or show a heartbeat.
507    ///
508    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
509    ///
510    /// Associated constants:
511    /// * ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_OFF
512    ///	* ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_ON
513    ///	* ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
514    ///	* ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
515    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
516        let mut payload = [0; 1];
517        config.write_to_slice(&mut payload[0..1]);
518
519        #[allow(unused_variables)]
520        let result = self.device.set(u8::from(OneWireBrickletFunction::SetStatusLedConfig), &payload).await?;
521        Ok(())
522    }
523
524    /// Returns the configuration as set by [`set_status_led_config`]
525    ///
526    /// Associated constants:
527    /// * ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_OFF
528    ///	* ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_ON
529    ///	* ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
530    ///	* ONE_WIRE_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
531    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
532        let payload = [0; 0];
533
534        #[allow(unused_variables)]
535        let result = self.device.get(u8::from(OneWireBrickletFunction::GetStatusLedConfig), &payload).await?;
536        Ok(u8::from_le_byte_slice(result.body()))
537    }
538
539    /// Returns the temperature as measured inside the microcontroller. The
540    /// value returned is not the ambient temperature!
541    ///
542    /// The temperature is only proportional to the real temperature and it has bad
543    /// accuracy. Practically it is only useful as an indicator for
544    /// temperature changes.
545    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
546        let payload = [0; 0];
547
548        #[allow(unused_variables)]
549        let result = self.device.get(u8::from(OneWireBrickletFunction::GetChipTemperature), &payload).await?;
550        Ok(i16::from_le_byte_slice(result.body()))
551    }
552
553    /// Calling this function will reset the Bricklet. All configurations
554    /// will be lost.
555    ///
556    /// After a reset you have to create new device objects,
557    /// calling functions on the existing ones will result in
558    /// undefined behavior!
559    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
560        let payload = [0; 0];
561
562        #[allow(unused_variables)]
563        let result = self.device.set(u8::from(OneWireBrickletFunction::Reset), &payload).await?;
564        Ok(())
565    }
566
567    /// Writes a new UID into flash. If you want to set a new UID
568    /// you have to decode the Base58 encoded UID string into an
569    /// integer first.
570    ///
571    /// We recommend that you use Brick Viewer to change the UID.
572    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
573        let mut payload = [0; 4];
574        uid.write_to_slice(&mut payload[0..4]);
575
576        #[allow(unused_variables)]
577        let result = self.device.set(u8::from(OneWireBrickletFunction::WriteUid), &payload).await?;
578        Ok(())
579    }
580
581    /// Returns the current UID as an integer. Encode as
582    /// Base58 to get the usual string version.
583    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
584        let payload = [0; 0];
585
586        #[allow(unused_variables)]
587        let result = self.device.get(u8::from(OneWireBrickletFunction::ReadUid), &payload).await?;
588        Ok(u32::from_le_byte_slice(result.body()))
589    }
590
591    /// Returns the UID, the UID where the Bricklet is connected to,
592    /// the position, the hardware and firmware version as well as the
593    /// device identifier.
594    ///
595    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
596    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
597    /// position 'z'.
598    ///
599    /// The device identifier numbers can be found [here](device_identifier).
600    /// |device_identifier_constant|
601    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
602        let payload = [0; 0];
603
604        #[allow(unused_variables)]
605        let result = self.device.get(u8::from(OneWireBrickletFunction::GetIdentity), &payload).await?;
606        Ok(Identity::from_le_byte_slice(result.body()))
607    }
608}