Skip to content

Commit

Permalink
Support for multiple devices, new release
Browse files Browse the repository at this point in the history
  • Loading branch information
Nortank12 committed Sep 20, 2024
1 parent 1a80934 commit 8d7fbf2
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deepcool-digital-linux"
version = "0.4.2"
version = "0.5.0"
edition = "2021"

[dependencies]
Expand Down
65 changes: 47 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ and run it in the command line. You will need root permission to send data to th
> On AMD's Zen architecture CPUs, you can install the [zenpower3](https://github.com/PutinVladimir/zenpower3)
> driver, to have a more accurate reading of the CPU die.
### Rootless mode (optional)
If you need to run the program without root privilege, you can create a `udev` rule to access all necessary resources as a user.

1. Locate your directory, it can be `/lib/udev/rules.d` or `/etc/udev/rules.d`.
```bash
cd /lib/udev/rules.d
```
2. Create a new file called `99-deepcool-digital.rules`.
```bash
sudo nano 99-deepcool-digital.rules
```
3. Copy the contents:
```bash
# Intel RAPL energy usage file
ACTION=="add", SUBSYSTEM=="powercap", KERNEL=="intel-rapl:0", RUN+="/bin/chmod 444 /sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj"

# DeepCool HID raw devices
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="3633", MODE="0666"
```
4. Reboot your computer.

# Supported devices

### CPU Coolers
<table>
<tr>
Expand Down Expand Up @@ -87,36 +110,42 @@ You can run the program with or without providing any options.
```bash
sudo ./deepcool-digital-linux [OPTIONS]
```
```bash
```
Options:
-m, --mode <MODE> Change the display mode between "temp, usage, auto" [default: temp]
--pid <ID> Specify the Product ID if you use mutiple devices
-f, --fahrenheit Change temperature unit to Fahrenheit
-a, --alarm Enable the alarm (85˚C | 185˚F)
-a, --alarm Enable the alarm [85˚C | 185˚F]
-l, --list Print Product ID of the connected devices
-h, --help Print help
-V, --version Print version

-v, --version Print version
```

### Rootless mode
If you need to run the program without root privilege, you can create a `udev` rule to access all necessary resources as a user.

1. Locate your directory, it can be `/lib/udev/rules.d` or `/etc/udev/rules.d`.
### Using multiple devices (optional)
If you have multiple devices connected, you can run the following
command to detect them:
```bash
cd /lib/udev/rules.d
sudo ./deepcool-digital-linux --list
```
2. Create a new file called `99-deepcool-digital.rules`.
```
Device list [PID | Name]
-----
4 | AK500S-DIGITAL
7 | MORPHEUS
```
After identifying, you can run them separately by providing their Product ID:
```bash
sudo nano 99-deepcool-digital.rules
sudo ./deepcool-digital-linux --pid 4
```
3. Copy the contents:
```bash
# Intel RAPL energy usage file
ACTION=="add", SUBSYSTEM=="powercap", KERNEL=="intel-rapl:0", RUN+="/bin/chmod 444 /sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj"

# DeepCool HID raw devices
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="3633", MODE="0666"
sudo ./deepcool-digital-linux --pid 7
```
4. Reboot your computer.
If you want to run them automatically, you can create 2 services
instead of 1.

For example:
- `deepcool-digital-case.service`
- `deepcool-digital-cooler.service`

# Automatic start

Expand Down
70 changes: 64 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const VENDOR: u16 = 0x3633;

struct Args {
mode: String,
pid: u16,
fahrenheit: bool,
alarm: bool,
}
Expand Down Expand Up @@ -41,14 +42,20 @@ fn main() {
let mut product_id = 0;
for device in api.device_list() {
if device.vendor_id() == VENDOR {
product_id = device.product_id();
println!("Device found: {}", device.product_string().unwrap().bright_green());
println!("-----");
break;
if args.pid == 0 || device.product_id() == args.pid {
product_id = device.product_id();
println!("Device found: {}", device.product_string().unwrap().bright_green());
println!("-----");
break;
}
}
}
if product_id == 0 {
error!("No DeepCool device was found");
if args.pid > 0 {
error!("No DeepCool device was found with the specified PID");
} else {
error!("No DeepCool device was found");
}
exit(1);
}

Expand Down Expand Up @@ -149,6 +156,7 @@ fn main() {
fn read_args() -> Args {
let args: Vec<String> = args().collect();
let mut mode = "temp".to_string();
let mut pid = 0;
let mut fahrenheit = false;
let mut alarm = false;

Expand All @@ -169,18 +177,67 @@ fn read_args() -> Args {
exit(1);
}
}
"--pid" => {
if i + 1 < args.len() {
match args[i + 1].parse::<u16>() {
Ok(id) => {
if id > 0 {
pid = id;
i += 1;
} else {
error!("Invalid PID");
exit(1);
}
}
Err(_) => {
error!("Invalid PID");
exit(1);
}
}
} else {
error!("--pid requires a value");
exit(1);
}
}
"-f" | "--fahrenheit" => {
fahrenheit = true;
}
"-a" | "--alarm" => {
alarm = true;
}
"-l" | "--list" => {
println!("Device list [{} | {}]", "PID".bright_green().bold(), "Name".bright_green());
println!("-----");
let api = HidApi::new().unwrap_or_else(|err| {
error!(err);
exit(1);
});
let mut products = 0;
for device in api.device_list() {
if device.vendor_id() == VENDOR {
products += 1;
println!(
"{} | {}",
device.product_id().to_string().bright_green().bold(),
device.product_string().unwrap().bright_green()
);
break;
}
}
if products == 0 {
error!("No DeepCool device was found");
exit(1);
}
exit(0);
}
"-h" | "--help" => {
println!("{} [OPTIONS]\n", "Usage: test-app".bold());
println!("{} [OPTIONS]\n", "Usage: deepcool-digital-linux".bold());
println!("{}", "Options:".bold());
println!(" {}, {} <MODE> Change the display mode between \"temp, usage, auto\" [default: temp]", "-m".bold(), "--mode".bold());
println!(" {} <ID> Specify the Product ID if you use mutiple devices", "--pid".bold());
println!(" {}, {} Change temperature unit to Fahrenheit", "-f".bold(), "--fahrenheit".bold());
println!(" {}, {} Enable the alarm [85˚C | 185˚F]", "-a".bold(), "--alarm".bold());
println!(" {}, {} Print Product ID of the connected devices", "-l".bold(), "--list".bold());
println!(" {}, {} Print help", "-h".bold(), "--help".bold());
println!(" {}, {} Print version", "-v".bold(), "--version".bold());
exit(0);
Expand Down Expand Up @@ -229,6 +286,7 @@ fn read_args() -> Args {

Args {
mode,
pid,
fahrenheit,
alarm,
}
Expand Down

0 comments on commit 8d7fbf2

Please sign in to comment.