summaryrefslogtreecommitdiff
path: root/users/riblee/riblee.c
blob: 02ba246f603eddee79ea0eb5442eaf6ba0d4a53c (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* Copyright 2020 Janos Daniel Reibl <janos.daniel.reibl@protonmail.com> @riblee
 *
 * 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 "riblee.h"
#include "raw_hid.h"
#include <string.h>

// Tap Dance functions
void dance_key_a (qk_tap_dance_state_t *state, void *user_data) {
    if (state->count == 1) {
        SEND_STRING("a");
        reset_tap_dance(state);
    } else if (state->count == 2) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("á");
        } else {
            send_unicode_string("Á");
        }

        reset_tap_dance(state);
    }
}

void dance_key_e (qk_tap_dance_state_t *state, void *user_data) {
    if (state->count == 1) {
        SEND_STRING("e");
        reset_tap_dance(state);
    } else if (state->count == 2) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("é");
        } else {
            send_unicode_string("É");
        }

        reset_tap_dance(state);
    }
}

void dance_key_i (qk_tap_dance_state_t *state, void *user_data) {
    if (state->count == 1) {
        SEND_STRING("i");
        reset_tap_dance(state);
    } else if (state->count == 2) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("í");
        } else {
            send_unicode_string("Í");
        }

        reset_tap_dance(state);
    }
}

void dance_key_o (qk_tap_dance_state_t *state, void *user_data) {
    if (state->count == 1) {
        SEND_STRING("o");
        reset_tap_dance(state);
    } else if (state->count == 2) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("ó");
        } else {
            send_unicode_string("Ó");
        }

        reset_tap_dance(state);
    } else if (state->count == 3) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("ö");
        } else {
            send_unicode_string("Ö");
        }

        reset_tap_dance(state);
    } else if (state->count == 4) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("ő");
        } else {
            send_unicode_string("Ő");
        }

        reset_tap_dance(state);
    }
}

void dance_key_u (qk_tap_dance_state_t *state, void *user_data) {
    if (state->count == 1) {
        SEND_STRING("u");
        reset_tap_dance(state);
    } else if (state->count == 2) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("ú");
        } else {
            send_unicode_string("Ú");
        }

        reset_tap_dance(state);
    } else if (state->count == 3) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("ü");
        } else {
            send_unicode_string("Ü");
        }

        reset_tap_dance(state);
    } else if (state->count == 4) {
        if (!(keyboard_report->mods & MOD_MASK_SHIFT)) {
            send_unicode_string("ű");
        } else {
            send_unicode_string("Ű");
        }

        reset_tap_dance(state);
    }
}

layer_state_t layer_state_set_user(layer_state_t state) {
    return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch (keycode) {
        case QWERTY:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_QWERTY);
            }
            return false;
            break;
        case COLEMAK:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_COLEMAK);
            }
            return false;
            break;
        case DVORAK:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_DVORAK);
            }
            return false;
            break;
        case WORKMAN:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_WORKMAN);
            }
            return false;
            break;
        case HUNGARIAN:
            if (record->event.pressed) {
                set_single_persistent_default_layer(_HUNGARIAN);
            }
            return false;
            break;
    }
    return true;
};

#ifdef OLED_ENABLE

static char receive_buffer[128] = {};
static uint8_t receive_buffer_length = 0;
uint16_t startup_timer;

oled_rotation_t oled_init_user(oled_rotation_t rotation) {
    startup_timer = timer_read();
    return rotation;
}

