Skip to content

Commit

Permalink
Conditional compile UHID
Browse files Browse the repository at this point in the history
  • Loading branch information
felfert committed Apr 29, 2023
1 parent 16cb746 commit 8bbe858
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cherryrgb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ serde = { version = "1.0.160", features = ["derive"] }
strum = "0.24.1"
strum_macros = "0.24.3"
serde_json = "1.0"

[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dependencies]
uhid-virt = "0.0.6"
5 changes: 5 additions & 0 deletions cherryrgb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
mod extensions;
mod models;
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
mod vkbd;

use binrw::BinReaderExt;
Expand All @@ -67,11 +68,13 @@ use thiserror::Error;
// Re-exports
pub use extensions::{OwnRGB8, ToVec};
pub use hex;
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
pub use models::RpcAnimation;
pub use models::{Brightness, CustomKeyLeds, LightingMode, Packet, Payload, Speed};
pub use rgb;
pub use rusb;
pub use strum;
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
pub use vkbd::VirtKbd;

// Constants
Expand All @@ -81,6 +84,7 @@ pub const CHERRY_USB_VID: u16 = 0x046a;
const INTERFACE_NUM: u8 = 1;
const INTERRUPT_EP: u8 = 0x82;
static TIMEOUT: Duration = Duration::from_millis(1000);
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
static SHORT_TIMEOUT: Duration = Duration::from_millis(100);

/// (64 byte packet - 4 byte packet header - 4 byte payload header)
Expand Down Expand Up @@ -432,6 +436,7 @@ impl CherryKeyboard {

/// forward a key event from our usb device to the virtual UHID keyboard,
/// filter out any bogus events while doing so.
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
pub fn forward_filtered_keys(&self, vdevice: &mut VirtKbd) -> Result<(), CherryRgbError> {
let mut buf = [0; 64];
match self
Expand Down
1 change: 1 addition & 0 deletions cherryrgb/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ impl CustomKeyLeds {

/// Parameters for set_led_animation (sent serialized from
/// cherryrgb_ncli to cherryrgb_service).
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
#[derive(Debug, Serialize, Deserialize)]
pub struct RpcAnimation {
pub mode: LightingMode,
Expand Down
2 changes: 2 additions & 0 deletions cherryrgb/src/vkbd.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(all(target_os = "linux", target_arch = "x86_64"))]

use log::error;
use uhid_virt::{Bus, CreateParams, UHIDDevice};

Expand Down

0 comments on commit 8bbe858

Please sign in to comment.