#[allow(unused_imports)]
use crate::{
byte_converter::*, device::*, error::TinkerforgeError, ip_connection::async_io::AsyncIpConnection, low_level_traits::LowLevelRead,
};
#[allow(unused_imports)]
use futures_core::Stream;
#[allow(unused_imports)]
use tokio_stream::StreamExt;
pub enum ServoBrickFunction {
Enable,
Disable,
IsEnabled,
SetPosition,
GetPosition,
GetCurrentPosition,
SetVelocity,
GetVelocity,
GetCurrentVelocity,
SetAcceleration,
GetAcceleration,
SetOutputVoltage,
GetOutputVoltage,
SetPulseWidth,
GetPulseWidth,
SetDegree,
GetDegree,
SetPeriod,
GetPeriod,
GetServoCurrent,
GetOverallCurrent,
GetStackInputVoltage,
GetExternalInputVoltage,
SetMinimumVoltage,
GetMinimumVoltage,
EnablePositionReachedCallback,
DisablePositionReachedCallback,
IsPositionReachedCallbackEnabled,
EnableVelocityReachedCallback,
DisableVelocityReachedCallback,
IsVelocityReachedCallbackEnabled,
SetSpitfpBaudrateConfig,
GetSpitfpBaudrateConfig,
GetSendTimeoutCount,
SetSpitfpBaudrate,
GetSpitfpBaudrate,
GetSpitfpErrorCount,
EnableStatusLed,
DisableStatusLed,
IsStatusLedEnabled,
GetProtocol1BrickletName,
GetChipTemperature,
Reset,
WriteBrickletPlugin,
ReadBrickletPlugin,
GetIdentity,
CallbackUnderVoltage,
CallbackPositionReached,
CallbackVelocityReached,
}
impl From<ServoBrickFunction> for u8 {
fn from(fun: ServoBrickFunction) -> Self {
match fun {
ServoBrickFunction::Enable => 1,
ServoBrickFunction::Disable => 2,
ServoBrickFunction::IsEnabled => 3,
ServoBrickFunction::SetPosition => 4,
ServoBrickFunction::GetPosition => 5,
ServoBrickFunction::GetCurrentPosition => 6,
ServoBrickFunction::SetVelocity => 7,
ServoBrickFunction::GetVelocity => 8,
ServoBrickFunction::GetCurrentVelocity => 9,
ServoBrickFunction::SetAcceleration => 10,
ServoBrickFunction::GetAcceleration => 11,
ServoBrickFunction::SetOutputVoltage => 12,
ServoBrickFunction::GetOutputVoltage => 13,
ServoBrickFunction::SetPulseWidth => 14,
ServoBrickFunction::GetPulseWidth => 15,
ServoBrickFunction::SetDegree => 16,
ServoBrickFunction::GetDegree => 17,
ServoBrickFunction::SetPeriod => 18,
ServoBrickFunction::GetPeriod => 19,
ServoBrickFunction::GetServoCurrent => 20,
ServoBrickFunction::GetOverallCurrent => 21,
ServoBrickFunction::GetStackInputVoltage => 22,
ServoBrickFunction::GetExternalInputVoltage => 23,
ServoBrickFunction::SetMinimumVoltage => 24,
ServoBrickFunction::GetMinimumVoltage => 25,
ServoBrickFunction::EnablePositionReachedCallback => 29,
ServoBrickFunction::DisablePositionReachedCallback => 30,
ServoBrickFunction::IsPositionReachedCallbackEnabled => 31,
ServoBrickFunction::EnableVelocityReachedCallback => 32,
ServoBrickFunction::DisableVelocityReachedCallback => 33,
ServoBrickFunction::IsVelocityReachedCallbackEnabled => 34,
ServoBrickFunction::SetSpitfpBaudrateConfig => 231,
ServoBrickFunction::GetSpitfpBaudrateConfig => 232,
ServoBrickFunction::GetSendTimeoutCount => 233,
ServoBrickFunction::SetSpitfpBaudrate => 234,
ServoBrickFunction::GetSpitfpBaudrate => 235,
ServoBrickFunction::GetSpitfpErrorCount => 237,
ServoBrickFunction::EnableStatusLed => 238,
ServoBrickFunction::DisableStatusLed => 239,
ServoBrickFunction::IsStatusLedEnabled => 240,
ServoBrickFunction::GetProtocol1BrickletName => 241,
ServoBrickFunction::GetChipTemperature => 242,
ServoBrickFunction::Reset => 243,
ServoBrickFunction::WriteBrickletPlugin => 246,
ServoBrickFunction::ReadBrickletPlugin => 247,
ServoBrickFunction::GetIdentity => 255,
ServoBrickFunction::CallbackUnderVoltage => 26,
ServoBrickFunction::CallbackPositionReached => 27,
ServoBrickFunction::CallbackVelocityReached => 28,
}
}
}
pub const SERVO_BRICK_COMMUNICATION_METHOD_NONE: u8 = 0;
pub const SERVO_BRICK_COMMUNICATION_METHOD_USB: u8 = 1;
pub const SERVO_BRICK_COMMUNICATION_METHOD_SPI_STACK: u8 = 2;
pub const SERVO_BRICK_COMMUNICATION_METHOD_CHIBI: u8 = 3;
pub const SERVO_BRICK_COMMUNICATION_METHOD_RS485: u8 = 4;
pub const SERVO_BRICK_COMMUNICATION_METHOD_WIFI: u8 = 5;
pub const SERVO_BRICK_COMMUNICATION_METHOD_ETHERNET: u8 = 6;
pub const SERVO_BRICK_COMMUNICATION_METHOD_WIFI_V2: u8 = 7;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct PulseWidth {
pub min: u16,
pub max: u16,
}
impl FromByteSlice for PulseWidth {
fn bytes_expected() -> usize {
4
}
fn from_le_byte_slice(bytes: &[u8]) -> PulseWidth {
PulseWidth { min: <u16>::from_le_byte_slice(&bytes[0..2]), max: <u16>::from_le_byte_slice(&bytes[2..4]) }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Degree {
pub min: i16,
pub max: i16,
}
impl FromByteSlice for Degree {
fn bytes_expected() -> usize {
4
}
fn from_le_byte_slice(bytes: &[u8]) -> Degree {
Degree { min: <i16>::from_le_byte_slice(&bytes[0..2]), max: <i16>::from_le_byte_slice(&bytes[2..4]) }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct PositionReachedEvent {
pub servo_num: u8,
pub position: i16,
}
impl FromByteSlice for PositionReachedEvent {
fn bytes_expected() -> usize {
3
}
fn from_le_byte_slice(bytes: &[u8]) -> PositionReachedEvent {
PositionReachedEvent { servo_num: <u8>::from_le_byte_slice(&bytes[0..1]), position: <i16>::from_le_byte_slice(&bytes[1..3]) }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct VelocityReachedEvent {
pub servo_num: u8,
pub velocity: i16,
}
impl FromByteSlice for VelocityReachedEvent {
fn bytes_expected() -> usize {
3
}
fn from_le_byte_slice(bytes: &[u8]) -> VelocityReachedEvent {
VelocityReachedEvent { servo_num: <u8>::from_le_byte_slice(&bytes[0..1]), velocity: <i16>::from_le_byte_slice(&bytes[1..3]) }
}
}
#[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 ServoBrick {
device: Device,
}
impl ServoBrick {
pub const DEVICE_IDENTIFIER: u16 = 14;
pub const DEVICE_DISPLAY_NAME: &'static str = "Servo Brick";
pub fn new(uid: u32, connection: AsyncIpConnection) -> ServoBrick {
let mut result = ServoBrick { device: Device::new([2, 0, 10], uid, connection, Self::DEVICE_DISPLAY_NAME) };
result.device.response_expected[u8::from(ServoBrickFunction::Enable) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::Disable) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::IsEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetPosition) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetCurrentPosition) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetVelocity) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetCurrentVelocity) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetAcceleration) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetAcceleration) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetOutputVoltage) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetOutputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetPulseWidth) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetPulseWidth) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetDegree) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetDegree) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetPeriod) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetPeriod) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetServoCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetOverallCurrent) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetStackInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetExternalInputVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetMinimumVoltage) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ServoBrickFunction::GetMinimumVoltage) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::EnablePositionReachedCallback) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ServoBrickFunction::DisablePositionReachedCallback) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ServoBrickFunction::IsPositionReachedCallbackEnabled) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::EnableVelocityReachedCallback) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ServoBrickFunction::DisableVelocityReachedCallback) as usize] = ResponseExpectedFlag::True;
result.device.response_expected[u8::from(ServoBrickFunction::IsVelocityReachedCallbackEnabled) as usize] =
ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetSpitfpBaudrateConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetSendTimeoutCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::SetSpitfpBaudrate) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::GetSpitfpBaudrate) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::EnableStatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::DisableStatusLed) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::IsStatusLedEnabled) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetProtocol1BrickletName) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::Reset) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::WriteBrickletPlugin) as usize] = ResponseExpectedFlag::False;
result.device.response_expected[u8::from(ServoBrickFunction::ReadBrickletPlugin) as usize] = ResponseExpectedFlag::AlwaysTrue;
result.device.response_expected[u8::from(ServoBrickFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
result
}
pub fn get_response_expected(&mut self, fun: ServoBrickFunction) -> Result<bool, GetResponseExpectedError> {
self.device.get_response_expected(u8::from(fun))
}
pub fn set_response_expected(&mut self, fun: ServoBrickFunction, 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 async fn get_under_voltage_callback_receiver(&mut self) -> impl Stream<Item = u16> {
self.device
.get_callback_receiver(u8::from(ServoBrickFunction::CallbackUnderVoltage))
.await
.map(|p| u16::from_le_byte_slice(p.body()))
}
pub async fn get_position_reached_callback_receiver(&mut self) -> impl Stream<Item = PositionReachedEvent> {
self.device
.get_callback_receiver(u8::from(ServoBrickFunction::CallbackPositionReached))
.await
.map(|p| PositionReachedEvent::from_le_byte_slice(p.body()))
}
pub async fn get_velocity_reached_callback_receiver(&mut self) -> impl Stream<Item = VelocityReachedEvent> {
self.device
.get_callback_receiver(u8::from(ServoBrickFunction::CallbackVelocityReached))
.await
.map(|p| VelocityReachedEvent::from_le_byte_slice(p.body()))
}
pub async fn enable(&mut self, servo_num: u8) -> Result<(), TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::Enable), &payload).await?;
Ok(())
}
pub async fn disable(&mut self, servo_num: u8) -> Result<(), TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::Disable), &payload).await?;
Ok(())
}
pub async fn is_enabled(&mut self, servo_num: u8) -> Result<bool, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::IsEnabled), &payload).await?;
Ok(bool::from_le_byte_slice(result.body()))
}
pub async fn set_position(&mut self, servo_num: u8, position: i16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 3];
servo_num.write_to_slice(&mut payload[0..1]);
position.write_to_slice(&mut payload[1..3]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetPosition), &payload).await?;
Ok(())
}
pub async fn get_position(&mut self, servo_num: u8) -> Result<i16, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetPosition), &payload).await?;
Ok(i16::from_le_byte_slice(result.body()))
}
pub async fn get_current_position(&mut self, servo_num: u8) -> Result<i16, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetCurrentPosition), &payload).await?;
Ok(i16::from_le_byte_slice(result.body()))
}
pub async fn set_velocity(&mut self, servo_num: u8, velocity: u16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 3];
servo_num.write_to_slice(&mut payload[0..1]);
velocity.write_to_slice(&mut payload[1..3]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetVelocity), &payload).await?;
Ok(())
}
pub async fn get_velocity(&mut self, servo_num: u8) -> Result<u16, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetVelocity), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn get_current_velocity(&mut self, servo_num: u8) -> Result<u16, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetCurrentVelocity), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn set_acceleration(&mut self, servo_num: u8, acceleration: u16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 3];
servo_num.write_to_slice(&mut payload[0..1]);
acceleration.write_to_slice(&mut payload[1..3]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetAcceleration), &payload).await?;
Ok(())
}
pub async fn get_acceleration(&mut self, servo_num: u8) -> Result<u16, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetAcceleration), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn set_output_voltage(&mut self, voltage: u16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 2];
voltage.write_to_slice(&mut payload[0..2]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetOutputVoltage), &payload).await?;
Ok(())
}
pub async fn get_output_voltage(&mut self) -> Result<u16, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetOutputVoltage), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn set_pulse_width(&mut self, servo_num: u8, min: u16, max: u16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 5];
servo_num.write_to_slice(&mut payload[0..1]);
min.write_to_slice(&mut payload[1..3]);
max.write_to_slice(&mut payload[3..5]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetPulseWidth), &payload).await?;
Ok(())
}
pub async fn get_pulse_width(&mut self, servo_num: u8) -> Result<PulseWidth, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetPulseWidth), &payload).await?;
Ok(PulseWidth::from_le_byte_slice(result.body()))
}
pub async fn set_degree(&mut self, servo_num: u8, min: i16, max: i16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 5];
servo_num.write_to_slice(&mut payload[0..1]);
min.write_to_slice(&mut payload[1..3]);
max.write_to_slice(&mut payload[3..5]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetDegree), &payload).await?;
Ok(())
}
pub async fn get_degree(&mut self, servo_num: u8) -> Result<Degree, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetDegree), &payload).await?;
Ok(Degree::from_le_byte_slice(result.body()))
}
pub async fn set_period(&mut self, servo_num: u8, period: u16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 3];
servo_num.write_to_slice(&mut payload[0..1]);
period.write_to_slice(&mut payload[1..3]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetPeriod), &payload).await?;
Ok(())
}
pub async fn get_period(&mut self, servo_num: u8) -> Result<u16, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetPeriod), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn get_servo_current(&mut self, servo_num: u8) -> Result<u16, TinkerforgeError> {
let mut payload = [0; 1];
servo_num.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetServoCurrent), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn get_overall_current(&mut self) -> Result<u16, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetOverallCurrent), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn get_stack_input_voltage(&mut self) -> Result<u16, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetStackInputVoltage), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn get_external_input_voltage(&mut self) -> Result<u16, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetExternalInputVoltage), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn set_minimum_voltage(&mut self, voltage: u16) -> Result<(), TinkerforgeError> {
let mut payload = [0; 2];
voltage.write_to_slice(&mut payload[0..2]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetMinimumVoltage), &payload).await?;
Ok(())
}
pub async fn get_minimum_voltage(&mut self) -> Result<u16, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetMinimumVoltage), &payload).await?;
Ok(u16::from_le_byte_slice(result.body()))
}
pub async fn enable_position_reached_callback(&mut self) -> Result<(), TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::EnablePositionReachedCallback), &payload).await?;
Ok(())
}
pub async fn disable_position_reached_callback(&mut self) -> Result<(), TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::DisablePositionReachedCallback), &payload).await?;
Ok(())
}
pub async fn is_position_reached_callback_enabled(&mut self) -> Result<bool, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::IsPositionReachedCallbackEnabled), &payload).await?;
Ok(bool::from_le_byte_slice(result.body()))
}
pub async fn enable_velocity_reached_callback(&mut self) -> Result<(), TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::EnableVelocityReachedCallback), &payload).await?;
Ok(())
}
pub async fn disable_velocity_reached_callback(&mut self) -> Result<(), TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::DisableVelocityReachedCallback), &payload).await?;
Ok(())
}
pub async fn is_velocity_reached_callback_enabled(&mut self) -> Result<bool, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::IsVelocityReachedCallbackEnabled), &payload).await?;
Ok(bool::from_le_byte_slice(result.body()))
}
pub async fn set_spitfp_baudrate_config(
&mut self,
enable_dynamic_baudrate: bool,
minimum_dynamic_baudrate: u32,
) -> Result<(), TinkerforgeError> {
let mut payload = [0; 5];
enable_dynamic_baudrate.write_to_slice(&mut payload[0..1]);
minimum_dynamic_baudrate.write_to_slice(&mut payload[1..5]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetSpitfpBaudrateConfig), &payload).await?;
Ok(())
}
pub async fn get_spitfp_baudrate_config(&mut self) -> Result<SpitfpBaudrateConfig, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetSpitfpBaudrateConfig), &payload).await?;
Ok(SpitfpBaudrateConfig::from_le_byte_slice(result.body()))
}
pub async fn get_send_timeout_count(&mut self, communication_method: u8) -> Result<u32, TinkerforgeError> {
let mut payload = [0; 1];
communication_method.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetSendTimeoutCount), &payload).await?;
Ok(u32::from_le_byte_slice(result.body()))
}
pub async fn set_spitfp_baudrate(&mut self, bricklet_port: char, baudrate: u32) -> Result<(), TinkerforgeError> {
let mut payload = [0; 5];
bricklet_port.write_to_slice(&mut payload[0..1]);
baudrate.write_to_slice(&mut payload[1..5]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::SetSpitfpBaudrate), &payload).await?;
Ok(())
}
pub async fn get_spitfp_baudrate(&mut self, bricklet_port: char) -> Result<u32, TinkerforgeError> {
let mut payload = [0; 1];
bricklet_port.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetSpitfpBaudrate), &payload).await?;
Ok(u32::from_le_byte_slice(result.body()))
}
pub async fn get_spitfp_error_count(&mut self, bricklet_port: char) -> Result<SpitfpErrorCount, TinkerforgeError> {
let mut payload = [0; 1];
bricklet_port.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetSpitfpErrorCount), &payload).await?;
Ok(SpitfpErrorCount::from_le_byte_slice(result.body()))
}
pub async fn enable_status_led(&mut self) -> Result<(), TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::EnableStatusLed), &payload).await?;
Ok(())
}
pub async fn disable_status_led(&mut self) -> Result<(), TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::DisableStatusLed), &payload).await?;
Ok(())
}
pub async fn is_status_led_enabled(&mut self) -> Result<bool, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::IsStatusLedEnabled), &payload).await?;
Ok(bool::from_le_byte_slice(result.body()))
}
pub async fn get_protocol1_bricklet_name(&mut self, port: char) -> Result<Protocol1BrickletName, TinkerforgeError> {
let mut payload = [0; 1];
port.write_to_slice(&mut payload[0..1]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetProtocol1BrickletName), &payload).await?;
Ok(Protocol1BrickletName::from_le_byte_slice(result.body()))
}
pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetChipTemperature), &payload).await?;
Ok(i16::from_le_byte_slice(result.body()))
}
pub async fn reset(&mut self) -> Result<(), TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::Reset), &payload).await?;
Ok(())
}
pub async fn write_bricklet_plugin(&mut self, port: char, offset: u8, chunk: &[u8; 32]) -> Result<(), TinkerforgeError> {
let mut payload = [0; 34];
port.write_to_slice(&mut payload[0..1]);
offset.write_to_slice(&mut payload[1..2]);
chunk.write_to_slice(&mut payload[2..34]);
#[allow(unused_variables)]
let result = self.device.set(u8::from(ServoBrickFunction::WriteBrickletPlugin), &payload).await?;
Ok(())
}
pub async fn read_bricklet_plugin(&mut self, port: char, offset: u8) -> Result<Box<[u8; 32]>, TinkerforgeError> {
let mut payload = [0; 2];
port.write_to_slice(&mut payload[0..1]);
offset.write_to_slice(&mut payload[1..2]);
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::ReadBrickletPlugin), &payload).await?;
Ok(Box::<[u8; 32]>::from_le_byte_slice(result.body()))
}
pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError> {
let payload = [0; 0];
#[allow(unused_variables)]
let result = self.device.get(u8::from(ServoBrickFunction::GetIdentity), &payload).await?;
Ok(Identity::from_le_byte_slice(result.body()))
}
}