Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL2 DCM #527

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ members = [
[profile.release]
lto = true
codegen-units = 1

# Need development sdl2 version with additional rumble-related methods
[patch.crates-io]
sdl2 = { git = "https://github.com/Rust-SDL2/rust-sdl2", rev = "a147388" }
4 changes: 3 additions & 1 deletion buttplug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ features = ["default", "unstable"]

[features]
# Basic features
default=["tokio-runtime", "client", "server", "serialize-json", "websockets", "btleplug-manager", "xinput-manager", "serial-manager", "lovense-dongle-manager", "lovense-connect-service-manager", "websocket-server-manager"]
default=["tokio-runtime", "client", "server", "serialize-json", "websockets", "btleplug-manager", "sdl2-manager", "serial-manager", "lovense-dongle-manager", "lovense-connect-service-manager", "websocket-server-manager"]
client=[]
server=[]
serialize-json=[]
# Connectors
websockets=["serialize-json", "async-tungstenite", "native-tls"]
# Device Communication Managers
sdl2-manager=["server", "sdl2"]
xinput-manager=["server"]
btleplug-manager=["server", "btleplug"]
serial-manager=["server", "serialport"]
Expand Down Expand Up @@ -88,6 +89,7 @@ os_info = "3.5.1"
jsonschema = { version = "0.16.1", default-features = false, features = ["resolve-file"] }
derivative = "2.2.0"
tokio-stream = "0.1.11"
sdl2 = { version = "0.35.2", optional = true, features = ["bundled", "static-link", "hidapi"] }

[dev-dependencies]
serde_yaml = "0.9.14"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@
}
}
},
"sdl2-definition": {
"type": "object",
"properties": {
"exists": {
"type": "boolean"
}
}
},
"lovense-connect-service-definition": {
"type": "object",
"properties": {
Expand Down
38 changes: 38 additions & 0 deletions buttplug/buttplug-device-config/buttplug-device-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,44 @@
}
}
},
"sdl2": {
"sdl2": {
"exists": true
},
"defaults": {
"name": "SDL2 Compatible Gamepad",
"messages": {
"ScalarCmd": [
{
"StepRange": [
0,
65535
],
"ActuatorType": "Vibrate"
},
{
"StepRange": [
0,
65535
],
"ActuatorType": "Vibrate"
}
],
"SensorReadCmd": [
{
"FeatureDescriptor": "Battery Level",
"SensorType": "Battery",
"SensorRange": [
[
0,
100
]
]
}
]
}
}
},
"kiiroo-v2": {
"btle": {
"names": [
Expand Down
20 changes: 17 additions & 3 deletions buttplug/buttplug-device-config/buttplug-device-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,6 @@ protocols:
# is its own connector type, so we don't have any special
# connection info here.
#
# TODO Maybe just start calling this "gamepad"? Maybe add "VR
# Controller" too?
#
# The specifier needs to be an object and have some content, but it
# doesn't matter what.
xinput:
Expand All @@ -419,6 +416,23 @@ protocols:
ActuatorType: Vibrate
- StepRange: [0, 65535]
ActuatorType: Vibrate
sdl2:
# Similarly to XInput, this represents any gamepad supported by SDL2
# (including HID and XInput gamepads) and is its own connector type.
sdl2:
exists: true
defaults:
name: SDL2 Compatible Gamepad
messages:
ScalarCmd:
- StepRange: [0, 65535]
ActuatorType: Vibrate
- StepRange: [0, 65535]
ActuatorType: Vibrate
SensorReadCmd:
- FeatureDescriptor: Battery Level
SensorType: Battery
SensorRange: [[0, 100]]
kiiroo-v2:
btle:
names:
Expand Down
32 changes: 29 additions & 3 deletions buttplug/src/server/device/configuration/specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ impl PartialEq for LovenseConnectServiceSpecifier {

/// Specifier for [XInput](crate::server::device::communication_manager::xinput) devices
///
/// Network based services, has no attributes because the
/// [XInput](crate::server::device::communication_manager::xinput) device communication manager handles all device
/// discovery and identification itself.
/// Has no attributes because the
/// [XInput](crate::server::device::communication_manager::xinput)
/// device communication manager handles all device discovery and identification itself.
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct XInputSpecifier {
// Needed for deserialziation but unused.
Expand All @@ -256,6 +256,30 @@ impl PartialEq for XInputSpecifier {
}
}

/// Specifier for [SDL2](crate::server::device::communication_manager::sdl2) devices
///
/// Has no attributes because the
/// [SDL2](crate::server::device::communication_manager::sdl2)
/// device communication manager handles all device discovery and identification itself.
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub struct SDL2Specifier {
// Needed for deserialziation but unused.
#[allow(dead_code)]
exists: bool,
}

impl Default for SDL2Specifier {
fn default() -> Self {
Self { exists: true }
}
}

impl PartialEq for SDL2Specifier {
fn eq(&self, _other: &Self) -> bool {
true
}
}

/// Specifier for HID (USB, Bluetooth) devices
///
/// Handles devices managed by the operating system's HID manager.
Expand Down Expand Up @@ -360,6 +384,7 @@ pub enum ProtocolCommunicationSpecifier {
USB(USBSpecifier),
Serial(SerialSpecifier),
XInput(XInputSpecifier),
SDL2(SDL2Specifier),
LovenseConnectService(LovenseConnectServiceSpecifier),
Websocket(WebsocketSpecifier),
}
Expand All @@ -373,6 +398,7 @@ impl PartialEq for ProtocolCommunicationSpecifier {
(BluetoothLE(self_spec), BluetoothLE(other_spec)) => self_spec == other_spec,
(HID(self_spec), HID(other_spec)) => self_spec == other_spec,
(XInput(self_spec), XInput(other_spec)) => self_spec == other_spec,
(SDL2(self_spec), SDL2(other_spec)) => self_spec == other_spec,
(Websocket(self_spec), Websocket(other_spec)) => self_spec == other_spec,
(LovenseConnectService(self_spec), LovenseConnectService(other_spec)) => {
self_spec == other_spec
Expand Down
62 changes: 57 additions & 5 deletions buttplug/src/server/device/hardware/communication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,47 @@ pub mod lovense_connect_service;
pub mod websocket_server;

// BTLEPlug works on anything not WASM
#[cfg(all(feature = "btleplug-manager", any(target_os = "windows", target_os = "macos", target_os = "linux", target_os="ios", target_os="android")))]
#[cfg(all(
feature = "btleplug-manager",
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "ios",
target_os = "android"
)
))]
pub mod btleplug;

// Lovense Dongles and Serial Ports work on all desktop platforms
#[cfg(all(feature = "lovense-dongle-manager", any(target_os = "windows", target_os = "macos", target_os = "linux")))]
#[cfg(all(
feature = "lovense-dongle-manager",
any(target_os = "windows", target_os = "macos", target_os = "linux")
))]
pub mod lovense_dongle;
#[cfg(all(feature = "serial-manager", any(target_os = "windows", target_os = "macos", target_os = "linux")))]
#[cfg(all(
feature = "serial-manager",
any(target_os = "windows", target_os = "macos", target_os = "linux")
))]
pub mod serialport;

