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.

236 lines
8.1 KiB

  1. /*
  2. M4cs Keymap for dekuNukem/duckyPad QMK firmware
  3. Copyright (C) 2020 Max Bridgland
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include QMK_KEYBOARD_H
  16. #include "stdio.h"
  17. #include <unistd.h>
  18. #include <string.h>
  19. #define LOGO_SIZE 384
  20. bool rgbToggled = false;
  21. bool altToggled = false;
  22. enum layer_codes {
  23. RGB_LAYER = SAFE_RANGE,
  24. ALT_LAYER
  25. };
  26. enum my_keycodes {
  27. Z0 = SAFE_RANGE, Z1, Z2,
  28. Z3, Z4, Z5,
  29. Z6, Z7, Z8,
  30. Z9, Z10, Z11,
  31. Z12, Z13, Z14
  32. };
  33. #define MAC_1 LCTL(LALT(KC_MINS))
  34. #define MAC_2 LCTL(LALT(KC_EQL))
  35. #define MAC_3 LCTL(LALT(KC_LBRC))
  36. #define MAC_4 LCTL(LALT(KC_RBRC))
  37. #define MAC_5 LCTL(LALT(KC_BSLS))
  38. #define MAC_6 LCTL(LALT(KC_SCLN))
  39. #define MAC_7 LCTL(LALT(KC_QUOT))
  40. #define MAC_8 LCTL(LALT(KC_COMM))
  41. #define MAC_9 LCTL(LALT(KC_SLSH))
  42. #define MAC_10 LCTL(LSFT(KC_MINS))
  43. #define MAC_11 LCTL(LSFT(KC_EQL))
  44. #define MAC_12 LCTL(LSFT(KC_SLSH))
  45. #define MAC_13 LCTL(LSFT(KC_LBRC))
  46. #define MAC_14 LCTL(LSFT(KC_RBRC))
  47. #define MAC_15 LCTL(LSFT(KC_BSLS))
  48. #define MAC_16 LCTL(LSFT(KC_SCLN))
  49. #define MAC_17 LCTL(LSFT(KC_QUOT))
  50. #define MAC_18 LCTL(LSFT(KC_COMM))
  51. #define _DEFAULT 0
  52. #define _RGB 1
  53. #define _ALT 2
  54. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  55. /*
  56. ,=========================================.
  57. | Media Prev. | Media Play | Media Next |
  58. |=========================================|
  59. | Mute Sound | Volume Do. | Volume Up |
  60. |=========================================|
  61. | Macro 1 | Macro 2 | Macro 3 |
  62. |=========================================|
  63. | Macro 4 | Macro 5 | Macro 6 |
  64. |=========================================| ,---------------------.
  65. | Macro 7 | Macro 8 | Macro 9 | | RGB Menu | Alt Menu |
  66. `=========================================' `--------------------'
  67. */
  68. [_DEFAULT] = LAYOUT(
  69. KC_MEDIA_PREV_TRACK, KC_MEDIA_PLAY_PAUSE, KC_MEDIA_NEXT_TRACK,
  70. KC_AUDIO_MUTE, KC_AUDIO_VOL_DOWN, KC_AUDIO_VOL_UP,
  71. MAC_1, MAC_2, MAC_3,
  72. MAC_4, MAC_5, MAC_6,
  73. MAC_7, MAC_8, MAC_9,
  74. RGB_LAYER, ALT_LAYER
  75. ),
  76. /*
  77. ,=========================================.
  78. | Plain RGB | Breathe RGB | Rainbow RGB |
  79. |=========================================|
  80. | Swirl RGB | Speed Down | Speed Up |
  81. |=========================================|
  82. | Effect Up | Sat. Down | Sat. Up |
  83. |=========================================|
  84. | Effect Down | Hue Down | Hue Up |
  85. |=========================================| ,----------------------.
  86. | Toggle RGB | Brt. Down | Brt. Up | | Norm Menu | Alt Menu |
  87. `=========================================' `---------------------'
  88. */
  89. [_RGB] = LAYOUT(
  90. RGB_MODE_PLAIN, RGB_MODE_BREATHE, RGB_MODE_RAINBOW,
  91. RGB_MODE_SWIRL, RGB_SPD, RGB_SPI,
  92. RGB_MOD, RGB_SAD, RGB_SAI,
  93. RGB_RMOD, RGB_HUD, RGB_HUI,
  94. RGB_TOG, RGB_VAD, RGB_VAI,
  95. RGB_LAYER, ALT_LAYER
  96. ),
  97. /*
  98. ,=========================================.
  99. | Macro 10 | Macro 11 | Macro 12 |
  100. |=========================================|
  101. | Undo | Cut | Copy |
  102. |=========================================|
  103. | Paste | Find | Prnt Scrn. |
  104. |=========================================|
  105. | Macro 13 | Macro 14 | Macro 15 |
  106. |=========================================| ,----------------------.
  107. | Macro 16 | Macro 17 | Macro 18 | | Norm Menu | Alt Menu |
  108. `=========================================' `---------------------'
  109. */
  110. [_ALT] = LAYOUT(
  111. MAC_10, MAC_11, MAC_12,
  112. KC_UNDO, KC_CUT, KC_COPY,
  113. KC_PASTE, KC_FIND, KC_PSCR,
  114. MAC_13, MAC_14, MAC_15,
  115. MAC_16, MAC_17, MAC_18,
  116. RGB_LAYER, ALT_LAYER
  117. )
  118. };
  119. static void render_logo(void) {
  120. static const char PROGMEM ducky_logo[LOGO_SIZE] = {
  121. 0, 0, 0, 0,128,128,128,128,128, 0, 0,252,252,252, 0, 0, 0,128,128,128, 0, 0, 0, 0, 0,128,128,128, 0, 0, 0, 0, 0,128,128,128,128,128, 0, 0, 0, 0, 0,252,252,252, 0, 0, 0, 0, 0,128,128,128,128,128,128, 0, 0, 0, 0, 0, 0,128,128,128,128, 0,248,248,248, 56, 56, 56, 56, 56, 56,120,240,224,192, 0, 0,128,128,128,128,128,128, 0, 0, 0, 0, 0, 0, 0, 0,128,128,128,128,128, 0, 0,252,252,252, 0, 0, 0, 0, 0,232, 24, 24,232, 0, 24, 48, 48, 24, 0,232, 24, 24,232, 0, 0,
  122. 0,248,254,255,143, 7, 3, 3, 3, 7,142,255,255,255, 0, 0, 0,255,255,255, 0, 0, 0, 0, 0,255,255,255, 0,248,254,255,143, 7, 3, 3, 3, 3,143, 7, 2, 0, 0,255,255,255,240,120,252,254,231,131, 1, 0, 1, 7, 63,254,240,192, 0,224,252,127, 31, 3, 0, 0,255,255,255,112,112,112,112,112,112, 56, 63, 31, 15,193,231,243,115, 51, 51, 51, 55,255,255,252, 0, 0,248,254,255,143, 7, 3, 3, 3, 7,142,255,255,255, 0, 0, 0, 0, 0, 21,127,127,252,252,252,253,253,252,252,252,255,255,255, 0, 0,
  123. 0, 0, 3, 7, 15, 15, 14, 14, 14, 7, 3, 15, 15, 15, 0, 0, 0, 3, 7, 15, 15, 14, 14, 6, 3, 15, 15, 15, 0, 0, 3, 7, 7, 15, 14, 14, 14, 14, 7, 7, 2, 0, 0, 15, 15, 15, 0, 0, 0, 1, 3, 15, 15, 12,136,224,224,224,247,127,127, 31, 3, 0, 0, 0, 0, 0, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 7, 15, 14, 14, 14, 6, 3, 15, 15, 15, 0, 0, 0, 3, 7, 15, 15, 14, 14, 14, 7, 3, 15, 15, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 7, 11, 3, 11, 7, 11, 7, 7, 31, 0, 0
  124. };
  125. oled_write_raw_P(ducky_logo, LOGO_SIZE);
  126. }
  127. char* make_menu_text(void){
  128. char *s = malloc((30 * 3) * sizeof(*s));
  129. int width = 3;
  130. sprintf(s, "%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s",
  131. width, MT_0_0, width, MT_0_1, width, MT_0_2,
  132. width, MT_0_3, width, MT_0_4, width, MT_0_5,
  133. width, MT_0_6, width, MT_0_7, width, MT_0_8,
  134. width, MT_0_9, width, MT_0_10, width,MT_0_11,
  135. width, MT_0_12, width, MT_0_13, width, MT_0_14
  136. );
  137. return s;
  138. };
  139. char* make_rgb_text(void){
  140. char *s = malloc((30 * 3) * sizeof(*s));
  141. int width = 3;
  142. sprintf(
  143. s, "%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s",
  144. width, MT_1_0, width, MT_1_1, width, MT_1_2,
  145. width, MT_1_3, width, MT_1_4, width, MT_1_5,
  146. width, MT_1_6, width, MT_1_7, width, MT_1_8,
  147. width, MT_1_9, width, MT_1_10, width,MT_1_11,
  148. width, MT_1_12, width, MT_1_13, width, MT_1_14
  149. );
  150. return s;
  151. };
  152. char* make_alt_text(void){
  153. char *s = malloc((30 * 3) * sizeof(*s));
  154. int width = 3;
  155. sprintf(
  156. s, "%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s",
  157. width, MT_2_0, width, MT_2_1, width, MT_2_2,
  158. width, MT_2_3, width, MT_2_4, width, MT_2_5,
  159. width, MT_2_6, width, MT_2_7, width, MT_2_8,
  160. width, MT_2_9, width, MT_2_10, width,MT_2_11,
  161. width, MT_2_12, width, MT_2_13, width, MT_2_14
  162. );
  163. return s;
  164. };
  165. void oled_task_user(void) {
  166. render_logo();
  167. oled_set_cursor(0,3);
  168. if (rgbToggled) {
  169. char *s = make_rgb_text();
  170. oled_write_ln_P(s, false);
  171. free(s);
  172. } else if (altToggled) {
  173. char *s = make_alt_text();
  174. oled_write_ln_P(s, false);
  175. free(s);
  176. } else {
  177. char *s = make_menu_text();
  178. oled_write_ln_P(s, false);
  179. free(s);
  180. }
  181. }
  182. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  183. switch (keycode) {
  184. case RGB_LAYER:
  185. if (record->event.pressed) {
  186. if (rgbToggled) {
  187. rgbToggled = false;
  188. altToggled = false;
  189. layer_clear();
  190. } else {
  191. rgbToggled = true;
  192. altToggled = false;
  193. layer_on(_RGB);
  194. }
  195. }
  196. return false;
  197. case ALT_LAYER:
  198. if (record->event.pressed) {
  199. if (altToggled) {
  200. rgbToggled = false;
  201. altToggled = false;
  202. layer_clear();
  203. } else {
  204. rgbToggled = false;
  205. altToggled = true;
  206. layer_on(_ALT);
  207. }
  208. }
  209. return false;
  210. default:
  211. return true;
  212. }
  213. return false;
  214. }