diff --git a/KeyboardioFirmware.ino b/KeyboardioFirmware.ino index 058d5d07..e03ddd90 100644 --- a/KeyboardioFirmware.ino +++ b/KeyboardioFirmware.ino @@ -7,6 +7,8 @@ #include "HID-Project.h" KeyboardStorage Storage; +LEDControl BlinkyLights; + void set_keymap(Key keymapEntry, byte matrixStateEntry) { if (keymapEntry.flags & SWITCH_TO_KEYMAP) { @@ -74,7 +76,7 @@ void setup() { Keyboard.begin(); Mouse.begin(); implementation_setup_leds(); - led_bootup(); + BlinkyLights.led_bootup(); implementation_pins_setup(); temporary_keymap = primary_keymap = Storage.load_primary_keymap(); @@ -86,7 +88,7 @@ void loop() { TS("about to scan the matrix") scan_matrix(); 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) { if (key_toggled_on (switchState)) { if (mappedKey.rawKey == LED_TOGGLE) { - next_led_mode(); + BlinkyLights.next_led_mode(); } } } else if (mappedKey.flags & IS_SYSCTL) { diff --git a/led_control.cpp b/led_control.cpp index ab1c8e0c..2f2bdceb 100644 --- a/led_control.cpp +++ b/led_control.cpp @@ -33,17 +33,17 @@ static uint8_t current_chase_counter = 0; // 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); } -cRGB get_key_color(byte row, byte col) { +cRGB LEDControl::get_key_color(byte row, byte 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); if (mode == LED_MODE_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++) { implementation_led_set_crgb_at(i, color); } } -void next_led_mode() { +void LEDControl::next_led_mode() { if (led_mode++ >= LED_MODES) { led_mode = 0; } } -void set_led_mode(uint8_t mode) { +void LEDControl::set_led_mode(uint8_t mode) { led_mode = mode; } -void update_leds(uint8_t numlock_enabled) { +void LEDControl::update_leds(uint8_t numlock_enabled) { if (numlock_enabled) { if (led_mode != LED_SPECIAL_MODE_NUMLOCK) { 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++) { implementation_led_set_crgb_at(i, led_off); } @@ -129,11 +129,11 @@ void led_effect_numlock_update() { implementation_led_sync(); } -void led_effect_steady_update() { +void LEDControl::led_effect_steady_update() { 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/ breathe_brightness = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0; // change the brightness for next time through the loop: @@ -148,13 +148,13 @@ void led_compute_breath() { SetHSV(led_breathe,200, 255, breathe_brightness); } -void led_effect_breathe_update() { +void LEDControl::led_effect_breathe_update() { led_compute_breath(); set_all_leds_to(led_breathe); implementation_led_sync(); } -void led_effect_chase_update() { +void LEDControl::led_effect_chase_update() { if (current_chase_counter++ < chase_threshold) { return; } @@ -171,7 +171,7 @@ void led_effect_chase_update() { implementation_led_sync(); } -void led_effect_rainbow_update() { +void LEDControl::led_effect_rainbow_update() { if (rainbow_current_ticks++ < rainbow_ticks) { return; } else { @@ -186,7 +186,7 @@ void led_effect_rainbow_update() { implementation_led_sync(); } -void led_effect_rainbow_wave_update() { +void LEDControl::led_effect_rainbow_wave_update() { if (rainbow_current_ticks++ < rainbow_wave_ticks) { return; } else { @@ -208,7 +208,7 @@ void led_effect_rainbow_wave_update() { implementation_led_sync(); } -void led_bootup() { +void LEDControl::led_bootup() { set_all_leds_to(led_off); 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_sync(); delay(250); @@ -240,11 +240,12 @@ void led_type_letter(uint8_t letter) { } - -void SetHSV(cRGB crgb, int hue, byte sat, byte val) { +/* SetHSV from light_ws2812. Their source was: + * getRGB() function based on + * 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 - The dim_curve is used only on brightness/value and on saturation (inverted). - This looks the most natural. */ int base; diff --git a/led_control.h b/led_control.h index e69e5701..99ca063c 100644 --- a/led_control.h +++ b/led_control.h @@ -15,21 +15,24 @@ #define LED_SPECIAL_MODE_NUMLOCK 100 -void update_leds(uint8_t numlock_enabled); -void set_all_leds_to(cRGB color); +class LEDControl { + public: + 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); -void next_led_mode(); + private: void set_key_color(uint8_t row, uint8_t col, cRGB color); cRGB get_key_color(uint8_t row, uint8_t col); - void led_compute_breath(); void led_effect_breathe_init(); void led_effect_rainbow_init(); void led_effect_chase_init(); void led_effect_steady_init(); -void led_Effect_heatmap_init(); +void led_effect_heatmap_init(); void led_effect_breathe_update(); void led_effect_rainbow_update(); @@ -38,7 +41,9 @@ void led_effect_chase_update(); void led_effect_steady_update(); void led_effect_heatmap_update(); void led_effect_numlock_update(); -void led_bootup(); -void led_type_letter(uint8_t letter); +void set_all_leds_to(cRGB color); void SetHSV(cRGB crgb, int hue, byte sat, byte val); +void initialize_led_mode(uint8_t mode); +}; +