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