You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
11 KiB

  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 3
  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(2)),
  21. [2] = LAYOUT(KC_LSFT, RGB_MOD, RGB_HUI, RGB_SAI, TO(0))
  22. };
  23. int get_icon_start_position(int key_position) {
  24. if (key_position == 1) {
  25. return 0;
  26. } else {
  27. return (key_position - 1) * 3;
  28. }
  29. }
  30. bool encoder_update_user(uint8_t index, bool clockwise) {
  31. static const char PROGMEM UP_ICON[] = {0x1E,0};
  32. static const char PROGMEM DOWN_ICON[] = {0x1F,0};
  33. if (index == 0) {
  34. if (layer_state_is(0)) {
  35. if (clockwise) {
  36. tap_code(KC_VOLU);
  37. oled_set_cursor(get_icon_start_position(7), 3);
  38. oled_write_P(PSTR(" "), false);
  39. oled_set_cursor(get_icon_start_position(7), 2);
  40. oled_write_P(UP_ICON, false);
  41. } else {
  42. tap_code(KC_VOLD);
  43. oled_set_cursor(get_icon_start_position(7), 2);
  44. oled_write_P(PSTR(" "), false);
  45. oled_set_cursor(get_icon_start_position(7), 3);
  46. oled_write_P(DOWN_ICON, false);
  47. }
  48. } else if (layer_state_is(1)) {
  49. if (clockwise) {
  50. tap_code(KC_BRIU);
  51. oled_set_cursor(get_icon_start_position(7), 3);
  52. oled_write_P(PSTR(" "), false);
  53. oled_set_cursor(get_icon_start_position(7), 2);
  54. oled_write_P(UP_ICON, false);
  55. } else {
  56. tap_code(KC_BRID);
  57. oled_set_cursor(get_icon_start_position(7), 2);
  58. oled_write_P(PSTR(" "), false);
  59. oled_set_cursor(get_icon_start_position(7), 3);
  60. oled_write_P(DOWN_ICON, false);
  61. }
  62. } else if (layer_state_is(2)) {
  63. if (clockwise) {
  64. rgblight_increase_val();
  65. oled_set_cursor(get_icon_start_position(7), 3);
  66. oled_write_P(PSTR(" "), false);
  67. oled_set_cursor(get_icon_start_position(7), 2);
  68. oled_write_P(UP_ICON, false);
  69. } else {
  70. rgblight_decrease_val();
  71. oled_set_cursor(get_icon_start_position(7), 2);
  72. oled_write_P(PSTR(" "), false);
  73. oled_set_cursor(get_icon_start_position(7), 3);
  74. oled_write_P(DOWN_ICON, false);
  75. }
  76. }
  77. }
  78. return true;
  79. }
  80. #ifdef OLED_ENABLE
  81. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  82. return OLED_ROTATION_180;
  83. }
  84. void draw_mute_icon(int key_position, int row) {
  85. static const char PROGMEM ICON_MUTE_0[] = {0x88, 0x89, 0};
  86. static const char PROGMEM ICON_MUTE_1[] = {0xA8, 0xA9, 0};
  87. oled_set_cursor(get_icon_start_position(key_position), row);
  88. oled_write_P(ICON_MUTE_0, false);
  89. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  90. oled_write_P(ICON_MUTE_1, false);
  91. }
  92. void draw_play_icon(int key_position, int row) {
  93. static const char PROGMEM ICON_PLAY_0[] = {0x8A, 0x8B, 0};
  94. static const char PROGMEM ICON_PLAY_1[] = {0xAA, 0xAB, 0};
  95. oled_set_cursor(get_icon_start_position(key_position), row);
  96. oled_write_P(ICON_PLAY_0, false);
  97. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  98. oled_write_P(ICON_PLAY_1, false);
  99. }
  100. void draw_rewind_icon(int key_position, int row) {
  101. static const char PROGMEM ICON_REWIND_0[] = {0x8C, 0x8D, 0};
  102. static const char PROGMEM ICON_REWIND_1[] = {0xAC, 0xAD, 0};
  103. oled_set_cursor(get_icon_start_position(key_position), row);
  104. oled_write_P(ICON_REWIND_0, false);
  105. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  106. oled_write_P(ICON_REWIND_1, false);
  107. }
  108. void draw_fast_forward_icon(int key_position, int row) {
  109. static const char PROGMEM ICON_FAST_FORWARD_0[] = {0x8E, 0x8F, 0};
  110. static const char PROGMEM ICON_FAST_FORWARD_1[] = {0xAE, 0xAF, 0};
  111. oled_set_cursor(get_icon_start_position(key_position), row);
  112. oled_write_P(ICON_FAST_FORWARD_0, false);
  113. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  114. oled_write_P(ICON_FAST_FORWARD_1, false);
  115. }
  116. void draw_prev_icon(int key_position, int row) {
  117. static const char PROGMEM ICON_PREV_0[] = {0x90, 0x91, 0};
  118. static const char PROGMEM ICON_PREV_1[] = {0xB0, 0xB1, 0};
  119. oled_set_cursor(get_icon_start_position(key_position), row);
  120. oled_write_P(ICON_PREV_0, false);
  121. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  122. oled_write_P(ICON_PREV_1, false);
  123. }
  124. void draw_next_icon(int key_position, int row) {
  125. static const char PROGMEM ICON_NEXT_0[] = {0x92, 0x93, 0};
  126. static const char PROGMEM ICON_NEXT_1[] = {0xB2, 0xB3, 0};
  127. oled_set_cursor(get_icon_start_position(key_position), row);
  128. oled_write_P(ICON_NEXT_0, false);
  129. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  130. oled_write_P(ICON_NEXT_1, false);
  131. }
  132. void draw_stop_icon(int key_position, int row) {
  133. static const char PROGMEM ICON_STOP_0[] = {0xA0, 0xA1, 0};
  134. static const char PROGMEM ICON_STOP_1[] = {0xC0, 0xC1, 0};
  135. oled_set_cursor(get_icon_start_position(key_position), row);
  136. oled_write_P(ICON_STOP_0, false);
  137. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  138. oled_write_P(ICON_STOP_1, false);
  139. }
  140. void draw_sound_icon(int key_position, int row) {
  141. static const char PROGMEM ICON_SOUND_0[] = {0xA2, 0xA3, 0};
  142. static const char PROGMEM ICON_SOUND_1[] = {0xC2, 0xC3, 0};
  143. oled_set_cursor(get_icon_start_position(key_position), row);
  144. oled_write_P(ICON_SOUND_0, false);
  145. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  146. oled_write_P(ICON_SOUND_1, false);
  147. }
  148. void draw_raise_icon(int key_position, int row) {
  149. static const char PROGMEM ICON_RAISE_0[] = {0xA4, 0xA5, 0};
  150. static const char PROGMEM ICON_RAISE_1[] = {0xC4, 0xC5, 0};
  151. oled_set_cursor(get_icon_start_position(key_position), row);
  152. oled_write_P(ICON_RAISE_0, false);
  153. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  154. oled_write_P(ICON_RAISE_1, false);
  155. }
  156. void draw_lower_icon(int key_position, int row) {
  157. static const char PROGMEM ICON_LOWER_0[] = {0xA6, 0xA7, 0};
  158. static const char PROGMEM ICON_LOWER_1[] = {0xC6, 0xC7, 0};
  159. oled_set_cursor(get_icon_start_position(key_position), row);
  160. oled_write_P(ICON_LOWER_0, false);
  161. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  162. oled_write_P(ICON_LOWER_1, false);
  163. }
  164. void draw_brightness_icon(int key_position, int row) {
  165. static const char PROGMEM ICON_BRIGHTNESS_0[] = {0xB9, 0xBA, 0};
  166. static const char PROGMEM ICON_BRIGHTNESS_1[] = {0xD9, 0xDA, 0};
  167. oled_set_cursor(get_icon_start_position(key_position), row);
  168. oled_write_P(ICON_BRIGHTNESS_0, false);
  169. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  170. oled_write_P(ICON_BRIGHTNESS_1, false);
  171. }
  172. void draw_mode_icon(int key_position, int row) {
  173. static const char PROGMEM ICON_MODE_0[] = {0x94, 0x95, 0};
  174. static const char PROGMEM ICON_MODE_1[] = {0xB4, 0xB5, 0};
  175. oled_set_cursor(get_icon_start_position(key_position), row);
  176. oled_write_P(ICON_MODE_0, false);
  177. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  178. oled_write_P(ICON_MODE_1, false);
  179. }
  180. void draw_hue_icon(int key_position, int row) {
  181. static const char PROGMEM ICON_HUE_0[] = {0x96, 0x97, 0};
  182. static const char PROGMEM ICON_HUE_1[] = {0xB6, 0xB7, 0};
  183. oled_set_cursor(get_icon_start_position(key_position), row);
  184. oled_write_P(ICON_HUE_0, false);
  185. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  186. oled_write_P(ICON_HUE_1, false);
  187. }
  188. void draw_sat_icon(int key_position, int row) {
  189. static const char PROGMEM ICON_SAT_0[] = {0xBB, 0xBC, 0};
  190. static const char PROGMEM ICON_SAT_1[] = {0xDB, 0xDC, 0};
  191. oled_set_cursor(get_icon_start_position(key_position), row);
  192. oled_write_P(ICON_SAT_0, false);
  193. oled_set_cursor(get_icon_start_position(key_position), row + 1);
  194. oled_write_P(ICON_SAT_1, false);
  195. }
  196. bool oled_task_user(void) {
  197. // Host Keyboard Layer Status
  198. static const char PROGMEM ICON_LAYER[] = {0x80, 0x81, 0x82, 0x83, 0};
  199. static const char PROGMEM ICON_ENCODER[] = {0x84, 0x85, 0x86, 0x87, 0};
  200. // static const char PROGMEM ICON_MUTE[] = {0x88, 0x89,0xA9, 0xAA};
  201. oled_write_P(ICON_LAYER, false);
  202. switch (get_highest_layer(layer_state)) {
  203. case 0:
  204. oled_write_P(PSTR("1ST "), false);
  205. break;
  206. case 1:
  207. oled_write_P(PSTR("2ND "), false);
  208. break;
  209. case 2:
  210. oled_write_P(PSTR("3RD "), false);
  211. break;
  212. default:
  213. // Or use the write_ln shortcut over adding '\n' to the end of your string
  214. oled_write_P(PSTR("UNDF"), false);
  215. }
  216. oled_write_P(PSTR(" "), false);
  217. oled_write_P(ICON_ENCODER, false);
  218. switch(get_highest_layer(layer_state)) {
  219. case 0:
  220. oled_write_P(PSTR("VOL "), false);
  221. break;
  222. case 1:
  223. oled_write_P(PSTR("BRGT"), false);
  224. break;
  225. case 2:
  226. oled_write_P(PSTR("RGB "), false);
  227. break;
  228. default:
  229. // Or use the write_ln shortcut over adding '\n' to the end of your string
  230. oled_write_P(PSTR("UNDF"), false);
  231. }
  232. switch(get_highest_layer(layer_state)) {
  233. default:
  234. case 0:
  235. draw_mute_icon(1, 2);
  236. draw_play_icon(2, 2);
  237. draw_prev_icon(3, 2);
  238. draw_next_icon(4, 2);
  239. draw_raise_icon(5, 2);
  240. draw_sound_icon(6, 2);
  241. break;
  242. case 1:
  243. draw_mute_icon(1, 2);
  244. draw_stop_icon(2, 2);
  245. draw_rewind_icon(3, 2);
  246. draw_fast_forward_icon(4, 2);
  247. draw_lower_icon(5, 2);
  248. draw_brightness_icon(6, 2);
  249. break;
  250. case 2:
  251. draw_raise_icon(1, 2);
  252. draw_mode_icon(2, 2);
  253. draw_hue_icon(3, 2);
  254. draw_sat_icon(4, 2);
  255. draw_lower_icon(5, 2);
  256. draw_brightness_icon(6, 2);
  257. break;
  258. }
  259. return false;
  260. }
  261. #endif