logo

qmk_firmware

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

kitt.c (2010B)


  1. /* Copyright 2022 HorrorTroll <https://github.com/HorrorTroll>
  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. // variable for startup animation
  17. bool BASE_EFFECT_NOT_STARTED_YET = true;
  18. uint8_t base_effect_startup_counter = 255;
  19. uint8_t led_count = 10;
  20. uint8_t led_first = 7;
  21. static uint8_t time_to_led(uint8_t time, uint8_t led_behind) {
  22. uint16_t led_time = led_count * time;
  23. uint16_t step = ((2 * led_count + (led_time / 128)) - led_behind) % (2 * led_count);
  24. uint8_t led;
  25. if (step < led_count) {
  26. led = step;
  27. } else {
  28. led = led_count - 1 - (step - led_count);
  29. }
  30. return led;
  31. }
  32. static hsv_t KITT_math(hsv_t hsv, uint8_t i, uint8_t time) {
  33. // reset base effect startup
  34. if (i == 0) {
  35. BASE_EFFECT_NOT_STARTED_YET = true;
  36. }
  37. hsv.h = 0;
  38. hsv.s = 255;
  39. if (i >= led_first && i < led_first + led_count) {
  40. uint8_t j = i - led_first;
  41. if (j == time_to_led(time, 0)) {
  42. hsv.v = hsv.v;
  43. } else if (j == time_to_led(time, 1)) {
  44. hsv.v = hsv.v/2;
  45. } else if (j == time_to_led(time, 2)) {
  46. hsv.v = hsv.v/4;
  47. } else if (j == time_to_led(time, 3)) {
  48. hsv.v = hsv.v/8;
  49. } else {
  50. hsv.v = 0;
  51. }
  52. } else {
  53. hsv.v = 0;
  54. }
  55. return hsv;
  56. }
  57. bool KITT(effect_params_t* params) { return effect_runner_i(params, &KITT_math); }