You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.7 KiB

  1. /* Copyright 2021 @nstickney
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "nstickney.h"
  17. // Tap Dancing
  18. void dance_layer(qk_tap_dance_state_t *state, void *user_data) {
  19. switch (state->count) {
  20. case 1:
  21. tap_code(KC_APP);
  22. break;
  23. case 2:
  24. layer_invert(NUMP);
  25. break;
  26. case 3:
  27. layer_invert(SYMB);
  28. break;
  29. default:
  30. break;
  31. }
  32. };
  33. void dance_lock_finished(qk_tap_dance_state_t *state, void *user_data) {
  34. switch (state->count) {
  35. case 1:
  36. register_code(KC_LGUI);
  37. break;
  38. case 2:
  39. register_code(KC_NLCK);
  40. break;
  41. case 3:
  42. register_code(KC_CAPS);
  43. break;
  44. case 4:
  45. register_code(KC_SLCK);
  46. break;
  47. default:
  48. break;
  49. }
  50. };
  51. void dance_lock_reset(qk_tap_dance_state_t *state, void *user_data) {
  52. switch (state->count) {
  53. case 1:
  54. unregister_code(KC_LGUI);
  55. break;
  56. case 2:
  57. register_code(KC_NLCK);
  58. break;
  59. case 3:
  60. register_code(KC_CAPS);
  61. break;
  62. case 4:
  63. register_code(KC_SLCK);
  64. break;
  65. default:
  66. break;
  67. }
  68. };
  69. qk_tap_dance_action_t tap_dance_actions[] = {
  70. [LOCKS] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, dance_lock_finished, dance_lock_reset),
  71. [LAYERS] = ACTION_TAP_DANCE_FN(dance_layer)
  72. };
  73. // RGB underglow per-layer hue values
  74. const uint16_t LAYER_HUE[] = {6, 197, 133, 69};
  75. // Initialize RGB underglow (colorful)
  76. void keyboard_post_init_user(void) {
  77. rgblight_enable_noeeprom();
  78. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  79. for (uint16_t i = 0; i < 256; ++i) {
  80. rgblight_sethsv_noeeprom((i + LAYER_HUE[BASE]) % 256, 255, 136);
  81. wait_ms(8);
  82. }
  83. };
  84. // Turn on RGB underglow according to active layer
  85. layer_state_t layer_state_set_user(layer_state_t state) {
  86. uint8_t user_val = rgblight_get_val();
  87. rgblight_sethsv_noeeprom(LAYER_HUE[get_highest_layer(state)], 255, user_val);
  88. return state;
  89. };