tinkerforge/bindings/
one_wire_bricklet.rs

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