// XInput is windows only
#[cfg(all(feature = "xinput-manager", target_os = "windows"))]
pub mod xinput;

// SDL2 works on anything not WASM
#[cfg(all(
feature = "sdl2-manager",
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "ios",
target_os = "android"
)
))]
pub mod sdl2;

use crate::{
core::{errors::ButtplugDeviceError, ButtplugResultFuture},
server::device::hardware::HardwareConnector,
Expand Down Expand Up @@ -74,11 +102,35 @@ pub enum HardwareSpecificError {
#[cfg(all(feature = "xinput-manager", target_os = "windows"))]
#[error("XInput usage error: {0}")]
XInputError(String),
#[cfg(all(
feature = "sdl2-manager",
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "ios",
target_os = "android"
)
))]
#[error("SDL2 error: {0}")]
SDL2Error(String),
// Btleplug library uses Failure, not Error, on its error enum. :(
#[cfg(all(feature = "btleplug-manager", any(target_os = "windows", target_os = "macos", target_os = "linux", target_os="ios", target_os="android")))]
#[cfg(all(
feature = "btleplug-manager",
any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "ios",
target_os = "android"
)
))]
#[error("Btleplug error: {0}")]
BtleplugError(String),
#[cfg(all(feature = "serial-manager", any(target_os = "windows", target_os = "macos", target_os = "linux")))]
#[cfg(all(
feature = "serial-manager",
any(target_os = "windows", target_os = "macos", target_os = "linux")
))]
#[error("Serial error: {0}")]
SerialError(String),
}
Expand Down
14 changes: 14 additions & 0 deletions buttplug/src/server/device/hardware/communication/sdl2/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Buttplug Rust Source Code File - See https://buttplug.io for more info.
//
// Copyright 2016-2022 Nonpolynomial Labs LLC. All rights reserved.
//
// Licensed under the BSD 3-Clause license. See LICENSE file in the project root
// for full license information.

mod sdl2_device_comm_manager;
mod sdl2_hardware;

pub use sdl2_device_comm_manager::{
SDL2DeviceCommunicationManager,
SDL2DeviceCommunicationManagerBuilder,
};
Loading