Trait SmartDevice

Source
pub trait SmartDevice {
    const UPDATE_INTERVAL: Duration = _;

    // Required methods
    fn port_number(&self) -> u8;
    fn device_type(&self) -> SmartDeviceType;

    // Provided methods
    fn is_connected(&self) -> bool { ... }
    fn timestamp(&self) -> Result<SmartDeviceTimestamp, PortError> { ... }
    fn validate_port(&self) -> Result<(), PortError> { ... }
}
Expand description

Defines common functionality shared by all Smart Port devices.

Provided Associated Constants§

Source

const UPDATE_INTERVAL: Duration = _

The interval at which the V5 brain reads packets from Smart devices.

Required Methods§

Source

fn port_number(&self) -> u8

Returns the port number of the SmartPort this device is registered on.

Ports are numbered starting from 1.

§Examples
let sensor = InertialSensor::new(peripherals.port_1)?;
assert_eq!(sensor.port_number(), 1);
Source

fn device_type(&self) -> SmartDeviceType

Returns the variant of SmartDeviceType that this device is associated with.

§Examples
let sensor = InertialSensor::new(peripherals.port_1)?;
assert_eq!(sensor.device_type(), SmartDeviceType::Imu);

Provided Methods§

Source

fn is_connected(&self) -> bool

Determine if this device type is currently connected to the SmartPort that it’s registered to.

§Examples
let sensor = InertialSensor::new(peripherals.port_1)?;

if sensor.port_connected() {
    println!("IMU is connected!");
} else {
    println!("No IMU connection found.");
}
Source

fn timestamp(&self) -> Result<SmartDeviceTimestamp, PortError>

Returns the timestamp recorded by this device’s internal clock.

§Errors

Currently, this function never returns an error. This behavior should be considered unstable.

Source

fn validate_port(&self) -> Result<(), PortError>

Verify that the device type is currently plugged into this port, returning an appropriate PortError if not available.

§Errors

Returns a PortError if there is not a physical device of type SmartDevice::device_type in this SmartDevice’s port.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§