tinkerforge_async/bindings/
imu_v2_brick.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//! Full fledged AHRS with 9 degrees of freedom.
12//!
13//! See also the documentation [here](https://www.tinkerforge.com/en/doc/Software/Bricks/IMUV2_Brick_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 ImuV2BrickFunction {
24    GetAcceleration,
25    GetMagneticField,
26    GetAngularVelocity,
27    GetTemperature,
28    GetOrientation,
29    GetLinearAcceleration,
30    GetGravityVector,
31    GetQuaternion,
32    GetAllData,
33    LedsOn,
34    LedsOff,
35    AreLedsOn,
36    SaveCalibration,
37    SetAccelerationPeriod,
38    GetAccelerationPeriod,
39    SetMagneticFieldPeriod,
40    GetMagneticFieldPeriod,
41    SetAngularVelocityPeriod,
42    GetAngularVelocityPeriod,
43    SetTemperaturePeriod,
44    GetTemperaturePeriod,
45    SetOrientationPeriod,
46    GetOrientationPeriod,
47    SetLinearAccelerationPeriod,
48    GetLinearAccelerationPeriod,
49    SetGravityVectorPeriod,
50    GetGravityVectorPeriod,
51    SetQuaternionPeriod,
52    GetQuaternionPeriod,
53    SetAllDataPeriod,
54    GetAllDataPeriod,
55    SetSensorConfiguration,
56    GetSensorConfiguration,
57    SetSensorFusionMode,
58    GetSensorFusionMode,
59    SetSpitfpBaudrateConfig,
60    GetSpitfpBaudrateConfig,
61    GetSendTimeoutCount,
62    SetSpitfpBaudrate,
63    GetSpitfpBaudrate,
64    GetSpitfpErrorCount,
65    EnableStatusLed,
66    DisableStatusLed,
67    IsStatusLedEnabled,
68    GetProtocol1BrickletName,
69    GetChipTemperature,
70    Reset,
71    WriteBrickletPlugin,
72    ReadBrickletPlugin,
73    GetIdentity,
74    CallbackAcceleration,
75    CallbackMagneticField,
76    CallbackAngularVelocity,
77    CallbackTemperature,
78    CallbackLinearAcceleration,
79    CallbackGravityVector,
80    CallbackOrientation,
81    CallbackQuaternion,
82    CallbackAllData,
83}
84impl From<ImuV2BrickFunction> for u8 {
85    fn from(fun: ImuV2BrickFunction) -> Self {
86        match fun {
87            ImuV2BrickFunction::GetAcceleration => 1,
88            ImuV2BrickFunction::GetMagneticField => 2,
89            ImuV2BrickFunction::GetAngularVelocity => 3,
90            ImuV2BrickFunction::GetTemperature => 4,
91            ImuV2BrickFunction::GetOrientation => 5,
92            ImuV2BrickFunction::GetLinearAcceleration => 6,
93            ImuV2BrickFunction::GetGravityVector => 7,
94            ImuV2BrickFunction::GetQuaternion => 8,
95            ImuV2BrickFunction::GetAllData => 9,
96            ImuV2BrickFunction::LedsOn => 10,
97            ImuV2BrickFunction::LedsOff => 11,
98            ImuV2BrickFunction::AreLedsOn => 12,
99            ImuV2BrickFunction::SaveCalibration => 13,
100            ImuV2BrickFunction::SetAccelerationPeriod => 14,
101            ImuV2BrickFunction::GetAccelerationPeriod => 15,
102            ImuV2BrickFunction::SetMagneticFieldPeriod => 16,
103            ImuV2BrickFunction::GetMagneticFieldPeriod => 17,
104            ImuV2BrickFunction::SetAngularVelocityPeriod => 18,
105            ImuV2BrickFunction::GetAngularVelocityPeriod => 19,
106            ImuV2BrickFunction::SetTemperaturePeriod => 20,
107            ImuV2BrickFunction::GetTemperaturePeriod => 21,
108            ImuV2BrickFunction::SetOrientationPeriod => 22,
109            ImuV2BrickFunction::GetOrientationPeriod => 23,
110            ImuV2BrickFunction::SetLinearAccelerationPeriod => 24,
111            ImuV2BrickFunction::GetLinearAccelerationPeriod => 25,
112            ImuV2BrickFunction::SetGravityVectorPeriod => 26,
113            ImuV2BrickFunction::GetGravityVectorPeriod => 27,
114            ImuV2BrickFunction::SetQuaternionPeriod => 28,
115            ImuV2BrickFunction::GetQuaternionPeriod => 29,
116            ImuV2BrickFunction::SetAllDataPeriod => 30,
117            ImuV2BrickFunction::GetAllDataPeriod => 31,
118            ImuV2BrickFunction::SetSensorConfiguration => 41,
119            ImuV2BrickFunction::GetSensorConfiguration => 42,
120            ImuV2BrickFunction::SetSensorFusionMode => 43,
121            ImuV2BrickFunction::GetSensorFusionMode => 44,
122            ImuV2BrickFunction::SetSpitfpBaudrateConfig => 231,
123            ImuV2BrickFunction::GetSpitfpBaudrateConfig => 232,
124            ImuV2BrickFunction::GetSendTimeoutCount => 233,
125            ImuV2BrickFunction::SetSpitfpBaudrate => 234,
126            ImuV2BrickFunction::GetSpitfpBaudrate => 235,
127            ImuV2BrickFunction::GetSpitfpErrorCount => 237,
128            ImuV2BrickFunction::EnableStatusLed => 238,
129            ImuV2BrickFunction::DisableStatusLed => 239,
130            ImuV2BrickFunction::IsStatusLedEnabled => 240,
131            ImuV2BrickFunction::GetProtocol1BrickletName => 241,
132            ImuV2BrickFunction::GetChipTemperature => 242,
133            ImuV2BrickFunction::Reset => 243,
134            ImuV2BrickFunction::WriteBrickletPlugin => 246,
135            ImuV2BrickFunction::ReadBrickletPlugin => 247,
136            ImuV2BrickFunction::GetIdentity => 255,
137            ImuV2BrickFunction::CallbackAcceleration => 32,
138            ImuV2BrickFunction::CallbackMagneticField => 33,
139            ImuV2BrickFunction::CallbackAngularVelocity => 34,
140            ImuV2BrickFunction::CallbackTemperature => 35,
141            ImuV2BrickFunction::CallbackLinearAcceleration => 36,
142            ImuV2BrickFunction::CallbackGravityVector => 37,
143            ImuV2BrickFunction::CallbackOrientation => 38,
144            ImuV2BrickFunction::CallbackQuaternion => 39,
145            ImuV2BrickFunction::CallbackAllData => 40,
146        }
147    }
148}
149pub const IMU_V2_BRICK_MAGNETOMETER_RATE_2HZ: u8 = 0;
150pub const IMU_V2_BRICK_MAGNETOMETER_RATE_6HZ: u8 = 1;
151pub const IMU_V2_BRICK_MAGNETOMETER_RATE_8HZ: u8 = 2;
152pub const IMU_V2_BRICK_MAGNETOMETER_RATE_10HZ: u8 = 3;
153pub const IMU_V2_BRICK_MAGNETOMETER_RATE_15HZ: u8 = 4;
154pub const IMU_V2_BRICK_MAGNETOMETER_RATE_20HZ: u8 = 5;
155pub const IMU_V2_BRICK_MAGNETOMETER_RATE_25HZ: u8 = 6;
156pub const IMU_V2_BRICK_MAGNETOMETER_RATE_30HZ: u8 = 7;
157pub const IMU_V2_BRICK_GYROSCOPE_RANGE_2000DPS: u8 = 0;
158pub const IMU_V2_BRICK_GYROSCOPE_RANGE_1000DPS: u8 = 1;
159pub const IMU_V2_BRICK_GYROSCOPE_RANGE_500DPS: u8 = 2;
160pub const IMU_V2_BRICK_GYROSCOPE_RANGE_250DPS: u8 = 3;
161pub const IMU_V2_BRICK_GYROSCOPE_RANGE_125DPS: u8 = 4;
162pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_523HZ: u8 = 0;
163pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_230HZ: u8 = 1;
164pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_116HZ: u8 = 2;
165pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_47HZ: u8 = 3;
166pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_23HZ: u8 = 4;
167pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_12HZ: u8 = 5;
168pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_64HZ: u8 = 6;
169pub const IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_32HZ: u8 = 7;
170pub const IMU_V2_BRICK_ACCELEROMETER_RANGE_2G: u8 = 0;
171pub const IMU_V2_BRICK_ACCELEROMETER_RANGE_4G: u8 = 1;
172pub const IMU_V2_BRICK_ACCELEROMETER_RANGE_8G: u8 = 2;
173pub const IMU_V2_BRICK_ACCELEROMETER_RANGE_16G: u8 = 3;
174pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_7_81HZ: u8 = 0;
175pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_15_63HZ: u8 = 1;
176pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_31_25HZ: u8 = 2;
177pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_62_5HZ: u8 = 3;
178pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_125HZ: u8 = 4;
179pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_250HZ: u8 = 5;
180pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_500HZ: u8 = 6;
181pub const IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_1000HZ: u8 = 7;
182pub const IMU_V2_BRICK_SENSOR_FUSION_OFF: u8 = 0;
183pub const IMU_V2_BRICK_SENSOR_FUSION_ON: u8 = 1;
184pub const IMU_V2_BRICK_SENSOR_FUSION_ON_WITHOUT_MAGNETOMETER: u8 = 2;
185pub const IMU_V2_BRICK_SENSOR_FUSION_ON_WITHOUT_FAST_MAGNETOMETER_CALIBRATION: u8 = 3;
186pub const IMU_V2_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
187pub const IMU_V2_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
188pub const IMU_V2_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
189pub const IMU_V2_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
190pub const IMU_V2_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
191pub const IMU_V2_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
192pub const IMU_V2_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
193pub const IMU_V2_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;
194
195#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
196pub struct Acceleration {
197    pub x: i16,
198    pub y: i16,
199    pub z: i16,
200}
201impl FromByteSlice for Acceleration {
202    fn bytes_expected() -> usize {
203        6
204    }
205    fn from_le_byte_slice(bytes: &[u8]) -> Acceleration {
206        Acceleration {
207            x: <i16>::from_le_byte_slice(&bytes[0..2]),
208            y: <i16>::from_le_byte_slice(&bytes[2..4]),
209            z: <i16>::from_le_byte_slice(&bytes[4..6]),
210        }
211    }
212}
213
214#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
215pub struct MagneticField {
216    pub x: i16,
217    pub y: i16,
218    pub z: i16,
219}
220impl FromByteSlice for MagneticField {
221    fn bytes_expected() -> usize {
222        6
223    }
224    fn from_le_byte_slice(bytes: &[u8]) -> MagneticField {
225        MagneticField {
226            x: <i16>::from_le_byte_slice(&bytes[0..2]),
227            y: <i16>::from_le_byte_slice(&bytes[2..4]),
228            z: <i16>::from_le_byte_slice(&bytes[4..6]),
229        }
230    }
231}
232
233#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
234pub struct AngularVelocity {
235    pub x: i16,
236    pub y: i16,
237    pub z: i16,
238}
239impl FromByteSlice for AngularVelocity {
240    fn bytes_expected() -> usize {
241        6
242    }
243    fn from_le_byte_slice(bytes: &[u8]) -> AngularVelocity {
244        AngularVelocity {
245            x: <i16>::from_le_byte_slice(&bytes[0..2]),
246            y: <i16>::from_le_byte_slice(&bytes[2..4]),
247            z: <i16>::from_le_byte_slice(&bytes[4..6]),
248        }
249    }
250}
251
252#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
253pub struct Orientation {
254    pub heading: i16,
255    pub roll: i16,
256    pub pitch: i16,
257}
258impl FromByteSlice for Orientation {
259    fn bytes_expected() -> usize {
260        6
261    }
262    fn from_le_byte_slice(bytes: &[u8]) -> Orientation {
263        Orientation {
264            heading: <i16>::from_le_byte_slice(&bytes[0..2]),
265            roll: <i16>::from_le_byte_slice(&bytes[2..4]),
266            pitch: <i16>::from_le_byte_slice(&bytes[4..6]),
267        }
268    }
269}
270
271#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
272pub struct LinearAcceleration {
273    pub x: i16,
274    pub y: i16,
275    pub z: i16,
276}
277impl FromByteSlice for LinearAcceleration {
278    fn bytes_expected() -> usize {
279        6
280    }
281    fn from_le_byte_slice(bytes: &[u8]) -> LinearAcceleration {
282        LinearAcceleration {
283            x: <i16>::from_le_byte_slice(&bytes[0..2]),
284            y: <i16>::from_le_byte_slice(&bytes[2..4]),
285            z: <i16>::from_le_byte_slice(&bytes[4..6]),
286        }
287    }
288}
289
290#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
291pub struct GravityVector {
292    pub x: i16,
293    pub y: i16,
294    pub z: i16,
295}
296impl FromByteSlice for GravityVector {
297    fn bytes_expected() -> usize {
298        6
299    }
300    fn from_le_byte_slice(bytes: &[u8]) -> GravityVector {
301        GravityVector {
302            x: <i16>::from_le_byte_slice(&bytes[0..2]),
303            y: <i16>::from_le_byte_slice(&bytes[2..4]),
304            z: <i16>::from_le_byte_slice(&bytes[4..6]),
305        }
306    }
307}
308
309#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
310pub struct Quaternion {
311    pub w: i16,
312    pub x: i16,
313    pub y: i16,
314    pub z: i16,
315}
316impl FromByteSlice for Quaternion {
317    fn bytes_expected() -> usize {
318        8
319    }
320    fn from_le_byte_slice(bytes: &[u8]) -> Quaternion {
321        Quaternion {
322            w: <i16>::from_le_byte_slice(&bytes[0..2]),
323            x: <i16>::from_le_byte_slice(&bytes[2..4]),
324            y: <i16>::from_le_byte_slice(&bytes[4..6]),
325            z: <i16>::from_le_byte_slice(&bytes[6..8]),
326        }
327    }
328}
329
330#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
331pub struct AllData {
332    pub acceleration: [i16; 3],
333    pub magnetic_field: [i16; 3],
334    pub angular_velocity: [i16; 3],
335    pub euler_angle: [i16; 3],
336    pub quaternion: [i16; 4],
337    pub linear_acceleration: [i16; 3],
338    pub gravity_vector: [i16; 3],
339    pub temperature: i8,
340    pub calibration_status: u8,
341}
342impl FromByteSlice for AllData {
343    fn bytes_expected() -> usize {
344        46
345    }
346    fn from_le_byte_slice(bytes: &[u8]) -> AllData {
347        AllData {
348            acceleration: <[i16; 3]>::from_le_byte_slice(&bytes[0..6]),
349            magnetic_field: <[i16; 3]>::from_le_byte_slice(&bytes[6..12]),
350            angular_velocity: <[i16; 3]>::from_le_byte_slice(&bytes[12..18]),
351            euler_angle: <[i16; 3]>::from_le_byte_slice(&bytes[18..24]),
352            quaternion: <[i16; 4]>::from_le_byte_slice(&bytes[24..32]),
353            linear_acceleration: <[i16; 3]>::from_le_byte_slice(&bytes[32..38]),
354            gravity_vector: <[i16; 3]>::from_le_byte_slice(&bytes[38..44]),
355            temperature: <i8>::from_le_byte_slice(&bytes[44..45]),
356            calibration_status: <u8>::from_le_byte_slice(&bytes[45..46]),
357        }
358    }
359}
360
361#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
362pub struct AccelerationEvent {
363    pub x: i16,
364    pub y: i16,
365    pub z: i16,
366}
367impl FromByteSlice for AccelerationEvent {
368    fn bytes_expected() -> usize {
369        6
370    }
371    fn from_le_byte_slice(bytes: &[u8]) -> AccelerationEvent {
372        AccelerationEvent {
373            x: <i16>::from_le_byte_slice(&bytes[0..2]),
374            y: <i16>::from_le_byte_slice(&bytes[2..4]),
375            z: <i16>::from_le_byte_slice(&bytes[4..6]),
376        }
377    }
378}
379
380#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
381pub struct MagneticFieldEvent {
382    pub x: i16,
383    pub y: i16,
384    pub z: i16,
385}
386impl FromByteSlice for MagneticFieldEvent {
387    fn bytes_expected() -> usize {
388        6
389    }
390    fn from_le_byte_slice(bytes: &[u8]) -> MagneticFieldEvent {
391        MagneticFieldEvent {
392            x: <i16>::from_le_byte_slice(&bytes[0..2]),
393            y: <i16>::from_le_byte_slice(&bytes[2..4]),
394            z: <i16>::from_le_byte_slice(&bytes[4..6]),
395        }
396    }
397}
398
399#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
400pub struct AngularVelocityEvent {
401    pub x: i16,
402    pub y: i16,
403    pub z: i16,
404}
405impl FromByteSlice for AngularVelocityEvent {
406    fn bytes_expected() -> usize {
407        6
408    }
409    fn from_le_byte_slice(bytes: &[u8]) -> AngularVelocityEvent {
410        AngularVelocityEvent {
411            x: <i16>::from_le_byte_slice(&bytes[0..2]),
412            y: <i16>::from_le_byte_slice(&bytes[2..4]),
413            z: <i16>::from_le_byte_slice(&bytes[4..6]),
414        }
415    }
416}
417
418#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
419pub struct LinearAccelerationEvent {
420    pub x: i16,
421    pub y: i16,
422    pub z: i16,
423}
424impl FromByteSlice for LinearAccelerationEvent {
425    fn bytes_expected() -> usize {
426        6
427    }
428    fn from_le_byte_slice(bytes: &[u8]) -> LinearAccelerationEvent {
429        LinearAccelerationEvent {
430            x: <i16>::from_le_byte_slice(&bytes[0..2]),
431            y: <i16>::from_le_byte_slice(&bytes[2..4]),
432            z: <i16>::from_le_byte_slice(&bytes[4..6]),
433        }
434    }
435}
436
437#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
438pub struct GravityVectorEvent {
439    pub x: i16,
440    pub y: i16,
441    pub z: i16,
442}
443impl FromByteSlice for GravityVectorEvent {
444    fn bytes_expected() -> usize {
445        6
446    }
447    fn from_le_byte_slice(bytes: &[u8]) -> GravityVectorEvent {
448        GravityVectorEvent {
449            x: <i16>::from_le_byte_slice(&bytes[0..2]),
450            y: <i16>::from_le_byte_slice(&bytes[2..4]),
451            z: <i16>::from_le_byte_slice(&bytes[4..6]),
452        }
453    }
454}
455
456#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
457pub struct OrientationEvent {
458    pub heading: i16,
459    pub roll: i16,
460    pub pitch: i16,
461}
462impl FromByteSlice for OrientationEvent {
463    fn bytes_expected() -> usize {
464        6
465    }
466    fn from_le_byte_slice(bytes: &[u8]) -> OrientationEvent {
467        OrientationEvent {
468            heading: <i16>::from_le_byte_slice(&bytes[0..2]),
469            roll: <i16>::from_le_byte_slice(&bytes[2..4]),
470            pitch: <i16>::from_le_byte_slice(&bytes[4..6]),
471        }
472    }
473}
474
475#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
476pub struct QuaternionEvent {
477    pub w: i16,
478    pub x: i16,
479    pub y: i16,
480    pub z: i16,
481}
482impl FromByteSlice for QuaternionEvent {
483    fn bytes_expected() -> usize {
484        8
485    }
486    fn from_le_byte_slice(bytes: &[u8]) -> QuaternionEvent {
487        QuaternionEvent {
488            w: <i16>::from_le_byte_slice(&bytes[0..2]),
489            x: <i16>::from_le_byte_slice(&bytes[2..4]),
490            y: <i16>::from_le_byte_slice(&bytes[4..6]),
491            z: <i16>::from_le_byte_slice(&bytes[6..8]),
492        }
493    }
494}
495
496#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
497pub struct AllDataEvent {
498    pub acceleration: [i16; 3],
499    pub magnetic_field: [i16; 3],
500    pub angular_velocity: [i16; 3],
501    pub euler_angle: [i16; 3],
502    pub quaternion: [i16; 4],
503    pub linear_acceleration: [i16; 3],
504    pub gravity_vector: [i16; 3],
505    pub temperature: i8,
506    pub calibration_status: u8,
507}
508impl FromByteSlice for AllDataEvent {
509    fn bytes_expected() -> usize {
510        46
511    }
512    fn from_le_byte_slice(bytes: &[u8]) -> AllDataEvent {
513        AllDataEvent {
514            acceleration: <[i16; 3]>::from_le_byte_slice(&bytes[0..6]),
515            magnetic_field: <[i16; 3]>::from_le_byte_slice(&bytes[6..12]),
516            angular_velocity: <[i16; 3]>::from_le_byte_slice(&bytes[12..18]),
517            euler_angle: <[i16; 3]>::from_le_byte_slice(&bytes[18..24]),
518            quaternion: <[i16; 4]>::from_le_byte_slice(&bytes[24..32]),
519            linear_acceleration: <[i16; 3]>::from_le_byte_slice(&bytes[32..38]),
520            gravity_vector: <[i16; 3]>::from_le_byte_slice(&bytes[38..44]),
521            temperature: <i8>::from_le_byte_slice(&bytes[44..45]),
522            calibration_status: <u8>::from_le_byte_slice(&bytes[45..46]),
523        }
524    }
525}
526
527#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
528pub struct SensorConfiguration {
529    pub magnetometer_rate: u8,
530    pub gyroscope_range: u8,
531    pub gyroscope_bandwidth: u8,
532    pub accelerometer_range: u8,
533    pub accelerometer_bandwidth: u8,
534}
535impl FromByteSlice for SensorConfiguration {
536    fn bytes_expected() -> usize {
537        5
538    }
539    fn from_le_byte_slice(bytes: &[u8]) -> SensorConfiguration {
540        SensorConfiguration {
541            magnetometer_rate: <u8>::from_le_byte_slice(&bytes[0..1]),
542            gyroscope_range: <u8>::from_le_byte_slice(&bytes[1..2]),
543            gyroscope_bandwidth: <u8>::from_le_byte_slice(&bytes[2..3]),
544            accelerometer_range: <u8>::from_le_byte_slice(&bytes[3..4]),
545            accelerometer_bandwidth: <u8>::from_le_byte_slice(&bytes[4..5]),
546        }
547    }
548}
549
550#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
551pub struct SpitfpBaudrateConfig {
552    pub enable_dynamic_baudrate: bool,
553    pub minimum_dynamic_baudrate: u32,
554}
555impl FromByteSlice for SpitfpBaudrateConfig {
556    fn bytes_expected() -> usize {
557        5
558    }
559    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpBaudrateConfig {
560        SpitfpBaudrateConfig {
561            enable_dynamic_baudrate: <bool>::from_le_byte_slice(&bytes[0..1]),
562            minimum_dynamic_baudrate: <u32>::from_le_byte_slice(&bytes[1..5]),
563        }
564    }
565}
566
567#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
568pub struct SpitfpErrorCount {
569    pub error_count_ack_checksum: u32,
570    pub error_count_message_checksum: u32,
571    pub error_count_frame: u32,
572    pub error_count_overflow: u32,
573}
574impl FromByteSlice for SpitfpErrorCount {
575    fn bytes_expected() -> usize {
576        16
577    }
578    fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
579        SpitfpErrorCount {
580            error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
581            error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
582            error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
583            error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
584        }
585    }
586}
587
588#[derive(Clone)]
589pub struct Protocol1BrickletName {
590    pub protocol_version: u8,
591    pub firmware_version: [u8; 3],
592    pub name: String,
593}
594impl FromByteSlice for Protocol1BrickletName {
595    fn bytes_expected() -> usize {
596        44
597    }
598    fn from_le_byte_slice(bytes: &[u8]) -> Protocol1BrickletName {
599        Protocol1BrickletName {
600            protocol_version: <u8>::from_le_byte_slice(&bytes[0..1]),
601            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[1..4]),
602            name: <String>::from_le_byte_slice(&bytes[4..44]),
603        }
604    }
605}
606
607#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
608pub struct Identity {
609    pub uid: String,
610    pub connected_uid: String,
611    pub position: char,
612    pub hardware_version: [u8; 3],
613    pub firmware_version: [u8; 3],
614    pub device_identifier: u16,
615}
616impl FromByteSlice for Identity {
617    fn bytes_expected() -> usize {
618        25
619    }
620    fn from_le_byte_slice(bytes: &[u8]) -> Identity {
621        Identity {
622            uid: <String>::from_le_byte_slice(&bytes[0..8]),
623            connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
624            position: <char>::from_le_byte_slice(&bytes[16..17]),
625            hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
626            firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
627            device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
628        }
629    }
630}
631
632/// Full fledged AHRS with 9 degrees of freedom
633#[derive(Clone)]
634pub struct ImuV2Brick {
635    device: Device,
636}
637impl ImuV2Brick {
638    pub const DEVICE_IDENTIFIER: u16 = 18;
639    pub const DEVICE_DISPLAY_NAME: &'static str = "IMU Brick 2.0";
640    /// Creates an object with the unique device ID `uid`. This object can then be used after the IP Connection `ip_connection` is connected.
641    pub fn new(uid: Uid, connection: AsyncIpConnection) -> ImuV2Brick {
642        let mut result = ImuV2Brick { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
643        result.device.response_expected[u8::from(ImuV2BrickFunction::GetAcceleration) as usize] = ResponseExpectedFlag::AlwaysTrue;
644        result.device.response_expected[u8::from(ImuV2BrickFunction::GetMagneticField) as usize] = ResponseExpectedFlag::AlwaysTrue;
645        result.device.response_expected[u8::from(ImuV2BrickFunction::GetAngularVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
646        result.device.response_expected[u8::from(ImuV2BrickFunction::GetTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
647        result.device.response_expected[u8::from(ImuV2BrickFunction::GetOrientation) as usize] = ResponseExpectedFlag::AlwaysTrue;
648        result.device.response_expected[u8::from(ImuV2BrickFunction::GetLinearAcceleration) as usize] = ResponseExpectedFlag::AlwaysTrue;
649        result.device.response_expected[u8::from(ImuV2BrickFunction::GetGravityVector) as usize] = ResponseExpectedFlag::AlwaysTrue;
650        result.device.response_expected[u8::from(ImuV2BrickFunction::GetQuaternion) as usize] = ResponseExpectedFlag::AlwaysTrue;
651        result.device.response_expected[u8::from(ImuV2BrickFunction::GetAllData) as usize] = ResponseExpectedFlag::AlwaysTrue;
652        result.device.response_expected[u8::from(ImuV2BrickFunction::LedsOn) as usize] = ResponseExpectedFlag::False;
653        result.device.response_expected[u8::from(ImuV2BrickFunction::LedsOff) as usize] = ResponseExpectedFlag::False;
654        result.device.response_expected[u8::from(ImuV2BrickFunction::AreLedsOn) as usize] = ResponseExpectedFlag::AlwaysTrue;
655        result.device.response_expected[u8::from(ImuV2BrickFunction::SaveCalibration) as usize] = ResponseExpectedFlag::AlwaysTrue;
656        result.device.response_expected[u8::from(ImuV2BrickFunction::SetAccelerationPeriod) as usize] = ResponseExpectedFlag::True;
657        result.device.response_expected[u8::from(ImuV2BrickFunction::GetAccelerationPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
658        result.device.response_expected[u8::from(ImuV2BrickFunction::SetMagneticFieldPeriod) as usize] = ResponseExpectedFlag::True;
659        result.device.response_expected[u8::from(ImuV2BrickFunction::GetMagneticFieldPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
660        result.device.response_expected[u8::from(ImuV2BrickFunction::SetAngularVelocityPeriod) as usize] = ResponseExpectedFlag::True;
661        result.device.response_expected[u8::from(ImuV2BrickFunction::GetAngularVelocityPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
662        result.device.response_expected[u8::from(ImuV2BrickFunction::SetTemperaturePeriod) as usize] = ResponseExpectedFlag::True;
663        result.device.response_expected[u8::from(ImuV2BrickFunction::GetTemperaturePeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
664        result.device.response_expected[u8::from(ImuV2BrickFunction::SetOrientationPeriod) as usize] = ResponseExpectedFlag::True;
665        result.device.response_expected[u8::from(ImuV2BrickFunction::GetOrientationPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
666        result.device.response_expected[u8::from(ImuV2BrickFunction::SetLinearAccelerationPeriod) as usize] = ResponseExpectedFlag::True;
667        result.device.response_expected[u8::from(ImuV2BrickFunction::GetLinearAccelerationPeriod) as usize] =
668            ResponseExpectedFlag::AlwaysTrue;
669        result.device.response_expected[u8::from(ImuV2BrickFunction::SetGravityVectorPeriod) as usize] = ResponseExpectedFlag::True;
670        result.device.response_expected[u8::from(ImuV2BrickFunction::GetGravityVectorPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
671        result.device.response_expected[u8::from(ImuV2BrickFunction::SetQuaternionPeriod) as usize] = ResponseExpectedFlag::True;
672        result.device.response_expected[u8::from(ImuV2BrickFunction::GetQuaternionPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
673        result.device.response_expected[u8::from(ImuV2BrickFunction::SetAllDataPeriod) as usize] = ResponseExpectedFlag::True;
674        result.device.response_expected[u8::from(ImuV2BrickFunction::GetAllDataPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
675        result.device.response_expected[u8::from(ImuV2BrickFunction::SetSensorConfiguration) as usize] = ResponseExpectedFlag::False;
676        result.device.response_expected[u8::from(ImuV2BrickFunction::GetSensorConfiguration) as usize] = ResponseExpectedFlag::AlwaysTrue;
677        result.device.response_expected[u8::from(ImuV2BrickFunction::SetSensorFusionMode) as usize] = ResponseExpectedFlag::False;
678        result.device.response_expected[u8::from(ImuV2BrickFunction::GetSensorFusionMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
679        result.device.response_expected[u8::from(ImuV2BrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
680        result.device.response_expected[u8::from(ImuV2BrickFunction::GetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
681        result.device.response_expected[u8::from(ImuV2BrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
682        result.device.response_expected[u8::from(ImuV2BrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
683        result.device.response_expected[u8::from(ImuV2BrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
684        result.device.response_expected[u8::from(ImuV2BrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
685        result.device.response_expected[u8::from(ImuV2BrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
686        result.device.response_expected[u8::from(ImuV2BrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
687        result.device.response_expected[u8::from(ImuV2BrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
688        result.device.response_expected[u8::from(ImuV2BrickFunction::GetProtocol1BrickletName) as usize] = ResponseExpectedFlag::AlwaysTrue;
689        result.device.response_expected[u8::from(ImuV2BrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
690        result.device.response_expected[u8::from(ImuV2BrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
691        result.device.response_expected[u8::from(ImuV2BrickFunction::WriteBrickletPlugin) as usize] = ResponseExpectedFlag::False;
692        result.device.response_expected[u8::from(ImuV2BrickFunction::ReadBrickletPlugin) as usize] = ResponseExpectedFlag::AlwaysTrue;
693        result.device.response_expected[u8::from(ImuV2BrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
694        result
695    }
696
697    /// Returns the response expected flag for the function specified by the function ID parameter.
698    /// It is true if the function is expected to send a response, false otherwise.
699    ///
700    /// For getter functions this is enabled by default and cannot be disabled, because those
701    /// functions will always send a response. For callback configuration functions it is enabled
702    /// by default too, but can be disabled by [`set_response_expected`](crate::imu_v2_brick::ImuV2Brick::set_response_expected).
703    /// For setter functions it is disabled by default and can be enabled.
704    ///
705    /// Enabling the response expected flag for a setter function allows to detect timeouts
706    /// and other error conditions calls of this setter as well. The device will then send a response
707    /// for this purpose. If this flag is disabled for a setter function then no response is sent
708    /// and errors are silently ignored, because they cannot be detected.
709    ///
710    /// See [`set_response_expected`](crate::imu_v2_brick::ImuV2Brick::set_response_expected) for the list of function ID constants available for this function.
711    pub fn get_response_expected(&mut self, fun: ImuV2BrickFunction) -> Result<bool, GetResponseExpectedError> {
712        self.device.get_response_expected(u8::from(fun))
713    }
714
715    /// Changes the response expected flag of the function specified by the function ID parameter.
716    /// This flag can only be changed for setter (default value: false) and callback configuration
717    /// functions (default value: true). For getter functions it is always enabled.
718    ///
719    /// Enabling the response expected flag for a setter function allows to detect timeouts and
720    /// other error conditions calls of this setter as well. The device will then send a response
721    /// for this purpose. If this flag is disabled for a setter function then no response is sent
722    /// and errors are silently ignored, because they cannot be detected.
723    pub fn set_response_expected(&mut self, fun: ImuV2BrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
724        self.device.set_response_expected(u8::from(fun), response_expected)
725    }
726
727    /// Changes the response expected flag for all setter and callback configuration functions of this device at once.
728    pub fn set_response_expected_all(&mut self, response_expected: bool) {
729        self.device.set_response_expected_all(response_expected)
730    }
731
732    /// Returns the version of the API definition (major, minor, revision) implemented by this API bindings.
733    /// This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.
734    pub fn get_api_version(&self) -> [u8; 3] {
735        self.device.api_version
736    }
737
738    /// This receiver is triggered periodically with the period that is set by
739    /// [`set_acceleration_period`]. The parameters are the acceleration
740    /// for the x, y and z axis.
741    ///
742    /// [`set_acceleration_period`]: #method.set_acceleration_period
743    pub async fn get_acceleration_callback_receiver(&mut self) -> impl Stream<Item = AccelerationEvent> {
744        self.device
745            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackAcceleration))
746            .await
747            .map(|p| AccelerationEvent::from_le_byte_slice(p.body()))
748    }
749
750    /// This receiver is triggered periodically with the period that is set by
751    /// [`set_magnetic_field_period`]. The parameters are the magnetic
752    /// field for the x, y and z axis.
753    pub async fn get_magnetic_field_callback_receiver(&mut self) -> impl Stream<Item = MagneticFieldEvent> {
754        self.device
755            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackMagneticField))
756            .await
757            .map(|p| MagneticFieldEvent::from_le_byte_slice(p.body()))
758    }
759
760    /// This receiver is triggered periodically with the period that is set by
761    /// [`set_angular_velocity_period`]. The parameters are the angular
762    /// velocity for the x, y and z axis.
763    pub async fn get_angular_velocity_callback_receiver(&mut self) -> impl Stream<Item = AngularVelocityEvent> {
764        self.device
765            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackAngularVelocity))
766            .await
767            .map(|p| AngularVelocityEvent::from_le_byte_slice(p.body()))
768    }
769
770    /// This receiver is triggered periodically with the period that is set by
771    /// [`set_temperature_period`]. The parameter is the temperature.
772    pub async fn get_temperature_callback_receiver(&mut self) -> impl Stream<Item = i8> {
773        self.device.get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackTemperature)).await.map(|p| i8::from_le_byte_slice(p.body()))
774    }
775
776    /// This receiver is triggered periodically with the period that is set by
777    /// [`set_linear_acceleration_period`]. The parameters are the
778    /// linear acceleration for the x, y and z axis.
779    pub async fn get_linear_acceleration_callback_receiver(&mut self) -> impl Stream<Item = LinearAccelerationEvent> {
780        self.device
781            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackLinearAcceleration))
782            .await
783            .map(|p| LinearAccelerationEvent::from_le_byte_slice(p.body()))
784    }
785
786    /// This receiver is triggered periodically with the period that is set by
787    /// [`set_gravity_vector_period`]. The parameters gravity vector
788    /// for the x, y and z axis.
789    pub async fn get_gravity_vector_callback_receiver(&mut self) -> impl Stream<Item = GravityVectorEvent> {
790        self.device
791            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackGravityVector))
792            .await
793            .map(|p| GravityVectorEvent::from_le_byte_slice(p.body()))
794    }
795
796    /// This receiver is triggered periodically with the period that is set by
797    /// [`set_orientation_period`]. The parameters are the orientation
798    /// (heading (yaw), roll, pitch) of the IMU Brick in Euler angles. See
799    /// [`get_orientation`] for details.
800    pub async fn get_orientation_callback_receiver(&mut self) -> impl Stream<Item = OrientationEvent> {
801        self.device
802            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackOrientation))
803            .await
804            .map(|p| OrientationEvent::from_le_byte_slice(p.body()))
805    }
806
807    /// This receiver is triggered periodically with the period that is set by
808    /// [`set_quaternion_period`]. The parameters are the orientation
809    /// (w, x, y, z) of the IMU Brick in quaternions. See [`get_quaternion`]
810    /// for details.
811    pub async fn get_quaternion_callback_receiver(&mut self) -> impl Stream<Item = QuaternionEvent> {
812        self.device
813            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackQuaternion))
814            .await
815            .map(|p| QuaternionEvent::from_le_byte_slice(p.body()))
816    }
817
818    /// This receiver is triggered periodically with the period that is set by
819    /// [`set_all_data_period`]. The parameters are as for
820    /// [`get_all_data`].
821    pub async fn get_all_data_callback_receiver(&mut self) -> impl Stream<Item = AllDataEvent> {
822        self.device
823            .get_callback_receiver(u8::from(ImuV2BrickFunction::CallbackAllData))
824            .await
825            .map(|p| AllDataEvent::from_le_byte_slice(p.body()))
826    }
827
828    /// Returns the calibrated acceleration from the accelerometer for the
829    /// x, y and z axis. The acceleration is in the range configured with
830    /// [`set_sensor_configuration`].
831    ///
832    /// If you want to get the acceleration periodically, it is recommended
833    /// to use the [`get_acceleration_callback_receiver`] receiver and set the period with
834    /// [`set_acceleration_period`].
835    pub async fn get_acceleration(&mut self) -> Result<Acceleration, TinkerforgeError> {
836        let payload = [0; 0];
837
838        #[allow(unused_variables)]
839        let result = self.device.get(u8::from(ImuV2BrickFunction::GetAcceleration), &payload).await?;
840        Ok(Acceleration::from_le_byte_slice(result.body()))
841    }
842
843    /// Returns the calibrated magnetic field from the magnetometer for the
844    /// x, y and z axis.
845    ///
846    /// If you want to get the magnetic field periodically, it is recommended
847    /// to use the [`get_magnetic_field_callback_receiver`] receiver and set the period with
848    /// [`set_magnetic_field_period`].
849    pub async fn get_magnetic_field(&mut self) -> Result<MagneticField, TinkerforgeError> {
850        let payload = [0; 0];
851
852        #[allow(unused_variables)]
853        let result = self.device.get(u8::from(ImuV2BrickFunction::GetMagneticField), &payload).await?;
854        Ok(MagneticField::from_le_byte_slice(result.body()))
855    }
856
857    /// Returns the calibrated angular velocity from the gyroscope for the
858    /// x, y and z axis. The angular velocity is in the range configured with
859    /// [`set_sensor_configuration`].
860    ///
861    /// If you want to get the angular velocity periodically, it is recommended
862    /// to use the [`get_angular_velocity_callback_receiver`] areceiver nd set the period with
863    /// [`set_angular_velocity_period`].
864    pub async fn get_angular_velocity(&mut self) -> Result<AngularVelocity, TinkerforgeError> {
865        let payload = [0; 0];
866
867        #[allow(unused_variables)]
868        let result = self.device.get(u8::from(ImuV2BrickFunction::GetAngularVelocity), &payload).await?;
869        Ok(AngularVelocity::from_le_byte_slice(result.body()))
870    }
871
872    /// Returns the temperature of the IMU Brick.
873    /// The temperature is measured in the core of the BNO055 IC, it is not the
874    /// ambient temperature
875    pub async fn get_temperature(&mut self) -> Result<i8, TinkerforgeError> {
876        let payload = [0; 0];
877
878        #[allow(unused_variables)]
879        let result = self.device.get(u8::from(ImuV2BrickFunction::GetTemperature), &payload).await?;
880        Ok(i8::from_le_byte_slice(result.body()))
881    }
882
883    /// Returns the current orientation (heading, roll, pitch) of the IMU Brick as
884    /// independent Euler angles. Note that Euler angles always
885    /// experience a [gimbal lock](https://en.wikipedia.org/wiki/Gimbal_lock)__.
886    /// We recommend that you use quaternions instead, if you need the absolute
887    /// orientation.
888    ///
889    /// If you want to get the orientation periodically, it is recommended
890    /// to use the [`get_orientation_callback_receiver`] receiver and set the period with
891    /// [`set_orientation_period`].
892    pub async fn get_orientation(&mut self) -> Result<Orientation, TinkerforgeError> {
893        let payload = [0; 0];
894
895        #[allow(unused_variables)]
896        let result = self.device.get(u8::from(ImuV2BrickFunction::GetOrientation), &payload).await?;
897        Ok(Orientation::from_le_byte_slice(result.body()))
898    }
899
900    /// Returns the linear acceleration of the IMU Brick for the
901    /// x, y and z axis. The acceleration is in the range configured with
902    /// [`set_sensor_configuration`].
903    ///
904    /// The linear acceleration is the acceleration in each of the three
905    /// axis of the IMU Brick with the influences of gravity removed.
906    ///
907    /// It is also possible to get the gravity vector with the influence of linear
908    /// acceleration removed, see [`get_gravity_vector`].
909    ///
910    /// If you want to get the linear acceleration periodically, it is recommended
911    /// to use the [`get_linear_acceleration_callback_receiver`] receiver and set the period with
912    /// [`set_linear_acceleration_period`].
913    pub async fn get_linear_acceleration(&mut self) -> Result<LinearAcceleration, TinkerforgeError> {
914        let payload = [0; 0];
915
916        #[allow(unused_variables)]
917        let result = self.device.get(u8::from(ImuV2BrickFunction::GetLinearAcceleration), &payload).await?;
918        Ok(LinearAcceleration::from_le_byte_slice(result.body()))
919    }
920
921    /// Returns the current gravity vector of the IMU Brick for the
922    /// x, y and z axis.
923    ///
924    /// The gravity vector is the acceleration that occurs due to gravity.
925    /// Influences of additional linear acceleration are removed.
926    ///
927    /// It is also possible to get the linear acceleration with the influence
928    /// of gravity removed, see [`get_linear_acceleration`].
929    ///
930    /// If you want to get the gravity vector periodically, it is recommended
931    /// to use the [`get_gravity_vector_callback_receiver`] receiver and set the period with
932    /// [`set_gravity_vector_period`].
933    pub async fn get_gravity_vector(&mut self) -> Result<GravityVector, TinkerforgeError> {
934        let payload = [0; 0];
935
936        #[allow(unused_variables)]
937        let result = self.device.get(u8::from(ImuV2BrickFunction::GetGravityVector), &payload).await?;
938        Ok(GravityVector::from_le_byte_slice(result.body()))
939    }
940
941    /// Returns the current orientation (w, x, y, z) of the IMU Brick as
942    /// [quaternions](https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation)__.
943    ///
944    /// You have to divide the return values by 16383 (14 bit) to get
945    /// the usual range of -1.0 to +1.0 for quaternions.
946    ///
947    /// If you want to get the quaternions periodically, it is recommended
948    /// to use the [`get_quaternion_callback_receiver`] receiver and set the period with
949    /// [`set_quaternion_period`].
950    pub async fn get_quaternion(&mut self) -> Result<Quaternion, TinkerforgeError> {
951        let payload = [0; 0];
952
953        #[allow(unused_variables)]
954        let result = self.device.get(u8::from(ImuV2BrickFunction::GetQuaternion), &payload).await?;
955        Ok(Quaternion::from_le_byte_slice(result.body()))
956    }
957
958    /// Return all of the available data of the IMU Brick.
959    ///
960    /// * acceleration (see [`get_acceleration`])
961    /// * magnetic field (see [`get_magnetic_field`])
962    /// * angular velocity (see [`get_angular_velocity`])
963    /// * Euler angles (see [`get_orientation`])
964    /// * quaternion (see [`get_quaternion`])
965    /// * linear acceleration (see [`get_linear_acceleration`])
966    /// * gravity vector (see [`get_gravity_vector`])
967    /// * temperature (see [`get_temperature`])
968    /// * calibration status (see below)
969    ///
970    /// The calibration status consists of four pairs of two bits. Each pair
971    /// of bits represents the status of the current calibration.
972    ///
973    /// * bit 0-1: Magnetometer
974    /// * bit 2-3: Accelerometer
975    /// * bit 4-5: Gyroscope
976    /// * bit 6-7: System
977    ///
978    /// A value of 0 means for not calibrated and a value of 3 means
979    /// fully calibrated. In your program you should always be able to
980    /// ignore the calibration status, it is used by the calibration
981    /// window of the Brick Viewer and it can be ignored after the first
982    /// calibration. See the documentation in the calibration window for
983    /// more information regarding the calibration of the IMU Brick.
984    ///
985    /// If you want to get the data periodically, it is recommended
986    /// to use the [`get_all_data_callback_receiver`] receiver and set the period with
987    /// [`set_all_data_period`].
988    pub async fn get_all_data(&mut self) -> Result<AllData, TinkerforgeError> {
989        let payload = [0; 0];
990
991        #[allow(unused_variables)]
992        let result = self.device.get(u8::from(ImuV2BrickFunction::GetAllData), &payload).await?;
993        Ok(AllData::from_le_byte_slice(result.body()))
994    }
995
996    /// Turns the orientation and direction LEDs of the IMU Brick on.
997    pub async fn leds_on(&mut self) -> Result<(), TinkerforgeError> {
998        let payload = [0; 0];
999
1000        #[allow(unused_variables)]
1001        let result = self.device.set(u8::from(ImuV2BrickFunction::LedsOn), &payload).await?;
1002        Ok(())
1003    }
1004
1005    /// Turns the orientation and direction LEDs of the IMU Brick off.
1006    pub async fn leds_off(&mut self) -> Result<(), TinkerforgeError> {
1007        let payload = [0; 0];
1008
1009        #[allow(unused_variables)]
1010        let result = self.device.set(u8::from(ImuV2BrickFunction::LedsOff), &payload).await?;
1011        Ok(())
1012    }
1013
1014    /// Returns *true* if the orientation and direction LEDs of the IMU Brick
1015    /// are on, *false* otherwise.
1016    pub async fn are_leds_on(&mut self) -> Result<bool, TinkerforgeError> {
1017        let payload = [0; 0];
1018
1019        #[allow(unused_variables)]
1020        let result = self.device.get(u8::from(ImuV2BrickFunction::AreLedsOn), &payload).await?;
1021        Ok(bool::from_le_byte_slice(result.body()))
1022    }
1023
1024    /// A call of this function saves the current calibration to be used
1025    /// as a starting point for the next restart of continuous calibration
1026    /// of the IMU Brick.
1027    ///
1028    /// A return value of *true* means that the calibration could be used and
1029    /// *false* means that it could not be used (this happens if the calibration
1030    /// status is not fully calibrated).
1031    ///
1032    /// This function is used by the calibration window of the Brick Viewer, you
1033    /// should not need to call it in your program.
1034    pub async fn save_calibration(&mut self) -> Result<bool, TinkerforgeError> {
1035        let payload = [0; 0];
1036
1037        #[allow(unused_variables)]
1038        let result = self.device.get(u8::from(ImuV2BrickFunction::SaveCalibration), &payload).await?;
1039        Ok(bool::from_le_byte_slice(result.body()))
1040    }
1041
1042    /// Sets the period with which the [`get_acceleration_callback_receiver`] receiver is triggered
1043    /// periodically. A value of 0 turns the receiver off.
1044    pub async fn set_acceleration_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1045        let mut payload = [0; 4];
1046        period.write_to_slice(&mut payload[0..4]);
1047
1048        #[allow(unused_variables)]
1049        let result = self.device.set(u8::from(ImuV2BrickFunction::SetAccelerationPeriod), &payload).await?;
1050        Ok(())
1051    }
1052
1053    /// Returns the period as set by [`set_acceleration_period`].
1054    pub async fn get_acceleration_period(&mut self) -> Result<u32, TinkerforgeError> {
1055        let payload = [0; 0];
1056
1057        #[allow(unused_variables)]
1058        let result = self.device.get(u8::from(ImuV2BrickFunction::GetAccelerationPeriod), &payload).await?;
1059        Ok(u32::from_le_byte_slice(result.body()))
1060    }
1061
1062    /// Sets the period with which the [`get_magnetic_field_callback_receiver`] receiver is triggered
1063    /// periodically. A value of 0 turns the receiver off.
1064    pub async fn set_magnetic_field_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1065        let mut payload = [0; 4];
1066        period.write_to_slice(&mut payload[0..4]);
1067
1068        #[allow(unused_variables)]
1069        let result = self.device.set(u8::from(ImuV2BrickFunction::SetMagneticFieldPeriod), &payload).await?;
1070        Ok(())
1071    }
1072
1073    /// Returns the period as set by [`set_magnetic_field_period`].
1074    pub async fn get_magnetic_field_period(&mut self) -> Result<u32, TinkerforgeError> {
1075        let payload = [0; 0];
1076
1077        #[allow(unused_variables)]
1078        let result = self.device.get(u8::from(ImuV2BrickFunction::GetMagneticFieldPeriod), &payload).await?;
1079        Ok(u32::from_le_byte_slice(result.body()))
1080    }
1081
1082    /// Sets the period with which the [`get_angular_velocity_callback_receiver`] receiver is
1083    /// triggered periodically. A value of 0 turns the receiver off.
1084    pub async fn set_angular_velocity_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1085        let mut payload = [0; 4];
1086        period.write_to_slice(&mut payload[0..4]);
1087
1088        #[allow(unused_variables)]
1089        let result = self.device.set(u8::from(ImuV2BrickFunction::SetAngularVelocityPeriod), &payload).await?;
1090        Ok(())
1091    }
1092
1093    /// Returns the period as set by [`set_angular_velocity_period`].
1094    pub async fn get_angular_velocity_period(&mut self) -> Result<u32, TinkerforgeError> {
1095        let payload = [0; 0];
1096
1097        #[allow(unused_variables)]
1098        let result = self.device.get(u8::from(ImuV2BrickFunction::GetAngularVelocityPeriod), &payload).await?;
1099        Ok(u32::from_le_byte_slice(result.body()))
1100    }
1101
1102    /// Sets the period with which the [`get_temperature_callback_receiver`] receiver is triggered
1103    /// periodically. A value of 0 turns the receiver off.
1104    pub async fn set_temperature_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1105        let mut payload = [0; 4];
1106        period.write_to_slice(&mut payload[0..4]);
1107
1108        #[allow(unused_variables)]
1109        let result = self.device.set(u8::from(ImuV2BrickFunction::SetTemperaturePeriod), &payload).await?;
1110        Ok(())
1111    }
1112
1113    /// Returns the period as set by [`set_temperature_period`].
1114    pub async fn get_temperature_period(&mut self) -> Result<u32, TinkerforgeError> {
1115        let payload = [0; 0];
1116
1117        #[allow(unused_variables)]
1118        let result = self.device.get(u8::from(ImuV2BrickFunction::GetTemperaturePeriod), &payload).await?;
1119        Ok(u32::from_le_byte_slice(result.body()))
1120    }
1121
1122    /// Sets the period with which the [`get_orientation_callback_receiver`] receiver is triggered
1123    /// periodically. A value of 0 turns the receiver off.
1124    pub async fn set_orientation_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1125        let mut payload = [0; 4];
1126        period.write_to_slice(&mut payload[0..4]);
1127
1128        #[allow(unused_variables)]
1129        let result = self.device.set(u8::from(ImuV2BrickFunction::SetOrientationPeriod), &payload).await?;
1130        Ok(())
1131    }
1132
1133    /// Returns the period as set by [`set_orientation_period`].
1134    pub async fn get_orientation_period(&mut self) -> Result<u32, TinkerforgeError> {
1135        let payload = [0; 0];
1136
1137        #[allow(unused_variables)]
1138        let result = self.device.get(u8::from(ImuV2BrickFunction::GetOrientationPeriod), &payload).await?;
1139        Ok(u32::from_le_byte_slice(result.body()))
1140    }
1141
1142    /// Sets the period with which the [`get_linear_acceleration_callback_receiver`] receiver is
1143    /// triggered periodically. A value of 0 turns the receiver off.
1144    pub async fn set_linear_acceleration_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1145        let mut payload = [0; 4];
1146        period.write_to_slice(&mut payload[0..4]);
1147
1148        #[allow(unused_variables)]
1149        let result = self.device.set(u8::from(ImuV2BrickFunction::SetLinearAccelerationPeriod), &payload).await?;
1150        Ok(())
1151    }
1152
1153    /// Returns the period as set by [`set_linear_acceleration_period`].
1154    pub async fn get_linear_acceleration_period(&mut self) -> Result<u32, TinkerforgeError> {
1155        let payload = [0; 0];
1156
1157        #[allow(unused_variables)]
1158        let result = self.device.get(u8::from(ImuV2BrickFunction::GetLinearAccelerationPeriod), &payload).await?;
1159        Ok(u32::from_le_byte_slice(result.body()))
1160    }
1161
1162    /// Sets the period with which the [`get_gravity_vector_callback_receiver`] receiver is triggered
1163    /// periodically. A value of 0 turns the receiver off.
1164    pub async fn set_gravity_vector_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1165        let mut payload = [0; 4];
1166        period.write_to_slice(&mut payload[0..4]);
1167
1168        #[allow(unused_variables)]
1169        let result = self.device.set(u8::from(ImuV2BrickFunction::SetGravityVectorPeriod), &payload).await?;
1170        Ok(())
1171    }
1172
1173    /// Returns the period as set by [`set_gravity_vector_period`].
1174    pub async fn get_gravity_vector_period(&mut self) -> Result<u32, TinkerforgeError> {
1175        let payload = [0; 0];
1176
1177        #[allow(unused_variables)]
1178        let result = self.device.get(u8::from(ImuV2BrickFunction::GetGravityVectorPeriod), &payload).await?;
1179        Ok(u32::from_le_byte_slice(result.body()))
1180    }
1181
1182    /// Sets the period with which the [`get_quaternion_callback_receiver`] receiver is triggered
1183    /// periodically. A value of 0 turns the receiver off.
1184    pub async fn set_quaternion_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1185        let mut payload = [0; 4];
1186        period.write_to_slice(&mut payload[0..4]);
1187
1188        #[allow(unused_variables)]
1189        let result = self.device.set(u8::from(ImuV2BrickFunction::SetQuaternionPeriod), &payload).await?;
1190        Ok(())
1191    }
1192
1193    /// Returns the period as set by [`set_quaternion_period`].
1194    pub async fn get_quaternion_period(&mut self) -> Result<u32, TinkerforgeError> {
1195        let payload = [0; 0];
1196
1197        #[allow(unused_variables)]
1198        let result = self.device.get(u8::from(ImuV2BrickFunction::GetQuaternionPeriod), &payload).await?;
1199        Ok(u32::from_le_byte_slice(result.body()))
1200    }
1201
1202    /// Sets the period with which the [`get_all_data_callback_receiver`] receiver is triggered
1203    /// periodically. A value of 0 turns the receiver off.
1204    pub async fn set_all_data_period(&mut self, period: u32) -> Result<(), TinkerforgeError> {
1205        let mut payload = [0; 4];
1206        period.write_to_slice(&mut payload[0..4]);
1207
1208        #[allow(unused_variables)]
1209        let result = self.device.set(u8::from(ImuV2BrickFunction::SetAllDataPeriod), &payload).await?;
1210        Ok(())
1211    }
1212
1213    /// Returns the period as set by [`set_all_data_period`].
1214    pub async fn get_all_data_period(&mut self) -> Result<u32, TinkerforgeError> {
1215        let payload = [0; 0];
1216
1217        #[allow(unused_variables)]
1218        let result = self.device.get(u8::from(ImuV2BrickFunction::GetAllDataPeriod), &payload).await?;
1219        Ok(u32::from_le_byte_slice(result.body()))
1220    }
1221
1222    /// Sets the available sensor configuration for the Magnetometer, Gyroscope and
1223    /// Accelerometer. The Accelerometer Range is user selectable in all fusion modes,
1224    /// all other configurations are auto-controlled in fusion mode.
1225    ///
1226    ///
1227    /// .. versionadded:: 2.0.5$nbsp;(Firmware)
1228    ///
1229    /// Associated constants:
1230    /// * IMU_V2_BRICK_MAGNETOMETER_RATE_2HZ
1231    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_6HZ
1232    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_8HZ
1233    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_10HZ
1234    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_15HZ
1235    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_20HZ
1236    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_25HZ
1237    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_30HZ
1238    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_2000DPS
1239    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_1000DPS
1240    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_500DPS
1241    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_250DPS
1242    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_125DPS
1243    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_523HZ
1244    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_230HZ
1245    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_116HZ
1246    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_47HZ
1247    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_23HZ
1248    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_12HZ
1249    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_64HZ
1250    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_32HZ
1251    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_2G
1252    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_4G
1253    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_8G
1254    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_16G
1255    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_7_81HZ
1256    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_15_63HZ
1257    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_31_25HZ
1258    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_62_5HZ
1259    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_125HZ
1260    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_250HZ
1261    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_500HZ
1262    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_1000HZ
1263    pub async fn set_sensor_configuration(
1264        &mut self,
1265        magnetometer_rate: u8,
1266        gyroscope_range: u8,
1267        gyroscope_bandwidth: u8,
1268        accelerometer_range: u8,
1269        accelerometer_bandwidth: u8,
1270    ) -> Result<(), TinkerforgeError> {
1271        let mut payload = [0; 5];
1272        magnetometer_rate.write_to_slice(&mut payload[0..1]);
1273        gyroscope_range.write_to_slice(&mut payload[1..2]);
1274        gyroscope_bandwidth.write_to_slice(&mut payload[2..3]);
1275        accelerometer_range.write_to_slice(&mut payload[3..4]);
1276        accelerometer_bandwidth.write_to_slice(&mut payload[4..5]);
1277
1278        #[allow(unused_variables)]
1279        let result = self.device.set(u8::from(ImuV2BrickFunction::SetSensorConfiguration), &payload).await?;
1280        Ok(())
1281    }
1282
1283    /// Returns the sensor configuration as set by [`set_sensor_configuration`].
1284    ///
1285    ///
1286    /// .. versionadded:: 2.0.5$nbsp;(Firmware)
1287    ///
1288    /// Associated constants:
1289    /// * IMU_V2_BRICK_MAGNETOMETER_RATE_2HZ
1290    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_6HZ
1291    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_8HZ
1292    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_10HZ
1293    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_15HZ
1294    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_20HZ
1295    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_25HZ
1296    ///	* IMU_V2_BRICK_MAGNETOMETER_RATE_30HZ
1297    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_2000DPS
1298    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_1000DPS
1299    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_500DPS
1300    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_250DPS
1301    ///	* IMU_V2_BRICK_GYROSCOPE_RANGE_125DPS
1302    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_523HZ
1303    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_230HZ
1304    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_116HZ
1305    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_47HZ
1306    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_23HZ
1307    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_12HZ
1308    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_64HZ
1309    ///	* IMU_V2_BRICK_GYROSCOPE_BANDWIDTH_32HZ
1310    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_2G
1311    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_4G
1312    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_8G
1313    ///	* IMU_V2_BRICK_ACCELEROMETER_RANGE_16G
1314    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_7_81HZ
1315    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_15_63HZ
1316    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_31_25HZ
1317    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_62_5HZ
1318    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_125HZ
1319    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_250HZ
1320    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_500HZ
1321    ///	* IMU_V2_BRICK_ACCELEROMETER_BANDWIDTH_1000HZ
1322    pub async fn get_sensor_configuration(&mut self) -> Result<SensorConfiguration, TinkerforgeError> {
1323        let payload = [0; 0];
1324
1325        #[allow(unused_variables)]
1326        let result = self.device.get(u8::from(ImuV2BrickFunction::GetSensorConfiguration), &payload).await?;
1327        Ok(SensorConfiguration::from_le_byte_slice(result.body()))
1328    }
1329
1330    /// If the fusion mode is turned off, the functions [`get_acceleration`],
1331    /// [`get_magnetic_field`] and [`get_angular_velocity`] return uncalibrated
1332    /// and uncompensated sensor data. All other sensor data getters return no data.
1333    ///
1334    /// Since firmware version 2.0.6 you can also use a fusion mode without magnetometer.
1335    /// In this mode the calculated orientation is relative (with magnetometer it is
1336    /// absolute with respect to the earth). However, the calculation can't be influenced
1337    /// by spurious magnetic fields.
1338    ///
1339    /// Since firmware version 2.0.13 you can also use a fusion mode without fast
1340    /// magnetometer calibration. This mode is the same as the normal fusion mode,
1341    /// but the fast magnetometer calibration is turned off. So to find the orientation
1342    /// the first time will likely take longer, but small magnetic influences might
1343    /// not affect the automatic calibration as much.
1344    ///
1345    ///
1346    /// .. versionadded:: 2.0.5$nbsp;(Firmware)
1347    ///
1348    /// Associated constants:
1349    /// * IMU_V2_BRICK_SENSOR_FUSION_OFF
1350    ///	* IMU_V2_BRICK_SENSOR_FUSION_ON
1351    ///	* IMU_V2_BRICK_SENSOR_FUSION_ON_WITHOUT_MAGNETOMETER
1352    ///	* IMU_V2_BRICK_SENSOR_FUSION_ON_WITHOUT_FAST_MAGNETOMETER_CALIBRATION
1353    pub async fn set_sensor_fusion_mode(&mut self, mode: u8) -> Result<(), TinkerforgeError> {
1354        let mut payload = [0; 1];
1355        mode.write_to_slice(&mut payload[0..1]);
1356
1357        #[allow(unused_variables)]
1358        let result = self.device.set(u8::from(ImuV2BrickFunction::SetSensorFusionMode), &payload).await?;
1359        Ok(())
1360    }
1361
1362    /// Returns the sensor fusion mode as set by [`set_sensor_fusion_mode`].
1363    ///
1364    ///
1365    /// .. versionadded:: 2.0.5$nbsp;(Firmware)
1366    ///
1367    /// Associated constants:
1368    /// * IMU_V2_BRICK_SENSOR_FUSION_OFF
1369    ///	* IMU_V2_BRICK_SENSOR_FUSION_ON
1370    ///	* IMU_V2_BRICK_SENSOR_FUSION_ON_WITHOUT_MAGNETOMETER
1371    ///	* IMU_V2_BRICK_SENSOR_FUSION_ON_WITHOUT_FAST_MAGNETOMETER_CALIBRATION
1372    pub async fn get_sensor_fusion_mode(&mut self) -> Result<u8, TinkerforgeError> {
1373        let payload = [0; 0];
1374
1375        #[allow(unused_variables)]
1376        let result = self.device.get(u8::from(ImuV2BrickFunction::GetSensorFusionMode), &payload).await?;
1377        Ok(u8::from_le_byte_slice(result.body()))
1378    }
1379
1380    /// The SPITF protocol can be used with a dynamic baudrate. If the dynamic baudrate is
1381    /// enabled, the Brick will try to adapt the baudrate for the communication
1382    /// between Bricks and Bricklets according to the amount of data that is transferred.
1383    ///
1384    /// The baudrate will be increased exponentially if lots of data is sent/received and
1385    /// decreased linearly if little data is sent/received.
1386    ///
1387    /// This lowers the baudrate in applications where little data is transferred (e.g.
1388    /// a weather station) and increases the robustness. If there is lots of data to transfer
1389    /// (e.g. Thermal Imaging Bricklet) it automatically increases the baudrate as needed.
1390    ///
1391    /// In cases where some data has to transferred as fast as possible every few seconds
1392    /// (e.g. RS485 Bricklet with a high baudrate but small payload) you may want to turn
1393    /// the dynamic baudrate off to get the highest possible performance.
1394    ///
1395    /// The maximum value of the baudrate can be set per port with the function
1396    /// [`set_spitfp_baudrate`]. If the dynamic baudrate is disabled, the baudrate
1397    /// as set by [`set_spitfp_baudrate`] will be used statically.
1398    ///
1399    ///
1400    /// .. versionadded:: 2.0.10$nbsp;(Firmware)
1401    pub async fn set_spitfp_baudrate_config(
1402        &mut self,
1403        enable_dynamic_baudrate: bool,
1404        minimum_dynamic_baudrate: u32,
1405    ) -> Result<(), TinkerforgeError> {
1406        let mut payload = [0; 5];
1407        enable_dynamic_baudrate.write_to_slice(&mut payload[0..1]);
1408        minimum_dynamic_baudrate.write_to_slice(&mut payload[1..5]);
1409
1410        #[allow(unused_variables)]
1411        let result = self.device.set(u8::from(ImuV2BrickFunction::SetSpitfpBaudrateConfig), &payload).await?;
1412        Ok(())
1413    }
1414
1415    /// Returns the baudrate config, see [`set_spitfp_baudrate_config`].
1416    ///
1417    ///
1418    /// .. versionadded:: 2.0.10$nbsp;(Firmware)
1419    pub async fn get_spitfp_baudrate_config(&mut self) -> Result<SpitfpBaudrateConfig, TinkerforgeError> {
1420        let payload = [0; 0];
1421
1422        #[allow(unused_variables)]
1423        let result = self.device.get(u8::from(ImuV2BrickFunction::GetSpitfpBaudrateConfig), &payload).await?;
1424        Ok(SpitfpBaudrateConfig::from_le_byte_slice(result.body()))
1425    }
1426
1427    /// Returns the timeout count for the different communication methods.
1428    ///
1429    /// The methods 0-2 are available for all Bricks, 3-7 only for Master Bricks.
1430    ///
1431    /// This function is mostly used for debugging during development, in normal operation
1432    /// the counters should nearly always stay at 0.
1433    ///
1434    ///
1435    /// .. versionadded:: 2.0.7$nbsp;(Firmware)
1436    ///
1437    /// Associated constants:
1438    /// * IMU_V2_BRICK_COMMUNICATION_METHOD_NONE
1439    ///	* IMU_V2_BRICK_COMMUNICATION_METHOD_USB
1440    ///	* IMU_V2_BRICK_COMMUNICATION_METHOD_SPI_STACK
1441    ///	* IMU_V2_BRICK_COMMUNICATION_METHOD_CHIBI
1442    ///	* IMU_V2_BRICK_COMMUNICATION_METHOD_RS485
1443    ///	* IMU_V2_BRICK_COMMUNICATION_METHOD_WIFI
1444    ///	* IMU_V2_BRICK_COMMUNICATION_METHOD_ETHERNET
1445    ///	* IMU_V2_BRICK_COMMUNICATION_METHOD_WIFI_V2
1446    pub async fn get_send_timeout_count(&mut self, communication_method: u8) -> Result<u32, TinkerforgeError> {
1447        let mut payload = [0; 1];
1448        communication_method.write_to_slice(&mut payload[0..1]);
1449
1450        #[allow(unused_variables)]
1451        let result = self.device.get(u8::from(ImuV2BrickFunction::GetSendTimeoutCount), &payload).await?;
1452        Ok(u32::from_le_byte_slice(result.body()))
1453    }
1454
1455    /// Sets the baudrate for a specific Bricklet port.
1456    ///
1457    /// If you want to increase the throughput of Bricklets you can increase
1458    /// the baudrate. If you get a high error count because of high
1459    /// interference (see [`get_spitfp_error_count`]) you can decrease the
1460    /// baudrate.
1461    ///
1462    /// If the dynamic baudrate feature is enabled, the baudrate set by this
1463    /// function corresponds to the maximum baudrate (see [`set_spitfp_baudrate_config`]).
1464    ///
1465    /// Regulatory testing is done with the default baudrate. If CE compatibility
1466    /// or similar is necessary in your applications we recommend to not change
1467    /// the baudrate.
1468    ///
1469    ///
1470    /// .. versionadded:: 2.0.5$nbsp;(Firmware)
1471    pub async fn set_spitfp_baudrate(&mut self, bricklet_port: char, baudrate: u32) -> Result<(), TinkerforgeError> {
1472        let mut payload = [0; 5];
1473        bricklet_port.write_to_slice(&mut payload[0..1]);
1474        baudrate.write_to_slice(&mut payload[1..5]);
1475
1476        #[allow(unused_variables)]
1477        let result = self.device.set(u8::from(ImuV2BrickFunction::SetSpitfpBaudrate), &payload).await?;
1478        Ok(())
1479    }
1480
1481    /// Returns the baudrate for a given Bricklet port, see [`set_spitfp_baudrate`].
1482    ///
1483    ///
1484    /// .. versionadded:: 2.0.5$nbsp;(Firmware)
1485    pub async fn get_spitfp_baudrate(&mut self, bricklet_port: char) -> Result<u32, TinkerforgeError> {
1486        let mut payload = [0; 1];
1487        bricklet_port.write_to_slice(&mut payload[0..1]);
1488
1489        #[allow(unused_variables)]
1490        let result = self.device.get(u8::from(ImuV2BrickFunction::GetSpitfpBaudrate), &payload).await?;
1491        Ok(u32::from_le_byte_slice(result.body()))
1492    }
1493
1494    /// Returns the error count for the communication between Brick and Bricklet.
1495    ///
1496    /// The errors are divided into
1497    ///
1498    /// * ACK checksum errors,
1499    /// * message checksum errors,
1500    /// * framing errors and
1501    /// * overflow errors.
1502    ///
1503    /// The errors counts are for errors that occur on the Brick side. All
1504    /// Bricklets have a similar function that returns the errors on the Bricklet side.
1505    ///
1506    ///
1507    /// .. versionadded:: 2.0.5$nbsp;(Firmware)
1508    pub async fn get_spitfp_error_count(&mut self, bricklet_port: char) -> Result<SpitfpErrorCount, TinkerforgeError> {
1509        let mut payload = [0; 1];
1510        bricklet_port.write_to_slice(&mut payload[0..1]);
1511
1512        #[allow(unused_variables)]
1513        let result = self.device.get(u8::from(ImuV2BrickFunction::GetSpitfpErrorCount), &payload).await?;
1514        Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
1515    }
1516
1517    /// Enables the status LED.
1518    ///
1519    /// The status LED is the blue LED next to the USB connector. If enabled is is
1520    /// on and it flickers if data is transfered. If disabled it is always off.
1521    ///
1522    /// The default state is enabled.
1523    pub async fn enable_status_led(&mut self) -> Result<(), TinkerforgeError> {
1524        let payload = [0; 0];
1525
1526        #[allow(unused_variables)]
1527        let result = self.device.set(u8::from(ImuV2BrickFunction::EnableStatusLed), &payload).await?;
1528        Ok(())
1529    }
1530
1531    /// Disables the status LED.
1532    ///
1533    /// The status LED is the blue LED next to the USB connector. If enabled is is
1534    /// on and it flickers if data is transfered. If disabled it is always off.
1535    ///
1536    /// The default state is enabled.
1537    pub async fn disable_status_led(&mut self) -> Result<(), TinkerforgeError> {
1538        let payload = [0; 0];
1539
1540        #[allow(unused_variables)]
1541        let result = self.device.set(u8::from(ImuV2BrickFunction::DisableStatusLed), &payload).await?;
1542        Ok(())
1543    }
1544
1545    /// Returns *true* if the status LED is enabled, *false* otherwise.
1546    pub async fn is_status_led_enabled(&mut self) -> Result<bool, TinkerforgeError> {
1547        let payload = [0; 0];
1548
1549        #[allow(unused_variables)]
1550        let result = self.device.get(u8::from(ImuV2BrickFunction::IsStatusLedEnabled), &payload).await?;
1551        Ok(bool::from_le_byte_slice(result.body()))
1552    }
1553
1554    /// Returns the firmware and protocol version and the name of the Bricklet for a
1555    /// given port.
1556    ///
1557    /// This functions sole purpose is to allow automatic flashing of v1.x.y Bricklet
1558    /// plugins.
1559    pub async fn get_protocol1_bricklet_name(&mut self, port: char) -> Result<Protocol1BrickletName, TinkerforgeError> {
1560        let mut payload = [0; 1];
1561        port.write_to_slice(&mut payload[0..1]);
1562
1563        #[allow(unused_variables)]
1564        let result = self.device.get(u8::from(ImuV2BrickFunction::GetProtocol1BrickletName), &payload).await?;
1565        Ok(Protocol1BrickletName::from_le_byte_slice(result.body()))
1566    }
1567
1568    /// Returns the temperature as measured inside the microcontroller. The
1569    /// value returned is not the ambient temperature!
1570    ///
1571    /// The temperature is only proportional to the real temperature and it has an
1572    /// accuracy of ±15%. Practically it is only useful as an indicator for
1573    /// temperature changes.
1574    pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
1575        let payload = [0; 0];
1576
1577        #[allow(unused_variables)]
1578        let result = self.device.get(u8::from(ImuV2BrickFunction::GetChipTemperature), &payload).await?;
1579        Ok(i16::from_le_byte_slice(result.body()))
1580    }
1581
1582    /// Calling this function will reset the Brick. Calling this function
1583    /// on a Brick inside of a stack will reset the whole stack.
1584    ///
1585    /// After a reset you have to create new device objects,
1586    /// calling functions on the existing ones will result in
1587    /// undefined behavior!
1588    pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
1589        let payload = [0; 0];
1590
1591        #[allow(unused_variables)]
1592        let result = self.device.set(u8::from(ImuV2BrickFunction::Reset), &payload).await?;
1593        Ok(())
1594    }
1595
1596    /// Writes 32 bytes of firmware to the bricklet attached at the given port.
1597    /// The bytes are written to the position offset * 32.
1598    ///
1599    /// This function is used by Brick Viewer during flashing. It should not be
1600    /// necessary to call it in a normal user program.
1601    pub async fn write_bricklet_plugin(&mut self, port: char, offset: u8, chunk: &[u8; 32]) -> Result<(), TinkerforgeError> {
1602        let mut payload = [0; 34];
1603        port.write_to_slice(&mut payload[0..1]);
1604        offset.write_to_slice(&mut payload[1..2]);
1605        chunk.write_to_slice(&mut payload[2..34]);
1606
1607        #[allow(unused_variables)]
1608        let result = self.device.set(u8::from(ImuV2BrickFunction::WriteBrickletPlugin), &payload).await?;
1609        Ok(())
1610    }
1611
1612    /// Reads 32 bytes of firmware from the bricklet attached at the given port.
1613    /// The bytes are read starting at the position offset * 32.
1614    ///
1615    /// This function is used by Brick Viewer during flashing. It should not be
1616    /// necessary to call it in a normal user program.
1617    pub async fn read_bricklet_plugin(&mut self, port: char, offset: u8) -> Result<Box<[u8; 32]>, TinkerforgeError> {
1618        let mut payload = [0; 2];
1619        port.write_to_slice(&mut payload[0..1]);
1620        offset.write_to_slice(&mut payload[1..2]);
1621
1622        #[allow(unused_variables)]
1623        let result = self.device.get(u8::from(ImuV2BrickFunction::ReadBrickletPlugin), &payload).await?;
1624        Ok(Box::<[u8; 32]>::from_le_byte_slice(result.body()))
1625    }
1626
1627    /// Returns the UID, the UID where the Brick is connected to,
1628    /// the position, the hardware and firmware version as well as the
1629    /// device identifier.
1630    ///
1631    /// The position is the position in the stack from '0' (bottom) to '8' (top).
1632    ///
1633    /// The device identifier numbers can be found [here](device_identifier).
1634    /// |device_identifier_constant|
1635    pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
1636        let payload = [0; 0];
1637
1638        #[allow(unused_variables)]
1639        let result = self.device.get(u8::from(ImuV2BrickFunction::GetIdentity), &payload).await?;
1640        Ok(Identity::from_le_byte_slice(result.body()))
1641    }
1642}