pub struct Controllers { /* private fields */ }Expand description
Stores state of VEX V5 master and partner controllers.
Implementations§
Source§impl Controllers
impl Controllers
pub fn new( master: Option<ControllerState>, partner: Option<ControllerState>, ) -> Self
Sourcepub fn update(
&mut self,
new_master: Option<ControllerState>,
new_partner: Option<ControllerState>,
)
pub fn update( &mut self, new_master: Option<ControllerState>, new_partner: Option<ControllerState>, )
Update state of both controllers and set new press values.
pub fn is_connected(&self, controller_id: u32) -> Result<bool, i32>
Sourcepub fn get_analog(&self, controller_id: u32, channel: u32) -> Result<i32, i32>
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 codeEINVAL.
§Example
if controllers.get_analog(pros_sys::E_CONTROLLER_MASTER, pros_sys::E_CONTROLLER_ANALOG_LEFT_X)? > 0 {
println!("Left joystick is pushed right")
}Sourcepub fn get_digital(&self, controller_id: u32, button: u32) -> Result<bool, i32>
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 codeEINVAL.
§Example
if controllers.get_digital(pros_sys::E_CONTROLLER_MASTER, pros_sys::E_CONTROLLER_DIGITAL_X)? {
println!("Button X pressed")
}Sourcepub fn get_digital_new_press(
&mut self,
controller_id: u32,
button: u32,
) -> Result<bool, i32>
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§
impl Freeze for Controllers
impl RefUnwindSafe for Controllers
impl Send for Controllers
impl Sync for Controllers
impl Unpin for Controllers
impl UnwindSafe for Controllers
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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