diff options
| author | Akaash Suresh <casa.akaash@gmail.com> | 2020-01-09 13:57:54 -0600 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2020-01-09 11:57:54 -0800 |
| commit | caa70df816033c30dbbbf4c5a90d803c7bb1dfde (patch) | |
| tree | 4246ca4b2808cdd1b8ed681392258f195e579014 /users/curry/rgb_matrix_user.c | |
| parent | 71de09d7510213d707ca1056c6e0eca840678d37 (diff) | |
| download | qmk_firmware-caa70df816033c30dbbbf4c5a90d803c7bb1dfde.tar.gz qmk_firmware-caa70df816033c30dbbbf4c5a90d803c7bb1dfde.zip | |
[Keymap] Userspace refactor, adding leader key functionality (#7790)
* Userspace refactor
* Fixed missed ifdef
* tapcode16, adjust layout
* glcdfont changes from #7745
* Modify Keymaps, add workman
* RGB & OLED update
Diffstat (limited to 'users/curry/rgb_matrix_user.c')
| -rw-r--r-- | users/curry/rgb_matrix_user.c | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/users/curry/rgb_matrix_user.c b/users/curry/rgb_matrix_user.c new file mode 100644 index 000000000..d1698b087 --- /dev/null +++ b/users/curry/rgb_matrix_user.c | |||
| @@ -0,0 +1,144 @@ | |||
| 1 | #include "curry.h" | ||
| 2 | #include "rgb_matrix_user.h" | ||
| 3 | #include "lib/lib8tion/lib8tion.h" | ||
| 4 | |||
| 5 | static uint32_t hypno_timer; | ||
| 6 | extern led_config_t g_led_config; | ||
| 7 | |||
| 8 | #define RGB_MATRIX_REST_MODE RGB_MATRIX_CYCLE_OUT_IN_DUAL | ||
| 9 | |||
| 10 | void suspend_power_down_keymap(void) { rgb_matrix_set_suspend_state(true); } | ||
| 11 | |||
| 12 | void suspend_wakeup_init_keymap(void) { rgb_matrix_set_suspend_state(false); } | ||
| 13 | |||
| 14 | void check_default_layer(uint8_t mode, uint8_t type) { | ||
| 15 | switch (get_highest_layer(default_layer_state)) { | ||
| 16 | case _QWERTY: | ||
| 17 | rgb_matrix_layer_helper(HSV_CYAN, mode, rgb_matrix_config.speed, type); | ||
| 18 | break; | ||
| 19 | case _COLEMAK: | ||
| 20 | rgb_matrix_layer_helper(HSV_MAGENTA, mode, rgb_matrix_config.speed, type); | ||
| 21 | break; | ||
| 22 | case _DVORAK: | ||
| 23 | rgb_matrix_layer_helper(HSV_SPRINGGREEN, mode, rgb_matrix_config.speed, type); | ||
| 24 | break; | ||
| 25 | case _WORKMAN: | ||
| 26 | rgb_matrix_layer_helper(HSV_GOLDENROD, mode, rgb_matrix_config.speed, type); | ||
| 27 | break; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | void rgb_matrix_indicators_user(void) { | ||
| 32 | if (userspace_config.rgb_layer_change && !g_suspend_state && rgb_matrix_config.enable) { | ||
| 33 | switch (get_highest_layer(layer_state)) { | ||
| 34 | case _RAISE: | ||
| 35 | rgb_matrix_layer_helper(HSV_YELLOW, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW); | ||
| 36 | break; | ||
| 37 | case _LOWER: | ||
| 38 | rgb_matrix_layer_helper(HSV_GREEN, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW); | ||
| 39 | break; | ||
| 40 | case _ADJUST: | ||
| 41 | rgb_matrix_layer_helper(HSV_RED, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW); | ||
| 42 | break; | ||
| 43 | default: { | ||
| 44 | check_default_layer(IS_LAYER_ON(_MODS), LED_FLAG_UNDERGLOW); | ||
| 45 | break; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | check_default_layer(0, LED_FLAG_MODIFIER); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { | ||
| 53 | uint16_t temp_keycode = keycode; | ||
| 54 | // Filter out the actual keycode from MT and LT keys. | ||
| 55 | if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { | ||
| 56 | temp_keycode &= 0xFF; | ||
| 57 | } | ||
| 58 | |||
| 59 | hypno_timer = timer_read32(); | ||
| 60 | if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_REST_MODE) { | ||
| 61 | rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); | ||
| 62 | } | ||
| 63 | |||
| 64 | switch (temp_keycode) { | ||
| 65 | case KC_RGB_T: // This allows me to use underglow as layer indication, or as normal | ||
| 66 | if (record->event.pressed) { | ||
| 67 | userspace_config.rgb_layer_change ^= 1; | ||
| 68 | dprintf("rgblight layer change [EEPROM]: %u\n", userspace_config.rgb_layer_change); | ||
| 69 | eeconfig_update_user(userspace_config.raw); | ||
| 70 | if (userspace_config.rgb_layer_change) { | ||
| 71 | layer_state_set(layer_state); // This is needed to immediately set the layer color (looks better) | ||
| 72 | } | ||
| 73 | } | ||
| 74 | break; | ||
| 75 | case RGB_IDL: // This allows me to use underglow as layer indication, or as normal | ||
| 76 | if (record->event.pressed) { | ||
| 77 | userspace_config.rgb_matrix_idle_anim ^= 1; | ||
| 78 | dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim); | ||
| 79 | eeconfig_update_user(userspace_config.raw); | ||
| 80 | if (userspace_config.rgb_matrix_idle_anim) { | ||
| 81 | rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | break; | ||
| 85 | case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // quantum_keycodes.h L400 for definitions | ||
| 86 | if (record->event.pressed) { | ||
| 87 | bool is_eeprom_updated = false; | ||
| 88 | if (userspace_config.rgb_matrix_idle_anim) { | ||
| 89 | userspace_config.rgb_matrix_idle_anim = false; | ||
| 90 | dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim); | ||
| 91 | is_eeprom_updated = true; | ||
| 92 | } | ||
| 93 | if (is_eeprom_updated) { | ||
| 94 | eeconfig_update_user(userspace_config.raw); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | break; | ||
| 98 | } | ||
| 99 | return true; | ||
| 100 | } | ||
| 101 | |||
| 102 | void keyboard_post_init_rgb(void) { | ||
| 103 | if (userspace_config.rgb_matrix_idle_anim) { | ||
| 104 | rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | void matrix_scan_rgb(void) { | ||
| 109 | if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_TYPING_HEATMAP && timer_elapsed32(hypno_timer) > 15000) { | ||
| 110 | rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type) { | ||
| 115 | HSV hsv = {hue, sat, val}; | ||
| 116 | if (hsv.v > rgb_matrix_config.hsv.v) { | ||
| 117 | hsv.v = rgb_matrix_config.hsv.v; | ||
| 118 | } | ||
| 119 | |||
| 120 | switch (mode) { | ||
| 121 | case 1: // breathing | ||
| 122 | { | ||
| 123 | uint16_t time = scale16by8(g_rgb_counters.tick, speed / 8); | ||
| 124 | hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); | ||
| 125 | RGB rgb = hsv_to_rgb(hsv); | ||
| 126 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 127 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { | ||
| 128 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 129 | } | ||
| 130 | } | ||
| 131 | break; | ||
| 132 | } | ||
| 133 | default: // Solid Color | ||
| 134 | { | ||
| 135 | RGB rgb = hsv_to_rgb(hsv); | ||
| 136 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { | ||
| 137 | if (HAS_FLAGS(g_led_config.flags[i], led_type)) { | ||
| 138 | rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | break; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | } | ||
