add hidapi as default feature

This commit is contained in:
Mikaël Fourrier
2021-09-15 21:57:42 +02:00
parent c5f57757e1
commit c261a0df2e
5 changed files with 30 additions and 15 deletions
+3 -2
View File
@@ -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}"
+5 -1
View File
@@ -9,6 +9,7 @@ authors = [ "Tony Aldridge <tony@angry-lawyer.com>", "Cobrand <cobrandw@gmail.co
keywords = ["SDL", "windowing", "graphics", "api", "engine"]
categories = ["rendering","api-bindings","game-engines","multimedia"]
readme = "README.md"
resolver = "2"
[lib]
name = "sdl2"
@@ -40,11 +41,13 @@ optional = true
[features]
unsafe_textures = []
default = []
#default = ["hidapi"]
gfx = ["c_vec", "sdl2-sys/gfx"]
mixer = ["sdl2-sys/mixer"]
image = ["sdl2-sys/image"]
ttf = ["sdl2-sys/ttf"]
# Use hidapi support in SDL. Only 2.0.12 and after
hidapi = []
use-bindgen = ["sdl2-sys/use-bindgen"]
use-pkgconfig = ["sdl2-sys/use-pkgconfig"]
@@ -141,6 +144,7 @@ required-features = ["ttf", "image"]
name = "resource-manager"
[[example]]
required-features = ["hidapi"]
name = "sensors"
[[example]]
+11 -8
View File
@@ -1,13 +1,15 @@
use crate::rwops::RWops;
use crate::sensor::SensorType;
use libc::c_char;
use std::convert::TryInto;
use std::error;
use std::ffi::{CStr, CString, NulError};
use std::fmt;
use std::io;
use std::path::Path;
use sys::SDL_bool;
#[cfg(feature = "hidapi")]
use crate::sensor::SensorType;
#[cfg(feature = "hidapi")]
use std::convert::TryInto;
use crate::common::{validate_int, IntegerOrSdlError};
use crate::get_error;
@@ -489,9 +491,10 @@ impl GameController {
}
}
#[cfg(feature = "hidapi")]
impl GameController {
#[doc(alias = "SDL_GameControllerHasSensor")]
pub fn has_sensor(&self, sensor_type: SensorType) -> 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
},
)
};
+10 -4
View File
@@ -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<u32> 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,
+1
View File
@@ -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;