pub trait DeviceOperations {
Show 27 methods
// Required methods
fn set_digital_output(
&self,
thread_id: u32,
pin: u32,
value: bool,
) -> Result<()>;
fn get_digital_input(&self, thread_id: u32, pin: u32) -> Result<bool>;
fn set_analog_output(
&self,
thread_id: u32,
pin: u32,
value: u32,
) -> Result<()>;
fn get_analog_input(&self, thread_id: u32, pin: u32) -> Result<u32>;
fn set_pwm_duty_cycle(
&self,
thread_id: u32,
channel: usize,
duty: u32,
) -> Result<()>;
fn set_pwm_duty_cycle_percent(
&self,
thread_id: u32,
channel: usize,
duty_percent: f32,
) -> Result<()>;
fn configure_servo(
&self,
thread_id: u32,
pin: u8,
servo_config: ServoConfig,
) -> Result<()>;
fn set_servo_angle(&self, thread_id: u32, pin: u8, angle: f32) -> Result<()>;
fn set_servo_speed(&self, thread_id: u32, pin: u8, speed: f32) -> Result<()>;
fn stop_servo(&self, thread_id: u32, pin: u8) -> Result<()>;
fn i2c_write(
&self,
thread_id: u32,
address: u8,
data: Vec<u8>,
) -> Result<()>;
fn i2c_read(
&self,
thread_id: u32,
address: u8,
length: u8,
) -> Result<Vec<u8>>;
fn i2c_write_read(
&self,
thread_id: u32,
address: u8,
write_data: Vec<u8>,
read_length: u8,
) -> Result<Vec<u8>>;
fn i2c_scan(&self, thread_id: u32) -> Result<Vec<u8>>;
fn configure_uspibridge(
&self,
thread_id: u32,
config: USPIBridgeConfig,
) -> Result<()>;
fn uspibridge_command(
&self,
thread_id: u32,
command: Vec<u8>,
) -> Result<Vec<u8>>;
fn check_pin_capability(
&self,
thread_id: u32,
pin: u8,
capability: PinCapability,
) -> Result<bool>;
fn get_device_model(&self, thread_id: u32) -> Result<Option<String>>;
fn validate_pin_operation(
&self,
thread_id: u32,
pin: u8,
operation: &str,
) -> Result<()>;
fn set_digital_outputs_bulk(
&self,
thread_id: u32,
pin_states: Vec<(u32, bool)>,
) -> Result<()>;
fn set_pwm_duties_bulk(
&self,
thread_id: u32,
channel_duties: Vec<(usize, u32)>,
) -> Result<()>;
fn read_analog_inputs_bulk(
&self,
thread_id: u32,
pins: Vec<u32>,
) -> Result<Vec<u32>>;
fn get_encoder_value(
&self,
thread_id: u32,
encoder_index: u32,
) -> Result<i32>;
fn configure_encoder(
&self,
thread_id: u32,
encoder_index: u32,
pin_a: u32,
pin_b: u32,
enabled: bool,
sampling_4x: bool,
) -> Result<()>;
fn reset_digital_counter(&self, thread_id: u32, pin: u32) -> Result<()>;
fn send_custom_request(
&self,
thread_id: u32,
request_type: u8,
param1: u8,
param2: u8,
param3: u8,
param4: u8,
) -> Result<()>;
fn set_pin_function(
&self,
thread_id: u32,
pin: u32,
pin_function: PinFunction,
) -> Result<()>;
}Expand description
Device operations trait for performing device-specific operations.
This trait provides a high-level interface for performing device operations
such as setting digital outputs, reading digital inputs, configuring encoders,
and more. It is implemented by the ThreadControllerImpl to provide a
convenient way to interact with devices.
Required Methods§
Sourcefn set_pwm_duty_cycle_percent(
&self,
thread_id: u32,
channel: usize,
duty_percent: f32,
) -> Result<()>
fn set_pwm_duty_cycle_percent( &self, thread_id: u32, channel: usize, duty_percent: f32, ) -> Result<()>
Sourcefn configure_servo(
&self,
thread_id: u32,
pin: u8,
servo_config: ServoConfig,
) -> Result<()>
fn configure_servo( &self, thread_id: u32, pin: u8, servo_config: ServoConfig, ) -> Result<()>
Sourcefn set_servo_angle(&self, thread_id: u32, pin: u8, angle: f32) -> Result<()>
fn set_servo_angle(&self, thread_id: u32, pin: u8, angle: f32) -> Result<()>
Set servo angle (for 180° and 360° position servos).
§Parameters
thread_id- The ID of the thread to send the command to.pin- The PWM pin (17-22).angle- The angle in degrees (0-180 for 180° servos, 0-360 for 360° position servos).
§Errors
Returns an error if the thread is not found or if the command send fails.
Sourcefn i2c_write_read(
&self,
thread_id: u32,
address: u8,
write_data: Vec<u8>,
read_length: u8,
) -> Result<Vec<u8>>
fn i2c_write_read( &self, thread_id: u32, address: u8, write_data: Vec<u8>, read_length: u8, ) -> Result<Vec<u8>>
Write then read from an I2C device (combined operation).
§Parameters
thread_id- The ID of the thread to send the command to.address- The I2C device address.write_data- The data to write first.read_length- The number of bytes to read after writing.
§Returns
The data read from the device.
§Errors
Returns an error if the thread is not found or if the command send fails.
Sourcefn configure_uspibridge(
&self,
thread_id: u32,
config: USPIBridgeConfig,
) -> Result<()>
fn configure_uspibridge( &self, thread_id: u32, config: USPIBridgeConfig, ) -> Result<()>
Sourcefn check_pin_capability(
&self,
thread_id: u32,
pin: u8,
capability: PinCapability,
) -> Result<bool>
fn check_pin_capability( &self, thread_id: u32, pin: u8, capability: PinCapability, ) -> Result<bool>
Sourcefn set_digital_outputs_bulk(
&self,
thread_id: u32,
pin_states: Vec<(u32, bool)>,
) -> Result<()>
fn set_digital_outputs_bulk( &self, thread_id: u32, pin_states: Vec<(u32, bool)>, ) -> Result<()>
Sourcefn set_pwm_duties_bulk(
&self,
thread_id: u32,
channel_duties: Vec<(usize, u32)>,
) -> Result<()>
fn set_pwm_duties_bulk( &self, thread_id: u32, channel_duties: Vec<(usize, u32)>, ) -> Result<()>
Sourcefn configure_encoder(
&self,
thread_id: u32,
encoder_index: u32,
pin_a: u32,
pin_b: u32,
enabled: bool,
sampling_4x: bool,
) -> Result<()>
fn configure_encoder( &self, thread_id: u32, encoder_index: u32, pin_a: u32, pin_b: u32, enabled: bool, sampling_4x: bool, ) -> Result<()>
Configure an encoder.
§Parameters
thread_id- The ID of the thread to send the command to.encoder_index- The encoder index to configure.pin_a- The pin number for encoder input A.pin_b- The pin number for encoder input B.enabled- Whether the encoder is enabled.sampling_4x- Whether to use 4x sampling.
§Errors
Returns an error if the thread is not found or if the command send fails.
Sourcefn send_custom_request(
&self,
thread_id: u32,
request_type: u8,
param1: u8,
param2: u8,
param3: u8,
param4: u8,
) -> Result<()>
fn send_custom_request( &self, thread_id: u32, request_type: u8, param1: u8, param2: u8, param3: u8, param4: u8, ) -> Result<()>
Send a custom request.
§Parameters
thread_id- The ID of the thread to send the command to.request_type- The request type.param1- The first parameter.param2- The second parameter.param3- The third parameter.param4- The fourth parameter.
§Errors
Returns an error if the thread is not found or if the command send fails.