Progress with touchpad workaround rewrite

main
John Jekel 1 year ago
parent 737534ee5b
commit 77935c9ee8
  1. 9
      Cargo.lock
  2. 1
      Cargo.toml
  3. 39
      src/touchpad_workaround.rs

9
Cargo.lock generated

@ -2,6 +2,15 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "libc"
version = "0.2.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
[[package]]
name = "rust-14ARE15-fixes"
version = "0.1.0"
dependencies = [
"libc",
]

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc = "0.2"
[[bin]]
name = "touchpad-workaround"

@ -11,7 +11,11 @@
/* Constants */
//TODO
const TOUCHPAD_I2C_STR: &'static str = "i2c-MSFT0001:00\n";
const NUM_MINOR_LOOP_TRIES: usize = 100;
const NUM_MAJOR_LOOP_TRIES: usize = 10;
const MINOR_LOOP_DELAY_MS: usize = 0;
const MAJOR_DELAYS_MS: usize = 0;
/* Macros */
@ -32,5 +36,38 @@
/* Functions */
fn main() {
//Check if we're root
if !is_root() {
eprintln!("touchpad_workaround requires root privileges to function");
return;
} else {
print(5, "touchpad_workaround: Started");
}
//Attempt to fix the touchpad
for i in 0..NUM_MAJOR_LOOP_TRIES {
print(6, format!("touchpad_workaround: attempt {}", i + 1));
if attempt() {
print(5, format!("touchpad_workaround: attempt {} successful", i + 1));
return;
} else {
print(3, format!("touchpad_workaround: attempt {} failed", i + 1));
}
}
//If we get here, we failed
print(3, format!("touchpad_workaround: giving up after {} attempts", NUM_MAJOR_LOOP_TRIES));
}
fn is_root() -> bool {
return unsafe { libc::getuid() } == 0;
}
fn print(severity: u8, string: impl AsRef<str>) {
eprintln!("{}", string.as_ref());
assert!(matches!(std::fs::write("/dev/kmsg", format!("<{}>{}", severity, string.as_ref())), Ok(())));
}
fn attempt() -> bool {
todo!();
}

Loading…
Cancel
Save