153 lines
4.6 KiB
C
153 lines
4.6 KiB
C
#include QMK_KEYBOARD_H
|
|
#include "version.h"
|
|
|
|
extern void sethsv(uint8_t hue, uint8_t sat, uint8_t val, int index);
|
|
|
|
static bool backlight;
|
|
static uint16_t timer;
|
|
static uint8_t hue_left, hue_right;
|
|
static uint8_t brightness_left, brightness_right;
|
|
static uint8_t count_left, count_right;
|
|
static uint8_t position_left, position_right;
|
|
|
|
static const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|
[0] = LAYOUT_ergodox(
|
|
QK_BOOT, KC_1, KC_2, KC_3, KC_4, KC_5, KC_NO,
|
|
KC_GRAVE, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_EQUAL,
|
|
KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G,
|
|
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LBRC,
|
|
KC_LCTL, KC_LALT, MO(1), KC_NO, KC_LCMD,
|
|
KC_NO, KC_NO, KC_NO, KC_SPACE, KC_ESC, KC_UNDS,
|
|
|
|
KC_NO, KC_6, KC_7, KC_8, KC_9, KC_0, PB_1,
|
|
KC_MINS, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
|
|
KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOTE,
|
|
KC_RBRC, KC_N, KC_M, KC_COMMA, KC_DOT, KC_SLASH, KC_RSFT,
|
|
KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, KC_RCTL,
|
|
KC_NO, KC_DEL, KC_NO, PB_2, KC_BSPC, KC_ENTER
|
|
),
|
|
[1] = LAYOUT_ergodox(
|
|
KC_NO, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F11,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
|
|
KC_F12, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
|
|
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO
|
|
),
|
|
};
|
|
|
|
static void color(uint8_t hue, uint8_t brightness, uint8_t position,
|
|
uint8_t index)
|
|
{
|
|
for (int i = index; i < (index + 15); ++i) {
|
|
const uint32_t cube = (uint32_t)brightness * brightness * brightness;
|
|
const uint8_t distance = position > i ? position - i : i - position;
|
|
sethsv(hue, 255, cube / 65025 * 5 / (5 + distance), i);
|
|
}
|
|
rgblight_set();
|
|
}
|
|
|
|
bool process_record_user(uint16_t keycode, keyrecord_t *record)
|
|
{
|
|
static uint16_t last_keycode = KC_NO;
|
|
|
|
if (record->event.key.row < 7) {
|
|
count_left += record->event.pressed ? 1 : -1;
|
|
} else {
|
|
count_right += record->event.pressed ? 1 : -1;
|
|
}
|
|
|
|
if (!record->event.pressed) {
|
|
return true;
|
|
}
|
|
|
|
switch (keycode) {
|
|
case PB_1:
|
|
backlight = !backlight;
|
|
break;
|
|
case PB_2:
|
|
SEND_STRING(SS_TAP(X_MINUS) SS_LSFT(SS_TAP(X_DOT)));
|
|
break;
|
|
case KC_BSPC:
|
|
if (last_keycode == PB_2) {
|
|
unregister_code(KC_BSPC);
|
|
register_code(KC_BSPC);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
last_keycode = keycode;
|
|
return true;
|
|
}
|
|
|
|
void post_process_record_user(uint16_t keycode, keyrecord_t *record)
|
|
{
|
|
if (!backlight || !record->event.pressed) {
|
|
return;
|
|
}
|
|
|
|
if (record->event.key.row < 7) {
|
|
hue_left = rand();
|
|
brightness_left = 255;
|
|
|
|
if (record->event.key.col != 5) {
|
|
position_left = 29 - 2 * record->event.key.row;
|
|
} else {
|
|
position_left = 15;
|
|
}
|
|
|
|
color(hue_left, brightness_left, position_left, 15);
|
|
} else {
|
|
hue_right = rand();
|
|
brightness_right = 255;
|
|
|
|
if (record->event.key.col != 5) {
|
|
position_right = 26 - 2 * record->event.key.row;
|
|
} else {
|
|
position_right = 14;
|
|
}
|
|
|
|
color(hue_right, brightness_right, position_right, 0);
|
|
}
|
|
|
|
}
|
|
|
|
void keyboard_post_init_user(void)
|
|
{
|
|
rgblight_enable_noeeprom();
|
|
rgblight_sethsv_noeeprom(0, 0, 0);
|
|
}
|
|
|
|
void matrix_init_user(void)
|
|
{
|
|
timer = timer_read();
|
|
}
|
|
|
|
void matrix_scan_user(void)
|
|
{
|
|
if ((brightness_left == 0 && brightness_right == 0)) {
|
|
return;
|
|
}
|
|
if (timer_elapsed(timer) < 20) {
|
|
return;
|
|
}
|
|
timer = timer_read();
|
|
|
|
if (brightness_left != 0 && count_left == 0) {
|
|
brightness_left -= 5;
|
|
color(hue_left, brightness_left, position_left, 15);
|
|
}
|
|
if (brightness_right != 0 && count_right == 0) {
|
|
brightness_right -= 5;
|
|
color(hue_right, brightness_right, position_right, 0);
|
|
}
|
|
}
|