-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholed.c
125 lines (112 loc) · 5.6 KB
/
oled.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include QMK_KEYBOARD_H
#include <stdio.h>
#include "layers.h"
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (!is_keyboard_master()) {
return OLED_ROTATION_180;
}
return rotation;
}
void oled_render_layer_state(void) {
// oled_write_P(PSTR("Layer"), false);
switch (get_highest_layer(default_layer_state)) {
case _COLEMAK:
oled_write_P(PSTR("C: "), false);
break;
default:
oled_write_P(PSTR("?: "), false);
break;
}
// oled_write_ln_P(PSTR(layer_state), false);
switch (get_highest_layer(layer_state|default_layer_state)) {
case _COLEMAK:
oled_write_P(PSTR("Base "), false);
break;
case _SYM:
oled_write_P(PSTR("Sym "), false);
break;
case _NUM:
oled_write_P(PSTR("Num "), false);
break;
case _LNUM:
oled_write_P(PSTR("LNum "), false);
break;
case _NAV:
oled_write_P(PSTR("Nav "), false);
break;
case _UTIL:
oled_write_P(PSTR("Util "), false);
break;
default:
oled_write_P(PSTR("Unkn "), false);
break;
}
oled_write_P(PSTR("\n"), false);
oled_write_P(PSTR("\n"), false);
}
void oled_render_mod_state(void) {
uint8_t modifiers = get_mods() | get_oneshot_mods();
oled_write_P((modifiers & MOD_MASK_SHIFT) ? PSTR("SFT ") : PSTR(""), false);
oled_write_P((modifiers & MOD_MASK_CTRL) ? PSTR("CTL ") : PSTR(""), false);
oled_write_P((modifiers & MOD_MASK_ALT) ? PSTR("ALT ") : PSTR(""), false);
oled_write_P((modifiers & MOD_MASK_GUI) ? PSTR("CMD ") : PSTR(""), false);
}
#ifdef RGBLIGHT_ENABLE
void oled_render_rgb_state(void) {
static char rgbStatusLine1[26] = {0};
snprintf(rgbStatusLine1, sizeof(rgbStatusLine1), "RGB: %d ", rgblight_get_mode());
oled_write(rgbStatusLine1, false);
static char rgbStatusLine2[26] = {0};
snprintf(rgbStatusLine2, sizeof(rgbStatusLine2), "%d, %d, %d", rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val());
oled_write_ln(rgbStatusLine2, false);
}
#endif
char keylog_str[12] = {};
const char code_to_name[60] = {
' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
'#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
void set_keylog(uint16_t keycode, keyrecord_t *record) {
char name = ' ';
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
(keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; }
if (keycode < 60) {
name = code_to_name[keycode];
snprintf(keylog_str, sizeof(keylog_str), "%c: k%-8d",
name, keycode);
}
}
void oled_render_keylog(void) {
oled_write_ln(keylog_str, false);
}
void oled_render_logo(void) {
static const char PROGMEM raw_logo[] = {
0, 0, 0, 0, 0, 8, 16, 32, 32,240,216,252,254,242, 18, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,192,224,176,240, 64,160, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,192,240,248,172,254,184, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,192,224, 96,224,224, 0,192,128, 0, 0, 0,
0, 0, 0, 0, 0, 16, 8, 4, 4, 15, 27, 63,127, 79, 72, 6, 0, 0, 0, 0, 0,128,224,240,176,240, 96,176, 24, 0, 0, 0, 1, 3, 7, 13, 15, 2, 5, 10, 0, 0, 0, 0, 0,224,184,188,254,146, 34, 0, 0, 0, 0, 0, 3, 15, 31, 53,127, 29, 8, 0, 0, 64, 64,132,136,144,192, 96,120,198,128, 32, 16, 8, 0, 0, 0, 0, 0, 0,128,128, 0, 0, 0, 0, 0, 0,128,128, 0, 0, 0,128,128,192,192,224, 96, 96,112,240,240, 48, 52,208,212, 52, 52,212,214, 55, 55,211,211, 51, 55,247,240, 99, 1, 0, 0, 0,
0, 0, 0, 0, 0, 8, 16, 32, 32,240,216,252,254,242, 18, 96, 0, 0, 0, 0, 0, 1, 7, 15, 13, 15, 6, 13, 24, 0, 0, 0,128,192,224,176,240, 64,160, 80, 0, 0, 0, 0, 0, 7, 29, 61,127, 73, 68, 0, 0, 0, 0, 0,192,240,248,172,254,184, 16, 0, 0, 0, 16, 8, 4, 1, 99, 30, 6, 3, 9, 17, 33, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 3, 7, 6, 6, 14, 15, 15, 12, 44, 11, 43, 44, 44, 43,107,236,236,235,203,204,236,239, 15,198,128, 0, 0, 0,
0, 0, 0, 0, 0, 16, 8, 4, 4, 15, 27, 63,127, 79, 72, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 13, 15, 2, 5, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 15, 31, 53,127, 29, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 6, 7, 7, 0, 3, 1, 0, 0, 0,
};
oled_write_raw_P(raw_logo, sizeof(raw_logo));
}
bool oled_task_user(void) {
if (is_keyboard_master()) {
oled_render_layer_state();
oled_render_mod_state();
oled_render_keylog();
#ifdef RGBLIGHT_ENABLE
oled_render_rgb_state();
#endif
} else {
oled_render_logo();
}
return false;
}
bool oled_process_record(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
set_keylog(keycode, record);
}
return true;
}