From 9bb0e64f4ad06f4a688100e8af924feaef1fc0e8 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 31 Jan 2016 17:32:43 -0800 Subject: [PATCH] move "scan_matrix" into the implementation specific class, since it looks like it'll be very different between beta and production --- KeyboardioFirmware.h | 1 - KeyboardioFirmware.ino | 22 ++-------------------- implementation/Model01Beta.cpp | 27 +++++++++++++++++++++++++++ implementation/Model01Beta.h | 18 ++++++++---------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/KeyboardioFirmware.h b/KeyboardioFirmware.h index e9380b83..8ad4b920 100644 --- a/KeyboardioFirmware.h +++ b/KeyboardioFirmware.h @@ -32,7 +32,6 @@ extern uint8_t primary_keymap; extern uint8_t temporary_keymap; -void scan_matrix(); #ifndef VERSION #define VERSION "locally-built" diff --git a/KeyboardioFirmware.ino b/KeyboardioFirmware.ino index 204828ec..e63e9b2a 100644 --- a/KeyboardioFirmware.ino +++ b/KeyboardioFirmware.ino @@ -13,38 +13,20 @@ uint8_t primary_keymap = 0; uint8_t temporary_keymap = 0; -void scan_matrix() { - //scan the Keyboard matrix looking for connections - for (byte row = 0; row < LEFT_ROWS; row++) { - KeyboardHardware.scan_row(row); - - for (byte col = 0; col < LEFT_COLS; col++) { - KeyboardHardware.scan_left_col(row,col,&matrixState[row][col]); - handle_key_event(row, col); - - if (KeyboardHardware.right_hand_connected()) { - KeyboardHardware.scan_right_col(row,col,&matrixState[row][(COLS - 1) - col]); - handle_key_event(row, (COLS - 1) - col); - } - } - KeyboardHardware.finish_scanning_row(row); - } -} - void setup() { wdt_disable(); Keyboard.begin(); Mouse.begin(); KeyboardHardware.leds_setup(); - LEDControl.boot_animation(); KeyboardHardware.pins_setup(); + LEDControl.boot_animation(); temporary_keymap = primary_keymap = Storage.load_primary_keymap(KEYMAPS); } void loop() { - scan_matrix(); + KeyboardHardware.scan_matrix(); Keyboard.sendReport(); Keyboard.releaseAll(); LEDControl.update(temporary_keymap); diff --git a/implementation/Model01Beta.cpp b/implementation/Model01Beta.cpp index 724e40df..bf6b1df5 100644 --- a/implementation/Model01Beta.cpp +++ b/implementation/Model01Beta.cpp @@ -34,6 +34,33 @@ void Model01Beta_::led_sync() { LED.sync(); } + + + +void Model01Beta_::scan_matrix() { + //scan the Keyboard matrix looking for connections + for (byte row = 0; row < LEFT_ROWS; row++) { + KeyboardHardware.scan_row(row); + + for (byte col = 0; col < LEFT_COLS; col++) { + KeyboardHardware.scan_left_col(row,col,&matrixState[row][col]); + handle_key_event(row, col); + + if (KeyboardHardware.right_hand_connected()) { + KeyboardHardware.scan_right_col(row,col,&matrixState[row][(COLS - 1) - col]); + handle_key_event(row, (COLS - 1) - col); + } + } + KeyboardHardware.finish_scanning_row(row); + } +} + + + + + + + void Model01Beta_::scan_row(byte row) { if (left_initted) { leftsx1509.updatePinState(left_rowpins[row], LOW); diff --git a/implementation/Model01Beta.h b/implementation/Model01Beta.h index 669d281a..c57053c1 100644 --- a/implementation/Model01Beta.h +++ b/implementation/Model01Beta.h @@ -1,8 +1,10 @@ #pragma once +#include "../keymaps.h" #include "../generated/keymaps.h" #include "WS2812.h" #include "KeyboardioSX1509.h" +#include "../key_events.h" #define USE_HSV_CURVE 1 @@ -25,11 +27,6 @@ static uint8_t right_rowpins[]= {8,9,10,11}; -#define COLS 16 -#define ROWS 4 -#define KEYMAPS 3 -#define NUMPAD_KEYMAP 2 -#define KEYMAP_LIST KEYMAP_QWERTY KEYMAP_GENERIC_FN2 KEYMAP_NUMPAD class Model01Beta_ { @@ -40,13 +37,9 @@ class Model01Beta_ { void led_set_crgb_at(uint8_t i, cRGB crgb); cRGB get_key_color(byte row, byte col); + void scan_matrix(void); - void scan_row(byte row); - void finish_scanning_row(byte row); - void scan_right_col(byte row, byte col, uint8_t *state); - void scan_left_col(byte row, byte col, uint8_t *state); void pins_setup(); - boolean right_hand_connected(void); void leds_setup(); @@ -57,6 +50,11 @@ class Model01Beta_ { int right_initted = 0; int left_initted = 0; + boolean right_hand_connected(void); + void scan_row(byte row); + void finish_scanning_row(byte row); + void scan_right_col(byte row, byte col, uint8_t *state); + void scan_left_col(byte row, byte col, uint8_t *state); void make_input(sx1509Class sx1509, uint8_t pin) ; void make_output(sx1509Class sx1509, uint8_t pin) ; int setup_sx1509 (sx1509Class sx1509, uint8_t colpins[], uint8_t rowpins[]);