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