You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.0 KiB

  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. /// customize breeathing effect part ///////////////////////////
  15. #define RGBLIGHT_EFFECT_BREATHE_CENTER 1.85 // 1 to 2.7
  16. #define RGBLIGHT_EFFECT_BREATHE_MAX 255 // 0 to 255
  17. ////////////////////////////////////////////////////////////////
  18. int main(void) {
  19. int pos, step;
  20. int table[256];
  21. for (pos = 0; pos < 256; pos ++ ) {
  22. table[pos] = (uint8_t)(
  23. (exp(sin((pos/255.0)*M_PI))- RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)
  24. * (RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E))
  25. );
  26. }
  27. printf("#ifndef RGBLIGHT_EFFECT_BREATHE_TABLE\n");
  28. printf("#define RGBLIGHT_EFFECT_BREATHE_TABLE\n\n");
  29. printf("const uint8_t rgblight_effect_breathe_table[] PROGMEM = {\n");
  30. printf(" /* #define RGBLIGHT_EFFECT_BREATHE_CENTER %.2f */\n", RGBLIGHT_EFFECT_BREATHE_CENTER);
  31. printf(" /* #define RGBLIGHT_EFFECT_BREATHE_MAX %d */\n", RGBLIGHT_EFFECT_BREATHE_MAX);
  32. for (int s = 0, step = (1<<s); s < 3 ; s += 1, step = (1<<s) ) {
  33. printf("\n #if RGBLIGHT_BREATHE_TABLE_SIZE == %d\n",
  34. s == 0 ? 256:(s== 1 ? 128: 64));
  35. for (pos = 0; pos < 256; pos += step ) {
  36. printf(" 0x%x%s", table[pos], (pos+step)>=256?"":"," );
  37. if ((pos+step) % 8 == 0)
  38. printf("\n");
  39. }
  40. printf(" #endif /* %d bytes table */\n", s == 0 ? 256:(s== 1 ? 128: 64));
  41. }
  42. printf("};\n");
  43. printf("\nstatic const int table_scale = 256/sizeof(rgblight_effect_breathe_table);\n");
  44. printf("\n#endif /* RGBLIGHT_EFFECT_BREATHE_TABLE */\n");
  45. return 0;
  46. }