keymap.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include "mechmini.h"
  14. #include "rgblight.h"
  15. #include "action_layer.h"
  16. #include "quantum.h"
  17. #define _BL 0
  18. #define _FN1 1
  19. #define _FN2 2
  20. #define _FN3 3
  21. #define _____ KC_TRNS
  22. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  23. [_BL] = KEYMAP(
  24. KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  25. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_ENT,
  26. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, MO(_FN2),
  27. KC_LCTL, KC_LGUI, KC_LALT, _____, KC_SPC, _____, MO(_FN1), MO(_FN3)
  28. ),
  29. [_FN1] = KEYMAP(
  30. _____, _____, KC_UP, KC_MUTE, KC_VOLD, KC_VOLU, KC_MRWD, KC_MPLY, KC_MFFD, KC_SLCK, KC_PAUS, KC_DEL,
  31. KC_CAPS, KC_LEFT, KC_DOWN, KC_RIGHT, _____, _____, _____, KC_INS, KC_HOME, KC_PGUP, KC_PSCR,
  32. _____, _____, M(0), M(1), M(2), _____, _____, KC_END, KC_PGDN, _____, _____,
  33. _____, _____, _____, _____, _____, _____, _____, _____
  34. ),
  35. [_FN2] = KEYMAP(
  36. KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  37. KC_CAPS, _____, _____, _____, _____, KC_LBRC, KC_RBRC, KC_BSLS, KC_MINS, KC_EQL, _____,
  38. _____, _____, _____, _____, _____, _____, _____, KC_SCLN, KC_QUOT, KC_SLSH, _____,
  39. _____, _____, _____, _____, _____, _____, _____, _____
  40. ),
  41. [_FN3] = KEYMAP(
  42. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  43. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____,
  44. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____,
  45. _____, _____, _____, _____, _____, _____, _____, _____
  46. )
  47. };
  48. /**
  49. * Blank keymap
  50. [0] = KEYMAP(
  51. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____
  52. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____,
  53. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____,
  54. _____, _____, _____, _____, _____, _____, _____, _____
  55. )
  56. */
  57. uint8_t current_level = 8;
  58. uint8_t prev_current_level = 8;
  59. int is_on = 0;
  60. enum macro_id {
  61. TOGGLE_RGB,
  62. RGB_LEVEL_DOWN,
  63. RGB_LEVEL_UP
  64. };
  65. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
  66. keyevent_t event = record->event;
  67. switch (id) {
  68. case TOGGLE_RGB:
  69. if (event.pressed) {
  70. if (!is_on) {
  71. is_on = 1;
  72. } else {
  73. is_on = 0;
  74. }
  75. }
  76. case RGB_LEVEL_DOWN:
  77. if (event.pressed && current_level > 0) {
  78. current_level--;
  79. prev_current_level--;
  80. }
  81. break;
  82. case RGB_LEVEL_UP:
  83. if (event.pressed && current_level < 15) {
  84. current_level++;
  85. prev_current_level++;
  86. }
  87. break;
  88. }
  89. return MACRO_NONE;
  90. }
  91. const uint16_t fn_actions[] PROGMEM = {
  92. [0] = ACTION_MACRO(TOGGLE_RGB),
  93. [1] = ACTION_MACRO(RGB_LEVEL_DOWN),
  94. [2] = ACTION_MACRO(RGB_LEVEL_UP)
  95. };
  96. void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b);
  97. uint8_t dim(uint8_t color, uint8_t opacity) {
  98. return ((uint16_t) color * opacity / 0xFF) & 0xFF;
  99. }
  100. void user_setrgb(uint8_t r, uint8_t g, uint8_t b) {
  101. uint8_t alpha = current_level * 0x11;
  102. rgblight_setrgb(dim(r, alpha), dim(g, alpha), dim(b, alpha));
  103. }
  104. void matrix_scan_user(void) {
  105. if (is_on) {
  106. current_level = prev_current_level;
  107. user_setrgb(0xFF, 0xFF, 0xFF);
  108. } else {
  109. current_level = 0;
  110. user_setrgb(0xFF, 0xFF, 0xFF);
  111. }
  112. }