Scott Perry 8 years ago
commit 9ebc996661

@ -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();
}

@ -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);

@ -24,9 +24,9 @@ void setup() {
void loop() {
KeyboardHardware.scan_matrix();
LEDControl.update(temporary_keymap);
Keyboard.sendReport();
Keyboard.releaseAll();
LEDControl.update(temporary_keymap);
}

@ -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;
}
@ -91,6 +94,7 @@ void LEDControl_::update(uint8_t current_keymap) {
}
led_sync();
last_led_mode = led_mode;
}
@ -101,15 +105,13 @@ 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
led_sync();
}
void LEDControl_::effect_steady_update() {
led_sync();
}
void LEDControl_::led_compute_breath() {
@ -130,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() {
@ -138,16 +139,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_sync();
led_set_crgb_at(pos - (chase_sign * chase_pixels), led_red);
}
void LEDControl_::effect_rainbow_update() {
@ -162,7 +162,6 @@ void LEDControl_::effect_rainbow_update() {
rainbow_hue %= 255;
}
set_all_leds_to(rainbow);
led_sync();
}
void LEDControl_::effect_rainbow_wave_update() {
@ -184,7 +183,6 @@ void LEDControl_::effect_rainbow_wave_update() {
if (rainbow_hue >= 255) {
rainbow_hue %= 255;
}
led_sync();
}
void LEDControl_::boot_animation() {
@ -210,7 +208,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);

@ -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();

@ -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

@ -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},\

@ -6,27 +6,107 @@ 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();
leftHandState.all = 0;
rightHandState.all = 0;
Wire.begin();
TWBR=12;
}
void Model01::led_set_crgb_at(uint8_t i, cRGB crgb) {
if(i<32) {
leftHand.ledData.leds[i] = crgb;
} 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?
}
}
void Model01::led_sync() {
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();
rightHand.sendLEDData();
rightHand.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);
for (byte col = 0; col < 4; col++) {
handle_key_event(row, col, &key_data);
handle_key_event(row, (8- 1) - col, &key_data);
handle_key_event(row, col,
bitRead(leftHandState.all, keynum),
bitRead(previousLeftHandState.all, keynum)
);
handle_key_event(row, (8+ col),
bitRead(rightHandState.all, keynum),
bitRead(previousRightHandState.all, keynum)
);
}
}
//scan the Keyboard matrix looking for connections
}

@ -20,15 +20,21 @@ 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);
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},

@ -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,17 @@ 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]);
}
if (mappedKey.flags & SYNTHETIC_KEY) {
handle_synthetic_key_event(*switchState, mappedKey);
} else if (key_is_pressed(*switchState)) {
handle_keymap_key_event(keymaps[primary_keymap][row][col], currentState, previousState);
} 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 +78,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 +89,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);
}

@ -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);

@ -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;
}
}

@ -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);

@ -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 , . / -

Loading…
Cancel
Save