Skip to content

Commit

Permalink
Add support for the rM2 battery
Browse files Browse the repository at this point in the history
This was not tested. Though by viewing the file
tree of /sys provided by @torwag
(Eeems-Org/oxide#48 (comment)
file tree.txt line 3166) it seems that all
methods are supported.
  • Loading branch information
LinusCDE authored and canselcik committed Dec 25, 2020
1 parent 67d7ed6 commit 075c050
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/battery.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
use crate::device::CURRENT_DEVICE;
use std::fs::File;
use std::io::Read;

// TODO: Implement API to allow callbacks backed via uevent / inotify

// File tree containing the rM2 battery:
// https://github.com/Eeems/oxide/issues/48#issue-698181952 (line 3166 of tree.txt)

fn read_attribute(attr: &str) -> Result<String, String> {
let mut data = String::new();
match File::open(format!("/sys/class/power_supply/bq27441-0/{0}", attr)) {
match File::open(format!(
"/sys/class/power_supply/{0}/{1}",
CURRENT_DEVICE.get_internal_battery_name(),
attr
)) {
Err(e) => Err(format!("Unable to open file: {0}", e)),
Ok(ref mut f) => match f.read_to_string(&mut data).unwrap_or(0) {
0 => Err("Unable to read file".to_owned()),
Expand Down
9 changes: 9 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ impl Device {
invert_y: false,
}
}

/// Name of the battery as found in /sys/class/power_supply
pub fn get_internal_battery_name(&self) -> &str {
match self.model {
Model::Gen1 => "bq27441-0",
Model::Gen2 => "max77818_battery",
Model::Unknown => unreachable!(),
}
}
}

0 comments on commit 075c050

Please sign in to comment.