Update energymon dependencies.

Ensure the energymon is enabled before trying to get refresh interval.
This commit is contained in:
Connor Imes 2015-10-28 14:53:47 -05:00
parent 484c0e4546
commit 965fbbd99f
3 changed files with 13 additions and 9 deletions

View file

@ -36,8 +36,8 @@ mod energymon {
static mut EM: Option<*mut EnergyMon> = None;
/// Read energy from the energy monitor, otherwise return 0.
pub fn read_energy_uj() -> u64 {
fn init() {
// can't use lazy_static macro for EM (no Sync trait for EnergyMon)
static ONCE: Once = ONCE_INIT;
ONCE.call_once(|| {
if let Ok(em) = EnergyMon::new() {
@ -47,7 +47,11 @@ mod energymon {
}
}
});
}
/// Read energy from the energy monitor, otherwise return 0.
pub fn read_energy_uj() -> u64 {
init();
unsafe {
// EnergyMon implementations of EnergyMonitor always return a value
EM.map_or(0, |em| (*em).read_uj().unwrap())
@ -55,6 +59,7 @@ mod energymon {
}
pub fn get_min_interval_ms() -> u32 {
init();
unsafe {
EM.map_or(0, |em| ((*em).interval_us() as f64 / 1000.0).ceil() as u32)
}