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