From c261a0df2ea785517ab2c48499a0c85352489917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Fourrier?= Date: Wed, 15 Sep 2021 21:57:42 +0200 Subject: [PATCH] add hidapi as default feature --- .github/workflows/CI.yml | 5 +++-- Cargo.toml | 6 +++++- src/sdl2/controller.rs | 19 +++++++++++-------- src/sdl2/event.rs | 14 ++++++++++---- src/sdl2/lib.rs | 1 + 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 09f68f62..908ed139 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -74,5 +74,6 @@ jobs: set -xeuo pipefail rustc --version cargo --version - cargo build --features "${CI_BUILD_FEATURES}" - cargo test --features "${CI_BUILD_FEATURES}" + # SDL 2.0.10 so no hidapi + cargo build --no-default-features --features "${CI_BUILD_FEATURES}" + cargo test --no-default-features --features "${CI_BUILD_FEATURES}" diff --git a/Cargo.toml b/Cargo.toml index 29e18172..2d8a2c5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ authors = [ "Tony Aldridge ", "Cobrand bool { + pub fn has_sensor(&self, sensor_type: crate::sensor::SensorType) -> bool { let result = unsafe { sys::SDL_GameControllerHasSensor(self.raw, sensor_type.into()) }; match result { @@ -501,7 +504,7 @@ impl GameController { } #[doc(alias = "SDL_GameControllerIsSensorEnabled")] - pub fn sensor_enabled(&self, sensor_type: SensorType) -> bool { + pub fn sensor_enabled(&self, sensor_type: crate::sensor::SensorType) -> bool { let result = unsafe { sys::SDL_GameControllerIsSensorEnabled(self.raw, sensor_type.into()) }; @@ -514,7 +517,7 @@ impl GameController { #[doc(alias = "SDL_GameControllerHasSensor")] pub fn sensor_set_enabled( &self, - sensor_type: SensorType, + sensor_type: crate::sensor::SensorType, enabled: bool, ) -> Result<(), IntegerOrSdlError> { let result = unsafe { @@ -522,9 +525,9 @@ impl GameController { self.raw, sensor_type.into(), if enabled { - SDL_bool::SDL_TRUE + sys::SDL_bool::SDL_TRUE } else { - SDL_bool::SDL_FALSE + sys::SDL_bool::SDL_FALSE }, ) }; diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index 0994479f..2c654073 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -15,6 +15,7 @@ use std::mem::transmute; use std::ptr; use std::sync::Mutex; +use crate::controller; use crate::controller::{Axis, Button}; use crate::get_error; use crate::joystick; @@ -25,7 +26,6 @@ use crate::keyboard::Mod; use crate::keyboard::Scancode; use crate::mouse; use crate::mouse::{MouseButton, MouseState, MouseWheelDirection}; -use crate::{controller, sensor::SensorType}; use crate::sys; use crate::sys::SDL_EventFilter; @@ -298,6 +298,7 @@ pub enum EventType { ControllerDeviceAdded = SDL_EventType::SDL_CONTROLLERDEVICEADDED as u32, ControllerDeviceRemoved = SDL_EventType::SDL_CONTROLLERDEVICEREMOVED as u32, ControllerDeviceRemapped = SDL_EventType::SDL_CONTROLLERDEVICEREMAPPED as u32, + #[cfg(feature = "hidapi")] ControllerSensorUpdated = SDL_EventType::SDL_CONTROLLERSENSORUPDATE as u32, FingerDown = SDL_EventType::SDL_FINGERDOWN as u32, @@ -367,6 +368,7 @@ impl TryFrom for EventType { SDL_CONTROLLERDEVICEADDED => ControllerDeviceAdded, SDL_CONTROLLERDEVICEREMOVED => ControllerDeviceRemoved, SDL_CONTROLLERDEVICEREMAPPED => ControllerDeviceRemapped, + #[cfg(feature = "hidapi")] SDL_CONTROLLERSENSORUPDATE => ControllerSensorUpdated, SDL_FINGERDOWN => FingerDown, @@ -677,10 +679,11 @@ pub enum Event { }, /// Triggered when the gyroscope or accelerometer is updated + #[cfg(feature = "hidapi")] ControllerSensorUpdated { timestamp: u32, which: u32, - sensor: SensorType, + sensor: crate::sensor::SensorType, /// Data from the sensor. /// /// See the `sensor` module for more information. @@ -1625,12 +1628,13 @@ impl Event { which: event.which as u32, } } + #[cfg(feature = "hidapi")] EventType::ControllerSensorUpdated => { let event = raw.csensor; Event::ControllerSensorUpdated { timestamp: event.timestamp, which: event.which as u32, - sensor: SensorType::from_ll(event.sensor), + sensor: crate::sensor::SensorType::from_ll(event.sensor), data: event.data, } } @@ -1903,7 +1907,6 @@ impl Event { | (Self::ControllerDeviceAdded { .. }, Self::ControllerDeviceAdded { .. }) | (Self::ControllerDeviceRemoved { .. }, Self::ControllerDeviceRemoved { .. }) | (Self::ControllerDeviceRemapped { .. }, Self::ControllerDeviceRemapped { .. }) - | (Self::ControllerSensorUpdated { .. }, Self::ControllerSensorUpdated { .. }) | (Self::FingerDown { .. }, Self::FingerDown { .. }) | (Self::FingerUp { .. }, Self::FingerUp { .. }) | (Self::FingerMotion { .. }, Self::FingerMotion { .. }) @@ -1921,6 +1924,8 @@ impl Event { | (Self::RenderDeviceReset { .. }, Self::RenderDeviceReset { .. }) | (Self::User { .. }, Self::User { .. }) | (Self::Unknown { .. }, Self::Unknown { .. }) => true, + #[cfg(feature = "hidapi")] + (Self::ControllerSensorUpdated { .. }, Self::ControllerSensorUpdated { .. }) => true, _ => false, } } @@ -1970,6 +1975,7 @@ impl Event { Self::ControllerDeviceAdded { timestamp, .. } => timestamp, Self::ControllerDeviceRemoved { timestamp, .. } => timestamp, Self::ControllerDeviceRemapped { timestamp, .. } => timestamp, + #[cfg(feature = "hidapi")] Self::ControllerSensorUpdated { timestamp, .. } => timestamp, Self::FingerDown { timestamp, .. } => timestamp, Self::FingerUp { timestamp, .. } => timestamp, diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 72d6b5b3..800ccbd3 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -83,6 +83,7 @@ pub mod rect; pub mod render; pub mod rwops; mod sdl; +#[cfg(feature = "hidapi")] pub mod sensor; pub mod surface; pub mod timer;