Compare commits
No commits in common. "c040555f01cf1988c1153ae790d2dfa9e20679e1" and "4f0ad04376fb6a3f4003be7064d1af4ba6374ef1" have entirely different histories.
c040555f01
...
4f0ad04376
45
.vscode/launch.json
vendored
Normal file
45
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug executable 'rustbook'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"build",
|
||||
"--bin=rustbook",
|
||||
"--package=rustbook"
|
||||
],
|
||||
"filter": {
|
||||
"name": "rustbook",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug unit tests in executable 'rustbook'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--bin=rustbook",
|
||||
"--package=rustbook"
|
||||
],
|
||||
"filter": {
|
||||
"name": "rustbook",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
57
.vscode/tasks.json
vendored
Normal file
57
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Cargo build (debug)",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": ["build"],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Cargo build (release)",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": ["build", "--release"],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Cargo clean",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": ["clean"],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Cargo doc",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": ["doc"],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "rustbook"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
linux_battery = { git = "https://git.blackfinn.de/rust/linux_battery.git" }
|
16
README.md
16
README.md
@ -1,3 +1,17 @@
|
||||
# batman
|
||||
|
||||
Simple linux battery monitor
|
||||
Simple linux battery monitor.
|
||||
|
||||
## Build
|
||||
|
||||
### debug
|
||||
|
||||
```shell
|
||||
cargo build
|
||||
```
|
||||
|
||||
### release
|
||||
|
||||
```shell
|
||||
cargo build --release
|
||||
```
|
||||
|
3
batman.log
Normal file
3
batman.log
Normal file
@ -0,0 +1,3 @@
|
||||
1624598988 Unknown 98 %
|
||||
1624598990 Unknown 98 %
|
||||
1624598992 Unknown 98 %
|
32
src/main.rs
Normal file
32
src/main.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use linux_battery::Battery;
|
||||
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use std::thread::sleep;
|
||||
|
||||
fn main() {
|
||||
let mut battery = Battery::new("BAT0");
|
||||
let mut log_file = OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open("batman.log")
|
||||
.expect("can't open log file");
|
||||
|
||||
loop {
|
||||
let sys_time = SystemTime::now();
|
||||
match sys_time.duration_since(SystemTime::UNIX_EPOCH) {
|
||||
Ok(n) => {
|
||||
let mut log_entry = format!("{}\t{}", n.as_secs(), battery.state());
|
||||
match battery.capacity() {
|
||||
Some(cap) => log_entry = format!("{}\t{} %", log_entry, cap),
|
||||
None => {},
|
||||
}
|
||||
log_entry = format!("{}\r\n", log_entry);
|
||||
log_file.write_all(log_entry.as_bytes()).expect("write to file failed");
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
sleep(Duration::new(2, 0));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user