Skip to content

Commit

Permalink
Improve Gamepad DPad Button Detection
Browse files Browse the repository at this point in the history
Enable the `axis_dpad_to_button` gilrs filter to map hats to dpad
buttons on supported remotes.
  • Loading branch information
zicklag committed Jul 5, 2022
1 parent f73987a commit 2155a3c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/bevy_gilrs/src/gilrs_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::converter::{convert_axis, convert_button, convert_gamepad_id};
use bevy_ecs::event::EventWriter;
use bevy_ecs::system::{NonSend, NonSendMut};
use bevy_input::{gamepad::GamepadEventRaw, prelude::*};
use gilrs::{EventType, Gilrs};
use gilrs::{ev::filter::axis_dpad_to_button, EventType, Filter, Gilrs};

pub fn gilrs_event_startup_system(gilrs: NonSend<Gilrs>, mut events: EventWriter<GamepadEventRaw>) {
for (id, _) in gilrs.gamepads() {
Expand All @@ -14,7 +14,12 @@ pub fn gilrs_event_startup_system(gilrs: NonSend<Gilrs>, mut events: EventWriter
}

pub fn gilrs_event_system(mut gilrs: NonSendMut<Gilrs>, mut events: EventWriter<GamepadEventRaw>) {
while let Some(gilrs_event) = gilrs.next_event() {
while let Some(gilrs_event) = gilrs
.next_event()
.filter_ev(&axis_dpad_to_button, &mut gilrs)
{
gilrs.update(&gilrs_event);

match gilrs_event.event {
EventType::Connected => {
events.send(GamepadEventRaw::new(
Expand Down

0 comments on commit 2155a3c

Please sign in to comment.