pub struct State(/* private fields */);Expand description
Keeps track of the known device state,
so that an individual Event may be isolated from each set of new bytes received over USB.
You must keep this object up-to-date by feeding all of the bytes read from the G11’s HID interface through State::try_consume_event.
Implementations§
Source§impl State
impl State
pub fn new() -> Self
Sourcepub fn is_pressed(&self, key: Key) -> bool
pub fn is_pressed(&self, key: Key) -> bool
Returns true if the given Key is known to be currently pressed, false otherwise
Sourcepub fn iter_pressed(&self) -> impl Iterator<Item = Key>
pub fn iter_pressed(&self) -> impl Iterator<Item = Key>
Returns every Key for which Self::is_pressed would return true
(there may be up to five pressed simultaneously on the G11)
Sourcepub fn try_consume_event(
&mut self,
usb_bytes: &[u8],
) -> Result<Event, EventError>
pub fn try_consume_event( &mut self, usb_bytes: &[u8], ) -> Result<Event, EventError>
Updates the State by inspecting the given bytes (which should have been acquired from the G11’s HID interface).
This, combined with the previously known state, will allow an Event to be inferred as the signal’s meaning.
Note: The G11 macro interface emits HID packets of 9 bytes. Anything less will produce an EventError
The provided buffer may be larger than that, but only the first 9 bytes will be inspected.
Sourcepub fn set_exact_lit_leds(&mut self, lit_keys: &[Key]) -> Option<[u8; 4]>
pub fn set_exact_lit_leds(&mut self, lit_keys: &[Key]) -> Option<[u8; 4]>
Produces an HID Feature Report (which you may then submit to the G11’s HID interface)
that will cause only the given Key LEDs to be lit (and all others unlit).
Will return None if the request would be fruitless (if these exact LEDs are already lit)
Sourcepub fn light_led(&mut self, key: Key) -> Option<[u8; 4]>
pub fn light_led(&mut self, key: Key) -> Option<[u8; 4]>
Produces an HID Feature Report (which you may then submit to the G11’s HID interface)
that will cause the given Key LED to transition from unlit to lit, leaving all other LEDs alone.
Will return None if the request would be fruitless (if the LED is already lit or a key with no LED is passed)
Sourcepub fn extinguish_led(&mut self, key: Key) -> Option<[u8; 4]>
pub fn extinguish_led(&mut self, key: Key) -> Option<[u8; 4]>
Produces an HID Feature Report (which you may then submit to the G11’s HID interface)
that will cause the given Key LED to transition from lit to unlit, leaving all other LEDs alone.
Will return None if the request would be fruitless (if the LED is already unlit or a key with no LED is passed)