G29

Struct G29 

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

G29 Establishes a connection to the Logitech G29 Racing Wheel and provides methods to interact with it.

§Example

use lib_g29{G29, Options, Led};
use std::time::Duration;
use std::thread::sleep;

   let options = Options {
     ..Default::default()
  };

  let g29 = G29::connect(options);

  g29.set_leds(Led::All);

  sleep(Duration::from_secs(5));

  g29.disconnect();

Implementations§

Source§

impl G29

Source

pub fn connect(options: Options) -> G29

Connect to the G29 Racing Wheel

Source

pub fn set_auto_center_force(&mut self, strength: u8, turning_multiplier: u8)

Set auto-center force.

§Arguments
  • strength - The strength of the auto-center force (0x00 to 0x0f)
  • turning_multiplier - The rate the effect strength rises as the wheel turns (0x00 to 0xff)
§Example
use lib_g29{G29, Options};

  let options = Options {
    ..Default::default()
  };


  let mut g29 = G29::connect(options);

  g29.set_auto_center_force(0x0f, 0xff);

  loop {}
Source

pub fn set_leds(&self, leds: Led)

Set the LED lights on the G29.

§Arguments
  • leds - The LED lights to set
§Example
use lib_g29{G29, Options, Led};
use std::time::Duration;
use std::thread::sleep;

  let options = Options {
    ..Default::default()
  };

  let g29 = G29::connect(options);

  loop {
    g29.set_leds(Led::All);
    sleep(Duration::from_secs(1));
    g29.set_leds(Led::Red | Led::GreenOne);
    sleep(Duration::from_secs(1));
  }
Source

pub fn force_friction(&self, left: u8, right: u8)

Set the force feedback on the G29.

§Arguments
  • left - The strength of the left motor (0x00 to 0x07)
  • right - The strength of the right motor (0x00 to 0x07)
§Example
use lib_g29{G29, Options};

  let options = Options {
    ..Default::default()
  };

  let mut g29 = G29::connect(options);

  g29.force_friction(0x07, 0x07);

  loop {}
Source

pub fn throttle(&self) -> u8

Get the throttle value. 255 is depressed, 0 is fully pressed

Source

pub fn brake(&self) -> u8

Get the brake value. 255 is depressed, 0 is fully pressed

Source

pub fn steering(&self) -> u8

Get the steering value. 255 is fully right, 0 is fully left

Source

pub fn steering_fine(&self) -> u8

Get the fine steering value. 255 is fully right, 0 is fully left

Source

pub fn dpad(&self) -> DpadPosition

Get the Dpad position.

§Example
if g29.dpad() == DpadPosition::Top {
   println!("Dpad is at the top");
}
Source

pub fn x_button(&self) -> bool

Returns true if the x button is pressed.

Source

pub fn square_button(&self) -> bool

Returns true if the square button is pressed.

Source

pub fn circle_button(&self) -> bool

Returns true if the circle button is pressed.

Source

pub fn triangle_button(&self) -> bool

Returns true if the triangle button is pressed.

Source

pub fn right_shifter(&self) -> bool

returns true if the right shifter is pressed.

Source

pub fn left_shifter(&self) -> bool

Returns true if the left shifter is pressed.

Source

pub fn r2_button(&self) -> bool

Returns true if the r2 button is pressed.

Source

pub fn l2_button(&self) -> bool

Returns true if the l2 button is pressed.

Source

pub fn share_button(&self) -> bool

Returns true if the share button is pressed.

Source

pub fn option_button(&self) -> bool

Returns true if the option button is pressed.

Source

pub fn r3_button(&self) -> bool

Returns true if the r3 button is pressed.

Source

pub fn l3_button(&self) -> bool

Returns true if the l3 button is pressed.

Source

pub fn gear_selector(&self) -> GearSelector

Get the gear selector position.

§Example
if g29.gear_selector() == GearSelector::First {
   println!("Gear is in first");
}
Source

pub fn plus_button(&self) -> bool

Returns true if the plus button is pressed.

Source

pub fn minus_button(&self) -> bool

Returns true if the minus button is pressed.

Source

pub fn spinner_right(&self) -> bool

Returns true if the spinner is rotating clockwise.

Source

pub fn spinner_left(&self) -> bool

Returns true if the spinner is rotating counter-clockwise.

Source

pub fn spinner_button(&self) -> bool

Returns true if the spinner button is pressed.

Source

pub fn playstation_button(&self) -> bool

Returns true if the playstation button is pressed.

Source

pub fn clutch(&self) -> u8

Returns the value of the clutch pedal. 255 is depressed, 0 is fully pressed

Source

pub fn shifter_x(&self) -> u8

Returns the value of the shifter x axis.

Source

pub fn shifter_y(&self) -> u8

Returns the value of the shifter y axis.

Source

pub fn shifter_pressed(&self) -> bool

Returns true if the shifter is pressed.

Source

pub fn disconnect(&mut self)

Disconnect from the G29.

§Example
use lib_g29{G29, Options};
use std::time::Duration;
use std::thread::sleep;

  let options = Options {
    ..Default::default()
  };

  let mut g29 = G29::connect(options);
   
  sleep(Duration::from_secs(5));
   
  g29.disconnect();
Source

pub fn connected(&self) -> bool

Source

pub fn register_event_handler( &self, event: Event, handler: HandlerFn, ) -> Option<EventHandler>

Register an event handler for a specific event.

§Arguments
  • event - The event to register the handler for
  • handler - The handler function
§Example
use lib_g29{G29, Options, Event, EventHandler};
use std::time::Duration;
use std::thread::sleep;

 let options = Options {
  ..Default::default()
};

let g29 = G29::connect(options);

let handler: EventHandler = g29.register_event_handler(Event::Steering, |g29| {
   println!("Steering: {}", g29.steering());
});

sleep(Duration::from_secs(5));

g29.unregister_event_handler(handler);

g29.disconnect();
Source

pub fn unregister_event_handler(&mut self, event_handler: EventHandler)

Unregister an event handler for a specific event.

§Arguments
  • event_handler - The event handler to unregister
§Example
use lib_g29{G29, Options, Event, EventHandler};
use std::time::Duration;
use std::thread::sleep;

 let options = Options {
  ..Default::default()
};

let g29 = G29::connect(options);

let handler: EventHandler = g29.register_event_handler(Event::Steering, |g29| {
   println!("Steering: {}", g29.steering());
});

sleep(Duration::from_secs(5));

g29.unregister_event_handler(handler);

g29.disconnect();

Trait Implementations§

Source§

impl Clone for G29

Source§

fn clone(&self) -> G29

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for G29

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for G29

§

impl RefUnwindSafe for G29

§

impl Send for G29

§

impl Sync for G29

§

impl Unpin for G29

§

impl UnwindSafe for G29

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> 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> 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.