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.

172 lines
5.9 KiB

  1. /* Copyright 2020 Brandon Schlack
  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 "brandonschlack.h"
  17. // Super CMD↯TAB
  18. bool is_cmd_tab_active = false;
  19. uint16_t cmd_tab_timer = 0;
  20. __attribute__ ((weak))
  21. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  22. return true;
  23. }
  24. // Consolidated Macros
  25. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  26. switch (keycode) {
  27. case QM_MAKE: // Sends 'qmk compile' or 'qmk flash'
  28. if (record->event.pressed) {
  29. bool flash = false;
  30. // If is a keyboard and auto-flash is not set in rules.mk,
  31. // then Shift will trigger the flash command
  32. #if !defined(FLASH_BOOTLOADER) && !defined(IS_MACROPAD)
  33. uint8_t temp_mod = get_mods();
  34. uint8_t temp_osm = get_oneshot_mods();
  35. clear_mods();
  36. clear_oneshot_mods();
  37. if ( (temp_mod | temp_osm) & MOD_MASK_SHIFT )
  38. #endif
  39. {
  40. flash = true;
  41. }
  42. send_make_command(flash);
  43. }
  44. break;
  45. case QM_FLSH: // Sends flash command instead of compile
  46. if (record->event.pressed) {
  47. clear_mods();
  48. clear_oneshot_mods();
  49. send_make_command(true);
  50. }
  51. break;
  52. case QM_VRSN: // Prints firmware version
  53. if (record->event.pressed) {
  54. SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION ", Built on: " QMK_BUILDDATE);
  55. }
  56. break;
  57. case QM_KYBD: // Prints keyboard path
  58. if (record->event.pressed) {
  59. SEND_STRING("keyboards/" QMK_KEYBOARD "/");
  60. }
  61. break;
  62. case QM_KYMP: // Prints keymap path
  63. if (record->event.pressed) {
  64. SEND_STRING("keyboards/" QMK_KEYBOARD "/keymaps/" QMK_KEYMAP "/keymap.c");
  65. }
  66. break;
  67. case CMD_TAB: // Super CMD↯TAB
  68. if (record->event.pressed) {
  69. if (!is_cmd_tab_active) {
  70. is_cmd_tab_active = true;
  71. register_code(KC_LGUI);
  72. }
  73. cmd_tab_timer = timer_read();
  74. register_code(KC_TAB);
  75. } else {
  76. unregister_code(KC_TAB);
  77. }
  78. break;
  79. #if defined(RGB_THEME_ENABLE)
  80. case RGB_LYR:
  81. if (record->event.pressed) {
  82. user_config.rgb_layer_change ^= 1;
  83. dprintf("rgb layer change [EEPROM]: %u\n", user_config.rgb_layer_change);
  84. eeconfig_update_user(user_config.raw);
  85. if (user_config.rgb_layer_change) {
  86. layer_state_set(layer_state);
  87. }
  88. }
  89. break;
  90. case RGB_HUI ... RGB_SAD:
  91. if (record->event.pressed) {
  92. if (user_config.rgb_layer_change) {
  93. user_config.rgb_layer_change = false;
  94. dprintf("rgb layer change [EEPROM]: %u\n", user_config.rgb_layer_change);
  95. eeconfig_update_user(user_config.raw);
  96. }
  97. }
  98. break;
  99. case RGB_THEME_FORWARD:
  100. if (record->event.pressed) {
  101. uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT));
  102. if(shifted) {
  103. rgb_theme_step_reverse();
  104. } else {
  105. rgb_theme_step();
  106. }
  107. layer_state_set(layer_state);
  108. }
  109. break;
  110. case RGB_THEME_REVERSE:
  111. if (record->event.pressed) {
  112. uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT));
  113. if(shifted) {
  114. rgb_theme_step();
  115. } else {
  116. rgb_theme_step_reverse();
  117. }
  118. layer_state_set(layer_state);
  119. }
  120. break;
  121. #endif
  122. }
  123. return process_record_keymap(keycode, record);
  124. }
  125. // Super CMD↯TAB
  126. void matrix_scan_cmd_tab(void) {
  127. if (is_cmd_tab_active) {
  128. if (timer_elapsed(cmd_tab_timer) > 500) {
  129. unregister_code(KC_LGUI);
  130. is_cmd_tab_active = false;
  131. }
  132. }
  133. }
  134. /**
  135. * Send Make Command
  136. *
  137. * Sends 'qmk compile -kb keyboard -km keymap' command to compile firmware
  138. * Uses 'qmk flash' and resets keyboard, if flash_bootloader set to true
  139. * Sends CTPC and/or FORCE_LAYOUT parameters if built with those options
  140. */
  141. void send_make_command(bool flash_bootloader) {
  142. #ifdef FORCE_LAYOUT // Add layout string if built with FORCE_LAYOUT
  143. SEND_STRING("FORCE_LAYOUT=" FORCE_LAYOUT " ");
  144. #endif
  145. #ifdef CONVERT_TO_PROTON_C // Add CTPC if built with CONVERT_TO_PROTON_C
  146. SEND_STRING("CTPC=yes ");
  147. #endif
  148. SEND_STRING("qmk ");
  149. if (flash_bootloader) {
  150. #ifndef KEYBOARD_massdrop // Don't run flash for Massdrop boards
  151. SEND_STRING("flash ");
  152. } else {
  153. #endif
  154. SEND_STRING("compile ");
  155. }
  156. SEND_STRING("-kb " QMK_KEYBOARD " ");
  157. SEND_STRING("-km " QMK_KEYMAP);
  158. if (flash_bootloader) {
  159. #if defined(KEYBOARD_massdrop) // only run for Massdrop boards
  160. SEND_STRING(" && mdlflash " QMK_KEYBOARD " " QMK_KEYMAP);
  161. #endif
  162. }
  163. SEND_STRING(SS_TAP(X_ENTER));
  164. if (flash_bootloader) {
  165. reset_keyboard();
  166. }
  167. }