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

Add MSC timestamp event #40

Open
wants to merge 3 commits into
base: stable
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions stick/src/ctlr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ impl Controller {
TrimDown(p) => self.button(Btn::TrimDown, TrimDown, p),
TrimLeft(p) => self.button(Btn::TrimLeft, TrimLeft, p),
TrimRight(p) => self.button(Btn::TrimRight, TrimRight, p),
Timestamp(p) => Poll::Ready(Timestamp(p)),
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions stick/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ pub enum Event {
ScrollY(f64),
/// Scroll Button on a mouse
Scroll(bool),
/// Timestamp event for the number of microseconds since last reset
Timestamp(u32),
}

impl Event {
Expand Down Expand Up @@ -335,6 +337,7 @@ impl Event {
0x5B => Event::TrimDown(value != 0.0),
0x5C => Event::TrimLeft(value != 0.0),
0x5D => Event::TrimRight(value != 0.0),
0x5E => Event::Timestamp(value as u32),
n => Event::Number((n & !0x80) as i8, value != 0.0),
}
}
Expand Down Expand Up @@ -438,6 +441,7 @@ impl Event {
TrimDown(p) => (0x5B, f64::from(u8::from(p))),
TrimLeft(p) => (0x5C, f64::from(u8::from(p))),
TrimRight(p) => (0x5D, f64::from(u8::from(p))),
Timestamp(p) => (0x5E, p as f64),
}
}
}
Expand Down Expand Up @@ -554,6 +558,7 @@ impl std::fmt::Display for Event {
ActionL(p) => write!(f, "ActionL {}", pushed(p)),
ActionR(p) => write!(f, "ActionR {}", pushed(p)),
Pinky(p) => write!(f, "Pinky {}", pushed(p)),
Timestamp(p) => write!(f, "Timestamp {}μs", p),
}
}
}
51 changes: 44 additions & 7 deletions stick/src/raw/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,56 @@ fn linux_abs_to_stick_event(
}
}

// Convert Linux MSC event to stick Event.
fn linux_msc_to_stick_event(
pending: &mut Vec<Event>,
msc_event: c_ushort,
msc_value: c_int,
) {
match msc_event {
0x00 /* MSC_SERIAL */ => {
eprintln!("Unknown Event: MSC_SERIAL");
eprintln!("Report at https://github.com/libcala/stick/issues");
}
0x01 /* MSC_PULSELED */ => {
eprintln!("Unknown Event: MSC_PULSELED");
eprintln!("Report at https://github.com/libcala/stick/issues");
}
0x02 /* MSC_GESTURE */ => {
eprintln!("Unknown Event: MSC_GESTURE");
eprintln!("Report at https://github.com/libcala/stick/issues");
}
0x03 /* MSC_RAW */ => {
eprintln!("Unknown Event: MSC_RAW");
eprintln!("Report at https://github.com/libcala/stick/issues");
}
0x04 /* MSC_SCAN */ => {
eprintln!("Unknown Event: MSC_SCAN");
eprintln!("Report at https://github.com/libcala/stick/issues");
}
0x05 /* MSC_TIMESTAMP */ => pending.push(Event::Timestamp(msc_value as u32)),

// there is no 0x06 defined

0x07 /* MSC_MAX */ => {
eprintln!("Unknown Event: MSC_MAX");
eprintln!("Report at https://github.com/libcala/stick/issues");
}

_unknown => {
eprintln!("Unknown Linux MSC {}", _unknown);
eprintln!("Report at https://github.com/libcala/stick/issues");
}
}
}

fn linux_evdev_to_stick_event(pending: &mut Vec<Event>, e: EvdevEv) {
match e.ev_type {
0x00 /* SYN */ => {}, // Ignore Syn Input Events
0x01 /* BTN */ => linux_btn_to_stick_event(pending, e.ev_code, e.ev_value != 0),
0x02 /* REL */ => linux_rel_to_stick_event(pending, e.ev_code, e.ev_value),
0x03 /* ABS */ => linux_abs_to_stick_event(pending, e.ev_code, e.ev_value),
0x04 /* MSC */ => {
if e.ev_code != 4 { // Ignore Misc./Scan Events
let (code, val) = (e.ev_code, e.ev_value);
eprintln!("Unknown Linux Misc Code: {}, Value: {}", code, val);
eprintln!("Report at https://github.com/libcala/stick/issues");
}
}
0x04 /* MSC */ => linux_msc_to_stick_event(pending, e.ev_code, e.ev_value),
0x15 /* FF */ => {}, // Ignore Force Feedback Input Events
_unknown => {
eprintln!("Unknown Linux Event Type: {}", _unknown);
Expand Down