tinkerforge_async/bindings/
multi_touch_v2_bricklet.rs

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