Skip to content

Commit 74d6b57

Browse files
skarardclaude
andcommitted
Move finalize into bind_key, remove finalize trait method
Send the finalize packet [03 FD FE FF] after each bind_key call (matching yawor's PR kriomant#154 approach) instead of adding a new trait method. This keeps the Keyboard trait unchanged from upstream. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3374f8d commit 74d6b57

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/keyboard/k8850.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ impl Keyboard for Keyboard8850 {
122122

123123
send_message(output, &msg);
124124

125-
Ok(())
126-
}
127-
128-
fn finalize(&self, output: &mut Vec<u8>) {
129-
// The 8850 requires a finalize packet after all key bindings are written.
125+
// The 8850 requires a finalize packet after each key binding.
130126
send_message(output, &[0x03, 0xFD, 0xFE, 0xFF]);
127+
128+
Ok(())
131129
}
132130

133131
fn set_led(&mut self, _args: &[String], _output: &mut Vec<u8>) -> Result<()> {
@@ -298,13 +296,19 @@ mod tests {
298296
}
299297

300298
#[test]
301-
fn test_finalize() {
299+
fn test_bind_key_includes_finalize() {
300+
// Every bind_key call should append a finalize packet [03 FD FE FF]
302301
let kb = Keyboard8850::new(16, 3).unwrap();
303302
let mut output = Vec::new();
304-
kb.finalize(&mut output);
303+
let macro_ = Macro::Keyboard(KeyboardEvent(
304+
Default::default(),
305+
vec![Accord { modifiers: EnumSet::empty(), code: Some(Code::WellKnown(WellKnownCode::A)) }],
306+
));
307+
kb.bind_key(0, Key::Button(0), &macro_, &mut output).unwrap();
305308

306-
assert_eq!(output.len(), 64);
307-
assert_msg(&output, 0, &[0x03, 0xFD, 0xFE, 0xFF]);
309+
// Should be 2 messages: the key binding + the finalize
310+
assert_eq!(output.len(), 2 * 64);
311+
assert_msg(&output, 1, &[0x03, 0xFD, 0xFE, 0xFF]);
308312
}
309313

310314
}

src/keyboard/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ use itertools::Itertools as _;
1717
pub trait Keyboard {
1818
fn bind_key(&self, layer: u8, key: Key, expansion: &Macro, output: &mut Vec<u8>) -> Result<()>;
1919
fn set_led(&mut self, args: &[String], output: &mut Vec<u8>) -> Result<()>;
20-
/// Called after all bind_key calls to finalize/commit the config.
21-
/// Default implementation does nothing (k884x handles this inline).
22-
fn finalize(&self, _output: &mut Vec<u8>) {}
2320

2421
fn preferred_endpoint() -> u8 where Self: Sized;
2522
}

src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ fn main() -> Result<()> {
102102
}
103103
}
104104

105-
// Finalize (device-specific commit sequence)
106-
keyboard.finalize(&mut output);
107-
108105
// Send all accumulated data to device
109106
send_to_device(&handle, endpoint, &output)?;
110107
}

0 commit comments

Comments
 (0)