tinkerforge_async/bindings/
accelerometer_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/Accelerometer_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 AccelerometerBrickletFunction {
24    GetAcceleration,
25    SetAccelerationCallbackPeriod,
26    GetAccelerationCallbackPeriod,
27    SetAccelerationCallbackThreshold,
28    GetAccelerationCallbackThreshold,
29    SetDebouncePeriod,
30    GetDebouncePeriod,
31    GetTemperature,
32    SetConfiguration,
33    GetConfiguration,
34    LedOn,
35    LedOff,
36    IsLedOn,
37    GetIdentity,
38    CallbackAcceleration,
39    CallbackAccelerationReached,
40}
41impl From<AccelerometerBrickletFunction> for u8 {
42    fn from(fun: AccelerometerBrickletFunction) -> Self {
43        match fun {
44            AccelerometerBrickletFunction::GetAcceleration => 1,
45            AccelerometerBrickletFunction::SetAccelerationCallbackPeriod => 2,
46            AccelerometerBrickletFunction::GetAccelerationCallbackPeriod => 3,
47            AccelerometerBrickletFunction::SetAccelerationCallbackThreshold => 4,
48            AccelerometerBrickletFunction::GetAccelerationCallbackThreshold => 5,
49            AccelerometerBrickletFunction::SetDebouncePeriod => 6,
50            AccelerometerBrickletFunction::GetDebouncePeriod => 7,
51            AccelerometerBrickletFunction::GetTemperature => 8,
52            AccelerometerBrickletFunction::SetConfiguration => 9,
53            AccelerometerBrickletFunction::GetConfiguration => 10,
54            AccelerometerBrickletFunction::LedOn => 11,
55            AccelerometerBrickletFunction::LedOff => 12,
56            AccelerometerBrickletFunction::IsLedOn => 13,
57            AccelerometerBrickletFunction::GetIdentity => 255,
58            AccelerometerBrickletFunction::CallbackAcceleration => 14,
59            AccelerometerBrickletFunction::CallbackAccelerationReached => 15,
60        }
61    }
62}
63pub const ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_OFF: char = 'x';
64pub const ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE: char = 'o';
65pub const ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE: char = 'i';
66pub const ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER: char = '<';
67pub const ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_GREATER: char = '>';
68pub const ACCELEROMETER_BRICKLET_DATA_RATE_OFF: u8 = 0;
69pub const ACCELEROMETER_BRICKLET_DATA_RATE_3HZ: u8 = 1;
70pub const ACCELEROMETER_BRICKLET_DATA_RATE_6HZ: u8 = 2;
71pub const ACCELEROMETER_BRICKLET_DATA_RATE_12HZ: u8 = 3;
72pub const ACCELEROMETER_BRICKLET_DATA_RATE_25HZ: u8 = 4;
73pub const ACCELEROMETER_BRICKLET_DATA_RATE_50HZ: u8 = 5;
74pub const ACCELEROMETER_BRICKLET_DATA_RATE_100HZ: u8 = 6;
75pub const ACCELEROMETER_BRICKLET_DATA_RATE_400HZ: u8 = 7;
76pub const ACCELEROMETER_BRICKLET_DATA_RATE_800HZ: u8 = 8;
77pub const ACCELEROMETER_BRICKLET_DATA_RATE_1600HZ: u8 = 9;
78pub const ACCELEROMETER_BRICKLET_FULL_SCALE_2G: u8 = 0;
79pub const ACCELEROMETER_BRICKLET_FULL_SCALE_4G: u8 = 1;
80pub const ACCELEROMETER_BRICKLET_FULL_SCALE_6G: u8 = 2;
81pub const ACCELEROMETER_BRICKLET_FULL_SCALE_8G: u8 = 3;
82pub const ACCELEROMETER_BRICKLET_FULL_SCALE_16G: u8 = 4;
83pub const ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_800HZ: u8 = 0;
84pub const ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_400HZ: u8 = 1;
85pub const ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_200HZ: u8 = 2;
86pub const ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_50HZ: u8 = 3;
87
88#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
89pub struct Acceleration {
90    pub x: i16,
91    pub y: i16,
92    pub z: i16,
93}
94impl FromByteSlice for Acceleration {
95    fn bytes_expected() -> usize {
96        6
97    }
98    fn from_le_byte_slice(bytes: &[u8]) -> Acceleration {
99        Acceleration {
100            x: <i16>::from_le_byte_slice(&bytes[0..2]),
101            y: <i16>::from_le_byte_slice(&bytes[2..4]),
102            z: <i16>::from_le_byte_slice(&bytes[4..6]),
103        }
104    }
105}
106
107#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
108pub struct AccelerationCallbackThreshold {
109    pub option: char,
110    pub min_x: i16,
111    pub max_x: i16,
112    pub min_y: i16,
113    pub max_y: i16,
114    pub min_z: i16,
115    pub max_z: i16,
116}
117impl FromByteSlice for AccelerationCallbackThreshold {
118    fn bytes_expected() -> usize {
119        13
120    }
121    fn from_le_byte_slice(bytes: &[u8]) -> AccelerationCallbackThreshold {
122        AccelerationCallbackThreshold {
123            option: <char>::from_le_byte_slice(&bytes[0..1]),
124            min_x: <i16>::from_le_byte_slice(&bytes[1..3]),
125            max_x: <i16>::from_le_byte_slice(&bytes[3..5]),
126            min_y: <i16>::from_le_byte_slice(&bytes[5..7]),
127            max_y: <i16>::from_le_byte_slice(&bytes[7..9]),
128            min_z: <i16>::from_le_byte_slice(&bytes[9..11]),
129            max_z: <i16>::from_le_byte_slice(&bytes[11..13]),
130        }
131    }
132}
133
134#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
135pub struct Configuration {
136    pub data_rate: u8,
137    pub full_scale: u8,
138    pub filter_bandwidth: u8,
139}
140impl FromByteSlice for Configuration {
141    fn bytes_expected() -> usize {
142        3
143    }
144    fn from_le_byte_slice(bytes: &[u8]) -> Configuration {
145        Configuration {
146            data_rate: <u8>::from_le_byte_slice(&bytes[0..1]),
147            full_scale: <u8>::from_le_byte_slice(&bytes[1..2]),
148            filter_bandwidth: <u8>::from_le_byte_slice(&bytes[2..3]),
149        }
150    }
151}
152
153#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
154pub struct AccelerationEvent {
155    pub x: i16,
156    pub y: i16,
157    pub z: i16,
158}
159impl FromByteSlice for AccelerationEvent {
160    fn bytes_expected() -> usize {
161        6
162    }
163    fn from_le_byte_slice(bytes: &[u8]) -> AccelerationEvent {
164        AccelerationEvent {
165            x: <i16>::from_le_byte_slice(&bytes[0..2]),
166            y: <i16>::from_le_byte_slice(&bytes[2..4]),
167            z: <i16>::from_le_byte_slice(&bytes[4..6]),
168        }
169    }
170}
171
172#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
173pub struct AccelerationReachedEvent {
174    pub x: i16,
175    pub y: i16,
176    pub z: i16,
177}
178impl FromByteSlice for AccelerationReachedEvent {
179    fn bytes_expected() -> usize {
180        6
181    }
182    fn from_le_byte_slice(bytes: &[u8]) -> AccelerationReachedEvent {
183        AccelerationReachedEvent {
184            x: <i16>::from_le_byte_slice(&bytes[0..2]),
185            y: <i16>::from_le_byte_slice(&bytes[2..4]),
186            z: <i16>::from_le_byte_slice(&bytes[4..6]),
187        }
188    }
189}
190
191#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
192pub struct Identity {
193    pub uid: String,
194    pub connected_uid: String,
195    pub position: char,
196    pub hardware_version: [u8; 3],
197    pub firmware_version: [u8; 3],
198    pub device_identifier: u16,
199}
200impl FromByteSlice for Identity {
201    fn bytes_expected() -> usize {
202        25
203    }
204    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
205        Identity {
206            uid: <String>::from_le_byte_slice(&bytes[0..8]),
207            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
208            position: <char>::from_le_byte_slice(&bytes[16..17]),
209            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
210            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
211            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
212        }
213    }
214}
215
216/// Measures acceleration in three axis
217#[derive(Clone)]
218pub struct AccelerometerBricklet {
219    device: Device,
220}
221impl AccelerometerBricklet {
222    pub const DEVICE_IDENTIFIER: u16 = 250;
223    pub const DEVICE_DISPLAY_NAME: &'static str = "Accelerometer Bricklet";
224    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
225    pub fn new(uid: Uid, connection: AsyncIpConnection) -> AccelerometerBricklet {
226        let mut result = AccelerometerBricklet { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
227        result.device.response_expected[u8::from(AccelerometerBrickletFunction::GetAcceleration) as usize] =
228            ResponseExpectedFlag::AlwaysTrue;
229        result.device.response_expected[u8::from(AccelerometerBrickletFunction::SetAccelerationCallbackPeriod) as usize] =
230            ResponseExpectedFlag::True;
231        result.device.response_expected[u8::from(AccelerometerBrickletFunction::GetAccelerationCallbackPeriod) as usize] =
232            ResponseExpectedFlag::AlwaysTrue;
233        result.device.response_expected[u8::from(AccelerometerBrickletFunction::SetAccelerationCallbackThreshold) as usize] =
234            ResponseExpectedFlag::True;
235        result.device.response_expected[u8::from(AccelerometerBrickletFunction::GetAccelerationCallbackThreshold) as usize] =
236            ResponseExpectedFlag::AlwaysTrue;
237        result.device.response_expected[u8::from(AccelerometerBrickletFunction::SetDebouncePeriod) as usize] = ResponseExpectedFlag::True;
238        result.device.response_expected[u8::from(AccelerometerBrickletFunction::GetDebouncePeriod) as usize] =
239            ResponseExpectedFlag::AlwaysTrue;
240        result.device.response_expected[u8::from(AccelerometerBrickletFunction::GetTemperature) as usize] =
241            ResponseExpectedFlag::AlwaysTrue;
242        result.device.response_expected[u8::from(AccelerometerBrickletFunction::SetConfiguration) as usize] = ResponseExpectedFlag::False;
243        result.device.response_expected[u8::from(AccelerometerBrickletFunction::GetConfiguration) as usize] =
244            ResponseExpectedFlag::AlwaysTrue;
245        result.device.response_expected[u8::from(AccelerometerBrickletFunction::LedOn) as usize] = ResponseExpectedFlag::False;
246        result.device.response_expected[u8::from(AccelerometerBrickletFunction::LedOff) as usize] = ResponseExpectedFlag::False;
247        result.device.response_expected[u8::from(AccelerometerBrickletFunction::IsLedOn) as usize] = ResponseExpectedFlag::AlwaysTrue;
248        result.device.response_expected[u8::from(AccelerometerBrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
249        result
250    }
251
252    /// Returns the response expected flag for the function specified by the function ID parameter.
253    /// It is true if the function is expected to send a response, false otherwise.
254    ///
255    /// For getter functions this is enabled by default and cannot be disabled, because those
256    /// functions will always send a response. For callback configuration functions it is enabled
257    /// by default too, but can be disabled by [`set_response_expected`](crate::accelerometer_bricklet::AccelerometerBricklet::set_response_expected).
258    /// For setter functions it is disabled by default and can be enabled.
259    ///
260    /// Enabling the response expected flag for a setter function allows to detect timeouts
261    /// and other error conditions calls of this setter as well. The device will then send a response
262    /// for this purpose. If this flag is disabled for a setter function then no response is sent
263    /// and errors are silently ignored, because they cannot be detected.
264    ///
265    /// See [`set_response_expected`](crate::accelerometer_bricklet::AccelerometerBricklet::set_response_expected) for the list of function ID constants available for this function.
266    pub fn get_response_expected(&mut self, fun: AccelerometerBrickletFunction) -> Result<bool, GetResponseExpectedError> {
267        self.device.get_response_expected(u8::from(fun))
268    }
269
270    /// Changes the response expected flag of the function specified by the function ID parameter.
271    /// This flag can only be changed for setter (default value: false) and callback configuration
272    /// functions (default value: true). For getter functions it is always enabled.
273    ///
274    /// Enabling the response expected flag for a setter function allows to detect timeouts and
275    /// other error conditions calls of this setter as well. The device will then send a response
276    /// for this purpose. If this flag is disabled for a setter function then no response is sent
277    /// and errors are silently ignored, because they cannot be detected.
278    pub fn set_response_expected(
279        &mut self,
280        fun: AccelerometerBrickletFunction,
281        response_expected: bool,
282    ) -> Result<(), SetResponseExpectedError> {
283        self.device.set_response_expected(u8::from(fun), response_expected)
284    }
285
286    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
287    pub fn set_response_expected_all(&mut self, response_expected: bool) {
288        self.device.set_response_expected_all(response_expected)
289    }
290
291    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
292    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
293    pub fn get_api_version(&self) -> [u8; 3] {
294        self.device.api_version
295    }
296
297    /// This receiver is triggered periodically with the period that is set by
298    /// [`set_acceleration_callback_period`]. The parameters are the
299    /// X, Y and Z acceleration. The range is
300    /// configured with [`set_configuration`].
301    ///
302    /// The [`get_acceleration_callback_receiver`] receiver is only triggered if the acceleration has
303    /// changed since the last triggering.
304    ///
305    /// [`set_acceleration_callback_period`]: #method.set_acceleration_callback_period
306    /// [`set_configuration`]: #method.set_configuration
307    /// [`get_acceleration_callback_receiver`]: #method.get_acceleration_callback_receiver
308    pub async fn get_acceleration_callback_receiver(&mut self) -> impl Stream<Item = AccelerationEvent> {
309        self.device
310            .get_callback_receiver(u8::from(AccelerometerBrickletFunction::CallbackAcceleration))
311            .await
312            .map(|p| AccelerationEvent::from_le_byte_slice(p.body()))
313    }
314
315    /// This receiver is triggered when the threshold as set by
316    /// [`set_acceleration_callback_threshold`] is reached.
317    /// The parameters are the X, Y and Z acceleration. The range is
318    /// configured with [`set_configuration`].
319    ///
320    /// If the threshold keeps being reached, the receiver is triggered periodically
321    /// with the period as set by [`set_debounce_period`].
322    pub async fn get_acceleration_reached_callback_receiver(&mut self) -> impl Stream<Item = AccelerationReachedEvent> {
323        self.device
324            .get_callback_receiver(u8::from(AccelerometerBrickletFunction::CallbackAccelerationReached))
325            .await
326            .map(|p| AccelerationReachedEvent::from_le_byte_slice(p.body()))
327    }
328
329    /// Returns the acceleration in x, y and z direction. The values
330    /// are given in gₙ/1000 (1gₙ = 9.80665m/s²). The range is
331    /// configured with [`set_configuration`].
332    ///
333    /// If you want to get the acceleration periodically, it is recommended
334    /// to use the [`get_acceleration_callback_receiver`] receiver and set the period with
335    /// [`set_acceleration_callback_period`].
336    pub async fn get_acceleration(&mut self) -> Result<Acceleration, TinkerforgeError> {
337        let payload = [0; 0];
338
339        #[allow(unused_variables)]
340        let result = self.device.get(u8::from(AccelerometerBrickletFunction::GetAcceleration), &payload).await?;
341        Ok(Acceleration::from_le_byte_slice(result.body()))
342    }
343
344    /// Sets the period with which the [`get_acceleration_callback_receiver`] receiver is triggered
345    /// periodically. A value of 0 turns the receiver off.
346    ///
347    /// The [`get_acceleration_callback_receiver`] receiver is only triggered if the acceleration has
348    /// changed since the last triggering.
349    pub async fn set_acceleration_callback_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
350        let mut payload = [0; 4];
351        period.write_to_slice(&mut payload[0..4]);
352
353        #[allow(unused_variables)]
354        let result = self.device.set(u8::from(AccelerometerBrickletFunction::SetAccelerationCallbackPeriod), &payload).await?;
355        Ok(())
356    }
357
358    /// Returns the period as set by [`set_acceleration_callback_period`].
359    pub async fn get_acceleration_callback_period(&mut self) -> Result<u32, TinkerforgeError> {
360        let payload = [0; 0];
361
362        #[allow(unused_variables)]
363        let result = self.device.get(u8::from(AccelerometerBrickletFunction::GetAccelerationCallbackPeriod), &payload).await?;
364        Ok(u32::from_le_byte_slice(result.body()))
365    }
366
367    /// Sets the thresholds for the [`get_acceleration_reached_callback_receiver`] receiver.
368    ///
369    /// The following options are possible:
370    ///
371    ///  Option| Description
372    ///  --- | ---
373    ///  'x'|    Receiver is turned off
374    ///  'o'|    Receiver is triggered when the acceleration is *outside* the min and max values
375    ///  'i'|    Receiver is triggered when the acceleration is *inside* the min and max values
376    ///  '<'|    Receiver is triggered when the acceleration is smaller than the min value (max is ignored)
377    ///  '>'|    Receiver is triggered when the acceleration is greater than the min value (max is ignored)
378    ///
379    /// Associated constants:
380    /// * ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_OFF
381    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
382    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE
383    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER
384    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_GREATER
385    pub async fn set_acceleration_callback_threshold(
386        &mut self,
387        option: char,
388        min_x: i16,
389        max_x: i16,
390        min_y: i16,
391        max_y: i16,
392        min_z: i16,
393        max_z: i16,
394    ) -> Result<(), TinkerforgeError> {
395        let mut payload = [0; 13];
396        option.write_to_slice(&mut payload[0..1]);
397        min_x.write_to_slice(&mut payload[1..3]);
398        max_x.write_to_slice(&mut payload[3..5]);
399        min_y.write_to_slice(&mut payload[5..7]);
400        max_y.write_to_slice(&mut payload[7..9]);
401        min_z.write_to_slice(&mut payload[9..11]);
402        max_z.write_to_slice(&mut payload[11..13]);
403
404        #[allow(unused_variables)]
405        let result = self.device.set(u8::from(AccelerometerBrickletFunction::SetAccelerationCallbackThreshold), &payload).await?;
406        Ok(())
407    }
408
409    /// Returns the threshold as set by [`set_acceleration_callback_threshold`].
410    ///
411    /// Associated constants:
412    /// * ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_OFF
413    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_OUTSIDE
414    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_INSIDE
415    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_SMALLER
416    ///	* ACCELEROMETER_BRICKLET_THRESHOLD_OPTION_GREATER
417    pub async fn get_acceleration_callback_threshold(&mut self) -> Result<AccelerationCallbackThreshold, TinkerforgeError> {
418        let payload = [0; 0];
419
420        #[allow(unused_variables)]
421        let result = self.device.get(u8::from(AccelerometerBrickletFunction::GetAccelerationCallbackThreshold), &payload).await?;
422        Ok(AccelerationCallbackThreshold::from_le_byte_slice(result.body()))
423    }
424
425    /// Sets the period with which the threshold receiver
426    ///
427    /// * [`get_acceleration_reached_callback_receiver`]
428    ///
429    /// is triggered, if the threshold
430    ///
431    /// * [`set_acceleration_callback_threshold`]
432    ///
433    /// keeps being reached.
434    pub async fn set_debounce_period(&mut self, debounce: u32) -> Result<(), TinkerforgeError> {
435        let mut payload = [0; 4];
436        debounce.write_to_slice(&mut payload[0..4]);
437
438        #[allow(unused_variables)]
439        let result = self.device.set(u8::from(AccelerometerBrickletFunction::SetDebouncePeriod), &payload).await?;
440        Ok(())
441    }
442
443    /// Returns the debounce period as set by [`set_debounce_period`].
444    pub async fn get_debounce_period(&mut self) -> Result<u32, TinkerforgeError> {
445        let payload = [0; 0];
446
447        #[allow(unused_variables)]
448        let result = self.device.get(u8::from(AccelerometerBrickletFunction::GetDebouncePeriod), &payload).await?;
449        Ok(u32::from_le_byte_slice(result.body()))
450    }
451
452    /// Returns the temperature of the accelerometer.
453    pub async fn get_temperature(&mut self) -> Result<i16, TinkerforgeError> {
454        let payload = [0; 0];
455
456        #[allow(unused_variables)]
457        let result = self.device.get(u8::from(AccelerometerBrickletFunction::GetTemperature), &payload).await?;
458        Ok(i16::from_le_byte_slice(result.body()))
459    }
460
461    /// Configures the data rate, full scale range and filter bandwidth.
462    /// Possible values are:
463    ///
464    /// * Data rate of 0Hz to 1600Hz.
465    /// * Full scale range of ±2gₙ up to ±16gₙ.
466    /// * Filter bandwidth between 50Hz and 800Hz.
467    ///
468    /// Decreasing data rate or full scale range will also decrease the noise on
469    /// the data.
470    ///
471    /// Associated constants:
472    /// * ACCELEROMETER_BRICKLET_DATA_RATE_OFF
473    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_3HZ
474    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_6HZ
475    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_12HZ
476    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_25HZ
477    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_50HZ
478    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_100HZ
479    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_400HZ
480    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_800HZ
481    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_1600HZ
482    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_2G
483    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_4G
484    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_6G
485    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_8G
486    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_16G
487    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_800HZ
488    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_400HZ
489    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_200HZ
490    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_50HZ
491    pub async fn set_configuration(&mut self, data_rate: u8, full_scale: u8, filter_bandwidth: u8) -> Result<(), TinkerforgeError> {
492        let mut payload = [0; 3];
493        data_rate.write_to_slice(&mut payload[0..1]);
494        full_scale.write_to_slice(&mut payload[1..2]);
495        filter_bandwidth.write_to_slice(&mut payload[2..3]);
496
497        #[allow(unused_variables)]
498        let result = self.device.set(u8::from(AccelerometerBrickletFunction::SetConfiguration), &payload).await?;
499        Ok(())
500    }
501
502    /// Returns the configuration as set by [`set_configuration`].
503    ///
504    /// Associated constants:
505    /// * ACCELEROMETER_BRICKLET_DATA_RATE_OFF
506    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_3HZ
507    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_6HZ
508    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_12HZ
509    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_25HZ
510    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_50HZ
511    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_100HZ
512    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_400HZ
513    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_800HZ
514    ///	* ACCELEROMETER_BRICKLET_DATA_RATE_1600HZ
515    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_2G
516    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_4G
517    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_6G
518    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_8G
519    ///	* ACCELEROMETER_BRICKLET_FULL_SCALE_16G
520    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_800HZ
521    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_400HZ
522    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_200HZ
523    ///	* ACCELEROMETER_BRICKLET_FILTER_BANDWIDTH_50HZ
524    pub async fn get_configuration(&mut self) -> Result<Configuration, TinkerforgeError> {
525        let payload = [0; 0];
526
527        #[allow(unused_variables)]
528        let result = self.device.get(u8::from(AccelerometerBrickletFunction::GetConfiguration), &payload).await?;
529        Ok(Configuration::from_le_byte_slice(result.body()))
530    }
531
532    /// Enables the LED on the Bricklet.
533    pub async fn led_on(&mut self) -> Result<(), TinkerforgeError> {
534        let payload = [0; 0];
535
536        #[allow(unused_variables)]
537        let result = self.device.set(u8::from(AccelerometerBrickletFunction::LedOn), &payload).await?;
538        Ok(())
539    }
540
541    /// Disables the LED on the Bricklet.
542    pub async fn led_off(&mut self) -> Result<(), TinkerforgeError> {
543        let payload = [0; 0];
544
545        #[allow(unused_variables)]
546        let result = self.device.set(u8::from(AccelerometerBrickletFunction::LedOff), &payload).await?;
547        Ok(())
548    }
549
550    /// Returns *true* if the LED is enabled, *false* otherwise.
551    pub async fn is_led_on(&mut self) -> Result<bool, TinkerforgeError> {
552        let payload = [0; 0];
553
554        #[allow(unused_variables)]
555        let result = self.device.get(u8::from(AccelerometerBrickletFunction::IsLedOn), &payload).await?;
556        Ok(bool::from_le_byte_slice(result.body()))
557    }
558
559    /// Returns the UID, the UID where the Bricklet is connected to,
560    /// the position, the hardware and firmware version as well as the
561    /// device identifier.
562    ///
563    /// The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
564    /// A Bricklet connected to an [Isolator Bricklet](isolator_bricklet) is always at
565    /// position 'z'.
566    ///
567    /// The device identifier numbers can be found [here](device_identifier).
568    /// |device_identifier_constant|
569    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
570        let payload = [0; 0];
571
572        #[allow(unused_variables)]
573        let result = self.device.get(u8::from(AccelerometerBrickletFunction::GetIdentity), &payload).await?;
574        Ok(Identity::from_le_byte_slice(result.body()))
575    }
576}