Skip to content

Commit

Permalink
Merge pull request korkje#5 from iguanajuice/master
Browse files Browse the repository at this point in the history
Add device "Model D-" and fix typo
  • Loading branch information
dxbednarczyk authored Feb 28, 2024
2 parents 2e493b5 + 05b74f0 commit 90fda7e
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub enum Button {
Scroll,
Forward,
Back,
DPI,
DPIBtn,
ScrollUp,
ScrollDown,
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/bind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 3 additions & 1 deletion src/config/debounce.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use hidapi::HidDevice;

use crate::lib::getstatus::check_sleep;
use super::DEFAULT_PROFILE;

pub fn set(device: &HidDevice, profile: Option<u8>, ms: u8) {
check_sleep(device);

let mut bfr = [0u8; 65];

let profile_id = profile.unwrap_or(DEFAULT_PROFILE);
Expand Down
3 changes: 3 additions & 0 deletions src/config/dpi_colors.rs
Original file line number Diff line number Diff line change
@@ -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<u8>, colors: Vec<Color>) {
check_sleep(device);

let mut bfr = [0u8; 65];

let profile_id = profile.unwrap_or(DEFAULT_PROFILE);
Expand Down
3 changes: 3 additions & 0 deletions src/config/dpi_stage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use hidapi::HidDevice;
use crate::lib::getstatus::check_sleep;

use super::DEFAULT_PROFILE;

pub fn set(device: &HidDevice, profile: Option<u8>, id: u8) {
check_sleep(device);

let mut bfr = [0u8; 65];

let profile_id = profile.unwrap_or(DEFAULT_PROFILE);
Expand Down
3 changes: 3 additions & 0 deletions src/config/led_brightness.rs
Original file line number Diff line number Diff line change
@@ -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<u8>) {
check_sleep(device);

let mut bfr = [0u8; 65];

bfr[3] = 0x02;
Expand Down
3 changes: 3 additions & 0 deletions src/config/led_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, effect: Effect) {
check_sleep(device);

let mut bfr = [0u8; 65];

let profile_id = profile.unwrap_or(DEFAULT_PROFILE);
Expand Down
3 changes: 3 additions & 0 deletions src/config/lift_off.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/config/polling_rate.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/config/profile.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/config/scroll.rs
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
3 changes: 3 additions & 0 deletions src/config/sleep.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use hidapi::HidDevice;
use crate::lib::getstatus::check_sleep;

pub fn set(device: &HidDevice, minutes: u8, seconds: Option<u8>) {
check_sleep(device);

let mut buffer = [0u8; 65];

buffer[3] = 0x02;
Expand Down
5 changes: 3 additions & 2 deletions src/glorious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub enum Device {
ModelO = 0x2011,
ModelD = 0x2012,
ModelOMinus = 0x2013,
WiredModel0 = 0x2022,
ModelDMinus = 0x2025,
WiredModelO = 0x2022,
WiredModelD = 0x2023,
WiredModelOMinus = 0x2024
}
}
44 changes: 44 additions & 0 deletions src/lib/getstatus.rs
Original file line number Diff line number Diff line change
@@ -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.");
}
}
1 change: 1 addition & 0 deletions src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod color;
pub mod key;
pub mod none;
pub mod range;
pub mod getstatus;
29 changes: 4 additions & 25 deletions src/report/battery.rs
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit 90fda7e

Please sign in to comment.