Struct pros_devices::smart::SmartPort
source · pub struct SmartPort { /* private fields */ }Expand description
Represents a smart port on a V5 Brain
Implementations§
source§impl SmartPort
impl SmartPort
sourcepub const unsafe fn new(index: u8) -> Self
pub const unsafe fn new(index: u8) -> Self
Creates a new smart port on a specified index.
§Safety
Creating new SmartPorts is inherently unsafe due to the possibility of constructing
more than one device on the same port index allowing multiple mutable references to
the same hardware device. This violates rust’s borrow checked guarantees. Prefer using
Peripherals to register devices if possible.
§Examples
// Create a new smart port at index 1.
// This is unsafe! You are responsible for ensuring that only one device registered on a
// single port index.
let my_port = unsafe { SmartPort::new(1) };sourcepub const fn index(&self) -> u8
pub const fn index(&self) -> u8
Get the index of the port (port number).
Ports are indexed starting from 1.
§Examples
let my_port = unsafe { SmartPort::new(1) };
assert_eq!(my_port.index(), 1);sourcepub fn connected_type(&self) -> Result<SmartDeviceType, PortError>
pub fn connected_type(&self) -> Result<SmartDeviceType, PortError>
Get the type of device currently connected to this port.
§Examples
let my_port = unsafe { SmartPort::new(1) };
println!("Type of device connected to port 1: {:?}", my_port.connected_type()?);sourcepub fn configured_type(&self) -> Result<SmartDeviceType, PortError>
pub fn configured_type(&self) -> Result<SmartDeviceType, PortError>
Get the type of device this port is configured as.
§Examples
let my_port = unsafe { SmartPort::new(1) };
let imu = InertialSensor::new(my_port)?;
assert_eq!(my_port.configured_type()?, SmartDeviceType::Imu);Trait Implementations§
source§impl PartialEq for SmartPort
impl PartialEq for SmartPort
impl Eq for SmartPort
impl StructuralPartialEq for SmartPort
Auto Trait Implementations§
impl RefUnwindSafe for SmartPort
impl Send for SmartPort
impl Sync for SmartPort
impl Unpin for SmartPort
impl UnwindSafe for SmartPort
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more