From 6a35d6fe037ab1e0d11fb285cd4b845261dabc6b Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 14 Mar 2015 22:42:43 -0700 Subject: [PATCH] snapshot led stuff --- keymaps_generated.h | 9 ++- keymaps_h-template | 3 +- led_control.cpp | 166 +++++++++++++++++--------------------------- led_control.h | 35 +++++++++- 4 files changed, 104 insertions(+), 109 deletions(-) diff --git a/keymaps_generated.h b/keymaps_generated.h index d9781c19..2f61bc6a 100644 --- a/keymaps_generated.h +++ b/keymaps_generated.h @@ -38,17 +38,22 @@ {Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Tab, Key_LGUI, Key_RAlt, Key_Return, 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_RShift, Key_RShift, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus},\ }, +#define KEYMAP_SYMMETRIC60_QWERTY { /* Generated keymap for SYMMETRIC60_QWERTY */ {Key_Esc, Key_1, Key_2, Key_3, Key_4, Key_5, Key_Minus, Key_Equals, Key_6, Key_7, Key_8, Key_9, Key_0, Key_Backspace},\ + {Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_LSquareBracket, Key_RSquareBracket, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Backslash},\ + {Key_LCtrl, Key_A, Key_S, Key_D, Key_F, Key_G, Key_Return, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote},\ + {Key_LShift, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Tab, Key_KeymapNext_Momentary, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_RShift},\ + {Key_LCtrl, Key_LAlt, Key_LGUI, Key_Backspace, Key_Backspace, Key_KeymapNext_Momentary, Key_Space, Key_Space, Key_RGUI, Key_RAlt, Key_RCtrl},\ +}, #define KEYMAP_WORKMAN { /* Generated keymap for WORKMAN */ {Key_skip, Key_1, Key_2, Key_3, Key_4, Key_5, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip},\ {Key_Backtick, Key_Q, Key_D, Key_R, Key_W, Key_B, Key_skip, Key_skip, Key_J, Key_F, Key_U, Key_P, Key_Semicolon, Key_Equals},\ {Key_PageUp, Key_A, Key_S, Key_H, Key_T, Key_G, Key_Tab, Key_Return, Key_Y, Key_N, Key_E, Key_O, Key_I, Key_Quote},\ {Key_PageDn, Key_Z, Key_X, Key_M, Key_C, Key_V, Key_Esc, Key_Keymap0, Key_K, Key_L, Key_Comma, Key_Period, Key_Slash, Key_Minus},\ {Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_KeymapNext_Momentary, Key_skip, Key_skip, Key_skip, Key_skip, Key_KeymapNext_Momentary, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\ }, -#define KEYMAPS 2 +#define KEYMAPS 1 // This is a total waste. we should only ever include any given keymap once static const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_QWERTY_PIERS - KEYMAP_GENERIC_FN2 diff --git a/keymaps_h-template b/keymaps_h-template index bf63106f..cea74cba 100644 --- a/keymaps_h-template +++ b/keymaps_h-template @@ -1,8 +1,7 @@ -#define KEYMAPS 2 +#define KEYMAPS 1 // This is a total waste. we should only ever include any given keymap once static const Key keymaps[KEYMAPS][ROWS][COLS] = { KEYMAP_QWERTY_PIERS - KEYMAP_GENERIC_FN2 diff --git a/led_control.cpp b/led_control.cpp index 71535490..00f981f0 100644 --- a/led_control.cpp +++ b/led_control.cpp @@ -1,127 +1,89 @@ #include -#include "WS2812.h" #include "led_control.h" -#include "KeyboardConfig.h" - -WS2812 LED(LED_COUNT); cRGB value; -byte intensity; -byte sign; -byte offset=0; +WS2812 LED(LED_COUNT); +int led_mode; +int last_led_mode; -void setup_leds() { - LED.setOutput(LED_DATA_PIN); +cRGB led_off; - LED.setColorOrderRGB(); // Uncomment for RGB color order - //LED.setColorOrderBRG(); // Uncomment for BRG color order - //LED.setColorOrderGRB(); // Uncomment for GRB color order (Default; will be used if none other is defined.) - intensity = 0; - sign = 1; +cRGB led_steady; + +cRGB led_breathe; + + +void setup_leds() { +led_off.r=0; +led_off.g=0; +led_off.b=0; +led_steady.r=30; +led_steady.g=30; +led_steady.b=30; + LED.setOutput(LED_DATA_PIN); + LED.setColorOrderRGB(); // Uncomment for RGB color order + led_mode=LED_MODE_STEADY; } - void update_leds_rgb(){ +byte key_to_led(byte row, byte col) { + return key_led_map[row][col]; +} - if (1) { - - - byte i = 0; - if (sign) { - intensity+=1; - if (intensity >= 128) - sign = 0; - } - else { - intensity-=1; - if (intensity < 5){ - sign = 1; - offset++;} - } -if (offset>2) offset=0; - - while (i < LED_COUNT){ - - - if (((i+offset) % 3) == 0) { // First LED, and every third after that - value.b = 0; - value.g = 0; - value.r = intensity; // RGB Value -> Red Only - LED.set_crgb_at(i, value); // Set value at LED found at index 0 - } - else if (((i+offset )% 3) == 1) { // Second LED, and every third after that - value.b = 0; - value.g = intensity; - value.r = 0; // RGB Value -> Green Only - LED.set_crgb_at(i, value); // Set value at LED found at index 0 - } - else { // Third LED, and every third after that - value.b = intensity; - value.g = 0; - value.r = 0; // RGB Value -> Blue Only - LED.set_crgb_at(i, value); // Set value at LED found at index 0 - } - - - i++; - } +void set_key_color(byte row, byte col, cRGB color){ + LED.set_crgb_at(key_to_led(row,col),color); +} + +cRGB get_key_color(byte row, byte col){ + return LED.get_crgb_at(key_to_led(row,col)); +} - + void update_leds_rgb(){ + //LED.set_crgb_at(i, value); // Set value at LED found at index 0 LED.sync(); // Sends the data to the LEDs - } } +void initialize_led_mode(int mode) { + if (mode == LED_MODE_OFF) { + set_all_leds_to(led_off); + } else if (mode == LED_MODE_HEATMAP) { + } else if (mode == LED_MODE_BREATHE) { -int red; -int green; -int blue; -int rednext=1; -int bluenext=1; -int greennext=1; -void update_leds_scroll() { - int i=0; - - if(red==0&& blue==0&& green==0) { - red=random(50); - green=random(50); - blue=random(50); - rednext=bluenext=greennext=1; + } else if (mode == LED_MODE_RAINBOW) { + } else if (mode == LED_MODE_CHASE) { + } else if (mode == LED_MODE_STEADY) { + set_all_leds_to(led_steady); } +} - if (red<0) {red=0;} - if (green<0) {green=0;} - if(blue<0){blue=0;} +void set_all_leds_to(cRGB color) { + for(int i=0; i100) { - rednext=-1; - bluenext=-1; - greennext=-1; - } -// if (green>100) { -// greennext=-1; -// } -// if (blue>100){ -// bluenext=-1; -// } - red+=rednext; - green+=greennext; - blue+=bluenext; - - value.r=red; - value.g=green; - value.b=blue; - - - while (i < LED_COUNT){ - LED.set_crgb_at(i, value); // Set value at LED found at index 0 - i++; - } - LED.sync(); } void update_leds() { - update_leds_rgb(); + if (led_mode != last_led_mode) { + initialize_led_mode(led_mode); + } + if (led_mode == LED_MODE_OFF) { + } else if (led_mode == LED_MODE_HEATMAP) { + } else if (led_mode == LED_MODE_BREATHE) { + // algorithm from http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + int brightness = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0; + led_breathe.r=brightness; + led_breathe.g=brightness; + led_breathe.b=brightness; + + } else if (led_mode == LED_MODE_RAINBOW) { + } else if (led_mode == LED_MODE_CHASE) { + } else if (led_mode == LED_MODE_STEADY) { + } + + LED.sync(); + last_led_mode = led_mode; } diff --git a/led_control.h b/led_control.h index f454d8e6..324a4d66 100644 --- a/led_control.h +++ b/led_control.h @@ -1,8 +1,37 @@ +#ifndef LED_CONTROL_H +#define LED_CONTROL_H + +#include "WS2812.h" +#define LED_MODES 6 +#define LED_MODE_OFF 0 +#define LED_MODE_STEADY 1 +#define LED_MODE_BREATHE 2 +#define LED_MODE_RAINBOW 3 +#define LED_MODE_HEATMAP 4 +#define LED_MODE_CHASE 5 + +#define LED_DATA_PIN 4 + +#define LED_COUNT 64 + +static const int key_led_map[4][16] = +{ + {3,4,11,12,19,20,27,28, 35,39,40,47,48,55,56,63}, + {2,5,10,13,18,21,26,29, 34,38,41,46,49,54,57,62}, + {1,6,9,14, 17,22,25,30, 33,37,42,45,50,53,58,61}, + {0,7,8,15,16,23,24,31, 32,36,43,44,51,52,59,60}, +}; -#ifndef led_control_h -#define led_control_h -void setup_leds(); + +void setup_leds(); void update_leds(); +void set_all_leds_to(cRGB color); + + + +byte key_to_led(byte row, byte col); +void set_key_color(byte row, byte col); +cRGB get_key_color(byte row, byte col); #endif