Allow controlling step and minimum value in acpi mode

Also remove the acpi module, it belonged in the binary source code
really since it was using failure::Error.
4 files changed, 41 insertions(+), 37 deletions(-)

R src/acpi.rs => 
M src/bin/brightd.rs
M src/cli.rs
M src/lib.rs
R src/acpi.rs =>  +0 -34
@@ 1,34 0,0 @@ 
-use std::os::unix::net::UnixStream;
-
-use std::io::prelude::*;
-
-use failure;
-use failure::ResultExt;
-
-use crate as bright;
-
-pub fn run(
-    acpi_socket: std::path::PathBuf,
-    dbus_bustype: dbus::BusType,
-    dbus_peer: String,
-) -> failure::Fallible<()> {
-    let client = bright::dbus::Client::new(dbus_bustype, dbus_peer)
-        .context("Failed to create D-Bus client for acpid watcher")?;
-    info!("Listening for ACPI events on {}", acpi_socket.display());
-    let stream = UnixStream::connect(acpi_socket)?;
-    let buffer = std::io::BufReader::new(stream);
-    for bytes in buffer.split('\n' as u8) {
-        let bytes = bytes?;
-        if bytes.starts_with(b"video/brightnessup BRTUP") {
-            for dev in client.devices()?.iter() {
-                client.inc(dev.to_owned(), 5)?;
-            }
-        };
-        if bytes.starts_with(b"video/brightnessdown BRTDN") {
-            for dev in client.devices()?.iter() {
-                client.dec(dev.to_owned(), 5, 1)?;
-            }
-        };
-    }
-    Ok(())
-}

          
M src/bin/brightd.rs +26 -1
@@ 8,6 8,8 @@ extern crate log;
 
 extern crate bright;
 
+use std::io::prelude::*;
+use std::os::unix::net::UnixStream;
 use std::rc::Rc;
 use std::sync::mpsc;
 

          
@@ 55,7 57,24 @@ fn run_acpi_listener(cfg: AppConfig, bus
     let peer = busname_rx
         .recv()
         .context("Peer D-Bus busname receiver died")?;
-    bright::acpi::run(cfg.acpi_socket, cfg.bustype, peer)?;
+    let client = bright::dbus::Client::new(cfg.bustype, peer)
+        .context("Failed to create D-Bus client for acpid watcher")?;
+    info!("Listening for ACPI events on {}", cfg.acpi_socket.display());
+    let stream = UnixStream::connect(cfg.acpi_socket)?;
+    let buffer = std::io::BufReader::new(stream);
+    for bytes in buffer.split('\n' as u8) {
+        let bytes = bytes?;
+        if bytes.starts_with(b"video/brightnessup BRTUP") {
+            for dev in client.devices()?.iter() {
+                client.inc(dev.to_owned(), cfg.acpi_step)?;
+            }
+        };
+        if bytes.starts_with(b"video/brightnessdown BRTDN") {
+            for dev in client.devices()?.iter() {
+                client.dec(dev.to_owned(), cfg.acpi_step, cfg.acpi_min)?;
+            }
+        };
+    }
     Ok(())
 }
 

          
@@ 128,6 147,8 @@ struct AppConfig {
     bustype: dbus::BusType,
     acpi: bool,
     acpi_socket: std::path::PathBuf,
+    acpi_step: u32,
+    acpi_min: u32,
 }
 
 impl AppConfig {

          
@@ 155,10 176,14 @@ impl AppConfig {
             None => panic!("No bus type"),
         };
         let acpi_socket = matches.value_of_os("acpi-socket").unwrap();
+        let acpi_step = matches.value_of("acpi-step").unwrap();
+        let acpi_min = matches.value_of("acpi-min").unwrap();
         Ok(AppConfig {
             bustype: bustype,
             acpi: matches.is_present("acpi"),
             acpi_socket: std::path::PathBuf::from(acpi_socket),
+            acpi_step: acpi_step.trim().parse::<u32>().unwrap(),
+            acpi_min: acpi_min.trim().parse::<u32>().unwrap(),
         })
     }
 }

          
M src/cli.rs +15 -1
@@ 81,7 81,7 @@ only modify one or more devices use the 
 fn is_int(arg: String) -> Result<(), String> {
     match arg.trim().parse::<u32>() {
         Ok(_) => Ok(()),
-        Err(_) => Err(String::from(format!("Not an integer: {}", arg))),
+        Err(_) => Err(String::from(format!("Not a positive integer: {}", arg))),
     }
 }
 

          
@@ 127,4 127,18 @@ modified.",
                 .default_value("/run/acpid.socket")
                 .help("Location of the acpid socket"),
         )
+        .arg(
+            Arg::with_name("acpi-step")
+                .long("acpi-step")
+                .default_value("5")
+                .validator(is_int)
+                .help("Increment/decrement steps for brightness up/down events"),
+        )
+        .arg(
+            Arg::with_name("acpi-min")
+                .long("acpi-min")
+                .default_value("1")
+                .validator(is_int)
+                .help("Minimum value to set with brightness up/down events"),
+        )
 }

          
M src/lib.rs +0 -1
@@ 5,7 5,6 @@ extern crate clap;
 #[macro_use]
 extern crate log;
 
-pub mod acpi;
 pub mod cli;
 pub mod dbus;
 pub mod pond;