MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / print_sensors

Function print_sensors

framework_lib/src/power.rs:282–353  ·  view source on GitHub ↗
(ec: &CrosEc)

Source from the content-addressed store, hash-verified

280}
281
282pub fn print_sensors(ec: &CrosEc) {
283 let mut has_als = false;
284 let mut accel_locations = vec![];
285
286 match ec.motionsense_sensor_info() {
287 Ok(sensors) => {
288 info!("Sensors: {}", sensors.len());
289 for sensor in sensors {
290 info!(" Type: {:?}", sensor.sensor_type);
291 info!(" Location: {:?}", sensor.location);
292 info!(" Chip: {:?}", sensor.chip);
293 if sensor.sensor_type == MotionSenseType::Light {
294 has_als = true;
295 }
296 if sensor.sensor_type == MotionSenseType::Accel {
297 accel_locations.push(sensor.location);
298 }
299 }
300 }
301 Err(EcError::Response(EcResponseStatus::InvalidCommand)) => {
302 debug!("Motionsense commands not supported")
303 }
304 err => _ = print_err(err),
305 }
306
307 // If we can't detect it based on motionsense, check the system family
308 // If family is unknown, assume it has
309 let als_family = matches!(
310 smbios::get_family(),
311 Some(PlatformFamily::Framework13) | Some(PlatformFamily::Framework16) | None
312 );
313
314 if has_als || als_family {
315 let als_int = get_als_reading(ec, 0).unwrap();
316 println!("ALS: {:>4} Lux", als_int);
317 }
318
319 // bit 4 = busy
320 // bit 7 = present
321 // #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
322 let acc_status = ec.read_memory(EC_MEMMAP_ACC_STATUS, 0x01).unwrap()[0];
323 // While busy, keep reading
324
325 let lid_angle = ec.read_memory(EC_MEMMAP_ACC_DATA, 0x02).unwrap();
326 let lid_angle = u16::from_le_bytes([lid_angle[0], lid_angle[1]]);
327 let accel_1 = ec.read_memory(EC_MEMMAP_ACC_DATA + 2, 0x06).unwrap();
328 let accel_2 = ec.read_memory(EC_MEMMAP_ACC_DATA + 8, 0x06).unwrap();
329
330 let present = (acc_status & 0x80) > 0;
331 if present {
332 println!("Accelerometers:");
333 debug!(" Status Bit: {} 0x{:X}", acc_status, acc_status);
334 debug!(" Present: {}", present);
335 debug!(" Busy: {}", (acc_status & 0x8) > 0);
336 print!(" Lid Angle: ");
337 if lid_angle == LID_ANGLE_UNRELIABLE {
338 println!("Unreliable");
339 } else {

Callers 1

run_with_argsFunction · 0.85

Calls 4

print_errFunction · 0.85
get_als_readingFunction · 0.85
read_memoryMethod · 0.80

Tested by

no test coverage detected