diff --git a/README.md b/README.md index d4bbbf7..0c89ba8 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ This fork uses updated dependencies, adds support for more devices (see below) a - [x] Tested - [x] Model O- - [ ] Tested -- [ ] Model D- - - [ ] Tested +- [x] Model D- + - [x] Tested Please, if you have a device that isn't supported, submit a pull request to add it! You can follow [this guide](https://kb.synology.com/en-ph/DSM/tutorial/How_do_I_check_the_PID_VID_of_my_USB_device) to figure out how to find the relevant info you need. diff --git a/src/args.rs b/src/args.rs index 41be13f..6b50733 100644 --- a/src/args.rs +++ b/src/args.rs @@ -302,7 +302,7 @@ pub enum Button { Scroll, Forward, Back, - DPI, + DPIBtn, ScrollUp, ScrollDown, } diff --git a/src/config/bind/mod.rs b/src/config/bind/mod.rs index 80e3b5a..0ab65ee 100644 --- a/src/config/bind/mod.rs +++ b/src/config/bind/mod.rs @@ -70,7 +70,7 @@ fn id_from_btn(button: Button) -> u8 { Button::Right => 2, Button::Forward => 5, Button::Back => 4, - Button::DPI => 20, + Button::DPIBtn => 20, Button::ScrollUp => 16, Button::ScrollDown => 17, } diff --git a/src/config/debounce.rs b/src/config/debounce.rs index 1a25a62..40db67e 100644 --- a/src/config/debounce.rs +++ b/src/config/debounce.rs @@ -1,8 +1,10 @@ use hidapi::HidDevice; - +use crate::lib::getstatus::check_sleep; use super::DEFAULT_PROFILE; pub fn set(device: &HidDevice, profile: Option, ms: u8) { + check_sleep(device); + let mut bfr = [0u8; 65]; let profile_id = profile.unwrap_or(DEFAULT_PROFILE); diff --git a/src/config/dpi_colors.rs b/src/config/dpi_colors.rs index b7d6b0b..95c6d75 100644 --- a/src/config/dpi_colors.rs +++ b/src/config/dpi_colors.rs @@ -1,9 +1,12 @@ use crate::lib::color::Color; use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; use super::DEFAULT_PROFILE; pub fn set(device: &HidDevice, profile: Option, colors: Vec) { + check_sleep(device); + let mut bfr = [0u8; 65]; let profile_id = profile.unwrap_or(DEFAULT_PROFILE); diff --git a/src/config/dpi_stage.rs b/src/config/dpi_stage.rs index 4e177c6..2b190f2 100644 --- a/src/config/dpi_stage.rs +++ b/src/config/dpi_stage.rs @@ -1,8 +1,11 @@ use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; use super::DEFAULT_PROFILE; pub fn set(device: &HidDevice, profile: Option, id: u8) { + check_sleep(device); + let mut bfr = [0u8; 65]; let profile_id = profile.unwrap_or(DEFAULT_PROFILE); diff --git a/src/config/led_brightness.rs b/src/config/led_brightness.rs index ad46d4d..20171e2 100644 --- a/src/config/led_brightness.rs +++ b/src/config/led_brightness.rs @@ -1,7 +1,10 @@ use hidapi::HidDevice; use std::{thread, time::Duration}; +use crate::lib::getstatus::check_sleep; pub fn set(device: &HidDevice, wired: u8, wireless: Option) { + check_sleep(device); + let mut bfr = [0u8; 65]; bfr[3] = 0x02; diff --git a/src/config/led_effect.rs b/src/config/led_effect.rs index 984b598..e55fed2 100644 --- a/src/config/led_effect.rs +++ b/src/config/led_effect.rs @@ -3,10 +3,13 @@ use std::process; use crate::args::Effect; use colored::Colorize; use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; use super::DEFAULT_PROFILE; pub fn set(device: &HidDevice, profile: Option, effect: Effect) { + check_sleep(device); + let mut bfr = [0u8; 65]; let profile_id = profile.unwrap_or(DEFAULT_PROFILE); diff --git a/src/config/lift_off.rs b/src/config/lift_off.rs index 58d28c5..2284cae 100644 --- a/src/config/lift_off.rs +++ b/src/config/lift_off.rs @@ -1,6 +1,9 @@ use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; pub fn set(device: &HidDevice, mm: String) { + check_sleep(device); + let mut bfr = [0u8; 65]; bfr[3] = 0x02; diff --git a/src/config/polling_rate.rs b/src/config/polling_rate.rs index 497dfdc..3e86852 100644 --- a/src/config/polling_rate.rs +++ b/src/config/polling_rate.rs @@ -1,6 +1,9 @@ use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; pub fn set(device: &HidDevice, ms: String) { + check_sleep(device); + let mut bfr = [0u8; 65]; bfr[3] = 0x02; diff --git a/src/config/profile.rs b/src/config/profile.rs index f3cbd45..ac98abe 100644 --- a/src/config/profile.rs +++ b/src/config/profile.rs @@ -1,6 +1,9 @@ use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; pub fn set(device: &HidDevice, id: u8) { + check_sleep(device); + let mut bfr = [0u8; 65]; bfr[3] = 0x02; diff --git a/src/config/scroll.rs b/src/config/scroll.rs index 4e7814c..12dab74 100644 --- a/src/config/scroll.rs +++ b/src/config/scroll.rs @@ -1,8 +1,11 @@ use super::bind; use crate::args::{Binding, Button, MouseFn, ScrollDirection}; use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; pub fn set(device: &HidDevice, direction: ScrollDirection) { + check_sleep(device); + for i in 1..=3 { match direction { ScrollDirection::Default => { diff --git a/src/config/sleep.rs b/src/config/sleep.rs index c979e3a..9c8c5be 100644 --- a/src/config/sleep.rs +++ b/src/config/sleep.rs @@ -1,6 +1,9 @@ use hidapi::HidDevice; +use crate::lib::getstatus::check_sleep; pub fn set(device: &HidDevice, minutes: u8, seconds: Option) { + check_sleep(device); + let mut buffer = [0u8; 65]; buffer[3] = 0x02; diff --git a/src/glorious.rs b/src/glorious.rs index f4320bd..454364a 100644 --- a/src/glorious.rs +++ b/src/glorious.rs @@ -7,7 +7,8 @@ pub enum Device { ModelO = 0x2011, ModelD = 0x2012, ModelOMinus = 0x2013, - WiredModel0 = 0x2022, + ModelDMinus = 0x2025, + WiredModelO = 0x2022, WiredModelD = 0x2023, WiredModelOMinus = 0x2024 -} \ No newline at end of file +} diff --git a/src/lib/getstatus.rs b/src/lib/getstatus.rs new file mode 100644 index 0000000..dc98873 --- /dev/null +++ b/src/lib/getstatus.rs @@ -0,0 +1,44 @@ +use colored::Colorize; +use hidapi::HidDevice; +use std::{thread, time::Duration}; + +pub fn get_bfr_r(device: &HidDevice) -> [u8;65] { + let mut bfr_w = [0u8; 65]; + + bfr_w[3] = 0x02; + bfr_w[4] = 0x02; + bfr_w[6] = 0x83; + + device.send_feature_report(&bfr_w).unwrap(); + + thread::sleep(Duration::from_millis(50)); + + let mut bfr_r = [0u8; 65]; + + device.get_feature_report(&mut bfr_r).unwrap(); + + bfr_r +} + +pub fn get_status(device: &HidDevice) -> usize { + let mut bfr_r = get_bfr_r(device); + + device.get_feature_report(&mut bfr_r).unwrap(); + + let mut status = [0xA1, 0xA4, 0xA2, 0xA0, 0xA3] + .iter() + .position(|&s| s == bfr_r[1]) + .unwrap(); + + if bfr_r[6] != 0x83 { + status = 2; + } + + status +} + +pub fn check_sleep(device: &HidDevice) { + if get_status(device) == 1 { + println!("Cannot write changes to device since it is off or sleeping."); + } +} diff --git a/src/lib/mod.rs b/src/lib/mod.rs index d382bd8..0c8f28c 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs @@ -2,3 +2,4 @@ pub mod color; pub mod key; pub mod none; pub mod range; +pub mod getstatus; diff --git a/src/report/battery.rs b/src/report/battery.rs index acdee4d..904c48a 100644 --- a/src/report/battery.rs +++ b/src/report/battery.rs @@ -1,37 +1,16 @@ use colored::Colorize; use hidapi::HidDevice; -use std::{thread, time::Duration}; +use crate::lib::getstatus::get_status; +use crate::lib::getstatus::get_bfr_r; pub fn get(device: &HidDevice, wired: bool) { - let mut bfr_w = [0u8; 65]; - - bfr_w[3] = 0x02; - bfr_w[4] = 0x02; - bfr_w[6] = 0x83; - - device.send_feature_report(&bfr_w).unwrap(); - - thread::sleep(Duration::from_millis(50)); - - let mut bfr_r = [0u8; 65]; - - device.get_feature_report(&mut bfr_r).unwrap(); - + let status = get_status(device); + let bfr_r = get_bfr_r(device); let mut percentage = bfr_r[8]; - if percentage == 0 { percentage = 1; } - let mut status = [0xA1, 0xA4, 0xA2, 0xA0, 0xA3] - .iter() - .position(|&s| s == bfr_r[1]) - .unwrap(); - - if bfr_r[6] != 0x83 { - status = 2; - } - match (status, wired) { (0, false) => println!("{percentage}%"), (0, true) => {