Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev->Main #15

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub fn run(
.iter()
.any(|gpu| gpu.inner.num_fans().map_or(0, |fc| fc) != 0);

lh.debug(&format!("GPU has fans = {}", have_fans));

loop {
_ = terminal.draw(|f| {
let gpu = &gpu_list[selected_gpu];
Expand All @@ -48,7 +50,10 @@ pub fn run(
.split(f.size());

#[cfg(target_os = "linux")]
f.render_widget(Paragraph::new("q to quit, p to rescan devices"), layout[1]);
f.render_widget(
Paragraph::new("q to quit, p to rescan devices").alignment(Alignment::Right),
layout[1],
);

#[cfg(target_os = "windows")]
f.render_widget(Paragraph::new("q to quit"), layout[1]);
Expand Down Expand Up @@ -148,7 +153,7 @@ pub fn run(
// Fan speed:
if have_fans {
let gauge = draw_fan_speed(gpu);
f.render_widget(gauge, chunks[2]);
f.render_widget(gauge, chunks[2]);
}
}
})?;
Expand All @@ -175,8 +180,12 @@ pub fn run(
pci_sub_system_id: Some(0),
}) {
Ok(()) => {
have_fans = gpu_list
.iter()
.any(|gpu| gpu.inner.num_fans().map_or(0, |fc| fc) != 0);

lh.debug(&format!("GPU has fans = {}", have_fans));
lh.debug("Re-scanned PCI tree");
have_fans = true;
}
Err(e @ (NvmlError::OperatingSystem | NvmlError::NoPermission)) => {
lh.debug(&format!("Failed to re-scan PCI tree: {e}"));
Expand Down Expand Up @@ -205,14 +214,18 @@ pub fn run(
}

fn draw_fan_speed<'d>(gpu: &GpuInfo<'d>) -> Gauge<'d> {
let temps = gpu.inner.num_fans().map_or(0, |fc| fc);
let temps = gpu
.inner
.num_fans()
.expect("This should be impossible as we never call this without having earlier checked.");
let avg = (0..temps as usize)
.flat_map(|v| gpu.inner.fan_speed(v as u32))
.map(|u| u as f64)
.sum::<f64>()
/ temps as f64;

let percentage = (avg / 100.).clamp(0., 1.0);
let percentage = (avg / 100.).clamp(0.0, 1.0);

let label = format!("{:.1}%", avg);
let spanned_label = Span::styled(label, Style::new().white().bold().bg(Color::Black));

Expand Down