aboutsummaryrefslogtreecommitdiff
path: root/users/ericgebhart/oled_stuff.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/ericgebhart/oled_stuff.c')
-rwxr-xr-xusers/ericgebhart/oled_stuff.c303
1 files changed, 303 insertions, 0 deletions
diff --git a/users/ericgebhart/oled_stuff.c b/users/ericgebhart/oled_stuff.c
new file mode 100755
index 000000000..99a752ec2
--- /dev/null
+++ b/users/ericgebhart/oled_stuff.c
@@ -0,0 +1,303 @@
1/*
2 Copyright 2018 Eric Gebhart <e.a.gebhart@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "ericgebhart.h"
18#include <string.h>
19#include <stdio.h>
20
21void oled_render_default_layer_state(void) {
22 oled_write_P(PSTR("Layout: "), false);
23 switch (get_highest_layer(default_layer_state)) {
24 case _QWERTY:
25 oled_write_ln_P(PSTR("Qwerty"), false);
26 break;
27 case _COLEMAK:
28 oled_write_ln_P(PSTR("Colemak"), false);
29 break;
30 case _DVORAK_BP:
31 case _DVORAK:
32 oled_write_ln_P(PSTR("Dvorak"), false);
33 break;
34
35
36 /* case _WORKMAN: */
37 // oled_write_ln_P(PSTR("Workman\n"), false);
38 /* break; */
39 /* case _NORMAN: */
40 // oled_write_ln_P(PSTR("Norman\n"), false);
41 /* break; */
42 /* case _MALTRON: */
43 // oled_write_ln_P(PSTR("Maltron\n"), false);
44 /* break; */
45
46 /* case _EUCALYN: */
47 // oled_write_ln_P(PSTR("Eucalyn\n"), false);
48 /* break; */
49 /* case _CARPLAX: */
50 // oled_write_ln_P(PSTR("Carplax\n"), false);
51 /* break; */
52
53 case _BEAKL:
54 case _BEAKL_BP:
55 oled_write_ln_P(PSTR("Beakl"), false);
56 break;
57 case _BEPO:
58 oled_write_ln_P(PSTR("Bepo"), false);
59 break;
60 }
61}
62
63void oled_render_layer_state(void) {
64 oled_write_P(PSTR("Layer: "), false);
65 switch (get_highest_layer(layer_state)) {
66 case _NAV:
67 oled_write_P(PSTR("Navigation"), false);
68 break;
69 case _LAYERS:
70 oled_write_P(PSTR("Layers"), false);
71 break;
72 case _RGB:
73 oled_write_P(PSTR("RGB"), false);
74 break;
75 case _TOPROWS:
76 case _TOPROWS_BP:
77 oled_write_P(PSTR("TopRows"), false);
78 break;
79 case _SYMB:
80 case _SYMB_BP:
81 oled_write_P(PSTR("Symbols"), false);
82 break;
83 case _KEYPAD:
84 case _KEYPAD_BP:
85 oled_write_P(PSTR("Keypad"), false);
86 break;
87 case _ADJUST:
88 oled_write_P(PSTR("Adjust"), false);
89 break;
90 }
91 oled_write_ln_P(PSTR(" "), false);
92}
93
94// this is part of my answer to a challenge.
95// My friend Ross thinks that the only use of an oled
96// is to say which layer.
97// I think there is more. this is just a beginning.
98void oled_render_layer_map(void) {
99 uint8_t lyr = get_highest_layer(layer_state);
100 if (lyr <= _BEPO) {
101 switch (get_highest_layer(default_layer_state)) {
102 case _QWERTY:
103 oled_write_ln_P(PSTR(" qwert yuiop"), false);
104 oled_write_ln_P(PSTR(" asdfg hjkl;"), false);
105 oled_write_ln_P(PSTR(" zxcvb nm,./"), false);
106 break;
107 case _COLEMAK:
108 oled_write_ln_P(PSTR(" qwfpb jluy;"), false);
109 oled_write_ln_P(PSTR(" arstg mneio"), false);
110 oled_write_ln_P(PSTR(" zxcdv kh,./"), false);
111 break;
112 case _DVORAK_BP:
113 case _DVORAK:
114 oled_write_ln_P(PSTR(" \",.py fgcrl"), false);
115 oled_write_ln_P(PSTR(" aoeui dhtns"), false);
116 oled_write_ln_P(PSTR(" ;qjkx bmwvz "), false);
117 break;
118
119 case _BEAKL:
120 case _BEAKL_BP:
121 oled_write_ln_P(PSTR(" qhoux gcrfz"), false);
122 oled_write_ln_P(PSTR(" yiea. dstnb"), false);
123 oled_write_ln_P(PSTR(" j/,k' wmlpv"), false);
124 break;
125
126 case _BEPO:
127 oled_write_P(PSTR(" cbe'po`e vdljz %"), false);
128 oled_write_P(PSTR(" auie, tsrnmc"), false);
129 oled_write_P(PSTR(" e^a'yx.k 'qghfw"), false);
130 break;
131 }
132
133 } else {
134
135 switch (lyr) {
136 case _TOPROWS:
137 case _TOPROWS_BP:
138 oled_write_ln_P(PSTR(" !@#$% ^&*()"), false);
139 oled_write_ln_P(PSTR(" 40123 76598"), false);
140 oled_write_ln_P(PSTR(" F1- -- -F12"), false);
141 break;
142
143 case _SYMB:
144 case _SYMB_BP:
145 oled_write_ln_P(PSTR(" `<$>' ?[_]-"), false);
146 oled_write_ln_P(PSTR(" -\\(\")# !{:}/;"), false);
147 oled_write_ln_P(PSTR(" @=*+; %&^~|"), false);
148 break;
149
150 case _NAV:
151 oled_write_ln_P(PSTR("54321 0 ctn 12345"), false);
152 oled_write_ln_P(PSTR(" ldur 1 ccv ldur"), false);
153 oled_write_ln_P(PSTR(" ldur 2 cwq hdue"), false);
154 break;
155
156 case _KEYPAD:
157 oled_write_ln_P(PSTR(" 523: F9-F12"), false);
158 oled_write_ln_P(PSTR(" -7.104 F5-F8"), false);
159 oled_write_ln_P(PSTR(" /698, F1-F4"), false);
160 break;
161
162 case _LAYERS:
163 oled_write_ln_P(PSTR(" Bp Dv Bk|Nv S K TR"), false);
164 oled_write_ln_P(PSTR("Q Cl Dv Bk|Nv S K TR"), false);
165 oled_write_P(PSTR(" "), false);
166 //oled_write_ln_P(PSTR("Ctrls?-> RGB ___ ___ Adjust"), false);
167 break;
168 }
169 }
170}
171
172void oled_render_keylock_status(uint8_t led_usb_state) {
173 oled_write_P(PSTR(" Lock:"), false);
174 oled_write_P(PSTR(" "), false);
175 oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK));
176 oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK));
177 oled_write_ln_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK));
178}
179
180void oled_render_mod_status(uint8_t modifiers) {
181 oled_write_P(PSTR("Mods:"), false);
182 oled_write_P(PSTR("S"), (modifiers & MOD_MASK_SHIFT));
183 oled_write_P(PSTR("C"), (modifiers & MOD_MASK_CTRL));
184 oled_write_P(PSTR("A"), (modifiers & MOD_MASK_ALT));
185 oled_write_P(PSTR("G"), (modifiers & MOD_MASK_GUI));
186}
187
188void oled_render_mod_lock_status(){
189 oled_render_mod_status(get_mods() | get_oneshot_mods());
190 oled_render_keylock_status(host_keyboard_leds());
191}
192
193
194char mkeylog_str[22] = {};
195
196const char mcode_to_name[60] = {
197 ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
198 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
199 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
200 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
201 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
202 '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
203
204
205void oled_render_keylog(void) {
206 oled_write_ln(mkeylog_str, false);
207 // sometimes there's an extra row. this is because sometimes it drops
208 // to the last line. and this clears it.
209 oled_write_ln_P(PSTR(" "), false);
210}
211
212
213void add_keylog(uint16_t keycode, keyrecord_t *record) {
214 char name = ' ';
215 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
216 (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
217 keycode = keycode & 0xFF;
218 }
219 if (keycode < 60) {
220 name = mcode_to_name[keycode];
221 }
222
223 // update keylog
224 memset(mkeylog_str, ' ', sizeof(mkeylog_str) - 1);
225 snprintf(mkeylog_str, sizeof(mkeylog_str), "%dx%d, k%2d : %c",
226 record->event.key.row, record->event.key.col,
227 keycode, name);
228}
229
230__attribute__((weak)) oled_rotation_t oled_init_keymap(oled_rotation_t rotation) { return rotation; }
231
232oled_rotation_t oled_init_user(oled_rotation_t rotation) {
233
234 // for the big screen.
235#ifdef OLED_DISPLAY_128X64
236 return OLED_ROTATION_180;
237#endif
238
239 return oled_init_keymap(rotation);
240}
241
242/* oled_rotation_t oled_init_user(oled_rotation_t rotation) { */
243/* memset(mkeylog_str, ' ', sizeof(mkeylog_str) - 1); */
244/* if (is_keyboard_master()) { */
245/* return OLED_ROTATION_270; */
246/* } else { */
247/* return OLED_ROTATION_180; */
248/* } */
249/* } */
250
251bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) {
252 if (record->event.pressed) {
253 //oled_timer = timer_read32();
254 add_keylog(keycode, record);
255 //add_keylog(keycode);
256 }
257 return true;
258}
259
260void render_bootmagic_status(bool status) {
261 /* Show Ctrl-Gui Swap options */
262 static const char PROGMEM logo[][2][3] = {
263 {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
264 {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
265 };
266 if (status) {
267 oled_write_ln_P(logo[0][0], false);
268 oled_write_ln_P(logo[0][1], false);
269 } else {
270 oled_write_ln_P(logo[1][0], false);
271 oled_write_ln_P(logo[1][1], false);
272 }
273}
274
275
276__attribute__((weak)) void oled_render_logo(void) {
277 // clang-format off
278 static const char PROGMEM qmk_logo[] = {
279 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
280 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
281 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
282 // clang-format on
283 oled_write_P(qmk_logo, false);
284}
285
286bool oled_task_user(void) {
287 if (is_keyboard_master()) {
288 oled_render_mod_lock_status();
289 oled_render_default_layer_state();
290 oled_render_layer_state();
291#ifdef OLED_DISPLAY_128X64
292 oled_render_layer_map();
293#endif
294 oled_render_keylog();
295 } else {
296 oled_render_logo();
297 oled_render_default_layer_state();
298 }
299 return(true);
300
301}
302/* oled_render_keylock_status(host_keyboard_leds()); */
303/* oled_render_mod_status(get_mods() | get_oneshot_mods()); */