[Keymap] Update to Userspace kuchosauronad0 (#6899)
* Add Plover layer, remove unused layers * Add rgb indicator for success/failed sequences * Add RGB effects * Add RGB * Add effects for start and end of a leader sequence * Add PLOVER layer * Add RGB * Add RBG * Minor clean up * Minor clean up * Minor clean up * Minor clean up * Rename rgb_light to rgblight_user and fix all references to it * Remove unnecessary guards Remove unnecessary matrix_scan in rgb post_init function * remove trailing newlineencoder_matrix
parent
b1c2bf071b
commit
674fcc474c
@ -1,77 +1,116 @@ |
||||
#include "leader.h" |
||||
#ifdef RGBLIGHT_ENABLE |
||||
extern rgblight_config_t rgblight_config; |
||||
#endif |
||||
bool leader_succeed; |
||||
|
||||
LEADER_EXTERNS(); |
||||
|
||||
void matrix_scan_user(void){ |
||||
void matrix_scan_user(void) { |
||||
static bool has_ran_yet; |
||||
if (!has_ran_yet) { |
||||
has_ran_yet = true; |
||||
startup_user(); |
||||
} |
||||
|
||||
#ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
|
||||
// run_diablo_macro_check();
|
||||
#endif // TAP_DANCE_ENABLE
|
||||
|
||||
#endif |
||||
#ifdef RGBLIGHT_ENABLE |
||||
matrix_scan_rgb(); |
||||
#endif // RGBLIGHT_ENABLE
|
||||
|
||||
#endif |
||||
LEADER_DICTIONARY() { |
||||
leading = false; |
||||
leader_end(); |
||||
leader_succeed = leading = false; |
||||
|
||||
SEQ_ONE_KEY(KC_W) { |
||||
// vim/tmux: Use in command mode in vim: write to file, switch tmux pane in the current session window and repeat the last command
|
||||
SEND_STRING(":w" SS_TAP(X_ENTER)); |
||||
tmux_pane_switch_repeat(); |
||||
} |
||||
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_ONE_KEY(KC_T) { |
||||
// Send the Tmux Prefix
|
||||
tmux_prefix(); |
||||
} |
||||
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_ONE_KEY(KC_A) { |
||||
// tmux: Send the prefix and press 'right' arrow
|
||||
tmux_prefix(); |
||||
tap_code(KC_RIGHT); |
||||
} |
||||
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_TWO_KEYS(KC_T, KC_T) { |
||||
// tmux: Send the prefix to a nested session
|
||||
tmux_prefix(); |
||||
tmux_prefix(); |
||||
} |
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_TWO_KEYS(KC_T, KC_R) { |
||||
// tmux: Switch pane and repeat last action
|
||||
tmux_pane_switch_repeat(); |
||||
} |
||||
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_TWO_KEYS(KC_V, KC_Z){ |
||||
// vim: Zoom pane
|
||||
tap_code16(LCTL(KC_W)); |
||||
tap_code16(LSFT(KC_BSLS)); |
||||
} |
||||
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_TWO_KEYS(KC_V, KC_R) { |
||||
// vim: Substitute and place cursor
|
||||
SEND_STRING(":%s///g" SS_TAP(X_LEFT)); |
||||
tap_code(KC_LEFT); |
||||
tap_code(KC_LEFT); |
||||
} |
||||
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_TWO_KEYS(KC_V, KC_T) { |
||||
// vim: move current pane to new tab
|
||||
tap_code16(LCTL(KC_W)); |
||||
tap_code16(LSFT(KC_T)); |
||||
} |
||||
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_ONE_KEY(KC_R){ |
||||
// Toggle RGB Layer indicator
|
||||
tap_code16(KC_RGB_T); |
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_ONE_KEY(KC_SPC){ |
||||
// One Shot Unicode layer
|
||||
//TODO tap_code16(OS_UNI);
|
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_TWO_KEYS(KC_SPC, KC_SPC){ |
||||
// Toggle _MODS
|
||||
tap_code16(TG_MODS); |
||||
leader_succeed = true; |
||||
} else |
||||
SEQ_THREE_KEYS(KC_BSPC, KC_BSPC, KC_BSPC){ |
||||
// Reset the keyboard
|
||||
reset_keyboard(); |
||||
leader_succeed = true; |
||||
} |
||||
leader_end(); |
||||
} |
||||
// matrix_scan_keymap();
|
||||
} |
||||
|
||||
void leader_start(void) { |
||||
#ifdef RGBLIGHT_ENABLE |
||||
rgblight_savebase(); |
||||
rgblight_mode_noeeprom(1); |
||||
rgblight_sethsv_noeeprom_goldenrod(); |
||||
#endif |
||||
} |
||||
|
||||
matrix_scan_keymap(); |
||||
void leader_end(void) { |
||||
// pick color depending of success /fail
|
||||
// fade leader_start from 100 to 0
|
||||
// fade new color from 0 to 100 to 0
|
||||
// fade old color from 0 to 100
|
||||
#ifdef RGBLIGHT_ENABLE |
||||
if (leader_succeed) { |
||||
fadeflash_leds(HSV_GREEN); |
||||
} else { |
||||
fadeflash_leds(HSV_RED); |
||||
} |
||||
#endif |
||||
} |
||||
|
@ -0,0 +1,156 @@ |
||||
#include "rgblight_user.h" |
||||
extern rgblight_config_t rgblight_config; |
||||
bool has_initialized; |
||||
uint8_t base_hue; // Hue value of base state
|
||||
uint8_t base_sat; // Saturation value of base state
|
||||
uint8_t base_val; // Brightness value of base state
|
||||
uint8_t base_mod; // Animation mode of the base state
|
||||
|
||||
void rgblight_savebase(void) { // Save the current settings to ram
|
||||
base_hue = rgblight_config.hue; |
||||
base_sat = rgblight_config.sat; |
||||
base_val = rgblight_config.val; |
||||
base_mod = rgblight_config.mode; |
||||
} |
||||
void rgblight_loadbase(void) { // Load settings from ram to eeprom
|
||||
rgblight_mode( base_mod ); |
||||
rgblight_sethsv_eeprom_helper(base_hue, base_sat, base_val, true); |
||||
} |
||||
|
||||
|
||||
|
||||
bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { |
||||
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { |
||||
keycode = keycode & 0xFF; |
||||
} |
||||
switch (keycode) { |
||||
case KC_RGB_T: // Switch between underglow layer indication and normal qmk behaviour
|
||||
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) |
||||
if (record->event.pressed) { |
||||
userspace_config.rgb_layer_change ^= 1; |
||||
xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); |
||||
eeconfig_update_user(userspace_config.raw); |
||||
if (userspace_config.rgb_layer_change) { |
||||
layer_state_set(layer_state); // Immediately set the layer color (looks better)
|
||||
} |
||||
} |
||||
#endif // RGBLIGHT_ENABLE
|
||||
return false; |
||||
break; |
||||
#ifdef RGBLIGHT_ENABLE |
||||
case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions
|
||||
if (record->event.pressed) { // This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
|
||||
if (userspace_config.rgb_layer_change) { |
||||
userspace_config.rgb_layer_change = false; |
||||
xprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); |
||||
eeconfig_update_user(userspace_config.raw); |
||||
} |
||||
} |
||||
return true; |
||||
break; |
||||
#endif // RGBLIGHT_ENABLE
|
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void keyboard_post_init_rgb(void) { |
||||
# if defined(RGBLIGHT_ENABLE) || defined(RGBLIGHT_STARTUP_ANIMATION) |
||||
bool is_enabled = rgblight_config.enable; |
||||
if (userspace_config.rgb_layer_change) { |
||||
rgblight_enable_noeeprom(); |
||||
} |
||||
if (rgblight_config.enable) { |
||||
layer_state_set_user(layer_state); |
||||
uint16_t old_hue = rgblight_config.hue; |
||||
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); |
||||
for (uint16_t i = 255; i > 0; i--) { |
||||
rgblight_sethsv_noeeprom((i + old_hue) % 255, 255, 255); |
||||
wait_ms(5); |
||||
} |
||||
} |
||||
if (!is_enabled) { |
||||
rgblight_disable_noeeprom(); |
||||
} |
||||
# endif // !RGBLIGHT_ENABLE || RGBLIGHT_STARTUP_ANIMATION
|
||||
layer_state_set_user(layer_state); |
||||
} |
||||
|
||||
void matrix_scan_rgb(void) { |
||||
# ifdef INDICATOR_LIGHTS |
||||
matrix_scan_indicator(); |
||||
# endif |
||||
} |
||||
|
||||
layer_state_t layer_state_set_rgb(layer_state_t state) { |
||||
# ifdef RGBLIGHT_ENABLE |
||||
if (userspace_config.rgb_layer_change) { |
||||
switch (biton32(state)) { // _RAISE, _LOWER and _ADJUST use a custom color and the breathing effect
|
||||
case _RAISE: |
||||
rgblight_sethsv_noeeprom_green(); |
||||
rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3); |
||||
break; |
||||
case _LOWER: |
||||
rgblight_sethsv_noeeprom_red(); |
||||
rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3); |
||||
break; |
||||
case _ADJUST: |
||||
rgblight_sethsv_noeeprom_white(); |
||||
rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 2); |
||||
break; |
||||
default: // Use a solid color for normal layers
|
||||
switch (biton32(default_layer_state)) { |
||||
case _QWERTY: |
||||
rgblight_sethsv_noeeprom_magenta(); |
||||
break; |
||||
case _COLEMAK: |
||||
rgblight_sethsv_noeeprom_green(); |
||||
break; |
||||
case _DVORAK: |
||||
rgblight_sethsv_noeeprom_blue(); |
||||
break; |
||||
case _WORKMAN: |
||||
rgblight_sethsv_noeeprom_goldenrod(); |
||||
break; |
||||
case _PLOVER: |
||||
rgblight_sethsv_noeeprom_pink(); |
||||
break; |
||||
default: |
||||
rgblight_sethsv_noeeprom_white(); |
||||
break; |
||||
} |
||||
biton32(state) == _MODS ? rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING) : rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); // if _MODS layer is on, then breath to denote it
|
||||
break; |
||||
} |
||||
} |
||||
# endif // !RGBLIGHT_ENABLE
|
||||
return state; |
||||
} |
||||
|
||||
#ifdef INDICATOR_LIGHTS |
||||
void matrix_scan_indicator(void) { |
||||
if (has_initialized) { |
||||
set_rgb_indicators(get_mods(), host_keyboard_leds(), get_oneshot_mods()); |
||||
} |
||||
} |
||||
#endif // !INDICATOR_LIGHTS
|
||||
|
||||
void rgblight_fade_helper(bool direction){ |
||||
// true: increase val = fade in
|
||||
// false: decrease val = fade out
|
||||
for (uint8_t index = 0; index < RGBLIGHT_VAL_STEP ; index++) { |
||||
direction ? rgblight_increase_val() : rgblight_decrease_val(); |
||||
wait_ms(5); |
||||
} |
||||
} |
||||
void fadeflash_leds(uint8_t hue, uint8_t sat, uint8_t val){ |
||||
// indicate success / fail of a leader sequence
|
||||
// fade out, set new hue and saturation, fade in, fade out, set old color, fade in
|
||||
// this is used in leader.c
|
||||
// TODO: come up with a better name maybe
|
||||
rgblight_fade_helper(false);
|
||||
rgblight_sethsv_noeeprom(hue, sat, 0);
|
||||
rgblight_fade_helper(true);
|
||||
rgblight_fade_helper(false);
|
||||
rgblight_sethsv_noeeprom(base_hue, base_sat, 0);
|
||||
rgblight_fade_helper(true);
|
||||
} |
@ -0,0 +1,23 @@ |
||||
#pragma once |
||||
#include "kuchosauronad0.h" |
||||
|
||||
typedef struct { |
||||
bool enabled; |
||||
uint8_t hue; |
||||
uint16_t timer; |
||||
uint8_t life; |
||||
} rgblight_fadeout; |
||||
const uint8_t RGBLIGHT_FADE_SPEED[6] PROGMEM; |
||||
|
||||
layer_state_t layer_state_set_rgb(layer_state_t state); |
||||
layer_state_t default_layer_state_set_rgb(layer_state_t state); |
||||
|
||||
bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record); |
||||
void scan_rgblight_fadeout(void); |
||||
void keyboard_post_init_rgb(void); |
||||
void matrix_scan_rgb(void); |
||||
void rgblight_sethsv_default_helper(uint8_t index); |
||||
void rgblight_savebase(void); |
||||
void rgblight_loadbase(void); |
||||
void rgblight_fade_helper(bool direction); |
||||
void fadeflash_leds(uint8_t hue, uint8_t sat, uint8_t val); |
Loading…
Reference in new issue