tinkerforge_async/bindings/
accelerometer_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//! Measures acceleration in three axis.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricklets/AccelerometerV2_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 AccelerometerV2BrickletFunction {
24    GetAcceleration,
25    SetConfiguration,
26    GetConfiguration,
27    SetAccelerationCallbackConfiguration,
28    GetAccelerationCallbackConfiguration,
29    SetInfoLedConfig,
30    GetInfoLedConfig,
31    SetContinuousAccelerationConfiguration,
32    GetContinuousAccelerationConfiguration,
33    SetFilterConfiguration,
34    GetFilterConfiguration,
35    GetSpitfpErrorCount,
36    SetBootloaderMode,
37    GetBootloaderMode,
38    SetWriteFirmwarePointer,
39    WriteFirmware,
40    SetStatusLedConfig,
41    GetStatusLedConfig,
42    GetChipTemperature,
43    Reset,
44    WriteUid,
45    ReadUid,
46    GetIdentity,
47    CallbackAcceleration,
48    CallbackContinuousAcceleration16Bit,
49    CallbackContinuousAcceleration8Bit,
50}
51impl From<AccelerometerV2BrickletFunction> for u8 {
52    fn from(fun: AccelerometerV2BrickletFunction) -> Self {
53        match fun {
54            AccelerometerV2BrickletFunction::GetAcceleration => 1,
55            AccelerometerV2BrickletFunction::SetConfiguration => 2,
56            AccelerometerV2BrickletFunction::GetConfiguration => 3,
57            AccelerometerV2BrickletFunction::SetAccelerationCallbackConfiguration => 4,
58            AccelerometerV2BrickletFunction::GetAccelerationCallbackConfiguration => 5,
59            AccelerometerV2BrickletFunction::SetInfoLedConfig => 6,
60            AccelerometerV2BrickletFunction::GetInfoLedConfig => 7,
61            AccelerometerV2BrickletFunction::SetContinuousAccelerationConfiguration => 9,
62            AccelerometerV2BrickletFunction::GetContinuousAccelerationConfiguration => 10,
63            AccelerometerV2BrickletFunction::SetFilterConfiguration => 13,
64            AccelerometerV2BrickletFunction::GetFilterConfiguration => 14,
65            AccelerometerV2BrickletFunction::GetSpitfpErrorCount => 234,
66            AccelerometerV2BrickletFunction::SetBootloaderMode => 235,
67            AccelerometerV2BrickletFunction::GetBootloaderMode => 236,
68            AccelerometerV2BrickletFunction::SetWriteFirmwarePointer => 237,
69            AccelerometerV2BrickletFunction::WriteFirmware => 238,
70            AccelerometerV2BrickletFunction::SetStatusLedConfig => 239,
71            AccelerometerV2BrickletFunction::GetStatusLedConfig => 240,
72            AccelerometerV2BrickletFunction::GetChipTemperature => 242,
73            AccelerometerV2BrickletFunction::Reset => 243,
74            AccelerometerV2BrickletFunction::WriteUid => 248,
75            AccelerometerV2BrickletFunction::ReadUid => 249,
76            AccelerometerV2BrickletFunction::GetIdentity => 255,
77            AccelerometerV2BrickletFunction::CallbackAcceleration => 8,
78            AccelerometerV2BrickletFunction::CallbackContinuousAcceleration16Bit => 11,
79            AccelerometerV2BrickletFunction::CallbackContinuousAcceleration8Bit => 12,
80        }
81    }
82}
83pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_0_781HZ: u8 = 0;
84pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_1_563HZ: u8 = 1;
85pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_3_125HZ: u8 = 2;
86pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_6_2512HZ: u8 = 3;
87pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_12_5HZ: u8 = 4;
88pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_25HZ: u8 = 5;
89pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_50HZ: u8 = 6;
90pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_100HZ: u8 = 7;
91pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_200HZ: u8 = 8;
92pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_400HZ: u8 = 9;
93pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_800HZ: u8 = 10;
94pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_1600HZ: u8 = 11;
95pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_3200HZ: u8 = 12;
96pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_6400HZ: u8 = 13;
97pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_12800HZ: u8 = 14;
98pub const ACCELEROMETER_V2_BRICKLET_DATA_RATE_25600HZ: u8 = 15;
99pub const ACCELEROMETER_V2_BRICKLET_FULL_SCALE_2G: u8 = 0;
100pub const ACCELEROMETER_V2_BRICKLET_FULL_SCALE_4G: u8 = 1;
101pub const ACCELEROMETER_V2_BRICKLET_FULL_SCALE_8G: u8 = 2;
102pub const ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_OFF: u8 = 0;
103pub const ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_ON: u8 = 1;
104pub const ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
105pub const ACCELEROMETER_V2_BRICKLET_RESOLUTION_8BIT: u8 = 0;
106pub const ACCELEROMETER_V2_BRICKLET_RESOLUTION_16BIT: u8 = 1;
107pub const ACCELEROMETER_V2_BRICKLET_IIR_BYPASS_APPLIED: u8 = 0;
108pub const ACCELEROMETER_V2_BRICKLET_IIR_BYPASS_BYPASSED: u8 = 1;
109pub const ACCELEROMETER_V2_BRICKLET_LOW_PASS_FILTER_NINTH: u8 = 0;
110pub const ACCELEROMETER_V2_BRICKLET_LOW_PASS_FILTER_HALF: u8 = 1;
111pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
112pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
113pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
114pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
115pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
116pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
117pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
118pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
119pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
120pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
121pub const ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
122pub const ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
123pub const ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
124pub const ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
125pub const ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
126
127#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
128pub struct Acceleration {
129    pub x: i32,
130    pub y: i32,
131    pub z: i32,
132}
133impl FromByteSlice for Acceleration {
134    fn bytes_expected() -> usize {
135        12
136    }
137    fn from_le_byte_slice(bytes: &[u8]) -> Acceleration {
138        Acceleration {
139            x: <i32>::from_le_byte_slice(&bytes[0..4]),
140            y: <i32>::from_le_byte_slice(&bytes[4..8]),
141            z: <i32>::from_le_byte_slice(&bytes[8..12]),
142        }
143    }
144}
145
146#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
147pub struct Configuration {
148    pub data_rate: u8,
149    pub full_scale: u8,
150}
151impl FromByteSlice for Configuration {
152    fn bytes_expected() -> usize {
153        2
154    }
155    fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
156        Configuration { data_rate: <u8>::from_le_byte_slice(&bytes[0..1]), full_scale: <u8>::from_le_byte_slice(&bytes[1..2]) }
157    }
158}
159
160#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
161pub struct AccelerationCallbackConfiguration {
162    pub period: u32,
163    pub value_has_to_change: bool,
164}
165impl FromByteSlice for AccelerationCallbackConfiguration {
166    fn bytes_expected() -> usize {
167        5
168    }
169    fn from_le_byte_slice(bytes: &[u8]) -> AccelerationCallbackConfiguration {
170        AccelerationCallbackConfiguration {
171            period: <u32>::from_le_byte_slice(&bytes[0..4]),
172            value_has_to_change: <bool>::from_le_byte_slice(&bytes[4..5]),
173        }
174    }
175}
176
177#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
178pub struct AccelerationEvent {
179    pub x: i32,
180    pub y: i32,
181    pub z: i32,
182}
183impl FromByteSlice for AccelerationEvent {
184    fn bytes_expected() -> usize {
185        12
186    }
187    fn from_le_byte_slice(bytes: &[u8]) -> AccelerationEvent {
188        AccelerationEvent {
189            x: <i32>::from_le_byte_slice(&bytes[0..4]),
190            y: <i32>::from_le_byte_slice(&bytes[4..8]),
191            z: <i32>::from_le_byte_slice(&bytes[8..12]),
192        }
193    }
194}
195
196#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
197pub struct ContinuousAccelerationConfiguration {
198    pub enable_x: bool,
199    pub enable_y: bool,
200    pub enable_z: bool,
201    pub resolution: u8,
202}
203impl FromByteSlice for ContinuousAccelerationConfiguration {
204    fn bytes_expected() -> usize {
205        4
206    }
207    fn from_le_byte_slice(bytes: &[u8]) -> ContinuousAccelerationConfiguration {
208        ContinuousAccelerationConfiguration {
209            enable_x: <bool>::from_le_byte_slice(&bytes[0..1]),
210            enable_y: <bool>::from_le_byte_slice(&bytes[1..2]),
211            enable_z: <bool>::from_le_byte_slice(&bytes[2..3]),
212            resolution: <u8>::from_le_byte_slice(&bytes[3..4]),
213        }
214    }
215}
216
217#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
218pub struct FilterConfiguration {
219    pub iir_bypass: u8,
220    pub low_pass_filter: u8,
221}
222impl FromByteSlice for FilterConfiguration {
223    fn bytes_expected() -> usize {
224        2
225    }
226    fn from_le_byte_slice(bytes: &[u8]) -> FilterConfiguration {
227        FilterConfiguration { iir_bypass: <u8>::from_le_byte_slice(&bytes[0..1]), low_pass_filter: <u8>::from_le_byte_slice(&bytes[1..2]) }
228    }
229}
230
231#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
232pub struct SpitfpErrorCount {
233    pub error_count_ack_checksum: u32,
234    pub error_count_message_checksum: u32,
235    pub error_count_frame: u32,
236    pub error_count_overflow: u32,
237}
238impl FromByteSlice for SpitfpErrorCount {
239    fn bytes_expected() -> usize {
240        16
241    }
242    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
243        SpitfpErrorCount {
244            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
245            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
246            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
247            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
248        }
249    }
250}
251
252#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
253pub struct Identity {
254    pub uid: String,
255    pub connected_uid: String,
256    pub position: char,
257    pub hardware_version: [u8; 3],
258    pub firmware_version: [u8; 3],
259    pub device_identifier: u16,
260}
261impl FromByteSlice for Identity {
262    fn bytes_expected() -> usize {
263        25
264    }
265    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
266        Identity {
267            uid: <String>::from_le_byte_slice(&bytes[0..8]),
268            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
269            position: <char>::from_le_byte_slice(&bytes[16..17]),
270            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
271            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
272            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
273        }
274    }
275}
276
277/// Measures acceleration in three axis
278#[derive(Clone)]
279pub struct AccelerometerV2Bricklet {
280    device: Device,
281}
282impl AccelerometerV2Bricklet {
283    pub const DEVICE_IDENTIFIER: u16 = 2130;
284    pub const DEVICE_DISPLAY_NAME: &'static str = "Accelerometer Bricklet 2.0";
285    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
286    pub fn new(uid: Uid, connection: AsyncIpConnection) -> AccelerometerV2Bricklet {
287        let mut result = AccelerometerV2Bricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
288        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetAcceleration) as usize] =
289            ResponseExpectedFlag::AlwaysTrue;
290        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
291        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetConfiguration) as usize] =
292            ResponseExpectedFlag::AlwaysTrue;
293        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetAccelerationCallbackConfiguration) as usize] =
294            ResponseExpectedFlag::True;
295        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetAccelerationCallbackConfiguration) as usize] =
296            ResponseExpectedFlag::AlwaysTrue;
297        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetInfoLedConfig) as usize] = ResponseExpectedFlag::False;
298        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetInfoLedConfig) as usize] =
299            ResponseExpectedFlag::AlwaysTrue;
300        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetContinuousAccelerationConfiguration) as usize] =
301            ResponseExpectedFlag::True;
302        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetContinuousAccelerationConfiguration) as usize] =
303            ResponseExpectedFlag::AlwaysTrue;
304        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetFilterConfiguration) as usize] =
305            ResponseExpectedFlag::False;
306        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetFilterConfiguration) as usize] =
307            ResponseExpectedFlag::AlwaysTrue;
308        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetSpitfpErrorCount) as usize] =
309            ResponseExpectedFlag::AlwaysTrue;
310        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetBootloaderMode) as usize] =
311            ResponseExpectedFlag::AlwaysTrue;
312        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetBootloaderMode) as usize] =
313            ResponseExpectedFlag::AlwaysTrue;
314        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetWriteFirmwarePointer) as usize] =
315            ResponseExpectedFlag::False;
316        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::WriteFirmware) as usize] =
317            ResponseExpectedFlag::AlwaysTrue;
318        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::SetStatusLedConfig) as usize] =
319            ResponseExpectedFlag::False;
320        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetStatusLedConfig) as usize] =
321            ResponseExpectedFlag::AlwaysTrue;
322        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetChipTemperature) as usize] =
323            ResponseExpectedFlag::AlwaysTrue;
324        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
325        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
326        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
327        result.device.response_expected[u8::from(AccelerometerV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
328        result
329    }
330
331    /// Returns the response expected flag for the function specified by the function ID parameter.
332    /// It is true if the function is expected to send a response, false otherwise.
333    ///
334    /// For getter functions this is enabled by default and cannot be disabled, because those
335    /// functions will always send a response. For callback configuration functions it is enabled
336    /// by default too, but can be disabled by [`set_response_expected`](crate::accelerometer_v2_bricklet::AccelerometerV2Bricklet::set_response_expected).
337    /// For setter functions it is disabled by default and can be enabled.
338    ///
339    /// Enabling the response expected flag for a setter function allows to detect timeouts
340    /// and other error conditions calls of this setter as well. The device will then send a response
341    /// for this purpose. If this flag is disabled for a setter function then no response is sent
342    /// and errors are silently ignored, because they cannot be detected.
343    ///
344    /// See [`set_response_expected`](crate::accelerometer_v2_bricklet::AccelerometerV2Bricklet::set_response_expected) for the list of function ID constants available for this function.
345    pub fn get_response_expected(&mut self, fun: AccelerometerV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
346        self.device.get_response_expected(u8::from(fun))
347    }
348
349    /// Changes the response expected flag of the function specified by the function ID parameter.
350    /// This flag can only be changed for setter (default value: false) and callback configuration
351    /// functions (default value: true). For getter functions it is always enabled.
352    ///
353    /// Enabling the response expected flag for a setter function allows to detect timeouts and
354    /// other error conditions calls of this setter as well. The device will then send a response
355    /// for this purpose. If this flag is disabled for a setter function then no response is sent
356    /// and errors are silently ignored, because they cannot be detected.
357    pub fn set_response_expected(
358        &mut self,
359        fun: AccelerometerV2BrickletFunction,
360        response_expected: bool,
361    ) -> Result<(), SetResponseExpectedError> {
362        self.device.set_response_expected(u8::from(fun), response_expected)
363    }
364
365    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
366    pub fn set_response_expected_all(&mut self, response_expected: bool) {
367        self.device.set_response_expected_all(response_expected)
368    }
369
370    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
371    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
372    pub fn get_api_version(&self) -> [u8; 3] {
373        self.device.api_version
374    }
375
376    /// This receiver is triggered periodically according to the configuration set by
377    /// [`set_acceleration_callback_configuration`].
378    ///
379    /// The parameters are the same as [`get_acceleration`].
380    ///
381    /// [`get_acceleration`]: #method.get_acceleration
382    /// [`set_acceleration_callback_configuration`]: #method.set_acceleration_callback_configuration
383    pub async fn get_acceleration_callback_receiver(&mut self) -> impl Stream<Item = AccelerationEvent> {
384        self.device
385            .get_callback_receiver(u8::from(AccelerometerV2BrickletFunction::CallbackAcceleration))
386            .await
387            .map(|p| AccelerationEvent::from_le_byte_slice(p.body()))
388    }
389
390    /// Returns 30 acceleration values with 16 bit resolution. The data rate can
391    /// be configured with [`set_configuration`] and this receiver can be
392    /// enabled with [`set_continuous_acceleration_configuration`].
393    ///
394    /// The returned values are raw ADC data. If you want to put this data into
395    /// a FFT to determine the occurrences of specific frequencies we recommend
396    /// that you use the data as is. It has all of the ADC noise in it. This noise
397    /// looks like pure noise at first glance, but it might still have some frequnecy
398    /// information in it that can be utilized by the FFT.
399    ///
400    /// Otherwise you have to use the following formulas that depend on the
401    /// full scale range (see [`set_configuration`]) to calculate
402    /// the data in gₙ/10000 (same unit that is returned by [`get_acceleration`]):
403    ///
404    /// * Full scale 2g: acceleration = value * 625 / 1024
405    /// * Full scale 4g: acceleration = value * 1250 / 1024
406    /// * Full scale 8g: acceleration = value * 2500 / 1024
407    ///
408    /// The data is formated in the sequence x, y, z, x, y, z, ... depending on
409    /// the enabled axis. Examples:
410    ///
411    /// * x, y, z enabled: x, y, z, ... 10x repeated
412    /// * x, z enabled: x, z, ... 15x repeated
413    /// * y enabled: y, ... 30x repeated
414    pub async fn get_continuous_acceleration_16_bit_callback_receiver(&mut self) -> impl Stream<Item = [i16; 30]> {
415        self.device
416            .get_callback_receiver(u8::from(AccelerometerV2BrickletFunction::CallbackContinuousAcceleration16Bit))
417            .await
418            .map(|p| <[i16; 30]>::from_le_byte_slice(p.body()))
419    }
420
421    /// Returns 60 acceleration values with 8 bit resolution. The data rate can
422    /// be configured with [`set_configuration`] and this receiver can be
423    /// enabled with [`set_continuous_acceleration_configuration`].
424    ///
425    /// The returned values are raw ADC data. If you want to put this data into
426    /// a FFT to determine the occurrences of specific frequencies we recommend
427    /// that you use the data as is. It has all of the ADC noise in it. This noise
428    /// looks like pure noise at first glance, but it might still have some frequnecy
429    /// information in it that can be utilized by the FFT.
430    ///
431    /// Otherwise you have to use the following formulas that depend on the
432    /// full scale range (see [`set_configuration`]) to calculate
433    /// the data in gₙ/10000 (same unit that is returned by [`get_acceleration`]):
434    ///
435    /// * Full scale 2g: acceleration = value * 256 * 625 / 1024
436    /// * Full scale 4g: acceleration = value * 256 * 1250 / 1024
437    /// * Full scale 8g: acceleration = value * 256 * 2500 / 1024
438    ///
439    /// The data is formated in the sequence x, y, z, x, y, z, ... depending on
440    /// the enabled axis. Examples:
441    ///
442    /// * x, y, z enabled: x, y, z, ... 20x repeated
443    /// * x, z enabled: x, z, ... 30x repeated
444    /// * y enabled: y, ... 60x repeated
445    pub async fn get_continuous_acceleration_8_bit_callback_receiver(&mut self) -> impl Stream<Item = [i8; 60]> {
446        self.device
447            .get_callback_receiver(u8::from(AccelerometerV2BrickletFunction::CallbackContinuousAcceleration8Bit))
448            .await
449            .map(|p| <[i8; 60]>::from_le_byte_slice(p.body()))
450    }
451
452    /// Returns the acceleration in x, y and z direction. The values
453    /// are given in gₙ/10000 (1gₙ = 9.80665m/s²). The range is
454    /// configured with [`set_configuration`].
455    ///
456    /// If you want to get the acceleration periodically, it is recommended
457    /// to use the [`get_acceleration_callback_receiver`] receiver and set the period with
458    /// [`set_acceleration_callback_configuration`].
459    pub async fn get_acceleration(&mut self) -> Result<Acceleration, TinkerforgeError> {
460        let payload = [0; 0];
461
462        #[allow(unused_variables)]
463        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetAcceleration), &payload).await?;
464        Ok(Acceleration::from_le_byte_slice(result.body()))
465    }
466
467    /// Configures the data rate and full scale range.
468    /// Possible values are:
469    ///
470    /// * Data rate of 0.781Hz to 25600Hz.
471    /// * Full scale range of ±2g up to ±8g.
472    ///
473    /// Decreasing data rate or full scale range will also decrease the noise on
474    /// the data.
475    ///
476    /// Associated constants:
477    /// * ACCELEROMETER_V2_BRICKLET_DATA_RATE_0_781HZ
478    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_1_563HZ
479    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_3_125HZ
480    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_6_2512HZ
481    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_12_5HZ
482    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_25HZ
483    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_50HZ
484    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_100HZ
485    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_200HZ
486    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_400HZ
487    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_800HZ
488    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_1600HZ
489    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_3200HZ
490    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_6400HZ
491    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_12800HZ
492    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_25600HZ
493    ///	* ACCELEROMETER_V2_BRICKLET_FULL_SCALE_2G
494    ///	* ACCELEROMETER_V2_BRICKLET_FULL_SCALE_4G
495    ///	* ACCELEROMETER_V2_BRICKLET_FULL_SCALE_8G
496    pub async fn set_configuration(&mut self, data_rate: u8, full_scale: u8) -> Result<(), TinkerforgeError> {
497        let mut payload = [0; 2];
498        data_rate.write_to_slice(&mut payload[0..1]);
499        full_scale.write_to_slice(&mut payload[1..2]);
500
501        #[allow(unused_variables)]
502        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::SetConfiguration), &payload).await?;
503        Ok(())
504    }
505
506    /// Returns the configuration as set by [`set_configuration`].
507    ///
508    /// Associated constants:
509    /// * ACCELEROMETER_V2_BRICKLET_DATA_RATE_0_781HZ
510    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_1_563HZ
511    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_3_125HZ
512    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_6_2512HZ
513    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_12_5HZ
514    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_25HZ
515    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_50HZ
516    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_100HZ
517    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_200HZ
518    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_400HZ
519    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_800HZ
520    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_1600HZ
521    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_3200HZ
522    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_6400HZ
523    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_12800HZ
524    ///	* ACCELEROMETER_V2_BRICKLET_DATA_RATE_25600HZ
525    ///	* ACCELEROMETER_V2_BRICKLET_FULL_SCALE_2G
526    ///	* ACCELEROMETER_V2_BRICKLET_FULL_SCALE_4G
527    ///	* ACCELEROMETER_V2_BRICKLET_FULL_SCALE_8G
528    pub async fn get_configuration(&mut self) -> Result<Configuration, TinkerforgeError> {
529        let payload = [0; 0];
530
531        #[allow(unused_variables)]
532        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetConfiguration), &payload).await?;
533        Ok(Configuration::from_le_byte_slice(result.body()))
534    }
535
536    /// The period is the period with which the [`get_acceleration_callback_receiver`]
537    /// receiver is triggered periodically. A value of 0 turns the receiver off.
538    ///
539    /// If the `value has to change`-parameter is set to true, the receiver is only
540    /// triggered after the value has changed. If the value didn't change within the
541    /// period, the receiver is triggered immediately on change.
542    ///
543    /// If it is set to false, the receiver is continuously triggered with the period,
544    /// independent of the value.
545    ///
546    /// If this receiver is enabled, the [`get_continuous_acceleration_16_bit_callback_receiver`] receiver
547    /// and [`get_continuous_acceleration_8_bit_callback_receiver`] receiver will automatically be disabled.
548    pub async fn set_acceleration_callback_configuration(
549        &mut self,
550        period: u32,
551        value_has_to_change: bool,
552    ) -> Result<(), TinkerforgeError> {
553        let mut payload = [0; 5];
554        period.write_to_slice(&mut payload[0..4]);
555        value_has_to_change.write_to_slice(&mut payload[4..5]);
556
557        #[allow(unused_variables)]
558        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::SetAccelerationCallbackConfiguration), &payload).await?;
559        Ok(())
560    }
561
562    /// Returns the receiver configuration as set by
563    /// [`set_acceleration_callback_configuration`].
564    pub async fn get_acceleration_callback_configuration(&mut self) -> Result<AccelerationCallbackConfiguration, TinkerforgeError> {
565        let payload = [0; 0];
566
567        #[allow(unused_variables)]
568        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetAccelerationCallbackConfiguration), &payload).await?;
569        Ok(AccelerationCallbackConfiguration::from_le_byte_slice(result.body()))
570    }
571
572    /// Configures the info LED (marked as Force on the Bricklet) to be either turned off,
573    /// turned on, or blink in heartbeat mode.
574    ///
575    /// Associated constants:
576    /// * ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_OFF
577    ///	* ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_ON
578    ///	* ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_SHOW_HEARTBEAT
579    pub async fn set_info_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
580        let mut payload = [0; 1];
581        config.write_to_slice(&mut payload[0..1]);
582
583        #[allow(unused_variables)]
584        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::SetInfoLedConfig), &payload).await?;
585        Ok(())
586    }
587
588    /// Returns the LED configuration as set by [`set_info_led_config`]
589    ///
590    /// Associated constants:
591    /// * ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_OFF
592    ///	* ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_ON
593    ///	* ACCELEROMETER_V2_BRICKLET_INFO_LED_CONFIG_SHOW_HEARTBEAT
594    pub async fn get_info_led_config(&mut self) -> Result<u8, TinkerforgeError> {
595        let payload = [0; 0];
596
597        #[allow(unused_variables)]
598        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetInfoLedConfig), &payload).await?;
599        Ok(u8::from_le_byte_slice(result.body()))
600    }
601
602    /// For high throughput of acceleration data (> 1000Hz) you have to use the
603    /// [`get_continuous_acceleration_16_bit_callback_receiver`] or [`get_continuous_acceleration_8_bit_callback_receiver`]
604    /// callbacks.
605    ///
606    /// You can enable the receiver for each axis (x, y, z) individually and choose a
607    /// resolution of 8 bit or 16 bit.
608    ///
609    /// If at least one of the axis is enabled and the resolution is set to 8 bit,
610    /// the [`get_continuous_acceleration_8_bit_callback_receiver`] receiver is activated. If at least
611    /// one of the axis is enabled and the resolution is set to 16 bit,
612    /// the [`get_continuous_acceleration_16_bit_callback_receiver`] receiver is activated.
613    ///
614    /// The returned values are raw ADC data. If you want to put this data into
615    /// a FFT to determine the occurrences of specific frequencies we recommend
616    /// that you use the data as is. It has all of the ADC noise in it. This noise
617    /// looks like pure noise at first glance, but it might still have some frequnecy
618    /// information in it that can be utilized by the FFT.
619    ///
620    /// Otherwise you have to use the following formulas that depend on the configured
621    /// resolution (8/16 bit) and the full scale range (see [`set_configuration`]) to calculate
622    /// the data in gₙ/10000 (same unit that is returned by [`get_acceleration`]):
623    ///
624    /// * 16 bit, full scale 2g: acceleration = value * 625 / 1024
625    /// * 16 bit, full scale 4g: acceleration = value * 1250 / 1024
626    /// * 16 bit, full scale 8g: acceleration = value * 2500 / 1024
627    ///
628    /// If a resolution of 8 bit is used, only the 8 most significant bits will be
629    /// transferred, so you can use the following formulas:
630    ///
631    /// * 8 bit, full scale 2g: acceleration = value * 256 * 625 / 1024
632    /// * 8 bit, full scale 4g: acceleration = value * 256 * 1250 / 1024
633    /// * 8 bit, full scale 8g: acceleration = value * 256 * 2500 / 1024
634    ///
635    /// If no axis is enabled, both receivers are disabled. If one of the continuous
636    /// callbacks is enabled, the [`get_acceleration_callback_receiver`] receiver is disabled.
637    ///
638    /// The maximum throughput depends on the exact configuration:
639    ///
640    ///  Number of axis enabled| Throughput 8 bit| Throughout 16 bit
641    ///  --- | --- | ---
642    ///  1| 25600Hz| 25600Hz
643    ///  2| 25600Hz| 15000Hz
644    ///  3| 20000Hz| 10000Hz
645    ///
646    /// Associated constants:
647    /// * ACCELEROMETER_V2_BRICKLET_RESOLUTION_8BIT
648    ///	* ACCELEROMETER_V2_BRICKLET_RESOLUTION_16BIT
649    pub async fn set_continuous_acceleration_configuration(
650        &mut self,
651        enable_x: bool,
652        enable_y: bool,
653        enable_z: bool,
654        resolution: u8,
655    ) -> Result<(), TinkerforgeError> {
656        let mut payload = [0; 4];
657        enable_x.write_to_slice(&mut payload[0..1]);
658        enable_y.write_to_slice(&mut payload[1..2]);
659        enable_z.write_to_slice(&mut payload[2..3]);
660        resolution.write_to_slice(&mut payload[3..4]);
661
662        #[allow(unused_variables)]
663        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::SetContinuousAccelerationConfiguration), &payload).await?;
664        Ok(())
665    }
666
667    /// Returns the continuous acceleration configuration as set by
668    /// [`set_continuous_acceleration_configuration`].
669    ///
670    /// Associated constants:
671    /// * ACCELEROMETER_V2_BRICKLET_RESOLUTION_8BIT
672    ///	* ACCELEROMETER_V2_BRICKLET_RESOLUTION_16BIT
673    pub async fn get_continuous_acceleration_configuration(&mut self) -> Result<ContinuousAccelerationConfiguration, TinkerforgeError> {
674        let payload = [0; 0];
675
676        #[allow(unused_variables)]
677        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetContinuousAccelerationConfiguration), &payload).await?;
678        Ok(ContinuousAccelerationConfiguration::from_le_byte_slice(result.body()))
679    }
680
681    /// Configures IIR Bypass filter mode and low pass filter roll off corner frequency.
682    ///
683    /// The filter can be applied or bypassed and the corner frequency can be
684    /// half or a ninth of the output data rate.
685    ///
686    /// .. image:: /Images/Bricklets/bricklet_accelerometer_v2_filter.png
687    ///    :scale: 100 %
688    ///    :alt: Accelerometer filter
689    ///    :align: center
690    ///    :target: ../../_images/Bricklets/bricklet_accelerometer_v2_filter.png
691    ///
692    ///
693    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
694    ///
695    /// Associated constants:
696    /// * ACCELEROMETER_V2_BRICKLET_IIR_BYPASS_APPLIED
697    ///	* ACCELEROMETER_V2_BRICKLET_IIR_BYPASS_BYPASSED
698    ///	* ACCELEROMETER_V2_BRICKLET_LOW_PASS_FILTER_NINTH
699    ///	* ACCELEROMETER_V2_BRICKLET_LOW_PASS_FILTER_HALF
700    pub async fn set_filter_configuration(&mut self, iir_bypass: u8, low_pass_filter: u8) -> Result<(), TinkerforgeError> {
701        let mut payload = [0; 2];
702        iir_bypass.write_to_slice(&mut payload[0..1]);
703        low_pass_filter.write_to_slice(&mut payload[1..2]);
704
705        #[allow(unused_variables)]
706        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::SetFilterConfiguration), &payload).await?;
707        Ok(())
708    }
709
710    /// Returns the configuration as set by [`set_filter_configuration`].
711    ///
712    ///
713    /// .. versionadded:: 2.0.2$nbsp;(Plugin)
714    ///
715    /// Associated constants:
716    /// * ACCELEROMETER_V2_BRICKLET_IIR_BYPASS_APPLIED
717    ///	* ACCELEROMETER_V2_BRICKLET_IIR_BYPASS_BYPASSED
718    ///	* ACCELEROMETER_V2_BRICKLET_LOW_PASS_FILTER_NINTH
719    ///	* ACCELEROMETER_V2_BRICKLET_LOW_PASS_FILTER_HALF
720    pub async fn get_filter_configuration(&mut self) -> Result<FilterConfiguration, TinkerforgeError> {
721        let payload = [0; 0];
722
723        #[allow(unused_variables)]
724        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetFilterConfiguration), &payload).await?;
725        Ok(FilterConfiguration::from_le_byte_slice(result.body()))
726    }
727
728    /// Returns the error count for the communication between Brick and Bricklet.
729    ///
730    /// The errors are divided into
731    ///
732    /// * ACK checksum errors,
733    /// * message checksum errors,
734    /// * framing errors and
735    /// * overflow errors.
736    ///
737    /// The errors counts are for errors that occur on the Bricklet side. All
738    /// Bricks have a similar function that returns the errors on the Brick side.
739    pub async fn get_spitfp_error_count(&mut self) -> Result<SpitfpErrorCount, TinkerforgeError> {
740        let payload = [0; 0];
741
742        #[allow(unused_variables)]
743        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetSpitfpErrorCount), &payload).await?;
744        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
745    }
746
747    /// Sets the bootloader mode and returns the status after the requested
748    /// mode change was instigated.
749    ///
750    /// You can change from bootloader mode to firmware mode and vice versa. A change
751    /// from bootloader mode to firmware mode will only take place if the entry function,
752    /// device identifier and CRC are present and correct.
753    ///
754    /// This function is used by Brick Viewer during flashing. It should not be
755    /// necessary to call it in a normal user program.
756    ///
757    /// Associated constants:
758    /// * ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
759    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
760    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
761    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
762    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
763    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_OK
764    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
765    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
766    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
767    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
768    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
769    pub async fn set_bootloader_mode(&mut self, mode: u8) -> Result<u8, TinkerforgeError> {
770        let mut payload = [0; 1];
771        mode.write_to_slice(&mut payload[0..1]);
772
773        #[allow(unused_variables)]
774        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::SetBootloaderMode), &payload).await?;
775        Ok(u8::from_le_byte_slice(result.body()))
776    }
777
778    /// Returns the current bootloader mode, see [`set_bootloader_mode`].
779    ///
780    /// Associated constants:
781    /// * ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
782    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
783    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
784    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
785    ///	* ACCELEROMETER_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
786    pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError> {
787        let payload = [0; 0];
788
789        #[allow(unused_variables)]
790        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetBootloaderMode), &payload).await?;
791        Ok(u8::from_le_byte_slice(result.body()))
792    }
793
794    /// Sets the firmware pointer for [`write_firmware`]. The pointer has
795    /// to be increased by chunks of size 64. The data is written to flash
796    /// every 4 chunks (which equals to one page of size 256).
797    ///
798    /// This function is used by Brick Viewer during flashing. It should not be
799    /// necessary to call it in a normal user program.
800    pub async fn set_write_firmware_pointer(&mut self, pointer: u32) -> Result<(), TinkerforgeError> {
801        let mut payload = [0; 4];
802        pointer.write_to_slice(&mut payload[0..4]);
803
804        #[allow(unused_variables)]
805        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::SetWriteFirmwarePointer), &payload).await?;
806        Ok(())
807    }
808
809    /// Writes 64 Bytes of firmware at the position as written by
810    /// [`set_write_firmware_pointer`] before. The firmware is written
811    /// to flash every 4 chunks.
812    ///
813    /// You can only write firmware in bootloader mode.
814    ///
815    /// This function is used by Brick Viewer during flashing. It should not be
816    /// necessary to call it in a normal user program.
817    pub async fn write_firmware(&mut self, data: &[u8; 64]) -> Result<u8, TinkerforgeError> {
818        let mut payload = [0; 64];
819        data.write_to_slice(&mut payload[0..64]);
820
821        #[allow(unused_variables)]
822        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::WriteFirmware), &payload).await?;
823        Ok(u8::from_le_byte_slice(result.body()))
824    }
825
826    /// Sets the status LED configuration. By default the LED shows
827    /// communication traffic between Brick and Bricklet, it flickers once
828    /// for every 10 received data packets.
829    ///
830    /// You can also turn the LED permanently on/off or show a heartbeat.
831    ///
832    /// If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
833    ///
834    /// Associated constants:
835    /// * ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_OFF
836    ///	* ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_ON
837    ///	* ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
838    ///	* ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
839    pub async fn set_status_led_config(&mut self, config: u8) -> Result<(), TinkerforgeError> {
840        let mut payload = [0; 1];
841        config.write_to_slice(&mut payload[0..1]);
842
843        #[allow(unused_variables)]
844        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::SetStatusLedConfig), &payload).await?;
845        Ok(())
846    }
847
848    /// Returns the configuration as set by [`set_status_led_config`]
849    ///
850    /// Associated constants:
851    /// * ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_OFF
852    ///	* ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_ON
853    ///	* ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
854    ///	* ACCELEROMETER_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
855    pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError> {
856        let payload = [0; 0];
857
858        #[allow(unused_variables)]
859        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetStatusLedConfig), &payload).await?;
860        Ok(u8::from_le_byte_slice(result.body()))
861    }
862
863    /// Returns the temperature as measured inside the microcontroller. The
864    /// value returned is not the ambient temperature!
865    ///
866    /// The temperature is only proportional to the real temperature and it has bad
867    /// accuracy. Practically it is only useful as an indicator for
868    /// temperature changes.
869    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
870        let payload = [0; 0];
871
872        #[allow(unused_variables)]
873        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetChipTemperature), &payload).await?;
874        Ok(i16::from_le_byte_slice(result.body()))
875    }
876
877    /// Calling this function will reset the Bricklet. All configurations
878    /// will be lost.
879    ///
880    /// After a reset you have to create new device objects,
881    /// calling functions on the existing ones will result in
882    /// undefined behavior!
883    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
884        let payload = [0; 0];
885
886        #[allow(unused_variables)]
887        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::Reset), &payload).await?;
888        Ok(())
889    }
890
891    /// Writes a new UID into flash. If you want to set a new UID
892    /// you have to decode the Base58 encoded UID string into an
893    /// integer first.
894    ///
895    /// We recommend that you use Brick Viewer to change the UID.
896    pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError> {
897        let mut payload = [0; 4];
898        uid.write_to_slice(&mut payload[0..4]);
899
900        #[allow(unused_variables)]
901        let result = self.device.set(u8::from(AccelerometerV2BrickletFunction::WriteUid), &payload).await?;
902        Ok(())
903    }
904
905    /// Returns the current UID as an integer. Encode as
906    /// Base58 to get the usual string version.
907    pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError> {
908        let payload = [0; 0];
909
910        #[allow(unused_variables)]
911        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::ReadUid), &payload).await?;
912        Ok(u32::from_le_byte_slice(result.body()))
913    }
914
915    /// Returns the UID, the UID where the Bricklet is connected to,
916    /// the position, the hardware and firmware version as well as the
917    /// device identifier.
918    ///
919    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
920    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
921    /// position 'z'.
922    ///
923    /// The device identifier numbers can be found [here](device_identifier).
924    /// |device_identifier_constant|
925    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
926        let payload = [0; 0];
927
928        #[allow(unused_variables)]
929        let result = self.device.get(u8::from(AccelerometerV2BrickletFunction::GetIdentity), &payload).await?;
930        Ok(Identity::from_le_byte_slice(result.body()))
931    }
932}