keymap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* Copyright 2019 ash0x0 2021 peepeetee
  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 "keymap.h"
  18. // // Defines names for use in layer keycodes and the keymap
  19. // enum layer_names {
  20. // _BASE,
  21. // _FN
  22. // };
  23. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  24. [0] = LAYOUT_65_ansi(
  25. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_HOME,
  26. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
  27. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDOWN,
  28. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
  29. KC_LCTL, KC_LGUI,LT(1, KC_LALT), KC_SPC, KC_RALT, MO(1),KC_RCTRL, KC_LEFT, KC_DOWN, KC_RGHT
  30. ),
  31. [1] = LAYOUT_65_ansi(
  32. KC_GRAVE, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_DELETE,
  33. RGB_MOD, RGB_HUI, RGB_VAI, RGB_SAI, RGB_SPI, _______, KC_KP_7, KC_KP_8, KC_KP_9, _______, _______, _______, _______, _______, KC_PGUP,
  34. RGB_TOG, RGB_HUD, RGB_VAD, RGB_SAD, RGB_SPD, _______, KC_KP_4, KC_KP_5, KC_KP_6, _______, _______, _______, _______, KC_PGDOWN,
  35. BL_TOGG, _______, _______, _______, _______, RESET, KC_KP_1, KC_KP_2, KC_KP_3, _______, _______, _______, KC_AUDIO_VOL_UP, KC_END,
  36. _______, _______, _______, _______, _______, _______, _______, KC_BRIGHTNESS_DOWN, KC_AUDIO_VOL_DOWN, KC_BRIGHTNESS_UP
  37. ),
  38. };
  39. /*
  40. Templete
  41. [ ] = LAYOUT_65_ansi(
  42. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  43. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  44. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  45. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  46. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  47. ),
  48. */
  49. #ifdef _______
  50. #undef _______
  51. #define _______ {0, 0, 0}
  52. const uint8_t PROGMEM ledmap[][DRIVER_LED_TOTAL][3] = {
  53. [1] = {
  54. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  55. GREEN, BLUE, {0, 0, 255}, PURPLE, AZURE, _______, {0, 0, 255}, {0, 0, 255}, {0, 0, 255}, _______, _______, _______, _______, _______, _______,
  56. RED, BLUE, {0, 0, 1}, PURPLE, AZURE, _______, {0, 0, 255}, {0, 0, 255}, {0, 0, 255}, _______, _______, _______, _______, _______,
  57. _______, _______, _______, _______, _______, RED, {0, 0, 255}, {0, 0, 255}, {0, 0, 255}, _______, _______, _______, _______, _______,
  58. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  59. }
  60. };
  61. #undef _______
  62. #define _______ KC_TRNS
  63. #endif
  64. void keyboard_post_init_user(void) {
  65. // Call the post init code.
  66. dfa_state = 0; // ENGLISH
  67. }
  68. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  69. switch (keycode) {
  70. case KC_DELETE:
  71. if (record->event.pressed) {
  72. dfa_state = 0;
  73. } else {
  74. // Do something else when release
  75. }
  76. return false; // Skip all further processing of this key
  77. case KC_SPC:
  78. if (record->event.pressed) {
  79. if ((get_mods() & MOD_BIT(KC_LGUI)) == MOD_BIT(KC_LGUI)){
  80. if(dfa_state == 3){
  81. dfa_state = 0;
  82. } else {
  83. dfa_state = dfa_state + 1;
  84. }
  85. }
  86. } else {
  87. // Do something else when release
  88. }
  89. return true; // Continue execution
  90. case KC_HOME:
  91. if (record->event.pressed) {
  92. switch(dfa_state){
  93. case 0 :{
  94. return false;
  95. }
  96. case 1 :{
  97. tap_code16(G(KC_SPC));
  98. wait_ms(100);
  99. tap_code16(G(KC_SPC));
  100. wait_ms(100);
  101. tap_code16(G(KC_SPC));
  102. dfa_state = 0;
  103. return false;
  104. }
  105. case 2 :{
  106. tap_code16(G(KC_SPC));
  107. wait_ms(100);
  108. tap_code16(G(KC_SPC));
  109. dfa_state = 0;
  110. return false;
  111. }
  112. case 3 :{
  113. tap_code16(G(KC_SPC));
  114. dfa_state = 0;
  115. return false;
  116. }
  117. }
  118. // Do something when pressed
  119. } else {
  120. // Do something else when release
  121. }
  122. return false; // Skip all further processing of this key
  123. // case KC_PGUP:
  124. // if (record->event.pressed) {
  125. // switch(dfa_state){
  126. // case 0 :{
  127. // tap_code16(G(KC_SPC));
  128. // dfa_state = 1;
  129. // return false;
  130. // }
  131. // case 1 :{
  132. // return false;
  133. // }
  134. // case 2 :{
  135. // tap_code16(G(KC_SPC));
  136. // wait_ms(100);
  137. // tap_code16(G(KC_SPC));
  138. // wait_ms(100);
  139. // tap_code16(G(KC_SPC));
  140. // dfa_state = 1;
  141. // return false;
  142. // }
  143. // case 3 :{
  144. // tap_code16(G(KC_SPC));
  145. // wait_ms(100);
  146. // tap_code16(G(KC_SPC));
  147. // dfa_state = 1;
  148. // return false;
  149. // }
  150. // }
  151. // // Do something when pressed
  152. // } else {
  153. // // Do something else when release
  154. // }
  155. // return false; // Skip all further processing of this key
  156. // case KC_PGDOWN:
  157. // if (record->event.pressed) {
  158. // switch(dfa_state){
  159. // case 0 :{
  160. // tap_code16(G(KC_SPC));
  161. // wait_ms(100);
  162. // tap_code16(G(KC_SPC));
  163. // dfa_state = 2;
  164. // return false;
  165. // }
  166. // case 1 :{
  167. // tap_code16(G(KC_SPC));
  168. // dfa_state = 2;
  169. // return false;
  170. // }
  171. // case 2 :{
  172. // return false;
  173. // }
  174. // case 3 :{
  175. // tap_code16(G(KC_SPC));
  176. // wait_ms(100);
  177. // tap_code16(G(KC_SPC));
  178. // wait_ms(100);
  179. // tap_code16(G(KC_SPC));
  180. // dfa_state = 2;
  181. // return false;
  182. // }
  183. // }
  184. // // Do something when pressed
  185. // } else {
  186. // // Do something else when release
  187. // }
  188. // return false; // Skip all further processing of this key
  189. // case KC_END:
  190. // if (record->event.pressed) {
  191. // switch(dfa_state){
  192. // case 0 :{
  193. // tap_code16(G(KC_SPC));
  194. // wait_ms(100);
  195. // tap_code16(G(KC_SPC));
  196. // wait_ms(100);
  197. // tap_code16(G(KC_SPC));
  198. // dfa_state = 3;
  199. // return false;
  200. // }
  201. // case 1 :{
  202. // tap_code16(G(KC_SPC));
  203. // wait_ms(100);
  204. // tap_code16(G(KC_SPC));
  205. // dfa_state = 3;
  206. // return false;
  207. // }
  208. // case 2 :{
  209. // tap_code16(G(KC_SPC));
  210. // dfa_state = 3;
  211. // return false;
  212. // }
  213. // case 3 :{
  214. // return false;
  215. // }
  216. // }
  217. // // Do something when pressed
  218. // } else {
  219. // // Do something else when release
  220. // }
  221. // return false; // Skip all further processing of this key
  222. case RGB_TOG:
  223. if (record->event.pressed) {
  224. switch (rgb_matrix_get_flags()) {
  225. case LED_FLAG_ALL: {
  226. rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
  227. rgb_matrix_set_color_all(0, 0, 0);
  228. }
  229. break;
  230. case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
  231. rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
  232. rgb_matrix_set_color_all(0, 0, 0);
  233. }
  234. break;
  235. case LED_FLAG_UNDERGLOW: {
  236. rgb_matrix_set_flags(LED_FLAG_NONE);
  237. rgb_matrix_disable_noeeprom();
  238. }
  239. break;
  240. default: {
  241. rgb_matrix_set_flags(LED_FLAG_ALL);
  242. rgb_matrix_enable_noeeprom();
  243. }
  244. break;
  245. }
  246. }
  247. return false;
  248. default:
  249. return true; // Process all other keycodes normally
  250. }
  251. }
  252. void set_layer_color(int layer) {
  253. if (layer == 0) { return; }
  254. for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
  255. HSV hsv = {
  256. .h = pgm_read_byte(&ledmap[layer][i][0]),
  257. .s = pgm_read_byte(&ledmap[layer][i][1]),
  258. .v = pgm_read_byte(&ledmap[layer][i][2]),
  259. };
  260. if (hsv.h || hsv.s || hsv.v) {
  261. RGB rgb = hsv_to_rgb(hsv);
  262. float f = (float)rgb_matrix_config.hsv.v / UINT8_MAX;
  263. rgb_matrix_set_color(i, f * rgb.r, f * rgb.g, f * rgb.b);
  264. } else if (layer != 1) {
  265. // Only deactivate non-defined key LEDs at layers other than FN. Because at FN we have RGB adjustments and need to see them live.
  266. // If the values are all false then it's a transparent key and deactivate LED at this layer
  267. rgb_matrix_set_color(i, 0, 0, 0);
  268. }
  269. }
  270. }
  271. void rgb_matrix_indicators_user(void) {
  272. led_t host_leds = host_keyboard_led_state();
  273. if (host_leds.caps_lock) {
  274. //rgb_matrix_set_color(30, 0xFF, 0xFF, 0xFF);
  275. rgb_matrix_set_color(30, 0x0, 0x0, 0x0);
  276. } else {
  277. //rgb_matrix_set_color(30, 0x0, 0x0, 0x0);
  278. }
  279. set_layer_color(get_highest_layer(layer_state));
  280. }