use std::fs::File; use std::io::SeekFrom; use std::io::prelude::*; use super::Sensor; pub struct TempSensor { file: File, temp: Option } impl TempSensor { pub fn new(zone: &str) -> TempSensor { let path = format!("/sys/class/thermal/{}/temp", zone); TempSensor { file: File::open(path).unwrap(), temp: None } } } impl Sensor for TempSensor { fn icon(&self) -> String { "".to_string() } fn status(&self) -> String { match self.temp { Some(i) => format!("{}°C", i/1000), None => "?°C".to_string(), } } fn process(&mut self) { let mut s = String::new(); self.file.read_to_string(&mut s).ok().expect("Could not read temperature stats"); let i : Option = s.trim().parse().ok(); self.file.seek(SeekFrom::Start(0)).ok().expect("Could not reread temperature"); self.temp = i; } }