Skip to content

Commit

Permalink
fix control config
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Sep 15, 2024
1 parent 0ce84a6 commit 3d17a85
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 25 deletions.
2 changes: 1 addition & 1 deletion configs-examples/settings.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
theme = "Light"
update_delay = 1500
current_config = "test"
current_config = "test-locale"
56 changes: 56 additions & 0 deletions configs-examples/test-locale.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CustomTemp = []
Graph = []
Linear = []
Target = []

[[Control]]
name = "pwm2 nct6798-isa-0290"
id = "pwm2-nct6798-isa-0290-pwm2"
input = "Plat 1"
active = false

[[Control]]
name = "pwm3 nct6798-isa-0290"
input = "Plat 1"
active = false

[[Control]]
name = "pwm4 nct6798-isa-0290"
input = "Plat 1"
active = false

[[Fan]]
name = "fan2 nct6798-isa-0290"
id = "fan2-nct6798-isa-0290-fan2_input"

[[Fan]]
name = "fan3 nct6798-isa-0290"
id = "fan3-nct6798-isa-0290-fan3_input"

[[Fan]]
name = "fan4 nct6798-isa-0290"
id = "fan4-nct6798-isa-0290-fan4_input"

[[Temp]]
name = "Tctl k10temp-pci-00c3"
id = "Tctl-k10temp-pci-00c3-temp1_input"

[[Temp]]
name = "Tccd1 k10temp-pci-00c3"
id = "Tccd1-k10temp-pci-00c3-temp3_input"

[[Temp]]
name = "CPUTIN nct6798-isa-0290"
id = "CPUTIN-nct6798-isa-0290-temp2_input"

[[Temp]]
name = "AUXTIN1 nct6798-isa-0290"
id = "AUXTIN1-nct6798-isa-0290-temp4_input"

[[Temp]]
name = "TSI0_TEMP nct6798-isa-0290"
id = "TSI0_TEMP-nct6798-isa-0290-temp13_input"

[[Flat]]
name = "Plat 1"
value = 100
53 changes: 32 additions & 21 deletions data/src/app_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@ pub struct AppGraph {
pub root_nodes: RootNodes,
}

impl Default for AppGraph {
fn default() -> Self {
Self::new()
}
}

impl AppGraph {
fn new() -> Self {
pub fn new() -> Self {
Self {
nodes: Nodes::new(),
id_generator: IdGenerator::new(),
root_nodes: Vec::new(),
}
}

pub fn from_config(config: Config, hardware: &Hardware) -> Self {
let mut app_graph = AppGraph::new();
app_graph.apply_config(config, hardware);
app_graph
}

pub fn insert_node(&mut self, node: Node) {
if node.is_root() {
self.root_nodes.push(node.id);
Expand Down Expand Up @@ -87,52 +99,51 @@ impl AppGraph {
app_graph
}

pub fn from_config(config: Config, hardware: &Hardware) -> Self {
let mut app_graph = AppGraph::new();
pub fn apply_config(&mut self, config: Config, hardware: &Hardware) {
self.nodes.clear();
self.root_nodes.clear();

// order: fan -> temp -> custom_temp -> behavior -> control

for fan in config.fans {
let node = fan.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = fan.to_node(self, hardware);
self.insert_node(node);
}

for temp in config.temps {
let node = temp.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = temp.to_node(self, hardware);
self.insert_node(node);
}

for custom_temp in config.custom_temps {
let node = custom_temp.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = custom_temp.to_node(self, hardware);
self.insert_node(node);
}

for flat in config.flats {
let node = flat.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = flat.to_node(self, hardware);
self.insert_node(node);
}

for linear in config.linears {
let node = linear.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = linear.to_node(self, hardware);
self.insert_node(node);
}

for target in config.targets {
let node = target.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = target.to_node(self, hardware);
self.insert_node(node);
}

for graph in config.graphs {
let node = graph.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = graph.to_node(self, hardware);
self.insert_node(node);
}

for control in config.controls {
let node = control.to_node(&mut app_graph, hardware);
app_graph.insert_node(node);
let node = control.to_node(self, hardware);
self.insert_node(node);
}

app_graph
}

fn find_unused_name(nodes: &Nodes, default_name: &str, i: u32) -> String {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::time::Duration;

use data::{
app_graph::AppGraph,
config::Config,
node::{validate_name, IsValid, NodeType},
settings::AppTheme,
Expand Down Expand Up @@ -395,8 +394,9 @@ impl<H: HardwareBridge + 'static> cosmic::Application for Ui<H> {
Ok(config) => match config {
Some((config_name, config)) => {
self.current_config_cached = config_name;
self.app_state.app_graph =
AppGraph::from_config(config, self.app_state.bridge.hardware());
self.app_state
.app_graph
.apply_config(config, self.app_state.bridge.hardware());
self.nodes_c = NodesC::new(self.app_state.app_graph.nodes.values());

self.update_hardware();
Expand Down

0 comments on commit 3d17a85

Please sign in to comment.