Add automatic thread execution.

This commit is contained in:
Eduard Tolosa 2019-03-30 08:57:15 -05:00
parent f2aad1e50d
commit bbf536fd6d
4 changed files with 44 additions and 8 deletions

21
Cargo.lock generated
View file

@ -1,4 +1,23 @@
[[package]]
name = "lazy_static"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "powerman"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"schedule_recv 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "schedule_recv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum schedule_recv 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca1520cf9d3182329ceb57b9a6b37eb68fe94f5d46c0be4aa2d2a522ec3d40eb"

View file

@ -1,7 +1,8 @@
[package]
name = "powerman"
version = "0.1.1"
version = "0.1.2"
authors = ["Eduard Toloza <tolosaeduard@gmail.com>"]
edition = "2018"
[dependencies]
schedule_recv = "0.1.0"

Binary file not shown.

View file

@ -3,6 +3,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use std::process::Command;
extern crate schedule_recv;
fn main() {
// Get user arguments, first argument is the level of battery
@ -12,18 +13,33 @@ fn main() {
// pass the following aguments: 5 hibernate
let args: Vec<String> = env::args().collect();
if args.len() == 3 {
// Convert user agument into integer
if args.len() == 4 {
let bat_discharging_action: u32 = args[1]
.trim()
.parse()
.expect("Error, battery percentage capacity can not be converted in a valid number.");
battery_critical_action(bat_discharging_action, &args[2]);
// Convert user agument into integer
let execution_time: u32 = args[2]
.trim()
.parse()
.expect("Error, execution time argument can not be converted in a valid number.");
// Execution time need to be miliseconds
let execution_time = execution_time * 1000;
let tick = schedule_recv::periodic_ms(execution_time);
loop {
tick.recv().unwrap();
battery_critical_action(bat_discharging_action, &args[3]);
}
} else {
println!("Usage:
powerman <Minimun level of battery before ation>, <Action>
Example: powerman 5 hibernate <- hibernate the computer when the battery level is less than 5%.
You need to enable powerman.timer unit.")
powerman <Minimun level of battery before ation> <Time in seconds to check the battery level> <Action>
Example:
powerman 5 60 hibernate
- Hibernate the computer when the battery level is less than 5%, the check is done every 60 seconds.
")
}
}