Skip to content

Commit 3f89c53

Browse files
committed
power: Add function to get ALS data
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 2e30627 commit 3f89c53

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

framework_lib/src/power.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,13 @@ pub fn print_memmap_version_info(ec: &CrosEc) {
191191
let _events_ver = ec.read_memory(EC_MEMMAP_EVENTS_VERSION, 2).unwrap();
192192
}
193193

194-
pub fn print_sensors(ec: &CrosEc) {
195-
let als = ec.read_memory(EC_MEMMAP_ALS, 0x04).unwrap();
194+
pub fn get_als_reading(ec: &CrosEc) -> Option<u32> {
195+
let als = ec.read_memory(EC_MEMMAP_ALS, 0x04)?;
196+
Some(u32::from_le_bytes([als[0], als[1], als[2], als[3]]))
197+
}
196198

197-
let als_int = u32::from_le_bytes([als[0], als[1], als[2], als[3]]);
199+
pub fn print_sensors(ec: &CrosEc) {
200+
let als_int = get_als_reading(ec).unwrap();
198201
println!("ALS: {:>4} Lux", als_int);
199202
}
200203

0 commit comments

Comments
 (0)