From 301436d8a83f96c1b6320b9b28301f2cf5cfa08b Mon Sep 17 00:00:00 2001 From: Zedris <32003202+Zedris@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:43:30 +0000 Subject: [PATCH 1/5] Fix Naga V3 Pro (00E8) polling type and interface from report #91 --- crates/secbird-core/devices.json | 2 +- crates/secbird-core/src/db.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/secbird-core/devices.json b/crates/secbird-core/devices.json index b467f39..e1be797 100644 --- a/crates/secbird-core/devices.json +++ b/crates/secbird-core/devices.json @@ -123,7 +123,7 @@ {"pid":"00E3","name":"Basilisk V4 Pro (Wireless)","kind":"mouse","txid":"1F","dpi":{"min":100,"max":30000,"step":50},"polling":"high","lighting":"extended","leds":[{"name":"logo","id":4},{"name":"scroll","id":1},{"name":"underglow","id":10}],"wireless":true,"source":"Synapse DualDongleCompatibleDevices.json (pairs with the Mouse Dock Pro); DPI max not confirmed; LEDs 1 and 4 from #16, 8K polling from #16, underglow 10 from #54"}, {"pid":"00E6","name":"Viper V4 Pro","kind":"mouse","interface":3,"txid":"1F","dpi":{"min":100,"max":35000,"step":50},"polling":"high","wireless":true,"source":"user report (#36): txid 1F on interface 3, battery, HyperPolling 00:C0, no LEDs; DPI max not confirmed"}, {"pid":"00E7","name":"Naga V3 Pro (Wired)","kind":"mouse","txid":"1F","dpi":{"min":100,"max":30000,"step":50},"polling":"high","lighting":"extended","leds":[{"name":"logo","id":4},{"name":"scroll","id":1},{"name":"side","id":5}],"wireless":true,"source":"Synapse DualDongleCompatibleDevices.json (pairs with the Mouse Dock Pro); DPI max not confirmed; scroll LED 1 seen in 0F:84 (#26); side plate LED 5 from #26"}, -{"pid":"00E8","name":"Naga V3 Pro (Wireless)","kind":"mouse","txid":"1F","dpi":{"min":100,"max":30000,"step":50},"polling":"high","lighting":"extended","leds":[{"name":"logo","id":4},{"name":"scroll","id":1},{"name":"side","id":5}],"wireless":true,"source":"Synapse DualDongleCompatibleDevices.json (pairs with the Mouse Dock Pro); DPI max not confirmed; scroll LED 1 seen in 0F:84 (#26); side plate LED 5 from #26"}, +{"pid":"00E8","name":"Naga V3 Pro (Wireless)","kind":"mouse","interface":3,"txid":"1F","dpi":{"min":100,"max":30000,"step":50},"polling":"standard","lighting":"extended","leds":[{"name":"logo","id":4},{"name":"scroll","id":1},{"name":"side","id":5}],"wireless":true,"source":"user report (#91): interface 3, txid 1F, 00:85 standard polling (00:C0 NotSupported), LEDs 1/4/5, battery; pairs with Mouse Dock Pro (#26); DPI max not confirmed"}, {"pid":"00EA","name":"Basilisk V4 HyperSpeed (Wireless)","kind":"mouse","txid":"1F","dpi":{"min":100,"max":30000,"step":50},"polling":"standard","lighting":"extended","leds":[{"name":"underglow","id":10}],"unsupported_effects":["reactive","starlight"],"wireless":true,"source":"Razer product specification: single underglow zone; user 2.4 GHz report: LED 10 on 00EA; 00EB layout mirrors same physical mouse; DPI max not confirmed"}, {"pid":"00EB","name":"Basilisk V4 HyperSpeed (Wired)","kind":"mouse","txid":"1F","dpi":{"min":100,"max":30000,"step":50},"polling":"standard","lighting":"extended","leds":[{"name":"underglow","id":10}],"unsupported_effects":["reactive","starlight"],"wireless":true,"source":"Razer product specification: single underglow zone; user 2.4 GHz report: LED 10 on 00EA; 00EB layout mirrors same physical mouse; DPI max not confirmed"}, {"pid":"00F1","name":"Mouse on Mouse Dock V2 Pro","kind":"mouse","txid":"1F","dpi":{"min":100,"max":30000,"step":50},"polling":"high","lighting":"extended","leds":[{"name":"logo","id":4},{"name":"scroll","id":1}],"wireless":true,"source":"user reports (#61, #72): works like the Mouse Dock Pro; answers the docked mouse at txid 1F (00:BF lists it, 00:C0 polling) and its own light, LED 15, at txid FF"}, diff --git a/crates/secbird-core/src/db.rs b/crates/secbird-core/src/db.rs index afd0af7..a097a92 100644 --- a/crates/secbird-core/src/db.rs +++ b/crates/secbird-core/src/db.rs @@ -271,6 +271,18 @@ mod tests { } } + #[test] + fn naga_v3_pro_wireless_matches_report() { + let db = Db::builtin().unwrap(); + let spec = db.get(0x00E8).expect("Naga V3 Pro (Wireless)"); + assert_eq!(spec.interface, Some(3)); + assert_eq!(spec.txid, Some(0x1F)); + assert_eq!(spec.polling, Some(Polling::Standard)); + assert!(spec.wireless); + let led_ids: Vec = spec.leds.iter().map(|l| l.id).collect(); + assert_eq!(led_ids, [4, 1, 5]); + } + #[test] fn builtin_entries_are_sane() { let text = BUILTIN; From efd6eb3ec661ab07f56d4b930c439315811af16e Mon Sep 17 00:00:00 2001 From: Zedris <32003202+Zedris@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:43:30 +0000 Subject: [PATCH 2/5] Echo-check button reads/writes and verify on-board slot saves --- crates/secbird-core/src/buttons.rs | 38 ++++-- crates/secbird-core/src/device.rs | 13 ++ crates/secbird-core/src/sim.rs | 196 +++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+), 11 deletions(-) diff --git a/crates/secbird-core/src/buttons.rs b/crates/secbird-core/src/buttons.rs index db538bf..0da4885 100644 --- a/crates/secbird-core/src/buttons.rs +++ b/crates/secbird-core/src/buttons.rs @@ -729,7 +729,7 @@ impl FromStr for Action { impl Device { fn read_input(&self, slot: u8, input: Input, layer: Layer) -> Result { let (command, size, id) = input.command(); - let r = self.get(command, size, &[slot, id, layer as u8])?; + let r = self.get_echo(command, size, &[slot, id, layer as u8], 3)?; let a = r.args(); Ok(Action::decode(a[3], [a[5], a[6], a[7], a[8], a[9]])) } @@ -748,14 +748,15 @@ impl Device { /// Set a button or key in the live slot. Returns whether anything was sent: an /// unchanged one is left alone. pub fn set_input(&self, input: Input, layer: Layer, action: Action) -> Result { - if self.input(input, layer).ok() == Some(action) { - return Ok(false); - } let (command, size, id) = input.command(); let (function, data_size, data) = action.encode(); + let expected = Action::decode(function, data); + if self.input(input, layer).ok() == Some(expected) { + return Ok(false); + } let mut args = vec![cmd::BUTTON_LIVE_SLOT, id, layer as u8, function, data_size]; args.extend_from_slice(&data); - self.transact(command, size, &args)?; + self.transact_echo(command, size, &args, 3)?; Ok(true) } @@ -766,20 +767,35 @@ impl Device { /// Write a button or key into on-board slot `slot` (1-5), which the device keeps /// without any software ("Save to mouse"). A flash write: only on request, never on a - /// profile switch. + /// profile switch. Reads back to verify, retrying if the flash write didn't stick. pub fn set_slot_input(&self, slot: u8, input: Input, layer: Layer, action: Action) -> Result<()> { if !(1..=5).contains(&slot) { return Err(Error::InvalidArg(format!("on-board slot {slot}: use 1 to 5"))); } - if self.slot_input(slot, input, layer).ok() == Some(action) { - return Ok(()); - } let (command, size, id) = input.command(); let (function, data_size, data) = action.encode(); + let expected = Action::decode(function, data); + if self.slot_input(slot, input, layer).ok() == Some(expected) { + return Ok(()); + } let mut args = vec![slot, id, layer as u8, function, data_size]; args.extend_from_slice(&data); - self.transact_slow(command, size, &args)?; - Ok(()) + // Flash writes can acknowledge without persisting (as seen on macro writes) or + // receive a stale reply on wireless receivers; echo-match and read back to verify. + let mut got = None; + for _ in 0..3 { + self.transact_slow_echo(command, size, &args, 3)?; + let back = self.slot_input(slot, input, layer)?; + if back == expected { + return Ok(()); + } + got = Some(back); + } + Err(Error::Unsupported(format!( + "the device didn't keep {} in on-board slot {slot} (wrote {expected}, read {})", + input.name(), + got.map_or_else(|| "nothing".into(), |a| a.to_string()), + ))) } /// Put a button or key back to its saved-slot setting. diff --git a/crates/secbird-core/src/device.rs b/crates/secbird-core/src/device.rs index b37f470..d37902d 100644 --- a/crates/secbird-core/src/device.rs +++ b/crates/secbird-core/src/device.rs @@ -191,6 +191,19 @@ impl Device { transact(self.transport.as_ref(), self.txid, command, size, args, FLASH_RETRIES, false, &[]) } + /// [`Device::transact_slow`] that only takes a reply echoing `args[..echo]`. + pub(crate) fn transact_slow_echo(&self, command: Command, size: u8, args: &[u8], echo: usize) -> Result { + let echo = &args[..echo.min(args.len())]; + let mut result = Err(Error::NoReply(command)); + for _ in 0..ECHO_SENDS { + result = transact(self.transport.as_ref(), self.txid, command, size, args, FLASH_RETRIES, false, echo); + if !matches!(result, Err(Error::NoReply(_))) { + break; + } + } + result + } + /// [`Device::transact`] with another transaction id (see [`DOCK_TXID`]). pub fn transact_as(&self, txid: u8, command: Command, size: u8, args: &[u8]) -> Result { transact(self.transport.as_ref(), txid, command, size, args, READ_RETRIES, true, &[]) diff --git a/crates/secbird-core/src/sim.rs b/crates/secbird-core/src/sim.rs index 7b18b99..c27cae6 100644 --- a/crates/secbird-core/src/sim.rs +++ b/crates/secbird-core/src/sim.rs @@ -2407,4 +2407,200 @@ mod tests { store.for_device(&da).active_mut().dpi = Some((400, 400)); assert_eq!(store.for_device(&db).active().dpi, None); } + + /// A transport wrapper that injects one stale `02:8C` reply (from the live slot) before + /// letting the real reply through, modelling a wireless receiver returning a cached reply. + struct StaleButtonReply { + inner: Sim, + stale: Mutex>, + injected: Mutex, + } + + impl Transport for StaleButtonReply { + fn send_feature_report(&self, data: &[u8]) -> Result<()> { + let cmd = Command::new(data[7], data[8]); + // Trigger once when reading slot 1 of button 5 (Normal layer). + if cmd == cmd::BUTTON.get() && data[9] == 1 && data[10] == 5 && data[11] == 0 { + let mut done = self.injected.lock().unwrap(); + if !*done { + *done = true; + // Stale reply for live slot (0), button 5, Normal layer, holding key:f13. + let mut b = [0u8; REPORT_LEN]; + b[0] = 2; // Status::Success + b[1] = data[2]; + b[5] = cmd::BUTTON_SIZE; + b[6] = cmd.class; + b[7] = cmd.id; + b[8..18].copy_from_slice(&[0, 5, 0, 2, 1, 0, 0x68, 0, 0, 0]); + b[88] = checksum(&b); + *self.stale.lock().unwrap() = Some(b); + } + } + self.inner.send_feature_report(data) + } + + fn get_feature_report(&self, buf: &mut [u8]) -> Result { + if let Some(stale) = self.stale.lock().unwrap().take() { + buf[0] = 0; + buf[1..=REPORT_LEN].copy_from_slice(&stale); + return Ok(REPORT_LEN + 1); + } + self.inner.get_feature_report(buf) + } + + fn read_delay(&self) -> Duration { + Duration::ZERO + } + } + + #[test] + fn save_to_mouse_ignores_stale_button_replies() { + use crate::buttons::{Action, Layer}; + let sim = Sim::mouse(); + let factory = Action::Mouse(5); + let f13 = Action::Key { modifiers: 0, usage: 0x68 }; + let transport = StaleButtonReply { + inner: sim.clone(), + stale: Mutex::new(None), + injected: Mutex::new(false), + }; + let dev = Device::open( + Box::new(transport), + MOUSE_PID, + 0, + CString::new("sim:stale").unwrap(), + &TXID_CANDIDATES, + Sim::spec_for(MOUSE_PID), + ) + .expect("wrapper opens"); + let path = std::env::temp_dir().join(format!("secbird-stale-btn-{}.json", std::process::id())); + let mut store = crate::Store::load(&path).unwrap(); + crate::actions::set_button(&dev, &mut store, "side-forward", Layer::Normal, Some(f13)).unwrap(); + assert_eq!(crate::actions::save_buttons_to_mouse(&dev, &mut store).unwrap(), 1); + assert_eq!(dev.slot_button(1, 5, Layer::Normal).unwrap(), f13); + let save = store.for_device(&dev).onboard.as_ref().unwrap(); + assert_eq!(save.before["side-forward"], factory.to_string()); + let _ = std::fs::remove_file(&path); + } + + /// A transport wrapper that acknowledges `drop_writes` on-board `02:0C` writes with + /// `Status::Success` without persisting them to `Sim`. + struct FlakySlotFlash { + inner: Sim, + drop_writes: Mutex, + fake_ok: Mutex>, + } + + impl Transport for FlakySlotFlash { + fn send_feature_report(&self, data: &[u8]) -> Result<()> { + let cmd = Command::new(data[7], data[8]); + if cmd == cmd::BUTTON && data[9] >= 1 { + let mut remaining = self.drop_writes.lock().unwrap(); + if *remaining > 0 { + *remaining -= 1; + let mut b = [0u8; REPORT_LEN]; + b.copy_from_slice(&data[1..=REPORT_LEN]); + b[0] = 2; // Status::Success + b[88] = checksum(&b); + *self.fake_ok.lock().unwrap() = Some(b); + return Ok(()); + } + } + self.inner.send_feature_report(data) + } + + fn get_feature_report(&self, buf: &mut [u8]) -> Result { + if let Some(rep) = self.fake_ok.lock().unwrap().take() { + buf[0] = 0; + buf[1..=REPORT_LEN].copy_from_slice(&rep); + return Ok(REPORT_LEN + 1); + } + self.inner.get_feature_report(buf) + } + + fn read_delay(&self) -> Duration { + Duration::ZERO + } + } + + #[test] + fn save_to_mouse_retries_dropped_flash_writes_and_reports_unkept_slots() { + use crate::buttons::{Action, Layer}; + let f13 = Action::Key { modifiers: 0, usage: 0x68 }; + + // One silently dropped flash write is caught by read-back and succeeds on retry. + let sim = Sim::mouse(); + let dev = Device::open( + Box::new(FlakySlotFlash { + inner: sim.clone(), + drop_writes: Mutex::new(1), + fake_ok: Mutex::new(None), + }), + MOUSE_PID, + 0, + CString::new("sim:flaky1").unwrap(), + &TXID_CANDIDATES, + Sim::spec_for(MOUSE_PID), + ) + .unwrap(); + dev.set_slot_button(1, 5, Layer::Normal, f13).unwrap(); + assert_eq!(dev.slot_button(1, 5, Layer::Normal).unwrap(), f13); + + // Permanently ignored flash writes surface an error instead of silently succeeding. + let sim2 = Sim::mouse(); + let dev2 = Device::open( + Box::new(FlakySlotFlash { + inner: sim2, + drop_writes: Mutex::new(10), + fake_ok: Mutex::new(None), + }), + MOUSE_PID, + 0, + CString::new("sim:flaky10").unwrap(), + &TXID_CANDIDATES, + Sim::spec_for(MOUSE_PID), + ) + .unwrap(); + let err = dev2.set_slot_button(1, 5, Layer::Normal, f13).unwrap_err().to_string(); + assert!(err.contains("didn't keep"), "{err}"); + } + + #[test] + fn naga_v3_pro_button_ids_and_save_to_mouse() { + use crate::buttons::{button_name, Action, Layer}; + // Exact 33 button ids from Naga V3 Pro (00E8) `02:84` report (#91). + const NAGA_V3_IDS: [u8; 33] = [ + 0x01, 0x02, 0x0B, 0x0C, 0x0E, 0x03, 0x34, 0x35, 0x6A, 0x39, 0x80, + 0x42, 0x41, 0x40, 0x45, 0x44, 0x43, 0x48, 0x47, 0x46, 0x4B, 0x4A, 0x49, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x05, 0x04, 0x09, 0x0A, + ]; + let mut s = SimState::new("SIMNAGAV3001"); + s.dpi = Some((1400, 1400)); + s.leds = vec![1, 4, 5]; + s.active_slot = Some(1); + let defs: Vec<(u8, u8, [u8; 5])> = NAGA_V3_IDS + .iter() + .map(|&id| (id, if id == 1 { 1 } else { 2 }, [if id == 1 { 1 } else { 0 }, 0x1E, 0, 0, 0])) + .collect(); + with_buttons(&mut s, &defs); + s.button_list = Some(NAGA_V3_IDS.to_vec()); + + let db = crate::Db::builtin().unwrap(); + let dev = Sim::new(s).open(0x00E8, db.spec(0x00E8)).expect("Naga V3 Pro opens"); + let ids = dev.button_ids().expect("button_ids"); + assert_eq!(ids.len(), 33); + assert!(ids.iter().all(|&id| !button_name(id).starts_with("button-")), "every Naga V3 Pro id is named"); + assert_eq!(dev.polling_rate().unwrap(), 1000); + + let path = std::env::temp_dir().join(format!("secbird-nagav3-{}.json", std::process::id())); + let mut store = crate::Store::load(&path).unwrap(); + let f13 = Action::Key { modifiers: 0, usage: 0x68 }; + crate::actions::set_button(&dev, &mut store, "grid-1", Layer::Normal, Some(f13)).unwrap(); + crate::actions::set_button(&dev, &mut store, "side-extra", Layer::Normal, Some(f13)).unwrap(); + assert_eq!(crate::actions::save_buttons_to_mouse(&dev, &mut store).unwrap(), 1); + assert_eq!(dev.slot_button(1, 0x40, Layer::Normal).unwrap(), f13); + assert_eq!(dev.slot_button(1, 0x80, Layer::Normal).unwrap(), f13); + assert_eq!(crate::actions::put_back_onboard(&dev, &mut store).unwrap(), 2); + let _ = std::fs::remove_file(&path); + } } From 9f69d2070fd4b76f2350dd8227481aa487129b0b Mon Sep 17 00:00:00 2001 From: Zedris <32003202+Zedris@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:43:30 +0000 Subject: [PATCH 3/5] Add --verbose / SECBIRD_TRACE packet logging to secbird CLI --- CHANGELOG.md | 15 +++++++++++ crates/secbird-core/src/device.rs | 42 +++++++++++++++++++++++++++++++ crates/secbird/src/main.rs | 5 ++++ 3 files changed, 62 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 113cbc9..1c633c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## [Unreleased] + +### Added +- Command line: `-v` / `--verbose` (or `SECBIRD_TRACE=1`) prints Protocol 2.5 requests and + replies to stderr for diagnosing device issues; serial replies are redacted. + +### Fixed +- Naga V3 Pro (Wireless, `00E8`): uses interface 3 and standard polling (`00:85`), matching + its device report (`00:C0` returns `NotSupported`, #91). +- Button remapping and "Save to mouse": reads and writes now require replies to echo the + requested `[slot, button, layer]` bytes (avoiding stale replies on wireless receivers), + and on-board slot writes (`02:0C`) are read back and retried up to 3 times, returning an + error if the device doesn't keep the assignment. Verified on simulator; not yet tested on + Naga V3 Pro hardware. + ## [0.6.1] - 2026-11-21 ### Added diff --git a/crates/secbird-core/src/device.rs b/crates/secbird-core/src/device.rs index d37902d..837831a 100644 --- a/crates/secbird-core/src/device.rs +++ b/crates/secbird-core/src/device.rs @@ -9,8 +9,34 @@ use hidapi::HidApi; use std::cell::RefCell; use std::collections::BTreeMap; use std::ffi::CString; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::OnceLock; use std::thread::sleep; +static TRACE: AtomicBool = AtomicBool::new(false); +static TRACE_ENV: OnceLock = OnceLock::new(); + +/// Log every Protocol 2.5 request and reply to stderr (serial replies are redacted). +/// Also enabled when `SECBIRD_TRACE` is set to a non-empty value other than `0`. +pub fn set_trace(enabled: bool) { + TRACE.store(enabled, Ordering::Relaxed); +} + +fn trace_enabled() -> bool { + TRACE.load(Ordering::Relaxed) + || *TRACE_ENV.get_or_init(|| { + std::env::var("SECBIRD_TRACE").is_ok_and(|v| !v.is_empty() && v != "0") + }) +} + +fn trace_reply(rep: &Report, note: &str) { + if rep.command() == cmd::SERIAL.get() && rep.status() == Status::Success { + eprintln!("[trace] <- Report[Success tx={:02X} cmd=00:82 ]{note}", rep.txid()); + } else { + eprintln!("[trace] <- {rep:?}{note}"); + } +} + /// Synapse retries reads up to 30 times (5 ms apart, see [`Transport::read_delay`]). const READ_RETRIES: u32 = 30; @@ -286,6 +312,10 @@ fn transact( echo: &[u8], ) -> Result { let req = Report::request(txid, command, size, args); + let tracing = trace_enabled(); + if tracing { + eprintln!("[trace] -> {req:?}"); + } let mut buf = [0u8; REPORT_LEN + 1]; // byte 0 is the HID report id (0) buf[1..].copy_from_slice(&req.0); hid.send_feature_report(&buf)?; @@ -301,6 +331,9 @@ fn transact( body.copy_from_slice(&reply[n - REPORT_LEN..n]); let rep = Report(body); if rep.command() != command || (exact && rep.txid() != txid) { + if tracing { + trace_reply(&rep, " (ignored: command/txid mismatch)"); + } continue; } // The echo check only sorts out successful replies meant for another request. A @@ -308,14 +341,23 @@ fn transact( // would turn "not supported" into a slow "no reply" after every resend. let status = rep.status(); if !rep.args().starts_with(echo) && matches!(status, Status::Success | Status::Busy | Status::New) { + if tracing { + trace_reply(&rep, " (ignored: echo mismatch)"); + } continue; } + if tracing { + trace_reply(&rep, ""); + } match status { Status::Success => return Ok(rep), Status::Busy | Status::New => continue, status => return Err(Error::Device { cmd: command, status }), } } + if tracing { + eprintln!("[trace] <- no reply for {command}"); + } Err(Error::NoReply(command)) } diff --git a/crates/secbird/src/main.rs b/crates/secbird/src/main.rs index e07f282..0e39f93 100644 --- a/crates/secbird/src/main.rs +++ b/crates/secbird/src/main.rs @@ -135,6 +135,7 @@ UPDATES: OPTIONS: -V Show the version (also --version) + -v Print Protocol 2.5 requests and replies to stderr (also --verbose, SECBIRD_TRACE=1) -d ID Pick a device by USB product id (0099) or serial, when several are connected Set SECBIRD_SIM=all (or a list: mouse,wireless,keyboard,old-keyboard,naga,cobra,dock,blackwidow, @@ -154,6 +155,10 @@ fn main() -> ExitCode { } fn run(mut args: Vec) -> Result<(), Error> { + if let Some(i) = args.iter().position(|a| matches!(a.as_str(), "-v" | "--verbose")) { + secbird_core::device::set_trace(true); + args.remove(i); + } // -d takes a product id (0099), a device key (0099:AB1234C56789012) or a serial. let mut selector: Option = None; if let Some(i) = args.iter().position(|a| a == "-d") { From 1332e18d95a1467857d73c47a6d563ebbe78570f Mon Sep 17 00:00:00 2001 From: Zedris <32003202+Zedris@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:43:30 +0000 Subject: [PATCH 4/5] Echo-match [slot, id] only for button reads/writes (Naga V3 Pro args[2] quirk) --- CHANGELOG.md | 8 ++++---- crates/secbird-core/src/buttons.rs | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c633c6..9cd1f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,10 @@ - Naga V3 Pro (Wireless, `00E8`): uses interface 3 and standard polling (`00:85`), matching its device report (`00:C0` returns `NotSupported`, #91). - Button remapping and "Save to mouse": reads and writes now require replies to echo the - requested `[slot, button, layer]` bytes (avoiding stale replies on wireless receivers), - and on-board slot writes (`02:0C`) are read back and retried up to 3 times, returning an - error if the device doesn't keep the assignment. Verified on simulator; not yet tested on - Naga V3 Pro hardware. + requested `[slot, button]` bytes (avoiding stale replies on wireless receivers while + accepting the Naga V3 Pro's `args[2]` reply byte), and on-board slot writes (`02:0C`) + are read back and retried up to 3 times, returning an error if the device doesn't keep + the assignment. ## [0.6.1] - 2026-11-21 diff --git a/crates/secbird-core/src/buttons.rs b/crates/secbird-core/src/buttons.rs index 0da4885..a0cb938 100644 --- a/crates/secbird-core/src/buttons.rs +++ b/crates/secbird-core/src/buttons.rs @@ -729,7 +729,9 @@ impl FromStr for Action { impl Device { fn read_input(&self, slot: u8, input: Input, layer: Layer) -> Result { let (command, size, id) = input.command(); - let r = self.get_echo(command, size, &[slot, id, layer as u8], 3)?; + // Echo-match [slot, id] only: the Naga V3 Pro (00E8) does not always echo the + // layer byte in args[2] of 02:8C replies (observed on hardware). + let r = self.get_echo(command, size, &[slot, id, layer as u8], 2)?; let a = r.args(); Ok(Action::decode(a[3], [a[5], a[6], a[7], a[8], a[9]])) } @@ -756,7 +758,7 @@ impl Device { } let mut args = vec![cmd::BUTTON_LIVE_SLOT, id, layer as u8, function, data_size]; args.extend_from_slice(&data); - self.transact_echo(command, size, &args, 3)?; + self.transact_echo(command, size, &args, 2)?; Ok(true) } @@ -784,7 +786,7 @@ impl Device { // receive a stale reply on wireless receivers; echo-match and read back to verify. let mut got = None; for _ in 0..3 { - self.transact_slow_echo(command, size, &args, 3)?; + self.transact_slow_echo(command, size, &args, 2)?; let back = self.slot_input(slot, input, layer)?; if back == expected { return Ok(()); From 6833eec56e45a70e678d95577fd8bbc862bbe502 Mon Sep 17 00:00:00 2001 From: Zedris <32003202+Zedris@users.noreply.github.com> Date: Sat, 28 Nov 2026 15:43:30 +0000 Subject: [PATCH 5/5] Show 'Saved on the mouse' tile in Profile section for mice --- crates/secbird-tray/src/editor.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/secbird-tray/src/editor.html b/crates/secbird-tray/src/editor.html index 32b4835..74b64d0 100644 --- a/crates/secbird-tray/src/editor.html +++ b/crates/secbird-tray/src/editor.html @@ -1151,7 +1151,9 @@

