Add barebones config for haptic length
This commit is contained in:
parent
d3ad2cf239
commit
10a70ff352
1 changed files with 18 additions and 4 deletions
22
src/main.rs
22
src/main.rs
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{path::{Path, PathBuf}, fs::{File, OpenOptions}, process::exit};
|
use std::{path::{Path}, fs::{File, OpenOptions}};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
@ -11,13 +11,27 @@ const HAPTIC_PATH: &str = "/sys/class/timed_output/vibrator/enable";
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// vibration duration in milliseconds
|
/// vibration duration in milliseconds
|
||||||
#[arg(short, long, default_value_t = 50)]
|
#[arg(short, long, default_value_t = String::from("/etc/kb-haptic-length"))]
|
||||||
length: usize,
|
config_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Args::parse();
|
let cli = Args::parse();
|
||||||
|
|
||||||
|
let haptic_length: String = {
|
||||||
|
let mut str = String::new();
|
||||||
|
|
||||||
|
match File::open(&Path::new(&cli.config_path)) {
|
||||||
|
Ok(mut f) => match f.read_to_string(&mut str) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => { str.push_str("50"); }
|
||||||
|
}
|
||||||
|
_ => { str.push_str("50"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
str
|
||||||
|
};
|
||||||
|
|
||||||
let mut haptic = OpenOptions::new()
|
let mut haptic = OpenOptions::new()
|
||||||
.append(true)
|
.append(true)
|
||||||
.open(HAPTIC_PATH)
|
.open(HAPTIC_PATH)
|
||||||
|
|
@ -39,7 +53,7 @@ fn main() {
|
||||||
loop {
|
loop {
|
||||||
for event in device.fetch_events().unwrap() {
|
for event in device.fetch_events().unwrap() {
|
||||||
if let EventSummary::Key(_, _, 1) = event.destructure() {
|
if let EventSummary::Key(_, _, 1) = event.destructure() {
|
||||||
match write!(haptic, "{}", cli.length) {
|
match write!(haptic, "{}", haptic_length) {
|
||||||
Err(_) => println!("Unable to write to haptics!"),
|
Err(_) => println!("Unable to write to haptics!"),
|
||||||
_ => ()
|
_ => ()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue