From 6035e39c05b6ca3af33c4f41d0f1c0f49360cac5 Mon Sep 17 00:00:00 2001 From: VassiliDev Date: Thu, 12 Aug 2021 19:45:07 -0400 Subject: [PATCH 1/3] Move normalization factor to cli argument --- src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 95d166f..f4a93f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -176,6 +176,12 @@ fn main() -> Result<(), String> { .value_name("THRESHOLD") .help("Set a rotation threshold between 0 and 1") .takes_value(true), + Arg::with_name("normalization-factor") + .default_value("6") + .long("normalization-factor") + .value_name("NORMALIZATION_FACTOR") + .help("Set factor for sensor value normalization") + .takes_value(true), ]; match backend { @@ -203,6 +209,11 @@ fn main() -> Result<(), String> { let old_state_owned = get_window_server_rotation_state(display, &backend)?; let mut old_state = old_state_owned.as_str(); + let normalization_factor = matches + .value_of("normalization-factor") + .unwrap_or("default.conf"); + let normalization_factor = normalization_factor.parse::().unwrap_or(1e6); + let keyboards = get_keyboards(&backend)?; for entry in glob("/sys/bus/iio/devices/iio:device*/in_accel_*_raw").unwrap() { @@ -258,8 +269,8 @@ fn main() -> Result<(), String> { let y_clean = y_raw.trim_end_matches('\n').parse::().unwrap_or(0); // Normalize vectors - let x: f32 = (x_clean as f32) / 1e6; - let y: f32 = (y_clean as f32) / 1e6; + let x: f32 = (x_clean as f32) / normalization_factor; + let y: f32 = (y_clean as f32) / normalization_factor; for (_i, orient) in orientations.iter().enumerate() { let d = (x - orient.vector.0).powf(2.0) + (y - orient.vector.1).powf(2.0); From 6630edfebf2044fc4550520dc856543ffd46a41d Mon Sep 17 00:00:00 2001 From: VassiliDev Date: Tue, 17 Aug 2021 06:34:38 -0400 Subject: [PATCH 2/3] Added short form arg and fixed feault value --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f4a93f3..bc809a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,8 +177,9 @@ fn main() -> Result<(), String> { .help("Set a rotation threshold between 0 and 1") .takes_value(true), Arg::with_name("normalization-factor") - .default_value("6") + .default_value("1e6") .long("normalization-factor") + .short("n") .value_name("NORMALIZATION_FACTOR") .help("Set factor for sensor value normalization") .takes_value(true), From 9e0d2f986f78a25838d5d8c0645b8965f9c27776 Mon Sep 17 00:00:00 2001 From: VassiliDev Date: Tue, 17 Aug 2021 06:36:20 -0400 Subject: [PATCH 3/3] Changed erroneous default.conf default --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index bc809a8..b2f3bfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -210,9 +210,7 @@ fn main() -> Result<(), String> { let old_state_owned = get_window_server_rotation_state(display, &backend)?; let mut old_state = old_state_owned.as_str(); - let normalization_factor = matches - .value_of("normalization-factor") - .unwrap_or("default.conf"); + let normalization_factor = matches.value_of("normalization-factor").unwrap_or("1e6"); let normalization_factor = normalization_factor.parse::().unwrap_or(1e6); let keyboards = get_keyboards(&backend)?;