diff options
| -rw-r--r-- | docs/feature_rgblight.md | 2 | ||||
| -rw-r--r-- | quantum/rgblight.c | 12 | ||||
| -rw-r--r-- | quantum/rgblight.h | 4 | ||||
| -rw-r--r-- | quantum/rgblight_breathe_table.h | 116 | ||||
| -rw-r--r-- | quantum/template/avr/config.h | 6 | ||||
| -rw-r--r-- | util/rgblight_breathing_table_calc.c | 49 |
6 files changed, 185 insertions, 4 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md index 8b0a45cb6..4572f45b2 100644 --- a/docs/feature_rgblight.md +++ b/docs/feature_rgblight.md | |||
| @@ -114,7 +114,7 @@ The following options can be used to tweak the various animations: | |||
| 114 | |`RGBLIGHT_EFFECT_RGB_TEST` |*Not defined*|If defined, enable RGB test animation mode. | | 114 | |`RGBLIGHT_EFFECT_RGB_TEST` |*Not defined*|If defined, enable RGB test animation mode. | |
| 115 | |`RGBLIGHT_EFFECT_ALTERNATING` |*Not defined*|If defined, enable alternating animation mode. | | 115 | |`RGBLIGHT_EFFECT_ALTERNATING` |*Not defined*|If defined, enable alternating animation mode. | |
| 116 | |`RGBLIGHT_ANIMATIONS` |*Not defined*|If defined, enables all additional animation modes | | 116 | |`RGBLIGHT_ANIMATIONS` |*Not defined*|If defined, enables all additional animation modes | |
| 117 | |`RGBLIGHT_EFFECT_BREATHE_CENTER` |`1.85` |Used to calculate the curve for the breathing animation. Valid values are 1.0 to 2.7 | | 117 | |`RGBLIGHT_EFFECT_BREATHE_CENTER` |*Not defined*|If defined, used to calculate the curve for the breathing animation. Valid values are 1.0 to 2.7 | |
| 118 | |`RGBLIGHT_EFFECT_BREATHE_MAX` |`255` |The maximum brightness for the breathing mode. Valid values are 1 to 255 | | 118 | |`RGBLIGHT_EFFECT_BREATHE_MAX` |`255` |The maximum brightness for the breathing mode. Valid values are 1 to 255 | |
| 119 | |`RGBLIGHT_EFFECT_SNAKE_LENGTH` |`4` |The number of LEDs to light up for the "Snake" animation | | 119 | |`RGBLIGHT_EFFECT_SNAKE_LENGTH` |`4` |The number of LEDs to light up for the "Snake" animation | |
| 120 | |`RGBLIGHT_EFFECT_KNIGHT_LENGTH` |`3` |The number of LEDs to light up for the "Knight" animation | | 120 | |`RGBLIGHT_EFFECT_KNIGHT_LENGTH` |`3` |The number of LEDs to light up for the "Knight" animation | |
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 98755ff08..77772e292 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -879,6 +879,14 @@ void rgblight_task(void) { | |||
| 879 | 879 | ||
| 880 | // Effects | 880 | // Effects |
| 881 | #ifdef RGBLIGHT_EFFECT_BREATHING | 881 | #ifdef RGBLIGHT_EFFECT_BREATHING |
| 882 | |||
| 883 | #ifndef RGBLIGHT_EFFECT_BREATHE_CENTER | ||
| 884 | #ifndef RGBLIGHT_BREATHE_TABLE_SIZE | ||
| 885 | #define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 | ||
| 886 | #endif | ||
| 887 | #include <rgblight_breathe_table.h> | ||
| 888 | #endif | ||
| 889 | |||
| 882 | __attribute__ ((weak)) | 890 | __attribute__ ((weak)) |
| 883 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; | 891 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; |
| 884 | 892 | ||
| @@ -886,7 +894,11 @@ void rgblight_effect_breathing(animation_status_t *anim) { | |||
| 886 | float val; | 894 | float val; |
| 887 | 895 | ||
| 888 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ | 896 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ |
| 897 | #ifdef RGBLIGHT_EFFECT_BREATHE_TABLE | ||
| 898 | val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]); | ||
| 899 | #else | ||
| 889 | val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); | 900 | val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); |
| 901 | #endif | ||
| 890 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); | 902 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); |
| 891 | anim->pos = (anim->pos + 1); | 903 | anim->pos = (anim->pos + 1); |
| 892 | } | 904 | } |
diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 9ccb3135c..35d7942ca 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h | |||
| @@ -80,9 +80,7 @@ enum RGBLIGHT_EFFECT_MODE { | |||
| 80 | 80 | ||
| 81 | #define RGBLIGHT_MODES (RGBLIGHT_MODE_last-1) | 81 | #define RGBLIGHT_MODES (RGBLIGHT_MODE_last-1) |
| 82 | 82 | ||
| 83 | #ifndef RGBLIGHT_EFFECT_BREATHE_CENTER | 83 | // sample: #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 |
| 84 | #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1-2.7 | ||
| 85 | #endif | ||
| 86 | 84 | ||
| 87 | #ifndef RGBLIGHT_EFFECT_BREATHE_MAX | 85 | #ifndef RGBLIGHT_EFFECT_BREATHE_MAX |
| 88 | #define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0-255 | 86 | #define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0-255 |
diff --git a/quantum/rgblight_breathe_table.h b/quantum/rgblight_breathe_table.h new file mode 100644 index 000000000..7ab8cc947 --- /dev/null +++ b/quantum/rgblight_breathe_table.h | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | #ifndef RGBLIGHT_EFFECT_BREATHE_TABLE | ||
| 2 | #define RGBLIGHT_EFFECT_BREATHE_TABLE | ||
| 3 | |||
| 4 | const uint8_t rgblight_effect_breathe_table[] PROGMEM = { | ||
| 5 | /* #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 */ | ||
| 6 | /* #define RGBLIGHT_EFFECT_BREATHE_MAX 255 */ | ||
| 7 | |||
| 8 | #if RGBLIGHT_BREATHE_TABLE_SIZE == 256 | ||
| 9 | 0x22, 0x23, 0x25, 0x26, 0x28, 0x29, 0x2a, 0x2c, | ||
| 10 | 0x2d, 0x2f, 0x30, 0x32, 0x33, 0x35, 0x36, 0x38, | ||
| 11 | 0x3a, 0x3b, 0x3d, 0x3e, 0x40, 0x42, 0x43, 0x45, | ||
| 12 | 0x47, 0x49, 0x4a, 0x4c, 0x4e, 0x50, 0x51, 0x53, | ||
| 13 | 0x55, 0x57, 0x59, 0x5a, 0x5c, 0x5e, 0x60, 0x62, | ||
| 14 | 0x64, 0x66, 0x68, 0x69, 0x6b, 0x6d, 0x6f, 0x71, | ||
| 15 | 0x73, 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81, | ||
| 16 | 0x83, 0x85, 0x87, 0x89, 0x8a, 0x8c, 0x8e, 0x90, | ||
| 17 | 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0x9f, | ||
| 18 | 0xa1, 0xa3, 0xa5, 0xa7, 0xa8, 0xaa, 0xac, 0xae, | ||
| 19 | 0xaf, 0xb1, 0xb3, 0xb4, 0xb6, 0xb8, 0xb9, 0xbb, | ||
| 20 | 0xbc, 0xbe, 0xbf, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, | ||
| 21 | 0xc7, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xd0, | ||
| 22 | 0xd1, 0xd2, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, | ||
| 23 | 0xd7, 0xd8, 0xd9, 0xd9, 0xda, 0xda, 0xdb, 0xdb, | ||
| 24 | 0xdb, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdd, 0xdd, | ||
| 25 | 0xdd, 0xdd, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdb, | ||
| 26 | 0xdb, 0xdb, 0xda, 0xda, 0xd9, 0xd9, 0xd8, 0xd7, | ||
| 27 | 0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd2, 0xd1, | ||
| 28 | 0xd0, 0xce, 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, | ||
| 29 | 0xc6, 0xc5, 0xc3, 0xc2, 0xc1, 0xbf, 0xbe, 0xbc, | ||
| 30 | 0xbb, 0xb9, 0xb8, 0xb6, 0xb4, 0xb3, 0xb1, 0xaf, | ||
| 31 | 0xae, 0xac, 0xaa, 0xa8, 0xa7, 0xa5, 0xa3, 0xa1, | ||
| 32 | 0x9f, 0x9e, 0x9c, 0x9a, 0x98, 0x96, 0x94, 0x92, | ||
| 33 | 0x90, 0x8e, 0x8c, 0x8a, 0x89, 0x87, 0x85, 0x83, | ||
| 34 | 0x81, 0x7f, 0x7d, 0x7b, 0x79, 0x77, 0x75, 0x73, | ||
| 35 | 0x71, 0x6f, 0x6d, 0x6b, 0x69, 0x68, 0x66, 0x64, | ||
| 36 | 0x62, 0x60, 0x5e, 0x5c, 0x5a, 0x59, 0x57, 0x55, | ||
| 37 | 0x53, 0x51, 0x50, 0x4e, 0x4c, 0x4a, 0x49, 0x47, | ||
| 38 | 0x45, 0x43, 0x42, 0x40, 0x3e, 0x3d, 0x3b, 0x3a, | ||
| 39 | 0x38, 0x36, 0x35, 0x33, 0x32, 0x30, 0x2f, 0x2d, | ||
| 40 | 0x2c, 0x2a, 0x29, 0x28, 0x26, 0x25, 0x23, 0x22 | ||
| 41 | #endif /* 256 bytes table */ | ||
| 42 | |||
| 43 | #if RGBLIGHT_BREATHE_TABLE_SIZE == 128 | ||
| 44 | 0x22, 0x25, 0x28, 0x2a, | ||
| 45 | 0x2d, 0x30, 0x33, 0x36, | ||
| 46 | 0x3a, 0x3d, 0x40, 0x43, | ||
| 47 | 0x47, 0x4a, 0x4e, 0x51, | ||
| 48 | 0x55, 0x59, 0x5c, 0x60, | ||
| 49 | 0x64, 0x68, 0x6b, 0x6f, | ||
| 50 | 0x73, 0x77, 0x7b, 0x7f, | ||
| 51 | 0x83, 0x87, 0x8a, 0x8e, | ||
| 52 | 0x92, 0x96, 0x9a, 0x9e, | ||
| 53 | 0xa1, 0xa5, 0xa8, 0xac, | ||
| 54 | 0xaf, 0xb3, 0xb6, 0xb9, | ||
| 55 | 0xbc, 0xbf, 0xc2, 0xc5, | ||
| 56 | 0xc7, 0xca, 0xcc, 0xce, | ||
| 57 | 0xd1, 0xd2, 0xd4, 0xd6, | ||
| 58 | 0xd7, 0xd9, 0xda, 0xdb, | ||
| 59 | 0xdb, 0xdc, 0xdc, 0xdd, | ||
| 60 | 0xdd, 0xdc, 0xdc, 0xdc, | ||
| 61 | 0xdb, 0xda, 0xd9, 0xd8, | ||
| 62 | 0xd7, 0xd5, 0xd3, 0xd2, | ||
| 63 | 0xd0, 0xcd, 0xcb, 0xc9, | ||
| 64 | 0xc6, 0xc3, 0xc1, 0xbe, | ||
| 65 | 0xbb, 0xb8, 0xb4, 0xb1, | ||
| 66 | 0xae, 0xaa, 0xa7, 0xa3, | ||
| 67 | 0x9f, 0x9c, 0x98, 0x94, | ||
| 68 | 0x90, 0x8c, 0x89, 0x85, | ||
| 69 | 0x81, 0x7d, 0x79, 0x75, | ||
| 70 | 0x71, 0x6d, 0x69, 0x66, | ||
| 71 | 0x62, 0x5e, 0x5a, 0x57, | ||
| 72 | 0x53, 0x50, 0x4c, 0x49, | ||
| 73 | 0x45, 0x42, 0x3e, 0x3b, | ||
| 74 | 0x38, 0x35, 0x32, 0x2f, | ||
| 75 | 0x2c, 0x29, 0x26, 0x23 | ||
| 76 | #endif /* 128 bytes table */ | ||
| 77 | |||
| 78 | #if RGBLIGHT_BREATHE_TABLE_SIZE == 64 | ||
| 79 | 0x22, 0x28, | ||
| 80 | 0x2d, 0x33, | ||
| 81 | 0x3a, 0x40, | ||
| 82 | 0x47, 0x4e, | ||
| 83 | 0x55, 0x5c, | ||
| 84 | 0x64, 0x6b, | ||
| 85 | 0x73, 0x7b, | ||
| 86 | 0x83, 0x8a, | ||
| 87 | 0x92, 0x9a, | ||
| 88 | 0xa1, 0xa8, | ||
| 89 | 0xaf, 0xb6, | ||
| 90 | 0xbc, 0xc2, | ||
| 91 | 0xc7, 0xcc, | ||
| 92 | 0xd1, 0xd4, | ||
| 93 | 0xd7, 0xda, | ||
| 94 | 0xdb, 0xdc, | ||
| 95 | 0xdd, 0xdc, | ||
| 96 | 0xdb, 0xd9, | ||
| 97 | 0xd7, 0xd3, | ||
| 98 | 0xd0, 0xcb, | ||
| 99 | 0xc6, 0xc1, | ||
| 100 | 0xbb, 0xb4, | ||
| 101 | 0xae, 0xa7, | ||
| 102 | 0x9f, 0x98, | ||
| 103 | 0x90, 0x89, | ||
| 104 | 0x81, 0x79, | ||
| 105 | 0x71, 0x69, | ||
| 106 | 0x62, 0x5a, | ||
| 107 | 0x53, 0x4c, | ||
| 108 | 0x45, 0x3e, | ||
| 109 | 0x38, 0x32, | ||
| 110 | 0x2c, 0x26 | ||
| 111 | #endif /* 64 bytes table */ | ||
| 112 | }; | ||
| 113 | |||
| 114 | static const int table_scale = 256/sizeof(rgblight_effect_breathe_table); | ||
| 115 | |||
| 116 | #endif /* RGBLIGHT_EFFECT_BREATHE_TABLE */ | ||
diff --git a/quantum/template/avr/config.h b/quantum/template/avr/config.h index a9bb75482..48d7afb14 100644 --- a/quantum/template/avr/config.h +++ b/quantum/template/avr/config.h | |||
| @@ -77,6 +77,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 77 | // #define RGBLIGHT_EFFECT_STATIC_GRADIENT | 77 | // #define RGBLIGHT_EFFECT_STATIC_GRADIENT |
| 78 | // #define RGBLIGHT_EFFECT_RGB_TEST | 78 | // #define RGBLIGHT_EFFECT_RGB_TEST |
| 79 | // #define RGBLIGHT_EFFECT_ALTERNATING | 79 | // #define RGBLIGHT_EFFECT_ALTERNATING |
| 80 | // /*== customize breathing effect ==*/ | ||
| 81 | // /*==== (DEFAULT) use fixed table instead of exp() and sin() ====*/ | ||
| 82 | // #define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256(default) or 128 or 64 | ||
| 83 | // /*==== use exp() and sin() ====*/ | ||
| 84 | // #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1 to 2.7 | ||
| 85 | // #define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0 to 255 | ||
| 80 | // #endif | 86 | // #endif |
| 81 | 87 | ||
| 82 | /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ | 88 | /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ |
diff --git a/util/rgblight_breathing_table_calc.c b/util/rgblight_breathing_table_calc.c new file mode 100644 index 000000000..fc4d49ea5 --- /dev/null +++ b/util/rgblight_breathing_table_calc.c | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | // | ||
| 2 | // calculate rgblight_effect_breathe_table[] values | ||
| 3 | // | ||
| 4 | // this is host program for quantum/rgblight.c:void rgblight_effect_breathing(); | ||
| 5 | // | ||
| 6 | // example: | ||
| 7 | // $ edit util/rgblight_breathing_table_calc.c | ||
| 8 | // $ cc -o util/rgblight_breathing_table_calc util/rgblight_breathing_table_calc.c | ||
| 9 | // $ ./util/rgblight_breathing_table_calc > keyboards/KEYBOARD_NAME/keymaps/KEYMAP_NAME/rgblight_breathe_table.h | ||
| 10 | // | ||
| 11 | #include <stdio.h> | ||
| 12 | #include <math.h> | ||
| 13 | #include <stdint.h> | ||
| 14 | |||
| 15 | /// customize breeathing effect part /////////////////////////// | ||
| 16 | #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1 to 2.7 | ||
| 17 | #define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0 to 255 | ||
| 18 | //////////////////////////////////////////////////////////////// | ||
| 19 | |||
| 20 | int main(void) { | ||
| 21 | int pos, step; | ||
| 22 | int table[256]; | ||
| 23 | for (pos = 0; pos < 256; pos ++ ) { | ||
| 24 | table[pos] = (uint8_t)( | ||
| 25 | (exp(sin((pos/255.0)*M_PI))- RGBLIGHT_EFFECT_BREATHE_CENTER/M_E) | ||
| 26 | * (RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)) | ||
| 27 | ); | ||
| 28 | } | ||
| 29 | printf("#ifndef RGBLIGHT_EFFECT_BREATHE_TABLE\n"); | ||
| 30 | printf("#define RGBLIGHT_EFFECT_BREATHE_TABLE\n\n"); | ||
| 31 | printf("const uint8_t rgblight_effect_breathe_table[] PROGMEM = {\n"); | ||
| 32 | printf(" /* #define RGBLIGHT_EFFECT_BREATHE_CENTER %.2f */\n", RGBLIGHT_EFFECT_BREATHE_CENTER); | ||
| 33 | printf(" /* #define RGBLIGHT_EFFECT_BREATHE_MAX %d */\n", RGBLIGHT_EFFECT_BREATHE_MAX); | ||
| 34 | |||
| 35 | for (int s = 0, step = (1<<s); s < 3 ; s += 1, step = (1<<s) ) { | ||
| 36 | printf("\n #if RGBLIGHT_BREATHE_TABLE_SIZE == %d\n", | ||
| 37 | s == 0 ? 256:(s== 1 ? 128: 64)); | ||
| 38 | for (pos = 0; pos < 256; pos += step ) { | ||
| 39 | printf(" 0x%x%s", table[pos], (pos+step)>=256?"":"," ); | ||
| 40 | if ((pos+step) % 8 == 0) | ||
| 41 | printf("\n"); | ||
| 42 | } | ||
| 43 | printf(" #endif /* %d bytes table */\n", s == 0 ? 256:(s== 1 ? 128: 64)); | ||
| 44 | } | ||
| 45 | printf("};\n"); | ||
| 46 | printf("\nstatic const int table_scale = 256/sizeof(rgblight_effect_breathe_table);\n"); | ||
| 47 | printf("\n#endif /* RGBLIGHT_EFFECT_BREATHE_TABLE */\n"); | ||
| 48 | return 0; | ||
| 49 | } | ||
