]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/xulkal/custom_oled.c
[Keymap][Xulkal] User code update (#6752)
[qmk_firmware.git] / users / xulkal / custom_oled.c
1 #include "custom_oled.h"
2 #include "process_records.h"
3
4 #include <stdio.h>
5
6 #ifdef RGBLIGHT_ENABLE
7 rgblight_config_t rgblight_config;
8 #endif
9
10 #if KEYBOARD_helix_rev2
11 extern uint8_t is_master;
12 bool is_keyboard_master(void) { return is_master; }
13 #endif
14
15 static void render_logo(void)
16 {
17     static const char PROGMEM font_logo[] = {
18         0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
19         0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
20         0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
21     oled_write_P(font_logo, false);
22 }
23
24 static void render_icon(void)
25 {
26 #ifdef OLED_90ROTATION
27     static const char PROGMEM font_icon[] = {
28         0x9b,0x9c,0x9d,0x9e,0x9f,
29         0xbb,0xbc,0xbd,0xbe,0xbf,
30         0xdb,0xdc,0xdd,0xde,0xdf,0
31     };
32 #else
33     static const char PROGMEM font_icon[] = {
34         // Use \r (0x0d) to jump to the next line without clearing the rest of the current line
35         0x9b,0x9c,0x9d,0x9e,0x9f,0x0d,
36         0xbb,0xbc,0xbd,0xbe,0xbf,0x0d,
37         0xdb,0xdc,0xdd,0xde,0xdf,0
38     };
39 #endif
40     oled_write_P(font_icon, false);
41 }
42
43 static void render_layer(void)
44 {
45     uint8_t layer = layer_state ? biton(layer_state) : biton32(default_layer_state);
46 #ifdef OLED_90ROTATION
47     oled_write_P(PSTR("Layer"), false);
48 #else
49     oled_write_P(PSTR("Layer: "), false);
50 #endif
51
52     switch (layer)
53     {
54         case _QWERTY:
55             oled_write_P(PSTR("BASE "), false);
56             break;
57 #ifndef GAMELAYER_DISABLE
58         case _GAME:
59             oled_write_P(PSTR("GAME "), false);
60             break;
61 #endif
62         case _LOWER:
63             oled_write_P(PSTR("LOWER"), false);
64             break;
65         case _RAISE:
66             oled_write_P(PSTR("RAISE"), false);
67             break;
68 #ifdef TRILAYER_ENABLED
69         case _ADJUST:
70             oled_write_P(PSTR("ADJST"), false);
71             break;
72 #endif
73     }
74 }
75
76 static void render_keyboard_leds(void)
77 {
78     // Host Keyboard LED Status
79     uint8_t led_state = host_keyboard_leds();
80 #ifdef OLED_90ROTATION
81     oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUMLK") : PSTR("     "), false);
82     oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPLK") : PSTR("     "), false);
83     oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR("     "), false);
84 #else
85     oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUM  ") : PSTR("     "), false);
86     oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR("     "), false);
87     oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRL") : PSTR("    "), false);
88 #endif
89 }
90
91 #ifdef RGB_OLED_MENU
92 extern uint8_t rgb_encoder_state;
93 #endif
94
95 #if defined(OLED_90ROTATION)
96
97 #ifdef RGB_ENABLE
98 static void render_rgb_state(void)
99 {
100     // TODO: need to do a bit more handling here for horizontal rendering
101 #if defined(RGB_MATRIX_ENABLE)
102     static char buffer[31] = {0};
103     snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d e%3d ", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, rgb_matrix_config.speed, rgb_matrix_config.mode, rgb_matrix_get_flags());
104 #elif defined(RGBLIGHT_ENABLE)
105     static char buffer[26] = {0};
106     snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d ", rgblight_config.hue, rgblight_config.sat, rgblight_config.val, rgblight_config.speed, rgblight_config.mode);
107 #endif
108
109 #ifdef RGB_OLED_MENU
110     buffer[4 + rgb_encoder_state * 5] = '<';
111 #endif
112     oled_write(buffer, false);
113 }
114 #endif
115
116 static void render_status(void)
117 {
118     render_icon();
119     render_layer();
120
121     // Host Keyboard LED Status
122     oled_write_P(PSTR("-----"), false);
123     render_keyboard_leds();
124
125     oled_write_P(PSTR("-----"), false);
126 #ifdef RGB_ENABLE
127     render_rgb_state();
128 #endif
129 }
130
131 oled_rotation_t oled_init_user(oled_rotation_t rotation) {
132 #if KEYBOARD_helix_rev2
133   if (is_keyboard_master())
134     return OLED_ROTATION_270;
135   return rotation;
136 #else
137   if (is_keyboard_master())
138     return OLED_ROTATION_90;
139   return rotation;
140 #endif
141 }
142
143 #else  // OLED_90ROTATION
144
145 #ifdef RGB_ENABLE
146 static void render_rgb_state(void)
147 {
148     // TODO: need to do a bit more handling here for horizontal rendering
149 #if defined(RGB_MATRIX_ENABLE)
150     static char buffer[37] = {0};
151     snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d       s%3d m%3d e%3d ", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, rgb_matrix_config.speed, rgb_matrix_config.mode, rgb_matrix_get_flags());
152 #elif defined(RGBLIGHT_ENABLE)
153     static char buffer[32] = {0};
154     snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d       s%3d m%3d ", rgblight_config.hue, rgblight_config.sat, rgblight_config.val, rgblight_config.speed, rgblight_config.mode);
155 #endif
156
157 #ifdef RGB_OLED_MENU
158     buffer[4 + rgb_encoder_state * 5] = '<';
159 #endif
160     oled_write(buffer, false);
161 }
162 #endif
163
164 static void render_status(void)
165 {
166     render_icon();
167
168     // Host Layer Status
169     oled_set_cursor(6, 0);
170     render_layer();
171
172     // Host Keyboard LED Status
173     oled_set_cursor(6, 1);
174     render_keyboard_leds();
175
176 #ifdef RGB_ENABLE
177     oled_set_cursor(6, 2);
178     render_rgb_state();
179 #endif
180 }
181
182 #endif // OLED_90ROTATION
183
184 void oled_task_user(void)
185 {
186     if (is_keyboard_master())
187         render_status();
188     else
189     {
190         render_logo();
191         oled_scroll_left();
192     }
193 }