From 3f89c53aa8df07868196c336976d9791e66a9f3d Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 21 Oct 2024 13:35:54 +0800 Subject: [PATCH] power: Add function to get ALS data Signed-off-by: Daniel Schaefer --- framework_lib/src/power.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/framework_lib/src/power.rs b/framework_lib/src/power.rs index 47b56c2..2a35733 100644 --- a/framework_lib/src/power.rs +++ b/framework_lib/src/power.rs @@ -191,10 +191,13 @@ pub fn print_memmap_version_info(ec: &CrosEc) { let _events_ver = ec.read_memory(EC_MEMMAP_EVENTS_VERSION, 2).unwrap(); } -pub fn print_sensors(ec: &CrosEc) { - let als = ec.read_memory(EC_MEMMAP_ALS, 0x04).unwrap(); +pub fn get_als_reading(ec: &CrosEc) -> Option { + let als = ec.read_memory(EC_MEMMAP_ALS, 0x04)?; + Some(u32::from_le_bytes([als[0], als[1], als[2], als[3]])) +} - let als_int = u32::from_le_bytes([als[0], als[1], als[2], als[3]]); +pub fn print_sensors(ec: &CrosEc) { + let als_int = get_als_reading(ec).unwrap(); println!("ALS: {:>4} Lux", als_int); }