has('auto-off') && { key: 'audio:auto-off', label: uiText('Auto power-off') }, ].filter(Boolean) }); } - s.push({ id: 'profile', name: uiText('Profile'), rows: [{ key: 'apps', label: uiText('Switches with') }] }); + const profileRows = [{ key: 'apps', label: uiText('Switches with') }]; + if (dev.kind === 'mouse') profileRows.push({ key: 'profile-onboard', label: uiText('Saved on the mouse') }); + s.push({ id: 'profile', name: uiText('Profile'), rows: profileRows }); s.push({ id: 'device', name: uiText('Device'), rows: [{ key: 'device', label: uiText('About this device') }] }); return s; } @@ -1531,7 +1533,7 @@

secs.forEach(s => { const body = el('tbody'); body.append(el('tr', { className: 'grp' }, el('th', { colSpan: span, scope: 'rowgroup', textContent: s.name + (s.id === 'buttons' && btnLayer === 'hypershift' ? ' · HyperShift' : '') }))); - let rowsOf = s.loading ? [{ key: 'loading', label: uiText('Reading buttons…') }] : s.rows.filter(r => !['lighting-control', 'charge', 'fans', 'temps'].includes(r.key)); + let rowsOf = s.loading ? [{ key: 'loading', label: uiText('Reading buttons…') }] : s.rows.filter(r => !['lighting-control', 'profile-onboard', 'charge', 'fans', 'temps'].includes(r.key)); // A keyboard has a hundred keys: only those some profile changes. if (s.id === 'buttons' && isBoard() && !s.loading) { const skey = r => btnLayer === 'normal' ? r.name : r.name + '/hypershift'; @@ -1568,7 +1570,7 @@

if (key === 'dimming') return dimmingOf(name) || ''; if (key === 'gaming') return gamingOf(name) || ''; if (key === 'scroll') return JSON.stringify(scrollOf(name) || ''); - if (key === 'macros' || key === 'onboard') return 'shared'; // the device's, the same in every profile + if (key === 'macros' || key === 'onboard' || key === 'profile-onboard') return 'shared'; // the device's, the same in every profile if (key.startsWith('btn:')) { const b = (btnData[dev.id] || []).find(x => x.name === key.slice(4)); if (!b) return ''; const skey = btnLayer === 'normal' ? b.name : b.name + '/hypershift'; @@ -1583,7 +1585,7 @@

function cellView(key, name) { const p = prof(name), active = name === dev.active; if (key === 'lighting-control') return [dev.lighting_control ? 'Secretarybird' : `${esc(uiText('Not controlled'))}`]; - if (key === 'onboard') { + if (key === 'onboard' || key === 'profile-onboard') { const o = onboardData[dev.id]; if (!o) return [`${esc(uiText('Not saved'))}`]; if (o.profile !== name) return [`${esc(uiText('Not this profile'))}`]; @@ -1719,7 +1721,7 @@

else if (r.key === 'fans' || r.key === 'temps') sensorsEditor(box); else if (r.key === 'gaming') gamingEditor(box); else if (r.key === 'scroll') scrollEditor(box); - else if (r.key === 'onboard') onboardEditor(box); + else if (r.key === 'onboard' || r.key === 'profile-onboard') onboardEditor(box); else if (r.key === 'macros') macrosEditor(box); else if (r.key === 'apps') appsEditor(box); else if (r.key === 'device') deviceEditor(box); @@ -3136,7 +3138,8 @@

: o.profile !== dev.active ? uiText`${o.profile} is saved in on-board slot ${o.slot}. Saving ${dev.active} replaces it.` : o.changed ? uiText`${o.profile} was saved in on-board slot ${o.slot} and has changed since. Save again to update the mouse.` : uiText`${o.profile} is saved in on-board slot ${o.slot} (${plural(o.count, 'remapped button')}). It works without Secretarybird.`; - const done = (r, msg) => { btnData[dev.id] = r.buttons; onboardData[dev.id] = r.onboard; sel = 'onboard'; renderWork(); toast(msg); }; + const keep = sel; + const done = (r, msg) => { btnData[dev.id] = r.buttons; onboardData[dev.id] = r.onboard; sel = keep; renderWork(); toast(msg); }; const save = el('button', { className: 'ghost', textContent: o && o.profile === dev.active ? uiText('Save again') : uiText('Save ') + dev.active + uiText(' to the mouse'), onclick: async e => { if (!o && !confirm(uiText`Write ${dev.active}'s button remaps into the mouse's memory? What it holds now is kept, and Put back restores it.`)) return;