Skip to content

Commit e7e623c

Browse files
committed
--thermal: log in csv format
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent ca1f347 commit e7e623c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

framework_lib/src/power.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ enum TempSensor {
8484
NotPowered,
8585
NotCalibrated,
8686
}
87+
impl From<&u8> for TempSensor {
88+
fn from(t: &u8) -> Self {
89+
TempSensor::from(*t)
90+
}
91+
}
8792
impl From<u8> for TempSensor {
8893
fn from(t: u8) -> Self {
8994
match t {
@@ -353,6 +358,38 @@ pub fn print_sensors(ec: &CrosEc) {
353358
}
354359

355360
pub fn print_thermal(ec: &CrosEc) {
361+
println!("timestamp, fan0,fan1,temp0,temp1,temp2,temp3,temp4,temp5,temp6,temp7,");
362+
loop {
363+
let temps = ec.read_memory(EC_MEMMAP_TEMP_SENSOR, 0x0F).unwrap();
364+
let fans = ec.read_memory(EC_MEMMAP_FAN, 0x08).unwrap();
365+
let now = std::time::SystemTime::now();
366+
let timestamp = now.duration_since(std::time::SystemTime::UNIX_EPOCH);
367+
368+
print!("{},", timestamp.unwrap().as_secs());
369+
370+
for i in 0..2 {
371+
let fan = u16::from_le_bytes([fans[i * 2], fans[1 + i * 2]]);
372+
if fan == EC_FAN_SPEED_STALLED_DEPRECATED || fan == EC_FAN_SPEED_NOT_PRESENT {
373+
print!(" ,");
374+
} else {
375+
print!("{:>4},", fan);
376+
}
377+
}
378+
379+
for temp in temps.iter().take(8) {
380+
if let TempSensor::Ok(c) = TempSensor::from(temp) {
381+
print!(" {:>4?},", c);
382+
} else {
383+
print!(" ,");
384+
}
385+
}
386+
println!();
387+
388+
crate::os_specific::sleep(1000_000)
389+
}
390+
}
391+
392+
pub fn foo_thermal(ec: &CrosEc) {
356393
let temps = ec.read_memory(EC_MEMMAP_TEMP_SENSOR, 0x0F).unwrap();
357394
let fans = ec.read_memory(EC_MEMMAP_FAN, 0x08).unwrap();
358395

0 commit comments

Comments
 (0)