tinkerforge/bindings/
dual_button_v2_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//! Two tactile buttons with built-in blue LEDs.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/DualButtonV2_Bricklet_Rust.html).
14use crate::{
15    byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
16    ip_connection::GetRequestSender,
17};
18pub enum DualButtonV2BrickletFunction {
19    SetLedState,
20    GetLedState,
21    GetButtonState,
22    SetSelectedLedState,
23    SetStateChangedCallbackConfiguration,
24    GetStateChangedCallbackConfiguration,
25    GetSpitfpErrorCount,
26    SetBootloaderMode,
27    GetBootloaderMode,
28    SetWriteFirmwarePointer,
29    WriteFirmware,
30    SetStatusLedConfig,
31    GetStatusLedConfig,
32    GetChipTemperature,
33    Reset,
34    WriteUid,
35    ReadUid,
36    GetIdentity,
37    CallbackStateChanged,
38}
39impl From<DualButtonV2BrickletFunction> for u8 {
40    fn from(fun: DualButtonV2BrickletFunction) -> Self {
41        match fun {
42            DualButtonV2BrickletFunction::SetLedState => 1,
43            DualButtonV2BrickletFunction::GetLedState => 2,
44            DualButtonV2BrickletFunction::GetButtonState => 3,
45            DualButtonV2BrickletFunction::SetSelectedLedState => 5,
46            DualButtonV2BrickletFunction::SetStateChangedCallbackConfiguration => 6,
47            DualButtonV2BrickletFunction::GetStateChangedCallbackConfiguration => 7,
48            DualButtonV2BrickletFunction::GetSpitfpErrorCount => 234,
49            DualButtonV2BrickletFunction::SetBootloaderMode => 235,
50            DualButtonV2BrickletFunction::GetBootloaderMode => 236,
51            DualButtonV2BrickletFunction::SetWriteFirmwarePointer => 237,
52            DualButtonV2BrickletFunction::WriteFirmware => 238,
53            DualButtonV2BrickletFunction::SetStatusLedConfig => 239,
54            DualButtonV2BrickletFunction::GetStatusLedConfig => 240,
55            DualButtonV2BrickletFunction::GetChipTemperature => 242,
56            DualButtonV2BrickletFunction::Reset => 243,
57            DualButtonV2BrickletFunction::WriteUid => 248,
58            DualButtonV2BrickletFunction::ReadUid => 249,
59            DualButtonV2BrickletFunction::GetIdentity => 255,
60            DualButtonV2BrickletFunction::CallbackStateChanged => 4,
61        }
62    }
63}
64pub const DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_ON: u8 = 0;
65pub const DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_OFF: u8 = 1;
66pub const DUAL_BUTTON_V2_BRICKLET_LED_STATE_ON: u8 = 2;
67pub const DUAL_BUTTON_V2_BRICKLET_LED_STATE_OFF: u8 = 3;
68pub const DUAL_BUTTON_V2_BRICKLET_BUTTON_STATE_PRESSED: u8 = 0;
69pub const DUAL_BUTTON_V2_BRICKLET_BUTTON_STATE_RELEASED: u8 = 1;
70pub const DUAL_BUTTON_V2_BRICKLET_LED_LEFT: u8 = 0;
71pub const DUAL_BUTTON_V2_BRICKLET_LED_RIGHT: u8 = 1;
72pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
73pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
74pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
75pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
76pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
77pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
78pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
79pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
80pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
81pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
82pub const DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
83pub const DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
84pub const DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
85pub const DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
86pub const DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
87
88#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
89pub struct LedState {
90    pub led_l: u8,
91    pub led_r: u8,
92}
93impl FromByteSlice for LedState {
94    fn bytes_expected() -> usize { 2 }
95    fn from_le_byte_slice(bytes: &[u8]) -> LedState {
96        LedState { led_l: <u8>::from_le_byte_slice(&bytes[0..1]), led_r: <u8>::from_le_byte_slice(&bytes[1..2]) }
97    }
98}
99
100#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
101pub struct ButtonState {
102    pub button_l: u8,
103    pub button_r: u8,
104}
105impl FromByteSlice for ButtonState {
106    fn bytes_expected() -> usize { 2 }
107    fn from_le_byte_slice(bytes: &[u8]) -> ButtonState {
108        ButtonState { button_l: <u8>::from_le_byte_slice(&bytes[0..1]), button_r: <u8>::from_le_byte_slice(&bytes[1..2]) }
109    }
110}
111
112#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
113pub struct StateChangedEvent {
114    pub button_l: u8,
115    pub button_r: u8,
116    pub led_l: u8,
117    pub led_r: u8,
118}
119impl FromByteSlice for StateChangedEvent {
120    fn bytes_expected() -> usize { 4 }
121    fn from_le_byte_slice(bytes: &[u8]) -> StateChangedEvent {
122        StateChangedEvent {
123            button_l: <u8>::from_le_byte_slice(&bytes[0..1]),
124            button_r: <u8>::from_le_byte_slice(&bytes[1..2]),
125            led_l: <u8>::from_le_byte_slice(&bytes[2..3]),
126            led_r: <u8>::from_le_byte_slice(&bytes[3..4]),
127        }
128    }
129}
130
131#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
132pub struct SpitfpErrorCount {
133    pub error_count_ack_checksum: u32,
134    pub error_count_message_checksum: u32,
135    pub error_count_frame: u32,
136    pub error_count_overflow: u32,
137}
138impl FromByteSlice for SpitfpErrorCount {
139    fn bytes_expected() -> usize { 16 }
140    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
141        SpitfpErrorCount {
142            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
143            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
144            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
145            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
146        }
147    }
148}
149
150#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
151pub struct Identity {
152    pub uid: String,
153    pub connected_uid: String,
154    pub position: char,
155    pub hardware_version: [u8; 3],
156    pub firmware_version: [u8; 3],
157    pub device_identifier: u16,
158}
159impl FromByteSlice for Identity {
160    fn bytes_expected() -> usize { 25 }
161    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
162        Identity {
163            uid: <String>::from_le_byte_slice(&bytes[0..8]),
164            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
165            position: <char>::from_le_byte_slice(&bytes[16..17]),
166            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
167            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
168            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
169        }
170    }
171}
172
173/// Two tactile buttons with built-in blue LEDs
174#[derive(Clone)]
175pub struct DualButtonV2Bricklet {
176    device: Device,
177}
178impl DualButtonV2Bricklet {
179    pub const DEVICE_IDENTIFIER: u16 = 2119;
180    pub const DEVICE_DISPLAY_NAME: &'static str = "Dual Button Bricklet 2.0";
181    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
182    pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> DualButtonV2Bricklet {
183        let mut result = DualButtonV2Bricklet { device: Device::new([2, 0, 0], uid, req_sender, 0) };
184        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::SetLedState) as usize] = ResponseExpectedFlag::False;
185        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetLedState) as usize] = ResponseExpectedFlag::AlwaysTrue;
186        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetButtonState) as usize] = ResponseExpectedFlag::AlwaysTrue;
187        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::SetSelectedLedState) as usize] = ResponseExpectedFlag::False;
188        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::SetStateChangedCallbackConfiguration) as usize] =
189            ResponseExpectedFlag::True;
190        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetStateChangedCallbackConfiguration) as usize] =
191            ResponseExpectedFlag::AlwaysTrue;
192        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetSpitfpErrorCount) as usize] =
193            ResponseExpectedFlag::AlwaysTrue;
194        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::SetBootloaderMode) as usize] =
195            ResponseExpectedFlag::AlwaysTrue;
196        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetBootloaderMode) as usize] =
197            ResponseExpectedFlag::AlwaysTrue;
198        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
199            ResponseExpectedFlag::False;
200        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
201        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
202        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetStatusLedConfig) as usize] =
203            ResponseExpectedFlag::AlwaysTrue;
204        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetChipTemperature) as usize] =
205            ResponseExpectedFlag::AlwaysTrue;
206        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
207        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
208        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
209        result.device.response_expected[u8::from(DualButtonV2BrickletFunction::GetIdentity) as usize] = 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::dual_button_v2_bricklet::DualButtonV2Bricklet::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::dual_button_v2_bricklet::DualButtonV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
227    pub fn get_response_expected(&mut self, fun: DualButtonV2BrickletFunction) -> 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: DualButtonV2BrickletFunction,
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) { self.device.set_response_expected_all(response_expected) }
249
250    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
251    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
252    pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
253
254    /// This receiver is called whenever a button is pressed.
255    ///
256    /// Possible states for buttons are:
257    ///
258    /// * 0 = pressed
259    /// * 1 = released
260    ///
261    /// Possible states for LEDs are:
262    ///
263    /// * 0 = AutoToggleOn: Auto toggle enabled and LED on.
264    /// * 1 = AutoToggleOff: Auto toggle enabled and LED off.
265    /// * 2 = On: LED on (auto toggle is disabled).
266    /// * 3 = Off: LED off (auto toggle is disabled).
267    ///
268    /// This receiver can be enabled with [`set_state_changed_callback_configuration`].
269    ///
270    /// [`set_state_changed_callback_configuration`]: #method.set_state_changed_callback_configuration
271    pub fn get_state_changed_callback_receiver(&self) -> ConvertingCallbackReceiver<StateChangedEvent> {
272        self.device.get_callback_receiver(u8::from(DualButtonV2BrickletFunction::CallbackStateChanged))
273    }
274
275    /// Sets the state of the LEDs. Possible states are:
276    ///
277    /// * 0 = AutoToggleOn: Enables auto toggle with initially enabled LED.
278    /// * 1 = AutoToggleOff: Activates auto toggle with initially disabled LED.
279    /// * 2 = On: Enables LED (auto toggle is disabled).
280    /// * 3 = Off: Disables LED (auto toggle is disabled).
281    ///
282    /// In auto toggle mode the LED is toggled automatically at each press of a button.
283    ///
284    /// If you just want to set one of the LEDs and don't know the current state
285    /// of the other LED, you can get the state with [`get_led_state`] or you
286    /// can use [`set_selected_led_state`].
287    ///
288    /// Associated constants:
289    /// * DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_ON
290    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_OFF
291    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_ON
292    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_OFF
293    pub fn set_led_state(&self, led_l: u8, led_r: u8) -> ConvertingReceiver<()> {
294        let mut payload = vec![0; 2];
295        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(led_l));
296        payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(led_r));
297
298        self.device.set(u8::from(DualButtonV2BrickletFunction::SetLedState), payload)
299    }
300
301    /// Returns the current state of the LEDs, as set by [`set_led_state`].
302    ///
303    /// Associated constants:
304    /// * DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_ON
305    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_OFF
306    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_ON
307    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_OFF
308    pub fn get_led_state(&self) -> ConvertingReceiver<LedState> {
309        let payload = vec![0; 0];
310
311        self.device.get(u8::from(DualButtonV2BrickletFunction::GetLedState), payload)
312    }
313
314    /// Returns the current state for both buttons. Possible states are:
315    ///
316    /// * 0 = pressed
317    /// * 1 = released
318    ///
319    /// Associated constants:
320    /// * DUAL_BUTTON_V2_BRICKLET_BUTTON_STATE_PRESSED
321    ///	* DUAL_BUTTON_V2_BRICKLET_BUTTON_STATE_RELEASED
322    pub fn get_button_state(&self) -> ConvertingReceiver<ButtonState> {
323        let payload = vec![0; 0];
324
325        self.device.get(u8::from(DualButtonV2BrickletFunction::GetButtonState), payload)
326    }
327
328    /// Sets the state of the selected LED.
329    ///
330    /// The other LED remains untouched.
331    ///
332    /// Associated constants:
333    /// * DUAL_BUTTON_V2_BRICKLET_LED_LEFT
334    ///	* DUAL_BUTTON_V2_BRICKLET_LED_RIGHT
335    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_ON
336    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_AUTO_TOGGLE_OFF
337    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_ON
338    ///	* DUAL_BUTTON_V2_BRICKLET_LED_STATE_OFF
339    pub fn set_selected_led_state(&self, led: u8, state: u8) -> ConvertingReceiver<()> {
340        let mut payload = vec![0; 2];
341        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(led));
342        payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(state));
343
344        self.device.set(u8::from(DualButtonV2BrickletFunction::SetSelectedLedState), payload)
345    }
346
347    /// If you enable this receiver, the [`get_state_changed_callback_receiver`] receiver is triggered
348    /// every time a button is pressed/released
349    pub fn set_state_changed_callback_configuration(&self, enabled: bool) -> ConvertingReceiver<()> {
350        let mut payload = vec![0; 1];
351        payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enabled));
352
353        self.device.set(u8::from(DualButtonV2BrickletFunction::SetStateChangedCallbackConfiguration), payload)
354    }
355
356    /// Returns the configuration as set by [`set_state_changed_callback_configuration`].
357    pub fn get_state_changed_callback_configuration(&self) -> ConvertingReceiver<bool> {
358        let payload = vec![0; 0];
359
360        self.device.get(u8::from(DualButtonV2BrickletFunction::GetStateChangedCallbackConfiguration), payload)
361    }
362
363    /// Returns the error count for the communication between Brick and Bricklet.
364    ///
365    /// The errors are divided into
366    ///
367    /// * ACK checksum errors,
368    /// * message checksum errors,
369    /// * framing errors and
370    /// * overflow errors.
371    ///
372    /// The errors counts are for errors that occur on the Bricklet side. All
373    /// Bricks have a similar function that returns the errors on the Brick side.
374    pub fn get_spitfp_error_count(&self) -> ConvertingReceiver<SpitfpErrorCount> {
375        let payload = vec![0; 0];
376
377        self.device.get(u8::from(DualButtonV2BrickletFunction::GetSpitfpErrorCount), payload)
378    }
379
380    /// Sets the bootloader mode and returns the status after the requested
381    /// mode change was instigated.
382    ///
383    /// You can change from bootloader mode to firmware mode and vice versa. A change
384    /// from bootloader mode to firmware mode will only take place if the entry function,
385    /// device identifier and CRC are present and correct.
386    ///
387    /// This function is used by Brick Viewer during flashing. It should not be
388    /// necessary to call it in a normal user program.
389    ///
390    /// Associated constants:
391    /// * DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
392    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
393    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
394    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
395    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
396    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_OK
397    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
398    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
399    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
400    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
401    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
402    pub fn set_bootloader_mode(&self, mode: u8) -> ConvertingReceiver<u8> {
403        let mut payload = vec![0; 1];
404        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
405
406        self.device.get(u8::from(DualButtonV2BrickletFunction::SetBootloaderMode), payload)
407    }
408
409    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
410    ///
411    /// Associated constants:
412    /// * DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
413    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
414    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
415    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
416    ///	* DUAL_BUTTON_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
417    pub fn get_bootloader_mode(&self) -> ConvertingReceiver<u8> {
418        let payload = vec![0; 0];
419
420        self.device.get(u8::from(DualButtonV2BrickletFunction::GetBootloaderMode), payload)
421    }
422
423    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
424    /// to be increased by chunks of size 64. The data is written to flash
425    /// every 4 chunks (which equals to one page of size 256).
426    ///
427    /// This function is used by Brick Viewer during flashing. It should not be
428    /// necessary to call it in a normal user program.
429    pub fn set_write_firmware_pointer(&self, pointer: u32) -> ConvertingReceiver<()> {
430        let mut payload = vec![0; 4];
431        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(pointer));
432
433        self.device.set(u8::from(DualButtonV2BrickletFunction::SetWriteFirmwarePointer), payload)
434    }
435
436    /// Writes 64 Bytes of firmware at the position as written by
437    /// [`set_write_firmware_pointer`] before. The firmware is written
438    /// to flash every 4 chunks.
439    ///
440    /// You can only write firmware in bootloader mode.
441    ///
442    /// This function is used by Brick Viewer during flashing. It should not be
443    /// necessary to call it in a normal user program.
444    pub fn write_firmware(&self, data: [u8; 64]) -> ConvertingReceiver<u8> {
445        let mut payload = vec![0; 64];
446        payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));
447
448        self.device.get(u8::from(DualButtonV2BrickletFunction::WriteFirmware), payload)
449    }
450
451    /// Sets the status LED configuration. By default the LED shows
452    /// communication traffic between Brick and Bricklet, it flickers once
453    /// for every 10 received data packets.
454    ///
455    /// You can also turn the LED permanently on/off or show a heartbeat.
456    ///
457    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
458    ///
459    /// Associated constants:
460    /// * DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_OFF
461    ///	* DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_ON
462    ///	* DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
463    ///	* DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
464    pub fn set_status_led_config(&self, config: u8) -> ConvertingReceiver<()> {
465        let mut payload = vec![0; 1];
466        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
467
468        self.device.set(u8::from(DualButtonV2BrickletFunction::SetStatusLedConfig), payload)
469    }
470
471    /// Returns the configuration as set by [`set_status_led_config`]
472    ///
473    /// Associated constants:
474    /// * DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_OFF
475    ///	* DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_ON
476    ///	* DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
477    ///	* DUAL_BUTTON_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
478    pub fn get_status_led_config(&self) -> ConvertingReceiver<u8> {
479        let payload = vec![0; 0];
480
481        self.device.get(u8::from(DualButtonV2BrickletFunction::GetStatusLedConfig), payload)
482    }
483
484    /// Returns the temperature as measured inside the microcontroller. The
485    /// value returned is not the ambient temperature!
486    ///
487    /// The temperature is only proportional to the real temperature and it has bad
488    /// accuracy. Practically it is only useful as an indicator for
489    /// temperature changes.
490    pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
491        let payload = vec![0; 0];
492
493        self.device.get(u8::from(DualButtonV2BrickletFunction::GetChipTemperature), payload)
494    }
495
496    /// Calling this function will reset the Bricklet. All configurations
497    /// will be lost.
498    ///
499    /// After a reset you have to create new device objects,
500    /// calling functions on the existing ones will result in
501    /// undefined behavior!
502    pub fn reset(&self) -> ConvertingReceiver<()> {
503        let payload = vec![0; 0];
504
505        self.device.set(u8::from(DualButtonV2BrickletFunction::Reset), payload)
506    }
507
508    /// Writes a new UID into flash. If you want to set a new UID
509    /// you have to decode the Base58 encoded UID string into an
510    /// integer first.
511    ///
512    /// We recommend that you use Brick Viewer to change the UID.
513    pub fn write_uid(&self, uid: u32) -> ConvertingReceiver<()> {
514        let mut payload = vec![0; 4];
515        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(uid));
516
517        self.device.set(u8::from(DualButtonV2BrickletFunction::WriteUid), payload)
518    }
519
520    /// Returns the current UID as an integer. Encode as
521    /// Base58 to get the usual string version.
522    pub fn read_uid(&self) -> ConvertingReceiver<u32> {
523        let payload = vec![0; 0];
524
525        self.device.get(u8::from(DualButtonV2BrickletFunction::ReadUid), payload)
526    }
527
528    /// Returns the UID, the UID where the Bricklet is connected to,
529    /// the position, the hardware and firmware version as well as the
530    /// device identifier.
531    ///
532    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
533    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
534    /// position 'z'.
535    ///
536    /// The device identifier numbers can be found [here](device_identifier).
537    /// |device_identifier_constant|
538    pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
539        let payload = vec![0; 0];
540
541        self.device.get(u8::from(DualButtonV2BrickletFunction::GetIdentity), payload)
542    }
543}