Controllers

Struct Controllers 

Source
pub struct Controllers { /* private fields */ }
Expand description

Stores state of VEX V5 master and partner controllers.

Implementations§

Source§

impl Controllers

Source

pub fn new( master: Option<ControllerState>, partner: Option<ControllerState>, ) -> Self

Source

pub fn update( &mut self, new_master: Option<ControllerState>, new_partner: Option<ControllerState>, )

Update state of both controllers and set new press values.

Source

pub fn is_connected(&self, controller_id: u32) -> Result<bool, i32>

Source

pub fn get_analog(&self, controller_id: u32, channel: u32) -> Result<i32, i32>

Returns the current state of a specific analog channel (joystick) on a specific controller.

This function retrieves the current state of a given analog channel (joystick) on a specific controller. The state is represented as a integer value in the range [-127, 127] where -127 is full down or left, and 127 is full up or right.

§Arguments
  • controller_id - A u32 that holds the ID of the controller.
  • channel - A u32 that represents the axis whose state is to be retrieved.
§Returns
  • Ok(i32) - If the controller and button exist, returns the state of the axis.
  • Err(i32) - If the controller or button does not exist, returns an error with the code EINVAL.
§Example
if controllers.get_analog(pros_sys::E_CONTROLLER_MASTER, pros_sys::E_CONTROLLER_ANALOG_LEFT_X)? > 0 {
    println!("Left joystick is pushed right")
}
Source

pub fn get_digital(&self, controller_id: u32, button: u32) -> Result<bool, i32>

Returns the current state of a specific button on a specific controller.

This function retrieves the current state of a given button on a specific controller. The state is represented as a boolean value, where true indicates that the button is currently pressed, and false indicates that it is not.

§Arguments
  • controller_id - A u32 that holds the ID of the controller.
  • button - A u32 that represents the button whose state is to be retrieved.
§Returns
  • Ok(bool) - If the controller and button exist, returns a boolean indicating whether the button is currently pressed.
  • Err(i32) - If the controller or button does not exist, returns an error with the code EINVAL.
§Example
if controllers.get_digital(pros_sys::E_CONTROLLER_MASTER, pros_sys::E_CONTROLLER_DIGITAL_X)? {
    println!("Button X pressed")
}
Source

pub fn get_digital_new_press( &mut self, controller_id: u32, button: u32, ) -> Result<bool, i32>

Returns whether a new press event occurred for a specific button on a specific controller.

This function checks if a new press event has occurred for a given button on a specific controller. If a new press event has occurred, it returns true and resets the state to false. If no new press event has occurred, it returns false. If the controller or button does not exist, it returns an error.

State is shared between tasks so to get notified on every change it’s best to always call this from the same task.

§Arguments
  • controller_id - A u32 that holds the ID of the controller.
  • button - A u32 that represents the button to check for a new press event.
§Returns
  • Ok(bool) - If the controller and button exist, returns whether a new press event has occurred.
  • Err(i32) - If the controller or button does not exist, returns an error.
§Example
if controllers.get_digital_new_press(pros_sys::E_CONTROLLER_MASTER, pros_sys::E_CONTROLLER_DIGITAL_X)? {
    println!("Button X has been pressed since last call");
}

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more