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

Custom widget #5

Merged
merged 9 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
LMSENSORS_STATIC = "1"
LMSENSORS_INCLUDE_DIR = { value = "libsensors_build/include", relative = true }
LMSENSORS_LIB_DIR = { value = "libsensors_build/lib", relative = true }
RUST_LOG = "fan_control=debug,data=debug,hardware=debug,ui=debug"
RUST_LOG = "fan_control=debug,data=info,hardware=info,ui=debug"
68 changes: 2 additions & 66 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/config1.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[[Control]]
name = "control1"
id = "nct6798-isa-0290-pwm1"
input = ""
auto = false

[[Control]]
Expand Down
2 changes: 1 addition & 1 deletion data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ serde_json.workspace = true
toml.workspace = true
directories = "5.0"
clap.workspace = true
light_enum = "0.1"
light_enum = "0.2"
log.workspace = true

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion data/src/config/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Control {

match res {
Ok(_) => {
self.manual_has_been_set = auto;
self.manual_has_been_set = !auto;
}
Err(_) => {
self.manual_has_been_set = false;
Expand Down
26 changes: 19 additions & 7 deletions data/src/config/custom_temp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hardware::{Hardware, Value};
use light_enum::Values;
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -7,17 +8,28 @@ use crate::{
update::UpdateError,
};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum CustomTempType {
#[derive(Serialize, Deserialize, Debug, Clone, Values, Default, PartialEq, Eq)]
pub enum CustomTempKind {
#[default]
Average,
Min,
Max,
Average,
}

impl ToString for CustomTempKind {
fn to_string(&self) -> String {
match self {
CustomTempKind::Average => "Average".into(),
CustomTempKind::Max => "Max".into(),
CustomTempKind::Min => "Min".into(),
}
}
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CustomTemp {
pub name: String,
pub kind: CustomTempType,
pub kind: CustomTempKind,
pub input: Vec<String>,
}

Expand Down Expand Up @@ -48,9 +60,9 @@ impl CustomTemp {
}

let value = match self.kind {
CustomTempType::Min => *values.iter().min().unwrap(),
CustomTempType::Max => *values.iter().min().unwrap(),
CustomTempType::Average => values.iter().sum::<i32>() / values.len() as i32,
CustomTempKind::Min => *values.iter().min().unwrap(),
CustomTempKind::Max => *values.iter().min().unwrap(),
CustomTempKind::Average => values.iter().sum::<i32>() / values.len() as i32,
};
Ok(value)
}
Expand Down
4 changes: 2 additions & 2 deletions data/src/config/serde_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::config::Config;
use crate::settings::Settings;

use super::control::Control;
use super::custom_temp::{CustomTemp, CustomTempType};
use super::custom_temp::{CustomTemp, CustomTempKind};

use super::fan::Fan;
use super::flat::Flat;
Expand Down Expand Up @@ -159,7 +159,7 @@ fn config1() -> Config {
}],
custom_temps: vec![CustomTemp {
name: "CustomTemp".into(),
kind: CustomTempType::Max,
kind: CustomTempKind::Max,
input: vec!["temp1".into(), "temp2".into()],
}],
graphs: vec![Graph {
Expand Down
26 changes: 22 additions & 4 deletions data/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl AppGraph {
pub struct Node {
pub id: Id,
pub node_type: NodeType,
pub inputs: Vec<Id>,
pub inputs: Vec<(Id, String)>,

pub value: Option<Value>,

Expand Down Expand Up @@ -165,7 +165,11 @@ impl NodeType {
}

impl Node {
pub fn new(id_generator: &mut IdGenerator, node_type: NodeType, inputs: Vec<Id>) -> Self {
pub fn new(
id_generator: &mut IdGenerator,
node_type: NodeType,
inputs: Vec<(Id, String)>,
) -> Self {
let name_cached = node_type.name().clone();
Self {
id: id_generator.new_id(),
Expand All @@ -180,6 +184,16 @@ impl Node {
pub fn name(&self) -> &String {
self.node_type.name()
}

#[allow(clippy::result_unit_err)]
pub fn hardware_id(&self) -> Result<&Option<String>, ()> {
match &self.node_type {
NodeType::Control(i) => Ok(&i.hardware_id),
NodeType::Fan(i) => Ok(&i.hardware_id),
NodeType::Temp(i) => Ok(&i.hardware_id),
_ => Err(()),
}
}
}

impl IsValid for Node {
Expand Down Expand Up @@ -250,7 +264,11 @@ pub trait Inputs {
fn get_inputs(&self) -> Vec<&String>;
}

pub fn sanitize_inputs(item: &mut impl Inputs, nodes: &Nodes, node_type: NodeTypeLight) -> Vec<Id> {
pub fn sanitize_inputs(
item: &mut impl Inputs,
nodes: &Nodes,
node_type: NodeTypeLight,
) -> Vec<(Id, String)> {
let mut inputs = Vec::new();

match node_type.max_input() {
Expand Down Expand Up @@ -291,7 +309,7 @@ pub fn sanitize_inputs(item: &mut impl Inputs, nodes: &Nodes, node_type: NodeTyp
inputs.clear();
return inputs;
}
inputs.push(node.id)
inputs.push((node.id, name.clone()))
} else {
eprintln!(
"sanitize_inputs: can't find {} in app_graph. Fall back: remove all",
Expand Down
4 changes: 2 additions & 2 deletions data/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Update {
if !node.is_valid() {
return Ok(None);
}
input_ids = node.inputs.clone();
input_ids = node.inputs.iter().map(|i| i.0).collect();
}

for id in &input_ids {
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Node {

trace.push(self.id);

for id in &self.inputs {
for (id, _) in &self.inputs {
match nodes.get(id) {
Some(node) => {
if !node.validate(nodes, trace)? {
Expand Down
2 changes: 1 addition & 1 deletion experimental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
[dependencies]
#lm-sensors = "0.2.0"
#ouroboros = "0.18.0"
iced = { version = "0.10", features = ["advanced", "smol"]}
#iced = { version = "0.10", features = ["advanced", "smol"]}

Loading