• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //! Power monitoring abstraction layer.
6 
7 use std::error::Error;
8 
9 use base::ReadNotifier;
10 
11 pub trait PowerMonitor: ReadNotifier {
read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>12     fn read_message(&mut self) -> std::result::Result<Option<PowerData>, Box<dyn Error>>;
13 }
14 
15 pub struct PowerData {
16     pub ac_online: bool,
17     pub battery: Option<BatteryData>,
18 }
19 
20 pub struct BatteryData {
21     pub status: BatteryStatus,
22     pub percent: u32,
23     /// Battery voltage in microvolts.
24     pub voltage: u32,
25     /// Battery current in microamps.
26     pub current: u32,
27     /// Battery charge counter in microampere hours.
28     pub charge_counter: u32,
29     /// Battery full charge counter in microampere hours.
30     pub charge_full: u32,
31 }
32 
33 pub enum BatteryStatus {
34     Unknown,
35     Charging,
36     Discharging,
37     NotCharging,
38 }
39 
40 pub trait CreatePowerMonitorFn:
41     Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
42 {
43 }
44 
45 impl<T> CreatePowerMonitorFn for T where
46     T: Send + Fn() -> std::result::Result<Box<dyn PowerMonitor>, Box<dyn Error>>
47 {
48 }
49 
50 #[cfg(feature = "powerd")]
51 pub mod powerd;
52 
53 mod protos {
54     // ANDROID: b/259142784 - we remove protos subdir b/c cargo2android
55     include!(concat!(env!("OUT_DIR"), "/generated.rs"));
56 }
57