better implementation/general separation for keyswitch matrix

pull/18/head
Jesse Vincent 9 years ago
parent 0be763e1d0
commit 3c223d4b3d

@ -27,7 +27,6 @@ void setup();
extern HARDWARE_IMPLEMENTATION KeyboardHardware; extern HARDWARE_IMPLEMENTATION KeyboardHardware;
extern uint8_t matrixState[ROWS][COLS];
extern const Key keymaps[KEYMAPS][ROWS][COLS]; extern const Key keymaps[KEYMAPS][ROWS][COLS];
extern uint8_t primary_keymap; extern uint8_t primary_keymap;
extern uint8_t temporary_keymap; extern uint8_t temporary_keymap;

@ -7,7 +7,6 @@
#include "KeyboardioHID.h" #include "KeyboardioHID.h"
uint8_t matrixState[ROWS][COLS] = {0};
const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST }; const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST };
uint8_t primary_keymap = 0; uint8_t primary_keymap = 0;
uint8_t temporary_keymap = 0; uint8_t temporary_keymap = 0;

@ -23,12 +23,13 @@ void Model01::led_sync() {
void Model01::scan_matrix() { void Model01::scan_matrix() {
uint8_t key_data;
//scan the Keyboard matrix looking for connections //scan the Keyboard matrix looking for connections
for (byte row = 0; row < LEFT_ROWS; row++) { for (byte row = 0; row < LEFT_ROWS; row++) {
for (byte col = 0; col < LEFT_COLS; col++) { for (byte col = 0; col < LEFT_COLS; col++) {
handle_key_event(row, col); handle_key_event(row, col, &key_data);
handle_key_event(row, (COLS - 1) - col); handle_key_event(row, (COLS - 1) - col, &key_data);
} }
} }
} }

@ -4,7 +4,6 @@
#include "../keymaps.h" #include "../keymaps.h"
#include "../generated/keymaps.h"
#include "../key_events.h" #include "../key_events.h"

@ -42,11 +42,11 @@ void Model01Beta::scan_matrix() {
for (byte col = 0; col < LEFT_COLS; col++) { for (byte col = 0; col < LEFT_COLS; col++) {
scan_left_col(row,col,&matrixState[row][col]); scan_left_col(row,col,&matrixState[row][col]);
handle_key_event(row, col); handle_key_event(row, col, &matrixState[row][col]);
if (right_hand_connected()) { if (right_hand_connected()) {
scan_right_col(row,col,&matrixState[row][(COLS - 1) - col]); scan_right_col(row,col,&matrixState[row][(COLS - 1) - col]);
handle_key_event(row, (COLS - 1) - col); handle_key_event(row, (COLS - 1) - col, &matrixState[row][(COLS - 1) - col]);
} }
} }
finish_scanning_row(row); finish_scanning_row(row);

@ -2,7 +2,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "../keymaps.h" #include "../keymaps.h"
#include "../generated/keymaps.h"
#include "WS2812.h" #include "WS2812.h"
#include "KeyboardioSX1509.h" #include "KeyboardioSX1509.h"
#include "../key_events.h" #include "../key_events.h"
@ -41,7 +40,7 @@ class Model01Beta {
static WS2812 LED; static WS2812 LED;
int right_initted = 0; int right_initted = 0;
int left_initted = 0; int left_initted = 0;
uint8_t matrixState[ROWS][COLS] = {{0}};
uint8_t left_colpins[LEFT_COLS]= {7,6,5,4,3,2,1,0}; uint8_t left_colpins[LEFT_COLS]= {7,6,5,4,3,2,1,0};
uint8_t left_rowpins[LEFT_ROWS]= {8,9,10,11}; uint8_t left_rowpins[LEFT_ROWS]= {8,9,10,11};

@ -1,6 +1,6 @@
#include "key_events.h" #include "key_events.h"
void handle_synthetic_key_event(byte switchState, Key mappedKey) { void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) {
if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) { if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) {
handle_mouse_key_event(switchState, mappedKey); handle_mouse_key_event(switchState, mappedKey);
} else if (! (mappedKey.flags & IS_INTERNAL) } else if (! (mappedKey.flags & IS_INTERNAL)
@ -44,19 +44,18 @@ void handle_synthetic_key_event(byte switchState, Key mappedKey) {
} }
} }
void handle_key_event(byte row, byte col) { void handle_key_event(byte row, byte col, uint8_t *switchState) {
//for every newly pressed button, figure out what logical key it is and send a key down event //for every newly pressed button, figure out what logical key it is and send a key down event
// for every newly released button, figure out what logical key it is and send a key up event // for every newly released button, figure out what logical key it is and send a key up event
byte switchState = matrixState[row][col];
Key mappedKey = keymaps[temporary_keymap][row][col]; Key mappedKey = keymaps[temporary_keymap][row][col];
if (keymaps[primary_keymap][row][col].flags & SWITCH_TO_KEYMAP) { if (keymaps[primary_keymap][row][col].flags & SWITCH_TO_KEYMAP) {
handle_keymap_key_event(switchState, keymaps[primary_keymap][row][col]); handle_keymap_key_event(*switchState, keymaps[primary_keymap][row][col]);
} }
if (mappedKey.flags & SYNTHETIC_KEY) { if (mappedKey.flags & SYNTHETIC_KEY) {
handle_synthetic_key_event(switchState, mappedKey); handle_synthetic_key_event(*switchState, mappedKey);
} else if (key_is_pressed(switchState)) { } else if (key_is_pressed(*switchState)) {
press_key(mappedKey); press_key(mappedKey);
} }
} }
@ -78,7 +77,7 @@ void press_key(Key mappedKey) {
} }
void handle_keymap_key_event(byte switchState, Key keymapEntry) { void handle_keymap_key_event(uint8_t switchState, Key keymapEntry) {
if (keymapEntry.flags & MOMENTARY ) { if (keymapEntry.flags & MOMENTARY ) {
if (key_toggled_on(switchState)) { if (key_toggled_on(switchState)) {
if ( keymapEntry.rawKey == KEYMAP_NEXT) { if ( keymapEntry.rawKey == KEYMAP_NEXT) {
@ -100,7 +99,7 @@ void handle_keymap_key_event(byte switchState, Key keymapEntry) {
} }
} }
void handle_mouse_key_event(byte switchState, Key mappedKey) { void handle_mouse_key_event(uint8_t switchState, Key mappedKey) {
if (key_is_pressed(switchState)) { if (key_is_pressed(switchState)) {
if (mappedKey.rawKey & KEY_MOUSE_UP) { if (mappedKey.rawKey & KEY_MOUSE_UP) {
MouseWrapper.move(0,-1); MouseWrapper.move(0,-1);

@ -7,15 +7,14 @@
#include "LEDControl.h" #include "LEDControl.h"
#include "Storage.h" #include "Storage.h"
extern uint8_t matrixState[ROWS][COLS];
extern const Key keymaps[KEYMAPS][ROWS][COLS]; extern const Key keymaps[KEYMAPS][ROWS][COLS];
extern uint8_t primary_keymap; extern uint8_t primary_keymap;
extern uint8_t temporary_keymap; extern uint8_t temporary_keymap;
// sending events to the computer // sending events to the computer
void handle_synthetic_key_event(byte switchState, Key mappedKey); void handle_synthetic_key_event(uint8_t switchState, Key mappedKey);
void handle_key_event(byte row, byte col); void handle_key_event(byte row, byte col, uint8_t *switch_state);
void press_key(Key mappedKey); void press_key(Key mappedKey);
void handle_keymap_key_event(byte switchState, Key keymapEntry); void handle_keymap_key_event(uint8_t switchState, Key keymapEntry);
void handle_mouse_key_event(byte switchState, Key mappedKey); void handle_mouse_key_event(uint8_t switchState, Key mappedKey);

Loading…
Cancel
Save