tinkerforge/bindings/
multi_touch_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//! Capacitive touch sensor for 12 electrodes.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/MultiTouchV2_Bricklet_Rust.html).
14use crate::{
15    byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
16    ip_connection::GetRequestSender,
17};
18pub enum MultiTouchV2BrickletFunction {
19    GetTouchState,
20    SetTouchStateCallbackConfiguration,
21    GetTouchStateCallbackConfiguration,
22    Recalibrate,
23    SetElectrodeConfig,
24    GetElectrodeConfig,
25    SetElectrodeSensitivity,
26    GetElectrodeSensitivity,
27    SetTouchLedConfig,
28    GetTouchLedConfig,
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    CallbackTouchState,
42}
43impl From<MultiTouchV2BrickletFunction> for u8 {
44    fn from(fun: MultiTouchV2BrickletFunction) -> Self {
45        match fun {
46            MultiTouchV2BrickletFunction::GetTouchState => 1,
47            MultiTouchV2BrickletFunction::SetTouchStateCallbackConfiguration => 2,
48            MultiTouchV2BrickletFunction::GetTouchStateCallbackConfiguration => 3,
49            MultiTouchV2BrickletFunction::Recalibrate => 5,
50            MultiTouchV2BrickletFunction::SetElectrodeConfig => 6,
51            MultiTouchV2BrickletFunction::GetElectrodeConfig => 7,
52            MultiTouchV2BrickletFunction::SetElectrodeSensitivity => 8,
53            MultiTouchV2BrickletFunction::GetElectrodeSensitivity => 9,
54            MultiTouchV2BrickletFunction::SetTouchLedConfig => 10,
55            MultiTouchV2BrickletFunction::GetTouchLedConfig => 11,
56            MultiTouchV2BrickletFunction::GetSpitfpErrorCount => 234,
57            MultiTouchV2BrickletFunction::SetBootloaderMode => 235,
58            MultiTouchV2BrickletFunction::GetBootloaderMode => 236,
59            MultiTouchV2BrickletFunction::SetWriteFirmwarePointer => 237,
60            MultiTouchV2BrickletFunction::WriteFirmware => 238,
61            MultiTouchV2BrickletFunction::SetStatusLedConfig => 239,
62            MultiTouchV2BrickletFunction::GetStatusLedConfig => 240,
63            MultiTouchV2BrickletFunction::GetChipTemperature => 242,
64            MultiTouchV2BrickletFunction::Reset => 243,
65            MultiTouchV2BrickletFunction::WriteUid => 248,
66            MultiTouchV2BrickletFunction::ReadUid => 249,
67            MultiTouchV2BrickletFunction::GetIdentity => 255,
68            MultiTouchV2BrickletFunction::CallbackTouchState => 4,
69        }
70    }
71}
72pub const MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_OFF: u8 = 0;
73pub const MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_ON: u8 = 1;
74pub const MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
75pub const MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_SHOW_TOUCH: u8 = 3;
76pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
77pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
78pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
79pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
80pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
81pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
82pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
83pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
84pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
85pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
86pub const MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
87pub const MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
88pub const MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
89pub const MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
90pub const MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
91
92#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
93pub struct TouchStateCallbackConfiguration {
94    pub period: u32,
95    pub value_has_to_change: bool,
96}
97impl FromByteSlice for TouchStateCallbackConfiguration {
98    fn bytes_expected() -> usize { 5 }
99    fn from_le_byte_slice(bytes: &[u8]) -> TouchStateCallbackConfiguration {
100        TouchStateCallbackConfiguration {
101            period: <u32>::from_le_byte_slice(&bytes[0..4]),
102            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
103        }
104    }
105}
106
107#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
108pub struct SpitfpErrorCount {
109    pub error_count_ack_checksum: u32,
110    pub error_count_message_checksum: u32,
111    pub error_count_frame: u32,
112    pub error_count_overflow: u32,
113}
114impl FromByteSlice for SpitfpErrorCount {
115    fn bytes_expected() -> usize { 16 }
116    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
117        SpitfpErrorCount {
118            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
119            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
120            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
121            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
122        }
123    }
124}
125
126#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
127pub struct Identity {
128    pub uid: String,
129    pub connected_uid: String,
130    pub position: char,
131    pub hardware_version: [u8; 3],
132    pub firmware_version: [u8; 3],
133    pub device_identifier: u16,
134}
135impl FromByteSlice for Identity {
136    fn bytes_expected() -> usize { 25 }
137    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
138        Identity {
139            uid: <String>::from_le_byte_slice(&bytes[0..8]),
140            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
141            position: <char>::from_le_byte_slice(&bytes[16..17]),
142            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
143            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
144            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
145        }
146    }
147}
148
149/// Capacitive touch sensor for 12 electrodes
150#[derive(Clone)]
151pub struct MultiTouchV2Bricklet {
152    device: Device,
153}
154impl MultiTouchV2Bricklet {
155    pub const DEVICE_IDENTIFIER: u16 = 2129;
156    pub const DEVICE_DISPLAY_NAME: &'static str = "Multi Touch Bricklet 2.0";
157    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
158    pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> MultiTouchV2Bricklet {
159        let mut result = MultiTouchV2Bricklet { device: Device::new([2, 0, 0], uid, req_sender, 0) };
160        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetTouchState) as usize] = ResponseExpectedFlag::AlwaysTrue;
161        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::SetTouchStateCallbackConfiguration) as usize] =
162            ResponseExpectedFlag::True;
163        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetTouchStateCallbackConfiguration) as usize] =
164            ResponseExpectedFlag::AlwaysTrue;
165        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::Recalibrate) as usize] = ResponseExpectedFlag::False;
166        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::SetElectrodeConfig) as usize] = ResponseExpectedFlag::False;
167        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetElectrodeConfig) as usize] =
168            ResponseExpectedFlag::AlwaysTrue;
169        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::SetElectrodeSensitivity) as usize] =
170            ResponseExpectedFlag::False;
171        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetElectrodeSensitivity) as usize] =
172            ResponseExpectedFlag::AlwaysTrue;
173        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::SetTouchLedConfig) as usize] = ResponseExpectedFlag::False;
174        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetTouchLedConfig) as usize] =
175            ResponseExpectedFlag::AlwaysTrue;
176        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetSpitfpErrorCount) as usize] =
177            ResponseExpectedFlag::AlwaysTrue;
178        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::SetBootloaderMode) as usize] =
179            ResponseExpectedFlag::AlwaysTrue;
180        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetBootloaderMode) as usize] =
181            ResponseExpectedFlag::AlwaysTrue;
182        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
183            ResponseExpectedFlag::False;
184        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
185        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
186        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetStatusLedConfig) as usize] =
187            ResponseExpectedFlag::AlwaysTrue;
188        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetChipTemperature) as usize] =
189            ResponseExpectedFlag::AlwaysTrue;
190        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
191        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
192        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
193        result.device.response_expected[u8::from(MultiTouchV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
194        result
195    }
196
197    /// Returns the response expected flag for the function specified by the function ID parameter.
198    /// It is true if the function is expected to send a response, false otherwise.
199    ///
200    /// For getter functions this is enabled by default and cannot be disabled, because those
201    /// functions will always send a response. For callback configuration functions it is enabled
202    /// by default too, but can be disabled by [`set_response_expected`](crate::multi_touch_v2_bricklet::MultiTouchV2Bricklet::set_response_expected).
203    /// For setter functions it is disabled by default and can be enabled.
204    ///
205    /// Enabling the response expected flag for a setter function allows to detect timeouts
206    /// and other error conditions calls of this setter as well. The device will then send a response
207    /// for this purpose. If this flag is disabled for a setter function then no response is sent
208    /// and errors are silently ignored, because they cannot be detected.
209    ///
210    /// See [`set_response_expected`](crate::multi_touch_v2_bricklet::MultiTouchV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
211    pub fn get_response_expected(&mut self, fun: MultiTouchV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
212        self.device.get_response_expected(u8::from(fun))
213    }
214
215    /// Changes the response expected flag of the function specified by the function ID parameter.
216    /// This flag can only be changed for setter (default value: false) and callback configuration
217    /// functions (default value: true). For getter functions it is always enabled.
218    ///
219    /// Enabling the response expected flag for a setter function allows to detect timeouts and
220    /// other error conditions calls of this setter as well. The device will then send a response
221    /// for this purpose. If this flag is disabled for a setter function then no response is sent
222    /// and errors are silently ignored, because they cannot be detected.
223    pub fn set_response_expected(
224        &mut self,
225        fun: MultiTouchV2BrickletFunction,
226        response_expected: bool,
227    ) -> Result<(), SetResponseExpectedError> {
228        self.device.set_response_expected(u8::from(fun), response_expected)
229    }
230
231    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
232    pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
233
234    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
235    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
236    pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
237
238    /// Returns the current touch state, see [`get_touch_state`] for
239    /// information about the state.
240    ///
241    /// This receiver is triggered every time the touch state changes with
242    /// a given period (see [`set_touch_state_callback_configuration`])
243    ///
244    /// [`get_touch_state`]: #method.get_touch_state
245    /// [`set_touch_state_callback_configuration`]: #method.set_touch_state_callback_configuration
246    pub fn get_touch_state_callback_receiver(&self) -> ConvertingCallbackReceiver<[bool; 13]> {
247        self.device.get_callback_receiver(u8::from(MultiTouchV2BrickletFunction::CallbackTouchState))
248    }
249
250    /// Returns the current touch state. The state is given as a array of
251    /// bools.
252    ///
253    /// Element 0 to 11 represent the 12 electrodes and element 12 represents
254    /// the proximity.
255    ///
256    /// If an electrode is touched, the corresponding element is *true*. If
257    /// a hand or similar is in proximity to the electrodes, element 12 is
258    /// *true*.
259    ///
260    /// The proximity is activated with a distance of 1-2cm. An electrode
261    /// is already counted as touched if a finger is nearly touching the
262    /// electrode. This means that you can put a piece of paper or foil
263    /// or similar on top of a electrode to build a touch panel with
264    /// a professional look.
265    ///
266    /// If you want to get the value periodically, it is recommended to use the
267    /// [`get_touch_state_callback_receiver`] receiver. You can set the receiver configuration
268    /// with [`set_touch_state_callback_configuration`].
269    pub fn get_touch_state(&self) -> ConvertingReceiver<[bool; 13]> {
270        let payload = vec![0; 0];
271
272        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetTouchState), payload)
273    }
274
275    /// The period is the period with which the [`get_touch_state_callback_receiver`] receiver
276    /// is triggered periodically. A value of 0 turns the receiver off.
277    ///
278    /// If the `value has to change`-parameter is set to true, the receiver is only
279    /// triggered after the value has changed. If the value didn't change within the
280    /// period, the receiver is triggered immediately on change.
281    ///
282    /// If it is set to false, the receiver is continuously triggered with the period,
283    /// independent of the value.
284    pub fn set_touch_state_callback_configuration(&self, period: u32, value_has_to_change: bool) -> ConvertingReceiver<()> {
285        let mut payload = vec![0; 5];
286        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
287        payload[4..5].copy_from_slice(&<bool>::to_le_byte_vec(value_has_to_change));
288
289        self.device.set(u8::from(MultiTouchV2BrickletFunction::SetTouchStateCallbackConfiguration), payload)
290    }
291
292    /// Returns the receiver configuration as set by
293    /// [`set_touch_state_callback_configuration`].
294    pub fn get_touch_state_callback_configuration(&self) -> ConvertingReceiver<TouchStateCallbackConfiguration> {
295        let payload = vec![0; 0];
296
297        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetTouchStateCallbackConfiguration), payload)
298    }
299
300    /// Recalibrates the electrodes. Call this function whenever you changed
301    /// or moved you electrodes.
302    pub fn recalibrate(&self) -> ConvertingReceiver<()> {
303        let payload = vec![0; 0];
304
305        self.device.set(u8::from(MultiTouchV2BrickletFunction::Recalibrate), payload)
306    }
307
308    /// Enables/disables electrodes with a bool array (see [`get_touch_state`]).
309    ///
310    /// *True* enables the electrode, *false* disables the electrode. A
311    /// disabled electrode will always return *false* as its state. If you
312    /// don't need all electrodes you can disable the electrodes that are
313    /// not needed.
314    ///
315    /// It is recommended that you disable the proximity electrode (element 12) if
316    /// the proximity feature is not needed. This will reduce the amount of
317    /// traffic that is produced by the [`get_touch_state_callback_receiver`] receiver.
318    ///
319    /// Disabling electrodes will also reduce power consumption.
320    pub fn set_electrode_config(&self, enabled_electrodes: [bool; 13]) -> ConvertingReceiver<()> {
321        let mut payload = vec![0; 2];
322        payload[0..2].copy_from_slice(&<[bool; 13]>::to_le_byte_vec(enabled_electrodes));
323
324        self.device.set(u8::from(MultiTouchV2BrickletFunction::SetElectrodeConfig), payload)
325    }
326
327    /// Returns the electrode configuration, as set by [`set_electrode_config`].
328    pub fn get_electrode_config(&self) -> ConvertingReceiver<[bool; 13]> {
329        let payload = vec![0; 0];
330
331        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetElectrodeConfig), payload)
332    }
333
334    /// Sets the sensitivity of the electrodes. An electrode with a high sensitivity
335    /// will register a touch earlier then an electrode with a low sensitivity.
336    ///
337    /// If you build a big electrode you might need to decrease the sensitivity, since
338    /// the area that can be charged will get bigger. If you want to be able to
339    /// activate an electrode from further away you need to increase the sensitivity.
340    ///
341    /// After a new sensitivity is set, you likely want to call [`recalibrate`]
342    /// to calibrate the electrodes with the newly defined sensitivity.
343    pub fn set_electrode_sensitivity(&self, sensitivity: u8) -> ConvertingReceiver<()> {
344        let mut payload = vec![0; 1];
345        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(sensitivity));
346
347        self.device.set(u8::from(MultiTouchV2BrickletFunction::SetElectrodeSensitivity), payload)
348    }
349
350    /// Returns the current sensitivity, as set by [`set_electrode_sensitivity`].
351    pub fn get_electrode_sensitivity(&self) -> ConvertingReceiver<u8> {
352        let payload = vec![0; 0];
353
354        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetElectrodeSensitivity), payload)
355    }
356
357    /// Configures the touch LED to be either turned off, turned on, blink in
358    /// heartbeat mode or show the touch state (electrode touched = LED on).
359    ///
360    /// Associated constants:
361    /// * MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_OFF
362    ///	* MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_ON
363    ///	* MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_SHOW_HEARTBEAT
364    ///	* MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_SHOW_TOUCH
365    pub fn set_touch_led_config(&self, config: u8) -> ConvertingReceiver<()> {
366        let mut payload = vec![0; 1];
367        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
368
369        self.device.set(u8::from(MultiTouchV2BrickletFunction::SetTouchLedConfig), payload)
370    }
371
372    /// Returns the LED configuration as set by [`set_touch_led_config`]
373    ///
374    /// Associated constants:
375    /// * MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_OFF
376    ///	* MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_ON
377    ///	* MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_SHOW_HEARTBEAT
378    ///	* MULTI_TOUCH_V2_BRICKLET_TOUCH_LED_CONFIG_SHOW_TOUCH
379    pub fn get_touch_led_config(&self) -> ConvertingReceiver<u8> {
380        let payload = vec![0; 0];
381
382        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetTouchLedConfig), payload)
383    }
384
385    /// Returns the error count for the communication between Brick and Bricklet.
386    ///
387    /// The errors are divided into
388    ///
389    /// * ACK checksum errors,
390    /// * message checksum errors,
391    /// * framing errors and
392    /// * overflow errors.
393    ///
394    /// The errors counts are for errors that occur on the Bricklet side. All
395    /// Bricks have a similar function that returns the errors on the Brick side.
396    pub fn get_spitfp_error_count(&self) -> ConvertingReceiver<SpitfpErrorCount> {
397        let payload = vec![0; 0];
398
399        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetSpitfpErrorCount), payload)
400    }
401
402    /// Sets the bootloader mode and returns the status after the requested
403    /// mode change was instigated.
404    ///
405    /// You can change from bootloader mode to firmware mode and vice versa. A change
406    /// from bootloader mode to firmware mode will only take place if the entry function,
407    /// device identifier and CRC are present and correct.
408    ///
409    /// This function is used by Brick Viewer during flashing. It should not be
410    /// necessary to call it in a normal user program.
411    ///
412    /// Associated constants:
413    /// * MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
414    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
415    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
416    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
417    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
418    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_OK
419    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
420    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
421    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
422    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
423    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
424    pub fn set_bootloader_mode(&self, mode: u8) -> ConvertingReceiver<u8> {
425        let mut payload = vec![0; 1];
426        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
427
428        self.device.get(u8::from(MultiTouchV2BrickletFunction::SetBootloaderMode), payload)
429    }
430
431    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
432    ///
433    /// Associated constants:
434    /// * MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
435    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
436    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
437    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
438    ///	* MULTI_TOUCH_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
439    pub fn get_bootloader_mode(&self) -> ConvertingReceiver<u8> {
440        let payload = vec![0; 0];
441
442        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetBootloaderMode), payload)
443    }
444
445    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
446    /// to be increased by chunks of size 64. The data is written to flash
447    /// every 4 chunks (which equals to one page of size 256).
448    ///
449    /// This function is used by Brick Viewer during flashing. It should not be
450    /// necessary to call it in a normal user program.
451    pub fn set_write_firmware_pointer(&self, pointer: u32) -> ConvertingReceiver<()> {
452        let mut payload = vec![0; 4];
453        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(pointer));
454
455        self.device.set(u8::from(MultiTouchV2BrickletFunction::SetWriteFirmwarePointer), payload)
456    }
457
458    /// Writes 64 Bytes of firmware at the position as written by
459    /// [`set_write_firmware_pointer`] before. The firmware is written
460    /// to flash every 4 chunks.
461    ///
462    /// You can only write firmware in bootloader mode.
463    ///
464    /// This function is used by Brick Viewer during flashing. It should not be
465    /// necessary to call it in a normal user program.
466    pub fn write_firmware(&self, data: [u8; 64]) -> ConvertingReceiver<u8> {
467        let mut payload = vec![0; 64];
468        payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));
469
470        self.device.get(u8::from(MultiTouchV2BrickletFunction::WriteFirmware), payload)
471    }
472
473    /// Sets the status LED configuration. By default the LED shows
474    /// communication traffic between Brick and Bricklet, it flickers once
475    /// for every 10 received data packets.
476    ///
477    /// You can also turn the LED permanently on/off or show a heartbeat.
478    ///
479    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
480    ///
481    /// Associated constants:
482    /// * MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_OFF
483    ///	* MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_ON
484    ///	* MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
485    ///	* MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
486    pub fn set_status_led_config(&self, config: u8) -> ConvertingReceiver<()> {
487        let mut payload = vec![0; 1];
488        payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
489
490        self.device.set(u8::from(MultiTouchV2BrickletFunction::SetStatusLedConfig), payload)
491    }
492
493    /// Returns the configuration as set by [`set_status_led_config`]
494    ///
495    /// Associated constants:
496    /// * MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_OFF
497    ///	* MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_ON
498    ///	* MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
499    ///	* MULTI_TOUCH_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
500    pub fn get_status_led_config(&self) -> ConvertingReceiver<u8> {
501        let payload = vec![0; 0];
502
503        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetStatusLedConfig), payload)
504    }
505
506    /// Returns the temperature as measured inside the microcontroller. The
507    /// value returned is not the ambient temperature!
508    ///
509    /// The temperature is only proportional to the real temperature and it has bad
510    /// accuracy. Practically it is only useful as an indicator for
511    /// temperature changes.
512    pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
513        let payload = vec![0; 0];
514
515        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetChipTemperature), payload)
516    }
517
518    /// Calling this function will reset the Bricklet. All configurations
519    /// will be lost.
520    ///
521    /// After a reset you have to create new device objects,
522    /// calling functions on the existing ones will result in
523    /// undefined behavior!
524    pub fn reset(&self) -> ConvertingReceiver<()> {
525        let payload = vec![0; 0];
526
527        self.device.set(u8::from(MultiTouchV2BrickletFunction::Reset), payload)
528    }
529
530    /// Writes a new UID into flash. If you want to set a new UID
531    /// you have to decode the Base58 encoded UID string into an
532    /// integer first.
533    ///
534    /// We recommend that you use Brick Viewer to change the UID.
535    pub fn write_uid(&self, uid: u32) -> ConvertingReceiver<()> {
536        let mut payload = vec![0; 4];
537        payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(uid));
538
539        self.device.set(u8::from(MultiTouchV2BrickletFunction::WriteUid), payload)
540    }
541
542    /// Returns the current UID as an integer. Encode as
543    /// Base58 to get the usual string version.
544    pub fn read_uid(&self) -> ConvertingReceiver<u32> {
545        let payload = vec![0; 0];
546
547        self.device.get(u8::from(MultiTouchV2BrickletFunction::ReadUid), payload)
548    }
549
550    /// Returns the UID, the UID where the Bricklet is connected to,
551    /// the position, the hardware and firmware version as well as the
552    /// device identifier.
553    ///
554    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
555    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
556    /// position 'z'.
557    ///
558    /// The device identifier numbers can be found [here](device_identifier).
559    /// |device_identifier_constant|
560    pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
561        let payload = vec![0; 0];
562
563        self.device.get(u8::from(MultiTouchV2BrickletFunction::GetIdentity), payload)
564    }
565}