-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"not charging" battery status #177
Comments
I saw this issue, and I had a similar thought about a battery crate a while ago (svartalf/rust-battery#100). Turns out on linux, the file to read the battery state from will have "not_charging" if the battery is plugged in but not charging. I think it would be easy for the linux module of libmacchina, since we would only have to add a branch to the match statement for the battery status, but each OS battery status function would need to have a different implementation of the "not charging" status were to show on every supported OS. i.e it will be a bit tricky on windows: fn status(&self) -> Result<BatteryState, ReadoutError> {
let power_state = WindowsBatteryReadout::get_power_status()?;
match power_state.ACLineStatus {
0 => Ok(BatteryState::Discharging),
1 => Ok(BatteryState::Charging),
a => Err(ReadoutError::Other(format!(
"Unexpected value for ac_line_status from win32 api: {a}"
))),
}
}
...
impl WindowsBatteryReadout {
fn get_power_status() -> Result<SYSTEM_POWER_STATUS, ReadoutError> {
let mut power_state = SYSTEM_POWER_STATUS::default();
if unsafe { GetSystemPowerStatus(&mut power_state) }.as_bool() {
return Ok(power_state);
}
Err(ReadoutError::Other(String::from(
"Call to GetSystemPowerStatus failed.",
)))
}
} I was thinking we could try reading from the I’d love to hear any thoughts or suggestions on this approach, as part of me thinks there is an easier way to do this. |
When the battery is not charging (because plugged in and fully charged) there is no output for the battery.
macchina -d
showsReadout "Battery" failed with message: Got an unexpected value "not charging" reading battery status
which is normal because there is no matching branch for that status in
libmacchina/src/linux/mod.rs -> LinuxBatteryReadout::status
Would be a nice enhancement to have..
but perhaps not possible for all os systems so it was left out intentionally...
The text was updated successfully, but these errors were encountered: