1 /* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
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.
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.
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/>.
18 #include "action_layer.h"
22 #ifdef QWIIC_MICRO_OLED_ENABLE
24 /* screen off after this many milliseconds */
26 #define ScreenOffInterval 60000 /* milliseconds */
27 static uint16_t last_flush;
29 volatile uint8_t led_numlock = false;
30 volatile uint8_t led_capslock = false;
31 volatile uint8_t led_scrolllock = false;
34 static bool queue_for_send = false;
35 static uint8_t encoder_value = 32;
37 __attribute__ ((weak))
40 last_flush = timer_read();
41 send_command(DISPLAYON);
43 /* Layer indicator is 41 x 10 pixels */
44 #define LAYER_INDICATOR_X 0
45 #define LAYER_INDICATOR_Y 0
47 draw_string(LAYER_INDICATOR_X + 1, LAYER_INDICATOR_Y + 2, "LAYER", PIXEL_ON, NORM, 0);
48 draw_rect_filled_soft(LAYER_INDICATOR_X + 32, LAYER_INDICATOR_Y + 1, 9, 9, PIXEL_ON, NORM);
49 draw_char(LAYER_INDICATOR_X + 34, LAYER_INDICATOR_Y + 2, layer + 0x30, PIXEL_ON, XOR, 0);
51 /* Matrix display is 19 x 9 pixels */
52 #define MATRIX_DISPLAY_X 0
53 #define MATRIX_DISPLAY_Y 18
55 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
56 for (uint8_t y = 0; y < MATRIX_COLS; y++) {
57 draw_pixel(MATRIX_DISPLAY_X + y + 2, MATRIX_DISPLAY_Y + x + 2,(matrix_get_row(x) & (1 << y)) > 0, NORM);
60 draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 19, 9, PIXEL_ON, NORM);
61 /* hadron oled location on thumbnail */
62 draw_rect_filled_soft(MATRIX_DISPLAY_X + 14, MATRIX_DISPLAY_Y + 2, 3, 1, PIXEL_ON, NORM);
64 draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
65 draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
69 /* Mod display is 41 x 16 pixels */
70 #define MOD_DISPLAY_X 30
71 #define MOD_DISPLAY_Y 18
73 uint8_t mods = get_mods();
74 if (mods & MOD_LSFT) {
75 draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
76 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
78 draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
80 if (mods & MOD_LCTL) {
81 draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
82 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
84 draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
86 if (mods & MOD_LALT) {
87 draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
88 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
90 draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
92 if (mods & MOD_LGUI) {
93 draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
94 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
96 draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
99 /* Lock display is 23 x 32 */
100 #define LOCK_DISPLAY_X 100
101 #define LOCK_DISPLAY_Y 0
103 if (led_numlock == true) {
104 draw_rect_filled_soft(LOCK_DISPLAY_X, LOCK_DISPLAY_Y, 5 + (3 * 6), 9, PIXEL_ON, NORM);
105 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_OFF, NORM, 0);
106 } else if (led_numlock == false) {
107 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 1, "NUM", PIXEL_ON, NORM, 0);
109 if (led_capslock == true) {
110 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 11, 5 + (3 * 6), 9, PIXEL_ON, NORM);
111 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_OFF, NORM, 0);
112 } else if (led_capslock == false) {
113 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 11 +1, "CAP", PIXEL_ON, NORM, 0);
116 if (led_scrolllock == true) {
117 draw_rect_filled_soft(LOCK_DISPLAY_X + 0, LOCK_DISPLAY_Y + 22, 5 + (3 * 6), 9, PIXEL_ON, NORM);
118 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_OFF, NORM, 0);
119 } else if (led_scrolllock == false) {
120 draw_string(LOCK_DISPLAY_X + 3, LOCK_DISPLAY_Y + 22 +1, "SCR", PIXEL_ON, NORM, 0);
125 void read_host_led_state(void) {
126 uint8_t leds = host_keyboard_leds();
127 if (leds & (1 << USB_LED_NUM_LOCK)) {
128 if (led_numlock == false){
131 if (led_numlock == true){
132 led_numlock = false;}
134 if (leds & (1 << USB_LED_CAPS_LOCK)) {
135 if (led_capslock == false){
136 led_capslock = true;}
138 if (led_capslock == true){
139 led_capslock = false;}
141 if (leds & (1 << USB_LED_SCROLL_LOCK)) {
142 if (led_scrolllock == false){
143 led_scrolllock = true;}
145 if (led_scrolllock == true){
146 led_scrolllock = false;}
150 uint32_t layer_state_set_kb(uint32_t state) {
151 state = layer_state_set_user(state);
152 layer = biton32(state);
153 queue_for_send = true;
157 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
158 queue_for_send = true;
159 return process_record_user(keycode, record);
162 void encoder_update_kb(uint8_t index, bool clockwise) {
163 encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
164 queue_for_send = true;
169 void matrix_init_kb(void) {
173 queue_for_send = true;
177 void matrix_scan_kb(void) {
179 if (queue_for_send) {
181 DRV_EFFECT play_eff = strong_click;
184 #ifdef QWIIC_MICRO_OLED_ENABLE
185 read_host_led_state();
188 queue_for_send = false;
190 #ifdef QWIIC_MICRO_OLED_ENABLE
191 if (timer_elapsed(last_flush) > ScreenOffInterval) {
192 send_command(DISPLAYOFF); /* 0xAE */