Skip to content

Commit

Permalink
Merge pull request #8 from wiiznokes/auroburos
Browse files Browse the repository at this point in the history
Auroburos
  • Loading branch information
wiiznokes authored Nov 14, 2023
2 parents f922999 + 98a4cb5 commit ab52927
Show file tree
Hide file tree
Showing 29 changed files with 609 additions and 310 deletions.
32 changes: 32 additions & 0 deletions .config/config3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[[Control]]
name = "control1"
input = "linear1"
auto = false

[[Linear]]
name = "linear1"
minTemp = 10
minSpeed = 10
maxTemp = 70
maxSpeed = 100
input = "custom_temp"

[[CustomTemp]]
name = "custom_temp"
kind = "Average"
input = [
"temp1",
"temp2",
]





[[Temp]]
name = "temp1"
id = "/intelcpu/0/temperature/1"

[[Temp]]
name = "temp2"
id = "/intelcpu/0/temperature/2"
28 changes: 28 additions & 0 deletions .config/config4.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[[Control]]
name = "control1"
input = "linear1"
auto = false

[[Linear]]
name = "linear1"
minTemp = 10
minSpeed = 10
maxTemp = 70
maxSpeed = 100
input = "custom_temp"

[[CustomTemp]]
name = "custom_temp"
kind = "Average"
input = [
"temp1",
"temp2",
]

[[Temp]]
name = "temp1"
id = "coretemp-isa-0000-temp3_input"

[[Temp]]
name = "temp2"
id = "coretemp-isa-0000-temp2_input"
17 changes: 0 additions & 17 deletions .config/hardware.toml

This file was deleted.

