aboutsummaryrefslogtreecommitdiff
path: root/keyboards/rubi/rubi.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/rubi/rubi.c')
-rw-r--r--keyboards/rubi/rubi.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/keyboards/rubi/rubi.c b/keyboards/rubi/rubi.c
new file mode 100644
index 000000000..6cdf8302c
--- /dev/null
+++ b/keyboards/rubi/rubi.c
@@ -0,0 +1,108 @@
1/* Copyright 2021 gregorio
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "rubi.h"
17
18uint8_t oled_mode = OLED_MODE_DEFAULT;
19
20char calc_result_display[CALC_DIGITS+1] = "";
21char calc_operator_display = ' ';
22char calc_status_display[CALC_DIGITS+1] = "";
23uint8_t calc_display_lines = 2;
24
25const 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, ';', '\'', '`', ',', '.', '/'};
26
27uint8_t encoder_mode = ENC_MODE_VOLUME;
28
29bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
30 if (keycode < 58 && keycode != KC_TAB) {
31 if (record->event.pressed) {
32 calcInput(keycode_to_ascii_lut[(uint8_t)keycode]);
33 }
34 return false;
35 }
36 switch (keycode) {
37 case ENC_PRESS:
38 if (record->event.pressed) {
39 uint16_t mapped_code = handle_encoder_press();
40 if (mapped_code != 0) {
41 tap_code16(mapped_code);
42 }
43 }
44 return false;
45 case CL_PLUS:
46 if (record->event.pressed) {
47 calcInput('+');
48 }
49 return false;
50 case CL_STAR:
51 if (record->event.pressed) {
52 calcInput('*');
53 }
54 return false;
55 case CL_TYPE:
56 if (record->event.pressed) {
57 send_string(calc_result_display);
58 }
59 return false;
60 default:
61 break;
62 }
63
64 return process_record_user_oled(keycode, record);
65}
66
67
68bool led_update_kb(led_t led_state) {
69 bool res = led_update_user(led_state);
70 if (res) {
71 writePin(C6, led_state.num_lock);
72 }
73 return true;
74}
75
76__attribute__ ((weak)) void encoder_update_user(uint8_t index, bool clockwise) {
77 if (index == 0) {
78 if (get_highest_layer(layer_state) == 0) {
79 uint16_t mapped_code = 0;
80 if (clockwise) {
81 mapped_code = handle_encoder_cw();
82 } else {
83 mapped_code = handle_encoder_ccw();
84 }
85 if (mapped_code != 0) {
86 tap_code16(mapped_code);
87 }
88 } else {
89 if (clockwise) {
90 if (oled_mode == OLED_MODE_CALC) {
91 handle_encoder_cw();
92 } else if (oled_mode == OLED_MODE_DEFAULT) {
93 change_encoder_mode(false);
94 }
95 } else {
96 if (oled_mode == OLED_MODE_CALC) {
97 handle_encoder_ccw();
98 } else if (oled_mode == OLED_MODE_DEFAULT) {
99 change_encoder_mode(true);
100 }
101 }
102 }
103 }
104}
105
106void encoder_update_kb(uint8_t index, bool clockwise) {
107 encoder_update_user(index, clockwise);
108}