From 5d0c0beda9e07688101b2217c4fdc1a9c4103b05 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sun, 30 Jan 2022 14:24:00 +0100 Subject: [PATCH] Expose ff effects --- src/constants.rs | 79 +++++++++++++++++++++++++++------------------- src/raw_stream.rs | 14 ++++++++ src/sync_stream.rs | 4 +++ 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 40b6e51..f9e6841 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -285,44 +285,57 @@ impl MiscType { pub(crate) const COUNT: usize = libc::MSC_CNT; } -// pub enum FFStatusDataIndex { -// FF_STATUS_STOPPED = 0x00, -// FF_STATUS_PLAYING = 0x01, -// } +#[derive(Copy, Clone, PartialEq, Eq)] +pub struct FFStatusDataIndex(pub u16); -// #[derive(Copy, Clone, Copy, Clone)] -// pub enum FFEffect { -// FF_RUMBLE = 0x50, -// FF_PERIODIC = 0x51, -// FF_CONSTANT = 0x52, -// FF_SPRING = 0x53, -// FF_FRICTION = 0x54, -// FF_DAMPER = 0x55, -// FF_INERTIA = 0x56, -// FF_RAMP = 0x57, -// FF_SQUARE = 0x58, -// FF_TRIANGLE = 0x59, -// FF_SINE = 0x5a, -// FF_SAW_UP = 0x5b, -// FF_SAW_DOWN = 0x5c, -// FF_CUSTOM = 0x5d, -// FF_GAIN = 0x60, -// FF_AUTOCENTER = 0x61, -// } +evdev_enum!( + FFStatusDataIndex, + Array, + FF_STATUS_STOPPED = 0x00, + FF_STATUS_PLAYING = 0x01, +); -// impl FFEffect { -// // Needs to be a multiple of 8 -// pub const COUNT: usize = libc::FF_CNT; -// } +impl FFStatusDataIndex { + pub const COUNT: usize = 2; +} -// #[derive(Copy, Clone, PartialEq, Eq)] -// pub struct RepeatType(pub u16); +#[derive(Copy, Clone, PartialEq, Eq)] +pub struct FFEffect(pub u16); -// evdev_enum!(RepeatType, REP_DELAY = 0x00, REP_PERIOD = 0x01,); +evdev_enum!( + FFEffect, + Array, + FF_RUMBLE = 0x50, + FF_PERIODIC = 0x51, + FF_CONSTANT = 0x52, + FF_SPRING = 0x53, + FF_FRICTION = 0x54, + FF_DAMPER = 0x55, + FF_INERTIA = 0x56, + FF_RAMP = 0x57, + FF_SQUARE = 0x58, + FF_TRIANGLE = 0x59, + FF_SINE = 0x5a, + FF_SAW_UP = 0x5b, + FF_SAW_DOWN = 0x5c, + FF_CUSTOM = 0x5d, + FF_GAIN = 0x60, + FF_AUTOCENTER = 0x61, +); -// impl RepeatType { -// pub(crate) const COUNT: usize = libc::REP_CNT; -// } +impl FFEffect { + // Needs to be a multiple of 8 + pub const COUNT: usize = libc::FF_CNT; +} + +#[derive(Copy, Clone, PartialEq, Eq)] +pub struct RepeatType(pub u16); + +evdev_enum!(RepeatType, REP_DELAY = 0x00, REP_PERIOD = 0x01,); + +impl RepeatType { + pub const COUNT: usize = libc::REP_CNT; +} /// A type associated with simple sounds, such as beeps or tones. #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/src/raw_stream.rs b/src/raw_stream.rs index e34fc51..20f1caf 100644 --- a/src/raw_stream.rs +++ b/src/raw_stream.rs @@ -62,6 +62,7 @@ pub struct RawDevice { supported_switch: Option>, supported_led: Option>, supported_misc: Option>, + supported_ff: Option>, auto_repeat: Option, // ff: Option>, // ff_stat: Option, @@ -178,6 +179,14 @@ impl RawDevice { None }; + let supported_ff = if ty.contains(EventType::FORCEFEEDBACK) { + let mut ff = AttributeSet::::new(); + unsafe { sys::eviocgbit_misc(file.as_raw_fd(), ff.as_mut_raw_slice())? }; + Some(ff) + } else { + None + }; + //unsafe { sys::eviocgbit(file.as_raw_fd(), ffs(FORCEFEEDBACK.bits()), 0x7f, bits_as_u8_slice)?; } let supported_snd = if ty.contains(EventType::SOUND) { @@ -222,6 +231,7 @@ impl RawDevice { supported_led, supported_misc, supported_snd, + supported_ff, auto_repeat, event_buf: Vec::new(), grabbed: false, @@ -360,6 +370,10 @@ impl RawDevice { self.supported_switch.as_deref() } + pub fn supported_forcefeedback_effects(&self) -> Option<&AttributeSetRef> { + self.supported_ff.as_deref() + } + /// Returns a set of supported LEDs on the device. /// /// Most commonly these are state indicator lights for things like Scroll Lock, but they diff --git a/src/sync_stream.rs b/src/sync_stream.rs index 7ee5455..29462a4 100644 --- a/src/sync_stream.rs +++ b/src/sync_stream.rs @@ -230,6 +230,10 @@ impl Device { self.raw.supported_switches() } + pub fn supported_forcefeedback_effects(&self) -> Option<&AttributeSetRef> { + self.raw.supported_forcefeedback_effects() + } + /// Returns a set of supported LEDs on the device. /// /// Most commonly these are state indicator lights for things like Scroll Lock, but they