-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
171 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "deepcool-digital-linux" | ||
version = "0.2.2" | ||
version = "0.3.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use crate::monitor::{cpu, gpu::nvidia::Gpu as NvGpu}; | ||
use hidapi::HidApi; | ||
use std::{thread::sleep, time::Duration}; | ||
|
||
const VENDOR: u16 = 0x3633; | ||
const POLLING_RATE: u64 = 750; | ||
|
||
pub struct Display { | ||
product_id: u16, | ||
fahrenheit: bool, | ||
nvidia_gpu: Option<NvGpu>, | ||
} | ||
|
||
impl Display { | ||
pub fn new(product_id: u16, fahrenheit: bool, gpu: &str) -> Self { | ||
let nv_gpu = if gpu == "nvidia" { Some(NvGpu::new()) } else { None }; | ||
|
||
Display { | ||
product_id, | ||
fahrenheit, | ||
nvidia_gpu: nv_gpu, | ||
} | ||
} | ||
|
||
pub fn run(&self, api: &HidApi, mode: &str, cpu_temp_sensor: &str) { | ||
// Connect to device | ||
let device = api.open(VENDOR, self.product_id).expect("Failed to open HID device"); | ||
|
||
// Data packet | ||
let mut data: [u8; 64] = [0; 64]; | ||
data[0] = 16; | ||
|
||
// Init sequence | ||
{ | ||
let mut init_data = data.clone(); | ||
init_data[1] = 170; | ||
device.write(&init_data).expect("Failed to write data"); | ||
} | ||
|
||
// Display loop | ||
if mode == "auto" { | ||
loop { | ||
for _ in 0..8 { | ||
device | ||
.write(&self.status_message(&data, "temp", &cpu_temp_sensor)) | ||
.expect("Failed to write data"); | ||
} | ||
for _ in 0..8 { | ||
device | ||
.write(&self.status_message(&data, "usage", &cpu_temp_sensor)) | ||
.expect("Failed to write data"); | ||
} | ||
} | ||
} else { | ||
loop { | ||
device | ||
.write(&self.status_message(&data, &mode, &cpu_temp_sensor)) | ||
.expect("Failed to write data"); | ||
} | ||
} | ||
} | ||
|
||
/// Reads the CPU status information and returns the data packet. | ||
fn status_message(&self, inital_data: &[u8; 64], mode: &str, cpu_temp_sensor: &str) -> [u8; 64] { | ||
// Clone the data packet | ||
let mut data = inital_data.clone(); | ||
|
||
// Read CPU utilization | ||
let cpu_instant = cpu::read_instant(); | ||
|
||
// Wait | ||
sleep(Duration::from_millis(POLLING_RATE)); | ||
|
||
// Calculate CPU & GPU usage | ||
let cpu_usage = cpu::get_usage(cpu_instant); | ||
let gpu_usage = self.nvidia_gpu.as_ref().unwrap().get_usage(); | ||
|
||
// Main display | ||
match mode { | ||
"temp" => { | ||
let unit = if self.fahrenheit { 35 } else { 19 }; | ||
let cpu_temp = cpu::get_temp(cpu_temp_sensor, self.fahrenheit); | ||
let gpu_temp = self.nvidia_gpu.as_ref().unwrap().get_temp(self.fahrenheit); | ||
// CPU | ||
data[1] = unit; | ||
data[3] = cpu_temp / 100; | ||
data[4] = cpu_temp % 100 / 10; | ||
data[5] = cpu_temp % 10; | ||
// GPU | ||
data[6] = unit; | ||
data[8] = gpu_temp / 100; | ||
data[9] = gpu_temp % 100 / 10; | ||
data[10] = gpu_temp % 10; | ||
} | ||
"usage" => { | ||
// CPU | ||
data[1] = 76; | ||
data[3] = cpu_usage / 100; | ||
data[4] = cpu_usage % 100 / 10; | ||
data[5] = cpu_usage % 10; | ||
// GPU | ||
data[6] = 76; | ||
data[8] = gpu_usage / 100; | ||
data[9] = gpu_usage % 100 / 10; | ||
data[10] = gpu_usage % 10; | ||
} | ||
_ => (), | ||
} | ||
// Status bar | ||
data[2] = if cpu_usage < 20 { 1 } else { (cpu_usage as f32 / 10 as f32).round() as u8 }; | ||
data[7] = if gpu_usage < 20 { 1 } else { (gpu_usage as f32 / 10 as f32).round() as u8 }; | ||
|
||
data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod ag_series; | ||
pub mod ak_series; | ||
pub mod ch_series; | ||
pub mod ld_series; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters