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.

681 lines
32 KiB

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