keymap.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "quantum.h"
  16. #define MAX_BRIGHTNESS 15
  17. #define MAX_BRIGHTNESS_IOS 5 // max brightness suitable for iOS devices
  18. #define _BL 0
  19. #define _FN1 1
  20. #define _FN2 2
  21. #define _FN3 3
  22. #define _____ KC_TRNS
  23. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  24. [_BL] = KEYMAP(
  25. KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  26. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_ENT,
  27. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, MO(_FN2),
  28. KC_LCTL, KC_LGUI, KC_LALT, _____, KC_SPC, _____, MO(_FN1), MO(_FN3)
  29. ),
  30. [_FN1] = KEYMAP(
  31. KC_GRAVE, _____, KC_UP, KC_MUTE, KC_VOLD, KC_VOLU, KC_MRWD, KC_MPLY, KC_MFFD, KC_SLCK, KC_PAUS, KC_DEL,
  32. KC_CAPS, KC_LEFT, KC_DOWN, KC_RIGHT, _____, _____, _____, KC_INS, KC_HOME, KC_PGUP, KC_PSCR,
  33. _____, _____, M(0), M(1), M(2), _____, _____, KC_END, KC_PGDN, _____, _____,
  34. _____, _____, _____, _____, _____, _____, _____, _____
  35. ),
  36. [_FN2] = KEYMAP(
  37. KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  38. KC_CAPS, _____, _____, _____, _____, KC_LBRC, KC_RBRC, KC_BSLS, KC_MINS, KC_EQL, _____,
  39. _____, _____, _____, _____, _____, _____, _____, KC_SCLN, KC_QUOT, KC_SLSH, _____,
  40. _____, _____, _____, _____, _____, _____, _____, _____
  41. ),
  42. [_FN3] = KEYMAP(
  43. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  44. _____, M(3), M(4), M(5), _____, _____, _____, _____, _____, _____, _____,
  45. _____, M(6), _____, _____, _____, _____, _____, _____, _____, _____, _____,
  46. _____, _____, _____, _____, _____, _____, _____, _____
  47. )
  48. };
  49. /**
  50. * Blank keymap
  51. [0] = KEYMAP(
  52. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____
  53. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____,
  54. _____, _____, _____, _____, _____, _____, _____, _____, _____, _____, _____,
  55. _____, _____, _____, _____, _____, _____, _____, _____
  56. )
  57. */
  58. uint8_t current_level = 4;
  59. int is_on = 0;
  60. uint8_t r = 0xFF;
  61. uint8_t g = 0xFF;
  62. uint8_t b = 0xFF;
  63. uint8_t max_brightness = MAX_BRIGHTNESS_IOS;
  64. enum macro_id {
  65. TOGGLE_RGB,
  66. BRIGHTNESS_DOWN,
  67. BRIGHTNESS_UP,
  68. COLOR_1,
  69. COLOR_2,
  70. COLOR_3,
  71. ENABLE_MAX_BRIGHTNESS
  72. };
  73. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
  74. keyevent_t event = record->event;
  75. switch (id) {
  76. case TOGGLE_RGB:
  77. if (event.pressed) {
  78. if (!is_on) {
  79. current_level = 4;
  80. is_on = 1;
  81. } else {
  82. is_on = 0;
  83. }
  84. }
  85. case BRIGHTNESS_DOWN:
  86. if (event.pressed && current_level > 0) {
  87. current_level--;
  88. }
  89. break;
  90. case BRIGHTNESS_UP:
  91. if (event.pressed && current_level < max_brightness) {
  92. current_level++;
  93. }
  94. break;
  95. case COLOR_1: // set to pink
  96. if (event.pressed) {
  97. r = 0xFF;
  98. g = 0x81;
  99. b = 0xC2;
  100. }
  101. break;
  102. case COLOR_2: // set to cyan
  103. if (event.pressed) {
  104. r = 0x00;
  105. g = 0xE0;
  106. b = 0xFF;
  107. }
  108. break;
  109. case COLOR_3: // set to white
  110. if (event.pressed) {
  111. r = 0xFF;
  112. g = 0xFF;
  113. b = 0xFF;
  114. }
  115. break;
  116. case ENABLE_MAX_BRIGHTNESS: // enable all 16 brightness steps
  117. if (event.pressed) {
  118. max_brightness = MAX_BRIGHTNESS;
  119. }
  120. break;
  121. }
  122. return MACRO_NONE;
  123. }
  124. const uint16_t fn_actions[] PROGMEM = {
  125. };
  126. void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b);
  127. uint8_t dim(uint8_t color, uint8_t opacity) {
  128. return ((uint16_t) color * opacity / 0xFF) & 0xFF;
  129. }
  130. void user_setrgb(uint8_t r, uint8_t g, uint8_t b) {
  131. uint8_t alpha = current_level * 0x11;
  132. rgblight_setrgb(dim(r, alpha), dim(g, alpha), dim(b, alpha));
  133. }
  134. void matrix_scan_user(void) {
  135. if (!is_on) {
  136. current_level = 0;
  137. user_setrgb(r, g, b);
  138. } else {
  139. user_setrgb(r, g, b);
  140. }
  141. }