First pass of making led_control into a class

pull/18/head
Jesse Vincent 9 years ago
parent 7bc2c42cfe
commit 16411878aa

@ -7,6 +7,8 @@
#include "HID-Project.h" #include "HID-Project.h"
KeyboardStorage Storage; KeyboardStorage Storage;
LEDControl BlinkyLights;
void set_keymap(Key keymapEntry, byte matrixStateEntry) { void set_keymap(Key keymapEntry, byte matrixStateEntry) {
if (keymapEntry.flags & SWITCH_TO_KEYMAP) { if (keymapEntry.flags & SWITCH_TO_KEYMAP) {
@ -74,7 +76,7 @@ void setup() {
Keyboard.begin(); Keyboard.begin();
Mouse.begin(); Mouse.begin();
implementation_setup_leds(); implementation_setup_leds();
led_bootup(); BlinkyLights.led_bootup();
implementation_pins_setup(); implementation_pins_setup();
temporary_keymap = primary_keymap = Storage.load_primary_keymap(); temporary_keymap = primary_keymap = Storage.load_primary_keymap();
@ -86,7 +88,7 @@ void loop() {
TS("about to scan the matrix") TS("about to scan the matrix")
scan_matrix(); scan_matrix();
TS("updating LEDs"); TS("updating LEDs");
update_leds(temporary_keymap == NUMPAD_KEYMAP); BlinkyLights.update_leds(temporary_keymap == NUMPAD_KEYMAP);
} }
@ -109,7 +111,7 @@ void handle_synthetic_key_press(byte switchState, Key mappedKey) {
} else if (mappedKey.flags & IS_INTERNAL) { } else if (mappedKey.flags & IS_INTERNAL) {
if (key_toggled_on (switchState)) { if (key_toggled_on (switchState)) {
if (mappedKey.rawKey == LED_TOGGLE) { if (mappedKey.rawKey == LED_TOGGLE) {
next_led_mode(); BlinkyLights.next_led_mode();
} }
} }
} else if (mappedKey.flags & IS_SYSCTL) { } else if (mappedKey.flags & IS_SYSCTL) {

@ -33,17 +33,17 @@ static uint8_t current_chase_counter = 0;
// End RGB stuff // End RGB stuff
void set_key_color(byte row, byte col, cRGB color) { void LEDControl::set_key_color(byte row, byte col, cRGB color) {
implementation_led_set_crgb_at(row, col, color); implementation_led_set_crgb_at(row, col, color);
} }
cRGB get_key_color(byte row, byte col) { cRGB LEDControl::get_key_color(byte row, byte col) {
return implementation_get_key_color(row, col); return implementation_get_key_color(row, col);
} }
void initialize_led_mode(uint8_t mode) { void LEDControl::initialize_led_mode(uint8_t mode) {
set_all_leds_to(led_off); set_all_leds_to(led_off);
if (mode == LED_MODE_OFF) { if (mode == LED_MODE_OFF) {
// set_all_leds_to(led_off); // set_all_leds_to(led_off);
@ -58,27 +58,27 @@ void initialize_led_mode(uint8_t mode) {
} }
} }
void set_all_leds_to(cRGB color) { void LEDControl::set_all_leds_to(cRGB color) {
for (uint8_t i = 0; i < LED_COUNT; i++) { for (uint8_t i = 0; i < LED_COUNT; i++) {
implementation_led_set_crgb_at(i, color); implementation_led_set_crgb_at(i, color);
} }
} }
void next_led_mode() { void LEDControl::next_led_mode() {
if (led_mode++ >= LED_MODES) { if (led_mode++ >= LED_MODES) {
led_mode = 0; led_mode = 0;
} }
} }
void set_led_mode(uint8_t mode) { void LEDControl::set_led_mode(uint8_t mode) {
led_mode = mode; led_mode = mode;
} }
void update_leds(uint8_t numlock_enabled) { void LEDControl::update_leds(uint8_t numlock_enabled) {
if (numlock_enabled) { if (numlock_enabled) {
if (led_mode != LED_SPECIAL_MODE_NUMLOCK) { if (led_mode != LED_SPECIAL_MODE_NUMLOCK) {
stored_led_mode = led_mode; stored_led_mode = led_mode;
@ -117,7 +117,7 @@ void update_leds(uint8_t numlock_enabled) {
void led_effect_numlock_update() { void LEDControl::led_effect_numlock_update() {
for (uint8_t i = 0; i < 44; i++) { for (uint8_t i = 0; i < 44; i++) {
implementation_led_set_crgb_at(i, led_off); implementation_led_set_crgb_at(i, led_off);
} }
@ -129,11 +129,11 @@ void led_effect_numlock_update() {
implementation_led_sync(); implementation_led_sync();
} }
void led_effect_steady_update() { void LEDControl::led_effect_steady_update() {
implementation_led_sync(); implementation_led_sync();
} }
void led_compute_breath() { void LEDControl::led_compute_breath() {
// algorithm from http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ // algorithm from http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
breathe_brightness = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0; breathe_brightness = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
// change the brightness for next time through the loop: // change the brightness for next time through the loop:
@ -148,13 +148,13 @@ void led_compute_breath() {
SetHSV(led_breathe,200, 255, breathe_brightness); SetHSV(led_breathe,200, 255, breathe_brightness);
} }
void led_effect_breathe_update() { void LEDControl::led_effect_breathe_update() {
led_compute_breath(); led_compute_breath();
set_all_leds_to(led_breathe); set_all_leds_to(led_breathe);
implementation_led_sync(); implementation_led_sync();
} }
void led_effect_chase_update() { void LEDControl::led_effect_chase_update() {
if (current_chase_counter++ < chase_threshold) { if (current_chase_counter++ < chase_threshold) {
return; return;
} }
@ -171,7 +171,7 @@ void led_effect_chase_update() {
implementation_led_sync(); implementation_led_sync();
} }
void led_effect_rainbow_update() { void LEDControl::led_effect_rainbow_update() {
if (rainbow_current_ticks++ < rainbow_ticks) { if (rainbow_current_ticks++ < rainbow_ticks) {
return; return;
} else { } else {
@ -186,7 +186,7 @@ void led_effect_rainbow_update() {
implementation_led_sync(); implementation_led_sync();
} }
void led_effect_rainbow_wave_update() { void LEDControl::led_effect_rainbow_wave_update() {
if (rainbow_current_ticks++ < rainbow_wave_ticks) { if (rainbow_current_ticks++ < rainbow_wave_ticks) {
return; return;
} else { } else {
@ -208,7 +208,7 @@ void led_effect_rainbow_wave_update() {
implementation_led_sync(); implementation_led_sync();
} }
void led_bootup() { void LEDControl::led_bootup() {
set_all_leds_to(led_off); set_all_leds_to(led_off);
led_type_letter(LED_K); led_type_letter(LED_K);
@ -230,7 +230,7 @@ void led_bootup() {
} }
void led_type_letter(uint8_t letter) { void LEDControl::led_type_letter(uint8_t letter) {
implementation_led_set_crgb_at(letter,led_bright_red); implementation_led_set_crgb_at(letter,led_bright_red);
implementation_led_sync(); implementation_led_sync();
delay(250); delay(250);
@ -240,11 +240,12 @@ void led_type_letter(uint8_t letter) {
} }
/* SetHSV from light_ws2812. Their source was:
void SetHSV(cRGB crgb, int hue, byte sat, byte val) { * getRGB() function based on <http://www.codeproject.com/miscctrl/CPicker.asp>
* dim_curve idea by Jims
* */
void LEDControl::SetHSV(cRGB crgb, int hue, byte sat, byte val) {
/* convert hue, saturation and brightness ( HSB/HSV ) to RGB /* convert hue, saturation and brightness ( HSB/HSV ) to RGB
The dim_curve is used only on brightness/value and on saturation (inverted).
This looks the most natural.
*/ */
int base; int base;

@ -15,21 +15,24 @@
#define LED_SPECIAL_MODE_NUMLOCK 100 #define LED_SPECIAL_MODE_NUMLOCK 100
void update_leds(uint8_t numlock_enabled);
void set_all_leds_to(cRGB color);
void set_led_mode(uint8_t mode); class LEDControl {
public:
void next_led_mode(); void next_led_mode();
void led_bootup();
void update_leds(uint8_t numlock_enabled);
void led_type_letter(uint8_t letter);
void set_led_mode(uint8_t mode);
private:
void set_key_color(uint8_t row, uint8_t col, cRGB color); void set_key_color(uint8_t row, uint8_t col, cRGB color);
cRGB get_key_color(uint8_t row, uint8_t col); cRGB get_key_color(uint8_t row, uint8_t col);
void led_compute_breath(); void led_compute_breath();
void led_effect_breathe_init(); void led_effect_breathe_init();
void led_effect_rainbow_init(); void led_effect_rainbow_init();
void led_effect_chase_init(); void led_effect_chase_init();
void led_effect_steady_init(); void led_effect_steady_init();
void led_Effect_heatmap_init(); void led_effect_heatmap_init();
void led_effect_breathe_update(); void led_effect_breathe_update();
void led_effect_rainbow_update(); void led_effect_rainbow_update();
@ -38,7 +41,9 @@ void led_effect_chase_update();
void led_effect_steady_update(); void led_effect_steady_update();
void led_effect_heatmap_update(); void led_effect_heatmap_update();
void led_effect_numlock_update(); void led_effect_numlock_update();
void led_bootup(); void set_all_leds_to(cRGB color);
void led_type_letter(uint8_t letter);
void SetHSV(cRGB crgb, int hue, byte sat, byte val); void SetHSV(cRGB crgb, int hue, byte sat, byte val);
void initialize_led_mode(uint8_t mode);
};

Loading…
Cancel
Save