|
| 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 "2021.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 matrix_scan_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 | + |
| 95 | +__attribute__ ((weak)) |
| 96 | +bool encoder_update_keymap(int8_t index, bool clockwise) { |
| 97 | + return false; |
| 98 | +} |
| 99 | + |
| 100 | +#define NUM_COLUMNS 8*MAX7219_CONTROLLERS |
| 101 | +uint8_t led_position[2] = {0,0}; // The location of the cursor in the matrix |
| 102 | + |
| 103 | +bool encoder_update_kb(uint8_t index, bool clockwise) { |
| 104 | + if (!encoder_update_keymap(index, clockwise)) { |
| 105 | +#if defined(DRAWING_TOY_MODE) |
| 106 | + // Encoder 1, left |
| 107 | + if (index == 0 && clockwise) { |
| 108 | + if (led_position[0] < NUM_COLUMNS-1) { // turned right |
| 109 | + led_position[0]++; |
| 110 | + } else { |
| 111 | + led_position[0]=0; |
| 112 | + } |
| 113 | + } else if (index == 0) { |
| 114 | + if (led_position[0] > 0) { // turned left |
| 115 | + led_position[0]--; |
| 116 | + } else { |
| 117 | + led_position[0]=NUM_COLUMNS-1; |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + // Encoder 2, right |
| 122 | + else if (index == 1 && clockwise) { |
| 123 | + if (led_position[1] < 7) { // turned right |
| 124 | + led_position[1]++; |
| 125 | + } else { |
| 126 | + led_position[1]=0; |
| 127 | + } |
| 128 | + } else if (index == 1) { |
| 129 | + if (led_position[1] > 0) { // turned left |
| 130 | + led_position[1]--; |
| 131 | + } else { |
| 132 | + led_position[1]=7; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + max7219_set_led(led_position[1], led_position[0], true); |
| 137 | +#else |
| 138 | + // Encoder 1, left |
| 139 | + if (index == 0 && clockwise) { |
| 140 | + tap_code(KC_MS_R); // turned right |
| 141 | + } else if (index == 0) { |
| 142 | + tap_code(KC_MS_L); // turned left |
| 143 | + } |
| 144 | + |
| 145 | + // Encoder 2, right |
| 146 | + else if (index == 1 && clockwise) { |
| 147 | + tap_code(KC_MS_U); // turned right |
| 148 | + } else if (index == 1) { |
| 149 | + tap_code(KC_MS_D); // turned left |
| 150 | + } |
| 151 | +#endif |
| 152 | + } |
| 153 | + return true; |
| 154 | +} |
0 commit comments