From 02d4fe52bfc8c73b5628afd0ae281efcd336b847 Mon Sep 17 00:00:00 2001 From: Sasha Finkelstein Date: Sat, 6 Jul 2024 12:33:08 +0200 Subject: [PATCH] feat: Add force feedback constants as an enum BREAKING CHANGE: Force feedback functions now take enums instead of ints --- Cargo.lock | 4 +- Cargo.toml | 2 +- src/evdev.rs | 8 +++- src/kinds.rs | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/uinput.rs | 2 +- 5 files changed, 119 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d655f51..c550b6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "input-linux-sys" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a687a25a4973027df9153753a5589f97fe1e958f694a34eea5606ae65299ab8" +checksum = "1c7ef95c35c8ef8d114f5e197a5ac9554dc4afdd19ae78ae1fd0fc0944cb1340" dependencies = [ "libc", "nix", diff --git a/Cargo.toml b/Cargo.toml index 0375b97..7ae2808 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ include = [ features = ["dox", "tokio-util-0_6", "tokio-util-0_7", "serde"] [dependencies] -input-linux-sys = "0.8" +input-linux-sys = "0.8.2" nix = "0.26" tokio-util-0_7 = { package = "tokio-util", version = "0.7", default-features = false, features = ["codec"], optional = true } tokio-util-0_6 = { package = "tokio-util", version = "0.6", default-features = false, features = ["codec"], optional = true } diff --git a/src/evdev.rs b/src/evdev.rs index 8a6d4b4..1a8b2cb 100644 --- a/src/evdev.rs +++ b/src/evdev.rs @@ -8,7 +8,8 @@ use nix; use crate::sys; use crate::{ AbsoluteAxis, AbsoluteInfo, AutorepeatKind, EventKind, InputId, - InputProperty, Key, LedKind, MiscKind, RelativeAxis, SoundKind, SwitchKind + InputProperty, Key, LedKind, MiscKind, RelativeAxis, SoundKind, SwitchKind, + ForceFeedbackKind, }; use crate::macros::convert_error; use crate::bitmask::Bitmask; @@ -237,6 +238,11 @@ impl EvdevHandle { autorepeat_bits } + impl_bitmasks! { ForceFeedbackKind, EventKind::ForceFeedback, + force_feedback_mask, set_force_feedback_mask, + force_feedback_bits + } + /// `EVIOCGMASK` pub fn event_mask_raw(&self, kind: EventKind, buffer: &mut [u8]) -> io::Result<()> { unsafe { diff --git a/src/kinds.rs b/src/kinds.rs index 41639d7..ecba647 100644 --- a/src/kinds.rs +++ b/src/kinds.rs @@ -396,6 +396,112 @@ pub enum SoundKind { Unknown7, } +/// Force feedback events. +#[repr(u16)] +#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug)] +#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] +#[allow(missing_docs)] +pub enum ForceFeedbackKind { + Unknown0 = 0, + Unknown1, + Unknown2, + Unknown3, + Unknown4, + Unknown5, + Unknown6, + Unknown7, + Unknown8, + Unknown9, + UnknownA, + UnknownB, + UnknownC, + UnknownD, + UnknownE, + UnknownF, + Unknown10, + Unknown11, + Unknown12, + Unknown13, + Unknown14, + Unknown15, + Unknown16, + Unknown17, + Unknown18, + Unknown19, + Unknown1A, + Unknown1B, + Unknown1C, + Unknown1D, + Unknown1E, + Unknown1F, + Unknown20, + Unknown21, + Unknown22, + Unknown23, + Unknown24, + Unknown25, + Unknown26, + Unknown27, + Unknown28, + Unknown29, + Unknown2A, + Unknown2B, + Unknown2C, + Unknown2D, + Unknown2E, + Unknown2F, + Unknown30, + Unknown31, + Unknown32, + Unknown33, + Unknown34, + Unknown35, + Unknown36, + Unknown37, + Unknown38, + Unknown39, + Unknown3A, + Unknown3B, + Unknown3C, + Unknown3D, + Unknown3E, + Unknown3F, + Unknown40, + Unknown41, + Unknown42, + Unknown43, + Unknown44, + Unknown45, + Unknown46, + Unknown47, + Unknown48, + Unknown49, + Unknown4A, + Unknown4B, + Unknown4C, + Unknown4D, + Unknown4E, + Unknown4F, + Rumble = sys::FF_RUMBLE as _, + Periodic = sys::FF_PERIODIC as _, + Constant = sys::FF_CONSTANT as _, + Spring = sys::FF_SPRING as _, + Friction = sys::FF_FRICTION as _, + Damper = sys::FF_DAMPER as _, + Inertia = sys::FF_INERTIA as _, + Ramp = sys::FF_RAMP as _, + Square = sys::FF_SQUARE as _, + Triangle = sys::FF_TRIANGLE as _, + Sine = sys::FF_SINE as _, + SawUp = sys::FF_SAW_UP as _, + SawDown = sys::FF_SAW_DOWN as _, + Custom = sys::FF_CUSTOM as _, + Unknown5E, + Unknown5F, + Gain = sys::FF_GAIN as _, + Autocenter = sys::FF_AUTOCENTER as _, +} + impl_iterable! { InputProperty(0, sys::INPUT_PROP_CNT) } impl EventKind { @@ -528,3 +634,5 @@ impl_iterable! { LedKind(0, sys::LED_CNT) } impl_iterable! { AutorepeatKind(0, sys::REP_CNT) } impl_iterable! { SoundKind(0, sys::SND_CNT) } + +impl_iterable! { ForceFeedbackKind(0, sys::FF_AUTOCENTER + 1) } diff --git a/src/uinput.rs b/src/uinput.rs index 6580372..ae05c3f 100644 --- a/src/uinput.rs +++ b/src/uinput.rs @@ -224,7 +224,7 @@ impl UInputHandle { } { /// `UI_SET_FFBIT` - @set set_ffbit(i32) = ui_set_ffbit + @set set_ffbit(kinds::ForceFeedbackKind) = ui_set_ffbit } { /// `UI_SET_PHYS`