2 changes: 1 addition & 1 deletion .config/settings.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
unit = "Celsius"
update_delay = 0
disable_pwm_value = 0
current_config = "config2.toml"
current_config = "config4.toml"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ target/
.vscode/*
!.vscode/launch.json
bin/
obj/
obj/
.config/hardware.toml
59 changes: 59 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fix:
cargo clippy --all --fix --allow-dirty --allow-staged
cargo fmt --all

clean-git:
git-cache:
git rm -rf --cached .
git add .

Expand All @@ -35,6 +35,9 @@ clean-libsensors:
lhm:
dotnet build ./hardware/LibreHardwareMonitorWrapper/ -c release

run-lhm:
dotnet run --project ./hardware/LibreHardwareMonitorWrapper/ -c release

test:
cargo test --all --all-features

Expand Down
26 changes: 16 additions & 10 deletions data/src/config/control.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::rc::Rc;

use hardware::{ControlH, Hardware, Value};
use hardware::{ControlH, Hardware, HardwareBridgeT, Value};
use serde::{Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -42,26 +42,32 @@ impl Control {
}
}

pub fn set_value(&mut self, value: Value) -> Result<Value, UpdateError> {
pub fn set_value(
&mut self,
value: Value,
bridge: &mut HardwareBridgeT,
) -> Result<Value, UpdateError> {
if !self.manual_has_been_set {
self.set_mode(false)?;
self.set_mode(false, bridge)?;
}

match &self.control_h {
Some(control_h) => control_h
.bridge
.set_value(value)
Some(control_h) => bridge
.set_value(&control_h.internal_index, value)
.map(|_| value)
.map_err(UpdateError::Hardware),
None => Err(UpdateError::NodeIsInvalid),
}
}

pub fn set_mode(&mut self, auto: bool) -> Result<(), UpdateError> {
pub fn set_mode(
&mut self,
auto: bool,
bridge: &mut HardwareBridgeT,
) -> Result<(), UpdateError> {
let res = match &self.control_h {
Some(control_h) => control_h
.bridge
.set_mode(!auto as i32)
Some(control_h) => bridge
.set_mode(&control_h.internal_index, !auto as i32)
.map_err(UpdateError::Hardware),
None => Err(UpdateError::NodeIsInvalid),
};
Expand Down
8 changes: 5 additions & 3 deletions data/src/config/fan.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::rc::Rc;

use hardware::{FanH, Hardware, Value};
use hardware::{FanH, Hardware, HardwareBridgeT, Value};
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -20,9 +20,11 @@ pub struct Fan {
}

impl Fan {
pub fn get_value(&self) -> Result<Value, UpdateError> {
pub fn get_value(&self, bridge: &mut HardwareBridgeT) -> Result<Value, UpdateError> {
match &self.fan_h {
Some(fan_h) => fan_h.bridge.get_value().map_err(UpdateError::Hardware),
Some(fan_h) => bridge
.get_value(&fan_h.internal_index)
.map_err(UpdateError::Hardware),
None => Err(UpdateError::NodeIsInvalid),
}
}
Expand Down
25 changes: 4 additions & 21 deletions data/src/config/serde_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use const_format::formatcp;
use hardware::{ControlH, FanH, Hardware, HardwareItem, TempH};
use hardware::{ControlH, FanH, Hardware, TempH};
use serial_test::serial;
use std::fmt::Debug;
use std::fs::{self, File};
Expand Down Expand Up @@ -95,44 +95,27 @@ fn write_file<E: Debug>(path: &str, content_generation: impl Fn() -> Result<Stri
println!("file {} succesfully writed!", path);
}

#[derive(Debug)]
struct T {}

impl HardwareItem for T {
fn get_value(&self) -> Result<hardware::Value, hardware::HardwareError> {
todo!()
}

fn set_value(&self, _value: hardware::Value) -> Result<(), hardware::HardwareError> {
todo!()
}

fn set_mode(&self, _value: hardware::Value) -> Result<(), hardware::HardwareError> {
todo!()
}
}

fn hardware1() -> Hardware {
Hardware {
controls: vec![ControlH {
name: "ControlH".into(),
hardware_id: "ControlH".into(),
info: "ControlH".into(),
bridge: Box::new(T {}),
internal_index: 0,
}
.into()],
temps: vec![TempH {
name: "TempH".into(),
hardware_id: "TempH".into(),
info: "TempH".into(),
bridge: Box::new(T {}),
internal_index: 0,
}
.into()],
fans: vec![FanH {
name: "FanH".into(),
hardware_id: "FanH".into(),
info: "FanH".into(),
bridge: Box::new(T {}),
internal_index: 0,
}
.into()],
}
Expand Down
8 changes: 5 additions & 3 deletions data/src/config/temp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::rc::Rc;

use hardware::{Hardware, TempH, Value};
use hardware::{Hardware, HardwareBridgeT, TempH, Value};
use serde::{Deserialize, Serialize};

use crate::{
Expand All @@ -20,9 +20,11 @@ pub struct Temp {
}

impl Temp {
pub fn get_value(&self) -> Result<Value, UpdateError> {
pub fn get_value(&self, bridge: &mut HardwareBridgeT) -> Result<Value, UpdateError> {
match &self.temp_h {
Some(temp_h) => temp_h.bridge.get_value().map_err(UpdateError::Hardware),
Some(temp_h) => bridge
.get_value(&temp_h.internal_index)
.map_err(UpdateError::Hardware),
None => Err(UpdateError::NodeIsInvalid),
}
}
Expand Down
3 changes: 2 additions & 1 deletion data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod node;
pub mod settings;
pub mod update;

use hardware::{Hardware, HardwareBridge};
use hardware::{Hardware, HardwareBridge, HardwareBridgeT};
use node::AppGraph;
use update::Update;

Expand All @@ -25,6 +25,7 @@ pub struct AppState {
pub dir_manager: DirManager,
pub settings: Settings,
pub hardware: Hardware,
pub bridge: HardwareBridgeT,
pub app_graph: AppGraph,
pub update: Update,
}
Loading

0 comments on commit ab52927

Please sign in to comment.