]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/hadron/ver3/ver3.c
rgb_led struct conversion (aka: Per led (key) type rgb matrix effects - part 2) ...
[qmk_firmware.git] / keyboards / hadron / ver3 / ver3.c
1 /* Copyright 2018 Jack Humbert <jack.humb@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 "ver3.h"
17 #include "qwiic.h"
18 #include "action_layer.h"
19 #include "haptic.h"
20
21 #ifdef RGB_MATRIX_ENABLE
22 #include "rgb_matrix.h"
23
24 led_config_t g_led_config = { {
25     { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
26     { NO_LED,   6, NO_LED, NO_LED,   7, NO_LED, NO_LED,   8, NO_LED, NO_LED,   9, NO_LED, NO_LED,   0, NO_LED },
27     { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
28     { NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED, NO_LED },
29     { NO_LED,   5, NO_LED, NO_LED,   4, NO_LED, NO_LED,   3, NO_LED, NO_LED,   2, NO_LED, NO_LED,   1, NO_LED }
30 }, {
31     { 195,   3 }, { 195,  16 }, { 150,  16 }, { 105,  16 }, {  60,  16 }, {  15,  16 }, {  15,   3 }, {  60,   3 }, { 105,   3 }, { 150,   3 }
32 }, {
33     4, 4, 4, 4, 4, 4, 4, 4, 4, 4
34 } };
35
36 #endif
37
38 uint8_t *o_fb;
39
40 uint16_t counterst = 0;
41
42
43
44 #ifdef QWIIC_MICRO_OLED_ENABLE
45
46 /* screen off after this many milliseconds */
47 #include "timer.h"
48 #define ScreenOffInterval 60000 /* milliseconds */
49 static uint16_t last_flush;
50
51 volatile uint8_t led_numlock = false;
52 volatile uint8_t  led_capslock = false;
53 volatile uint8_t  led_scrolllock = false;
54
55 static uint8_t layer;
56 static bool queue_for_send = false;
57 static uint8_t encoder_value = 32;
58
59 __attribute__ ((weak))
60 void draw_ui(void) {
61   clear_buffer();
62   last_flush = timer_read();
63   send_command(DISPLAYON);
64
65 /* Layer indicator is 41 x 10 pixels */
66 #define LAYER_INDICATOR_X 5
67 #define LAYER_INDICATOR_Y 0
68
69   draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
70   draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
71   draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
72
73 /* Matrix display is 19 x 9 pixels */
74 #define MATRIX_DISPLAY_X 5
75 #define MATRIX_DISPLAY_Y 18
76
77   for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
78     for (uint8_t y = 0; y < MATRIX_COLS; y++) {
79       draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
80     }
81   }
82   draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM);
83   /* hadron oled location on thumbnail */
84   draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM);
85 /*
86   draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
87   draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
88
89 */
90
91 /* Mod display is 41 x 16 pixels */
92 #define MOD_DISPLAY_X 30
93 #define MOD_DISPLAY_Y 18
94
95   uint8_t mods = get_mods();
96   if (mods & MOD_LSFT) {
97     draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
98     draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
99   } else {
100     draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
101   }
102   if (mods & MOD_LCTL) {
103     draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
104     draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
105   } else {
106     draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
107   }
108   if (mods & MOD_LALT) {
109     draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
110     draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
111   } else {
112     draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
113   }
114   if (mods & MOD_LGUI) {
115     draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
116     draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
117   } else {
118     draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
119   }
120
121 /* Lock display is 23 x 32 */
122 #define LOCK_DISPLAY_X 100
123 #define LOCK_DISPLAY_Y 0
124
125   if (led_numlock == true) {
126     draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
127     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
128   } else if (led_numlock == false) {
129     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
130   }
131   if (led_capslock == true) {
132     draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
133     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
134   } else if (led_capslock == false) {
135     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
136   }
137
138   if (led_scrolllock == true) {
139     draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
140     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
141   } else if (led_scrolllock == false) {
142     draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
143   }
144   send_buffer();
145 }
146
147 void read_host_led_state(void) {
148   uint8_t leds = host_keyboard_leds();
149   if (leds & (1 << USB_LED_NUM_LOCK))    {
150     if (led_numlock == false){
151     led_numlock = true;}
152     } else {
153     if (led_numlock == true){
154     led_numlock = false;}
155     }
156   if (leds & (1 << USB_LED_CAPS_LOCK))   {
157     if (led_capslock == false){
158     led_capslock = true;}
159     } else {
160     if (led_capslock == true){
161     led_capslock = false;}
162     }
163   if (leds & (1 << USB_LED_SCROLL_LOCK)) {
164     if (led_scrolllock == false){
165     led_scrolllock = true;}
166     } else {
167     if (led_scrolllock == true){
168     led_scrolllock = false;}
169     }
170 }
171
172 uint32_t layer_state_set_kb(uint32_t state) {
173   state = layer_state_set_user(state);
174   layer = biton32(state);
175   queue_for_send = true;
176   return state;
177 }
178
179 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
180   queue_for_send = true;
181   return process_record_user(keycode, record);
182 }
183
184 void encoder_update_kb(uint8_t index, bool clockwise) {
185   encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
186   queue_for_send = true;
187 }
188
189 #endif
190
191 void matrix_init_kb(void) {
192   queue_for_send = true;
193         matrix_init_user();
194 }
195
196 void matrix_scan_kb(void) {
197 if (queue_for_send) {
198 #ifdef QWIIC_MICRO_OLED_ENABLE
199    read_host_led_state();
200    draw_ui();
201 #endif
202    queue_for_send = false;
203   }
204 #ifdef QWIIC_MICRO_OLED_ENABLE
205   if (timer_elapsed(last_flush) > ScreenOffInterval) {
206   send_command(DISPLAYOFF);      /* 0xAE */
207   }
208 #endif
209   if (counterst == 0) {
210     //testPatternFB(o_fb);
211   }
212   counterst = (counterst + 1) % 1024;
213   //rgblight_task();
214         matrix_scan_user();
215 }