summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorClementTsang <clementjhtsang@gmail.com>2019-09-07 22:30:15 -0400
committerClementTsang <clementjhtsang@gmail.com>2019-09-07 22:30:15 -0400
commitac85c42ce909a1561d1e88a532997133532cbd0c (patch)
tree794e8bc1041ff9b4a5e13c19d816191d0985d1d6 /src/widgets
parent521698a2bd43e597d82318538d35612520a42802 (diff)
Added temperature support for data polling.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/network.rs14
-rw-r--r--src/widgets/processes.rs13
-rw-r--r--src/widgets/temperature.rs58
3 files changed, 74 insertions, 11 deletions
diff --git a/src/widgets/network.rs b/src/widgets/network.rs
index 1f35ca7f..6b9c54a9 100644
--- a/src/widgets/network.rs
+++ b/src/widgets/network.rs
@@ -1,3 +1,13 @@
-fn get_timestamped_network_data() {}
+pub struct TimedNetworkData {
+ pub rx : u32,
+ pub tx : u32,
+ pub time : std::time::SystemTime,
+}
-fn get_network_data_list() {}
+pub fn get_network_data() -> TimedNetworkData {
+ TimedNetworkData {
+ rx : 0,
+ tx : 0,
+ time : std::time::SystemTime::now(),
+ }
+}
diff --git a/src/widgets/processes.rs b/src/widgets/processes.rs
index 5d3946b5..e3c1aecf 100644
--- a/src/widgets/processes.rs
+++ b/src/widgets/processes.rs
@@ -14,8 +14,8 @@ pub enum ProcessSorting {
#[derive(Debug)]
pub struct ProcessInfo {
pub pid : u32,
- pub cpu_usage : f32,
- pub mem_usage : u64,
+ pub cpu_usage_percent : f32,
+ pub mem_usage_in_mb : u64,
pub command : String,
}
@@ -52,7 +52,6 @@ async fn cpu_usage(process : heim::process::Process) -> heim::process::ProcessRe
pub async fn get_sorted_processes_list(sorting_method : ProcessSorting, reverse_order : bool) -> Vec<ProcessInfo> {
let mut process_stream = heim::process::processes().map_ok(cpu_usage).try_buffer_unordered(std::usize::MAX);
- // TODO: Evaluate whether this is too slow!
// TODO: Group together processes
let mut process_vector : Vec<ProcessInfo> = Vec::new();
@@ -64,15 +63,15 @@ pub async fn get_sorted_processes_list(sorting_method : ProcessSorting, reverse_
process_vector.push(ProcessInfo {
command : process.name().await.unwrap_or_else(|_| "".to_string()),
pid : process.pid() as u32,
- cpu_usage : cpu_usage.get::<units::ratio::percent>(),
- mem_usage : mem_measurement.rss().get::<units::information::megabyte>(),
+ cpu_usage_percent : cpu_usage.get::<units::ratio::percent>(),
+ mem_usage_in_mb : mem_measurement.rss().get::<units::information::megabyte>(),
});
}
}
}
match sorting_method {
- ProcessSorting::CPU => process_vector.sort_by(|a, b| get_ordering(a.cpu_usage, b.cpu_usage, reverse_order)),
- ProcessSorting::MEM => process_vector.sort_by(|a, b| get_ordering(a.mem_usage, b.mem_usage, reverse_order)),
+ ProcessSorting::CPU => process_vector.sort_by(|a, b| get_ordering(a.cpu_usage_percent, b.cpu_usage_percent, reverse_order)),
+ ProcessSorting::MEM => process_vector.sort_by(|a, b| get_ordering(a.mem_usage_in_mb, b.mem_usage_in_mb, reverse_order)),
ProcessSorting::PID => process_vector.sort_by(|a, b| get_ordering(a.pid, b.pid, reverse_order)),
ProcessSorting::NAME => process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, reverse_order)),
}
diff --git a/src/widgets/temperature.rs b/src/widgets/temperature.rs
index 2617bab9..d18a7c01 100644
--- a/src/widgets/temperature.rs
+++ b/src/widgets/temperature.rs
@@ -1,3 +1,57 @@
-fn get_timestamped_temperature() {}
+use heim_common::{prelude::StreamExt, units::thermodynamic_temperature};
-fn get_temps_list() {}
+pub struct TempData {
+ pub component_name : Box<str>,
+ pub temperature : f32,
+}
+
+pub struct TimedTempData {
+ pub temperature_vec : Vec<TempData>,
+ pub time : std::time::SystemTime,
+}
+
+pub async fn get_temperature_data() -> Result<TimedTempData, heim::Error> {
+ let mut temperature_vec : Vec<TempData> = Vec::new();
+
+ let mut sensor_data = heim::sensors::temperatures();
+ while let Some(sensor) = sensor_data.next().await {
+ if let Ok(sensor) = sensor {
+ temperature_vec.push(TempData {
+ component_name : Box::from(sensor.unit()),
+ temperature : sensor.current().get::<thermodynamic_temperature::degree_celsius>(),
+ });
+ }
+ }
+
+ // By default, sort temperature, then by alphabetically! Allow for configuring this...
+
+ // Note we sort in reverse here; we want greater temps to be higher priority.
+ temperature_vec.sort_by(|a, b| {
+ if a.temperature > b.temperature {
+ std::cmp::Ordering::Less
+ }
+ else if a.temperature < b.temperature {
+ std::cmp::Ordering::Greater
+ }
+ else {
+ std::cmp::Ordering::Equal
+ }
+ });
+
+ temperature_vec.sort_by(|a, b| {
+ if a.component_name > b.component_name {
+ std::cmp::Ordering::Greater
+ }
+ else if a.component_name < b.component_name {
+ std::cmp::Ordering::Less
+ }
+ else {
+ std::cmp::Ordering::Equal
+ }
+ });
+
+ Ok(TimedTempData {
+ temperature_vec,
+ time : std::time::SystemTime::now(),
+ })
+}