Skip to content

Commit

Permalink
feat(via): add set buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Oct 31, 2023
1 parent 979018c commit fe40c37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions rmk/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ impl<const ROW: usize, const COL: usize, const NUM_LAYER: usize> KeyMap<ROW, COL
}
}

pub fn get_keymap_config(&self) -> (usize, usize, usize) {
(ROW, COL, NUM_LAYER)
}

pub fn set_action_at(&mut self, row: usize, col: usize, layer_num: usize, action: KeyAction) {
self.layers[layer_num][row][col] = action;
}
Expand Down
28 changes: 24 additions & 4 deletions rmk/src/via/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,28 @@ pub fn process_via_packet<
// size <= 28
let size = report.output_data[3];
let mut idx = 4;
let (row_num, col_num, _layer_num) = keymap.get_keymap_config();
keymap
.layers
.iter_mut()
.flatten()
.flatten()
.skip(offset as usize)
.take(size as usize)
.for_each(|a| {
.enumerate()
.for_each(|(i, a)| {
let via_keycode = LittleEndian::read_u16(&report.output_data[idx..idx + 2]);
let action = from_via_keycode(via_keycode);
let action: crate::action::KeyAction = from_via_keycode(via_keycode);
*a = action;
idx += 2;
// TODO: Set buffer
})
let current_offset = offset as usize + i;
let (row, col, layer) = get_position_from_offset(current_offset, row_num, col_num);
info!("Setting keymap buffer of offset: {}, row,col,layer: {},{},{}", offset, row, col, layer);
match eeprom {
Some(e) => e.set_keymap_action(row, col, layer, action),
None => (),
}
});
}
ViaCommand::DynamicKeymapGetEncoder => {
warn!("Keymap get encoder -- not supported");
Expand All @@ -201,3 +209,15 @@ pub fn process_via_packet<
ViaCommand::Unhandled => report.input_data[0] = ViaCommand::Unhandled as u8,
}
}

pub fn get_position_from_offset(
offset: usize,
max_row: usize,
max_col: usize,
) -> (usize, usize, usize) {
let layer = offset / (max_col * max_row);
let current_layer_offset = offset % (max_col * max_row);
let row = current_layer_offset / max_col;
let col = current_layer_offset % max_col;
(row, col, layer)
}

0 comments on commit fe40c37

Please sign in to comment.