Skip to content

Commit

Permalink
Bump version and reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Mar 20, 2022
1 parent f0fd7d4 commit bb7b644
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dawctl"
version = "0.2.2"
authors = ["João M. Bezerra <[email protected]>"]
edition = "2018"
edition = "2021"
license = "MIT"
description = "Razer Deathadder White Edition mouse device manager."
repository = "https://github.com/marcospb19/dawctl"
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
max_width = 120
max_width = 100
unstable_features = true
format_strings = true
wrap_comments = true
32 changes: 24 additions & 8 deletions src/daw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl DeathAdderWhite {
} else {
let mut option_path: Option<PathBuf> = None;
for device in enumerator.scan_devices()? {
if let Some(usb_parent) = device.parent_with_subsystem_devtype("usb", "usb_device") {
if let Some(usb_parent) = device.parent_with_subsystem_devtype("usb", "usb_device")
{
let device_id_vendor = usb_parent
.attribute_value("idVendor")
.expect("Error: unable to read the device idVendor.");
Expand Down Expand Up @@ -64,8 +65,8 @@ impl DeathAdderWhite {
}
};

let file_descriptor =
fcntl::open(&mouse_device_path, nix::fcntl::O_RDWR, Mode::empty()).unwrap_or_else(|err| {
let file_descriptor = fcntl::open(&mouse_device_path, nix::fcntl::O_RDWR, Mode::empty())
.unwrap_or_else(|err| {
runtime_error!("Failed to open device: {}", err.to_string());
});

Expand All @@ -74,7 +75,10 @@ impl DeathAdderWhite {

pub fn set_dpi(&self, dpi: u16) {
if !(200..=6400).contains(&dpi) {
runtime_error!("Error: DPI_LEVEL isn't in the valid interval [200-6400]: '{}'", dpi);
runtime_error!(
"Error: DPI_LEVEL isn't in the valid interval [200-6400]: '{}'",
dpi
);
}

if dpi % 100 != 0 {
Expand Down Expand Up @@ -112,7 +116,10 @@ impl DeathAdderWhite {

pub fn set_brightness(&self, brightness: u16) {
if brightness > 100 {
runtime_error!("Error: Brightness level '{}' is out of the range [0,100].", brightness);
runtime_error!(
"Error: Brightness level '{}' is out of the range [0,100].",
brightness
);
}

// Command sequence to change brightness
Expand Down Expand Up @@ -200,15 +207,23 @@ impl DeathAdderWhite {
for _ in 0..4 {
unsafe {
// Send command to DeathAdder, skip if error
if let Err(err) = usbhid_communication::sfeature(self.file_descriptor, buf.as_mut_ptr(), buf.len()) {
if let Err(err) = usbhid_communication::sfeature(
self.file_descriptor,
buf.as_mut_ptr(),
buf.len(),
) {
eprintln!("USBHID_IOCSFEATURE: {}", err);
eprintln!("error, trying again maybe this time it'll work shit");
continue;
}

// Communication: receive response from mouse
// We are overwriting the same buffer used for sending the message
if let Err(err) = usbhid_communication::gfeature(self.file_descriptor, buf.as_mut_ptr(), buf.len()) {
if let Err(err) = usbhid_communication::gfeature(
self.file_descriptor,
buf.as_mut_ptr(),
buf.len(),
) {
eprintln!("USBHID_IOCGFEATURE: {}", err);
continue;
}
Expand All @@ -221,7 +236,8 @@ impl DeathAdderWhite {
return;
}
other => eprintln!(
"Command failed: Device did not answered what we expected: '{}'.\ncmd_bytes: {:#?}",
"Command failed: Device did not answered what we expected: '{}'.\ncmd_bytes: \
{:#?}",
other, cmd
),
}
Expand Down

0 comments on commit bb7b644

Please sign in to comment.