summaryrefslogtreecommitdiff
path: root/keyboards/nullbitsco/nibble/keymaps/oled_status/oled_display.c
blob: c734e80cefea89c199ce4081bba1b5da63d4b156 (plain)
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
/* Copyright 2021 Jose Luis Adelantado Torres
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "quantum.h"
#include "oled_display.h"

static const char PROGMEM oled_mode_messages[5][15] = {
    "",
    "Volume Up",
    "Volume Down",
    "RGB ON",
    "RGB OFF"
};

static const char PROGMEM oled_mode_icons[5][3][5] = {
    {{128,129,130,131,0},{160,161,162,163,0},{192,193,194,195,0}},
    {{132,133,134,135,0},{164,165,166,167,0},{196,197,198,199,0}},
    {{136,137,138,139,0},{168,169,170,171,0},{200,201,202,203,0}},
    {{140,141,142,143,0},{172,173,174,175,0},{204,205,206,207,0}},
    {{144,145,146,147,0},{176,177,178,179,0},{208,209,210,211,0}}
};

void set_oled_mode(oled_mode_t mode) {
    oled_mode = mode;
}

void process_record_encoder_oled(uint16_t keycode) {
    oled_timer = timer_read32();
    switch (keycode) {
        case KC_VOLU:
            set_oled_mode(OLED_MODE_VOLUME_UP);
            break;
        case KC_VOLD:
            set_oled_mode(OLED_MODE_VOLUME_DOWN);
            break;
        default:
            set_oled_mode(OLED_MODE_IDLE);
            break;
    }
}

void process_record_keymap_oled(uint16_t keycode) {
    oled_timer = timer_read32();
    if(rgblight_is_enabled()) {
        set_oled_mode(OLED_MODE_RGB_OFF);
    } else {
        set_oled_mode(OLED_MODE_RGB_ON);
    }
}

void render_wpm(void) {
    uint8_t n = get_current_wpm();
    char wpm_counter[4];
    wpm_counter[3] = '\0';
    wpm_counter[2] = '0' + n % 10;
    wpm_counter[1] = '0' + (n /= 10) % 10;
    wpm_counter[0] = '0' + n / 10 ;
    oled_write_P(PSTR("                 "), false);
    oled_write(wpm_counter, false);
}

void render_idle(void) {
    // Host Keyboard LED Status
    led_t led_state = host_keyboard_led_state();

    // Printing logo, state
    oled_write_P(oled_mode_icons[0][0], false);
    oled_write_P(PSTR("        "), false);
    oled_write_P(led_state.scroll_lock ? PSTR("S ") : PSTR("  "), false);
    oled_write_P(led_state.num_lock ? PSTR("N ") : PSTR("  "), false);
    oled_write_P(led_state.caps_lock ? PSTR("C ") : PSTR("  "), false);
    oled_write_P(PSTR("\n"), false);
    oled_write_P(oled_mode_icons[0][1], false);
    oled_write_P(PSTR("  Nibble"), false);
    oled_write_P(PSTR("\n"), false);
    oled_write_P(oled_mode_icons[0][2], false);
    oled_write_P(PSTR("\n"), false);

    // Printing WPM
    render_wpm();
}

void render_status_mode_message(void) {
    // Printing state icon with message
    oled_write_P(oled_mode_icons[oled_mode][0], false);
    oled_write_P(PSTR("\n"), false);
    oled_write_P(oled_mode_icons[oled_mode][1], false);
    oled_write_P(PSTR("  "), false);
    oled_write_P(oled_mode_messages[oled_mode], false);
    oled_write_P(PSTR("\n"), false);
    oled_write_P(oled_mode_icons[oled_mode][2], false);
    oled_write_P(PSTR("\n\n"), false);
}

void render_frame(void) {
    switch (oled_mode) {
        case OLED_MODE_VOLUME_UP:
        case OLED_MODE_VOLUME_DOWN:
        case OLED_MODE_RGB_ON:
        case OLED_MODE_RGB_OFF:
            render_status_mode_message();
            break;
        default:
            render_idle();
            break;
    }
}