summaryrefslogtreecommitdiff
path: root/keyboards/rubi/rubi.c
blob: 50e5fcf7827847aee1dd9821f7da5c81a9fb6ac2 (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
/* Copyright 2021 gregorio
 *
 * 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 "rubi.h"

uint8_t oled_mode = OLED_MODE_DEFAULT;

char calc_result_display[CALC_DIGITS+1] = "";
char calc_operator_display = ' ';
char calc_status_display[CALC_DIGITS+1] = "";
uint8_t calc_display_lines = 2;

const char keycode_to_ascii_lut[58] = {0, 0, 0, 0, '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', 0, 0, 0, '\t', ' ', '-', '=', '[', ']', '\\', 0, ';', '\'', '`', ',', '.', '/'};

uint8_t encoder_mode = ENC_MODE_VOLUME;

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
    if (keycode < 58 && keycode != KC_TAB) {
        if (record->event.pressed) {
            calcInput(keycode_to_ascii_lut[(uint8_t)keycode]);
        }
        return false;
    }
    switch (keycode) {
        case ENC_PRESS:
            if (record->event.pressed) {
                uint16_t mapped_code = handle_encoder_press();
                if (mapped_code != 0) {
                    tap_code16(mapped_code);
                }
            }
            return false;
        case CL_PLUS:
            if (record->event.pressed) {
                calcInput('+');
            }
            return false;
        case CL_STAR:
            if (record->event.pressed) {
                calcInput('*');
            }
            return false;
        case CL_TYPE:
            if (record->event.pressed) {
                send_string(calc_result_display);
            }
            return false;
        default:
            break;
    }

    return process_record_user_oled(keycode, record);
}


bool led_update_kb(led_t led_state) {
    bool res = led_update_user(led_state);
    if (res) {
        writePin(C6, led_state.num_lock);
    }
    return true;
}

bool encoder_update_kb(uint8_t index, bool clockwise) {
    if (!encoder_update_user(index, clockwise)) { return false; }
    return true;
}