Skip to content

Commit

Permalink
Use evdev git
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <[email protected]>
  • Loading branch information
seanyoung committed May 11, 2024
1 parent 91b4c2f commit 627c1d7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = [ "/.git*", "/testdata", "/tests", "/TODO" ]
clap = { version = "4.5", features = [ "derive" ] }
toml = "0.8"
itertools = "0.12"
evdev = "0.12.1"
evdev = { git = "https://github.com/emberian/evdev" }
mio = { version = "0.8", features = [ "os-poll", "os-ext" ] }
nix = { version = "0.28", features = [ "fs", "ioctl" ] }
humantime = "2.1"
Expand Down
8 changes: 4 additions & 4 deletions src/bin/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cir::{
rc_maps::parse_rc_maps_file,
rcdev::{enumerate_rc_dev, Rcdev},
};
use evdev::Key;
use evdev::KeyCode;
use irp::{Irp, Options};
use log::debug;
use std::{
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn config(config: &crate::Config) {

if !config.scankey.is_empty() {
for (scancode, keycode) in &config.scankey {
let key = match Key::from_str(keycode) {
let key = match KeyCode::from_str(keycode) {
Ok(key) => key,
Err(_) => {
eprintln!("error: ‘{keycode}’ is not a valid keycode");
Expand Down Expand Up @@ -392,7 +392,7 @@ fn load_keymap(
for keymap in keymaps {
for (scancode, keycode) in &keymap.scancodes {
// TODO: needs some logic to check for KEY_{} etc like load_lircd
let key = match Key::from_str(keycode) {
let key = match KeyCode::from_str(keycode) {
Ok(key) => key,
Err(_) => {
eprintln!("error: ‘{keycode}’ is not a valid keycode");
Expand Down Expand Up @@ -605,7 +605,7 @@ fn load_lircd(
if !name.starts_with("KEY_") {
name.insert_str(0, "KEY_");
};
let key = match Key::from_str(&name) {
let key = match KeyCode::from_str(&name) {
Ok(key) => key,
Err(_) => {
eprintln!(
Expand Down
4 changes: 2 additions & 2 deletions src/bin/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn print_rc_dev(list: &[rcdev::Rcdev], config: &crate::List) {
// kernel v5.7 and later give 64 bit scancodes
let scancode =
u64::from_ne_bytes(scancode.try_into().unwrap());
let keycode = evdev::Key::new(keycode as u16);
let keycode = evdev::KeyCode::new(keycode as u16);

println!(
"\tScancode\t\t: 0x{scancode:08x} => {keycode:?}"
Expand All @@ -86,7 +86,7 @@ fn print_rc_dev(list: &[rcdev::Rcdev], config: &crate::List) {
// kernel v5.6 and earlier give 32 bit scancodes
let scancode =
u32::from_ne_bytes(scancode.try_into().unwrap());
let keycode = evdev::Key::new(keycode as u16);
let keycode = evdev::KeyCode::new(keycode as u16);

println!(
"\tScancode\t\t: 0x{scancode:08x} => {keycode:?}"
Expand Down
52 changes: 3 additions & 49 deletions src/bin/commands/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cir::lirc::{Lirc, LIRC_SCANCODE_FLAG_REPEAT, LIRC_SCANCODE_FLAG_TOGGLE};
use evdev::{Device, InputEventKind};
use evdev::Device;
use mio::{unix::SourceFd, Events, Interest, Poll, Token};
use nix::fcntl::{FcntlArg, OFlag};
use std::os::unix::io::AsRawFd;
Expand Down Expand Up @@ -227,7 +227,7 @@ pub fn test(test: &crate::Test) {
}

for entry in &scanbuf {
let keycode = evdev::Key::new(entry.keycode as u16);
let keycode = evdev::KeyCode::new(entry.keycode as u16);

let timestamp = Duration::new(
entry.timestamp / 1_000_000_000,
Expand Down Expand Up @@ -301,53 +301,7 @@ pub fn test(test: &crate::Test) {

last_event_time = Some(timestamp);

let ty = ev.event_type();
let value = ev.value();

match ev.kind() {
InputEventKind::Misc(misc) => {
println!("{ty:?}: {misc:?} = {value:#010x}");
}
InputEventKind::Synchronization(sync) => {
println!("{sync:?}");
}
InputEventKind::Key(key) if value == 1 => {
println!("KEY_DOWN: {key:?} ");
}
InputEventKind::Key(key) if value == 0 => {
println!("KEY_UP: {key:?}");
}
InputEventKind::Key(key) => {
println!("{ty:?} {key:?} {value}");
}
InputEventKind::RelAxis(rel) => {
println!("{ty:?} {rel:?} {value:#08x}");
}
InputEventKind::AbsAxis(abs) => {
println!("{ty:?} {abs:?} {value:#08x}");
}
InputEventKind::Switch(switch) => {
println!("{ty:?} {switch:?} {value:#08x}");
}
InputEventKind::Led(led) => {
println!("{ty:?} {led:?} {value:#08x}");
}
InputEventKind::Sound(sound) => {
println!("{ty:?} {sound:?} {value:#08x}");
}
InputEventKind::ForceFeedback(ff) => {
println!("forcefeedback {ff}");
}
InputEventKind::ForceFeedbackStatus(ff) => {
println!("forcefeedback status {ff}");
}
InputEventKind::UInput(u) => {
println!("uinput {u}");
}
InputEventKind::Other => {
println!("other");
}
}
println!("{ev:?}");
}
}
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => (),
Expand Down
6 changes: 3 additions & 3 deletions src/rcdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! controller is either an infrared receiver/transmitter or a cec interface.
use crate::rc_maps::KeymapTable;
use evdev::{Device, Key};
use evdev::{Device, KeyCode};
use itertools::Itertools;
use std::{
fs::{self, OpenOptions},
Expand Down Expand Up @@ -192,7 +192,7 @@ impl Rcdev {

let inputdev = self.input_chdev.as_ref().unwrap();
loop {
match inputdev.update_scancode_by_index(0, Key::KEY_RESERVED, &[]) {
match inputdev.update_scancode_by_index(0, KeyCode::KEY_RESERVED, &[]) {
Ok(_) => (),
Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => break,
Err(e) => {
Expand All @@ -205,7 +205,7 @@ impl Rcdev {
}

/// Add a single scancode mapping
pub fn update_scancode(&mut self, key: Key, scancode: u64) -> Result<(), std::io::Error> {
pub fn update_scancode(&mut self, key: KeyCode, scancode: u64) -> Result<(), std::io::Error> {
self.open_input()?;

// Kernels from before v5.7 want the scancode in 4 bytes; try this if possible
Expand Down

0 comments on commit 627c1d7

Please sign in to comment.