From 4d353cdba8038aacbd2b6292ab35c8ddd4cf4c52 Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Date: Thu, 18 Mar 2021 22:21:13 +0700 Subject: [PATCH 1/7] initial commit --- keyboards/rubi/config.h | 65 ++++++ keyboards/rubi/info.json | 58 +++++ keyboards/rubi/keymaps/default/keymap.c | 53 +++++ keyboards/rubi/keymaps/default/readme.md | 3 + keyboards/rubi/keymaps/via/keymap.c | 53 +++++ keyboards/rubi/keymaps/via/rules.mk | 2 + keyboards/rubi/lib/calc.c | 259 ++++++++++++++++++++++ keyboards/rubi/lib/encoder.c | 98 +++++++++ keyboards/rubi/lib/glcdfont.c | 238 +++++++++++++++++++++ keyboards/rubi/lib/oled.c | 261 +++++++++++++++++++++++ keyboards/rubi/lib/oled.h | 17 ++ keyboards/rubi/readme.md | 19 ++ keyboards/rubi/rubi.c | 111 ++++++++++ keyboards/rubi/rubi.h | 101 +++++++++ keyboards/rubi/rules.mk | 28 +++ 15 files changed, 1366 insertions(+) create mode 100644 keyboards/rubi/config.h create mode 100644 keyboards/rubi/info.json create mode 100644 keyboards/rubi/keymaps/default/keymap.c create mode 100644 keyboards/rubi/keymaps/default/readme.md create mode 100644 keyboards/rubi/keymaps/via/keymap.c create mode 100644 keyboards/rubi/keymaps/via/rules.mk create mode 100644 keyboards/rubi/lib/calc.c create mode 100644 keyboards/rubi/lib/encoder.c create mode 100644 keyboards/rubi/lib/glcdfont.c create mode 100644 keyboards/rubi/lib/oled.c create mode 100644 keyboards/rubi/lib/oled.h create mode 100644 keyboards/rubi/readme.md create mode 100644 keyboards/rubi/rubi.c create mode 100644 keyboards/rubi/rubi.h create mode 100644 keyboards/rubi/rules.mk diff --git a/keyboards/rubi/config.h b/keyboards/rubi/config.h new file mode 100644 index 000000000000..b22e20cbb34e --- /dev/null +++ b/keyboards/rubi/config.h @@ -0,0 +1,65 @@ +/* +Copyright 2020 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 . +*/ + +#pragma once + +#include "config_common.h" + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0x4752 +#define PRODUCT_ID 0x5242 +#define DEVICE_VER 0x0001 +#define MANUFACTURER gregorio +#define PRODUCT Rubi + +/* key matrix size */ +#define MATRIX_ROWS 5 +#define MATRIX_COLS 4 + +/* + * Keyboard Matrix Assignments + * + * Change this to how you wired your keyboard + * COLS: AVR pins used for columns, left to right + * ROWS: AVR pins used for rows, top to bottom + * DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode) + * ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode) + * + */ +#define MATRIX_ROW_PINS { F0, F1, F4, F5, F6 } +#define MATRIX_COL_PINS { B3, B2, B1, F7 } +#define UNUSED_PINS + +#define ENCODERS_PAD_A { D7 } +#define ENCODERS_PAD_B { D6 } + +/* COL2ROW, ROW2COL */ +#define DIODE_DIRECTION COL2ROW + +/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ +#define DEBOUNCE 5 + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +#define LOCKING_RESYNC_ENABLE + +/* disable these deprecated features by default */ +#define NO_ACTION_MACRO +#define NO_ACTION_FUNCTION + +#define OLED_FONT_H "lib/glcdfont.c" diff --git a/keyboards/rubi/info.json b/keyboards/rubi/info.json new file mode 100644 index 000000000000..7382394b299c --- /dev/null +++ b/keyboards/rubi/info.json @@ -0,0 +1,58 @@ +{ + "keyboard_name": "Rubi", + "url": "https://github.com/ohchiko/qmk_firmware/tree/master/keyboards/rubi", + "maintainer": "gregorio", + "width": 4, + "height": 5, + "layouts": { + "LAYOUT": { + "layout": [ + [ + { + "x": 3 + }, + "Mute" + ], + [ + { + "y": 0.25 + }, + "Num Lock", + "/", + "*", + "-" + ], + [ + "7\nHome", + "8\n?", + "9\nPgUp", + { + "h": 2 + }, + "+" + ], + [ + "4\n?", + "5", + "6\n?" + ], + [ + "1\nEnd", + "2\n?", + "3\nPgDn", + { + "h": 2 + }, + "Enter" + ], + [ + { + "w": 2 + }, + "0\nIns", + ".\nDel" + ] + ] + } + } +} \ No newline at end of file diff --git a/keyboards/rubi/keymaps/default/keymap.c b/keyboards/rubi/keymaps/default/keymap.c new file mode 100644 index 000000000000..3003db8886d6 --- /dev/null +++ b/keyboards/rubi/keymaps/default/keymap.c @@ -0,0 +1,53 @@ +/* Copyright 2020 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 . + */ +#include QMK_KEYBOARD_H + +// Defines names for use in layer keycodes and the keymap +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* Base */ + [0] = LAYOUT( + ENC_PRESS, + KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, + KC_P7 , KC_P8 , KC_P9 , KC_PPLS, + KC_P4 , KC_P5 , KC_P6 , + KC_P1 , KC_P2 , KC_P3 , KC_PENT, + KC_P0 , LT(2, KC_PDOT) + ), + [1] = LAYOUT( + KC_TRNS, + KC_C , KC_SLSH, CL_STAR, KC_MINS, + KC_7 , KC_8 , KC_9 , CL_PLUS, + KC_4 , KC_5 , KC_6 , + KC_1 , KC_2 , KC_3 , KC_EQL, + KC_0 , KC_DOT + ), + [2] = LAYOUT( + KC_TRNS, + KC_TRNS, KC_N , KC_S , KC_R , + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS + ), + [3] = LAYOUT( + KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, RESET , KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS + ), +}; diff --git a/keyboards/rubi/keymaps/default/readme.md b/keyboards/rubi/keymaps/default/readme.md new file mode 100644 index 000000000000..454d487a0199 --- /dev/null +++ b/keyboards/rubi/keymaps/default/readme.md @@ -0,0 +1,3 @@ +# The default keymap for Rubi + +[Rubi Default Keymap](https://i.imgur.com/bsG8BdW.jpg) diff --git a/keyboards/rubi/keymaps/via/keymap.c b/keyboards/rubi/keymaps/via/keymap.c new file mode 100644 index 000000000000..3003db8886d6 --- /dev/null +++ b/keyboards/rubi/keymaps/via/keymap.c @@ -0,0 +1,53 @@ +/* Copyright 2020 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 . + */ +#include QMK_KEYBOARD_H + +// Defines names for use in layer keycodes and the keymap +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + /* Base */ + [0] = LAYOUT( + ENC_PRESS, + KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, + KC_P7 , KC_P8 , KC_P9 , KC_PPLS, + KC_P4 , KC_P5 , KC_P6 , + KC_P1 , KC_P2 , KC_P3 , KC_PENT, + KC_P0 , LT(2, KC_PDOT) + ), + [1] = LAYOUT( + KC_TRNS, + KC_C , KC_SLSH, CL_STAR, KC_MINS, + KC_7 , KC_8 , KC_9 , CL_PLUS, + KC_4 , KC_5 , KC_6 , + KC_1 , KC_2 , KC_3 , KC_EQL, + KC_0 , KC_DOT + ), + [2] = LAYOUT( + KC_TRNS, + KC_TRNS, KC_N , KC_S , KC_R , + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS + ), + [3] = LAYOUT( + KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, RESET , KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS + ), +}; diff --git a/keyboards/rubi/keymaps/via/rules.mk b/keyboards/rubi/keymaps/via/rules.mk new file mode 100644 index 000000000000..43061db1dd46 --- /dev/null +++ b/keyboards/rubi/keymaps/via/rules.mk @@ -0,0 +1,2 @@ +VIA_ENABLE = yes +LTO_ENABLE = yes \ No newline at end of file diff --git a/keyboards/rubi/lib/calc.c b/keyboards/rubi/lib/calc.c new file mode 100644 index 000000000000..14e59fb274ce --- /dev/null +++ b/keyboards/rubi/lib/calc.c @@ -0,0 +1,259 @@ +/* + Calculator for QMK-based keyboard by MWWorks, https://mwworks.uk + This is free, usual disclaimers, don't use it to calculate megaton yields, surgery plans, etc + + I did not plan to reinvent the wheel for this - I figured surely somebody somewhere has working calculator code? + Found lots but none that actually work like you expect a calculator to, hence DIYing it + + As such, this is probably a bit janky, especially as I am a bit of a hack at C + Seems to be working well, with occasional glitchs, solved by clearing it + And some occasional floating-point issues - eg get a long decimal rather than the whole number you were expecting + Feel free to fix it! I think it needs to detect the precision of the two operands and then figure out what the precision of the result should be + +*/ +#include "rubi.h" + +static uint8_t calc_current_operand = 0; +static char calc_operand_0[CALC_DIGITS+1] = ""; +static char calc_operand_1[CALC_DIGITS+1] = ""; +char calc_result[CALC_DIGITS+1] = ""; +static char calc_status[CALC_DIGITS+1] = ""; +static char calc_operator = ' '; +static bool calc_reset = false; + + +void calcBegin(void){ +} + +//update display +void calcUpdate(void){ + if (calc_display_lines == 2) { + if((calc_current_operand == 1) || (calc_reset)){ + strcpy(calc_status, calc_operand_0); + if((strlen(calc_operand_0)>0) || (strlen(calc_operand_1)>0)){ + uint8_t len = strlen(calc_status); + if (!(calc_operator == 's' || calc_operator == 'r' || calc_operator == 'n')) { + calc_status[len] = calc_operator; + } + calc_status[len+1] = 0; + if(calc_reset + && !(calc_operator == 's' || calc_operator == 'r' || calc_operator == 'n')){ + strncat(calc_status, calc_operand_1, CALC_DIGITS-strlen(calc_status)); + calc_operator = ' '; + } + } + strcpy(calc_status_display, calc_status); + } + } else if (calc_display_lines == 1) { + if(calc_reset + && !(calc_operator == 's' || calc_operator == 'r' || calc_operator == 'n')){ + calc_operator = ' '; + } + } + calc_operator_display = calc_operator; + strcpy(calc_result_display, calc_result); +} + +//perform calculation on the 2 operands +void calcOperands(void){ + float result = 0; + switch (calc_operator){ + + //standard operators + case '+': + result = strtod(calc_operand_0, NULL) + strtod(calc_operand_1, NULL); + break; + + case '-': + result = strtod(calc_operand_0, NULL) - strtod(calc_operand_1, NULL); + break; + + case '/': + result = strtod(calc_operand_0, NULL) / strtod(calc_operand_1, NULL); + break; + + case '*': + result = strtod(calc_operand_0, NULL) * strtod(calc_operand_1, NULL); + break; + + //single operand operators - these are all in 2 + case 's': + result = sqrt(strtod(calc_operand_0, NULL)); + break; + + case 'r': + result = 1/(strtod(calc_operand_0, NULL)); + break; + + } + + //now convert the float result into a string + //we know the total string size but we need to find the size of the integer component to know how much we have for decimals + uint8_t magnitude = ceil(log10(result)); + uint8_t max_decimals = CALC_DIGITS-magnitude-1; + //but max it at 7 because that seems the useful limit of our floats + if(max_decimals>7){ + max_decimals = 7; + } + dtostrf(result, CALC_DIGITS, max_decimals, calc_result); + + //now to clean up the result - we need it clean as it may be the input of next calculation + //this seems a lot of code to format this string :| note that this c doesn't support float in sprintf + uint8_t i; + + //first find if theres a dot + uint8_t dotpos = CALC_DIGITS+1; + for(i=0; i=0){ + for(i=strlen(calc_result)-1; i>=dotpos; i--){ + if((calc_result[i] == '0') || (calc_result[i] == '.')){ + calc_result[i] = 0; + }else{ + break; + } + } + } + + //now find how many leading spaces + uint8_t spaces = 0; + for(i=0; i= 48) && (input <= 57)) || + (input == '.') + ){ + //if this is following an equals, then we start from scratch as if new calculation + if(calc_reset == true){ + calc_reset = false; + calc_current_operand = 0; + calc_operand_0[0] = 0; + calc_operand_1[0] = 0; + operand = calc_operand_0; + len = 0; + } + + if(len0)){ + uint8_t i; + + if(operand[0] == '-'){ + for(i=1; i<=len; i++){ + operand[i-1] = operand[i]; + } + }else if(len0){ + calcOperands(); + } + calc_operand_1[0] = 0; + calc_operator = input; + calcUpdate(); + } + + + }else if(input == '='){ + //only accept = if we are on the second operand + if(calc_current_operand == 1){ + //keep the second operand for a subsequent press of =; but flag to reset if start entry of new operand + calc_reset = true; + calcOperands(); + } + + //single operands - square root and reciprocal - needs to operate on 0 so it works after a previous = result + }else if((input == 's') || (input == 'r')){ + //but maybe we started entering 1 + if(calc_current_operand == 1 && !calc_reset){ + strcpy(calc_operand_0, calc_operand_1); + } + calc_current_operand = 1; + calc_operand_1[0] = 0; + calc_operator = input; + calc_reset = true; //simulate another = + calcOperands(); + + } + +} diff --git a/keyboards/rubi/lib/encoder.c b/keyboards/rubi/lib/encoder.c new file mode 100644 index 000000000000..ed79e93a9413 --- /dev/null +++ b/keyboards/rubi/lib/encoder.c @@ -0,0 +1,98 @@ +#include "rubi.h" + +void change_encoder_mode(bool reverse) { + if (reverse) { + if (encoder_mode == 0) { + encoder_mode = _NUM_ENCODER_MODES - 1; + } else { + encoder_mode = encoder_mode - 1; + } + } else { + encoder_mode = (encoder_mode + 1) % _NUM_ENCODER_MODES; + } +} + +uint16_t handle_encoder_cw(void) { + uint16_t mapped_code = 0; + + if (oled_mode == OLED_MODE_CALC) { + layer_on(2); + return mapped_code; + } + + switch (encoder_mode) { + default: + case ENC_MODE_VOLUME: + mapped_code = KC_VOLU; + break; + case ENC_MODE_MEDIA: + mapped_code = KC_MEDIA_NEXT_TRACK; + break; + case ENC_MODE_BRIGHTNESS: + mapped_code = KC_BRIGHTNESS_UP; + break; + } + + return mapped_code; +} + +uint16_t handle_encoder_ccw(void) { + uint16_t mapped_code = 0; + + if (oled_mode == OLED_MODE_CALC) { + layer_off(2); + return mapped_code; + } + + switch (encoder_mode) { + default: + case ENC_MODE_VOLUME: + mapped_code = KC_VOLD; + break; + case ENC_MODE_MEDIA: + mapped_code = KC_MEDIA_PREV_TRACK; + break; + case ENC_MODE_BRIGHTNESS: + mapped_code = KC_BRIGHTNESS_DOWN; + break; + } + + return mapped_code; +} + +uint16_t handle_encoder_press(void) { + uint16_t mapped_code = 0; + if (current_layer == 1) { + if (oled_mode == OLED_MODE_CALC) { + layer_on(3); + } + layer_off(1); + return mapped_code; + } else if (current_layer == 2) { + if (oled_mode == OLED_MODE_CALC) { + layer_off(1); + layer_on(3); + } else { + layer_on(1); + } + layer_off(2); + return mapped_code; + } else if (current_layer == 3) { + if (oled_mode == OLED_MODE_OFF) { + layer_off(3); + } + return mapped_code; + } + + switch (encoder_mode) { + default: + case ENC_MODE_VOLUME: + mapped_code = KC_MUTE; + break; + case ENC_MODE_MEDIA: + mapped_code = KC_MEDIA_PLAY_PAUSE; + break; + } + + return mapped_code; +} diff --git a/keyboards/rubi/lib/glcdfont.c b/keyboards/rubi/lib/glcdfont.c new file mode 100644 index 000000000000..7551d52f10b1 --- /dev/null +++ b/keyboards/rubi/lib/glcdfont.c @@ -0,0 +1,238 @@ +#pragma once + +#ifdef __AVR__ + #include + #include +#elif defined(ESP8266) + #include +#else + #define PROGMEM +#endif + + +const unsigned char font[] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, + 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, + 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, + 0x18, 0x3C, 0x7E, 0xBC, 0x18, 0x00, + 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, + 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, + 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, + 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, + 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, + 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, + 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, + 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, + 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, + 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, + 0x5A, 0x3C, 0x66, 0x3C, 0x5A, 0x00, + 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, + 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, + 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, + 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, + 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, + 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, + 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, + 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, + 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00, + 0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, + 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, + 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, + 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, + 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, + 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, + 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x5E, 0x00, 0x00, 0x00, + 0x00, 0x06, 0x00, 0x06, 0x00, 0x00, + 0x14, 0x3E, 0x14, 0x3E, 0x14, 0x00, + 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, + 0x26, 0x16, 0x08, 0x34, 0x32, 0x00, + 0x36, 0x4A, 0x56, 0x20, 0x50, 0x00, + 0x00, 0x0A, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x3C, 0x42, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x42, 0x3C, 0x00, 0x00, + 0x14, 0x08, 0x3E, 0x08, 0x14, 0x00, + 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, + 0x00, 0xA0, 0x60, 0x00, 0x00, 0x00, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, + 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, + 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, + 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, + 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, + 0x72, 0x49, 0x49, 0x49, 0x46, 0x00, + 0x21, 0x41, 0x45, 0x45, 0x3B, 0x00, + 0x38, 0x26, 0x21, 0x7F, 0x20, 0x00, + 0x2F, 0x49, 0x49, 0x49, 0x31, 0x00, + 0x3E, 0x49, 0x49, 0x49, 0x31, 0x00, + 0x01, 0x01, 0x61, 0x19, 0x07, 0x00, + 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, + 0x4E, 0x51, 0x51, 0x51, 0x3E, 0x00, + 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x14, 0x22, 0x00, 0x00, + 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, + 0x00, 0x00, 0x22, 0x14, 0x08, 0x00, + 0x00, 0x04, 0x52, 0x0A, 0x04, 0x00, + 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, + 0x7E, 0x09, 0x09, 0x09, 0x7E, 0x00, + 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, + 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, + 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, + 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, + 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, + 0x3E, 0x41, 0x49, 0x49, 0x3A, 0x00, + 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, + 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, + 0x20, 0x41, 0x41, 0x3F, 0x00, 0x00, + 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, + 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, + 0x7F, 0x02, 0x04, 0x02, 0x7F, 0x00, + 0x7F, 0x02, 0x04, 0x08, 0x7F, 0x00, + 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, + 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, + 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, + 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, + 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, + 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, + 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, + 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, + 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, + 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, + 0x07, 0x08, 0x70, 0x08, 0x07, 0x00, + 0x61, 0x51, 0x49, 0x45, 0x43, 0x00, + 0x00, 0x7F, 0x41, 0x41, 0x00, 0x00, + 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, + 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00, + 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, + 0x00, 0x00, 0x06, 0x0A, 0x00, 0x00, + 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, + 0x7E, 0x48, 0x48, 0x48, 0x30, 0x00, + 0x30, 0x48, 0x48, 0x48, 0x48, 0x00, + 0x30, 0x48, 0x48, 0x48, 0x7E, 0x00, + 0x38, 0x54, 0x54, 0x54, 0x58, 0x00, + 0x00, 0x08, 0x7C, 0x0A, 0x00, 0x00, + 0x98, 0xA4, 0xA4, 0xA4, 0x78, 0x00, + 0x7E, 0x08, 0x08, 0x08, 0x70, 0x00, + 0x00, 0x00, 0x7A, 0x00, 0x00, 0x00, + 0x20, 0x40, 0x40, 0x3A, 0x00, 0x00, + 0x7E, 0x10, 0x28, 0x44, 0x00, 0x00, + 0x00, 0x00, 0x7E, 0x40, 0x00, 0x00, + 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00, + 0x7C, 0x04, 0x04, 0x04, 0x78, 0x00, + 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, + 0xFC, 0x24, 0x24, 0x24, 0x18, 0x00, + 0x18, 0x24, 0x24, 0x24, 0xFC, 0x00, + 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00, + 0x48, 0x54, 0x54, 0x54, 0x24, 0x00, + 0x00, 0x04, 0x7E, 0x44, 0x00, 0x00, + 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00, + 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, + 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, + 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, + 0x5C, 0xA0, 0xA0, 0xA0, 0x7C, 0x00, + 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, + 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, + 0x02, 0x01, 0x02, 0x04, 0x02, 0x00, + 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00, + 0x7E, 0xFF, 0x81, 0xFB, 0xF7, 0xEF, + 0x81, 0xFF, 0xC1, 0xBF, 0xBF, 0xBF, + 0xC1, 0xFF, 0x81, 0xFB, 0xF7, 0xFB, + 0x81, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xC3, 0xBD, 0xBD, 0xBD, + 0xDB, 0xFF, 0x83, 0xED, 0xED, 0xED, + 0x83, 0xFF, 0x81, 0xED, 0xED, 0xED, + 0xF3, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xE1, 0xDF, 0xBF, 0xDF, + 0xE1, 0xFF, 0xC3, 0xBD, 0xBD, 0xBD, + 0xC3, 0xFF, 0x81, 0xBF, 0xBF, 0xBF, + 0xBF, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0x81, 0xB5, 0xB5, 0xB5, + 0xCB, 0xFF, 0x81, 0xED, 0xCD, 0xAD, + 0xB3, 0xFF, 0xFD, 0xFD, 0x81, 0xFD, + 0xFD, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xC3, 0xBD, 0xBD, 0xBD, + 0xDB, 0xFF, 0x83, 0xED, 0xED, 0xED, + 0x83, 0xFF, 0x81, 0xBF, 0xBF, 0xBF, + 0xBF, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x08, 0x3E, + 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x6F, 0x5F, 0x63, + 0x7B, 0x7B, 0x3E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x7F, 0x59, 0x6F, + 0x77, 0x7B, 0x3E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x14, 0x08, 0x3E, + 0x08, 0x14, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x08, 0x2A, + 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x7E, 0x04, 0x08, 0x10, + 0x7E, 0x00, 0x3E, 0x40, 0x40, 0x40, + 0x3E, 0x00, 0x7E, 0x04, 0x08, 0x04, + 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, + 0x24, 0x00, 0x7C, 0x12, 0x12, 0x12, + 0x7C, 0x00, 0x7E, 0x12, 0x12, 0x12, + 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0x81, 0xFB, 0xE7, 0xFB, + 0x81, 0xFF, 0x81, 0xB5, 0xB5, 0xB5, + 0xBD, 0xFF, 0x81, 0xBD, 0xBD, 0xBD, + 0xC3, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0x81, 0xB5, 0xB5, 0xB5, + 0xCB, 0xFF, 0x81, 0xEF, 0xF7, 0xEB, + 0x9D, 0xFF, 0x81, 0xBF, 0xBF, 0xBF, + 0xBF, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0x81, 0xED, 0xED, 0xED, + 0xF3, 0xFF, 0x83, 0xED, 0xED, 0xED, + 0x83, 0xFF, 0x81, 0xBD, 0xBD, 0xBD, + 0xC3, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x77, 0x6F, 0x77, + 0x7B, 0x77, 0x3E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x10, 0x08, + 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x77, 0x77, 0x55, + 0x77, 0x77, 0x3E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xB3, 0xAD, 0xAD, 0xAD, + 0xDB, 0xFF, 0xC3, 0xBD, 0xBD, 0xBD, + 0xDB, 0xFF, 0x81, 0xED, 0xCD, 0xAD, + 0xB3, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x20, 0x1C, + 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, + 0x24, 0x00, 0x7C, 0x12, 0x12, 0x12, + 0x7C, 0x00, 0x7E, 0x40, 0x40, 0x40, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x7E, 0x12, 0x12, 0x12, + 0x0C, 0x00, 0x7C, 0x12, 0x12, 0x12, + 0x7C, 0x00, 0x7E, 0x42, 0x42, 0x42, + 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xC3, 0xBD, 0xBD, 0xBD, + 0xC3, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xFF, 0xBB, 0x81, 0xBF, + 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0x9B, 0xAD, 0xAD, 0xAD, + 0xB3, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xDD, 0xBD, 0xB5, 0xB5, + 0xC9, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xE7, 0xEB, 0xED, 0x81, + 0xFF, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x7E, 0xFF, 0xD1, 0xB5, 0xB5, 0xB5, + 0xCD, 0xFF, 0x7E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x77, 0x77, 0x41, + 0x77, 0x77, 0x3E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x77, 0x77, 0x77, + 0x77, 0x77, 0x3E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3E, 0x6B, 0x77, 0x41, + 0x77, 0x6B, 0x3E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x4C, 0x52, 0x52, 0x52, + 0x24, 0x00, 0x3C, 0x42, 0x42, 0x42, + 0x24, 0x00, 0x7E, 0x12, 0x32, 0x52, + 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x26, 0x10, + 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, +}; \ No newline at end of file diff --git a/keyboards/rubi/lib/oled.c b/keyboards/rubi/lib/oled.c new file mode 100644 index 000000000000..3b26155576a7 --- /dev/null +++ b/keyboards/rubi/lib/oled.c @@ -0,0 +1,261 @@ +#include QMK_KEYBOARD_H +#include "./lib/oled.h" + +bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) { + return process_record_user(keycode, record); +} + +void change_oled_mode(void) { + oled_mode = (oled_mode + 1) % _NUM_OLED_MODES; +} + +void render_layer_section(void) { + // Layer indicators + static const char PROGMEM layer_0[] = {0xc8, 0xc9, 0}; + static const char PROGMEM layer_1[] = {0xca, 0xcb, 0}; + static const char PROGMEM layer_2[] = {0xcc, 0xcd, 0}; + static const char PROGMEM layer_3[] = {0xce, 0xcf, 0}; + + oled_set_cursor(oled_max_chars()-15, 0); + oled_write_P(PSTR("LAYER"), false); + switch (current_layer) { + case 0: + oled_write_P(layer_0, false); + break; + case 1: + oled_write_P(layer_1, false); + break; + case 2: + oled_write_P(layer_2, false); + break; + case 3: + oled_write_P(layer_3, false); + break; + default: + oled_write_P(PSTR("? "), false); + break; + } +} + +void render_encoder_section(void) { + static const char PROGMEM enc_vol[] = {0x88, 0x89, 0x8a, 0x8b, 0}; + static const char PROGMEM enc_med[] = {0xa8, 0xa9, 0xaa, 0xab, 0}; + static const char PROGMEM enc_brt[] = {0x8c, 0x8d, 0x8e, 0x8f, 0}; + + oled_set_cursor(oled_max_chars()-7, 0); + oled_write_P(PSTR("ENC"), false); + switch (encoder_mode) { + default: + case ENC_MODE_VOLUME: + oled_write_P(enc_vol, false); + break; + case ENC_MODE_MEDIA: + oled_write_P(enc_med, false); + break; + case ENC_MODE_BRIGHTNESS: + oled_write_P(enc_brt, false); + break; + } +} + +void render_numlock_section(void) { + static const char PROGMEM num_on[] = {0x80, 0x81, 0x82, 0x83, 0}; + static const char PROGMEM num_off[] = {0xa0, 0xa1, 0xa2, 0xa3, 0}; + static const char PROGMEM cap_on[] = {0x84, 0x85, 0x86, 0x87, 0}; + static const char PROGMEM cap_off[] = {0xa4, 0xa5, 0xa6, 0xa7, 0}; + static const char PROGMEM scr_on[] = {0xba, 0xbb, 0xbc, 0xbd, 0}; + static const char PROGMEM scr_off[] = {0xda, 0xdb, 0xdc, 0xdd, 0}; + + led_t led_state = host_keyboard_led_state(); + + oled_set_cursor(oled_max_chars()-12, 3); + // num lock + oled_write_P(led_state.num_lock ? num_on : num_off, false); + oled_write_P(led_state.caps_lock ? cap_on : cap_off, false); + oled_write_P(led_state.scroll_lock ? scr_on : scr_off, false); +} + +void render_mode_section(void) { + static const char PROGMEM pad_on[] = {0xb0, 0xb1, 0xb2, 0xb3, 0}; + static const char PROGMEM pad_off[] = {0xc4, 0xc5, 0xc6, 0xc7, 0}; + static const char PROGMEM cal_on[] = {0x90, 0x91, 0x92, 0x93, 0}; + static const char PROGMEM cal_off[] = {0xc0, 0xc1, 0xc2, 0xc3, 0}; + + if (oled_mode == OLED_MODE_CALC) { + oled_set_cursor(0, 0); + oled_write_P(pad_off, false); + oled_set_cursor(0, 1); + oled_write_P(cal_on, false); + } else { + oled_set_cursor(0, 0); + oled_write_P(pad_on, false); + oled_set_cursor(0, 1); + oled_write_P(cal_off, false); + } +} + +void render_calc_section(void) { + static const char PROGMEM add_on[] = {0xd4, 0xd5, 0}; + static const char PROGMEM add_off[] = {0x94, 0x95, 0}; + static const char PROGMEM sub_on[] = {0xd6, 0xd7, 0}; + static const char PROGMEM sub_off[] = {0x96, 0x97, 0}; + static const char PROGMEM mul_on[] = {0xd8, 0xd9, 0}; + static const char PROGMEM mul_off[] = {0x9c, 0x9d, 0}; + static const char PROGMEM div_on[] = {0xb8, 0xb9, 0}; + static const char PROGMEM div_off[] = {0x9e, 0x9f, 0}; + static const char PROGMEM sqr_on[] = {0x98, 0x99, 0}; + static const char PROGMEM sqr_off[] = {0xbe, 0xbf, 0}; + static const char PROGMEM rec_on[] = {0x9a, 0x9b, 0}; + static const char PROGMEM rec_off[] = {0xde, 0xdf, 0}; + static const char PROGMEM neg_on[] = {0xb4, 0xb5, 0}; + static const char PROGMEM neg_off[] = {0xb6, 0xb7, 0}; + + + if (oled_mode == OLED_MODE_CALC) { + if (current_layer == 1) { + oled_set_cursor(oled_max_chars()-8, 0); + + switch (calc_operator_display) { + case '+': + oled_write_P(div_off, false); + oled_write_P(mul_off, false); + oled_write_P(sub_off, false); + oled_write_P(add_on, false); + break; + case '-': + oled_write_P(div_off, false); + oled_write_P(mul_off, false); + oled_write_P(sub_on, false); + oled_write_P(add_off, false); + break; + case '*': + oled_write_P(div_off, false); + oled_write_P(mul_on, false); + oled_write_P(sub_off, false); + oled_write_P(add_off, false); + break; + case '/': + oled_write_P(div_on, false); + oled_write_P(mul_off, false); + oled_write_P(sub_off, false); + oled_write_P(add_off, false); + break; + case 's': + case 'r': + case 'n': + layer_on(2); + break; + default: + oled_write_P(div_off, false); + oled_write_P(mul_off, false); + oled_write_P(sub_off, false); + oled_write_P(add_off, false); + break; + } + } else if (current_layer == 2) { + oled_set_cursor(oled_max_chars()-6, 0); + + switch (calc_operator_display) { + case '+': + case '-': + case '*': + case '/': + layer_off(2); + break; + case 's': + oled_write_P(neg_off, false); + oled_write_P(sqr_on, false); + oled_write_P(rec_off, false); + break; + case 'r': + oled_write_P(neg_off, false); + oled_write_P(sqr_off, false); + oled_write_P(rec_on, false); + break; + case 'n': + oled_write_P(neg_on, false); + oled_write_P(sqr_off, false); + oled_write_P(rec_off, false); + break; + default: + oled_write_P(neg_off, false); + oled_write_P(sqr_off, false); + oled_write_P(rec_off, false); + break; + } + } + + if (calc_display_lines == 1) { + oled_set_cursor(oled_max_chars()-strlen(calc_result_display)-2, 3); + oled_write_char(calc_operator_display, false); + } else if (calc_display_lines == 2) { + oled_set_cursor(oled_max_chars()-strlen(calc_status_display), 2); + oled_write(calc_status_display, false); + } + oled_set_cursor(oled_max_chars()-strlen(calc_result_display), 3); + oled_write(calc_result_display, false); + } +} + +static void render_logo(void) { + oled_write_raw_P(raw_logo, sizeof(raw_logo)); +} + +void render_frame(void) { + if (oled_logo_expired) { + if (oled_mode == OLED_MODE_DEFAULT) { + render_mode_section(); + render_layer_section(); + render_encoder_section(); + render_numlock_section(); + } else if (oled_mode == OLED_MODE_CALC) { + render_mode_section(); + render_calc_section(); + } else if (oled_mode == OLED_MODE_OFF) { + if (is_oled_on()) { + oled_off(); + } + } + } else { + render_logo(); + oled_logo_expired = timer_elapsed(oled_logo_timer) > OLED_LOGO_TIMEOUT; + } +} + +void oled_task_user(void) { + // re-render oled and reset timer if it's time for the next frame + //if (oled_mode == OLED_MODE_DEFAULT) { + // if (timer_elapsed32(oled_sleep_timer) > OLED_SLEEP_TIMEOUT) { + // oled_off(); + // return; + // } else { + // oled_on(); + // } + //} + + if (timer_elapsed(oled_frame_timer) > OLED_FRAME_TIMEOUT) { + oled_clear(); + oled_frame_timer = timer_read(); + render_frame(); + } + + if (current_layer == 1) { + oled_mode = OLED_MODE_CALC; + } else if (current_layer == 2) { + if (IS_LAYER_ON(1)) { + oled_mode = OLED_MODE_CALC; + } else { + oled_mode = OLED_MODE_DEFAULT; + } + } else if (current_layer == 3) { + oled_mode = OLED_MODE_OFF; + } else { + oled_mode = OLED_MODE_DEFAULT; + } +} + +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + oled_logo_timer = timer_read(); + oled_frame_timer = timer_read(); + return rotation; +} diff --git a/keyboards/rubi/lib/oled.h b/keyboards/rubi/lib/oled.h new file mode 100644 index 000000000000..7b4e91fb20cf --- /dev/null +++ b/keyboards/rubi/lib/oled.h @@ -0,0 +1,17 @@ +#pragma once + +#define OLED_FRAME_TIMEOUT (1000 / 30) // 30 fps +//#define OLED_SLEEP_TIMEOUT 60000 // 60 sec +#define OLED_LOGO_TIMEOUT 3000 // 3 sec + +static uint16_t oled_frame_timer = 0; +//static uint32_t oled_sleep_timer = 0; +static uint16_t oled_logo_timer = 0; +static bool oled_logo_expired = false; + +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,128,128,128,128,128,128, 0, 0, 0, 0, 0, 0, 0,128,128,128,128,128,128,128,128,128,128,128, 0, 0, 0, 0, 0, 0,128,128,128,128, 0, 0, 0, 0, 0, 0,128,128,128,128, 0, 0,128,128,128,128,128,128,128,128,128,128,128, 0, 0, 0, 0, 0,128,128,128,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 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,224,112,184,220,204,182,123,254,251,187,223,231,203,126,254, 0, 0, 0, 0, 0, 0,255, 0, 0, 0,248, 8, 8, 8, 8, 8,249,225, 2, 12,248, 0, 0,255,255,255,255, 0, 0, 0, 0, 0, 0,255,255,255,255, 0, 0,255,255,255,255,199,199,199,199,199,207,255,255,254,124, 0, 0,255,255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,127,191,188,211,223,223,247,187,187,252,126,123,247,239,223,190,115,142, 0, 0, 0, 0, 0,255, 0, 0, 0,227, 34, 34, 34, 98,194, 1, 56,236,135, 1, 0, 0, 31, 63,127,255,248,240,240,240,240,248,255,127, 63, 31, 0, 0,255,255,255,255,227,227,227,227,227,243,255,255,127, 62, 0, 0,255,255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; diff --git a/keyboards/rubi/readme.md b/keyboards/rubi/readme.md new file mode 100644 index 000000000000..7c8f154db576 --- /dev/null +++ b/keyboards/rubi/readme.md @@ -0,0 +1,19 @@ +# Rubi + +![Rubi](https://i.imgur.com/Mi3nCpc.jpeg) + +A 4x5 layout numpad with rotary encoder, LED indicator and OLED screen, featuring a basic calculator inside the OLED screen. The PCB supports both hotswap and solderable switch. Currently the PCB and case can only be purchased in Indonesia. + +* Keyboard Maintainer: [ohchiko](https://github.com/ohchiko) +* Hardware Supported: Rubi PCB Rev. A, ATMega32u4 +* Hardware Availability: [Tokopedia](https://tokopedia.com) (Indonesia only) or any electronic part store. + +Make example for this keyboard (after setting up your build environment): + + make rubi:default + +Flashing example for this keyboard: + + make rubi:default:flash + +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). diff --git a/keyboards/rubi/rubi.c b/keyboards/rubi/rubi.c new file mode 100644 index 000000000000..c317244796d8 --- /dev/null +++ b/keyboards/rubi/rubi.c @@ -0,0 +1,111 @@ +/* Copyright 2020 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 . + */ +#include "rubi.h" + +uint8_t current_layer = 0; +bool mod_shift = false; +bool mod_control = false; +bool mod_alt = false; +bool mod_gui = false; + +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); +} + +layer_state_t layer_state_set_kb(layer_state_t state) { + current_layer = get_highest_layer(state); + return state; +} + +bool led_update_kb(led_t led_state) { + writePin(C6, led_state.num_lock); + return true; +} + +void encoder_update_kb(uint8_t index, bool clockwise) { + if (index == 0) { + if (current_layer == 0) { + uint16_t mapped_code = 0; + if (clockwise) { + mapped_code = handle_encoder_cw(); + } else { + mapped_code = handle_encoder_ccw(); + } + if (mapped_code != 0) { + tap_code16(mapped_code); + } + } else { + if (clockwise) { + if (oled_mode == OLED_MODE_CALC) { + handle_encoder_cw(); + } else if (oled_mode == OLED_MODE_DEFAULT) { + change_encoder_mode(false); + } + } else { + if (oled_mode == OLED_MODE_CALC) { + handle_encoder_ccw(); + } else if (oled_mode == OLED_MODE_DEFAULT) { + change_encoder_mode(true); + } + } + } + } +} diff --git a/keyboards/rubi/rubi.h b/keyboards/rubi/rubi.h new file mode 100644 index 000000000000..6a24dd1c7b67 --- /dev/null +++ b/keyboards/rubi/rubi.h @@ -0,0 +1,101 @@ +/* Copyright 2020 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 . + */ +#pragma once + +#include "quantum.h" + +#define CALC_DIGITS 12 + +enum rubi_keycodes { + ENC_PRESS = SAFE_RANGE, + CL_PLUS, + CL_STAR, + CL_TYPE +}; + +enum oled_modes { + OLED_MODE_DEFAULT, + OLED_MODE_CALC, + OLED_MODE_OFF, + _NUM_OLED_MODES +}; + +enum encoder_modes { + ENC_MODE_VOLUME, + ENC_MODE_MEDIA, + ENC_MODE_BRIGHTNESS, + _NUM_ENCODER_MODES +}; + +extern uint8_t current_layer; +extern uint8_t oled_mode; +extern uint8_t encoder_mode; + +extern char calc_result_display[CALC_DIGITS+1]; +extern char calc_operator_display; +extern char calc_status_display[CALC_DIGITS+1]; +extern uint8_t calc_display_lines; + +bool process_record_user_oled(uint16_t keycode, keyrecord_t *record); +void change_oled_mode(void); + +void change_encoder_mode(bool reverse); +uint16_t handle_encoder_cw(void); +uint16_t handle_encoder_ccw(void); +uint16_t handle_encoder_press(void); + +void calcUpdate(void); +void calcInput(char input); +void calcOperands(void); + +/* This is a shortcut to help you visually see your layout. + * + * The first section contains all of the arguments representing the physical + * layout of the board and position of the keys. + * + * The second converts the arguments into a two-dimensional array which + * represents the switch matrix. + */ + +/* Rubi matrix layout + * ,---------------. + * | 23| + * |---------------| + * | 00| 01| 02| 03| + * |---------------| + * | 10| 11| 12| | + * |-----------| 13| + * | 20| 21| 22| | + * |---------------| + * | 30| 31| 32| | + * |-----------| 33| + * | 41 | 42| | + * `---------------' + */ +#define LAYOUT( \ + k23, \ + k00, k01, k02, k03, \ + k10, k11, k12, k13, \ + k20, k21, k22, \ + k30, k31, k32, k33, \ + k41, k42 \ +) { \ + { k00, k01, k02, k03 }, \ + { k10, k11, k12, k13 }, \ + { k20, k21, k22, k23 }, \ + { k30, k31, k32, k33 }, \ + { KC_NO, k41, k42, KC_NO } \ +} diff --git a/keyboards/rubi/rules.mk b/keyboards/rubi/rules.mk new file mode 100644 index 000000000000..02fd354b2602 --- /dev/null +++ b/keyboards/rubi/rules.mk @@ -0,0 +1,28 @@ +# MCU name +MCU = atmega32u4 + +# Bootloader selection +BOOTLOADER = atmel-dfu # change this to `atmel-dfu` for production + +# Build Options +# change yes to no to disable +# +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration +MOUSEKEY_ENABLE = no # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = no # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration +# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE +SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend +# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work +NKRO_ENABLE = yes # USB Nkey Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow +BLUETOOTH_ENABLE = no # Enable Bluetooth +AUDIO_ENABLE = no # Audio output +OLED_DRIVER_ENABLE = yes +ENCODER_ENABLE = yes + +SRC += lib/oled.c \ + lib/encoder.c \ + lib/calc.c From 35081f54e133a38c8ca573ea02d71be1382ac348 Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Date: Thu, 18 Mar 2021 23:23:49 +0700 Subject: [PATCH 2/7] update license --- keyboards/rubi/config.h | 2 +- keyboards/rubi/info.json | 63 ++++++++++------------------------- keyboards/rubi/lib/calc.c | 2 ++ keyboards/rubi/lib/encoder.c | 17 ++++++++++ keyboards/rubi/lib/glcdfont.c | 19 ++++++++++- keyboards/rubi/lib/oled.c | 17 ++++++++++ keyboards/rubi/lib/oled.h | 17 ++++++++++ keyboards/rubi/readme.md | 8 +++-- keyboards/rubi/rubi.c | 6 +--- keyboards/rubi/rubi.h | 2 +- 10 files changed, 98 insertions(+), 55 deletions(-) diff --git a/keyboards/rubi/config.h b/keyboards/rubi/config.h index b22e20cbb34e..5b6b1c4531ad 100644 --- a/keyboards/rubi/config.h +++ b/keyboards/rubi/config.h @@ -1,5 +1,5 @@ /* -Copyright 2020 gregorio +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 diff --git a/keyboards/rubi/info.json b/keyboards/rubi/info.json index 7382394b299c..72b6242fcd8a 100644 --- a/keyboards/rubi/info.json +++ b/keyboards/rubi/info.json @@ -7,51 +7,24 @@ "layouts": { "LAYOUT": { "layout": [ - [ - { - "x": 3 - }, - "Mute" - ], - [ - { - "y": 0.25 - }, - "Num Lock", - "/", - "*", - "-" - ], - [ - "7\nHome", - "8\n?", - "9\nPgUp", - { - "h": 2 - }, - "+" - ], - [ - "4\n?", - "5", - "6\n?" - ], - [ - "1\nEnd", - "2\n?", - "3\nPgDn", - { - "h": 2 - }, - "Enter" - ], - [ - { - "w": 2 - }, - "0\nIns", - ".\nDel" - ] + {"x":3, "y":0}, + {"x":0, "y":1.25}, + {"x":1, "y":1.25}, + {"x":2, "y":1.25}, + {"x":3, "y":1.25}, + {"x":0, "y":2.25}, + {"x":1, "y":2.25}, + {"x":2, "y":2.25}, + {"x":3, "y":2.25, "h":2}, + {"x":0, "y":3.25}, + {"x":1, "y":3.25}, + {"x":2, "y":3.25}, + {"x":0, "y":4.25}, + {"x":1, "y":4.25}, + {"x":2, "y":4.25}, + {"x":3, "y":4.25, "h":2}, + {"x":0, "y":5.25, "w":2}, + {"x":2, "y":5.25} ] } } diff --git a/keyboards/rubi/lib/calc.c b/keyboards/rubi/lib/calc.c index 14e59fb274ce..7796a9be4516 100644 --- a/keyboards/rubi/lib/calc.c +++ b/keyboards/rubi/lib/calc.c @@ -1,4 +1,6 @@ /* +This is the modified version of [calculator by MWWorks](https://github.com/MWWorks/mw_calc_numpad/blob/master/calc.c). Below is the quote from [MWWorks](https://github.com/MWWorks). + Calculator for QMK-based keyboard by MWWorks, https://mwworks.uk This is free, usual disclaimers, don't use it to calculate megaton yields, surgery plans, etc diff --git a/keyboards/rubi/lib/encoder.c b/keyboards/rubi/lib/encoder.c index ed79e93a9413..43c20d3acab1 100644 --- a/keyboards/rubi/lib/encoder.c +++ b/keyboards/rubi/lib/encoder.c @@ -1,3 +1,20 @@ +/* +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 . +*/ + #include "rubi.h" void change_encoder_mode(bool reverse) { diff --git a/keyboards/rubi/lib/glcdfont.c b/keyboards/rubi/lib/glcdfont.c index 7551d52f10b1..0894c654f232 100644 --- a/keyboards/rubi/lib/glcdfont.c +++ b/keyboards/rubi/lib/glcdfont.c @@ -1,3 +1,20 @@ +/* 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 . + */ +#pragma once + #pragma once #ifdef __AVR__ @@ -235,4 +252,4 @@ const unsigned char font[] PROGMEM = { 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, -}; \ No newline at end of file +}; diff --git a/keyboards/rubi/lib/oled.c b/keyboards/rubi/lib/oled.c index 3b26155576a7..a17c9420c395 100644 --- a/keyboards/rubi/lib/oled.c +++ b/keyboards/rubi/lib/oled.c @@ -1,3 +1,20 @@ +/* +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 . +*/ + #include QMK_KEYBOARD_H #include "./lib/oled.h" diff --git a/keyboards/rubi/lib/oled.h b/keyboards/rubi/lib/oled.h index 7b4e91fb20cf..9e622a6fa735 100644 --- a/keyboards/rubi/lib/oled.h +++ b/keyboards/rubi/lib/oled.h @@ -1,3 +1,20 @@ +/* +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 . +*/ + #pragma once #define OLED_FRAME_TIMEOUT (1000 / 30) // 30 fps diff --git a/keyboards/rubi/readme.md b/keyboards/rubi/readme.md index 7c8f154db576..703346802995 100644 --- a/keyboards/rubi/readme.md +++ b/keyboards/rubi/readme.md @@ -1,12 +1,14 @@ # Rubi -![Rubi](https://i.imgur.com/Mi3nCpc.jpeg) +![Rubi](https://i.imgur.com/Mi3nCpcm.jpeg) + +![Proto Album](https://imgur.com/a/QVtU7hV) A 4x5 layout numpad with rotary encoder, LED indicator and OLED screen, featuring a basic calculator inside the OLED screen. The PCB supports both hotswap and solderable switch. Currently the PCB and case can only be purchased in Indonesia. * Keyboard Maintainer: [ohchiko](https://github.com/ohchiko) * Hardware Supported: Rubi PCB Rev. A, ATMega32u4 -* Hardware Availability: [Tokopedia](https://tokopedia.com) (Indonesia only) or any electronic part store. +* Hardware Availability: Local Indonesia GB. Make example for this keyboard (after setting up your build environment): @@ -16,4 +18,6 @@ Flashing example for this keyboard: make rubi:default:flash +To put this keyboard into bootloader mode (for flashing firmware), simply activate layer 3 and press the middle key (key "5" on the proto picture) on the default keymap. + See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). diff --git a/keyboards/rubi/rubi.c b/keyboards/rubi/rubi.c index c317244796d8..b3a44dcca785 100644 --- a/keyboards/rubi/rubi.c +++ b/keyboards/rubi/rubi.c @@ -1,4 +1,4 @@ -/* Copyright 2020 gregorio +/* 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 @@ -16,10 +16,6 @@ #include "rubi.h" uint8_t current_layer = 0; -bool mod_shift = false; -bool mod_control = false; -bool mod_alt = false; -bool mod_gui = false; uint8_t oled_mode = OLED_MODE_DEFAULT; diff --git a/keyboards/rubi/rubi.h b/keyboards/rubi/rubi.h index 6a24dd1c7b67..b05e63bcb6f5 100644 --- a/keyboards/rubi/rubi.h +++ b/keyboards/rubi/rubi.h @@ -1,4 +1,4 @@ -/* Copyright 2020 gregorio +/* 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 From 1cf3e0941f177d98f1e364f29acf9c7396163831 Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Date: Fri, 19 Mar 2021 10:46:57 +0700 Subject: [PATCH 3/7] updated readme files --- keyboards/rubi/keymaps/default/readme.md | 3 ++- keyboards/rubi/readme.md | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/keyboards/rubi/keymaps/default/readme.md b/keyboards/rubi/keymaps/default/readme.md index 454d487a0199..1e7cbc85f45d 100644 --- a/keyboards/rubi/keymaps/default/readme.md +++ b/keyboards/rubi/keymaps/default/readme.md @@ -1,3 +1,4 @@ # The default keymap for Rubi -[Rubi Default Keymap](https://i.imgur.com/bsG8BdW.jpg) +[KLE](http://www.keyboard-layout-editor.com/#/gists/984e9039971cf4738d507150b4494190) +![Rubi Default Keymap](https://i.imgur.com/bsG8BdW.jpg) diff --git a/keyboards/rubi/readme.md b/keyboards/rubi/readme.md index 703346802995..8004c00f25d7 100644 --- a/keyboards/rubi/readme.md +++ b/keyboards/rubi/readme.md @@ -1,6 +1,6 @@ # Rubi -![Rubi](https://i.imgur.com/Mi3nCpcm.jpeg) +![Rubi](https://i.imgur.com/XUzxe0r.jpg) ![Proto Album](https://imgur.com/a/QVtU7hV) @@ -20,4 +20,6 @@ Flashing example for this keyboard: To put this keyboard into bootloader mode (for flashing firmware), simply activate layer 3 and press the middle key (key "5" on the proto picture) on the default keymap. +![Default Keymap](keymaps/default/readme.md) + See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). From aa7174911fcdcf5167c8ef77589187675d2acfbc Mon Sep 17 00:00:00 2001 From: Gregorio <38576492+ohchiko@users.noreply.github.com> Date: Sat, 3 Apr 2021 12:04:09 +0700 Subject: [PATCH 4/7] Update keyboards/rubi/lib/glcdfont.c Co-authored-by: Drashna Jaelre --- keyboards/rubi/lib/glcdfont.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/keyboards/rubi/lib/glcdfont.c b/keyboards/rubi/lib/glcdfont.c index 0894c654f232..1a83ed3edc06 100644 --- a/keyboards/rubi/lib/glcdfont.c +++ b/keyboards/rubi/lib/glcdfont.c @@ -15,16 +15,7 @@ */ #pragma once -#pragma once - -#ifdef __AVR__ - #include - #include -#elif defined(ESP8266) - #include -#else - #define PROGMEM -#endif +#include "progmem.h" const unsigned char font[] PROGMEM = { From 9cf41ee489b38ce8e1e07a85ac57f20674a23488 Mon Sep 17 00:00:00 2001 From: Gregorio Chiko Date: Tue, 18 May 2021 21:25:51 +0700 Subject: [PATCH 5/7] implement call for user functions --- keyboards/rubi/lib/encoder.c | 6 +++--- keyboards/rubi/lib/oled.c | 22 ++++++---------------- keyboards/rubi/lib/oled.h | 2 -- keyboards/rubi/rubi.c | 18 +++++++++++------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/keyboards/rubi/lib/encoder.c b/keyboards/rubi/lib/encoder.c index 43c20d3acab1..06c25ad3175f 100644 --- a/keyboards/rubi/lib/encoder.c +++ b/keyboards/rubi/lib/encoder.c @@ -79,13 +79,13 @@ uint16_t handle_encoder_ccw(void) { uint16_t handle_encoder_press(void) { uint16_t mapped_code = 0; - if (current_layer == 1) { + if (get_highest_layer(layer_state) == 1) { if (oled_mode == OLED_MODE_CALC) { layer_on(3); } layer_off(1); return mapped_code; - } else if (current_layer == 2) { + } else if (get_highest_layer(layer_state) == 2) { if (oled_mode == OLED_MODE_CALC) { layer_off(1); layer_on(3); @@ -94,7 +94,7 @@ uint16_t handle_encoder_press(void) { } layer_off(2); return mapped_code; - } else if (current_layer == 3) { + } else if (get_highest_layer(layer_state) == 3) { if (oled_mode == OLED_MODE_OFF) { layer_off(3); } diff --git a/keyboards/rubi/lib/oled.c b/keyboards/rubi/lib/oled.c index a17c9420c395..03c364d9a4de 100644 --- a/keyboards/rubi/lib/oled.c +++ b/keyboards/rubi/lib/oled.c @@ -35,7 +35,7 @@ void render_layer_section(void) { oled_set_cursor(oled_max_chars()-15, 0); oled_write_P(PSTR("LAYER"), false); - switch (current_layer) { + switch (get_highest_layer(layer_state)) { case 0: oled_write_P(layer_0, false); break; @@ -129,7 +129,7 @@ void render_calc_section(void) { if (oled_mode == OLED_MODE_CALC) { - if (current_layer == 1) { + if (get_highest_layer(layer_state) == 1) { oled_set_cursor(oled_max_chars()-8, 0); switch (calc_operator_display) { @@ -169,7 +169,7 @@ void render_calc_section(void) { oled_write_P(add_off, false); break; } - } else if (current_layer == 2) { + } else if (get_highest_layer(layer_state) == 2) { oled_set_cursor(oled_max_chars()-6, 0); switch (calc_operator_display) { @@ -240,31 +240,21 @@ void render_frame(void) { } void oled_task_user(void) { - // re-render oled and reset timer if it's time for the next frame - //if (oled_mode == OLED_MODE_DEFAULT) { - // if (timer_elapsed32(oled_sleep_timer) > OLED_SLEEP_TIMEOUT) { - // oled_off(); - // return; - // } else { - // oled_on(); - // } - //} - if (timer_elapsed(oled_frame_timer) > OLED_FRAME_TIMEOUT) { oled_clear(); oled_frame_timer = timer_read(); render_frame(); } - if (current_layer == 1) { + if (get_highest_layer(layer_state) == 1) { oled_mode = OLED_MODE_CALC; - } else if (current_layer == 2) { + } else if (get_highest_layer(layer_state) == 2) { if (IS_LAYER_ON(1)) { oled_mode = OLED_MODE_CALC; } else { oled_mode = OLED_MODE_DEFAULT; } - } else if (current_layer == 3) { + } else if (get_highest_layer(layer_state) == 3) { oled_mode = OLED_MODE_OFF; } else { oled_mode = OLED_MODE_DEFAULT; diff --git a/keyboards/rubi/lib/oled.h b/keyboards/rubi/lib/oled.h index 9e622a6fa735..1737541c96c0 100644 --- a/keyboards/rubi/lib/oled.h +++ b/keyboards/rubi/lib/oled.h @@ -18,11 +18,9 @@ along with this program. If not, see . #pragma once #define OLED_FRAME_TIMEOUT (1000 / 30) // 30 fps -//#define OLED_SLEEP_TIMEOUT 60000 // 60 sec #define OLED_LOGO_TIMEOUT 3000 // 3 sec static uint16_t oled_frame_timer = 0; -//static uint32_t oled_sleep_timer = 0; static uint16_t oled_logo_timer = 0; static bool oled_logo_expired = false; diff --git a/keyboards/rubi/rubi.c b/keyboards/rubi/rubi.c index b3a44dcca785..7f387d7c0f3c 100644 --- a/keyboards/rubi/rubi.c +++ b/keyboards/rubi/rubi.c @@ -15,8 +15,6 @@ */ #include "rubi.h" -uint8_t current_layer = 0; - uint8_t oled_mode = OLED_MODE_DEFAULT; char calc_result_display[CALC_DIGITS+1] = ""; @@ -67,18 +65,20 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { } layer_state_t layer_state_set_kb(layer_state_t state) { - current_layer = get_highest_layer(state); - return state; + return layer_state_set_user(state); } bool led_update_kb(led_t led_state) { - writePin(C6, led_state.num_lock); + bool res = led_update_user(led_state); + if (res) { + writePin(C6, led_state.num_lock); + } return true; } -void encoder_update_kb(uint8_t index, bool clockwise) { +__attribute__ ((weak)) void encoder_update_user(uint8_t index, bool clockwise) { if (index == 0) { - if (current_layer == 0) { + if (get_highest_layer(layer_state) == 0) { uint16_t mapped_code = 0; if (clockwise) { mapped_code = handle_encoder_cw(); @@ -105,3 +105,7 @@ void encoder_update_kb(uint8_t index, bool clockwise) { } } } + +void encoder_update_kb(uint8_t index, bool clockwise) { + encoder_update_user(index, clockwise); +} From 37803ea4378f842bf0ed79702dddda04a5bb4adb Mon Sep 17 00:00:00 2001 From: Gregorio <38576492+ohchiko@users.noreply.github.com> Date: Wed, 19 May 2021 02:46:59 +0700 Subject: [PATCH 6/7] Apply suggestions from code review - add placeholder for custom keycodes for user implementation - define weak attribute for `oled_task_user` function - remove unnecessary `layer_state_set_kb` function - add enum value `NEW_SAFE_RANGE` for custom keycodes Co-authored-by: Drashna Jaelre --- keyboards/rubi/keymaps/default/keymap.c | 5 +++++ keyboards/rubi/lib/oled.c | 2 +- keyboards/rubi/rubi.c | 3 --- keyboards/rubi/rubi.h | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/keyboards/rubi/keymaps/default/keymap.c b/keyboards/rubi/keymaps/default/keymap.c index 3003db8886d6..054e3ce2324f 100644 --- a/keyboards/rubi/keymaps/default/keymap.c +++ b/keyboards/rubi/keymaps/default/keymap.c @@ -15,6 +15,11 @@ */ #include QMK_KEYBOARD_H + +// enum custom_keycodes { +// FIRST = NEW_SAFE_RANGE, +// }; + // Defines names for use in layer keycodes and the keymap const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Base */ diff --git a/keyboards/rubi/lib/oled.c b/keyboards/rubi/lib/oled.c index 03c364d9a4de..d48d27323c63 100644 --- a/keyboards/rubi/lib/oled.c +++ b/keyboards/rubi/lib/oled.c @@ -239,7 +239,7 @@ void render_frame(void) { } } -void oled_task_user(void) { +__attribute__((weak)) void oled_task_user(void) { if (timer_elapsed(oled_frame_timer) > OLED_FRAME_TIMEOUT) { oled_clear(); oled_frame_timer = timer_read(); diff --git a/keyboards/rubi/rubi.c b/keyboards/rubi/rubi.c index 7f387d7c0f3c..6cdf8302c18f 100644 --- a/keyboards/rubi/rubi.c +++ b/keyboards/rubi/rubi.c @@ -64,9 +64,6 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user_oled(keycode, record); } -layer_state_t layer_state_set_kb(layer_state_t state) { - return layer_state_set_user(state); -} bool led_update_kb(led_t led_state) { bool res = led_update_user(led_state); diff --git a/keyboards/rubi/rubi.h b/keyboards/rubi/rubi.h index b05e63bcb6f5..472ce8e000c9 100644 --- a/keyboards/rubi/rubi.h +++ b/keyboards/rubi/rubi.h @@ -23,7 +23,8 @@ enum rubi_keycodes { ENC_PRESS = SAFE_RANGE, CL_PLUS, CL_STAR, - CL_TYPE + CL_TYPE, + NEW_SAFE_RANGE }; enum oled_modes { From 4365cc1641c7fd6b9980a9022e93b65587d4dd0b Mon Sep 17 00:00:00 2001 From: Gregorio <38576492+ohchiko@users.noreply.github.com> Date: Fri, 28 May 2021 12:17:12 +0700 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Ryan --- keyboards/rubi/readme.md | 6 ++---- keyboards/rubi/rules.mk | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/keyboards/rubi/readme.md b/keyboards/rubi/readme.md index 8004c00f25d7..b46487cfb914 100644 --- a/keyboards/rubi/readme.md +++ b/keyboards/rubi/readme.md @@ -1,8 +1,8 @@ # Rubi -![Rubi](https://i.imgur.com/XUzxe0r.jpg) +![Rubi](https://i.imgur.com/XUzxe0rh.jpg) -![Proto Album](https://imgur.com/a/QVtU7hV) +[Proto Album](https://imgur.com/a/QVtU7hV) A 4x5 layout numpad with rotary encoder, LED indicator and OLED screen, featuring a basic calculator inside the OLED screen. The PCB supports both hotswap and solderable switch. Currently the PCB and case can only be purchased in Indonesia. @@ -20,6 +20,4 @@ Flashing example for this keyboard: To put this keyboard into bootloader mode (for flashing firmware), simply activate layer 3 and press the middle key (key "5" on the proto picture) on the default keymap. -![Default Keymap](keymaps/default/readme.md) - See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). diff --git a/keyboards/rubi/rules.mk b/keyboards/rubi/rules.mk index 02fd354b2602..59ba4ffa1971 100644 --- a/keyboards/rubi/rules.mk +++ b/keyboards/rubi/rules.mk @@ -2,20 +2,20 @@ MCU = atmega32u4 # Bootloader selection -BOOTLOADER = atmel-dfu # change this to `atmel-dfu` for production +BOOTLOADER = atmel-dfu # Build Options # change yes to no to disable # -BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration -MOUSEKEY_ENABLE = no # Mouse keys +BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration +MOUSEKEY_ENABLE = no # Mouse keys EXTRAKEY_ENABLE = yes # Audio control and System control CONSOLE_ENABLE = no # Console for debug COMMAND_ENABLE = no # Commands for debug and configuration # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend # if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work -NKRO_ENABLE = yes # USB Nkey Rollover +NKRO_ENABLE = yes # USB Nkey Rollover BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow BLUETOOTH_ENABLE = no # Enable Bluetooth