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.

154 lines
4.8 KiB

  1. /* Copyright 2017 Zach White <skullydazed@gmail.com>
  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 "2021.h"
  17. #include "max7219.h"
  18. #include "font.h"
  19. #ifndef DRAWING_TOY_MODE
  20. static uint16_t led_frame_timer = 0;
  21. void matrix_scan_kb(void) {
  22. if (timer_elapsed(led_frame_timer) > 100) {
  23. max7219_message_sign_task(true);
  24. led_frame_timer = timer_read();
  25. }
  26. }
  27. #endif
  28. void matrix_init_kb(void) {
  29. max7219_init();
  30. #if defined(MAX7219_LED_TEST)
  31. while(1) {
  32. for (int i=0; i<MAX7219_CONTROLLERS; i++) {
  33. max7219_display_test(i, true);
  34. wait_ms(500);
  35. max7219_display_test(i, false);
  36. }
  37. }
  38. #elif defined(MAX7219_LED_ITERATE)
  39. while (1) {
  40. for (int row=0; row<8; row++) {
  41. for(int col=0;col<8*MAX7219_CONTROLLERS;col++) {
  42. max7219_set_led(row, col, true);
  43. wait_ms(500);
  44. max7219_set_led(row, col, false);
  45. }
  46. }
  47. }
  48. #elif defined(MAX7219_LED_DANCE)
  49. while (1) {
  50. for (int col=0; col<8; col++) {
  51. for (int device_num=0; device_num<MAX7219_CONTROLLERS; device_num++) {
  52. if (col % 2 == 0) {
  53. max7219_led_a[col][device_num] = 0b01010101;
  54. } else {
  55. max7219_led_a[col][device_num] = 0b10101010;
  56. }
  57. }
  58. }
  59. max7219_write_frame();
  60. wait_ms(500);
  61. for (int col=0; col<8; col++) {
  62. for (int device_num=0; device_num<MAX7219_CONTROLLERS; device_num++) {
  63. if (col % 2 == 0) {
  64. max7219_led_a[col][device_num] = 0b10101010;
  65. } else {
  66. max7219_led_a[col][device_num] = 0b01010101;
  67. }
  68. }
  69. }
  70. max7219_write_frame();
  71. wait_ms(500);
  72. }
  73. #elif defined(MAX7219_LED_FONTTEST)
  74. uint8_t message[MSG_FONTTEST_LEN][6] = MSG_FONTTEST;
  75. max7219_message_sign(message, MSG_FONTTEST_LEN);
  76. #elif defined(MAX7219_LED_CLUEBOARD)
  77. uint8_t message[MSG_CLUEBOARD_LEN][6] = MSG_CLUEBOARD;
  78. max7219_message_sign(message, MSG_CLUEBOARD_LEN);
  79. #elif defined(MAX7219_LED_KONAMI)
  80. uint8_t message[MSG_KONAMI_LEN][6] = MSG_KONAMI;
  81. max7219_message_sign(message, MSG_KONAMI_LEN);
  82. #elif defined(MAX7219_LED_QMK_POWERED)
  83. uint8_t message[MSG_QMK_POWERED_LEN][6] = MSG_QMK_POWERED;
  84. max7219_message_sign(message, MSG_QMK_POWERED_LEN);
  85. #elif defined(DRAWING_TOY_MODE)
  86. max7219_set_led(0, 0, true);
  87. #endif
  88. }
  89. __attribute__ ((weak))
  90. bool encoder_update_keymap(int8_t index, bool clockwise) {
  91. return false;
  92. }
  93. #define NUM_COLUMNS 8*MAX7219_CONTROLLERS
  94. uint8_t led_position[2] = {0,0}; // The location of the cursor in the matrix
  95. bool encoder_update_kb(uint8_t index, bool clockwise) {
  96. if (!encoder_update_keymap(index, clockwise)) {
  97. #if defined(DRAWING_TOY_MODE)
  98. // Encoder 1, left
  99. if (index == 0 && clockwise) {
  100. if (led_position[0] < NUM_COLUMNS-1) { // turned right
  101. led_position[0]++;
  102. } else {
  103. led_position[0]=0;
  104. }
  105. } else if (index == 0) {
  106. if (led_position[0] > 0) { // turned left
  107. led_position[0]--;
  108. } else {
  109. led_position[0]=NUM_COLUMNS-1;
  110. }
  111. }
  112. // Encoder 2, right
  113. else if (index == 1 && clockwise) {
  114. if (led_position[1] < 7) { // turned right
  115. led_position[1]++;
  116. } else {
  117. led_position[1]=0;
  118. }
  119. } else if (index == 1) {
  120. if (led_position[1] > 0) { // turned left
  121. led_position[1]--;
  122. } else {
  123. led_position[1]=7;
  124. }
  125. }
  126. max7219_set_led(led_position[1], led_position[0], true);
  127. #else
  128. // Encoder 1, left
  129. if (index == 0 && clockwise) {
  130. tap_code(KC_MS_R); // turned right
  131. } else if (index == 0) {
  132. tap_code(KC_MS_L); // turned left
  133. }
  134. // Encoder 2, right
  135. else if (index == 1 && clockwise) {
  136. tap_code(KC_MS_U); // turned right
  137. } else if (index == 1) {
  138. tap_code(KC_MS_D); // turned left
  139. }
  140. #endif
  141. }
  142. return true;
  143. }