-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge wljoywake branch adding functionality akin to the wljoywake branch handling idle_inhibition on joystick input https://github.com/nowrep/wljoywake
- Loading branch information
Showing
8 changed files
with
494 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub const APP_NAME: &str = "sleepwatcher-rs"; | ||
pub const CONFIG_FILE_NAME: &str = "idle_config.lua"; | ||
pub const CONFIG_FILE: &str = include_str!("../lua_configs/idle_config.lua"); | ||
pub const TIMEOUT_SEC: u64 = 30; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use evdev::{Device, InputEventKind}; | ||
use log::{debug, info}; | ||
use std::path::Path; | ||
use tokio::sync::mpsc; | ||
|
||
use crate::types::Request; | ||
|
||
#[derive(Debug)] | ||
pub struct JoystickHandler { | ||
syspath: String, | ||
tx: mpsc::Sender<Request>, | ||
} | ||
|
||
impl JoystickHandler { | ||
pub fn new(syspath: String, tx: mpsc::Sender<Request>) -> Self { | ||
Self { syspath, tx } | ||
} | ||
|
||
pub async fn js_handler(&self) -> anyhow::Result<()> { | ||
let device_path = Path::new("/dev/input").join(&self.syspath); | ||
let device = Device::open(device_path)?; | ||
//let absinfo = device.get_abs_state(); | ||
let mut event_stream = device.into_event_stream()?; | ||
|
||
loop { | ||
tokio::select! { | ||
ev = event_stream.next_event() => { | ||
match ev { | ||
Ok(ev) => { | ||
match ev.kind() { | ||
InputEventKind::Key(key) => { | ||
debug!("Key event: {:?}, value: {}", key, ev.value()); | ||
self.tx.send(Request::Inhibit).await.unwrap(); | ||
} | ||
// Ignore axis and synchronization events for now. For Axis events | ||
// it's not currently clear how to get absinfo | ||
InputEventKind::AbsAxis(..) => { | ||
} | ||
InputEventKind::Synchronization(..) => {} | ||
_ => { | ||
debug!("Other event: {:?}", ev); | ||
} | ||
} | ||
} | ||
Err(e) => { | ||
info!("Error reading event: {:?}", e); | ||
break Ok(()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.