1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use driver::Driver;
use driver::Attribute;
use driver::AttributeResult;
use std::fs;
pub struct PowerSupply {
driver: Driver
}
impl PowerSupply {
pub fn new() -> Option<PowerSupply> {
let paths = fs::read_dir("/sys/class/power_supply").unwrap();
for path in paths {
let file_name = path.unwrap().file_name();
let name = String::from(file_name.to_str().unwrap());
if name.contains("ev3-battery") {
return Some(PowerSupply {
driver: Driver::new(String::from("power_supply"), name)
});
}
}
None
}
fn get_attribute(&mut self, name: &str) -> &Attribute {
self.driver.get_attribute(name)
}
pub fn get_current_now(&mut self) -> AttributeResult<isize> {
self.get_attribute("current_now").get_int()
}
pub fn get_scope(&mut self) -> AttributeResult<String> {
self.get_attribute("scope").get_str()
}
pub fn get_technology(&mut self) -> AttributeResult<String> {
self.get_attribute("technology").get_str()
}
pub fn get_type(&mut self) -> AttributeResult<String> {
self.get_attribute("type").get_str()
}
pub fn get_voltage_max_design(&mut self) -> AttributeResult<isize> {
self.get_attribute("voltage_max_design").get_int()
}
pub fn get_voltage_min_design(&mut self) -> AttributeResult<isize> {
self.get_attribute("voltage_min_design").get_int()
}
pub fn get_voltage_now(&mut self) -> AttributeResult<isize> {
self.get_attribute("voltage_now").get_int()
}
}