diff options
| author | jonavin <71780717+Jonavin@users.noreply.github.com> | 2021-08-19 13:45:49 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-19 10:45:49 -0700 |
| commit | 98af5bc64e6148915cebcfdd607119b9feefe90d (patch) | |
| tree | 3f7e4e4f3ce67c279a872d31ef62e89f3d0b5a73 /users/jonavin/jonavin.c | |
| parent | 425e1e665dc3c114fc42878f2b6a9d3225e5e6b5 (diff) | |
| download | qmk_firmware-98af5bc64e6148915cebcfdd607119b9feefe90d.tar.gz qmk_firmware-98af5bc64e6148915cebcfdd607119b9feefe90d.zip | |
[Keymap] Add jonavin user space / common functions (#13876)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: Ryan <fauxpark@gmail.com>
Co-authored-by: Jonavin <=>
Diffstat (limited to 'users/jonavin/jonavin.c')
| -rw-r--r-- | users/jonavin/jonavin.c | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/users/jonavin/jonavin.c b/users/jonavin/jonavin.c new file mode 100644 index 000000000..d5fdb2a1e --- /dev/null +++ b/users/jonavin/jonavin.c | |||
| @@ -0,0 +1,231 @@ | |||
| 1 | |||
| 2 | /* Copyright 2021 Jonavin Eng @Jonavin | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | |||
| 19 | #include QMK_KEYBOARD_H | ||
| 20 | #include "jonavin.h" | ||
| 21 | |||
| 22 | |||
| 23 | #ifdef TD_LSFT_CAPSLOCK_ENABLE | ||
| 24 | // Tap once for shift, twice for Caps Lock but only if Win Key in not disabled | ||
| 25 | void dance_LSFT_finished(qk_tap_dance_state_t *state, void *user_data) { | ||
| 26 | if (state->count == 1 || keymap_config.no_gui) { | ||
| 27 | register_code16(KC_LSFT); | ||
| 28 | } else { | ||
| 29 | register_code(KC_CAPS); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | void dance_LSFT_reset(qk_tap_dance_state_t *state, void *user_data) { | ||
| 34 | if (state->count == 1 || keymap_config.no_gui) { | ||
| 35 | unregister_code16(KC_LSFT); | ||
| 36 | } else { | ||
| 37 | unregister_code(KC_CAPS); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | qk_tap_dance_action_t tap_dance_actions[] = { | ||
| 42 | // Tap once for shift, twice for Caps Lock | ||
| 43 | [TD_LSFT_CAPSLOCK] = ACTION_TAP_DANCE_DOUBLE(KC_LSFT, KC_CAPS), | ||
| 44 | [TD_LSFT_CAPS_WIN] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_LSFT_finished, dance_LSFT_reset), | ||
| 45 | }; | ||
| 46 | #endif // TD_LSFT_CAPSLOCK_ENABLE | ||
| 47 | |||
| 48 | // TIMEOUTS | ||
| 49 | #ifdef IDLE_TIMEOUT_ENABLE | ||
| 50 | static uint16_t timeout_timer = 0; | ||
| 51 | static uint16_t timeout_counter = 0; //in minute intervals | ||
| 52 | static uint16_t timeout_threshold = TIMEOUT_THRESHOLD_DEFAULT; | ||
| 53 | |||
| 54 | uint16_t get_timeout_threshold(void) { | ||
| 55 | return timeout_threshold; | ||
| 56 | } | ||
| 57 | |||
| 58 | void timeout_reset_timer(void) { | ||
| 59 | timeout_timer = timer_read(); | ||
| 60 | timeout_counter = 0; | ||
| 61 | }; | ||
| 62 | |||
| 63 | void timeout_update_threshold(bool increase) { | ||
| 64 | if (increase && timeout_threshold < TIMEOUT_THRESHOLD_MAX) timeout_threshold++; | ||
| 65 | if (!increase && timeout_threshold > 0) timeout_threshold--; | ||
| 66 | }; | ||
| 67 | |||
| 68 | void timeout_tick_timer(void) { | ||
| 69 | if (timeout_threshold > 0) { | ||
| 70 | if (timer_elapsed(timeout_timer) >= 60000) { // 1 minute tick | ||
| 71 | timeout_counter++; | ||
| 72 | timeout_timer = timer_read(); | ||
| 73 | } | ||
| 74 | #ifdef RGB_MATRIX_ENABLE | ||
| 75 | if (timeout_threshold > 0 && timeout_counter >= timeout_threshold) { | ||
| 76 | rgb_matrix_disable_noeeprom(); | ||
| 77 | } | ||
| 78 | #endif | ||
| 79 | } // timeout_threshold = 0 will disable timeout | ||
| 80 | } | ||
| 81 | |||
| 82 | __attribute__((weak)) void matrix_scan_keymap(void) {} | ||
| 83 | |||
| 84 | void matrix_scan_user(void) { | ||
| 85 | timeout_tick_timer(); | ||
| 86 | matrix_scan_keymap(); | ||
| 87 | } | ||
| 88 | #endif // IDLE_TIMEOUT_ENABLE | ||
| 89 | |||
| 90 | |||
| 91 | #if defined(ENCODER_ENABLE) && defined(ENCODER_DEFAULTACTIONS_ENABLE) // Encoder Functionality | ||
| 92 | #ifndef DYNAMIC_KEYMAP_LAYER_COUNT | ||
| 93 | #define DYNAMIC_KEYMAP_LAYER_COUNT 4 //default in case this is not already defined elsewhere | ||
| 94 | #endif | ||
| 95 | #ifndef ENCODER_DEFAULTACTIONS_INDEX | ||
| 96 | #define ENCODER_DEFAULTACTIONS_INDEX 0 // can select encoder index if there are multiple encoders | ||
| 97 | #endif | ||
| 98 | |||
| 99 | uint8_t selected_layer = 0; | ||
| 100 | |||
| 101 | __attribute__((weak)) bool encoder_update_keymap(uint8_t index, bool clockwise) { return true; } | ||
| 102 | |||
| 103 | bool encoder_update_user(uint8_t index, bool clockwise) { | ||
| 104 | if (!encoder_update_keymap(index, clockwise)) { return false; } | ||
| 105 | if (index != ENCODER_DEFAULTACTIONS_INDEX) {return true;} // exit if the index doesn't match | ||
| 106 | if ( clockwise ) { | ||
| 107 | if (keyboard_report->mods & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, encoder changes layers | ||
| 108 | if(selected_layer < (DYNAMIC_KEYMAP_LAYER_COUNT - 1)) { | ||
| 109 | selected_layer ++; | ||
| 110 | layer_move(selected_layer); | ||
| 111 | } | ||
| 112 | } else if (keyboard_report->mods & MOD_BIT(KC_RSFT) ) { // If you are holding R shift, Page up | ||
| 113 | unregister_mods(MOD_BIT(KC_RSFT)); | ||
| 114 | register_code(KC_PGDN); | ||
| 115 | register_mods(MOD_BIT(KC_RSFT)); | ||
| 116 | } else if (keyboard_report->mods & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next word | ||
| 117 | tap_code16(LCTL(KC_RGHT)); | ||
| 118 | } else if (keyboard_report->mods & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next track | ||
| 119 | tap_code(KC_MEDIA_NEXT_TRACK); | ||
| 120 | } else { | ||
| 121 | switch (selected_layer) { | ||
| 122 | case _FN1: | ||
| 123 | #ifdef IDLE_TIMEOUT_ENABLE | ||
| 124 | timeout_update_threshold(true); | ||
| 125 | #endif | ||
| 126 | break; | ||
| 127 | default: | ||
| 128 | tap_code(KC_VOLU); // Otherwise it just changes volume | ||
| 129 | break; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } else { | ||
| 133 | if (keyboard_report->mods & MOD_BIT(KC_LSFT) ) { | ||
| 134 | if (selected_layer > 0) { | ||
| 135 | selected_layer --; | ||
| 136 | layer_move(selected_layer); | ||
| 137 | } | ||
| 138 | } else if (keyboard_report->mods & MOD_BIT(KC_RSFT) ) { | ||
| 139 | unregister_mods(MOD_BIT(KC_RSFT)); | ||
| 140 | register_code(KC_PGUP); | ||
| 141 | register_mods(MOD_BIT(KC_RSFT)); | ||
| 142 | } else if (keyboard_report->mods & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate previous word | ||
| 143 | tap_code16(LCTL(KC_LEFT)); | ||
| 144 | } else if (keyboard_report->mods & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media previous track | ||
| 145 | tap_code(KC_MEDIA_PREV_TRACK); | ||
| 146 | } else { | ||
| 147 | switch (selected_layer) { | ||
| 148 | case _FN1: | ||
| 149 | #ifdef IDLE_TIMEOUT_ENABLE | ||
| 150 | timeout_update_threshold(false); | ||
| 151 | #endif | ||
| 152 | break; | ||
| 153 | default: | ||
| 154 | tap_code(KC_VOLD); | ||
| 155 | break; | ||
| 156 | } | ||
| 157 | } | ||
| 158 | } | ||
| 159 | |||
| 160 | return true; | ||
| 161 | } | ||
| 162 | #endif // ENCODER_ENABLE | ||
| 163 | |||
| 164 | |||
| 165 | // PROCESS KEY CODES | ||
| 166 | __attribute__ ((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } | ||
| 167 | |||
| 168 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 169 | if (!process_record_keymap(keycode, record)) { return false; } | ||
| 170 | switch (keycode) { | ||
| 171 | case KC_00: | ||
| 172 | if (record->event.pressed) { | ||
| 173 | // when keycode KC_00 is pressed | ||
| 174 | SEND_STRING("00"); | ||
| 175 | } else unregister_code16(keycode); | ||
| 176 | break; | ||
| 177 | case KC_WINLCK: | ||
| 178 | if (record->event.pressed) { | ||
| 179 | keymap_config.no_gui = !keymap_config.no_gui; //toggle status | ||
| 180 | } else unregister_code16(keycode); | ||
| 181 | break; | ||
| 182 | |||
| 183 | #ifdef IDLE_TIMEOUT_ENABLE | ||
| 184 | case RGB_TOI: | ||
| 185 | if(record->event.pressed) { | ||
| 186 | timeout_update_threshold(true); | ||
| 187 | } else unregister_code16(keycode); | ||
| 188 | break; | ||
| 189 | case RGB_TOD: | ||
| 190 | if(record->event.pressed) { | ||
| 191 | timeout_update_threshold(false); //decrease timeout | ||
| 192 | } else unregister_code16(keycode); | ||
| 193 | break; | ||
| 194 | #endif // IDLE_TIMEOUT_ENABLE | ||
| 195 | |||
| 196 | default: | ||
| 197 | if (record->event.pressed) { | ||
| 198 | #ifdef RGB_MATRIX_ENABLE | ||
| 199 | rgb_matrix_enable(); | ||
| 200 | #endif | ||
| 201 | #ifdef IDLE_TIMEOUT_ENABLE | ||
| 202 | timeout_reset_timer(); //reset activity timer | ||
| 203 | #endif | ||
| 204 | } | ||
| 205 | break; | ||
| 206 | } | ||
| 207 | return true; | ||
| 208 | }; | ||
| 209 | |||
| 210 | |||
| 211 | // Turn on/off NUM LOCK if current state is different | ||
| 212 | void activate_numlock(bool turn_on) { | ||
| 213 | if (IS_HOST_LED_ON(USB_LED_NUM_LOCK) != turn_on) { | ||
| 214 | tap_code(KC_NUMLOCK); | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | |||
| 219 | // INITIAL STARTUP | ||
| 220 | |||
| 221 | __attribute__ ((weak)) void keyboard_post_init_keymap(void) {} | ||
| 222 | |||
| 223 | void keyboard_post_init_user(void) { | ||
| 224 | keyboard_post_init_keymap(); | ||
| 225 | #ifdef STARTUP_NUMLOCK_ON | ||
| 226 | activate_numlock(true); // turn on Num lock by default so that the numpad layer always has predictable results | ||
| 227 | #endif // STARTUP_NUMLOC_ON | ||
| 228 | #ifdef IDLE_TIMEOUT_ENABLE | ||
| 229 | timeout_timer = timer_read(); // set inital time for ide timeout | ||
| 230 | #endif | ||
| 231 | } | ||
