keymap.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* Copyright 2020 sendyyeah
  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. #define LAYERNUM 2
  18. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  19. [0] = LAYOUT(KC_MUTE, KC_MPLY, KC_MPRV, KC_MNXT, TO(1)),
  20. [1] = LAYOUT(KC_TRNS, KC_MSTP, KC_MRWD, KC_MFFD, TO(0))
  21. };
  22. int get_icon_start_position(int key_position) {
  23. if (key_position == 1) {
  24. return 0;
  25. } else {
  26. return (key_position - 1) * 3;
  27. }
  28. }
  29. bool encoder_update_user(uint8_t index, bool clockwise) {
  30. static const char PROGMEM UP_ICON[] = {0x1E,0};
  31. static const char PROGMEM DOWN_ICON[] = {0x1F,0};
  32. if (index == 0) {
  33. if (layer_state_is(0)) {
  34. if (clockwise) {
  35. tap_code(KC_VOLU);
  36. oled_set_cursor(get_icon_start_position(7), 3);
  37. oled_write_P(PSTR(" "), false);
  38. oled_set_cursor(get_icon_start_position(7), 2);
  39. oled_write_P(UP_ICON, false);
  40. } else {
  41. tap_code(KC_VOLD);
  42. oled_set_cursor(get_icon_start_position(7), 2);
  43. oled_write_P(PSTR(" "), false);
  44. oled_set_cursor(get_icon_start_position(7), 3);
  45. oled_write_P(DOWN_ICON, false);
  46. }
  47. } else {
  48. if (clockwise) {
  49. tap_code(KC_BRIU);
  50. oled_set_cursor(get_icon_start_position(7), 3);
  51. oled_write_P(PSTR(" "), false);
  52. oled_set_cursor(get_icon_start_position(7), 2);
  53. oled_write_P(UP_ICON, false);
  54. } else {
  55. tap_code(KC_BRID);
  56. oled_set_cursor(get_icon_start_position(7), 2);
  57. oled_write_P(PSTR(" "), false);
  58. oled_set_cursor(get_icon_start_position(7), 3);
  59. oled_write_P(DOWN_ICON, false);
  60. }
  61. }
  62. }
  63. return true;
  64. }
  65. #ifdef OLED_DRIVER_ENABLE
  66. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  67. return OLED_ROTATION_180;
  68. }
  69. void draw_mute_icon(int key_position, int row) {
  70. static const char PROGMEM ICON_MUTE_0[] = {0x88, 0x89, 0};
  71. static const char PROGMEM ICON_MUTE_1[] = {0xA8, 0xA9, 0};
  72. oled_set_cursor(get_icon_start_position(key_position), row);
  73. oled_write_P(ICON_MUTE_0, false);
  74. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  75. oled_write_P(ICON_MUTE_1, false);
  76. }
  77. void draw_play_icon(int key_position, int row) {
  78. static const char PROGMEM ICON_PLAY_0[] = {0x8A, 0x8B, 0};
  79. static const char PROGMEM ICON_PLAY_1[] = {0xAA, 0xAB, 0};
  80. oled_set_cursor(get_icon_start_position(key_position), row);
  81. oled_write_P(ICON_PLAY_0, false);
  82. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  83. oled_write_P(ICON_PLAY_1, false);
  84. }
  85. void draw_rewind_icon(int key_position, int row) {
  86. static const char PROGMEM ICON_REWIND_0[] = {0x8C, 0x8D, 0};
  87. static const char PROGMEM ICON_REWIND_1[] = {0xAC, 0xAD, 0};
  88. oled_set_cursor(get_icon_start_position(key_position), row);
  89. oled_write_P(ICON_REWIND_0, false);
  90. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  91. oled_write_P(ICON_REWIND_1, false);
  92. }
  93. void draw_fast_forward_icon(int key_position, int row) {
  94. static const char PROGMEM ICON_FAST_FORWARD_0[] = {0x8E, 0x8F, 0};
  95. static const char PROGMEM ICON_FAST_FORWARD_1[] = {0xAE, 0xAF, 0};
  96. oled_set_cursor(get_icon_start_position(key_position), row);
  97. oled_write_P(ICON_FAST_FORWARD_0, false);
  98. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  99. oled_write_P(ICON_FAST_FORWARD_1, false);
  100. }
  101. void draw_prev_icon(int key_position, int row) {
  102. static const char PROGMEM ICON_PREV_0[] = {0x90, 0x91, 0};
  103. static const char PROGMEM ICON_PREV_1[] = {0xB0, 0xB1, 0};
  104. oled_set_cursor(get_icon_start_position(key_position), row);
  105. oled_write_P(ICON_PREV_0, false);
  106. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  107. oled_write_P(ICON_PREV_1, false);
  108. }
  109. void draw_next_icon(int key_position, int row) {
  110. static const char PROGMEM ICON_NEXT_0[] = {0x92, 0x93, 0};
  111. static const char PROGMEM ICON_NEXT_1[] = {0xB2, 0xB3, 0};
  112. oled_set_cursor(get_icon_start_position(key_position), row);
  113. oled_write_P(ICON_NEXT_0, false);
  114. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  115. oled_write_P(ICON_NEXT_1, false);
  116. }
  117. void draw_stop_icon(int key_position, int row) {
  118. static const char PROGMEM ICON_STOP_0[] = {0xA0, 0xA1, 0};
  119. static const char PROGMEM ICON_STOP_1[] = {0xC0, 0xC1, 0};
  120. oled_set_cursor(get_icon_start_position(key_position), row);
  121. oled_write_P(ICON_STOP_0, false);
  122. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  123. oled_write_P(ICON_STOP_1, false);
  124. }
  125. void draw_sound_icon(int key_position, int row) {
  126. static const char PROGMEM ICON_SOUND_0[] = {0xA2, 0xA3, 0};
  127. static const char PROGMEM ICON_SOUND_1[] = {0xC2, 0xC3, 0};
  128. oled_set_cursor(get_icon_start_position(key_position), row);
  129. oled_write_P(ICON_SOUND_0, false);
  130. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  131. oled_write_P(ICON_SOUND_1, false);
  132. }
  133. void draw_raise_icon(int key_position, int row) {
  134. static const char PROGMEM ICON_RAISE_0[] = {0xA4, 0xA5, 0};
  135. static const char PROGMEM ICON_RAISE_1[] = {0xC4, 0xC5, 0};
  136. oled_set_cursor(get_icon_start_position(key_position), row);
  137. oled_write_P(ICON_RAISE_0, false);
  138. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  139. oled_write_P(ICON_RAISE_1, false);
  140. }
  141. void draw_lower_icon(int key_position, int row) {
  142. static const char PROGMEM ICON_LOWER_0[] = {0xA6, 0xA7, 0};
  143. static const char PROGMEM ICON_LOWER_1[] = {0xC6, 0xC7, 0};
  144. oled_set_cursor(get_icon_start_position(key_position), row);
  145. oled_write_P(ICON_LOWER_0, false);
  146. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  147. oled_write_P(ICON_LOWER_1, false);
  148. }
  149. void draw_brightness_icon(int key_position, int row) {
  150. static const char PROGMEM ICON_BRIGHTNESS_0[] = {0xB9, 0xBA, 0};
  151. static const char PROGMEM ICON_BRIGHTNESS_1[] = {0xD9, 0xDA, 0};
  152. oled_set_cursor(get_icon_start_position(key_position), row);
  153. oled_write_P(ICON_BRIGHTNESS_0, false);
  154. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  155. oled_write_P(ICON_BRIGHTNESS_1, false);
  156. }
  157. void oled_task_user(void) {
  158. // Host Keyboard Layer Status
  159. static const char PROGMEM ICON_LAYER[] = {0x80, 0x81, 0x82, 0x83, 0};
  160. static const char PROGMEM ICON_ENCODER[] = {0x84, 0x85, 0x86, 0x87, 0};
  161. // static const char PROGMEM ICON_MUTE[] = {0x88, 0x89,0xA9, 0xAA};
  162. oled_write_P(ICON_LAYER, false);
  163. switch (get_highest_layer(layer_state)) {
  164. case 0:
  165. oled_write_P(PSTR("1ST "), false);
  166. break;
  167. case 1:
  168. oled_write_P(PSTR("2ND "), false);
  169. break;
  170. default:
  171. // Or use the write_ln shortcut over adding '\n' to the end of your string
  172. oled_write_P(PSTR("UNDF"), false);
  173. }
  174. oled_write_P(PSTR(" "), false);
  175. oled_write_P(ICON_ENCODER, false);
  176. switch(get_highest_layer(layer_state)) {
  177. case 0:
  178. oled_write_P(PSTR("VOL "), false);
  179. break;
  180. case 1:
  181. oled_write_P(PSTR("BRGT"), false);
  182. break;
  183. default:
  184. // Or use the write_ln shortcut over adding '\n' to the end of your string
  185. oled_write_P(PSTR("UNDF"), false);
  186. }
  187. switch(get_highest_layer(layer_state)) {
  188. default:
  189. case 0:
  190. draw_mute_icon(1, 2);
  191. draw_play_icon(2, 2);
  192. draw_prev_icon(3, 2);
  193. draw_next_icon(4, 2);
  194. draw_raise_icon(5, 2);
  195. draw_sound_icon(6, 2);
  196. break;
  197. case 1:
  198. draw_mute_icon(1, 2);
  199. draw_stop_icon(2, 2);
  200. draw_rewind_icon(3, 2);
  201. draw_fast_forward_icon(4, 2);
  202. draw_lower_icon(5, 2);
  203. draw_brightness_icon(6, 2);
  204. break;
  205. }
  206. }
  207. #endif