use crate::{
byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
ip_connection::GetRequestSender,
};
pub enum ImuBrickFunction {
GetAcceleration,
GetMagneticField,
GetAngularVelocity,
GetAllData,
GetOrientation,
GetQuaternion,
GetImuTemperature,
LedsOn,
LedsOff,
AreLedsOn,
SetAccelerationRange,
GetAccelerationRange,
SetMagnetometerRange,
GetMagnetometerRange,
SetConvergenceSpeed,
GetConvergenceSpeed,
SetCalibration,
GetCalibration,
SetAccelerationPeriod,
GetAccelerationPeriod,
SetMagneticFieldPeriod,
GetMagneticFieldPeriod,
SetAngularVelocityPeriod,
GetAngularVelocityPeriod,
SetAllDataPeriod,
GetAllDataPeriod,
SetOrientationPeriod,
GetOrientationPeriod,
SetQuaternionPeriod,
GetQuaternionPeriod,
OrientationCalculationOn,
OrientationCalculationOff,
IsOrientationCalculationOn,
SetSpitfpBaudrateConfig,
GetSpitfpBaudrateConfig,
GetSendTimeoutCount,
SetSpitfpBaudrate,
GetSpitfpBaudrate,
GetSpitfpErrorCount,
EnableStatusLed,
DisableStatusLed,
IsStatusLedEnabled,
GetProtocol1BrickletName,
GetChipTemperature,
Reset,
WriteBrickletPlugin,
ReadBrickletPlugin,
GetIdentity,
CallbackAcceleration,
CallbackMagneticField,
CallbackAngularVelocity,
CallbackAllData,
CallbackOrientation,
CallbackQuaternion,
}
impl From<ImuBrickFunction> for u8 {
fn from(fun: ImuBrickFunction) -> Self {
match fun {
ImuBrickFunction::GetAcceleration => 1,
ImuBrickFunction::GetMagneticField => 2,
ImuBrickFunction::GetAngularVelocity => 3,
ImuBrickFunction::GetAllData => 4,
ImuBrickFunction::GetOrientation => 5,
ImuBrickFunction::GetQuaternion => 6,
ImuBrickFunction::GetImuTemperature => 7,
ImuBrickFunction::LedsOn => 8,
ImuBrickFunction::LedsOff => 9,
ImuBrickFunction::AreLedsOn => 10,
ImuBrickFunction::SetAccelerationRange => 11,
ImuBrickFunction::GetAccelerationRange => 12,
ImuBrickFunction::SetMagnetometerRange => 13,
ImuBrickFunction::GetMagnetometerRange => 14,
ImuBrickFunction::SetConvergenceSpeed => 15,
ImuBrickFunction::GetConvergenceSpeed => 16,
ImuBrickFunction::SetCalibration => 17,
ImuBrickFunction::GetCalibration => 18,
ImuBrickFunction::SetAccelerationPeriod => 19,
ImuBrickFunction::GetAccelerationPeriod => 20,
ImuBrickFunction::SetMagneticFieldPeriod => 21,
ImuBrickFunction::GetMagneticFieldPeriod => 22,
ImuBrickFunction::SetAngularVelocityPeriod => 23,
ImuBrickFunction::GetAngularVelocityPeriod => 24,
ImuBrickFunction::SetAllDataPeriod => 25,
ImuBrickFunction::GetAllDataPeriod => 26,
ImuBrickFunction::SetOrientationPeriod => 27,
ImuBrickFunction::GetOrientationPeriod => 28,
ImuBrickFunction::SetQuaternionPeriod => 29,
ImuBrickFunction::GetQuaternionPeriod => 30,
ImuBrickFunction::OrientationCalculationOn => 37,
ImuBrickFunction::OrientationCalculationOff => 38,
ImuBrickFunction::IsOrientationCalculationOn => 39,
ImuBrickFunction::SetSpitfpBaudrateConfig => 231,
ImuBrickFunction::GetSpitfpBaudrateConfig => 232,
ImuBrickFunction::GetSendTimeoutCount => 233,
ImuBrickFunction::SetSpitfpBaudrate => 234,
ImuBrickFunction::GetSpitfpBaudrate => 235,
ImuBrickFunction::GetSpitfpErrorCount => 237,
ImuBrickFunction::EnableStatusLed => 238,
ImuBrickFunction::DisableStatusLed => 239,
ImuBrickFunction::IsStatusLedEnabled => 240,
ImuBrickFunction::GetProtocol1BrickletName => 241,
ImuBrickFunction::GetChipTemperature => 242,
ImuBrickFunction::Reset => 243,
ImuBrickFunction::WriteBrickletPlugin => 246,
ImuBrickFunction::ReadBrickletPlugin => 247,
ImuBrickFunction::GetIdentity => 255,
ImuBrickFunction::CallbackAcceleration => 31,
ImuBrickFunction::CallbackMagneticField => 32,
ImuBrickFunction::CallbackAngularVelocity => 33,
ImuBrickFunction::CallbackAllData => 34,
ImuBrickFunction::CallbackOrientation => 35,
ImuBrickFunction::CallbackQuaternion => 36,
}
}
}
pub const IMU_BRICK_CALIBRATION_TYPE_ACCELEROMETER_GAIN: u8 = 0;
pub const IMU_BRICK_CALIBRATION_TYPE_ACCELEROMETER_BIAS: u8 = 1;
pub const IMU_BRICK_CALIBRATION_TYPE_MAGNETOMETER_GAIN: u8 = 2;
pub const IMU_BRICK_CALIBRATION_TYPE_MAGNETOMETER_BIAS: u8 = 3;
pub const IMU_BRICK_CALIBRATION_TYPE_GYROSCOPE_GAIN: u8 = 4;
pub const IMU_BRICK_CALIBRATION_TYPE_GYROSCOPE_BIAS: u8 = 5;
pub const IMU_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
pub const IMU_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
pub const IMU_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
pub const IMU_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
pub const IMU_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
pub const IMU_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
pub const IMU_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
pub const IMU_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Acceleration {
pub x: i16,
pub y: i16,
pub z: i16,
}
impl FromByteSlice for Acceleration {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> Acceleration {
Acceleration {
x: <i16>::from_le_byte_slice(&bytes[0..2]),
y: <i16>::from_le_byte_slice(&bytes[2..4]),
z: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct MagneticField {
pub x: i16,
pub y: i16,
pub z: i16,
}
impl FromByteSlice for MagneticField {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> MagneticField {
MagneticField {
x: <i16>::from_le_byte_slice(&bytes[0..2]),
y: <i16>::from_le_byte_slice(&bytes[2..4]),
z: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AngularVelocity {
pub x: i16,
pub y: i16,
pub z: i16,
}
impl FromByteSlice for AngularVelocity {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> AngularVelocity {
AngularVelocity {
x: <i16>::from_le_byte_slice(&bytes[0..2]),
y: <i16>::from_le_byte_slice(&bytes[2..4]),
z: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AllData {
pub acc_x: i16,
pub acc_y: i16,
pub acc_z: i16,
pub mag_x: i16,
pub mag_y: i16,
pub mag_z: i16,
pub ang_x: i16,
pub ang_y: i16,
pub ang_z: i16,
pub temperature: i16,
}
impl FromByteSlice for AllData {
fn bytes_expected() -> usize { 20 }
fn from_le_byte_slice(bytes: &[u8]) -> AllData {
AllData {
acc_x: <i16>::from_le_byte_slice(&bytes[0..2]),
acc_y: <i16>::from_le_byte_slice(&bytes[2..4]),
acc_z: <i16>::from_le_byte_slice(&bytes[4..6]),
mag_x: <i16>::from_le_byte_slice(&bytes[6..8]),
mag_y: <i16>::from_le_byte_slice(&bytes[8..10]),
mag_z: <i16>::from_le_byte_slice(&bytes[10..12]),
ang_x: <i16>::from_le_byte_slice(&bytes[12..14]),
ang_y: <i16>::from_le_byte_slice(&bytes[14..16]),
ang_z: <i16>::from_le_byte_slice(&bytes[16..18]),
temperature: <i16>::from_le_byte_slice(&bytes[18..20]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Orientation {
pub roll: i16,
pub pitch: i16,
pub yaw: i16,
}
impl FromByteSlice for Orientation {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> Orientation {
Orientation {
roll: <i16>::from_le_byte_slice(&bytes[0..2]),
pitch: <i16>::from_le_byte_slice(&bytes[2..4]),
yaw: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Quaternion {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}
impl FromByteSlice for Quaternion {
fn bytes_expected() -> usize { 16 }
fn from_le_byte_slice(bytes: &[u8]) -> Quaternion {
Quaternion {
x: <f32>::from_le_byte_slice(&bytes[0..4]),
y: <f32>::from_le_byte_slice(&bytes[4..8]),
z: <f32>::from_le_byte_slice(&bytes[8..12]),
w: <f32>::from_le_byte_slice(&bytes[12..16]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AccelerationEvent {
pub x: i16,
pub y: i16,
pub z: i16,
}
impl FromByteSlice for AccelerationEvent {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> AccelerationEvent {
AccelerationEvent {
x: <i16>::from_le_byte_slice(&bytes[0..2]),
y: <i16>::from_le_byte_slice(&bytes[2..4]),
z: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct MagneticFieldEvent {
pub x: i16,
pub y: i16,
pub z: i16,
}
impl FromByteSlice for MagneticFieldEvent {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> MagneticFieldEvent {
MagneticFieldEvent {
x: <i16>::from_le_byte_slice(&bytes[0..2]),
y: <i16>::from_le_byte_slice(&bytes[2..4]),
z: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AngularVelocityEvent {
pub x: i16,
pub y: i16,
pub z: i16,
}
impl FromByteSlice for AngularVelocityEvent {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> AngularVelocityEvent {
AngularVelocityEvent {
x: <i16>::from_le_byte_slice(&bytes[0..2]),
y: <i16>::from_le_byte_slice(&bytes[2..4]),
z: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct AllDataEvent {
pub acc_x: i16,
pub acc_y: i16,
pub acc_z: i16,
pub mag_x: i16,
pub mag_y: i16,
pub mag_z: i16,
pub ang_x: i16,
pub ang_y: i16,
pub ang_z: i16,
pub temperature: i16,
}
impl FromByteSlice for AllDataEvent {
fn bytes_expected() -> usize { 20 }
fn from_le_byte_slice(bytes: &[u8]) -> AllDataEvent {
AllDataEvent {
acc_x: <i16>::from_le_byte_slice(&bytes[0..2]),
acc_y: <i16>::from_le_byte_slice(&bytes[2..4]),
acc_z: <i16>::from_le_byte_slice(&bytes[4..6]),
mag_x: <i16>::from_le_byte_slice(&bytes[6..8]),
mag_y: <i16>::from_le_byte_slice(&bytes[8..10]),
mag_z: <i16>::from_le_byte_slice(&bytes[10..12]),
ang_x: <i16>::from_le_byte_slice(&bytes[12..14]),
ang_y: <i16>::from_le_byte_slice(&bytes[14..16]),
ang_z: <i16>::from_le_byte_slice(&bytes[16..18]),
temperature: <i16>::from_le_byte_slice(&bytes[18..20]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct OrientationEvent {
pub roll: i16,
pub pitch: i16,
pub yaw: i16,
}
impl FromByteSlice for OrientationEvent {
fn bytes_expected() -> usize { 6 }
fn from_le_byte_slice(bytes: &[u8]) -> OrientationEvent {
OrientationEvent {
roll: <i16>::from_le_byte_slice(&bytes[0..2]),
pitch: <i16>::from_le_byte_slice(&bytes[2..4]),
yaw: <i16>::from_le_byte_slice(&bytes[4..6]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct QuaternionEvent {
pub x: f32,
pub y: f32,
pub z: f32,
pub w: f32,
}
impl FromByteSlice for QuaternionEvent {
fn bytes_expected() -> usize { 16 }
fn from_le_byte_slice(bytes: &[u8]) -> QuaternionEvent {
QuaternionEvent {
x: <f32>::from_le_byte_slice(&bytes[0..4]),
y: <f32>::from_le_byte_slice(&bytes[4..8]),
z: <f32>::from_le_byte_slice(&bytes[8..12]),
w: <f32>::from_le_byte_slice(&bytes[12..16]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpBaudrateConfig {
pub enable_dynamic_baudrate: bool,
pub minimum_dynamic_baudrate: u32,
}
impl FromByteSlice for SpitfpBaudrateConfig {
fn bytes_expected() -> usize { 5 }
fn from_le_byte_slice(bytes: &[u8]) -> SpitfpBaudrateConfig {
SpitfpBaudrateConfig {
enable_dynamic_baudrate: <bool>::from_le_byte_slice(&bytes[0..1]),
minimum_dynamic_baudrate: <u32>::from_le_byte_slice(&bytes[1..5]),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct SpitfpErrorCount {
pub error_count_ack_checksum: u32,
pub error_count_message_checksum: u32,
pub error_count_frame: u32,
pub error_count_overflow: u32,
}
impl FromByteSlice for SpitfpErrorCount {
fn bytes_expected() -> usize { 16 }
fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
SpitfpErrorCount {
error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
}
}
}
#[derive(Clone)]
pub struct Protocol1BrickletName {
pub protocol_version: u8,
pub firmware_version: [u8; 3],
pub name: String,
}
impl FromByteSlice for Protocol1BrickletName {
fn bytes_expected() -> usize { 44 }
fn from_le_byte_slice(bytes: &[u8]) -> Protocol1BrickletName {
Protocol1BrickletName {
protocol_version: <u8>::from_le_byte_slice(&bytes[0..1]),
firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[1..4]),
name: <String>::from_le_byte_slice(&bytes[4..44]),
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct Identity {
pub uid: String,
pub connected_uid: String,
pub position: char,
pub hardware_version: [u8; 3],
pub firmware_version: [u8; 3],
pub device_identifier: u16,
}
impl FromByteSlice for Identity {
fn bytes_expected() -> usize { 25 }
fn from_le_byte_slice(bytes: &[u8]) -> Identity {
Identity {
uid: <String>::from_le_byte_slice(&bytes[0..8]),
connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
position: <char>::from_le_byte_slice(&bytes[16..17]),
hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
}
}
}
#[derive(Clone)]
pub struct ImuBrick {
device: Device,
}
impl ImuBrick {
pub const DEVICE_IDENTIFIER: u16 = 16;
pub const DEVICE_DISPLAY_NAME: &'static str = "IMU Brick";
pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> ImuBrick {
let mut result = ImuBrick { device: Device::new([2, 0, 4], uid, req_sender, 0) };
result.device.response_expected[u8::from(ImuBrickFunction::GetAcceleration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetMagneticField) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetAngularVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetAllData) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetOrientation) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetQuaternion) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetImuTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::LedsOn) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::LedsOff) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::AreLedsOn) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetAccelerationRange) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::GetAccelerationRange) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetMagnetometerRange) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::GetMagnetometerRange) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetConvergenceSpeed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::GetConvergenceSpeed) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetCalibration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::GetCalibration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetAccelerationPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ImuBrickFunction::GetAccelerationPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetMagneticFieldPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ImuBrickFunction::GetMagneticFieldPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetAngularVelocityPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ImuBrickFunction::GetAngularVelocityPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetAllDataPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ImuBrickFunction::GetAllDataPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetOrientationPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ImuBrickFunction::GetOrientationPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetQuaternionPeriod) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ImuBrickFunction::GetQuaternionPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::OrientationCalculationOn) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::OrientationCalculationOff) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::IsOrientationCalculationOn) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::GetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetProtocol1BrickletName) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::WriteBrickletPlugin) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ImuBrickFunction::ReadBrickletPlugin) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ImuBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
result
}
pub fn get_response_expected(&mut self, fun: ImuBrickFunction) -> Result<bool, GetResponseExpectedError> {
self.device.get_response_expected(u8::from(fun))
}
pub fn set_response_expected(&mut self, fun: ImuBrickFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
self.device.set_response_expected(u8::from(fun), response_expected)
}
pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
pub fn get_acceleration_callback_receiver(&self) -> ConvertingCallbackReceiver<AccelerationEvent> {
self.device.get_callback_receiver(u8::from(ImuBrickFunction::CallbackAcceleration))
}
pub fn get_magnetic_field_callback_receiver(&self) -> ConvertingCallbackReceiver<MagneticFieldEvent> {
self.device.get_callback_receiver(u8::from(ImuBrickFunction::CallbackMagneticField))
}
pub fn get_angular_velocity_callback_receiver(&self) -> ConvertingCallbackReceiver<AngularVelocityEvent> {
self.device.get_callback_receiver(u8::from(ImuBrickFunction::CallbackAngularVelocity))
}
pub fn get_all_data_callback_receiver(&self) -> ConvertingCallbackReceiver<AllDataEvent> {
self.device.get_callback_receiver(u8::from(ImuBrickFunction::CallbackAllData))
}
pub fn get_orientation_callback_receiver(&self) -> ConvertingCallbackReceiver<OrientationEvent> {
self.device.get_callback_receiver(u8::from(ImuBrickFunction::CallbackOrientation))
}
pub fn get_quaternion_callback_receiver(&self) -> ConvertingCallbackReceiver<QuaternionEvent> {
self.device.get_callback_receiver(u8::from(ImuBrickFunction::CallbackQuaternion))
}
pub fn get_acceleration(&self) -> ConvertingReceiver<Acceleration> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetAcceleration), payload)
}
pub fn get_magnetic_field(&self) -> ConvertingReceiver<MagneticField> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetMagneticField), payload)
}
pub fn get_angular_velocity(&self) -> ConvertingReceiver<AngularVelocity> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetAngularVelocity), payload)
}
pub fn get_all_data(&self) -> ConvertingReceiver<AllData> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetAllData), payload)
}
pub fn get_orientation(&self) -> ConvertingReceiver<Orientation> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetOrientation), payload)
}
pub fn get_quaternion(&self) -> ConvertingReceiver<Quaternion> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetQuaternion), payload)
}
pub fn get_imu_temperature(&self) -> ConvertingReceiver<i16> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetImuTemperature), payload)
}
pub fn leds_on(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ImuBrickFunction::LedsOn), payload)
}
pub fn leds_off(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ImuBrickFunction::LedsOff), payload)
}
pub fn are_leds_on(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::AreLedsOn), payload)
}
pub fn set_acceleration_range(&self, range: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(range));
self.device.set(u8::from(ImuBrickFunction::SetAccelerationRange), payload)
}
pub fn get_acceleration_range(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetAccelerationRange), payload)
}
pub fn set_magnetometer_range(&self, range: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(range));
self.device.set(u8::from(ImuBrickFunction::SetMagnetometerRange), payload)
}
pub fn get_magnetometer_range(&self) -> ConvertingReceiver<u8> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetMagnetometerRange), payload)
}
pub fn set_convergence_speed(&self, speed: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 2];
payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(speed));
self.device.set(u8::from(ImuBrickFunction::SetConvergenceSpeed), payload)
}
pub fn get_convergence_speed(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetConvergenceSpeed), payload)
}
pub fn set_calibration(&self, typ: u8, data: [i16; 10]) -> ConvertingReceiver<()> {
let mut payload = vec![0; 21];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(typ));
payload[1..21].copy_from_slice(&<[i16; 10]>::to_le_byte_vec(data));
self.device.set(u8::from(ImuBrickFunction::SetCalibration), payload)
}
pub fn get_calibration(&self, typ: u8) -> ConvertingReceiver<[i16; 10]> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(typ));
self.device.get(u8::from(ImuBrickFunction::GetCalibration), payload)
}
pub fn set_acceleration_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(ImuBrickFunction::SetAccelerationPeriod), payload)
}
pub fn get_acceleration_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetAccelerationPeriod), payload)
}
pub fn set_magnetic_field_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(ImuBrickFunction::SetMagneticFieldPeriod), payload)
}
pub fn get_magnetic_field_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetMagneticFieldPeriod), payload)
}
pub fn set_angular_velocity_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(ImuBrickFunction::SetAngularVelocityPeriod), payload)
}
pub fn get_angular_velocity_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetAngularVelocityPeriod), payload)
}
pub fn set_all_data_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(ImuBrickFunction::SetAllDataPeriod), payload)
}
pub fn get_all_data_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetAllDataPeriod), payload)
}
pub fn set_orientation_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(ImuBrickFunction::SetOrientationPeriod), payload)
}
pub fn get_orientation_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetOrientationPeriod), payload)
}
pub fn set_quaternion_period(&self, period: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 4];
payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
self.device.set(u8::from(ImuBrickFunction::SetQuaternionPeriod), payload)
}
pub fn get_quaternion_period(&self) -> ConvertingReceiver<u32> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetQuaternionPeriod), payload)
}
pub fn orientation_calculation_on(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ImuBrickFunction::OrientationCalculationOn), payload)
}
pub fn orientation_calculation_off(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ImuBrickFunction::OrientationCalculationOff), payload)
}
pub fn is_orientation_calculation_on(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::IsOrientationCalculationOn), payload)
}
pub fn set_spitfp_baudrate_config(&self, enable_dynamic_baudrate: bool, minimum_dynamic_baudrate: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<bool>::to_le_byte_vec(enable_dynamic_baudrate));
payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(minimum_dynamic_baudrate));
self.device.set(u8::from(ImuBrickFunction::SetSpitfpBaudrateConfig), payload)
}
pub fn get_spitfp_baudrate_config(&self) -> ConvertingReceiver<SpitfpBaudrateConfig> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetSpitfpBaudrateConfig), payload)
}
pub fn get_send_timeout_count(&self, communication_method: u8) -> ConvertingReceiver<u32> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(communication_method));
self.device.get(u8::from(ImuBrickFunction::GetSendTimeoutCount), payload)
}
pub fn set_spitfp_baudrate(&self, bricklet_port: char, baudrate: u32) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
payload[1..5].copy_from_slice(&<u32>::to_le_byte_vec(baudrate));
self.device.set(u8::from(ImuBrickFunction::SetSpitfpBaudrate), payload)
}
pub fn get_spitfp_baudrate(&self, bricklet_port: char) -> ConvertingReceiver<u32> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
self.device.get(u8::from(ImuBrickFunction::GetSpitfpBaudrate), payload)
}
pub fn get_spitfp_error_count(&self, bricklet_port: char) -> ConvertingReceiver<SpitfpErrorCount> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(bricklet_port));
self.device.get(u8::from(ImuBrickFunction::GetSpitfpErrorCount), payload)
}
pub fn enable_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ImuBrickFunction::EnableStatusLed), payload)
}
pub fn disable_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ImuBrickFunction::DisableStatusLed), payload)
}
pub fn is_status_led_enabled(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::IsStatusLedEnabled), payload)
}
pub fn get_protocol1_bricklet_name(&self, port: char) -> ConvertingReceiver<Protocol1BrickletName> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
self.device.get(u8::from(ImuBrickFunction::GetProtocol1BrickletName), payload)
}
pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetChipTemperature), payload)
}
pub fn reset(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ImuBrickFunction::Reset), payload)
}
pub fn write_bricklet_plugin(&self, port: char, offset: u8, chunk: [u8; 32]) -> ConvertingReceiver<()> {
let mut payload = vec![0; 34];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(offset));
payload[2..34].copy_from_slice(&<[u8; 32]>::to_le_byte_vec(chunk));
self.device.set(u8::from(ImuBrickFunction::WriteBrickletPlugin), payload)
}
pub fn read_bricklet_plugin(&self, port: char, offset: u8) -> ConvertingReceiver<[u8; 32]> {
let mut payload = vec![0; 2];
payload[0..1].copy_from_slice(&<char>::to_le_byte_vec(port));
payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(offset));
self.device.get(u8::from(ImuBrickFunction::ReadBrickletPlugin), payload)
}
pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
let payload = vec![0; 0];
self.device.get(u8::from(ImuBrickFunction::GetIdentity), payload)
}
}