feat: further fan curve wip

This commit is contained in:
Ilya Zlobintsev
2023-01-30 20:17:15 +02:00
parent d1399f3c0d
commit 1b57bfefc1
4 changed files with 73 additions and 178 deletions

View File

@@ -1,6 +1,6 @@
use amdgpu_sysfs::hw_mon::Temperature;
use anyhow::anyhow;
use lact_schema::FanCurveMap;
use lact_schema::{default_fan_curve, FanCurveMap};
use serde::{Deserialize, Serialize};
use tracing::warn;
@@ -51,17 +51,7 @@ impl FanCurve {
impl Default for FanCurve {
fn default() -> Self {
Self(
[
(30, 0.0),
(40, 0.2),
(50, 0.35),
(60, 0.5),
(70, 0.75),
(80, 1.0),
]
.into(),
)
Self(default_fan_curve())
}
}

View File

@@ -1,179 +1,51 @@
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::FanCurveMap;
use std::collections::BTreeMap;
use std::cell::RefCell;
use tracing::debug;
#[derive(Clone)]
pub struct FanCurveFrame {
pub container: Frame,
curve: FanCurveMap,
points: RefCell<Vec<Adjustment>>,
}
impl FanCurveFrame {
pub fn new() -> Self {
let container = Frame::new(Some("Fan Curve"));
let root_container = Frame::new(Some("Fan Curve"));
container.set_margin_start(10);
container.set_margin_end(10);
container.set_margin_bottom(10);
container.set_margin_top(10);
root_container.set_margin_start(10);
root_container.set_margin_end(10);
root_container.set_margin_bottom(10);
root_container.set_margin_top(10);
container.set_label_align(0.35, 0.5);
// container.set_shadow_type(ShadowType::None);
//
let root_grid = Grid::new();
// PWM Percentage Labels
{
root_grid.attach(
&{
let label = Label::new(Some("PWM %"));
label.set_angle(90.0);
label.set_vexpand(true); // This expands the entire top section of the grid, including the scales
label
},
0,
0,
1,
5,
);
root_grid.attach(
&{
let label = Label::new(Some("0"));
label.set_angle(90.0);
label
},
1,
4,
1,
1,
);
root_grid.attach(
&{
let label = Label::new(Some("25"));
label.set_angle(90.0);
label
},
1,
3,
1,
1,
);
root_grid.attach(
&{
let label = Label::new(Some("50"));
label.set_angle(90.0);
label
},
1,
2,
1,
1,
);
root_grid.attach(
&{
let label = Label::new(Some("75"));
label.set_angle(90.0);
label
},
1,
1,
1,
1,
);
root_grid.attach(
&{
let label = Label::new(Some("100"));
label.set_angle(90.0);
label
},
1,
0,
1,
1,
);
}
// Temperature threshold labels
{
root_grid.attach(
&{
let label = Label::new(Some("Temperature °C"));
label.set_hexpand(true);
label
},
2,
7,
5,
1,
);
root_grid.attach(&Label::new(Some("20")), 2, 6, 1, 1);
root_grid.attach(&Label::new(Some("40")), 3, 6, 1, 1);
root_grid.attach(&Label::new(Some("60")), 4, 6, 1, 1);
root_grid.attach(&Label::new(Some("80")), 5, 6, 1, 1);
root_grid.attach(&Label::new(Some("100")), 6, 6, 1, 1);
}
// The actual adjustments
let adjustment_1 = Adjustment::new(0.0, 0.0, 100.0, 1.0, 0.0, 0.0); // 20 °C
let adjustment_2 = Adjustment::new(0.0, 0.0, 100.0, 1.0, 0.0, 0.0); // 40 °C
let adjustment_3 = Adjustment::new(0.0, 0.0, 100.0, 1.0, 0.0, 0.0); // 60 °C
let adjustment_4 = Adjustment::new(0.0, 0.0, 100.0, 1.0, 0.0, 0.0); // 80 °C
let adjustment_5 = Adjustment::new(0.0, 0.0, 100.0, 1.0, 0.0, 0.0); // 100 °C
// Scales for the adjustments
{
let adjustments = [
&adjustment_1,
&adjustment_2,
&adjustment_3,
&adjustment_4,
&adjustment_5,
];
for i in 0..adjustments.len() {
let adj = adjustments[i];
root_grid.attach(
&{
let scale = Scale::new(Orientation::Vertical, Some(adj));
scale.set_draw_value(false);
scale.set_inverted(true);
scale
},
i as i32 + 2,
0,
1,
5,
);
}
}
container.add(&root_grid);
let points = RefCell::new(Vec::new());
Self {
container,
adjustment_1,
adjustment_2,
adjustment_3,
adjustment_4,
adjustment_5,
container: root_container,
points,
}
}
pub fn set_curve(&self, curve: &BTreeMap<i64, f64>) {
self.adjustment_1.set_value(*curve.get(&20).unwrap());
self.adjustment_2.set_value(*curve.get(&40).unwrap());
self.adjustment_3.set_value(*curve.get(&60).unwrap());
self.adjustment_4.set_value(*curve.get(&80).unwrap());
self.adjustment_5.set_value(*curve.get(&100).unwrap());
pub fn set_curve(&self, curve: &FanCurveMap) {
let points_container = Box::builder()
.orientation(Orientation::Horizontal)
.spacing(5)
.vexpand(true)
.build();
let mut adjustments = Vec::with_capacity(curve.len());
for (temperature, ratio) in curve {
let adjustment = point_adjustment(&points_container, *ratio, *temperature);
adjustments.push(adjustment);
}
self.points.replace(adjustments);
self.container.set_child(Some(&points_container));
}
pub fn get_curve(&self) -> BTreeMap<i64, f64> {
/*pub fn get_curve(&self) -> BTreeMap<i64, f64> {
let mut curve = BTreeMap::new();
curve.insert(20, self.adjustment_1.value());
@@ -183,7 +55,7 @@ impl FanCurveFrame {
curve.insert(100, self.adjustment_5.value());
curve
}
}*/
pub fn show(&self) {
debug!("Manual fan control enaged, showing fan curve");
@@ -195,7 +67,7 @@ impl FanCurveFrame {
self.container.set_visible(false);
}
pub fn connect_adjusted<F: Fn() + 'static + Clone>(&self, f: F) {
/*pub fn connect_adjusted<F: Fn() + 'static + Clone>(&self, f: F) {
let adjustments = [
&self.adjustment_1,
&self.adjustment_2,
@@ -210,5 +82,25 @@ impl FanCurveFrame {
f();
});
}
}
}*/
}
fn point_adjustment(parent: &Box, ratio: f32, temperature: i32) -> Adjustment {
let container = Box::new(Orientation::Vertical, 5);
let adjustment = Adjustment::new(ratio.into(), 0.0, 1.0, 0.01, 0.05, 0.05);
let scale = Scale::builder()
.orientation(Orientation::Vertical)
.adjustment(&adjustment)
.hexpand(true)
.vexpand(true)
.inverted(true)
.build();
container.append(&scale);
let temp_label = Label::new(Some(&temperature.to_string()));
container.append(&temp_label);
parent.append(&container);
adjustment
}

View File

@@ -1,11 +1,11 @@
// mod fan_curve_frame;
mod fan_curve_frame;
use fan_curve_frame::FanCurveFrame;
use glib::clone;
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::DeviceStats;
use lact_client::schema::{default_fan_curve, DeviceStats};
use std::collections::BTreeMap;
// use fan_curve_frame::FanCurveFrame;
pub struct ThermalsSettings {
pub automatic_fan_control_enabled: bool,
@@ -18,7 +18,7 @@ pub struct ThermalsPage {
temp_label: Label,
fan_speed_label: Label,
fan_control_enabled_switch: Switch,
// fan_curve_frame: FanCurveFrame,
fan_curve_frame: FanCurveFrame,
}
impl ThermalsPage {
@@ -92,11 +92,12 @@ impl ThermalsPage {
container.prepend(&grid);
/*let fan_curve_frame = FanCurveFrame::new();
let fan_curve_frame = FanCurveFrame::new();
fan_curve_frame.set_curve(&default_fan_curve());
container.pack_start(&fan_curve_frame.container, true, true, 5);
container.append(&fan_curve_frame.container);
// Show/hide fan curve when the switch is toggled
/*// Show/hide fan curve when the switch is toggled
{
let fan_curve_frame = fan_curve_frame.clone();
fan_control_enabled_switch.connect_changed_active(move |switch| {
@@ -124,7 +125,7 @@ impl ThermalsPage {
temp_label,
fan_speed_label,
fan_control_enabled_switch,
// fan_curve_frame,
fan_curve_frame,
}
}

View File

@@ -23,6 +23,18 @@ use std::{
pub type FanCurveMap = BTreeMap<i32, f32>;
pub fn default_fan_curve() -> FanCurveMap {
[
(30, 0.0),
(40, 0.2),
(50, 0.35),
(60, 0.5),
(70, 0.75),
(80, 1.0),
]
.into()
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Pong;