Skip to content

Commit

Permalink
Fix timing issues in USB drivers
Browse files Browse the repository at this point in the history
In combination with slow USB hubs or KVM switches, some drivers
apparently fail to initialize due to too strict timing constraints.
So be more lenient with timings, and increase the time we wait between
issuing of commands

Referencs #161
  • Loading branch information
X3n0m0rph59 committed Oct 11, 2022
1 parent 6ca2eb7 commit 6745d9e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions eruption-hwutil/src/hwdevices/roccat_kone_pro_air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::collections::HashMap;
use std::time::Duration;
use std::{cell::RefCell, thread};

use crate::constants::DEVICE_SETTLE_MILLIS;
#[allow(unused)]
use crate::{constants, eprintln_v, println_v};

Expand Down Expand Up @@ -302,7 +303,7 @@ impl DeviceTrait for RoccatKoneProAir {
Err(_) => return Err(HwDeviceError::InvalidResult {}.into()),
}

thread::sleep(Duration::from_millis(70));
thread::sleep(Duration::from_millis(DEVICE_SETTLE_MILLIS));

Ok(())
}
Expand Down Expand Up @@ -404,7 +405,7 @@ impl DeviceTrait for RoccatKoneProAir {
_ => { /* do nothing */ }
}

thread::sleep(Duration::from_millis(15));
thread::sleep(Duration::from_millis(DEVICE_SETTLE_MILLIS));
}

Ok(DeviceStatus(table))
Expand Down
2 changes: 1 addition & 1 deletion eruption/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub const MAX_EVENTS_PER_ITERATION: u64 = 128;
pub const EVENTS_UPCALL_RATE_LIMIT_MILLIS: u64 = 25;

/// Amount of time that has to pass before we retry sending a command to the LED control device
pub const DEVICE_SETTLE_MILLIS: u64 = 15;
pub const DEVICE_SETTLE_MILLIS: u64 = 25;

/// Update sensors every n seconds
/// It is recommended to use a prime number value here
Expand Down
8 changes: 6 additions & 2 deletions eruption/src/hwdevices/roccat_kone_pro_air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ use evdev_rs::enums::EV_KEY;
use hidapi::{HidApi, HidDevice};
use log::*;
use parking_lot::{Mutex, RwLock};
use std::time::Duration;
// use std::sync::atomic::Ordering;
use std::any::Any;
use std::collections::HashMap;
use std::sync::Arc;
use std::{any::Any, thread};

use crate::constants;
use crate::constants::{self, DEVICE_SETTLE_MILLIS};

use super::{
DeviceCapabilities, DeviceInfoTrait, DeviceStatus, DeviceTrait, HwDeviceError, MouseDevice,
Expand Down Expand Up @@ -256,6 +257,8 @@ impl RoccatKoneProAir {
Err(_) => { /* do nothing */ }
}

thread::sleep(Duration::from_millis(DEVICE_SETTLE_MILLIS));

Ok(())
}
}
Expand Down Expand Up @@ -507,6 +510,7 @@ impl DeviceInfoTrait for RoccatKoneProAir {
} */

let result = super::DeviceInfo::new(0_i32);

Ok(result)
}
}
Expand Down
4 changes: 3 additions & 1 deletion eruption/src/hwdevices/roccat_vulcan_1xx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::thread;
use std::time::Duration;
use std::{any::Any, mem::size_of};

use crate::constants;
use crate::constants::{self, DEVICE_SETTLE_MILLIS};

use super::{
DeviceCapabilities, DeviceInfoTrait, DeviceStatus, DeviceTrait, HwDeviceError, KeyboardDevice,
Expand Down Expand Up @@ -469,6 +469,8 @@ impl RoccatVulcan1xx {

Err(_) => return Err(HwDeviceError::InvalidResult {}.into()),
}

thread::sleep(Duration::from_millis(DEVICE_SETTLE_MILLIS));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions eruption/src/hwdevices/roccat_vulcan_pro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::collections::HashMap;
use std::{any::Any, mem::size_of, time::Duration};
use std::{sync::Arc, thread};

use crate::constants;
use crate::constants::{self, DEVICE_SETTLE_MILLIS};

use super::{
DeviceCapabilities, DeviceInfoTrait, DeviceStatus, DeviceTrait, HwDeviceError, KeyboardDevice,
Expand Down Expand Up @@ -325,7 +325,7 @@ impl RoccatVulcanPro {
// }
// }

thread::sleep(Duration::from_millis(70));
thread::sleep(Duration::from_millis(DEVICE_SETTLE_MILLIS));

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions eruption/src/hwdevices/roccat_vulcan_pro_tkl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::time::Duration;
use std::{any::Any, mem::size_of};
use std::{sync::Arc, thread};

use crate::constants;
use crate::constants::{self, DEVICE_SETTLE_MILLIS};

use super::{
DeviceCapabilities, DeviceInfoTrait, DeviceStatus, DeviceTrait, HwDeviceError, KeyboardDevice,
Expand Down Expand Up @@ -322,7 +322,7 @@ impl RoccatVulcanProTKL {
// }
// }

thread::sleep(Duration::from_millis(70));
thread::sleep(Duration::from_millis(DEVICE_SETTLE_MILLIS));

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions eruption/src/hwdevices/roccat_vulcan_tkl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::collections::HashMap;
use std::{any::Any, mem::size_of, time::Duration};
use std::{sync::Arc, thread};

use crate::constants;
use crate::constants::{self, DEVICE_SETTLE_MILLIS};

use super::{
DeviceCapabilities, DeviceInfoTrait, DeviceStatus, DeviceTrait, HwDeviceError, KeyboardDevice,
Expand Down Expand Up @@ -420,7 +420,7 @@ impl RoccatVulcanTKL {
// }
// }

thread::sleep(Duration::from_millis(70));
thread::sleep(Duration::from_millis(DEVICE_SETTLE_MILLIS));

Ok(())
}
Expand Down

0 comments on commit 6745d9e

Please sign in to comment.