logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

terrazzo.c (5398B)


  1. /* Copyright 2020 ademey "MsMustard"
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <math.h>
  17. #include "terrazzo.h"
  18. #ifdef LED_MATRIX_ENABLE
  19. const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
  20. /* Refer to IS31 manual for these locations
  21. * https://cdn-learn.adafruit.com/downloads/pdf/adafruit-15x7-7x15-charlieplex-led-matrix-charliewing-featherwing.pdf
  22. */
  23. {0, C1_2}, {0, C1_3}, {0, C1_4}, {0, C1_5}, {0, C1_6}, {0, C1_7}, {0, C1_8},
  24. {0, C2_2}, {0, C2_3}, {0, C2_4}, {0, C2_5}, {0, C2_6}, {0, C2_7}, {0, C2_8},
  25. {0, C3_2}, {0, C3_3}, {0, C3_4}, {0, C3_5}, {0, C3_6}, {0, C3_7}, {0, C3_8},
  26. {0, C4_2}, {0, C4_3}, {0, C4_4}, {0, C4_5}, {0, C4_6}, {0, C4_7}, {0, C4_8},
  27. {0, C5_2}, {0, C5_3}, {0, C5_4}, {0, C5_5}, {0, C5_6}, {0, C5_7}, {0, C5_8},
  28. {0, C6_2}, {0, C6_3}, {0, C6_4}, {0, C6_5}, {0, C6_6}, {0, C6_7}, {0, C6_8},
  29. {0, C7_2}, {0, C7_3}, {0, C7_4}, {0, C7_5}, {0, C7_6}, {0, C7_7}, {0, C7_8},
  30. {0, C8_2}, {0, C8_3}, {0, C8_4}, {0, C8_5}, {0, C8_6}, {0, C8_7}, {0, C8_8},
  31. //
  32. {0, C8_15},{0, C8_14},{0, C8_13},{0, C8_12},{0, C8_11},{0, C8_10},{0, C8_9},
  33. {0, C7_15},{0, C7_14},{0, C7_13},{0, C7_12},{0, C7_11},{0, C7_10},{0, C7_9},
  34. {0, C6_15},{0, C6_14},{0, C6_13},{0, C6_12},{0, C6_11},{0, C6_10},{0, C6_9},
  35. {0, C5_15},{0, C5_14},{0, C5_13},{0, C5_12},{0, C5_11},{0, C5_10},{0, C5_9},
  36. {0, C4_15},{0, C4_14},{0, C4_13},{0, C4_12},{0, C4_11},{0, C4_10},{0, C4_9},
  37. {0, C3_15},{0, C3_14},{0, C3_13},{0, C3_12},{0, C3_11},{0, C3_10},{0, C3_9},
  38. {0, C2_15},{0, C2_14},{0, C2_13},{0, C2_12},{0, C2_11},{0, C2_10},{0, C2_9}
  39. };
  40. #define TERRAZZO_EFFECT(name)
  41. #define TERRAZZO_EFFECT_IMPLS
  42. #include "terrazzo_effects/terrazzo_effects.inc"
  43. #undef TERRAZZO_EFFECT_IMPLS
  44. #undef TERRAZZO_EFFECT
  45. uint8_t terrazzo_led_index = 0;
  46. uint8_t terrazzo_dir = 1;
  47. uint8_t terrazzo_effect = 1;
  48. void terrazzo_set_pixel(uint8_t x, uint8_t y, uint8_t value) {
  49. uint8_t target = y * LED_MATRIX_COLS + x;
  50. if (target < LED_MATRIX_LED_COUNT && target >= 0) {
  51. led_matrix_set_value(y * LED_MATRIX_COLS + x, value);
  52. }
  53. }
  54. void terrazzo_draw_at(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t image[]) {
  55. uint8_t index = 0;
  56. for (int v = 0; v < height; v++) {
  57. for (int h = 0; h < width; h++) {
  58. uint8_t pixel_value = image[index];
  59. if (pixel_value != 0) {
  60. terrazzo_set_pixel(x + h, y + v, image[index]);
  61. }
  62. index++;
  63. }
  64. }
  65. }
  66. void terrazzo_scroll_pixel(bool clockwise) {
  67. terrazzo_dir = clockwise;
  68. if (clockwise) {
  69. terrazzo_led_index = terrazzo_led_index + 1;
  70. } else {
  71. terrazzo_led_index = terrazzo_led_index - 1;
  72. }
  73. if (terrazzo_led_index >= LED_MATRIX_LED_COUNT) {
  74. terrazzo_led_index = 0;
  75. } else if (terrazzo_led_index <= 0 ) {
  76. terrazzo_led_index = LED_MATRIX_LED_COUNT - 1;
  77. }
  78. }
  79. void terrazzo_step_mode(void) {
  80. terrazzo_effect++;
  81. if (terrazzo_effect >= TERRAZZO_EFFECT_MAX) {
  82. terrazzo_effect = 1;
  83. }
  84. }
  85. void terrazzo_step_mode_reverse(void) {
  86. terrazzo_effect--;
  87. if (terrazzo_effect < 1) {
  88. terrazzo_effect = TERRAZZO_EFFECT_MAX - 1;
  89. }
  90. }
  91. void terrazzo_mode_off(void) {
  92. terrazzo_effect = TERRAZZO_NONE;
  93. }
  94. void terrazzo_render(void) {
  95. switch(terrazzo_effect) {
  96. case TERRAZZO_NONE:
  97. led_matrix_set_value_all(0);
  98. break;
  99. #define TERRAZZO_EFFECT(name, ...) \
  100. case TERRAZZO_EFFECT_##name: \
  101. name(terrazzo_led_index, terrazzo_dir); \
  102. break;
  103. #include "terrazzo_effects/terrazzo_effects.inc"
  104. #undef TERRAZZO_EFFECT
  105. }
  106. }
  107. bool led_matrix_indicators_kb(void) {
  108. if (!led_matrix_indicators_user()) {
  109. return false;
  110. }
  111. terrazzo_render();
  112. return true;
  113. }
  114. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  115. if (record->event.pressed) {
  116. switch(keycode) {
  117. case TZ_NXT:
  118. terrazzo_step_mode();
  119. return true;
  120. case TZ_PRV:
  121. terrazzo_step_mode_reverse();
  122. return true;
  123. case TZ_OFF:
  124. terrazzo_mode_off();
  125. return true;
  126. // Reverse animation on backspace
  127. case KC_BSPC:
  128. terrazzo_scroll_pixel(0);
  129. return true;
  130. // Any keycode increments counter
  131. default:
  132. terrazzo_scroll_pixel(1);
  133. break;
  134. }
  135. }
  136. return process_record_user(keycode, record);
  137. }
  138. void suspend_power_down_kb(void) {
  139. led_matrix_set_suspend_state(true);
  140. }
  141. void suspend_wakeup_init_kb(void) {
  142. led_matrix_set_suspend_state(false);
  143. }
  144. #endif