keymap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 "raw_hid.h"
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #include <math.h>
  21. #define LOGO_SIZE 384
  22. bool rgbToggled = false;
  23. bool altToggled = false;
  24. bool sysToggled = false;
  25. enum layer_codes {
  26. RGB_LAYER = SAFE_RANGE,
  27. ALT_LAYER,
  28. SYS_LAYER,
  29. CLOCK_TOGGLE
  30. };
  31. #define MAC_1 LCTL(LALT(KC_MINS))
  32. #define MAC_2 LCTL(LALT(KC_EQL))
  33. #define MAC_3 LCTL(LALT(KC_LBRC))
  34. #define MAC_4 LCTL(LALT(KC_RBRC))
  35. #define MAC_5 LCTL(LALT(KC_BSLS))
  36. #define MAC_6 LCTL(LALT(KC_SCLN))
  37. #define MAC_7 LCTL(LALT(KC_QUOT))
  38. #define MAC_8 LCTL(LALT(KC_COMM))
  39. #define MAC_9 LCTL(LALT(KC_SLSH))
  40. #define MAC_10 LCTL(LSFT(KC_MINS))
  41. #define MAC_11 LCTL(LSFT(KC_EQL))
  42. #define MAC_12 LCTL(LSFT(KC_SLSH))
  43. #define MAC_13 LCTL(LSFT(KC_LBRC))
  44. #define MAC_14 LCTL(LSFT(KC_RBRC))
  45. #define MAC_15 LCTL(LSFT(KC_BSLS))
  46. #define MAC_16 LCTL(LSFT(KC_SCLN))
  47. #define MAC_17 LCTL(LSFT(KC_QUOT))
  48. #define MAC_18 LCTL(LSFT(KC_COMM))
  49. #define _DEFAULT 0
  50. #define _RGB 1
  51. #define _ALT 2
  52. #define _SYS 3
  53. float cpuFreq = 0;
  54. int memPerc = 0;
  55. int gpuLoad = 0;
  56. int temp = 0;
  57. int hour = 0;
  58. int minute = 0;
  59. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  60. /*
  61. ,=========================================.
  62. | Media Prev. | Media Play | Media Next |
  63. |=========================================|
  64. | Mute Sound | Volume Do. | Volume Up |
  65. |=========================================|
  66. | Macro 1 | Macro 2 | Macro 3 |
  67. |=========================================|
  68. | Macro 4 | Macro 5 | Macro 6 |
  69. |=========================================| ,---------------------.
  70. | Macro 7 | Macro 8 | Sys. Info | | RGB Menu | Alt Menu |
  71. `=========================================' `--------------------'
  72. */
  73. [_DEFAULT] = LAYOUT(
  74. KC_MEDIA_PREV_TRACK, KC_MEDIA_PLAY_PAUSE, KC_MEDIA_NEXT_TRACK,
  75. KC_AUDIO_MUTE, KC_AUDIO_VOL_DOWN, KC_AUDIO_VOL_UP,
  76. MAC_1, MAC_2, MAC_3,
  77. MAC_4, MAC_5, MAC_6,
  78. CLOCK_TOGGLE, MAC_8, SYS_LAYER,
  79. RGB_LAYER, ALT_LAYER
  80. ),
  81. /*
  82. ,=========================================.
  83. | Plain RGB | Breathe RGB | Rainbow RGB |
  84. |=========================================|
  85. | Swirl RGB | Speed Down | Speed Up |
  86. |=========================================|
  87. | Effect Up | Sat. Down | Sat. Up |
  88. |=========================================|
  89. | Effect Down | Hue Down | Hue Up |
  90. |=========================================| ,----------------------.
  91. | Toggle RGB | Brt. Down | Brt. Up | | Norm Menu | Alt Menu |
  92. `=========================================' `---------------------'
  93. */
  94. [_RGB] = LAYOUT(
  95. RGB_MODE_PLAIN, RGB_MODE_BREATHE, RGB_MODE_RAINBOW,
  96. RGB_MODE_SWIRL, RGB_SPD, RGB_SPI,
  97. RGB_MOD, RGB_SAD, RGB_SAI,
  98. RGB_RMOD, RGB_HUD, RGB_HUI,
  99. RGB_TOG, RGB_VAD, RGB_VAI,
  100. RGB_LAYER, ALT_LAYER
  101. ),
  102. /*
  103. ,=========================================.
  104. | Macro 10 | Macro 11 | Macro 12 |
  105. |=========================================|
  106. | Undo | Cut | Copy |
  107. |=========================================|
  108. | Paste | Find | Prnt Scrn. |
  109. |=========================================|
  110. | Macro 13 | Macro 14 | Macro 15 |
  111. |=========================================| ,----------------------.
  112. | Macro 16 | Macro 17 | Sys. Info | | Norm Menu | Alt Menu |
  113. `=========================================' `---------------------'
  114. */
  115. [_ALT] = LAYOUT(
  116. MAC_10, MAC_11, MAC_12,
  117. KC_UNDO, KC_CUT, KC_COPY,
  118. KC_PASTE, KC_FIND, KC_PSCR,
  119. MAC_13, MAC_14, MAC_15,
  120. CLOCK_TOGGLE, MAC_17, SYS_LAYER,
  121. RGB_LAYER, ALT_LAYER
  122. ),
  123. [_SYS] = LAYOUT(
  124. KC_NO, KC_NO, KC_NO,
  125. KC_NO, KC_NO, KC_NO,
  126. KC_NO, KC_NO, KC_NO,
  127. KC_NO, KC_NO, KC_NO,
  128. CLOCK_TOGGLE, KC_NO, SYS_LAYER,
  129. RGB_LAYER, ALT_LAYER
  130. )
  131. };
  132. static void render_logo(void) {
  133. static const char PROGMEM raw_logo[] = {
  134. 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  135. 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,192,240,240, 96, 48, 48, 0, 12, 12,134,198,230,126, 60, 0, 0, 0,
  136. 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, 12, 15, 7, 0, 0, 0, 12, 14, 15, 15, 13, 13, 12, 12, 0, 0, 0, 0,
  137. };
  138. oled_write_raw_P(raw_logo, sizeof(raw_logo));
  139. }
  140. char* make_menu_text(void){
  141. char *s = malloc((30 * 4) * sizeof(*s));
  142. int width = 3;
  143. snprintf(s, 120, "%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s",
  144. width, MT_0_0, width, MT_0_1, width, MT_0_2,
  145. width, MT_0_3, width, MT_0_4, width, MT_0_5,
  146. width, MT_0_6, width, MT_0_7, width, MT_0_8,
  147. width, MT_0_9, width, MT_0_10, width,MT_0_11,
  148. width, MT_0_12, width, MT_0_13, width, MT_0_14
  149. );
  150. return s;
  151. };
  152. char* make_rgb_text(void){
  153. char *s = malloc((30 * 4) * sizeof(*s));
  154. int width = 3;
  155. snprintf(
  156. s, 120, "%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s",
  157. width, MT_1_0, width, MT_1_1, width, MT_1_2,
  158. width, MT_1_3, width, MT_1_4, width, MT_1_5,
  159. width, MT_1_6, width, MT_1_7, width, MT_1_8,
  160. width, MT_1_9, width, MT_1_10, width,MT_1_11,
  161. width, MT_1_12, width, MT_1_13, width, MT_1_14
  162. );
  163. return s;
  164. };
  165. char* make_alt_text(void){
  166. char *s = malloc((30 * 4) * sizeof(*s));
  167. int width = 3;
  168. snprintf(
  169. s, 120, "%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s\n%-*s %-*s %-*s",
  170. width, MT_2_0, width, MT_2_1, width, MT_2_2,
  171. width, MT_2_3, width, MT_2_4, width, MT_2_5,
  172. width, MT_2_6, width, MT_2_7, width, MT_2_8,
  173. width, MT_2_9, width, MT_2_10, width,MT_2_11,
  174. width, MT_2_12, width, MT_2_13, width, MT_2_14
  175. );
  176. return s;
  177. };
  178. char* make_sys_info_text(void) {
  179. char *s = malloc((30 * 5) * sizeof(*s));
  180. snprintf(s, 150, " cpu: %.1fGHz\n mem: %d%%\n gpu: %d%%\n temp: %dC\n time: %d:%d", cpuFreq, memPerc, gpuLoad, temp, hour, minute);
  181. return s;
  182. };
  183. void oled_task_user(void) {
  184. if (!sysToggled) {
  185. render_logo();
  186. oled_set_cursor(0,3);
  187. if (rgbToggled) {
  188. char *s = make_rgb_text();
  189. oled_write_ln(s, false);
  190. free(s);
  191. } else if (altToggled) {
  192. char *s = make_alt_text();
  193. oled_write_ln(s, false);
  194. free(s);
  195. } else {
  196. char *s = make_menu_text();
  197. oled_write_ln(s, false);
  198. free(s);
  199. }
  200. }
  201. };
  202. int concat(int a, int b) {
  203. char s1[20];
  204. char s2[20];
  205. sprintf(s1, "%d", a);
  206. sprintf(s2, "%d", b);
  207. strcat(s1, s2);
  208. int c = atoi(s1);
  209. return c;
  210. };
  211. void raw_hid_receive(uint8_t *data, uint8_t length) {
  212. if (sysToggled) {
  213. oled_clear();
  214. render_logo();
  215. int i;
  216. int stepper = 0;
  217. int toWrite;
  218. for (i=0; i < length; i++) {
  219. if (data[i] != 13) {
  220. toWrite = concat(toWrite, data[i]);
  221. } else {
  222. switch (stepper) {
  223. case 0:
  224. cpuFreq = floor(100*toWrite)/10000;
  225. break;
  226. case 1:
  227. memPerc = toWrite / 10;
  228. break;
  229. case 2:
  230. gpuLoad = toWrite;
  231. break;
  232. case 3:
  233. temp = toWrite;
  234. break;
  235. case 4:
  236. hour = toWrite;
  237. break;
  238. case 5:
  239. minute = toWrite;
  240. break;
  241. default:
  242. break;
  243. }
  244. toWrite = 0;
  245. stepper++;
  246. }
  247. }
  248. oled_set_cursor(0,3);
  249. char *s = make_sys_info_text();
  250. oled_write_ln(s, false);
  251. free(s);
  252. }
  253. };
  254. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  255. switch (keycode) {
  256. case RGB_LAYER:
  257. if (record->event.pressed) {
  258. if (rgbToggled) {
  259. rgbToggled = false;
  260. altToggled = false;
  261. sysToggled = false;
  262. oled_clear();
  263. layer_clear();
  264. } else {
  265. rgbToggled = true;
  266. altToggled = false;
  267. sysToggled = false;
  268. layer_on(_RGB);
  269. }
  270. }
  271. return false;
  272. case ALT_LAYER:
  273. if (record->event.pressed) {
  274. if (altToggled) {
  275. rgbToggled = false;
  276. altToggled = false;
  277. sysToggled = false;
  278. oled_clear();
  279. layer_clear();
  280. } else {
  281. rgbToggled = false;
  282. sysToggled = false;
  283. altToggled = true;
  284. layer_on(_ALT);
  285. }
  286. }
  287. return false;
  288. case SYS_LAYER:
  289. if (record->event.pressed) {
  290. if (sysToggled) {
  291. rgbToggled = false;
  292. altToggled = false;
  293. sysToggled = false;
  294. oled_clear();
  295. layer_clear();
  296. } else {
  297. rgbToggled = false;
  298. sysToggled = true;
  299. altToggled = false;
  300. layer_on(_SYS);
  301. }
  302. }
  303. default:
  304. return true;
  305. }
  306. return false;
  307. };