Reduce the firmware size by 1500 bytes when rgblight_effect_breathing() is enabled.

pull/5020/head
mtei 6 years ago
parent e44546fec2
commit b61004e63e

@ -908,11 +908,54 @@ void rgblight_task(void) {
__attribute__ ((weak))
const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
#ifdef RGBLIGHT_EFFECT_BREATHE_USE_TABLE
__attribute__ ((weak))
const uint8_t rgblight_effect_breathe_table[] PROGMEM = {
0x22, 0x23, 0x25, 0x26, 0x28, 0x29, 0x2a, 0x2c,
0x2d, 0x2f, 0x30, 0x32, 0x33, 0x35, 0x36, 0x38,
0x3a, 0x3b, 0x3d, 0x3e, 0x40, 0x42, 0x43, 0x45,
0x47, 0x49, 0x4a, 0x4c, 0x4e, 0x50, 0x51, 0x53,
0x55, 0x57, 0x59, 0x5a, 0x5c, 0x5e, 0x60, 0x62,
0x64, 0x66, 0x68, 0x69, 0x6b, 0x6d, 0x6f, 0x71,
0x73, 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81,
0x83, 0x85, 0x87, 0x89, 0x8a, 0x8c, 0x8e, 0x90,
0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e, 0x9f,
0xa1, 0xa3, 0xa5, 0xa7, 0xa8, 0xaa, 0xac, 0xae,
0xaf, 0xb1, 0xb3, 0xb4, 0xb6, 0xb8, 0xb9, 0xbb,
0xbc, 0xbe, 0xbf, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6,
0xc7, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xd0,
0xd1, 0xd2, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd7, 0xd8, 0xd9, 0xd9, 0xda, 0xda, 0xdb, 0xdb,
0xdb, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdd, 0xdd,
0xdd, 0xdd, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdb,
0xdb, 0xdb, 0xda, 0xda, 0xd9, 0xd9, 0xd8, 0xd7,
0xd7, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd2, 0xd1,
0xd0, 0xce, 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7,
0xc6, 0xc5, 0xc3, 0xc2, 0xc1, 0xbf, 0xbe, 0xbc,
0xbb, 0xb9, 0xb8, 0xb6, 0xb4, 0xb3, 0xb1, 0xaf,
0xae, 0xac, 0xaa, 0xa8, 0xa7, 0xa5, 0xa3, 0xa1,
0x9f, 0x9e, 0x9c, 0x9a, 0x98, 0x96, 0x94, 0x92,
0x90, 0x8e, 0x8c, 0x8a, 0x89, 0x87, 0x85, 0x83,
0x81, 0x7f, 0x7d, 0x7b, 0x79, 0x77, 0x75, 0x73,
0x71, 0x6f, 0x6d, 0x6b, 0x69, 0x68, 0x66, 0x64,
0x62, 0x60, 0x5e, 0x5c, 0x5a, 0x59, 0x57, 0x55,
0x53, 0x51, 0x50, 0x4e, 0x4c, 0x4a, 0x49, 0x47,
0x45, 0x43, 0x42, 0x40, 0x3e, 0x3d, 0x3b, 0x3a,
0x38, 0x36, 0x35, 0x33, 0x32, 0x30, 0x2f, 0x2d,
0x2c, 0x2a, 0x29, 0x28, 0x26, 0x25, 0x23, 0x22
};
#endif
void rgblight_effect_breathing(animation_status_t *anim) {
float val;
// http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
#ifndef RGBLIGHT_EFFECT_BREATHE_USE_TABLE
val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E));
#else
val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos]);
#endif
rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
anim->pos = (anim->pos + 1) % 256;
}

@ -86,8 +86,12 @@ enum RGBLIGHT_EFFECT_MODE {
#define RGBLIGHT_MODES (RGBLIGHT_MODE_last-1)
// #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1-2.7
#ifndef RGBLIGHT_EFFECT_BREATHE_CENTER
#define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1-2.7
#define RGBLIGHT_EFFECT_BREATHE_USE_TABLE
// this is same effect #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85
// see TOP/util/breathing_table_calc.c
#endif
#ifndef RGBLIGHT_EFFECT_BREATHE_MAX

@ -0,0 +1,25 @@
//
// this is host program for quantum/rgblight.c:void rgblight_effect_breathing();
//
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85
#define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0-255
int main(void) {
int pos;
printf("#ifdef RGBLIGHT_EFFECT_BREATHE_USE_TABLE\n");
printf("__attribute__ ((weak))\n");
printf("const uint8_t rgblight_effect_breathe_table[] PROGMEM = {\n");
for (pos = 0; pos < 256; pos ++ ) {
printf(" 0x%x%s",(uint8_t)( (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E))),pos==255?"":"," );
if ((pos+1) % 8 == 0)
printf("\n");
}
printf("};\n");
printf("#endif\n");
return 0;
}
Loading…
Cancel
Save