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.

680 lines
32 KiB

1 year ago
  1. /* Copyright 2021 Glorious, LLC <salman@pcgamingrace.com>
  2. Copyright 2021 Jonavin Eng @Jonavin
  3. Copyright 2022 gourdo1 <gourdo1@outlook.com>
  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 2 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. // Note: Several advanced functions referenced in this file (like Tap Dance functions) are defined in /users/gourdo1/gourdo1.c
  16. #include QMK_KEYBOARD_H
  17. #include "rgb_matrix_map.h"
  18. #include "gourdo1.h"
  19. #include "paddlegame.h"
  20. #include <math.h>
  21. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  22. /* Base Layout
  23. *
  24. * ,-------------------------------------------------------------------------------------------------------------.
  25. * | Esc || F1 | F2 | F3 | F4 || F5 | F6 | F7 | F8 || F9 | F10 | F11 | F12 || Home || Mute |
  26. * |=============================================================================================================|
  27. * | ` ~ | 1 ! | 2 @ | 3 # | 4 $ | 5 % | 6 ^ | 7 & | 8 * | 9 ( | 0 ) | - _ | = + | Backspc || Del |
  28. * |------+------+------+------+------+------+------+------+------+------+------+------+------+----------++------|
  29. * | Tab | Q | W | E | R | T | Y | U | I | O | P | [ } | ] } | \ | || PgUp |
  30. * |---------+------+------+------+------+------+------+------+------+------+------+------+------+-------++------|
  31. * | Capslock | A | S | D | F | G | H | J | K | L | ; : | ' " | Enter || PgDn |
  32. * |------------+------+------+------+-----+------+------+------+------+------+------+------|----+========+------|
  33. * | LShift | Z | X | C | V | B | N | M | , < | . > | / ? | RShift || Up || End |
  34. * |--------------+------+------+------+------+------+------+------+------+------+------+--+=====++------++======|
  35. * | Ctrl | Win | LAlt | Space | RAlt | Fn | Ctrl || Left | Down | Rght |
  36. * `------------------------------------------------------------------------------------------------------------'
  37. */
  38. [_BASE] = LAYOUT(
  39. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, LEFTOFENC, ENCFUNC,
  40. KC_GRV, 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, BELOWENC,
  41. 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,
  42. CAPSNUM, 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_PGDN,
  43. LSFTCAPSWIN, 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,
  44. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(_FN1),KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
  45. ),
  46. /* FN1 Layout
  47. *
  48. * ,-------------------------------------------------------------------------------------------------------------.
  49. * | Esc ||MyCmp |WbHom | Calc |MdSel ||MdPrv |MdNxt |MdPly |MdStp ||VolDn |VolUp |PrScr |ScrLk ||Pause ||Sleep |
  50. * |=============================================================================================================|
  51. * | ____ | ____ | ____ | ____ | ____ | ____ | ____ | ____ | ____ | ____ | ____ |RGBTOD|RGBTOI| ________ ||RGBTOG|
  52. * |------+------+------+------+------+------+------+------+------+------+------+------+------+----------++------|
  53. * | ______ |RGBSAD|RGBVAI|RGBSAI| NKRO | ____ |YAHOO | ____ | ____ |OUTLK |Pause | ____ | ____ | Reset || Home |
  54. * |---------+------+------+------+------+------+------+------+------+------+------+------+------+-------++------|
  55. * | Capslock |RGBHUD|RGBVAD|RGBHUI| ____|GMAIL |HTMAIL| ____ | ____ | ____ | ____ | ____ | __________ || End |
  56. * |------------+------+------+------+-----+------+------+------+------+------+------+------|----+========+------|
  57. * | __________ |RGBNIT| ____ | ____ | ____ | ____ |NumLk | ____ | ____ |DOTCOM| CAD | ______ ||RGBMOD|| ____ |
  58. * |--------------+------+------+------+------+------+------+------+------+------+------+--+=====++------++======|
  59. * | ____ | WinKyLk | ____ | _____ | ____ | ____ | ____ ||RGBSPD|RGBRMD|RGBSPI|
  60. * `------------------------------------------------------------------------------------------------------------'
  61. */
  62. #ifdef GAME_ENABLE
  63. [_FN1] = LAYOUT(
  64. EE_CLR, KC_MYCM, KC_WHOM, KC_CALC, KC_MSEL, KC_MPRV, KC_MNXT, KC_MPLY, KC_MSTP, KC_VOLD, KC_VOLU, KC_PSCR, KC_SLCK, KC_PAUS, KC_SLEP,
  65. PRNCONF, TG_CAPS, TG_PAD, TG_ESC, TG_DEL, TG_TDCAP,TG_ENC, TG_INS,TG_CTLSPC, _______, _______, RGB_TOD, RGB_TOI, _______, RGB_TOG,
  66. _______, RGB_SAD, RGB_VAI, RGB_SAI, NK_TOGG, _______, YAHOO, _______, _______, OUTLOOK, TG(_GAME),SWAP_L, SWAP_R, RESET, KC_HOME,
  67. KC_CAPS, RGB_HUD, RGB_VAD, RGB_HUI, _______, GMAIL, HOTMAIL, _______, _______, LOCKPC, _______, _______, _______, KC_END,
  68. _______, RGB_NITE,_______, _______, _______, _______, KC_NLCK, _______, _______, DOTCOM, KC_CAD, _______, RGB_MOD, _______,
  69. _______, WINLOCK, _______, _______, _______, _______, _______, RGB_SPD, RGB_RMOD, RGB_SPI
  70. ),
  71. [_GAME] = LAYOUT(
  72. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  73. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  74. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  75. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  76. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  77. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  78. ),
  79. #else
  80. [_FN1] = LAYOUT(
  81. EE_CLR, KC_MYCM, KC_WHOM, KC_CALC, KC_MSEL, KC_MPRV, KC_MNXT, KC_MPLY, KC_MSTP, KC_VOLD, KC_VOLU, KC_PSCR, KC_SLCK, KC_PAUS, KC_SLEP,
  82. PRNCONF, TG_CAPS, TG_PAD, TG_ESC, TG_DEL, TG_TDCAP,TG_ENC, TG_INS,TG_CTLSPC, _______, _______, RGB_TOD, RGB_TOI, _______, RGB_TOG,
  83. _______, RGB_SAD, RGB_VAI, RGB_SAI, NK_TOGG, _______, YAHOO, _______, _______, OUTLOOK, KC_PAUS, SWAP_L, SWAP_R, RESET, KC_HOME,
  84. KC_CAPS, RGB_HUD, RGB_VAD, RGB_HUI, _______, GMAIL, HOTMAIL, _______, _______, LOCKPC, _______, _______, _______, KC_END,
  85. _______, RGB_NITE,_______, _______, _______, _______, KC_NLCK, _______, _______, DOTCOM, KC_CAD, _______, RGB_MOD, _______,
  86. _______, KC_WINLCK, _______, _______, _______, _______, _______, RGB_SPD, RGB_RMOD, RGB_SPI
  87. ),
  88. #endif //GAME_ENABLE
  89. /* _NUMPADMOUSE Layout
  90. * Note: A symbol preceded by "P" is a Numpad-encoded version of the key -- any app that differentiates will recognize the char as coming from a physical numpad.
  91. * ,-------------------------------------------------------------------------------------------------------------.
  92. * | ____ || ____ | ____ | ____ | ____ || ____ | ____ | ____ | ____ || ____ | ____ | ____ | ____ || ____ || ____ |
  93. * |=============================================================================================================|
  94. * | ____ | P1 | P2 | P3 | P4 | P5 | P6 | P7 | P8 | P9 | P0 | P- | P+ | ________ || ____ |
  95. * |------+------+------+------+------+------+------+------+------+------+------+------+------+----------++------|
  96. * | ______ | PGUP | Up | PGDN | None | None | None | P4 | P5 | P6 | P+ | ____ | ____ | _____ || WhUp |
  97. * |---------+------+------+------+------+------+------+------+------+------+------+------+------+-------++------|
  98. * | ________ | Left | Down | Rght | None| None | None | P1 | P2 | P3 | P* | ____ | P-Enter || WhDn |
  99. * |------------+------+------+------+-----+------+------+------+------+------+------+------|----+========+------|
  100. * | __________ | None | ____ | ____ | ____ | None | None | 0 | 00 | P. | P/ | MBt1 ||MS_UP || MBt2 |
  101. * |--------------+------+------+------+------+------+------+------+------+------+------+--+=====++------++======|
  102. * | ____ | ____ | ____ | _____ | ____ | ____ | MBt3 ||MS_LT |MS_DN |MS_RT |
  103. * `------------------------------------------------------------------------------------------------------------'
  104. */
  105. [_NUMPADMOUSE] = LAYOUT(
  106. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  107. _______, KC_P1, KC_P2, KC_P3, KC_P4, KC_P5, KC_P6, KC_P7, KC_P8, KC_P9, KC_P0, KC_PMNS, KC_PPLS, _______, _______,
  108. _______, KC_PGUP, KC_UP, KC_PGDN, KC_NO, KC_NO, KC_NO, KC_P4, KC_P5, KC_P6, KC_PPLS, _______, _______, _______, KC_WH_U,
  109. _______, KC_LEFT, KC_DOWN, KC_RGHT, KC_NO, KC_NO, KC_NO, KC_P1, KC_P2, KC_P3, KC_PAST, _______, KC_PENT, KC_WH_D,
  110. _______, KC_NO, _______, _______, _______, KC_NO, KC_NO, KC_P0, KC_00, KC_PDOT, KC_PSLS, KC_BTN1, KC_MS_U, KC_BTN2,
  111. _______, _______, _______, KC_PENT, _______, _______, KC_BTN3, KC_MS_L, KC_MS_D, KC_MS_R
  112. ),
  113. [_MOUSEKEY] = LAYOUT(
  114. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  115. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  116. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_WH_U,
  117. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_WH_D,
  118. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN1, KC_MS_U, KC_BTN2,
  119. _______, _______, _______, _______, _______, _______, KC_BTN3, KC_MS_L, KC_MS_D, KC_MS_R
  120. ),
  121. #ifdef COLEMAK_LAYER_ENABLE
  122. [_COLEMAK] = LAYOUT(
  123. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
  124. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, _______, _______,
  125. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
  126. _______, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, KC_ENT, KC_PGDN,
  127. _______, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
  128. _______, _______, _______, KC_SPC, KC_RALT, _______, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
  129. ),
  130. #endif // COLEMAK_LAYER_ENABLE
  131. };
  132. #if defined(ENCODER_ENABLE) && !defined(ENCODER_DEFAULTACTIONS_ENABLE) // Encoder Functionality when not using userspace defaults
  133. void encoder_action_rgbhue(bool clockwise) {
  134. if (clockwise)
  135. rgblight_increase_hue_noeeprom();
  136. else
  137. rgblight_decrease_hue_noeeprom();
  138. }
  139. bool encoder_update_user(uint8_t index, bool clockwise) {
  140. uint8_t mods_state = get_mods();
  141. if (mods_state & MOD_BIT(KC_LSFT)) { // If you are holding L shift, encoder changes layers
  142. encoder_action_layerchange(clockwise);
  143. } else if (mods_state & MOD_BIT(KC_RSFT)) { // If you are holding R shift, Page up/dn
  144. unregister_mods(MOD_BIT(KC_RSFT));
  145. encoder_action_navpage(clockwise);
  146. register_mods(MOD_BIT(KC_RSFT));
  147. } else if (mods_state & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next/prev word
  148. encoder_action_navword(clockwise);
  149. } else if (mods_state & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, change rgb hue/colour
  150. encoder_action_rgbhue(clockwise);
  151. } else if (mods_state & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next/prev track
  152. encoder_action_mediatrack(clockwise);
  153. } else {
  154. switch (get_highest_layer(layer_state)) {
  155. case _FN1:
  156. #ifdef IDLE_TIMEOUT_ENABLE
  157. timeout_update_threshold(clockwise);
  158. #endif
  159. break;
  160. #ifdef GAME_ENABLE
  161. case _GAME:
  162. // Game: Paddle movement
  163. if (damage_count == 0) {
  164. if (clockwise) {
  165. if (paddle_pos_full < 15) ++paddle_pos_full;
  166. } else {
  167. if (paddle_pos_full > 0) --paddle_pos_full;
  168. }
  169. }
  170. break;
  171. #endif //GAME_ENABLE
  172. default:
  173. encoder_action_volume(clockwise); // Otherwise it just changes volume
  174. break;
  175. }
  176. }
  177. //return true; //set to return false to counteract enabled encoder in pro.c
  178. return false;
  179. }
  180. #endif // ENCODER_ENABLE && !ENCODER_DEFAULTACTIONS_ENABLE
  181. #ifdef RGB_MATRIX_ENABLE
  182. // Game logic
  183. #ifdef GAME_ENABLE
  184. void init_ball(uint8_t i) {
  185. i &= 1;
  186. ball[i].on = true;
  187. ball[i].up = false;
  188. ball[i].y = 0;
  189. ball[i].x = rand() % 16;
  190. // Set initial ball state
  191. if (ball[i].x < 8) {
  192. ball[i].left = false;
  193. } else {
  194. ball[i].x -= 4;
  195. ball[i].left = true;
  196. }
  197. // 1/4 chance of being an enemy ball after level 6
  198. if (level_number > 3) {
  199. ball[i].enemy = ((rand() % 4) == 0);
  200. } else {
  201. ball[i].enemy = false;
  202. }
  203. }
  204. void hurt_paddle(void) {
  205. if (paddle_lives > 0) {
  206. --paddle_lives;
  207. }
  208. damage_timer = timer_read();
  209. damage_count = 10;
  210. // Reset board
  211. init_ball(0);
  212. ball[1].on = false;
  213. }
  214. #endif //GAME_ENABLE
  215. // Capslock, Scroll lock and Numlock indicator on Left side lights.
  216. void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
  217. if (get_rgb_nightmode()) rgb_matrix_set_color_all(RGB_OFF);
  218. // Scroll Lock RGB setup
  219. if (IS_HOST_LED_ON(USB_LED_SCROLL_LOCK)) {
  220. rgb_matrix_set_color(LED_L3, RGB_RED);
  221. rgb_matrix_set_color(LED_L4, RGB_RED);
  222. rgb_matrix_set_color(LED_TAB, RGB_RED);
  223. rgb_matrix_set_color(LED_F12, RGB_RED);
  224. }
  225. // System NumLock warning indicator RGB setup
  226. #ifdef INVERT_NUMLOCK_INDICATOR
  227. if (!IS_HOST_LED_ON(USB_LED_NUM_LOCK)) { // on if NUM lock is OFF to bring attention to overlay numpad not functional when enabled
  228. rgb_matrix_set_color(LED_GRV, RGB_ORANGE2);
  229. rgb_matrix_set_color(LED_L1, RGB_ORANGE2);
  230. rgb_matrix_set_color(LED_L2, RGB_ORANGE2);
  231. rgb_matrix_set_color(LED_N, RGB_ORANGE2);
  232. rgb_matrix_set_color(LED_FN, RGB_ORANGE2);
  233. }
  234. #else
  235. if (IS_HOST_LED_ON(USB_LED_NUM_LOCK)) { // Normal, on if NUM lock is ON
  236. rgb_matrix_set_color(LED_GRV, RGB_ORANGE2);
  237. rgb_matrix_set_color(LED_L1, RGB_ORANGE2);
  238. rgb_matrix_set_color(LED_L2, RGB_ORANGE2);
  239. rgb_matrix_set_color(LED_N, RGB_ORANGE2);
  240. rgb_matrix_set_color(LED_FN, RGB_ORANGE2);
  241. }
  242. #endif // INVERT_NUMLOCK_INDICATOR
  243. // CapsLock RGB setup
  244. if (IS_HOST_LED_ON(USB_LED_CAPS_LOCK)) {
  245. if (user_config.rgb_hilite_caps) {
  246. for (uint8_t i = 0; i < ARRAYSIZE(LED_LIST_LETTERS); i++) {
  247. rgb_matrix_set_color(LED_LIST_LETTERS[i], RGB_CHARTREUSE);
  248. }
  249. rgb_matrix_set_color(LED_L7, RGB_CHARTREUSE);
  250. rgb_matrix_set_color(LED_L8, RGB_CHARTREUSE);
  251. rgb_matrix_set_color(LED_LSFT, RGB_CHARTREUSE);
  252. }
  253. else {
  254. rgb_matrix_set_color(LED_L7, RGB_CHARTREUSE);
  255. rgb_matrix_set_color(LED_L8, RGB_CHARTREUSE);
  256. rgb_matrix_set_color(LED_LSFT, RGB_CHARTREUSE);
  257. }
  258. }
  259. // Winkey disabled (gaming) mode RGB setup
  260. if (keymap_config.no_gui) {
  261. rgb_matrix_set_color(LED_LWIN, RGB_RED); //light up Winkey red when disabled
  262. rgb_matrix_set_color(LED_W, RGB_CHARTREUSE); //light up gaming keys with WSAD higlighted
  263. rgb_matrix_set_color(LED_S, RGB_CHARTREUSE);
  264. rgb_matrix_set_color(LED_A, RGB_CHARTREUSE);
  265. rgb_matrix_set_color(LED_D, RGB_CHARTREUSE);
  266. rgb_matrix_set_color(LED_Q, RGB_ORANGE2);
  267. rgb_matrix_set_color(LED_E, RGB_ORANGE2);
  268. rgb_matrix_set_color(LED_R, RGB_ORANGE2);
  269. rgb_matrix_set_color(LED_TAB, RGB_ORANGE2);
  270. rgb_matrix_set_color(LED_F, RGB_ORANGE2);
  271. rgb_matrix_set_color(LED_Z, RGB_ORANGE2);
  272. rgb_matrix_set_color(LED_X, RGB_ORANGE2);
  273. rgb_matrix_set_color(LED_C, RGB_ORANGE2);
  274. rgb_matrix_set_color(LED_V, RGB_ORANGE2);
  275. rgb_matrix_set_color(LED_SPC, RGB_ORANGE2);
  276. rgb_matrix_set_color(LED_LCTL, RGB_ORANGE2);
  277. rgb_matrix_set_color(LED_LSFT, RGB_ORANGE2);
  278. }
  279. // Fn selector mode RGB setup
  280. switch (get_highest_layer(layer_state)) { // special handling per layer
  281. case _FN1: // on Fn layer select what the encoder does when pressed
  282. rgb_matrix_set_color(LED_FN, RGB_RED); //FN key
  283. //NEW RGB LIGHTING TO RING KEYBOARD ON FN LAYER ACTIVATION:
  284. for (uint8_t j = 0; j < ARRAYSIZE(LED_LIST_FUNCROW); j++) {
  285. rgb_matrix_set_color(LED_LIST_FUNCROW[j], RGB_RED);
  286. }
  287. rgb_matrix_set_color(LED_LCTL, RGB_RED);
  288. rgb_matrix_set_color(LED_LALT, RGB_RED);
  289. rgb_matrix_set_color(LED_SPC, RGB_RED);
  290. rgb_matrix_set_color(LED_LWIN, RGB_RED);
  291. //rgb_matrix_set_color(LED_RALT, RGB_RED);
  292. rgb_matrix_set_color(LED_FN, RGB_OFFBLUE);
  293. //rgb_matrix_set_color(LED_RCTL, RGB_RED);
  294. rgb_matrix_set_color(LED_BSLS, RGB_RED);
  295. rgb_matrix_set_color(LED_L1, RGB_RED);
  296. rgb_matrix_set_color(LED_L2, RGB_RED);
  297. rgb_matrix_set_color(LED_L3, RGB_RED);
  298. rgb_matrix_set_color(LED_L4, RGB_RED);
  299. rgb_matrix_set_color(LED_L5, RGB_RED);
  300. rgb_matrix_set_color(LED_L6, RGB_RED);
  301. rgb_matrix_set_color(LED_L7, RGB_RED);
  302. rgb_matrix_set_color(LED_L8, RGB_RED);
  303. rgb_matrix_set_color(LED_DOWN, RGB_RED);
  304. rgb_matrix_set_color(LED_LEFT, RGB_RED);
  305. rgb_matrix_set_color(LED_RIGHT, RGB_RED);
  306. rgb_matrix_set_color(LED_R1, RGB_RED);
  307. rgb_matrix_set_color(LED_R2, RGB_RED);
  308. rgb_matrix_set_color(LED_R3, RGB_RED);
  309. rgb_matrix_set_color(LED_R4, RGB_RED);
  310. rgb_matrix_set_color(LED_R5, RGB_RED);
  311. rgb_matrix_set_color(LED_R6, RGB_RED);
  312. rgb_matrix_set_color(LED_R7, RGB_RED);
  313. rgb_matrix_set_color(LED_R8, RGB_RED);
  314. rgb_matrix_set_color(LED_MINS, RGB_OFFBLUE);
  315. rgb_matrix_set_color(LED_EQL, RGB_OFFBLUE);
  316. #ifdef GAME_ENABLE
  317. rgb_matrix_set_color(LED_P, RGB_CHARTREUSE);
  318. #else
  319. rgb_matrix_set_color(LED_P, RGB_RED);
  320. #endif // GAME_ENABLE
  321. //Add RGB statuses for user.config toggles
  322. if (user_config.rgb_hilite_caps) {
  323. rgb_matrix_set_color(LED_1, RGB_GREEN);
  324. } else {
  325. rgb_matrix_set_color(LED_1, RGB_PURPLE);
  326. }
  327. if (user_config.rgb_hilite_numpad) {
  328. rgb_matrix_set_color(LED_2, RGB_GREEN);
  329. } else {
  330. rgb_matrix_set_color(LED_2, RGB_PURPLE);
  331. }
  332. if (user_config.esc_double_tap_to_baselyr) {
  333. rgb_matrix_set_color(LED_3, RGB_GREEN);
  334. } else {
  335. rgb_matrix_set_color(LED_3, RGB_PURPLE);
  336. }
  337. if (user_config.del_right_home_top) {
  338. rgb_matrix_set_color(LED_4, RGB_GREEN);
  339. } else {
  340. rgb_matrix_set_color(LED_4, RGB_PURPLE);
  341. }
  342. if (user_config.double_tap_shift_for_capslock) {
  343. rgb_matrix_set_color(LED_5, RGB_GREEN);
  344. } else {
  345. rgb_matrix_set_color(LED_5, RGB_PURPLE);
  346. }
  347. if (user_config.encoder_press_mute_or_media) {
  348. rgb_matrix_set_color(LED_6, RGB_GREEN);
  349. } else {
  350. rgb_matrix_set_color(LED_6, RGB_PURPLE);
  351. }
  352. if (user_config.ins_on_shft_bkspc_or_del) {
  353. rgb_matrix_set_color(LED_7, RGB_GREEN);
  354. } else {
  355. rgb_matrix_set_color(LED_7, RGB_PURPLE);
  356. }
  357. if (user_config.disable_ctrl_space) {
  358. rgb_matrix_set_color(LED_8, RGB_GREEN);
  359. } else {
  360. rgb_matrix_set_color(LED_8, RGB_PURPLE);
  361. }
  362. // Add RGB Timeout Indicator -- shows 0 to 139 using F row and num row; larger numbers using 16bit code
  363. uint16_t timeout_threshold = get_timeout_threshold();
  364. if (timeout_threshold <= 10) rgb_matrix_set_color(LED_LIST_FUNCROW[timeout_threshold], RGB_BLUE);
  365. else if (timeout_threshold < 140) {
  366. rgb_matrix_set_color(LED_LIST_FUNCROW[(timeout_threshold / 10)], RGB_CYAN);
  367. rgb_matrix_set_color(LED_LIST_FUNCROW[(timeout_threshold % 10)], RGB_BLUE);
  368. } else { // >= 140 minutes, just show these 3 lights
  369. rgb_matrix_set_color(LED_LIST_FUNCROW[10], RGB_CYAN);
  370. rgb_matrix_set_color(LED_LIST_FUNCROW[11], RGB_CYAN);
  371. rgb_matrix_set_color(LED_LIST_FUNCROW[12], RGB_CYAN);
  372. }
  373. break;
  374. // Numpad & Mouse Keys overlay RGB
  375. case _NUMPADMOUSE:
  376. if (user_config.rgb_hilite_numpad) {
  377. for (uint8_t i = 0; i < ARRAYSIZE(LED_LIST_NUMPAD); i++) {
  378. rgb_matrix_set_color(LED_LIST_NUMPAD[i], RGB_OFFBLUE);
  379. }
  380. rgb_matrix_set_color(LED_L5, RGB_OFFBLUE);
  381. rgb_matrix_set_color(LED_L6, RGB_OFFBLUE);
  382. rgb_matrix_set_color(LED_CAPS, RGB_OFFBLUE);
  383. rgb_matrix_set_color(LED_UP, RGB_CHARTREUSE);
  384. rgb_matrix_set_color(LED_DOWN, RGB_CHARTREUSE);
  385. rgb_matrix_set_color(LED_LEFT, RGB_CHARTREUSE);
  386. rgb_matrix_set_color(LED_RIGHT, RGB_CHARTREUSE);
  387. rgb_matrix_set_color(LED_RCTL, RGB_CHARTREUSE);
  388. rgb_matrix_set_color(LED_RSFT, RGB_CHARTREUSE);
  389. rgb_matrix_set_color(LED_END, RGB_CHARTREUSE);
  390. rgb_matrix_set_color(LED_PGUP, RGB_CHARTREUSE);
  391. rgb_matrix_set_color(LED_PGDN, RGB_CHARTREUSE);
  392. } else {
  393. rgb_matrix_set_color(LED_L5, RGB_OFFBLUE);
  394. rgb_matrix_set_color(LED_L6, RGB_OFFBLUE);
  395. rgb_matrix_set_color(LED_CAPS, RGB_OFFBLUE);
  396. }
  397. break;
  398. // MOUSEKEYS mode RGB
  399. case _MOUSEKEY:
  400. rgb_matrix_set_color(LED_UP, RGB_CHARTREUSE);
  401. rgb_matrix_set_color(LED_DOWN, RGB_CHARTREUSE);
  402. rgb_matrix_set_color(LED_LEFT, RGB_CHARTREUSE);
  403. rgb_matrix_set_color(LED_RIGHT, RGB_CHARTREUSE);
  404. rgb_matrix_set_color(LED_RCTL, RGB_CYAN);
  405. rgb_matrix_set_color(LED_RSFT, RGB_CYAN);
  406. rgb_matrix_set_color(LED_END, RGB_CYAN);
  407. rgb_matrix_set_color(LED_PGUP, RGB_OFFBLUE);
  408. rgb_matrix_set_color(LED_PGDN, RGB_OFFBLUE);
  409. break;
  410. // Colemak layer RGB
  411. #ifdef COLEMAK_LAYER_ENABLE
  412. case _COLEMAK:
  413. for (uint8_t i = 0; i < ARRAYSIZE(LED_SIDE_RIGHT); i++) {
  414. rgb_matrix_set_color(LED_SIDE_RIGHT[i], RGB_MAGENTA);
  415. rgb_matrix_set_color(LED_SIDE_LEFT[i], RGB_MAGENTA);
  416. }
  417. break;
  418. #endif
  419. // Paddle game logic
  420. #ifdef GAME_ENABLE
  421. case _GAME:
  422. if (!game_start) {
  423. srand((unsigned int) timer_read());
  424. // Store user light settings
  425. last_hsv = rgb_matrix_get_hsv();
  426. rgb_matrix_sethsv_noeeprom(0, 0, 0);
  427. paddle_pos_full = 8;
  428. paddle_lives = 4;
  429. bounce_count = 0;
  430. level_number = 0;
  431. damage_count = 0;
  432. init_ball(0);
  433. ball[1].on = false;
  434. ball_timer = timer_read();
  435. game_start = true;
  436. }
  437. // Set level indicator
  438. if (level_number < 12) {
  439. rgb_matrix_set_color(GAME_R0[level_number], RGB_BLUE);
  440. }
  441. // Set life bar
  442. for (uint8_t i = 0; i < paddle_lives; i++) {
  443. rgb_matrix_set_color(GAME_LIVES[i], RGB_GREEN);
  444. }
  445. uint8_t paddle_pos = paddle_pos_full >> 1;
  446. if (damage_count > 0) {
  447. // Flash paddle when receiving damage
  448. if (timer_elapsed(damage_timer) > 500) {
  449. --damage_count;
  450. damage_timer = timer_read();
  451. }
  452. if ((damage_count & 1) == 0) {
  453. for (uint8_t i = 0; i < 3; i++) {
  454. rgb_matrix_set_color(GAME_PADDLE[paddle_pos + i], RGB_RED);
  455. }
  456. }
  457. if (damage_count == 0) {
  458. ball_timer = timer_read();
  459. }
  460. } else if (paddle_lives == 0) {
  461. // Game over
  462. for (uint8_t i = 0; i < sizeof(LED_GAME_OVER) / sizeof(LED_GAME_OVER[0]); i++) {
  463. rgb_matrix_set_color(LED_GAME_OVER[i], RGB_RED);
  464. }
  465. } else if (level_number >= 12) {
  466. // You win
  467. if (rgb_value.r == 0xff && rgb_value.g < 0xff) {
  468. if (rgb_value.b > 0) {
  469. --rgb_value.b;
  470. } else {
  471. ++rgb_value.g;
  472. }
  473. } else if (rgb_value.g == 0xff && rgb_value.b < 0xff) {
  474. if (rgb_value.r > 0) {
  475. --rgb_value.r;
  476. } else {
  477. ++rgb_value.b;
  478. }
  479. } else if (rgb_value.b == 0xff && rgb_value.r < 0xff) {
  480. if (rgb_value.g > 0) {
  481. --rgb_value.g;
  482. } else {
  483. ++rgb_value.r;
  484. }
  485. }
  486. for (uint8_t i = 0; i < 3; i++) {
  487. rgb_matrix_set_color(GAME_PADDLE[paddle_pos + i], rgb_value.r, rgb_value.g, rgb_value.b);
  488. }
  489. rgb_matrix_set_color(GAME_SMILE1[paddle_pos], rgb_value.r, rgb_value.g, rgb_value.b);
  490. rgb_matrix_set_color(GAME_SMILE1[paddle_pos + 3], rgb_value.r, rgb_value.g, rgb_value.b);
  491. rgb_matrix_set_color(GAME_SMILE2[paddle_pos], rgb_value.r, rgb_value.g, rgb_value.b);
  492. rgb_matrix_set_color(GAME_SMILE2[paddle_pos + 3], rgb_value.r, rgb_value.g, rgb_value.b);
  493. } else {
  494. // normal game loop
  495. // Set paddle position
  496. for (uint8_t i = 0; i < 3; i++) {
  497. rgb_matrix_set_color(GAME_PADDLE[paddle_pos + i], RGB_GREEN);
  498. }
  499. // Ball movement logic happens at intervals
  500. if (timer_elapsed(ball_timer) > GAME_TIMER[level_number]) {
  501. for (int i = 0; i < 2; ++i) {
  502. if (ball[i].on) {
  503. // Ball movement
  504. if (ball[i].up) {
  505. if (ball[i].y > 0) {
  506. --ball[i].y;
  507. if (!ball[i].left) ++ball[i].x;
  508. } else {
  509. // Count reflections. If > 10, increase level
  510. ++bounce_count;
  511. if (bounce_count >= 10) {
  512. bounce_count = 0;
  513. ++level_number;
  514. }
  515. ball[i].on = false;
  516. }
  517. } else {
  518. ++ball[i].y;
  519. if (ball[i].left) --ball[i].x;
  520. if (ball[i].y > 4) {
  521. // Remove a life if ball isn't returned and isn't enemy
  522. if (!ball[i].enemy) {
  523. hurt_paddle();
  524. i = 2;
  525. } else {
  526. ball[i].on = false;
  527. }
  528. }
  529. }
  530. }
  531. }
  532. if (ball[0].y == 4 && !ball[1].on) {
  533. init_ball(1);
  534. }
  535. if (ball[1].y == 4 && !ball[0].on) {
  536. init_ball(0);
  537. }
  538. if (!ball[0].on && !ball[1].on) {
  539. init_ball(0);
  540. }
  541. ball_timer = timer_read();
  542. }
  543. // Other ball stuff
  544. for (int i = 0; i < 2; ++i) {
  545. if (ball[i].on) {
  546. // Ball deflection logic
  547. if (!ball[i].up && ball[i].y == 4 && (ball[i].x == paddle_pos || ball[i].x == paddle_pos - 1 || ball[i].x == paddle_pos + 1)) {
  548. if (!ball[i].enemy) {
  549. --ball[i].y;
  550. if (!ball[i].left) {
  551. ++ball[i].x;
  552. }
  553. ball[i].up = true;
  554. } else {
  555. hurt_paddle();
  556. i = 2;
  557. }
  558. }
  559. // Ball display
  560. switch (ball[i].y) {
  561. case 0:
  562. if (ball[i].enemy) {
  563. rgb_matrix_set_color(GAME_R0[ball[i].x], RGB_RED);
  564. } else {
  565. rgb_matrix_set_color(GAME_R0[ball[i].x], RGB_WHITE);
  566. }
  567. break;
  568. case 1:
  569. if (ball[i].enemy) {
  570. rgb_matrix_set_color(GAME_R1[ball[i].x], RGB_RED);
  571. } else {
  572. rgb_matrix_set_color(GAME_R1[ball[i].x], RGB_WHITE);
  573. }
  574. break;
  575. case 2:
  576. if (ball[i].enemy) {
  577. rgb_matrix_set_color(GAME_R2[ball[i].x], RGB_RED);
  578. } else {
  579. rgb_matrix_set_color(GAME_R2[ball[i].x], RGB_WHITE);
  580. }
  581. break;
  582. case 3:
  583. if (ball[i].enemy) {
  584. rgb_matrix_set_color(GAME_R3[ball[i].x], RGB_RED);
  585. } else {
  586. rgb_matrix_set_color(GAME_R3[ball[i].x], RGB_WHITE);
  587. }
  588. break;
  589. case 4:
  590. if (ball[i].enemy) {
  591. rgb_matrix_set_color(GAME_R4[ball[i].x], RGB_RED);
  592. } else {
  593. rgb_matrix_set_color(GAME_R4[ball[i].x], RGB_WHITE);
  594. }
  595. break;
  596. }
  597. }
  598. }
  599. }
  600. break;
  601. #endif //GAME_ENABLE
  602. default:
  603. #ifdef GAME_ENABLE
  604. if (game_start) {
  605. // Reset lighting settings
  606. game_start = false;
  607. rgb_matrix_sethsv_noeeprom(last_hsv.h, last_hsv.s, last_hsv.v);
  608. }
  609. #endif //GAME_ENABLE
  610. break;
  611. }
  612. }
  613. #endif
  614. void keyboard_post_init_keymap(void) {
  615. // keyboard_post_init_user() moved to userspace
  616. #ifdef RGB_MATRIX_ENABLE
  617. activate_rgb_nightmode(false); // Set to true if you want to startup in nightmode, otherwise use Fn + Z to toggle
  618. #endif
  619. }