From b461309910c021107a9b88640449ea5800db1e74 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 1 Feb 2016 19:33:46 -0800 Subject: [PATCH 1/4] Make cRGB initialization not depend on struct order. --- LEDControl.cpp | 19 ++++++++++++++++++- LEDControl.h | 13 +++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/LEDControl.cpp b/LEDControl.cpp index d5eeb1c7..d1a81f77 100644 --- a/LEDControl.cpp +++ b/LEDControl.cpp @@ -1,6 +1,23 @@ #include "LEDControl.h" + + LEDControl_::LEDControl_(void) { + led_off.r = 0; + led_off.g = 0; + led_off.b = 0; + led_steady.r = 0; + led_steady.g = 255; + led_steady.b = 0; + led_blue.r = 0; + led_blue.g = 0; + led_blue.b = 255; + led_dark_blue.r = 0; + led_dark_blue.g = 0; + led_dark_blue .b = 127; + led_bright_red.r = 255; + led_bright_red.g = 0; + led_bright_red.b = 0; } @@ -107,7 +124,7 @@ void LEDControl_::led_compute_breath() { } - led_breathe.SetHSV(200, 255, breathe_brightness); + hsv_to_rgb(&led_breathe,200, 255, breathe_brightness); } void LEDControl_::effect_breathe_update() { diff --git a/LEDControl.h b/LEDControl.h index 0fc6f184..f633b3c6 100644 --- a/LEDControl.h +++ b/LEDControl.h @@ -32,17 +32,14 @@ class LEDControl_ { uint8_t pos = 0; void hsv_to_rgb(cRGB *cRGB, uint16_t h, uint16_t s, uint16_t v); - - - cRGB led_off = { .r = 0, .g = 0, .b = 0 }; - cRGB led_steady = { .r = 0, .g = 255, .b = 0}; - cRGB led_blue = { .r = 0, .g = 0, .b = 255 }; - cRGB led_dark_blue = { .r = 0, .g = 0, .b = 127 }; - cRGB led_bright_red = { .r = 255, .g = 0, .b = 0}; + cRGB led_off; + cRGB led_steady; + cRGB led_blue; + cRGB led_dark_blue; + cRGB led_bright_red; cRGB led_breathe; cRGB rainbow; - uint16_t rainbow_hue = 0; //stores 0 to 614 static const uint8_t rainbow_steps = 1; //number of hues we skip in a 360 range per update From 0be763e1d00a26dc7546b75547dae0f9fa3b5054 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 1 Feb 2016 19:42:14 -0800 Subject: [PATCH 2/4] We're not using WS2812 in the new implementation --- implementation/Model01.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index bbe90fa8..43d1b979 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -1,5 +1,4 @@ #include -#include "WS2812.h" #include "Model01.h" Model01::Model01(void) { From 3c223d4b3d3c386c944c629187873a87e05d0aba Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 1 Feb 2016 20:09:20 -0800 Subject: [PATCH 3/4] better implementation/general separation for keyswitch matrix --- KeyboardioFirmware.h | 1 - KeyboardioFirmware.ino | 1 - implementation/Model01.cpp | 5 +++-- implementation/Model01.h | 1 - implementation/Model01Beta.cpp | 4 ++-- implementation/Model01Beta.h | 3 +-- key_events.cpp | 15 +++++++-------- key_events.h | 9 ++++----- 8 files changed, 17 insertions(+), 22 deletions(-) diff --git a/KeyboardioFirmware.h b/KeyboardioFirmware.h index abef7126..6ffac297 100644 --- a/KeyboardioFirmware.h +++ b/KeyboardioFirmware.h @@ -27,7 +27,6 @@ void setup(); extern HARDWARE_IMPLEMENTATION KeyboardHardware; -extern uint8_t matrixState[ROWS][COLS]; extern const Key keymaps[KEYMAPS][ROWS][COLS]; extern uint8_t primary_keymap; extern uint8_t temporary_keymap; diff --git a/KeyboardioFirmware.ino b/KeyboardioFirmware.ino index 297e4312..54fec12b 100644 --- a/KeyboardioFirmware.ino +++ b/KeyboardioFirmware.ino @@ -7,7 +7,6 @@ #include "KeyboardioHID.h" -uint8_t matrixState[ROWS][COLS] = {0}; const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST }; uint8_t primary_keymap = 0; uint8_t temporary_keymap = 0; diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 43d1b979..f0dc6b7a 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -23,12 +23,13 @@ void Model01::led_sync() { void Model01::scan_matrix() { + uint8_t key_data; //scan the Keyboard matrix looking for connections for (byte row = 0; row < LEFT_ROWS; row++) { for (byte col = 0; col < LEFT_COLS; col++) { - handle_key_event(row, col); - handle_key_event(row, (COLS - 1) - col); + handle_key_event(row, col, &key_data); + handle_key_event(row, (COLS - 1) - col, &key_data); } } } diff --git a/implementation/Model01.h b/implementation/Model01.h index f8403c50..57ba4e14 100644 --- a/implementation/Model01.h +++ b/implementation/Model01.h @@ -4,7 +4,6 @@ #include "../keymaps.h" -#include "../generated/keymaps.h" #include "../key_events.h" diff --git a/implementation/Model01Beta.cpp b/implementation/Model01Beta.cpp index 78453c08..14ecc880 100644 --- a/implementation/Model01Beta.cpp +++ b/implementation/Model01Beta.cpp @@ -42,11 +42,11 @@ void Model01Beta::scan_matrix() { for (byte col = 0; col < LEFT_COLS; 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()) { 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); diff --git a/implementation/Model01Beta.h b/implementation/Model01Beta.h index a3e56e33..a8beaae8 100644 --- a/implementation/Model01Beta.h +++ b/implementation/Model01Beta.h @@ -2,7 +2,6 @@ #include #include "../keymaps.h" -#include "../generated/keymaps.h" #include "WS2812.h" #include "KeyboardioSX1509.h" #include "../key_events.h" @@ -41,7 +40,7 @@ class Model01Beta { static WS2812 LED; int right_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_rowpins[LEFT_ROWS]= {8,9,10,11}; diff --git a/key_events.cpp b/key_events.cpp index 4520c116..e37bade8 100644 --- a/key_events.cpp +++ b/key_events.cpp @@ -1,6 +1,6 @@ #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) ) { handle_mouse_key_event(switchState, mappedKey); } 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 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]; 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) { - handle_synthetic_key_event(switchState, mappedKey); - } else if (key_is_pressed(switchState)) { + handle_synthetic_key_event(*switchState, mappedKey); + } else if (key_is_pressed(*switchState)) { 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 (key_toggled_on(switchState)) { 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 (mappedKey.rawKey & KEY_MOUSE_UP) { MouseWrapper.move(0,-1); diff --git a/key_events.h b/key_events.h index fd01ab6a..a05aff0e 100644 --- a/key_events.h +++ b/key_events.h @@ -7,15 +7,14 @@ #include "LEDControl.h" #include "Storage.h" -extern uint8_t matrixState[ROWS][COLS]; extern const Key keymaps[KEYMAPS][ROWS][COLS]; extern uint8_t primary_keymap; extern uint8_t temporary_keymap; // sending events to the computer -void handle_synthetic_key_event(byte switchState, Key mappedKey); -void handle_key_event(byte row, byte col); +void handle_synthetic_key_event(uint8_t switchState, Key mappedKey); +void handle_key_event(byte row, byte col, uint8_t *switch_state); void press_key(Key mappedKey); -void handle_keymap_key_event(byte switchState, Key keymapEntry); -void handle_mouse_key_event(byte switchState, Key mappedKey); +void handle_keymap_key_event(uint8_t switchState, Key keymapEntry); +void handle_mouse_key_event(uint8_t switchState, Key mappedKey); From feebc13dcacbbcd1ce951f80559f7fbdc0172027 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 1 Feb 2016 20:17:42 -0800 Subject: [PATCH 4/4] Move keymap data structures out of the toplevel sketch --- KeyboardioFirmware.h | 1 - KeyboardioFirmware.ino | 1 - key_events.cpp | 2 ++ key_events.h | 2 ++ 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/KeyboardioFirmware.h b/KeyboardioFirmware.h index 6ffac297..b1919389 100644 --- a/KeyboardioFirmware.h +++ b/KeyboardioFirmware.h @@ -27,7 +27,6 @@ void setup(); extern HARDWARE_IMPLEMENTATION KeyboardHardware; -extern const Key keymaps[KEYMAPS][ROWS][COLS]; extern uint8_t primary_keymap; extern uint8_t temporary_keymap; diff --git a/KeyboardioFirmware.ino b/KeyboardioFirmware.ino index 54fec12b..40f1c683 100644 --- a/KeyboardioFirmware.ino +++ b/KeyboardioFirmware.ino @@ -7,7 +7,6 @@ #include "KeyboardioHID.h" -const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST }; uint8_t primary_keymap = 0; uint8_t temporary_keymap = 0; diff --git a/key_events.cpp b/key_events.cpp index e37bade8..1010adcf 100644 --- a/key_events.cpp +++ b/key_events.cpp @@ -1,5 +1,7 @@ #include "key_events.h" +const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST }; + void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) { if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) { handle_mouse_key_event(switchState, mappedKey); diff --git a/key_events.h b/key_events.h index a05aff0e..b6fc2049 100644 --- a/key_events.h +++ b/key_events.h @@ -6,6 +6,8 @@ #include "MouseWrapper.h" #include "LEDControl.h" #include "Storage.h" +#include "keymaps.h" +#include "generated/keymaps.h" extern const Key keymaps[KEYMAPS][ROWS][COLS]; extern uint8_t primary_keymap;