keymap.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Copyright 2019 monksoffunk
  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 QMK_KEYBOARD_H
  17. #include "common/oled_helper.h"
  18. // Defines the keycodes used by our macros in process_record_user
  19. enum custom_keycodes {
  20. RGBRST = SAFE_RANGE,
  21. WRTROM,
  22. };
  23. enum layer_number {
  24. _AUDIO = 0,
  25. _HUE,
  26. _SAT,
  27. _VAL,
  28. _MODE,
  29. };
  30. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  31. // LAYOUT(LeftEncoder, RightEncoder, LeftSwitch, CenterLeftSwitch, CenterRightSwitch, RightSwitch)
  32. [_AUDIO] = LAYOUT(KC_MUTE, KC_ENT, LT(_HUE, KC_MPRV), LT(_SAT, KC_MPLY), LT(_VAL, KC_MNXT), LT(_MODE, KC_SPC)),
  33. [_HUE] = LAYOUT(RGB_TOG, RGBRST, _______, _______, RGB_HUD, RGB_HUI),
  34. [_SAT] = LAYOUT(_______, _______, _______, _______, RGB_SAD, RGB_SAI),
  35. [_VAL] = LAYOUT(_______, _______, RGB_VAD, RGB_VAI, _______, RGB_VAI),
  36. [_MODE] = LAYOUT(_______, WRTROM, RGB_RMOD, RGB_MOD, RGB_MOD, _______),
  37. };
  38. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  39. switch (keycode) {
  40. case WRTROM:
  41. #ifdef RGBLIGHT_ENABLE
  42. if (record->event.pressed) {
  43. eeconfig_update_rgblight_current();
  44. }
  45. #endif
  46. return false;
  47. break;
  48. case RGBRST:
  49. #ifdef RGBLIGHT_ENABLE
  50. if (record->event.pressed) {
  51. eeconfig_update_rgblight_default();
  52. rgblight_enable();
  53. }
  54. #endif
  55. return false;
  56. break;
  57. }
  58. return true;
  59. }
  60. #ifdef OLED_DRIVER_ENABLE
  61. # include <stdio.h>
  62. # include <string.h>
  63. // assign the right code to your layers for OLED display
  64. # define L_AUDIO 0
  65. # define L_HUE (1 << _HUE)
  66. # define L_SAT (1 << _SAT)
  67. # define L_VAL (1 << _VAL)
  68. # define L_MODE (1 << _MODE)
  69. void render_status(void) {
  70. render_logo();
  71. // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
  72. switch (layer_state) {
  73. case L_AUDIO:
  74. oled_write_P(PSTR("audio control\n"), false);
  75. break;
  76. case L_HUE:
  77. oled_write_P(PSTR("rgb HUE control\n"), false);
  78. break;
  79. case L_SAT:
  80. oled_write_P(PSTR("rgb SAT control\n"), false);
  81. break;
  82. case L_VAL:
  83. oled_write_P(PSTR("rgb VAL control\n"), false);
  84. break;
  85. case L_MODE:
  86. oled_write_P(PSTR("rgb MODE control\n"), false);
  87. break;
  88. default:
  89. break;
  90. }
  91. UPDATE_LED_STATUS();
  92. RENDER_LED_STATUS();
  93. }
  94. void oled_task_user(void) {
  95. if (is_keyboard_master()) {
  96. render_status();
  97. } else {
  98. render_logo();
  99. }
  100. }
  101. #endif
  102. void led_set_user(uint8_t usb_led) {}
  103. bool encoder_update_user(uint8_t index, bool clockwise) {
  104. oled_on();
  105. if (index == 0) { /* left encoder */
  106. switch (layer_state) {
  107. case L_AUDIO:
  108. if (clockwise) {
  109. tap_code(KC_VOLU);
  110. } else {
  111. tap_code(KC_VOLD);
  112. }
  113. break;
  114. case L_HUE:
  115. #ifdef RGBLIGHT_ENABLE
  116. if (clockwise) {
  117. rgblight_increase_hue_noeeprom();
  118. } else {
  119. rgblight_decrease_hue_noeeprom();
  120. }
  121. #endif
  122. break;
  123. case L_SAT:
  124. #ifdef RGBLIGHT_ENABLE
  125. if (clockwise) {
  126. rgblight_increase_sat_noeeprom();
  127. } else {
  128. rgblight_decrease_sat_noeeprom();
  129. }
  130. #endif
  131. break;
  132. case L_VAL:
  133. #ifdef RGBLIGHT_ENABLE
  134. if (clockwise) {
  135. rgblight_increase_val_noeeprom();
  136. } else {
  137. rgblight_decrease_val_noeeprom();
  138. }
  139. #endif
  140. break;
  141. case L_MODE:
  142. #ifdef RGBLIGHT_ENABLE
  143. if (clockwise) {
  144. rgblight_step_noeeprom();
  145. } else {
  146. rgblight_step_reverse_noeeprom();
  147. }
  148. #endif
  149. break;
  150. }
  151. } else if (index == 1) { /* right encoder */
  152. if (clockwise) {
  153. tap_code(KC_DOWN);
  154. } else {
  155. tap_code(KC_UP);
  156. }
  157. }
  158. return true;
  159. }