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