Skip to content

Commit

Permalink
feat: Add force feedback constants as an enum
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Force feedback functions now take enums instead of ints
  • Loading branch information
WhatAmISupposedToPutHere authored and arcnmx committed Jul 19, 2024
1 parent 3f5d3fc commit 02d4fe5
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 7 additions & 1 deletion src/evdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -237,6 +238,11 @@ impl<F: AsRawFd> EvdevHandle<F> {
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 {
Expand Down
108 changes: 108 additions & 0 deletions src/kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) }
2 changes: 1 addition & 1 deletion src/uinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<F: AsRawFd> UInputHandle<F> {
}
{
/// `UI_SET_FFBIT`
@set set_ffbit(i32) = ui_set_ffbit
@set set_ffbit(kinds::ForceFeedbackKind) = ui_set_ffbit
}
{
/// `UI_SET_PHYS`
Expand Down

0 comments on commit 02d4fe5

Please sign in to comment.