diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f3a409..60f10d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ GitHub are made from them (python3 tools/release.py notes X.Y.Z); CI checks the ## Unreleased +### New devices +- **67 more Razer keyboards, read only**: BlackWidow (from the 2012 Ultimate to the V4, V4 Pro, V4 75%, V4 X and the V4 Tenkeyless HyperSpeed models), Huntsman (Elite, Tournament Edition, Mini, V2, V2 Analog, V3 Pro and V3 HE), Ornata, Cynosa, DeathStalker, Anansi and Joro, the wireless ones also through their own HyperSpeed receiver. PeriHub reads the firmware and the layout, and where the keyboard has them the backlight brightness, the game mode and the battery; it changes nothing. The list and each keyboard's interface, wait and transaction ids are written from facts found in OpenRazer (GPL-2.0; no code copied) by `tools/openrazer_facts.py`. Nobody has tried one yet: a test report moves a keyboard up. On Linux only the BlackWidow V4 Mini HyperSpeed is opened for now: on most of the others the interface PeriHub would read also carries what is typed, so the udev rule does not open it, and **Send a report** lists the keyboard with its interfaces instead. + ### Fixed - **Steam and Epic Games games now show up in "Add from installed games" on Windows.** PeriHub only looked for Steam in `Program Files (x86)\Steam`, ignored the Epic Games Launcher, and only found a game's program when it sat directly in the game's folder (not in `bin\x64` or an Unreal game's `Binaries\Win64`). It now finds Steam where Windows says it is installed (also when it is not in Program Files), reads the Epic Games Launcher's list of installed games, and looks a few folders deep, preferring the real game program over launchers, crash reporters and installers. Games started from a folder with a very long path are also recognised as the app in focus. diff --git a/README.md b/README.md index a10f90b..e2c7c62 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ | **Logitech G9, G9x, G500, G700** with a cable | πŸ‘ Profile in use, DPI, polling rate and buttons | | 26 **Corsair mice** and 23 **Corsair keyboards** (KATAR, M65, M75, SCIMITAR, DARK CORE, K55, K70, K100…) | πŸ§ͺ Read, and one colour of lighting for the session, at your own risk | | 74 **Razer mice** (DeathAdder, Viper, Basilisk, Naga, Orochi…) on their USB cable | πŸ§ͺ Read; DPI, polling rate and the brightness of the lights can be saved at your own risk, and on 27 of them one colour can be sent without saving it | +| 69 **Razer keyboards** (BlackWidow, Huntsman, Ornata, Cynosa, DeathStalker…) | πŸ‘ Firmware, layout, backlight brightness, game mode and battery; on Linux only the BlackWidow V4 Mini HyperSpeed for now | | 33 **SteelSeries mice** (Rival, Sensei, Aerox, Prime, Kana, Kinzu) | πŸ§ͺ They cannot report their settings: DPI, polling rate, colours and effects are sent one at a time, never saved to the mouse | | 21 **ASUS ROG and TUF mice** (Chakram, Gladius II, Keris, Spatha X, Strix Impact, TUF Gaming M3…) | πŸ§ͺ Read; DPI, polling rate, button response, angle snapping and lighting can be changed at your own risk | | 3 **Glorious mice** (Model O/O-, Model D, Model O Eternal) with a cable | πŸ§ͺ Read; on Linux DPI and polling rate can be saved at your own risk, on Windows read-only for now | diff --git a/THIRD-PARTY-NOTICES.md b/THIRD-PARTY-NOTICES.md index 7f46536..005ce4f 100644 --- a/THIRD-PARTY-NOTICES.md +++ b/THIRD-PARTY-NOTICES.md @@ -503,8 +503,8 @@ was copied. and the Roccat Kone mice have. - [OpenRazer](https://github.com/openrazer/openrazer) (GPL-2.0): the Razer report layout and commands, and per mouse its USB interface, transaction ids, maximum DPI, lights with a brightness and custom frame width, read as text - by `tools/openrazer_facts.py` (see `docs/protocols/razer-mice.md`); for the BlackWidow V4 Mini HyperSpeed, its - interface, waits and transaction ids, and the battery, charging, brightness and game mode reads (see + by `tools/openrazer_facts.py` (see `docs/protocols/razer-mice.md`); per keyboard its USB interface, waits + and transaction ids, and the battery, charging, brightness and game mode reads, read as text by the same tool (see `docs/protocols/razer-keyboards.md`); the keyboard layout read and its region codes (see `docs/protocols/keyboard-layouts.md`). - [OpenMouse mouse-protocol](https://github.com/OpenMouse-Project/mouse-protocol) (AGPL-3.0), its K-Snake driver diff --git a/app/src/lib/credits.ts b/app/src/lib/credits.ts index 2487d82..be3366d 100644 --- a/app/src/lib/credits.ts +++ b/app/src/lib/credits.ts @@ -191,7 +191,7 @@ export const creditGroups: CreditGroup[] = [ link: "https://github.com/openrazer/openrazer", license: "GPL-2.0", notes: [ - "The Razer report layout and commands, and per mouse its USB interface, transaction ids, maximum DPI, lights with a brightness and custom frame width, read as text by tools/openrazer_facts.py (docs/protocols/razer-mice.md); for the BlackWidow V4 Mini HyperSpeed, its interface, waits and transaction ids, and the battery, charging, brightness and game mode reads (docs/protocols/razer-keyboards.md); the keyboard layout read and its region codes (docs/protocols/keyboard-layouts.md). " + NO_CODE, + "The Razer report layout and commands, and per mouse its USB interface, transaction ids, maximum DPI, lights with a brightness and custom frame width, read as text by tools/openrazer_facts.py (docs/protocols/razer-mice.md); per keyboard its USB interface, waits and transaction ids, and the battery, charging, brightness and game mode reads, read as text by the same tool (docs/protocols/razer-keyboards.md); the keyboard layout read and its region codes (docs/protocols/keyboard-layouts.md). " + NO_CODE, ], }, { diff --git a/app/src/lib/devices.generated.json b/app/src/lib/devices.generated.json index 49a7b85..67082c7 100644 --- a/app/src/lib/devices.generated.json +++ b/app/src/lib/devices.generated.json @@ -1114,6 +1114,301 @@ "kind": "mouse", "level": "experimental" }, + { + "name": "BlackWidow Ultimate 2012", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Stealth Edition", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Anansi", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker/DeathStalker Essential", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Ultimate 2013", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow (Classic)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Tournament Edition 2014", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker Expert", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Chroma", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker Chroma", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Tournament Edition Chroma", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Chroma (Overwatch)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Ultimate 2016", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow X Chroma", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow X Ultimate", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow X Tournament Edition Chroma", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata Chroma", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Chroma V2", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman Elite", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Elite", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Cynosa Chroma", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Cynosa Chroma Pro", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Lite", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow Essential", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Cynosa Lite", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow 2019", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman Tournament Edition", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V3", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman Mini", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V3 Mini HyperSpeed (Wired)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V3 Pro Wired", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V3 Pro 2.4 Ghz Wireless", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata V2", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Cynosa V2", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V2 Analog", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman Mini JP", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V2 Tenkeyless", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V2", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V3 Mini HyperSpeed (Wireless)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman Mini Analog", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4 Pro", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata V3 (Alternate)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker V2 Pro (Wireless)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker V2 Pro (Wired)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4 X", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata V3 X", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker V2", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker V2 Pro TKL (Wireless)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "DeathStalker V2 Pro TKL (Wired)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata V3", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata V3 X (Alternate)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Ornata V3 Tenkeyless", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4 75%", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V3 Pro", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V3 Pro TKL", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V3 Pro Mini", + "kind": "keyboard", + "level": "read_only" + }, { "name": "BlackWidow V4 Mini HyperSpeed", "kind": "keyboard", @@ -1123,6 +1418,46 @@ "name": "BlackWidow V4 Mini HyperSpeed (wireless)", "kind": "keyboard", "level": "read_only" + }, + { + "name": "Joro", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V3 Pro 8KHz", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wireless)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wired)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4 Tenkeyless HyperSpeed (Wireless)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V4 Tenkeyless HyperSpeed (Wired)", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "Huntsman V3 HE Magnetic Tenkeyless 8KHz", + "kind": "keyboard", + "level": "read_only" + }, + { + "name": "BlackWidow V3 TK", + "kind": "keyboard", + "level": "read_only" } ] }, diff --git a/crates/perihub-core/src/manager.rs b/crates/perihub-core/src/manager.rs index 70edc59..1813824 100644 --- a/crates/perihub-core/src/manager.rs +++ b/crates/perihub-core/src/manager.rs @@ -1171,9 +1171,10 @@ impl Manager { // A keyboard of another brand is opened only where nothing typed arrives (Linux; elsewhere the // system keeps typed keys away from programs). QMK keyboards were checked above, more strictly. found.retain(|(d, model)| { - // On Linux the Wraith's collection is opened only by a rule the user turns on: it can carry - // how far each key is pressed. That rule is not there yet. - if cfg!(target_os = "linux") && matches!(model.protocol, Protocol::Wraith(_)) { + // On Linux a model 70-perihub.rules does not open is not opened at all: the Wraith's collection + // can carry how far each key is pressed (it will need a rule the user turns on), and most Razer + // keyboards' interface also carries typed keys. + if cfg!(target_os = "linux") && !peripheral::opened_on_linux(model) { return false; } let typing = model.kind == peripheral::Kind::Keyboard diff --git a/crates/perihub-core/src/peripheral/mod.rs b/crates/perihub-core/src/peripheral/mod.rs index bcef6be..2c62d91 100644 --- a/crates/perihub-core/src/peripheral/mod.rs +++ b/crates/perihub-core/src/peripheral/mod.rs @@ -20,6 +20,8 @@ pub mod qmk; pub mod razer; pub mod razer_keyboard; #[rustfmt::skip] +pub mod razer_keyboard_models; +#[rustfmt::skip] pub mod razer_models; pub mod roccat; pub mod sinowealth; @@ -110,7 +112,7 @@ pub fn models() -> impl Iterator { .iter() .chain(steelseries_models::MODELS) .chain(razer_models::MODELS) - .chain(razer_keyboard::MODELS) + .chain(razer_keyboard_models::MODELS) .chain(sinowealth::MODELS) .chain(logitech_g600::MODELS) .chain(logitech_hidpp10::MODELS) @@ -127,6 +129,17 @@ pub fn find(vendor_id: u16, product_id: u16) -> Option<&'static Model> { models().find(|m| m.vendor_id == vendor_id && m.product_ids.contains(&product_id)) } +/// Whether 70-perihub.rules opens the model's configuration interface on Linux. Where it does not, +/// PeriHub does not open the model there either: the Wraith W60, whose collection can carry how far +/// each key is pressed, and the Razer keyboards whose interface may also carry typed keys. +pub fn opened_on_linux(model: &Model) -> bool { + match model.protocol { + Protocol::Wraith(_) => false, + Protocol::RazerKeyboard(p) => p.linux, + _ => true, + } +} + /// The vendors with a driver: only their devices are looked at. pub fn vendors() -> impl Iterator { let mut ids: Vec = models().map(|m| m.vendor_id).collect(); diff --git a/crates/perihub-core/src/peripheral/razer_keyboard.rs b/crates/perihub-core/src/peripheral/razer_keyboard.rs index c8b7819..daa1b2d 100644 --- a/crates/perihub-core/src/peripheral/razer_keyboard.rs +++ b/crates/perihub-core/src/peripheral/razer_keyboard.rs @@ -1,15 +1,18 @@ -//! Razer keyboards: for now the BlackWidow V4 Mini HyperSpeed, on its cable and through its -//! HyperSpeed receiver. The protocol is the one of the Razer mice (`docs/protocols/razer-mice.md`); -//! the keyboard's own facts are in `docs/protocols/razer-keyboards.md`, written from facts found in -//! OpenRazer (GPL-2.0): no code was copied. Nobody has tried it with PeriHub yet. +//! Razer keyboards, on their cable and through their own HyperSpeed receiver. The protocol is the +//! one of the Razer mice (`docs/protocols/razer-mice.md`); the keyboards' own facts are in +//! `docs/protocols/razer-keyboards.md`, and per model in [`super::razer_keyboard_models`], written by +//! `tools/openrazer_facts.py` from facts found in OpenRazer (GPL-2.0): no code was copied. Nobody has +//! tried one with PeriHub yet. //! -//! Only read for now: firmware, battery, charging, brightness and game mode. The reports go to USB -//! interface 3, which through the receiver holds only the media keys. On Linux a keyboard node that -//! carries typed keys is never opened (see [`super::node_carries_typing`]). +//! Only read for now: firmware, layout, and where the keyboard has them, battery, charging, +//! brightness and game mode. The reports go to the USB interface OpenRazer sends to (1, 2 or 3). On +//! Linux 70-perihub.rules opens it only where a tester showed it carries no typed keys (the +//! BlackWidow V4 Mini HyperSpeed's interface 3), and a keyboard node that carries typed keys is never +//! opened anyway (see [`super::node_carries_typing`]). use super::razer::exchange; use super::task::Driver; -use super::{Command, Effect, Io, Kind, Model, Protocol, Reading, Settings}; +use super::{Command, Effect, Io, Reading, Settings}; use crate::error::{Error, Result}; const VARSTORE: u8 = 0x01; @@ -22,6 +25,8 @@ const GET_FIRMWARE: [u8; 2] = [0x00, 0x81]; const GET_BATTERY: [u8; 2] = [0x07, 0x80]; const GET_CHARGING: [u8; 2] = [0x07, 0x84]; const GET_BRIGHTNESS: [u8; 2] = [0x0F, 0x84]; +/// The standard brightness read of the older keyboards. +const GET_STANDARD_BRIGHTNESS: [u8; 2] = [0x03, 0x83]; const GET_LED_STATE: [u8; 2] = [0x03, 0x80]; /// The keyboard's region, so its physical layout (see [`crate::kblayout::razer`]). const GET_LAYOUT: [u8; 2] = [0x00, 0x86]; @@ -38,50 +43,43 @@ pub const COMMANDS: &[Command] = &[ effect: Effect::Read, name: "read backlight brightness", }, + Command { + prefix: &[0x03, 0x83, VARSTORE, BACKLIGHT_LED], + at: 6, + effect: Effect::Read, + name: "read backlight brightness", + }, Command { prefix: &[0x03, 0x80, VARSTORE, GAME_LED], at: 6, effect: Effect::Read, name: "read game mode" }, Command { prefix: &GET_LAYOUT, at: 6, effect: Effect::Read, name: "read layout" }, ]; -/// What a keyboard needs, from OpenRazer: how long it takes to answer and the transaction id of -/// each command. +/// What a keyboard needs, from OpenRazer (written by `tools/openrazer_facts.py --keyboards` into +/// [`super::razer_keyboard_models`]): how long it takes to answer, and the transaction id of each read +/// it takes. The firmware and the layout are read with transaction id `ff` on every keyboard. #[derive(Debug, Clone, Copy)] pub struct Params { pub wait_us: u32, - pub tid_firmware: u8, - pub tid_battery: u8, - pub tid_brightness: u8, - pub tid_game: u8, + /// The battery and charging reads, on the keyboards with a battery. + pub battery: Option, + /// The backlight brightness read. + pub brightness: Option, + /// The game mode read. + pub game: Option, + /// 70-perihub.rules opens its interface on Linux: only where a tester showed that the interface + /// carries no typed keys (on most Razer keyboards the one OpenRazer sends to carries them). + pub linux: bool, } -/// On its cable: OpenRazer waits 600 Β΅s and sends battery and brightness with 0x1f. -const WIRED: Params = - Params { wait_us: 600, tid_firmware: 0xFF, tid_battery: 0x1F, tid_brightness: 0x1F, tid_game: 0xFF }; -/// Through the HyperSpeed receiver: 4.9 ms, and 0x9f. -const WIRELESS: Params = - Params { wait_us: 4900, tid_firmware: 0xFF, tid_battery: 0x9F, tid_brightness: 0x9F, tid_game: 0xFF }; +/// How a keyboard reads its backlight brightness: with the extended command (`0f 84`) or the +/// standard one (`03 83`), and its transaction id. +#[derive(Debug, Clone, Copy)] +pub struct Brightness { + pub standard: bool, + pub tid: u8, +} -pub const MODELS: &[Model] = &[ - Model { - vendor_id: 0x1532, - product_ids: &[0x02B9], - brand: "Razer", - name: "BlackWidow V4 Mini HyperSpeed", - kind: Kind::Keyboard, - interface: Some(3), - usage_page: None, - protocol: Protocol::RazerKeyboard(WIRED), - }, - Model { - vendor_id: 0x1532, - product_ids: &[0x02BA], - brand: "Razer", - name: "BlackWidow V4 Mini HyperSpeed (wireless)", - kind: Kind::Keyboard, - interface: Some(3), - usage_page: None, - protocol: Protocol::RazerKeyboard(WIRELESS), - }, -]; +/// The transaction id of the firmware and layout reads on every keyboard. +const TID_FF: u8 = 0xFF; /// 0–255 in percent. fn percent(raw: u8) -> u8 { @@ -123,9 +121,9 @@ impl Driver for RazerKeyboard { // Only read for now: the page shows it read-only. io.forbid_changes(); let p = self.p; - // For the test report: whether interface 3 declares the 90-byte feature report. + // For the test report: whether the interface declares the 90-byte feature report. let _ = io.report_descriptor(); - let fw = match self.query(io, p.tid_firmware, GET_FIRMWARE, 0x02, &[]) { + let fw = match self.query(io, TID_FF, GET_FIRMWARE, 0x02, &[]) { Ok(fw) => fw, // Off, asleep or away from the receiver, or a status the keyboard was not expected to // give: the page and its test report show it, and it is read again every few seconds. @@ -142,31 +140,44 @@ impl Driver for RazerKeyboard { }; let mut problems = Vec::new(); let mut details = Vec::new(); - let level = self.query(io, p.tid_battery, GET_BATTERY, 0x02, &[])?[1]; - let charging = self.query(io, p.tid_battery, GET_CHARGING, 0x02, &[])?[1]; - if charging > 1 { - problems.push(format!("charging state {charging:02x}")); - } + let battery = match p.battery { + Some(tid) => { + let level = self.query(io, tid, GET_BATTERY, 0x02, &[])?[1]; + let charging = self.query(io, tid, GET_CHARGING, 0x02, &[])?[1]; + if charging > 1 { + problems.push(format!("charging state {charging:02x}")); + } + Some((percent(level), charging == 1)) + } + None => None, + }; // A keyboard that does not take one of the light reads is shown without it. - match self.query(io, p.tid_brightness, GET_BRIGHTNESS, 0x03, &[VARSTORE, BACKLIGHT_LED]) { - Ok(a) if a[1] == BACKLIGHT_LED => { - details.push(("Backlight brightness".into(), format!("{} %", percent(a[2])))) + if let Some(b) = p.brightness { + let command = if b.standard { GET_STANDARD_BRIGHTNESS } else { GET_BRIGHTNESS }; + match self.query(io, b.tid, command, 0x03, &[VARSTORE, BACKLIGHT_LED]) { + Ok(a) if a[1] == BACKLIGHT_LED => { + details.push(("Backlight brightness".into(), format!("{} %", percent(a[2])))) + } + Ok(a) => problems.push(format!("brightness answered for LED {:02x}", a[1])), + Err(Error::Invalid(_)) => { + details.push(("Backlight brightness".into(), "not read: not supported".into())) + } + Err(e) => return Err(e), } - Ok(a) => problems.push(format!("brightness answered for LED {:02x}", a[1])), - Err(Error::Invalid(_)) => details.push(("Backlight brightness".into(), "not read: not supported".into())), - Err(e) => return Err(e), } - match self.query(io, p.tid_game, GET_LED_STATE, 0x03, &[VARSTORE, GAME_LED]) { - Ok(a) if a[1] == GAME_LED && a[2] <= 1 => { - details.push(("Game mode".into(), if a[2] == 1 { "on" } else { "off" }.into())) + if let Some(tid) = p.game { + match self.query(io, tid, GET_LED_STATE, 0x03, &[VARSTORE, GAME_LED]) { + Ok(a) if a[1] == GAME_LED && a[2] <= 1 => { + details.push(("Game mode".into(), if a[2] == 1 { "on" } else { "off" }.into())) + } + Ok(a) => problems.push(format!("game mode answered {:02x} {:02x}", a[1], a[2])), + Err(Error::Invalid(_)) => details.push(("Game mode".into(), "not read: not supported".into())), + Err(e) => return Err(e), } - Ok(a) => problems.push(format!("game mode answered {:02x} {:02x}", a[1], a[2])), - Err(Error::Invalid(_)) => details.push(("Game mode".into(), "not read: not supported".into())), - Err(e) => return Err(e), } // Its layout, with the firmware's transaction id as OpenRazer sends it. A keyboard that does // not take it leaves the layout to the system. - let layout = match self.query(io, p.tid_firmware, GET_LAYOUT, 0x02, &[]) { + let layout = match self.query(io, TID_FF, GET_LAYOUT, 0x02, &[]) { Ok(a) => Some(crate::kblayout::razer(a[0])), Err(Error::Invalid(_)) => None, Err(e) => return Err(e), @@ -174,7 +185,7 @@ impl Driver for RazerKeyboard { Ok(Reading { firmware: Some(format!("v{}.{}", fw[0], fw[1])), layout, - battery: Some((percent(level), charging == 1)), + battery, details, problem: (!problems.is_empty()).then(|| format!("unexpected answer: {}", problems.join(", "))), ..Default::default() @@ -197,7 +208,7 @@ mod tests { use super::super::fake::FakeHid; use super::super::razer::request; use super::super::task::start_for_test; - use super::super::{Kind, find}; + use super::super::{Kind, Protocol, find, models, opened_on_linux}; use super::*; /// A simulated V4 Mini: battery 0xcc (80 %), charging, brightness 0x80, game mode on. Records @@ -224,6 +235,104 @@ mod tests { hid } + fn params(id: u16) -> Params { + match find(0x1532, id).unwrap().protocol { + Protocol::RazerKeyboard(p) => p, + _ => panic!("{id:04x} is not a Razer keyboard"), + } + } + + #[test] + fn every_razer_keyboard_is_a_keyboard_on_the_interface_openrazer_names_and_only_read() { + let keyboards: Vec<_> = models().filter(|m| matches!(m.protocol, Protocol::RazerKeyboard(_))).collect(); + assert!(keyboards.len() >= 60, "{}", keyboards.len()); + for m in keyboards { + assert_eq!(m.kind, Kind::Keyboard, "{}", m.name); + assert!(matches!(m.interface, Some(1..=3)), "{}", m.name); + assert_eq!(m.product_ids.len(), 1, "{}", m.name); + // No mouse, receiver or other device of the tables has the same id. + assert!(std::ptr::eq(find(0x1532, m.product_ids[0]).unwrap(), m), "{}", m.name); + // Linux: only where the interface was seen to carry no typed keys. + assert_eq!(opened_on_linux(m), matches!(m.product_ids[0], 0x02B9 | 0x02BA), "{}", m.name); + } + assert!(COMMANDS.iter().all(|c| c.effect == Effect::Read)); + } + + #[test] + fn the_facts_of_a_few_keyboards_are_the_ones_openrazer_gives() { + // BlackWidow V3: interface 3, extended brightness with 3f, no battery. + let p = params(0x024E); + assert_eq!(find(0x1532, 0x024E).unwrap().interface, Some(3)); + assert!(matches!(p.brightness, Some(Brightness { standard: false, tid: 0x3F }))); + assert_eq!((p.battery, p.game, p.wait_us), (None, Some(0xFF), 600)); + // BlackWidow Chroma: interface 1, the standard brightness read. + assert_eq!(find(0x1532, 0x0203).unwrap().interface, Some(1)); + assert!(matches!(params(0x0203).brightness, Some(Brightness { standard: true, tid: 0xFF }))); + // Huntsman V2: its game mode is read from another storage, which PeriHub does not send. + assert_eq!(params(0x026C).game, None); + // DeathStalker V2 Pro through its receiver: interface 2, 4.9 ms, battery with 9f. + let p = params(0x0290); + assert_eq!(find(0x1532, 0x0290).unwrap().interface, Some(2)); + assert_eq!((p.battery, p.wait_us), (Some(0x9F), 4900)); + // The BlackWidow V4 Mini HyperSpeed as before. + let (wired, wireless) = (params(0x02B9), params(0x02BA)); + assert_eq!((wired.battery, wired.wait_us, wired.linux), (Some(0x1F), 600, true)); + assert_eq!((wireless.battery, wireless.wait_us, wireless.linux), (Some(0x9F), 4900, true)); + } + + /// A simulated BlackWidow Chroma: no battery, the standard brightness read (0x40), game mode off. + fn chroma(sent: Arc>>>) -> FakeHid { + let hid = FakeHid::new(|_| Vec::new()); + hid.0.lock().unwrap().on_feature = Some(Box::new(move |req: &[u8]| { + sent.lock().unwrap().push(req.to_vec()); + let mut a = req.to_vec(); + a[0] = 0x02; + match ([req[6], req[7]], req[1]) { + (GET_FIRMWARE, 0xFF) => a[8..10].copy_from_slice(&[2, 4]), + (GET_STANDARD_BRIGHTNESS, 0xFF) => a[10] = 0x40, + (GET_LED_STATE, 0xFF) => a[10] = 0, + (GET_LAYOUT, 0xFF) => a[8] = 0x01, + _ => a[0] = 0x05, + } + a + })); + hid + } + + #[test] + fn a_wired_keyboard_is_not_asked_for_a_battery_and_reads_the_standard_brightness() { + let sent = Arc::new(Mutex::new(Vec::new())); + let model = find(0x1532, 0x0203).unwrap(); + let backups = std::env::temp_dir().join(format!("perihub-test-razer-kb-chroma-{}", std::process::id())); + let task = start_for_test(Box::new(chroma(sent.clone())), model, 0x0203, true, backups).unwrap(); + let info = &task.info; + assert_eq!(info.firmware.as_deref(), Some("v2.4")); + assert!(info.battery.is_none()); + assert!(info.details.contains(&("Backlight brightness".into(), "25 %".into())), "{:?}", info.details); + assert!(info.details.contains(&("Game mode".into(), "off".into()))); + assert_eq!(info.problem, None); + assert!(!info.editable); + let sent = sent.lock().unwrap(); + assert!( + !sent + .iter() + .any(|r| [r[6], r[7]] == GET_BATTERY || [r[6], r[7]] == GET_CHARGING || [r[6], r[7]] == GET_BRIGHTNESS) + ); + for req in sent.iter() { + assert!(COMMANDS.iter().any(|c| req[6..].starts_with(c.prefix)), "{req:02x?}"); + } + } + + #[test] + fn a_keyboard_without_a_game_mode_read_is_not_asked_for_it() { + let sent = Arc::new(Mutex::new(Vec::new())); + let model = find(0x1532, 0x026C).unwrap(); + let backups = std::env::temp_dir().join(format!("perihub-test-razer-kb-huntsman-{}", std::process::id())); + let task = start_for_test(Box::new(fake(sent.clone(), 0x02, false)), model, 0x026C, true, backups).unwrap(); + assert!(!task.info.details.iter().any(|(k, _)| k == "Game mode"), "{:?}", task.info.details); + assert!(!sent.lock().unwrap().iter().any(|r| [r[6], r[7]] == GET_LED_STATE)); + } + #[test] fn both_ids_are_keyboards_on_interface_3() { for id in [0x02B9, 0x02BA] { diff --git a/crates/perihub-core/src/peripheral/razer_keyboard_models.rs b/crates/perihub-core/src/peripheral/razer_keyboard_models.rs new file mode 100644 index 0000000..f8ba574 --- /dev/null +++ b/crates/perihub-core/src/peripheral/razer_keyboard_models.rs @@ -0,0 +1,1174 @@ +//! Generated by tools/openrazer_facts.py --keyboards from facts in OpenRazer +//! (https://github.com/openrazer/openrazer, GPL-2.0, commit cd5c4243bfafb08df7e2d2963367c3c150626eac): product ids, the USB +//! interface of the reports, the wait before the answer and the transaction id of each read. No code +//! was copied. Do not edit by hand. + +use super::razer_keyboard::{Brightness, Params}; +use super::{Kind, Model, Protocol}; + +pub const MODELS: &[Model] = &[ + Model { + vendor_id: 0x1532, + product_ids: &[0x010D], + brand: "Razer", + name: "BlackWidow Ultimate 2012", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: None, + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x010E], + brand: "Razer", + name: "BlackWidow Stealth Edition", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: None, + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x010F], + brand: "Razer", + name: "Anansi", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0118], + brand: "Razer", + name: "DeathStalker/DeathStalker Essential", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x011A], + brand: "Razer", + name: "BlackWidow Ultimate 2013", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: None, + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x011B], + brand: "Razer", + name: "BlackWidow (Classic)", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: None, + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x011C], + brand: "Razer", + name: "BlackWidow Tournament Edition 2014", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: None, + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0202], + brand: "Razer", + name: "DeathStalker Expert", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0203], + brand: "Razer", + name: "BlackWidow Chroma", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0204], + brand: "Razer", + name: "DeathStalker Chroma", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0209], + brand: "Razer", + name: "BlackWidow Tournament Edition Chroma", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0211], + brand: "Razer", + name: "BlackWidow Chroma (Overwatch)", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0214], + brand: "Razer", + name: "BlackWidow Ultimate 2016", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0216], + brand: "Razer", + name: "BlackWidow X Chroma", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0217], + brand: "Razer", + name: "BlackWidow X Ultimate", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x021A], + brand: "Razer", + name: "BlackWidow X Tournament Edition Chroma", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x021E], + brand: "Razer", + name: "Ornata Chroma", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x021F], + brand: "Razer", + name: "Ornata", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0221], + brand: "Razer", + name: "BlackWidow Chroma V2", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0226], + brand: "Razer", + name: "Huntsman Elite", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0227], + brand: "Razer", + name: "Huntsman", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0228], + brand: "Razer", + name: "BlackWidow Elite", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x022A], + brand: "Razer", + name: "Cynosa Chroma", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x022C], + brand: "Razer", + name: "Cynosa Chroma Pro", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0235], + brand: "Razer", + name: "BlackWidow Lite", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0237], + brand: "Razer", + name: "BlackWidow Essential", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x023F], + brand: "Razer", + name: "Cynosa Lite", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0241], + brand: "Razer", + name: "BlackWidow 2019", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0243], + brand: "Razer", + name: "Huntsman Tournament Edition", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x024E], + brand: "Razer", + name: "BlackWidow V3", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0257], + brand: "Razer", + name: "Huntsman Mini", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0258], + brand: "Razer", + name: "BlackWidow V3 Mini HyperSpeed (Wired)", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x1F), + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x025A], + brand: "Razer", + name: "BlackWidow V3 Pro Wired", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x3F), + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x025C], + brand: "Razer", + name: "BlackWidow V3 Pro 2.4 Ghz Wireless", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 4900, + battery: Some(0x9F), + brightness: Some(Brightness { standard: false, tid: 0x9F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x025D], + brand: "Razer", + name: "Ornata V2", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x025E], + brand: "Razer", + name: "Cynosa V2", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0266], + brand: "Razer", + name: "Huntsman V2 Analog", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0269], + brand: "Razer", + name: "Huntsman Mini JP", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x026B], + brand: "Razer", + name: "Huntsman V2 Tenkeyless", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: None, + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x026C], + brand: "Razer", + name: "Huntsman V2", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: None, + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0271], + brand: "Razer", + name: "BlackWidow V3 Mini HyperSpeed (Wireless)", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 4900, + battery: Some(0x9F), + brightness: Some(Brightness { standard: false, tid: 0x9F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0282], + brand: "Razer", + name: "Huntsman Mini Analog", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0287], + brand: "Razer", + name: "BlackWidow V4", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x028D], + brand: "Razer", + name: "BlackWidow V4 Pro", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x028F], + brand: "Razer", + name: "Ornata V3 (Alternate)", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0290], + brand: "Razer", + name: "DeathStalker V2 Pro (Wireless)", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 4900, + battery: Some(0x9F), + brightness: Some(Brightness { standard: false, tid: 0x9F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0292], + brand: "Razer", + name: "DeathStalker V2 Pro (Wired)", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x1F), + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0293], + brand: "Razer", + name: "BlackWidow V4 X", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0294], + brand: "Razer", + name: "Ornata V3 X", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0295], + brand: "Razer", + name: "DeathStalker V2", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0296], + brand: "Razer", + name: "DeathStalker V2 Pro TKL (Wireless)", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 4900, + battery: Some(0x9F), + brightness: Some(Brightness { standard: false, tid: 0x9F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0298], + brand: "Razer", + name: "DeathStalker V2 Pro TKL (Wired)", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x1F), + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02A1], + brand: "Razer", + name: "Ornata V3", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02A2], + brand: "Razer", + name: "Ornata V3 X (Alternate)", + kind: Kind::Keyboard, + interface: Some(1), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02A3], + brand: "Razer", + name: "Ornata V3 Tenkeyless", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02A5], + brand: "Razer", + name: "BlackWidow V4 75%", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02A6], + brand: "Razer", + name: "Huntsman V3 Pro", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02A7], + brand: "Razer", + name: "Huntsman V3 Pro TKL", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: None, + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02B0], + brand: "Razer", + name: "Huntsman V3 Pro Mini", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02B9], + brand: "Razer", + name: "BlackWidow V4 Mini HyperSpeed", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x1F), + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: true, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02BA], + brand: "Razer", + name: "BlackWidow V4 Mini HyperSpeed (wireless)", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 4900, + battery: Some(0x9F), + brightness: Some(Brightness { standard: false, tid: 0x9F }), + game: Some(0xFF), + linux: true, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02CD], + brand: "Razer", + name: "Joro", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x1F), + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02CF], + brand: "Razer", + name: "Huntsman V3 Pro 8KHz", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02D2], + brand: "Razer", + name: "BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wireless)", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 4900, + battery: Some(0x9F), + brightness: Some(Brightness { standard: false, tid: 0x9F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02D4], + brand: "Razer", + name: "BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wired)", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x1F), + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02D5], + brand: "Razer", + name: "BlackWidow V4 Tenkeyless HyperSpeed (Wireless)", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 4900, + battery: Some(0x9F), + brightness: Some(Brightness { standard: false, tid: 0x9F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02D7], + brand: "Razer", + name: "BlackWidow V4 Tenkeyless HyperSpeed (Wired)", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: Some(0x1F), + brightness: Some(Brightness { standard: false, tid: 0x1F }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x02EA], + brand: "Razer", + name: "Huntsman V3 HE Magnetic Tenkeyless 8KHz", + kind: Kind::Keyboard, + interface: Some(3), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: true, tid: 0xFF }), + game: Some(0xFF), + linux: false, + }), + }, + Model { + vendor_id: 0x1532, + product_ids: &[0x0A24], + brand: "Razer", + name: "BlackWidow V3 TK", + kind: Kind::Keyboard, + interface: Some(2), + usage_page: None, + protocol: Protocol::RazerKeyboard(Params { + wait_us: 600, + battery: None, + brightness: Some(Brightness { standard: false, tid: 0x3F }), + game: Some(0xFF), + linux: false, + }), + }, +]; + +/// OpenRazer keyboards PeriHub leaves out, and why. +pub const LEFT_OUT: &[&str] = &[ + "USB_DEVICE_ID_RAZER_NOSTROMO (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_ORBWEAVER (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_TARTARUS (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_ORBWEAVER_CHROMA (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_TARTARUS_CHROMA (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_QHD (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_PRO_LATE_2016 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH_LATE_2016 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_LATE_2016 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_PRO_2017 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_TARTARUS_V2 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH_MID_2017 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_PRO_2017_FULLHD (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH_LATE_2017 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_2018 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_PRO_2019 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH_2019 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_2019_ADV (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_2018_BASE (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_2018_MERCURY (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_TARTARUS_PRO (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_MID_2019_MERCURY (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_2019_BASE (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH_LATE_2019 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_ADV_LATE_2019 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_PRO_LATE_2019 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STUDIO_EDITION_2019 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH_EARLY_2020 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_15_ADV_2020 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_EARLY_2020_BASE (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_PRO_EARLY_2020 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_STEALTH_LATE_2020 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_LATE_2020_BASE (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BOOK_2020 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_15_ADV_EARLY_2021 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_17_PRO_EARLY_2021 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_15_BASE_EARLY_2021 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_14_2021 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_15_ADV_MID_2021 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_17_PRO_MID_2021 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_15_BASE_2022 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_15_ADV_EARLY_2022 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_17_2022 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_14_2022 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_14_2023 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_15_2023 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_16_2023 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_18_2023 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_14_2024 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_18_2024 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_14_2025 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_16_2025 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_18_2025 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_16_2026 (not a keyboard, or built into a laptop)", + "USB_DEVICE_ID_RAZER_BLADE_18_2026 (not a keyboard, or built into a laptop)", +]; diff --git a/crates/perihub-core/src/report_devices.rs b/crates/perihub-core/src/report_devices.rs index f3a36e2..756a23b 100644 --- a/crates/perihub-core/src/report_devices.rs +++ b/crates/perihub-core/src/report_devices.rs @@ -65,7 +65,9 @@ impl Entry { } } -/// A device PeriHub opens, or names, by itself: it has its own entry in the interface already. +/// A device PeriHub opens, or names, by itself: it has its own entry in the interface already. On +/// Linux a model PeriHub does not open there (see [`peripheral::opened_on_linux`]) is listed, so that a +/// device request can show what its interfaces carry. pub fn known(vendor_id: u16, product_id: u16) -> bool { match vendor_id { STEELSERIES if STEELSERIES_KEYBOARDS.contains(&product_id) => true, @@ -74,7 +76,8 @@ pub fn known(vendor_id: u16, product_id: u16) -> bool { corsair::CORSAIR if corsair::models::find(product_id).is_some() || corsair::models::is_receiver(product_id) => { true } - _ => peripheral::find(vendor_id, product_id).is_some(), + _ => peripheral::find(vendor_id, product_id) + .is_some_and(|m| !cfg!(target_os = "linux") || peripheral::opened_on_linux(m)), } } @@ -161,4 +164,11 @@ mod tests { let names: Vec<_> = devices.iter().map(|d| d.product.as_deref().unwrap()).collect(); assert_eq!(names, ["A Logitech headset"]); } + + #[test] + fn a_keyboard_perihub_does_not_open_on_linux_is_listed_there() { + let devices = unknown_devices([entry(0x1532, 0x0203, Some("BlackWidow Chroma"), 1, 1, 6)]); + assert_eq!(devices.len(), usize::from(cfg!(target_os = "linux"))); + assert!(unknown_devices([entry(0x1532, 0x02B9, Some("BlackWidow V4 Mini"), 3, 0x0C, 1)]).is_empty()); + } } diff --git a/crates/perihub-core/tests/udev_rule.rs b/crates/perihub-core/tests/udev_rule.rs index a4b1971..04bd823 100644 --- a/crates/perihub-core/tests/udev_rule.rs +++ b/crates/perihub-core/tests/udev_rule.rs @@ -112,6 +112,10 @@ fn udev_rule_matches_the_other_brands_tables() { .collect(); let mut in_tables = Vec::new(); for model in models().filter(|m| m.vendor_id == vendor) { + // Models PeriHub does not open on Linux have no line (checked below). + if !perihub_core::peripheral::opened_on_linux(model) { + continue; + } for id in model.product_ids { let id = format!("{id:04x}"); let line = lines.iter().find(|l| l.contains(&format!(r#"ATTRS{{idProduct}}=="{id}""#))).unwrap(); @@ -146,3 +150,19 @@ fn udev_rule_never_opens_the_wraith_keyboard() { assert!(!line.contains(r#"ATTRS{idVendor}=="2e3c""#), "{line}"); } } + +#[test] +fn udev_rule_never_opens_a_razer_keyboard_whose_interface_may_carry_typing() { + use perihub_core::peripheral::{Protocol, models, opened_on_linux}; + let keyboards: Vec<_> = models().filter(|m| matches!(m.protocol, Protocol::RazerKeyboard(_))).collect(); + assert!(keyboards.len() > 2); + for model in keyboards { + for id in model.product_ids { + let tag = format!(r#"ATTRS{{idVendor}}=="1532", ATTRS{{idProduct}}=="{id:04x}""#); + let opened = RULE.lines().any(|l| !l.trim_start().starts_with('#') && l.contains(&tag)); + assert_eq!(opened, opened_on_linux(model), "{} {id:04x}", model.name); + // Only the BlackWidow V4 Mini HyperSpeed, whose interface 3 a tester showed (issue #24). + assert_eq!(opened, matches!(id, 0x02B9 | 0x02BA), "{} {id:04x}", model.name); + } + } +} diff --git a/crates/xtask/src/catalog.rs b/crates/xtask/src/catalog.rs index 4531980..b91cb73 100644 --- a/crates/xtask/src/catalog.rs +++ b/crates/xtask/src/catalog.rs @@ -250,10 +250,14 @@ pub fn devices() -> Vec { PeripheralKind::Mouse => Kind::Mouse, PeripheralKind::Keyboard => Kind::Keyboard, }; - // The Wraith W60's configuration collection can carry how far each key is pressed: on Linux it - // is opened only by a rule the user turns on (perihub-core/src/manager.rs), never by 70-perihub.rules. - let access = - if family == "wraith" { Access::Closed } else { m.interface.map_or(Access::Whole, Access::Interface) }; + // Not opened by 70-perihub.rules: the Wraith W60, whose configuration collection can carry how far + // each key is pressed, and the Razer keyboards whose interface may carry typed keys + // (perihub-core/src/peripheral/mod.rs). + let access = if !peripheral::opened_on_linux(m) { + Access::Closed + } else { + m.interface.map_or(Access::Whole, Access::Interface) + }; list.push(device( family, m.brand, diff --git a/crates/xtask/src/udev.rs b/crates/xtask/src/udev.rs index e7672f3..8cf797b 100644 --- a/crates/xtask/src/udev.rs +++ b/crates/xtask/src/udev.rs @@ -64,9 +64,11 @@ on some newer mice). Interface 0 also carries the mouse's movements and clicks, above. Receivers and docks are left out: some can be shared with a keyboard."# } "razer-keyboard" => { - r#"Razer keyboards (read only, untested; facts from OpenRazer): only interface 3, the one OpenRazer sends -to. Through the receiver it holds only the media keys. PeriHub also reads each keyboard node's report -descriptor and does not open one that carries typed keys. The receiver (02ba) belongs to this keyboard alone."# + r#"Razer keyboards (read only, untested; facts from OpenRazer): only the BlackWidow V4 Mini HyperSpeed's +interface 3, the one OpenRazer sends to. Through the receiver it holds only the media keys. PeriHub also +reads each keyboard node's report descriptor and does not open one that carries typed keys. The receiver +(02ba) belongs to this keyboard alone. The other Razer keyboards PeriHub reads are left out on Linux for +now: on most of them the interface OpenRazer sends to also carries typed keys."# } "yjx" => { r#"Mice on the YJX platform (MAMBASNAKE, Rajin, K-Snake, EWEADN…; read only, untested): only interface 2, diff --git a/docs/devices.md b/docs/devices.md index fd2d9f4..d0b9947 100644 --- a/docs/devices.md +++ b/docs/devices.md @@ -429,21 +429,94 @@ is described in [protocols/razer-mice.md](protocols/razer-mice.md), from facts f πŸ‘ Read-only: nobody has tried PeriHub on one yet. The protocol is the one of the Razer mice, from facts found in [OpenRazer](https://github.com/openrazer/openrazer) (GPL-2.0), described in -[protocols/razer-keyboards.md](protocols/razer-keyboards.md): no code was copied. +[protocols/razer-keyboards.md](protocols/razer-keyboards.md): no code was copied. The list below is written from +OpenRazer's tables by `tools/openrazer_facts.py`; Razer laptops and keypads (Tartarus, Orbweaver, Nostromo) are left out. -- **BlackWidow V4 Mini HyperSpeed**, on its cable and through its HyperSpeed receiver (the receiver belongs to this - keyboard alone): PeriHub reads the firmware, the battery and whether it is charging, the backlight brightness and - the game mode, and changes nothing. +- PeriHub reads the firmware and the layout, and where OpenRazer reads them on that keyboard, the backlight + brightness, the game mode, and on the wireless ones the battery and whether it is charging. It changes nothing. +- Wireless keyboards are recognized on their cable and through their own HyperSpeed receiver, where OpenRazer gives + that receiver to the keyboard alone. - Left out: lighting effects (OpenRazer stores them in the keyboard's memory and nothing reads them back, so one could not be undone), changing the brightness and the game mode, macros, key remapping and profiles. -- On Linux only interface 3 is opened, and PeriHub reads the report descriptor of a keyboard's node first: a node that +- **On Linux only the BlackWidow V4 Mini HyperSpeed for now.** On most Razer keyboards the interface OpenRazer sends + to also carries what is typed, and the udev rule would let any program read it, so the rule opens only interface 3 + of the V4 Mini, which a tester showed holds only the media keys. The others are read on Windows, where the system + keeps typed keys from programs. On Linux, **Send a report** lists such a keyboard with its interfaces, which is what + is needed to open it there safely. PeriHub also reads the report descriptor of a keyboard's node first: a node that declares typed keys is never opened, whatever rule gave access to it. | Keyboard | USB ID | Opened on Linux | |---|---|---| +| BlackWidow Ultimate 2012 | `1532:010d` | β€” | +| BlackWidow Stealth Edition | `1532:010e` | β€” | +| Anansi | `1532:010f` | β€” | +| DeathStalker/DeathStalker Essential | `1532:0118` | β€” | +| BlackWidow Ultimate 2013 | `1532:011a` | β€” | +| BlackWidow (Classic) | `1532:011b` | β€” | +| BlackWidow Tournament Edition 2014 | `1532:011c` | β€” | +| DeathStalker Expert | `1532:0202` | β€” | +| BlackWidow Chroma | `1532:0203` | β€” | +| DeathStalker Chroma | `1532:0204` | β€” | +| BlackWidow Tournament Edition Chroma | `1532:0209` | β€” | +| BlackWidow Chroma (Overwatch) | `1532:0211` | β€” | +| BlackWidow Ultimate 2016 | `1532:0214` | β€” | +| BlackWidow X Chroma | `1532:0216` | β€” | +| BlackWidow X Ultimate | `1532:0217` | β€” | +| BlackWidow X Tournament Edition Chroma | `1532:021a` | β€” | +| Ornata Chroma | `1532:021e` | β€” | +| Ornata | `1532:021f` | β€” | +| BlackWidow Chroma V2 | `1532:0221` | β€” | +| Huntsman Elite | `1532:0226` | β€” | +| Huntsman | `1532:0227` | β€” | +| BlackWidow Elite | `1532:0228` | β€” | +| Cynosa Chroma | `1532:022a` | β€” | +| Cynosa Chroma Pro | `1532:022c` | β€” | +| BlackWidow Lite | `1532:0235` | β€” | +| BlackWidow Essential | `1532:0237` | β€” | +| Cynosa Lite | `1532:023f` | β€” | +| BlackWidow 2019 | `1532:0241` | β€” | +| Huntsman Tournament Edition | `1532:0243` | β€” | +| BlackWidow V3 | `1532:024e` | β€” | +| Huntsman Mini | `1532:0257` | β€” | +| BlackWidow V3 Mini HyperSpeed (Wired) | `1532:0258` | β€” | +| BlackWidow V3 Pro Wired | `1532:025a` | β€” | +| BlackWidow V3 Pro 2.4 Ghz Wireless | `1532:025c` | β€” | +| Ornata V2 | `1532:025d` | β€” | +| Cynosa V2 | `1532:025e` | β€” | +| Huntsman V2 Analog | `1532:0266` | β€” | +| Huntsman Mini JP | `1532:0269` | β€” | +| Huntsman V2 Tenkeyless | `1532:026b` | β€” | +| Huntsman V2 | `1532:026c` | β€” | +| BlackWidow V3 Mini HyperSpeed (Wireless) | `1532:0271` | β€” | +| Huntsman Mini Analog | `1532:0282` | β€” | +| BlackWidow V4 | `1532:0287` | β€” | +| BlackWidow V4 Pro | `1532:028d` | β€” | +| Ornata V3 (Alternate) | `1532:028f` | β€” | +| DeathStalker V2 Pro (Wireless) | `1532:0290` | β€” | +| DeathStalker V2 Pro (Wired) | `1532:0292` | β€” | +| BlackWidow V4 X | `1532:0293` | β€” | +| Ornata V3 X | `1532:0294` | β€” | +| DeathStalker V2 | `1532:0295` | β€” | +| DeathStalker V2 Pro TKL (Wireless) | `1532:0296` | β€” | +| DeathStalker V2 Pro TKL (Wired) | `1532:0298` | β€” | +| Ornata V3 | `1532:02a1` | β€” | +| Ornata V3 X (Alternate) | `1532:02a2` | β€” | +| Ornata V3 Tenkeyless | `1532:02a3` | β€” | +| BlackWidow V4 75% | `1532:02a5` | β€” | +| Huntsman V3 Pro | `1532:02a6` | β€” | +| Huntsman V3 Pro TKL | `1532:02a7` | β€” | +| Huntsman V3 Pro Mini | `1532:02b0` | β€” | | BlackWidow V4 Mini HyperSpeed | `1532:02b9` | interface 3 | | BlackWidow V4 Mini HyperSpeed (wireless) | `1532:02ba` | interface 3 | +| Joro | `1532:02cd` | β€” | +| Huntsman V3 Pro 8KHz | `1532:02cf` | β€” | +| BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wireless) | `1532:02d2` | β€” | +| BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wired) | `1532:02d4` | β€” | +| BlackWidow V4 Tenkeyless HyperSpeed (Wireless) | `1532:02d5` | β€” | +| BlackWidow V4 Tenkeyless HyperSpeed (Wired) | `1532:02d7` | β€” | +| Huntsman V3 HE Magnetic Tenkeyless 8KHz | `1532:02ea` | β€” | +| BlackWidow V3 TK | `1532:0a24` | β€” | ## Glorious mice diff --git a/docs/protocols/razer-keyboards.md b/docs/protocols/razer-keyboards.md index 965c534..706fbf6 100644 --- a/docs/protocols/razer-keyboards.md +++ b/docs/protocols/razer-keyboards.md @@ -3,9 +3,27 @@ How PeriHub reads a Razer keyboard. **No keyboard has been tried with PeriHub yet**, and for now PeriHub only reads. The transport is the one of the Razer mice (`razer-mice.md`): one 90-byte feature report, number 0, read back after a wait, with the status, transaction id, command class and id, arguments and an XOR checksum. The -facts below were found in [OpenRazer](https://github.com/openrazer/openrazer) (GPL-2.0, commit dfe987c) and are +facts below were found in [OpenRazer](https://github.com/openrazer/openrazer) (GPL-2.0, commit cd5c424) and are written here in PeriHub's own words. No code was copied. +The facts of each keyboard are written into `crates/perihub-core/src/peripheral/razer_keyboard_models.rs` by +`tools/openrazer_facts.py --keyboards`, which reads OpenRazer's keyboard driver and daemon as text. It leaves out +Razer laptops and keypads (Tartarus, Orbweaver, Nostromo), and any product id another OpenRazer driver also +claims, such as a receiver shared with a mouse. + +## Per keyboard + +| | Where it comes from in OpenRazer | Values | +|---|---|---| +| USB interface of the reports | the interface the keyboard driver sends its requests to and reads the answers from (the index of the USB request) | 1 on most keyboards, 2 or 3 on the newer ones | +| Wait before reading the answer | the same place | 600 Β΅s on a cable, 4.9 ms through a HyperSpeed receiver | +| Battery and charging | the keyboards whose daemon offers the battery, where both reads use the same transaction id | `1f` on a cable, `9f` through the receiver, `3f` for the BlackWidow V3 Pro on its cable | +| Backlight brightness | the read of the backlight (LED `05`) from the stored values (`01`): the extended command or the standard one | extended with `1f`, `3f` or `9f`; standard with `ff` | +| Game mode | the read of the game mode light (LED `08`) from the stored values, where the daemon offers the game mode | `ff`; left out on the Huntsman V2 and V2 Tenkeyless, which read it from another storage | +| Firmware, layout | the same on every keyboard | `ff` | + +A keyboard with no brightness or game mode read in OpenRazer is not asked for it. + ## BlackWidow V4 Mini HyperSpeed | | On its cable | Through its HyperSpeed receiver | @@ -18,11 +36,20 @@ written here in PeriHub's own words. No code was copied. Interface 3 holds, through the receiver, only a consumer control collection (usage page `000c`, the media keys), as the device request in [issue #24](https://github.com/hex-dump/perihub/issues/24) shows. On its cable it has not -been seen yet. On Linux PeriHub reads each keyboard node's report descriptor first and does not open one that -declares typed keys (the Keyboard/Keypad page, or a keyboard or keypad of the Generic Desktop page), whatever rule -gave access to it. +been seen yet. The receiver belongs to this keyboard: OpenRazer gives it a product id of its own and the +keyboard's commands. + +## Linux + +On Linux the udev rule opens a keyboard's interface only where a tester showed that it carries no typed keys: +for now only the BlackWidow V4 Mini HyperSpeed's interface 3. On most Razer keyboards the interface OpenRazer +sends to also carries what is typed: OpenRazer's daemon reads the key presses of these keyboards from interface 0 +and 1. A rule that opened such an interface would let any program running as the user read the typing, so +PeriHub does not open the other keyboards on Linux, and **Send a report** lists them with their interfaces. On +Windows the system keeps typed keys from programs. -The receiver belongs to this keyboard: OpenRazer gives it a product id of its own and the keyboard's commands. +On Linux PeriHub also reads each keyboard node's report descriptor first and does not open one that declares typed +keys (the Keyboard/Keypad page, or a keyboard or keypad of the Generic Desktop page), whatever rule gave access to it. ## Reads @@ -31,7 +58,8 @@ The receiver belongs to this keyboard: OpenRazer gives it a product id of its ow | `00 81` | `02` | none | firmware major, minor | | `07 80` | `02` | none | battery level 0–255 in the second byte | | `07 84` | `02` | none | `01` while charging, in the second byte | -| `0f 84` | `03` | `01` (stored), `05` (backlight) | storage, LED, brightness 0–255 | +| `0f 84` | `03` | `01` (stored), `05` (backlight) | storage, LED, brightness 0–255 (extended) | +| `03 83` | `03` | `01` (stored), `05` (backlight) | storage, LED, brightness 0–255 (standard, older keyboards) | | `03 80` | `03` | `01` (stored), `08` (game mode light) | storage, LED, `01` on or `00` off | | `00 86` | `02` | none | the keyboard's region (`11` Italian, `06` UK…), with transaction id `ff`: see `keyboard-layouts.md` | @@ -40,8 +68,7 @@ Status `05` means the keyboard does not take the command: PeriHub then shows tha ## Left out for now -Lighting effects, the custom frame of 5 rows Γ— 14 columns, changing the brightness and game mode, macros and key -remapping. OpenRazer stores every lighting effect of these keyboards in their memory and has no command that -reads the effect back, so a stored effect could not be undone. Key remapping, the Hypershift layer and onboard -profiles are not described by any source PeriHub may use: they would need USB captures of Razer Synapse from a -tester. +Lighting effects, the custom frame, changing the brightness and game mode, macros and key remapping. OpenRazer +stores every lighting effect of these keyboards in their memory and has no command that reads the effect back, so +a stored effect could not be undone. Key remapping, the Hypershift layer and onboard profiles are not described by +any source PeriHub may use: they would need USB captures of Razer Synapse from a tester. diff --git a/packaging/linux/70-perihub.rules b/packaging/linux/70-perihub.rules index 24bbfc5..1b0bfc8 100644 --- a/packaging/linux/70-perihub.rules +++ b/packaging/linux/70-perihub.rules @@ -567,9 +567,11 @@ KERNEL=="hidraw*", ATTRS{idVendor}=="1532", ATTRS{idProduct}=="00d6", ENV{ID_USB # Razer Viper V3 Pro SE (Wired) KERNEL=="hidraw*", ATTRS{idVendor}=="1532", ATTRS{idProduct}=="00de", ENV{ID_USB_INTERFACE_NUM}=="00", TAG+="uaccess" -# Razer keyboards (read only, untested; facts from OpenRazer): only interface 3, the one OpenRazer sends -# to. Through the receiver it holds only the media keys. PeriHub also reads each keyboard node's report -# descriptor and does not open one that carries typed keys. The receiver (02ba) belongs to this keyboard alone. +# Razer keyboards (read only, untested; facts from OpenRazer): only the BlackWidow V4 Mini HyperSpeed's +# interface 3, the one OpenRazer sends to. Through the receiver it holds only the media keys. PeriHub also +# reads each keyboard node's report descriptor and does not open one that carries typed keys. The receiver +# (02ba) belongs to this keyboard alone. The other Razer keyboards PeriHub reads are left out on Linux for +# now: on most of them the interface OpenRazer sends to also carries typed keys. # Razer BlackWidow V4 Mini HyperSpeed (read only) KERNEL=="hidraw*", ATTRS{idVendor}=="1532", ATTRS{idProduct}=="02b9", ENV{ID_USB_INTERFACE_NUM}=="03", TAG+="uaccess" # Razer BlackWidow V4 Mini HyperSpeed (wireless) (read only) diff --git a/site/devices.json b/site/devices.json index 5976b06..99a5427 100644 --- a/site/devices.json +++ b/site/devices.json @@ -3484,6 +3484,773 @@ "interface": 0 } }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Ultimate 2012", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:010d" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Stealth Edition", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:010e" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Anansi", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:010f" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker/DeathStalker Essential", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0118" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Ultimate 2013", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:011a" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow (Classic)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:011b" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Tournament Edition 2014", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:011c" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker Expert", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0202" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Chroma", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0203" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker Chroma", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0204" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Tournament Edition Chroma", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0209" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Chroma (Overwatch)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0211" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Ultimate 2016", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0214" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow X Chroma", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0216" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow X Ultimate", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0217" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow X Tournament Edition Chroma", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:021a" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata Chroma", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:021e" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:021f" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Chroma V2", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0221" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman Elite", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0226" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0227" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Elite", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0228" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Cynosa Chroma", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:022a" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Cynosa Chroma Pro", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:022c" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Lite", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0235" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow Essential", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0237" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Cynosa Lite", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:023f" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow 2019", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0241" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman Tournament Edition", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0243" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V3", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:024e" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman Mini", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0257" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V3 Mini HyperSpeed (Wired)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0258" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V3 Pro Wired", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:025a" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V3 Pro 2.4 Ghz Wireless", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:025c" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata V2", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:025d" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Cynosa V2", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:025e" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V2 Analog", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0266" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman Mini JP", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0269" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V2 Tenkeyless", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:026b" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V2", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:026c" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V3 Mini HyperSpeed (Wireless)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0271" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman Mini Analog", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0282" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0287" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4 Pro", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:028d" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata V3 (Alternate)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:028f" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker V2 Pro (Wireless)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0290" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker V2 Pro (Wired)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0292" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4 X", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0293" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata V3 X", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0294" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker V2", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0295" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker V2 Pro TKL (Wireless)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0296" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "DeathStalker V2 Pro TKL (Wired)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0298" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata V3", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02a1" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata V3 X (Alternate)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02a2" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Ornata V3 Tenkeyless", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02a3" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4 75%", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02a5" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V3 Pro", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02a6" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V3 Pro TKL", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02a7" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V3 Pro Mini", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02b0" + ], + "linux": { + "kind": "closed" + } + }, { "family": "razer-keyboard", "brand": "Razer", @@ -3512,6 +4279,110 @@ "interface": 3 } }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Joro", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02cd" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V3 Pro 8KHz", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02cf" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wireless)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02d2" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4 Low-profile Tenkeyless HyperSpeed (Wired)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02d4" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4 Tenkeyless HyperSpeed (Wireless)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02d5" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V4 Tenkeyless HyperSpeed (Wired)", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02d7" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "Huntsman V3 HE Magnetic Tenkeyless 8KHz", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:02ea" + ], + "linux": { + "kind": "closed" + } + }, + { + "family": "razer-keyboard", + "brand": "Razer", + "name": "BlackWidow V3 TK", + "kind": "keyboard", + "level": "read_only", + "usb_ids": [ + "1532:0a24" + ], + "linux": { + "kind": "closed" + } + }, { "family": "glorious", "brand": "Glorious", diff --git a/site/index.html b/site/index.html index b15c56c..e447583 100644 --- a/site/index.html +++ b/site/index.html @@ -649,6 +649,20 @@

