use crate::{
byte_converter::*, converting_callback_receiver::ConvertingCallbackReceiver, converting_receiver::ConvertingReceiver, device::*,
ip_connection::GetRequestSender,
};
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,
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::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<T: GetRequestSender>(uid: &str, req_sender: T) -> ServoBrick {
let mut result = ServoBrick { device: Device::new([2, 0, 4], uid, req_sender, 0) };
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::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 fn get_under_voltage_callback_receiver(&self) -> ConvertingCallbackReceiver<u16> {
self.device.get_callback_receiver(u8::from(ServoBrickFunction::CallbackUnderVoltage))
}
pub fn get_position_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<PositionReachedEvent> {
self.device.get_callback_receiver(u8::from(ServoBrickFunction::CallbackPositionReached))
}
pub fn get_velocity_reached_callback_receiver(&self) -> ConvertingCallbackReceiver<VelocityReachedEvent> {
self.device.get_callback_receiver(u8::from(ServoBrickFunction::CallbackVelocityReached))
}
pub fn enable(&self, servo_num: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.set(u8::from(ServoBrickFunction::Enable), payload)
}
pub fn disable(&self, servo_num: u8) -> ConvertingReceiver<()> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.set(u8::from(ServoBrickFunction::Disable), payload)
}
pub fn is_enabled(&self, servo_num: u8) -> ConvertingReceiver<bool> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::IsEnabled), payload)
}
pub fn set_position(&self, servo_num: u8, position: i16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 3];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
payload[1..3].copy_from_slice(&<i16>::to_le_byte_vec(position));
self.device.set(u8::from(ServoBrickFunction::SetPosition), payload)
}
pub fn get_position(&self, servo_num: u8) -> ConvertingReceiver<i16> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetPosition), payload)
}
pub fn get_current_position(&self, servo_num: u8) -> ConvertingReceiver<i16> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetCurrentPosition), payload)
}
pub fn set_velocity(&self, servo_num: u8, velocity: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 3];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(velocity));
self.device.set(u8::from(ServoBrickFunction::SetVelocity), payload)
}
pub fn get_velocity(&self, servo_num: u8) -> ConvertingReceiver<u16> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetVelocity), payload)
}
pub fn get_current_velocity(&self, servo_num: u8) -> ConvertingReceiver<u16> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetCurrentVelocity), payload)
}
pub fn set_acceleration(&self, servo_num: u8, acceleration: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 3];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(acceleration));
self.device.set(u8::from(ServoBrickFunction::SetAcceleration), payload)
}
pub fn get_acceleration(&self, servo_num: u8) -> ConvertingReceiver<u16> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetAcceleration), payload)
}
pub fn set_output_voltage(&self, voltage: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 2];
payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(voltage));
self.device.set(u8::from(ServoBrickFunction::SetOutputVoltage), payload)
}
pub fn get_output_voltage(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::GetOutputVoltage), payload)
}
pub fn set_pulse_width(&self, servo_num: u8, min: u16, max: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(min));
payload[3..5].copy_from_slice(&<u16>::to_le_byte_vec(max));
self.device.set(u8::from(ServoBrickFunction::SetPulseWidth), payload)
}
pub fn get_pulse_width(&self, servo_num: u8) -> ConvertingReceiver<PulseWidth> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetPulseWidth), payload)
}
pub fn set_degree(&self, servo_num: u8, min: i16, max: i16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 5];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
payload[1..3].copy_from_slice(&<i16>::to_le_byte_vec(min));
payload[3..5].copy_from_slice(&<i16>::to_le_byte_vec(max));
self.device.set(u8::from(ServoBrickFunction::SetDegree), payload)
}
pub fn get_degree(&self, servo_num: u8) -> ConvertingReceiver<Degree> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetDegree), payload)
}
pub fn set_period(&self, servo_num: u8, period: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 3];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
payload[1..3].copy_from_slice(&<u16>::to_le_byte_vec(period));
self.device.set(u8::from(ServoBrickFunction::SetPeriod), payload)
}
pub fn get_period(&self, servo_num: u8) -> ConvertingReceiver<u16> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetPeriod), payload)
}
pub fn get_servo_current(&self, servo_num: u8) -> ConvertingReceiver<u16> {
let mut payload = vec![0; 1];
payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(servo_num));
self.device.get(u8::from(ServoBrickFunction::GetServoCurrent), payload)
}
pub fn get_overall_current(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::GetOverallCurrent), payload)
}
pub fn get_stack_input_voltage(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::GetStackInputVoltage), payload)
}
pub fn get_external_input_voltage(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::GetExternalInputVoltage), payload)
}
pub fn set_minimum_voltage(&self, voltage: u16) -> ConvertingReceiver<()> {
let mut payload = vec![0; 2];
payload[0..2].copy_from_slice(&<u16>::to_le_byte_vec(voltage));
self.device.set(u8::from(ServoBrickFunction::SetMinimumVoltage), payload)
}
pub fn get_minimum_voltage(&self) -> ConvertingReceiver<u16> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::GetMinimumVoltage), payload)
}
pub fn enable_position_reached_callback(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ServoBrickFunction::EnablePositionReachedCallback), payload)
}
pub fn disable_position_reached_callback(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ServoBrickFunction::DisablePositionReachedCallback), payload)
}
pub fn is_position_reached_callback_enabled(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::IsPositionReachedCallbackEnabled), payload)
}
pub fn enable_velocity_reached_callback(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ServoBrickFunction::EnableVelocityReachedCallback), payload)
}
pub fn disable_velocity_reached_callback(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ServoBrickFunction::DisableVelocityReachedCallback), payload)
}
pub fn is_velocity_reached_callback_enabled(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::IsVelocityReachedCallbackEnabled), 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(ServoBrickFunction::SetSpitfpBaudrateConfig), payload)
}
pub fn get_spitfp_baudrate_config(&self) -> ConvertingReceiver<SpitfpBaudrateConfig> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::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(ServoBrickFunction::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(ServoBrickFunction::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(ServoBrickFunction::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(ServoBrickFunction::GetSpitfpErrorCount), payload)
}
pub fn enable_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ServoBrickFunction::EnableStatusLed), payload)
}
pub fn disable_status_led(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ServoBrickFunction::DisableStatusLed), payload)
}
pub fn is_status_led_enabled(&self) -> ConvertingReceiver<bool> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::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(ServoBrickFunction::GetProtocol1BrickletName), payload)
}
pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::GetChipTemperature), payload)
}
pub fn reset(&self) -> ConvertingReceiver<()> {
let payload = vec![0; 0];
self.device.set(u8::from(ServoBrickFunction::Reset), payload)
}
pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
let payload = vec![0; 0];
self.device.get(u8::from(ServoBrickFunction::GetIdentity), payload)
}
}