(
&mut self,
app: &mut S,
gilrs: &Gilrs,
event: gilrs::Event,
)
| 227 | None |
| 228 | } |
| 229 | |
| 230 | fn ensure_gilrs(&mut self) { |
| 231 | if self.gilrs.is_some() { |
| 232 | return; |
| 233 | } |
| 234 | if let Ok(gilrs) = Gilrs::new() { |
| 235 | self.gilrs = Some(gilrs); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | fn handle_event<S: GamepadSink>( |
| 240 | &mut self, |
| 241 | app: &mut S, |
| 242 | gilrs: &Gilrs, |
| 243 | event: gilrs::Event, |
| 244 | ) { |
| 245 | let id = event.id; |
| 246 | match event.event { |
| 247 | EventType::Connected => { |
| 248 | let gp = gilrs.gamepad(id); |
| 249 | if is_joycon(&gp) { |
| 250 | return; |
| 251 | } |
| 252 | if let Some(index) = self.assign_index_if_unique(gilrs, id) { |
| 253 | log_gamepad_connected(gilrs, id, index); |
| 254 | clear_gamepad(app, index); |
| 255 | } |
| 256 | } |
| 257 | EventType::Disconnected => { |
| 258 | let disconnected_index = self |
| 259 | .id_to_uuid |
| 260 | .get(&id) |
| 261 | .and_then(|uuid| self.uuid_to_index.get(uuid).copied()); |
| 262 | self.handle_disconnect(app, id); |
| 263 | if let Some(index) = disconnected_index { |
| 264 | self.stop_rumble(index); |
| 265 | } |
| 266 | self.down_masks.remove(&id); |
| 267 | if let Some(uuid) = self.id_to_uuid.remove(&id) { |
| 268 | self.uuid_in_use.remove(&uuid); |
| 269 | } |
| 270 | } |
| 271 | EventType::ButtonPressed(button, _) => { |
| 272 | if let Some(mapped) = map_button(button) { |
| 273 | self.set_button(app, gilrs, id, mapped, true); |
| 274 | self.set_trigger_axis_from_button(app, gilrs, id, button, 1.0); |
| 275 | self.log_raw_like_state(gilrs, id, "button_pressed"); |
| 276 | } |
| 277 | } |
| 278 | EventType::ButtonRepeated(button, _) => { |
| 279 | if let Some(mapped) = map_button(button) { |
| 280 | self.set_button(app, gilrs, id, mapped, true); |
| 281 | self.set_trigger_axis_from_button(app, gilrs, id, button, 1.0); |
| 282 | self.log_raw_like_state(gilrs, id, "button_repeated"); |
| 283 | } |
| 284 | } |
| 285 | EventType::ButtonReleased(button, _) => { |
| 286 | if let Some(mapped) = map_button(button) { |
no test coverage detected