forked from svartalf/rust-battery
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: NetBSD support with envsys ioctl and plist (#69)
* NetBSD support with envsys ioctl and plist New examples, simple.rs only refreshed the first battery, and this does not help checking for iterator validity for development, all.rs solves the problem. The example oneshot.rs is just for comfort avoiding loop. NetBSD exposes battery information through one ioctl so for now we have to "waste" resource getting all sensors info for each single battery refresh. We can't assume the library user will want to refresh all bateries at the same time even if 90% of time it will probably be. The result of the ioctl is a plist (apple format) that needs to be parsed and accessed. The plist library only uses options, so this is the reason for utils.rs. These are all oneline functions to reduce the lenght of chains in the netbsd platform device.rs file. NetBSD does not expose battery vendor, model, technology, cycle among other things for now, but these are optional. Got inspiration from the FreeBSD port regarding having a better understanding on how the library works. Thanks to unitedbsd.com community for the guidance, and shout out to https://github.com/distatus/battery/blob/master/battery_netbsd.go as well as the NetBSD devs for the great man pages and the clear code allowing to read what happens for undocumented things. * Correcting rustfmt formatting on netbsd/device.rs * Maybe crossbuild only as on FreeBSD ? (Already tried manually on Linux and it works) * Revert "Maybe crossbuild only as on FreeBSD ? (Already tried manually on Linux and it works)" Well the naive approach did not work This reverts commit 693c882. * Trying CICD regarding cross-rs * Installing some prerequisites for NetBSD CI * Correct path for libexecinfo.so in NetBSD CICD * Clippy fixes for NetBSD platform * Update src/platform/netbsd/iterator.rs Remove default Co-authored-by: David Knaack <[email protected]> * Update Cross.toml Co-authored-by: David Knaack <[email protected]> * We support acpibat only in the end, but now we relyin on NetBSD kernel enum to ensure the data is correct even if someonechange envsys description fields. Extending the code for other battery driver is possible * Updated the branch Cargo.toml to match updated version --------- Co-authored-by: David Knaack <[email protected]>
- Loading branch information
Showing
15 changed files
with
639 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extern crate starship_battery as battery; | ||
|
||
use std::thread; | ||
use std::time::Duration; | ||
use std::vec::Vec; | ||
|
||
use battery::Battery; | ||
|
||
fn main() -> battery::Result<()> { | ||
let manager = battery::Manager::new()?; | ||
let mut vc: Vec<Battery> = Vec::<Battery>::new(); | ||
|
||
let iter = manager.batteries()?; | ||
|
||
for bat in iter { | ||
vc.push(match bat { | ||
Ok(battery) => battery, | ||
Err(e) => { | ||
eprintln!("Unable to access battery information"); | ||
return Err(e); | ||
} | ||
}) | ||
} | ||
|
||
loop { | ||
for bat in &mut vc { | ||
println!("{:?}", bat); | ||
thread::sleep(Duration::from_secs(1)); | ||
manager.refresh(bat)?; | ||
} | ||
println!("Back to the beginning") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extern crate starship_battery as battery; | ||
|
||
use std::io; | ||
|
||
fn main() -> battery::Result<()> { | ||
let manager = battery::Manager::new()?; | ||
let battery = match manager.batteries()?.next() { | ||
Some(Ok(battery)) => battery, | ||
Some(Err(e)) => { | ||
eprintln!("Unable to access battery information"); | ||
return Err(e); | ||
} | ||
None => { | ||
eprintln!("Unable to find any batteries"); | ||
return Err(io::Error::from(io::ErrorKind::NotFound).into()); | ||
} | ||
}; | ||
|
||
println!("{:?}", battery); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.