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