From 719ab8e6c7bb226ca7ec5e31dc145629daabb6a3 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 12 Jun 2016 21:53:37 -0700 Subject: [PATCH 01/15] Add a keymap for the Model 01 Spring 2016 prototype --- generated/keymaps.h | 6 +++--- layouts/qwerty | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/generated/keymaps.h b/generated/keymaps.h index fc54a671..7c9123e5 100644 --- a/generated/keymaps.h +++ b/generated/keymaps.h @@ -32,9 +32,9 @@ {Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_LShift, Key_RShift, Key_skip, Key_N, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadSlash, Key_Enter},\ }, #define KEYMAP_QWERTY { /* Generated keymap for QWERTY */ {Key_LEDEffectNext, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_LCtrl, Key_RCtrl, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_Keymap2},\ - {Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_KeymapNext_Momentary, Key_Backspace, Key_Space, Key_KeymapNext_Momentary, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},\ - {Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_LGUI, Key_RAlt, Key_Enter, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote},\ - {Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Esc, Key_LShift, Key_RShift, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},\ + {Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_Backspace, Key_Space, Key_KeymapNext_Momentary, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},\ + {Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Esc, Key_LGUI, Key_RAlt, Key_Enter, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote},\ + {Key_PageDn, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_KeymapNext_Momentary, Key_LShift, Key_RShift, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},\ }, #define KEYMAP_QWERTY_MOO { /* Generated keymap for QWERTY_MOO */ {Key_LEDEffectNext, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_LCtrl, Key_RCtrl, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_Keymap2},\ {Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_KeymapNext_Momentary, Key_Backspace, Key_Space, Key_KeymapNext_Momentary, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals},\ diff --git a/layouts/qwerty b/layouts/qwerty index 1ee58caf..acfab9b6 100644 --- a/layouts/qwerty +++ b/layouts/qwerty @@ -1,5 +1,5 @@ #NAME: QWERTY LEDEffectNext 1 2 3 4 5 skip LCtrl RCtrl skip 6 7 8 9 0 Keymap2 -` Q W E R T KeymapNext_Momentary Backspace Space KeymapNext_Momentary Y U I O P = -PageUp A S D F G Tab LGUI RAlt Enter H J K L ; ' -PageDn Z X C V B Esc LShift RShift skip N M , . / - +` Q W E R T Tab Backspace Space KeymapNext_Momentary Y U I O P = +PageUp A S D F G Esc LGUI RAlt Enter H J K L ; ' +PageDn Z X C V B KeymapNext_Momentary LShift RShift skip N M , . / - From 5e49c8fef359b46084582620854e8e13ea57b9a9 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 12 Jun 2016 21:54:40 -0700 Subject: [PATCH 02/15] Add an alternate version of our keystate code that depends on in-hardware debouncing --- key_events.cpp | 32 ++++++++++++++++---------------- key_events.h | 8 ++++---- keyswitch_state.cpp | 32 ++++++++++++++++++++++++++++++++ keyswitch_state.h | 5 +++++ 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/key_events.cpp b/key_events.cpp index 41adf125..20ced5fc 100644 --- a/key_events.cpp +++ b/key_events.cpp @@ -2,19 +2,19 @@ const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_LIST }; -void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) { +void handle_synthetic_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) { if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) { - handle_mouse_key_event(switchState, mappedKey); + handle_mouse_key_event(mappedKey, currentState, previousState); } else if (! (mappedKey.flags & IS_INTERNAL) && (mappedKey.rawKey == KEY_MOUSE_BTN_L || mappedKey.rawKey == KEY_MOUSE_BTN_M || mappedKey.rawKey == KEY_MOUSE_BTN_R)) { - if (key_toggled_on (switchState)) { + if (key_toggled_on(currentState, previousState)) { MouseWrapper.press_button( (mappedKey.rawKey == KEY_MOUSE_BTN_L ? KEY_MOUSE_BUTTON_LEFT : 0x00) | (mappedKey.rawKey == KEY_MOUSE_BTN_M ? KEY_MOUSE_BUTTON_MIDDLE : 0x00) | (mappedKey.rawKey == KEY_MOUSE_BTN_R ? KEY_MOUSE_BUTTON_RIGHT : 0x00) ); - } else if (key_toggled_off(switchState)) { + } else if (key_toggled_off(currentState, previousState)) { MouseWrapper.release_button( (mappedKey.rawKey == KEY_MOUSE_BTN_L ? KEY_MOUSE_BUTTON_LEFT : 0x00) | (mappedKey.rawKey == KEY_MOUSE_BTN_M ? KEY_MOUSE_BUTTON_MIDDLE : 0x00) | @@ -23,7 +23,7 @@ void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) { } - else if (key_toggled_on(switchState)) { + else if (key_toggled_on(currentState,previousState)) { if (mappedKey.rawKey & KEY_MOUSE_WARP && mappedKey.flags & IS_MOUSE_KEY) { // we don't pass in the left and up values because those are the // default, "no-op" conditionals @@ -46,18 +46,18 @@ void handle_synthetic_key_event(uint8_t switchState, Key mappedKey) { } } -void handle_key_event(byte row, byte col, uint8_t *switchState) { +void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previousState) { //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 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(keymaps[primary_keymap][row][col], currentState, previousState); } - if (mappedKey.flags & SYNTHETIC_KEY) { - handle_synthetic_key_event(*switchState, mappedKey); - } else if (key_is_pressed(*switchState)) { + else if (mappedKey.flags & SYNTHETIC_KEY) { + handle_synthetic_key_event( mappedKey, currentState, previousState); + } else if (key_is_pressed(currentState, previousState)) { press_key(mappedKey); } } @@ -79,9 +79,9 @@ void press_key(Key mappedKey) { } -void handle_keymap_key_event(uint8_t switchState, Key keymapEntry) { +void handle_keymap_key_event(Key keymapEntry, uint8_t currentState, uint8_t previousState) { if (keymapEntry.flags & MOMENTARY ) { - if (key_toggled_on(switchState)) { + if (key_toggled_on(currentState, previousState)) { if ( keymapEntry.rawKey == KEYMAP_NEXT) { temporary_keymap++; } else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) { @@ -90,19 +90,19 @@ void handle_keymap_key_event(uint8_t switchState, Key keymapEntry) { temporary_keymap = keymapEntry.rawKey; } } - if (key_toggled_off(switchState)) { + if (key_toggled_off(currentState, previousState)) { temporary_keymap = primary_keymap; } // switch keymap and stay there - } else if (key_toggled_on(switchState)) { + } else if (key_toggled_on(currentState, previousState)) { temporary_keymap = primary_keymap = keymapEntry.rawKey; Storage.save_primary_keymap(primary_keymap); } } -void handle_mouse_key_event(uint8_t switchState, Key mappedKey) { - if (key_is_pressed(switchState)) { +void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) { + if (key_is_pressed(currentState,previousState)) { if (mappedKey.rawKey & KEY_MOUSE_UP) { MouseWrapper.move(0,-1); } diff --git a/key_events.h b/key_events.h index b6fc2049..5442909e 100644 --- a/key_events.h +++ b/key_events.h @@ -14,9 +14,9 @@ extern uint8_t primary_keymap; extern uint8_t temporary_keymap; // sending events to the computer -void handle_synthetic_key_event(uint8_t switchState, Key mappedKey); -void handle_key_event(byte row, byte col, uint8_t *switch_state); +void handle_synthetic_key_event( Key mappedKey, uint8_t currentState, uint8_t previousState); +void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previousState); void press_key(Key mappedKey); -void handle_keymap_key_event(uint8_t switchState, Key keymapEntry); -void handle_mouse_key_event(uint8_t switchState, Key mappedKey); +void handle_keymap_key_event(Key keymapEntry, uint8_t currentState, uint8_t previousState); +void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState); diff --git a/keyswitch_state.cpp b/keyswitch_state.cpp index 9f0ec330..90ea9cbb 100644 --- a/keyswitch_state.cpp +++ b/keyswitch_state.cpp @@ -10,6 +10,14 @@ boolean key_was_pressed (byte keyState) { } } +boolean key_was_pressed (uint8_t currentState, uint8_t previousState) { + if (previousState) { + return true; + } else { + return false; + } +} + boolean key_is_pressed (byte keyState) { if ( keyState & B00000001 && keyState & B00000010 ) { return true; @@ -18,6 +26,14 @@ boolean key_is_pressed (byte keyState) { } } +boolean key_is_pressed (uint8_t currentState, uint8_t previousState) { + if (currentState) { + return true; + } else { + return false; + } +} + boolean key_toggled_on(byte keyState) { if (key_is_pressed(keyState) && ! key_was_pressed(keyState)) { return true; @@ -26,6 +42,14 @@ boolean key_toggled_on(byte keyState) { } } +boolean key_toggled_on (uint8_t currentState, uint8_t previousState) { + if (currentState && ! previousState ) { + return true; + } else { + return false; + } +} + boolean key_toggled_off(byte keyState) { if (key_was_pressed(keyState) && ! key_is_pressed(keyState)) { @@ -34,3 +58,11 @@ boolean key_toggled_off(byte keyState) { return false; } } + +boolean key_toggled_off (uint8_t currentState, uint8_t previousState) { + if (previousState && ! currentState ) { + return true; + } else { + return false; + } +} diff --git a/keyswitch_state.h b/keyswitch_state.h index 8466781b..13aa82d9 100644 --- a/keyswitch_state.h +++ b/keyswitch_state.h @@ -8,3 +8,8 @@ boolean key_was_pressed (byte keyState); boolean key_is_pressed (byte keyState); boolean key_toggled_on(byte keyState); boolean key_toggled_off(byte keyState); + +boolean key_was_pressed (uint8_t currentState, uint8_t previousState); +boolean key_is_pressed (uint8_t currentState, uint8_t previousState); +boolean key_toggled_on(uint8_t currentState, uint8_t previousState); +boolean key_toggled_off(uint8_t currentState, uint8_t previousState); From 06383e8c3dfcb89fbe539278f01674b500090ea1 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 12 Jun 2016 21:55:31 -0700 Subject: [PATCH 03/15] Add first-pass implementation of Model 01 spring 2016 prototype --- implementation/Model01.cpp | 102 ++++++++++++++++++++++++++++++++++--- implementation/Model01.h | 9 +++- 2 files changed, 101 insertions(+), 10 deletions(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 98cfb4c6..e6bb4138 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -6,27 +6,113 @@ Model01::Model01(void) { } +void Model01::enable_scanner_power(void) { + pinMode(13, OUTPUT); + digitalWrite(13, HIGH); +} + +// This lets the keyboard pull up to 1.6 amps from +// the host. That violates the USB spec. But it sure +// is pretty looking +void Model01::enable_high_power_leds(void) { + pinMode(7, OUTPUT); + digitalWrite(7, LOW); +} + void Model01::setup(void) { + enable_scanner_power(); + + // Consider not doing this until 30s after keyboard + // boot up, to make it easier to rescue things + // in case of power draw issues. + enable_high_power_leds(); + + Wire.begin(); + TWBR=12; } void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { + if(i<32) { + leftHand.ledData.leds[i] = crgb; + // controller2.ledData.leds[i] = color; + + + } else { + rightHand.ledData.leds[i-32] = crgb; + } + + } void Model01::led_sync() { -} + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); +} +void debug_key_event(keydata_t state, keydata_t previousState, uint8_t keynum, uint8_t row, uint8_t col) { + if (bitRead(state.all, keynum) != bitRead(previousState.all, keynum )) { + Serial.print("Looking at row "); + Serial.print(row); + Serial.print(", col "); + Serial.print(col); + Serial.print(" key # "); + Serial.print(keynum); + Serial.print(" "); + Serial.print(bitRead(previousState.all, keynum)); + Serial.print(" -> "); + Serial.print(bitRead(state.all, keynum )); + Serial.println(); + } +} void Model01::scan_matrix() { - uint8_t key_data; - //scan the Keyboard matrix looking for connections + previousLeftHandState = leftHandState; + previousRightHandState = rightHandState; + + if (leftHand.readKeys()) { + leftHandState = leftHand.getKeyData(); + } + + if (rightHand.readKeys()) { + rightHandState = rightHand.getKeyData(); + } + for (byte row = 0; row < 4; row++) { + for (byte col = 0; col < 8; col++) { + + uint8_t keynum = (col*4+row); + + debug_key_event(leftHandState, previousLeftHandState,keynum, row, col); + handle_key_event(row, col, + bitRead(leftHandState.all, keynum), + bitRead(previousLeftHandState.all, keynum) + ); - for (byte col = 0; col < 4; col++) { - handle_key_event(row, col, &key_data); - handle_key_event(row, (8- 1) - col, &key_data); + debug_key_event(rightHandState, previousRightHandState,keynum, row,col); + handle_key_event(row, (8+ col), + bitRead(rightHandState.all, keynum), + bitRead(previousRightHandState.all, keynum) + ); + } } - } -} + + + //scan the Keyboard matrix looking for connections +} diff --git a/implementation/Model01.h b/implementation/Model01.h index 3390ef80..001e516c 100644 --- a/implementation/Model01.h +++ b/implementation/Model01.h @@ -24,11 +24,16 @@ class Model01 { void scan_matrix(void); void setup(); - + void enable_high_power_leds(void); + void enable_scanner_power(void); private: - static KeyboardioScanner leftHand; + static KeyboardioScanner leftHand; static KeyboardioScanner rightHand; + keydata_t leftHandState; + keydata_t rightHandState; + keydata_t previousLeftHandState; + keydata_t previousRightHandState; static constexpr uint8_t key_led_map[4][16] = { {3,4,11,12,19,20,26,27, 36,37,43,44,51,52,59,60}, From 61798be38ea4325a3807af6334e416676e0764aa Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 13 Jun 2016 15:44:57 -0700 Subject: [PATCH 04/15] HACK: Invert the order of "write to i2c" and "read from i2c" HACK: Invert the order of "write to i2c" and "read from i2c" because we're seeing a weird phantom issue where after writing LED data to the ATTiny, and reading immediately, we get back its own address, a 0 byte and then garbage I2C,Setup Read to [0xB1] + ACK I2C,0xB1 + ACK I2C,0x00 + ACK I2C,0xFF + ACK I2C,0xFF + ACK I2C,0xFF + NAK It appears that this has ~nothing to do with the ATTiny's firmware, but I've been wrong before --- KeyboardioFirmware.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeyboardioFirmware.ino b/KeyboardioFirmware.ino index 40f1c683..daae7b47 100644 --- a/KeyboardioFirmware.ino +++ b/KeyboardioFirmware.ino @@ -24,9 +24,9 @@ void setup() { void loop() { KeyboardHardware.scan_matrix(); + LEDControl.update(temporary_keymap); Keyboard.sendReport(); Keyboard.releaseAll(); - LEDControl.update(temporary_keymap); } From 13576ae1fed7844404752d082b661cc6e1460c15 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 14 Jun 2016 09:32:24 -0700 Subject: [PATCH 05/15] Be clear about the fact that key state should start off zeroed out --- implementation/Model01.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index e6bb4138..69f1c941 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -26,7 +26,8 @@ void Model01::setup(void) { // boot up, to make it easier to rescue things // in case of power draw issues. enable_high_power_leds(); - + leftHandState.all = 0; + rightHandState.all = 0; Wire.begin(); TWBR=12; From 75205f28c38564c7120d36861323b182af74dc78 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 14 Jun 2016 09:33:42 -0700 Subject: [PATCH 06/15] astyle. no code changes. --- implementation/Model01.cpp | 34 +++++++++++++++++----------------- key_events.cpp | 3 +-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 69f1c941..17d89b62 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -39,10 +39,10 @@ void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { leftHand.ledData.leds[i] = crgb; // controller2.ledData.leds[i] = color; - - } else { - rightHand.ledData.leds[i-32] = crgb; - } + + } else { + rightHand.ledData.leds[i-32] = crgb; + } } @@ -68,19 +68,19 @@ void Model01::led_sync() { } void debug_key_event(keydata_t state, keydata_t previousState, uint8_t keynum, uint8_t row, uint8_t col) { - if (bitRead(state.all, keynum) != bitRead(previousState.all, keynum )) { - Serial.print("Looking at row "); - Serial.print(row); - Serial.print(", col "); - Serial.print(col); - Serial.print(" key # "); - Serial.print(keynum); - Serial.print(" "); - Serial.print(bitRead(previousState.all, keynum)); - Serial.print(" -> "); - Serial.print(bitRead(state.all, keynum )); - Serial.println(); - } + if (bitRead(state.all, keynum) != bitRead(previousState.all, keynum )) { + Serial.print("Looking at row "); + Serial.print(row); + Serial.print(", col "); + Serial.print(col); + Serial.print(" key # "); + Serial.print(keynum); + Serial.print(" "); + Serial.print(bitRead(previousState.all, keynum)); + Serial.print(" -> "); + Serial.print(bitRead(state.all, keynum )); + Serial.println(); + } } void Model01::scan_matrix() { previousLeftHandState = leftHandState; diff --git a/key_events.cpp b/key_events.cpp index 20ced5fc..741c9df5 100644 --- a/key_events.cpp +++ b/key_events.cpp @@ -54,8 +54,7 @@ void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previous if (keymaps[primary_keymap][row][col].flags & SWITCH_TO_KEYMAP) { handle_keymap_key_event(keymaps[primary_keymap][row][col], currentState, previousState); - } - else if (mappedKey.flags & SYNTHETIC_KEY) { + } else if (mappedKey.flags & SYNTHETIC_KEY) { handle_synthetic_key_event( mappedKey, currentState, previousState); } else if (key_is_pressed(currentState, previousState)) { press_key(mappedKey); From 6873a6a2ea3f229ffeb2ad7a6a034a5ce6922a5f Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 14 Jun 2016 09:34:59 -0700 Subject: [PATCH 07/15] We've moved from 8 banks of LED data to 4 banks --- implementation/Model01.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 17d89b62..91620801 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -48,22 +48,14 @@ void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { } void Model01::led_sync() { - rightHand.sendLEDData(); - rightHand.sendLEDData(); - rightHand.sendLEDData(); - rightHand.sendLEDData(); - rightHand.sendLEDData(); - rightHand.sendLEDData(); - rightHand.sendLEDData(); - rightHand.sendLEDData(); - leftHand.sendLEDData(); - leftHand.sendLEDData(); - leftHand.sendLEDData(); - leftHand.sendLEDData(); - leftHand.sendLEDData(); - leftHand.sendLEDData(); - leftHand.sendLEDData(); - leftHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + rightHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); + leftHand.sendLEDData(); } From 27e58c18d2c59847f33b0444a3e36625fde85cfe Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 14 Jun 2016 09:40:53 -0700 Subject: [PATCH 08/15] Remove commented out code, reformat --- implementation/Model01.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 91620801..3e2d3432 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -35,16 +35,11 @@ void Model01::setup(void) { void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { - if(i<32) { - leftHand.ledData.leds[i] = crgb; - // controller2.ledData.leds[i] = color; - - + if(i<32) { + leftHand.ledData.leds[i] = crgb; } else { rightHand.ledData.leds[i-32] = crgb; } - - } void Model01::led_sync() { From 1926379ebb62e0219c278b4445d3a0e3650d2c9f Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 14 Jun 2016 09:45:27 -0700 Subject: [PATCH 09/15] Remove verbose debugging on every step of the key matrix scan --- implementation/Model01.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 3e2d3432..47926d17 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -86,13 +86,11 @@ void Model01::scan_matrix() { uint8_t keynum = (col*4+row); - debug_key_event(leftHandState, previousLeftHandState,keynum, row, col); handle_key_event(row, col, bitRead(leftHandState.all, keynum), bitRead(previousLeftHandState.all, keynum) ); - debug_key_event(rightHandState, previousRightHandState,keynum, row,col); handle_key_event(row, (8+ col), bitRead(rightHandState.all, keynum), bitRead(previousRightHandState.all, keynum) From f5d0384354ed67bdc068b01c3a3cd0657353790d Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Tue, 14 Jun 2016 09:46:21 -0700 Subject: [PATCH 10/15] astyle. no code changes --- implementation/Model01.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 47926d17..6f0767fe 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -95,10 +95,7 @@ void Model01::scan_matrix() { bitRead(rightHandState.all, keynum), bitRead(previousRightHandState.all, keynum) ); - } } - - - + } //scan the Keyboard matrix looking for connections } From 40f71ffcaa790d0961291955957f0ae8f0fd17ef Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 15 Jun 2016 14:19:49 -0700 Subject: [PATCH 11/15] Guard against users accidentally overwriting the keymatrix buffer when trying to write an LED that doesn't exist --- implementation/Model01.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 6f0767fe..72e071b1 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -37,8 +37,11 @@ void Model01::setup(void) { void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { if(i<32) { leftHand.ledData.leds[i] = crgb; - } else { + } else if (i<64) { rightHand.ledData.leds[i-32] = crgb; + } else { + // TODO how do we want to handle debugging assertions about crazy user + // code that would overwrite other memory? } } From 0cfef37d44e37ef4c0a2cb2f5e9d7d78fec1f1d7 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 15 Jun 2016 14:35:10 -0700 Subject: [PATCH 12/15] Dumb LED effects update --- LEDControl.cpp | 27 +++++++++++++++------------ LEDControl.h | 8 +++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/LEDControl.cpp b/LEDControl.cpp index 6e70ee3e..f92284a3 100644 --- a/LEDControl.cpp +++ b/LEDControl.cpp @@ -14,10 +14,13 @@ LEDControl_::LEDControl_(void) { 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; + led_dark_blue.b = 127; + led_red.r = 255; + led_red.g = 0; + led_red.b = 0; + led_dark_red.r = 127; + led_dark_red.g = 0; + led_dark_red.b = 0; } @@ -101,7 +104,7 @@ void LEDControl_::effect_numlock_update() { led_set_crgb_at(i, led_off); } for (uint8_t i = 44; i < LED_COUNT; i++) { - led_set_crgb_at(i, led_bright_red); + led_set_crgb_at(i, led_red); } led_compute_breath(); led_set_crgb_at(60, led_breathe); // make numlock breathe @@ -138,15 +141,15 @@ void LEDControl_::effect_chase_update() { return; } current_chase_counter = 0; - led_set_crgb_at(pos - chase_pixels, led_off); - led_set_crgb_at(pos, led_dark_blue); + led_set_crgb_at(pos - (chase_sign* chase_pixels), led_off); + led_set_crgb_at(pos, led_off); - pos += chase_pixels; - if (pos > LED_COUNT || pos < 0) { - chase_pixels = -chase_pixels; - pos += chase_pixels; + pos += chase_sign; + if (pos >= LED_COUNT || pos <= 0) { + chase_sign = -chase_sign; } led_set_crgb_at(pos, led_blue); + led_set_crgb_at(pos - (chase_sign * chase_pixels), led_red); led_sync(); } @@ -210,7 +213,7 @@ void LEDControl_::boot_animation() { } void LEDControl_::type_letter(uint8_t letter) { - led_set_crgb_at(letter,led_bright_red); + led_set_crgb_at(letter,led_red); led_sync(); delay(250); led_set_crgb_at(letter,led_off); diff --git a/LEDControl.h b/LEDControl.h index 3f85c50c..76538c3c 100644 --- a/LEDControl.h +++ b/LEDControl.h @@ -36,7 +36,8 @@ class LEDControl_ { cRGB led_steady; cRGB led_blue; cRGB led_dark_blue; - cRGB led_bright_red; + cRGB led_red; + cRGB led_dark_red; cRGB led_breathe; cRGB rainbow; @@ -54,9 +55,10 @@ class LEDControl_ { uint8_t breathe_brightness = 0; // how bright the LED is int8_t breathe_fadeAmount=1; // how many points to fade the LED by (can be negative) - int8_t chase_pixels =1; //negative values when it's going backwar + int8_t chase_sign =1; //negative values when it's going backwar + uint8_t chase_pixels=5; uint8_t current_chase_counter = 0; - static const uint8_t chase_threshold = 6; + static const uint8_t chase_threshold = 20; // End RGB stuff void led_compute_breath(); void effect_breathe_init(); From ec40cfbbfba9587db93fb23eaf09afcd651fc1a7 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 20 Jun 2016 17:44:47 -0700 Subject: [PATCH 13/15] Add a 'get_crgb_at' API --- KeyboardConfig.cpp | 3 +++ KeyboardConfig.h | 1 + implementation/Model01.cpp | 8 ++++++++ implementation/Model01.h | 1 + 4 files changed, 13 insertions(+) diff --git a/KeyboardConfig.cpp b/KeyboardConfig.cpp index 77074dab..33d5238e 100644 --- a/KeyboardConfig.cpp +++ b/KeyboardConfig.cpp @@ -6,6 +6,9 @@ HARDWARE_IMPLEMENTATION KeyboardHardware; void led_set_crgb_at(uint8_t i, cRGB crgb) { KeyboardHardware.led_set_crgb_at(i,crgb); } +cRGB led_get_crgb_at(uint8_t i){ + KeyboardHardware.led_get_crgb_at(i); +} void led_sync(void) { KeyboardHardware.led_sync(); } diff --git a/KeyboardConfig.h b/KeyboardConfig.h index 0b871a7d..8933c6a3 100644 --- a/KeyboardConfig.h +++ b/KeyboardConfig.h @@ -10,6 +10,7 @@ // and the 'userspace' LED implementation. If my C++ were stronger, there woudl // certainly be a better way -JV 2016-02-01 void led_set_crgb_at(uint8_t i, cRGB crgb); +cRGB led_get_crgb_at(uint8_t i); void led_sync(void); diff --git a/implementation/Model01.cpp b/implementation/Model01.cpp index 72e071b1..e42593f6 100644 --- a/implementation/Model01.cpp +++ b/implementation/Model01.cpp @@ -45,6 +45,14 @@ void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) { } } +cRGB Model01::led_get_crgb_at(uint8_t i) { + if(i<32) { + return leftHand.ledData.leds[i]; + } else if (i<64) { + return rightHand.ledData.leds[i-32] ; + } +} + void Model01::led_sync() { rightHand.sendLEDData(); rightHand.sendLEDData(); diff --git a/implementation/Model01.h b/implementation/Model01.h index 001e516c..a7d0046b 100644 --- a/implementation/Model01.h +++ b/implementation/Model01.h @@ -20,6 +20,7 @@ class Model01 { void led_sync(void); void led_set_crgb_at(byte row, byte col, cRGB color); void led_set_crgb_at(uint8_t i, cRGB crgb); + cRGB led_get_crgb_at(uint8_t i); cRGB get_key_color(byte row, byte col); void scan_matrix(void); From 0f1bf7ab7f26ee3f9ac5016f84919d77bae06253 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 20 Jun 2016 17:48:17 -0700 Subject: [PATCH 14/15] Since we always update the LEDS, factor out that call into the surrounding code. --- LEDControl.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/LEDControl.cpp b/LEDControl.cpp index f92284a3..57ee2fe9 100644 --- a/LEDControl.cpp +++ b/LEDControl.cpp @@ -94,6 +94,7 @@ void LEDControl_::update(uint8_t current_keymap) { } + led_sync(); last_led_mode = led_mode; } @@ -108,11 +109,9 @@ void LEDControl_::effect_numlock_update() { } led_compute_breath(); led_set_crgb_at(60, led_breathe); // make numlock breathe - led_sync(); } void LEDControl_::effect_steady_update() { - led_sync(); } void LEDControl_::led_compute_breath() { @@ -133,7 +132,6 @@ void LEDControl_::led_compute_breath() { void LEDControl_::effect_breathe_update() { led_compute_breath(); set_all_leds_to(led_breathe); - led_sync(); } void LEDControl_::effect_chase_update() { @@ -150,7 +148,6 @@ void LEDControl_::effect_chase_update() { } led_set_crgb_at(pos, led_blue); led_set_crgb_at(pos - (chase_sign * chase_pixels), led_red); - led_sync(); } void LEDControl_::effect_rainbow_update() { @@ -165,7 +162,6 @@ void LEDControl_::effect_rainbow_update() { rainbow_hue %= 255; } set_all_leds_to(rainbow); - led_sync(); } void LEDControl_::effect_rainbow_wave_update() { @@ -187,7 +183,6 @@ void LEDControl_::effect_rainbow_wave_update() { if (rainbow_hue >= 255) { rainbow_hue %= 255; } - led_sync(); } void LEDControl_::boot_animation() { From a4bf3d099b386723b2e03281864278eeaaa68bc4 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 20 Jun 2016 17:49:24 -0700 Subject: [PATCH 15/15] Ignore failures when we reset the keyboard into bootloader mode. We probably already did the reset and are just trying to upload a new firmware. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bcc712ca..a110bd64 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ size: compile $(ARDUINO_TOOLS_PATH)/avr/bin/avr-size -C --mcu=$(MCU) $(ELF_FILE_PATH) reset-device: - stty -f $(DEVICE_PORT) 1200 ; + -stty -f $(DEVICE_PORT) 1200 ; flash: compile reset-device sleep 3