static void render_logo(void) {
    static const char PROGMEM raw_logo[] = {
        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,  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,  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,  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,  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, 96, 96, 96,240,248,255, 63, 56,255,255,248, 63, 63,248,255,255, 56, 63,255,248,240, 96, 96, 96,  0,  0,  0,  0,  0,252,254, 38, 54, 60,  8,240,152,152,248,240, 24,248,224,248,120,224,240,120, 96,248,248,248,248, 32,248,248, 24, 24,240,248,248,248,240,240,248,152,152,254,254,  0,  0,  0,254,254,152,248,240, 24,248,224,240,120,  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,219,219,219,255,255,255,240,192,143,159, 63,  0,  0, 63,159,143,192,240,255,255,255,219,219,219,  0,  0,  0,  0,  0,192,225,112, 48, 48, 48,112,225,129,  1,240,240,240,193,  1,  0,  1,193,240,240,241,  1,  1,241,240,193,225,112, 48,  0,  1,  1,  1,  1,240,241, 49, 49, 49,  0,240,240,  0,129,193,129,193,192,  0,196,135,193,192,128,128,192,192,128,  0,  0,192,128,  0,128,192,128,  0,  0,192,192,128,128,192,192,192,128,  0,128,192,128,192,192,  0,128,192,192,192,128,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  6,  6,  6, 15, 31,255,255, 31,255,255, 31,252,252, 31,255,255, 31,255,255, 31, 15,  6,  6,  6,  0,  0,  0,  0,  0, 15, 31, 56, 48, 48, 48, 60,127,103, 96, 63, 63,  0,  7, 63, 56, 31,  7,  0, 63, 63,  0,  0, 63, 63,  7, 30, 60, 48,  0,  0,  0,  0,  0, 63, 31,  3,  3,  3,  0, 63, 63,  0, 31, 63,  1,  0,  0,  0, 63, 31,  0,  1, 63, 63,  0,  0, 63, 63,  0,  7, 63, 60, 63,  7, 31, 60, 63, 15,  0, 28, 60, 54, 54, 63, 63,  0, 63, 63,  1,  0,  0, 31, 63, 54, 54, 55, 55,  2,  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,128,128,128,128,128,128,  0,  0,192,192,192,  0,192,192,192,  0,  0,  0,  0,  0,  0,192,192,192,  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,  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,255,255,255, 29,127,255,247,224,  0,254,254,254,  0,255,255,255,198,254,254,254,  0,  0,255,255,255,124,254,254,214,214,222,222, 92,124,254,254,214,214,222,222, 92,  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,  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,  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,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    };

    oled_write_raw_P(raw_logo, sizeof(raw_logo));
}

static void render_info(void) {
    // Keyboard Layer Status
    oled_write_P(PSTR("Layer: "), false);

    switch (get_highest_layer(layer_state)) {
        case _QWERTY:
            if (layer_state_cmp(default_layer_state, _QWERTY)) {
                oled_write_P(PSTR("Qwerty\n"), false);
            } else if (layer_state_cmp(default_layer_state, _COLEMAK)) {
                oled_write_P(PSTR("Colmak\n"), false);
            } else if (layer_state_cmp(default_layer_state, _DVORAK)) {
                oled_write_P(PSTR("Dvorak\n"), false);
            } else if (layer_state_cmp(default_layer_state, _WORKMAN)) {
                oled_write_P(PSTR("Workman\n"), false);
            } else if (layer_state_cmp(default_layer_state, _HUNGARIAN)) {
                oled_write_P(PSTR("HUN Qwerty\n"), false);
            } else {
                oled_write_P(PSTR("Undefined\n"), false);
            }
            break;
        case _LOWER:
            oled_write_P(PSTR("Lower\n"), false);
            break;
        case _RAISE:
            oled_write_P(PSTR("Raise\n"), false);
            break;
        case _ADJUST:
            oled_write_P(PSTR("Adjust\n"), false);
            break;
        default:
            oled_write_P(PSTR("Undefined\n"), false);
    }

    // Print string received via HID RAW
    oled_write_ln(receive_buffer, false);}

bool oled_task_user(void) {
    static bool finished_timer = false;
    if (!finished_timer && (timer_elapsed(startup_timer) < 1000)) {
        render_logo();
    } else {
        if (!finished_timer) {
            oled_clear();
            finished_timer = true;
        }
        render_info();
    }
    return false;

}

#ifdef RAW_ENABLE

void raw_hid_receive(uint8_t *data, uint8_t length) {

    // Append data to receive_buffer, without the first byte
    memcpy(receive_buffer + receive_buffer_length, data + 1, length - 1);
    receive_buffer_length += (length - 1);

    // First byte indicate if we will recive more package for the current string
    // If it's 1 then this was the last package and we can reset the offset
    if (data[0] == 1) {
        // Reset the offset for memcpy to the begining of our buffer
        receive_buffer_length = 0;
    }

    // Reset the offset to prevent overwriting memory outside of the buffer
    if (receive_buffer_length + 32 >= 128) {
        receive_buffer_length = 0;
    }

}

#endif

#endif

void keyboard_pre_init_user(void) {
    // Set C13 pin as output
    setPinOutput(C13);

    // Turn off the LED
    writePinHigh(C13);
}