Read-only

+
+ Razer69 keyboards +
+ + + + + + + + +
Razer, read-only
69 keyboardsBlackWidow, Huntsman, Ornata, Cynosa, DeathStalker and more. On Linux only the BlackWidow V4 Mini HyperSpeed for nowFirmware, layout, backlight brightness and game mode; battery on the wireless ones.
+
+
RoccatKone Pure, Kone XTD, Kone EMP
diff --git a/tools/openrazer_facts.py b/tools/openrazer_facts.py index 6fa7fc6..45de332 100644 --- a/tools/openrazer_facts.py +++ b/tools/openrazer_facts.py @@ -9,6 +9,9 @@ Usage: python3 -I tools/openrazer_facts.py OPENRAZER_CHECKOUT COMMIT > crates/perihub-core/src/peripheral/razer_models.rs where OPENRAZER_CHECKOUT holds driver/razermouse_driver.{c,h} and daemon/openrazer_daemon/hardware/mouse.py. Mice only: the receivers and docks, which may be shared with a keyboard, are left out. + +With --keyboards after COMMIT it writes crates/perihub-core/src/peripheral/razer_keyboard_models.rs instead, +from driver/razerkbd_driver.{c,h} and daemon/openrazer_daemon/hardware/keyboards.py (see main_keyboards). """ import ast @@ -271,5 +274,181 @@ def function_static_int(source, name): raise ValueError(name) +# --------------------------------------------------------------------------------------------- +# Keyboards: python3 -I tools/openrazer_facts.py OPENRAZER_CHECKOUT COMMIT --keyboards +# > crates/perihub-core/src/peripheral/razer_keyboard_models.rs +# Reads driver/razerkbd_driver.{c,h} and daemon/openrazer_daemon/hardware/keyboards.py. Only what +# PeriHub reads from a keyboard: the interface of the reports, the wait before the answer, and the +# transaction id of the battery, brightness and game mode reads. Laptops and keypads are left out, +# and so is any product id another OpenRazer driver also claims (a receiver shared with a mouse). + +# Keyboards whose interface 70-perihub.rules opens on Linux: only where a tester showed what that +# interface carries (issue #24: through the receiver, only the media keys). On most Razer keyboards +# the interface OpenRazer sends to also carries typed keys, so the rule must not open it. +LINUX_OPENED = {0x02B9, 0x02BA} +# Names PeriHub already used, kept so that settings saved with them still match. +NAMES = {0x02B9: "BlackWidow V4 Mini HyperSpeed", 0x02BA: "BlackWidow V4 Mini HyperSpeed (wireless)"} +NOT_KEYBOARDS = r"Blade|Book|Tartarus|Orbweaver|Nostromo" +KBD_WAITS = {"RAZER_BLACKWIDOW_CHROMA_WAIT_US": 600, "RAZER_BLACKWIDOW_V3_WIRELESS_WAIT_US": 4900, + "RAZER_DEATHSTALKER_V2_WIRELESS_WAIT_US": 4900} + + +def function_void(source, name): + start = source.index(f"static void {name}(") + depth, i = 0, source.index("{", start) + for j in range(i, len(source)): + depth += {"{": 1, "}": -1}.get(source[j], 0) + if depth == 0: + return source[i : j + 1] + raise ValueError(name) + + +def daemon_classes(path): + """Every device class of a daemon file, with what it inherits, by product id.""" + tree = ast.parse(path.read_text()) + classes = {} + for node in tree.body: + if not isinstance(node, ast.ClassDef): + continue + attrs = {} + for stmt in node.body: + if isinstance(stmt, ast.Assign) and isinstance(stmt.targets[0], ast.Name): + try: + attrs[stmt.targets[0].id] = ast.literal_eval(stmt.value) + except ValueError: + pass + doc = ast.get_docstring(node) or "" + attrs["name"] = re.sub(r"^Class for the (Razer )?", "", doc.strip().splitlines()[0] if doc else node.name) + attrs["class"] = node.name + attrs["base"] = node.bases[0].id if node.bases and isinstance(node.bases[0], ast.Name) else None + classes[node.name] = attrs + out = {} + for cls in classes: + merged, c = {}, cls + while c in classes: + for k, v in classes[c].items(): + merged.setdefault(k, v) + c = classes[c]["base"] + merged["class"], merged["name"] = cls, classes[cls]["name"] + if "USB_PID" in merged: + out[merged["USB_PID"]] = merged + return out + + +def read_facts(body): + """Per product define: (builder, its arguments, transaction id); for a group that tells laptops + apart, the builder of the other devices (the last one).""" + out = {} + for labels, code in groups(body): + builders = re.findall(r"request\s*=\s*(razer_\w+)\(([^)]*)\)", code) + tid = re.search(r"transaction_id\.id\s*=\s*(0x[0-9A-Fa-f]+)", code) + for label in labels: + out[label] = (builders[-1][0], builders[-1][1].replace(" ", ""), int(tid.group(1), 16)) if builders and tid else None + return out + + +def main_keyboards(root, commit): + driver = (root / "driver" / "razerkbd_driver.c").read_text() + ids = defines((root / "driver" / "razerkbd_driver.h").read_text()) + others = set() + for h in ("razermouse_driver.h", "razeraccessory_driver.h", "razerkraken_driver.h"): + others |= set(defines((root / "driver" / h).read_text()).values()) + daemon = daemon_classes(root / "daemon" / "openrazer_daemon" / "hardware" / "keyboards.py") + + # The firmware and the layout are read the same way on every keyboard, with transaction id ff. + fw = function(driver, "razer_attr_read_firmware_version") + if not re.search(r"razer_chroma_standard_get_firmware_version\(\);\s*request\.transaction_id\.id = 0xFF;", fw): + sys.exit("the firmware is no longer read the same way on every keyboard") + layout = function(driver, "razer_attr_read_kbd_layout") + if not re.search(r"get_razer_report\(0x00, 0x86, 0x02\);\s*request\.transaction_id\.id = 0xFF;", layout): + sys.exit("the layout is no longer read the same way on every keyboard") + + params = {} + for labels, code in groups(function_void(driver, "razer_get_report_params")): + index = re.search(r"\*report_index\s*=\s*(0x[0-9A-Fa-f]+)", code) + response = re.search(r"\*response_index\s*=\s*(0x[0-9A-Fa-f]+)", code) + wait = re.search(r"\*wait\s*=\s*(RAZER_\w+_WAIT_US)", code) + if index.group(1) != response.group(1): + sys.exit(f"{labels}: the answer comes from another interface") + for label in labels: + params[label] = (int(index.group(1), 16), KBD_WAITS[wait.group(1)]) + bright = read_facts(function(driver, "razer_attr_read_matrix_brightness")) + game = read_facts(function(driver, "razer_attr_read_game_led_state")) + # The battery reads build their request before the switch, which only sets the transaction id. + level = {k: v[1] for k, v in facts(function(driver, "razer_attr_read_charge_level"), "get_battery_level").items() if v[1]} + charging = {k: v[1] for k, v in facts(function(driver, "razer_attr_read_charge_status"), "get_charging_status").items() if v[1]} + for name, body in (("level", "razer_attr_read_charge_level"), ("charging", "razer_attr_read_charge_status")): + wanted = {"level": "razer_chroma_misc_get_battery_level()", "charging": "razer_chroma_misc_get_charging_status()"}[name] + if f"request = {wanted};" not in function(driver, body): + sys.exit(f"the battery {name} is no longer read the same way") + + out = [ + "//! Generated by tools/openrazer_facts.py --keyboards from facts in OpenRazer", + f"//! (https://github.com/openrazer/openrazer, GPL-2.0, commit {commit}): product ids, the USB", + "//! interface of the reports, the wait before the answer and the transaction id of each read. No code", + "//! was copied. Do not edit by hand.", + "", + "use super::razer_keyboard::{Brightness, Params};", + "use super::{Kind, Model, Protocol};", + "", + "pub const MODELS: &[Model] = &[", + ] + left_out = [] + for define, pid in sorted(ids.items(), key=lambda kv: kv[1]): + if pid not in daemon: + continue + m = daemon[pid] + if re.search(NOT_KEYBOARDS, m["class"]): + left_out.append(f"{define} (not a keyboard, or built into a laptop)") + continue + if pid in others: + left_out.append(f"{define} (another OpenRazer driver claims it too)") + continue + methods = m.get("METHODS", []) + interface, wait_us = params.get(define, params["default"]) + b = bright.get(define, bright.get("default")) + brightness = "None" + if b and b[1] == "VARSTORE,BACKLIGHT_LED": + if b[0] == "razer_chroma_extended_matrix_get_brightness": + brightness = f"Some(Brightness {{ standard: false, tid: 0x{b[2]:02X} }})" + elif b[0] == "razer_chroma_standard_get_led_brightness": + brightness = f"Some(Brightness {{ standard: true, tid: 0x{b[2]:02X} }})" + g = game.get(define, game.get("default")) + game_tid = "None" + if g and g[0] == "razer_chroma_standard_get_led_state" and g[1] == "VARSTORE,GAME_LED" and "get_game_mode" in methods: + game_tid = f"Some(0x{g[2]:02X})" + lv, ch = level.get(define, level.get("default")), charging.get(define, charging.get("default")) + battery = "None" + if lv is not None and lv == ch and "get_battery" in methods and "is_charging" in methods: + battery = f"Some(0x{lv:02X})" + name = NAMES.get(pid, m["name"]).replace('"', "") + out.append(" Model {") + out.append(" vendor_id: 0x1532,") + out.append(f" product_ids: &[0x{pid:04X}],") + out.append(' brand: "Razer",') + out.append(f' name: "{name}",') + out.append(" kind: Kind::Keyboard,") + out.append(f" interface: Some({interface}),") + out.append(" usage_page: None,") + out.append(" protocol: Protocol::RazerKeyboard(Params {") + out.append(f" wait_us: {wait_us},") + out.append(f" battery: {battery},") + out.append(f" brightness: {brightness},") + out.append(f" game: {game_tid},") + out.append(f" linux: {str(pid in LINUX_OPENED).lower()},") + out.append(" }),") + out.append(" },") + out.append("];") + out.append("") + out.append("/// OpenRazer keyboards PeriHub leaves out, and why.") + out.append("pub const LEFT_OUT: &[&str] = &[") + out.extend(f' "{x}",' for x in left_out) + out.append("];") + print("\n".join(out)) + + if __name__ == "__main__": - main() + if sys.argv[3:] == ["--keyboards"]: + main_keyboards(Path(sys.argv[1]), sys.argv[2]) + else: + main()