Struct VisionCode

Source
pub struct VisionCode(pub u8, pub u8, pub Option<u8>, pub Option<u8>, pub Option<u8>);
Expand description

A vision detection code.

Codes are a special type of detection signature that group multiple VisionSignatures together. A VisionCode can associate 2-5 color signatures together, detecting the resulting object when its color signatures are present close to each other.

These codes work very similarly to Pixy2 Color Codes.

Tuple Fields§

§0: u8§1: u8§2: Option<u8>§3: Option<u8>§4: Option<u8>

Implementations§

Source§

impl VisionCode

Source

pub const fn new( sig_1: u8, sig_2: u8, sig_3: Option<u8>, sig_4: Option<u8>, sig_5: Option<u8>, ) -> Self

Creates a new vision code.

Two signatures are required to create a vision code, with an additional three optional signatures.

§Examples
use vexide::devices::smart::vision::VisionCode;

// Create a vision code associated with signatures 1, 2, and 3.
let code = VisionCode::new(1, 2, Some(3), None, None);
Source

pub const fn from_id(id: u16) -> Self

Creates a VisionCode from a bit representation of its signature IDs.

§Examples
use vexide::devices::smart::vision::VisionCode;

let sig_1_id = 1;
let sig_2_id = 2;

let mut code_id: u16 = 0;

// Store the bits of IDs 1 and 2 in the code ID.
code_id = (code_id << 3) | u16::from(sig_1_id);
code_id = (code_id << 3) | u16::from(sig_2_id);

// Create a [`VisionCode`] from signatures 1 and 2.
let code = VisionCode::from_id(code_id);
Source

pub const fn contains_signature(&self, id: u8) -> bool

Returns true if a given signature ID is stored in this code.

§Examples
use vexide::devices::smart::vision::VisionCode;

// Create a vision code associated with signatures 1, 2, and 3.
let code = VisionCode::new(1, 2, Some(3), None, None);

assert!(code.contains_signature(1));
Source

pub fn id(&self) -> u16

Returns the internal ID used by the sensor to determine which signatures belong to which code.

§Examples
use vexide::devices::smart::vision::VisionCode;

let sig_1_id = 1;
let sig_2_id = 2;

let mut code_id: u16 = 0;

// Store the bits of IDs 1 and 2 in the code ID.
code_id = (code_id << 3) | u16::from(sig_1_id);
code_id = (code_id << 3) | u16::from(sig_2_id);

// Create a [`VisionCode`] from signatures 1 and 2.
let code = VisionCode::from_id(code_id);

// The ID of the code we just created should be identical to the bit representation
// containing each signature ID we created it from.
assert_eq!(code.id(), code_id);

Trait Implementations§

Source§

impl Clone for VisionCode

Source§

fn clone(&self) -> VisionCode

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VisionCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<(u8, u8)> for VisionCode

Source§

fn from(signatures: (u8, u8)) -> Self

Convert a tuple of two VisionSignatures into a VisionCode.

Source§

impl From<(u8, u8, u8)> for VisionCode

Source§

fn from(signatures: (u8, u8, u8)) -> Self

Convert a tuple of three VisionSignatures into a VisionCode.

Source§

impl From<(u8, u8, u8, u8)> for VisionCode

Source§

fn from(signatures: (u8, u8, u8, u8)) -> Self

Convert a tuple of four VisionSignatures into a VisionCode.

Source§

impl From<(u8, u8, u8, u8, u8)> for VisionCode

Source§

fn from(signatures: (u8, u8, u8, u8, u8)) -> Self

Convert a tuple of five VisionSignatures into a VisionCode.

Source§

impl PartialEq for VisionCode

Source§

fn eq(&self, other: &VisionCode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for VisionCode

Source§

impl Eq for VisionCode

Source§

impl StructuralPartialEq for VisionCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.