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.

633 lines
18 KiB

  1. #include "bbaserdem.h"
  2. /*---------------*\
  3. |*-----MOUSE-----*|
  4. \*---------------*/
  5. #ifdef MOUSEKEY_ENABLE
  6. #include "mousekey.h"
  7. #endif
  8. /*-------------*\
  9. |*-----RGB-----*|
  10. \*-------------*/
  11. #ifdef RGBLIGHT_ENABLE
  12. #include "rgblight.h"
  13. #endif
  14. /*-------------*\
  15. |*---UNICODE---*|
  16. \*-------------*/
  17. #ifdef UNICODE_ENABLE
  18. #endif
  19. /*-----------------*\
  20. |*-----SECRETS-----*|
  21. \*-----------------*/
  22. // Enabled by adding a non-tracked secrets.h to this dir.
  23. #if (__has_include("secrets.h"))
  24. #include "secrets.h"
  25. #endif
  26. /*---------------*\
  27. |*-----MUSIC-----*|
  28. \*---------------*/
  29. #ifdef AUDIO_ENABLE
  30. float tone_game[][2] = SONG(ZELDA_PUZZLE);
  31. float tone_return[][2] = SONG(ZELDA_TREASURE);
  32. float tone_linux[][2] = SONG(UNICODE_LINUX);
  33. float tone_windows[][2] = SONG(UNICODE_WINDOWS);
  34. #endif
  35. /*-------------------*\
  36. |*-----TAP-DANCE-----*|
  37. \*-------------------*/
  38. #ifdef TAP_DANCE_ENABLE
  39. qk_tap_dance_action_t tap_dance_actions[] = {
  40. // Shift on double tap of semicolon
  41. [SCL] = ACTION_TAP_DANCE_DOUBLE( KC_SCLN, KC_COLN )
  42. };
  43. #endif
  44. /* In keymaps, instead of writing _user functions, write _keymap functions
  45. * The __attribute__((weak)) allows for empty definitions here, and during
  46. * compilation, if these functions are defined elsewhere, they are written
  47. * over. This allows to include custom code from keymaps in the generic code
  48. * in this file.
  49. */
  50. __attribute__ ((weak)) void matrix_init_keymap(void) { }
  51. __attribute__ ((weak)) void matrix_scan_keymap(void) { }
  52. __attribute__ ((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  53. return true;
  54. }
  55. __attribute__ ((weak)) uint32_t layer_state_set_keymap (uint32_t state) {
  56. return state;
  57. }
  58. __attribute__ ((weak)) void led_set_keymap(uint8_t usb_led) { }
  59. /* ----------------------- *\
  60. * -----RGB Functions----- *
  61. \* ----------------------- */
  62. #ifdef RGBLIGHT_ENABLE
  63. // Storage variables
  64. extern rgblight_config_t rgblight_config;
  65. bool base_sta; // Keeps track if in saveable state
  66. bool base_tog; // Whether base state is active or not
  67. int base_hue; // Hue value of base state
  68. int base_sat; // Saturation value of base state
  69. int base_val; // Brightness value of base state
  70. uint8_t base_mod; // Animation mode of the base state
  71. // Save the current state of the rgb mode
  72. void rgblight_saveBase(void) {
  73. base_hue = rgblight_config.hue;
  74. base_sat = rgblight_config.sat;
  75. base_val = rgblight_config.val;
  76. base_mod = rgblight_config.mode;
  77. base_tog = rgblight_config.enable;
  78. base_sta = false; // If saving, that means base layer is being left
  79. }
  80. // Load the base state back
  81. void rgblight_loadBase(void) {
  82. // Don't do anything if not enabled
  83. if ( !base_sta ) {
  84. if ( base_tog ) {
  85. rgblight_enable();
  86. rgblight_mode( base_mod );
  87. rgblight_sethsv( base_hue, base_sat, base_val );
  88. } else {
  89. rgblight_disable();
  90. }
  91. }
  92. // Mark that base is loaded, and to be saved before leaving
  93. base_sta = true;
  94. }
  95. // Set to plain HSV color
  96. void rgblight_colorStatic( int hu, int sa, int va ) {
  97. // First, it must be enabled or color change is not written
  98. rgblight_enable();
  99. rgblight_mode(1);
  100. rgblight_sethsv(hu,sa,va);
  101. }
  102. /* HSV values
  103. * white ( 0, 0, 255)
  104. * red ( 0, 255, 255)
  105. * coral ( 16, 176, 255)
  106. * orange ( 39, 255, 255)
  107. * goldenrod ( 43, 218, 218)
  108. * gold ( 51, 255, 255)
  109. * yellow ( 60, 255, 255)
  110. * chartreuse ( 90, 255, 255)
  111. * green (120, 255, 255)
  112. * springgreen (150, 255, 255)
  113. * turquoise (174, 90, 112)
  114. * teal (180, 255, 128)
  115. * cyan (180, 255, 255)
  116. * azure (186, 102, 255)
  117. * blue (240, 255, 255)
  118. * purple (270, 255, 255)
  119. * magenta (300, 255, 255)
  120. * pink (330, 128, 255)
  121. */
  122. // Set RGBLIGHT state depending on layer
  123. void rgblight_change( uint8_t this_layer ) {
  124. // Save state, if saving is requested
  125. if ( base_sta ) {
  126. rgblight_saveBase();
  127. }
  128. // Change RGB light
  129. switch ( this_layer ) {
  130. case _DV:
  131. // Load base layer
  132. rgblight_loadBase();
  133. break;
  134. case _AL:
  135. // Do yellow for alternate
  136. rgblight_colorStatic( 60,255,255);
  137. break;
  138. case _GA:
  139. // Do purple for game
  140. rgblight_colorStatic(285,255,255);
  141. break;
  142. case _NU:
  143. // Do azure for number
  144. rgblight_colorStatic(186,200,255);
  145. break;
  146. case _SE:
  147. // Do red for settings
  148. rgblight_colorStatic( 16,255,255);
  149. break;
  150. case _MO:
  151. // Do green for mouse
  152. rgblight_colorStatic(120,255,255);
  153. break;
  154. case _MU:
  155. // Do orange for music
  156. rgblight_colorStatic( 39,255,255);
  157. break;
  158. default:
  159. // Something went wrong
  160. rgblight_colorStatic( 0,255,255);
  161. break;
  162. }
  163. }
  164. #endif
  165. /*---------------------*\
  166. |*-----MATRIX INIT-----*|
  167. \*---------------------*/
  168. void matrix_init_user (void) {
  169. // Keymap specific things, do it first thing to allow for delays etc
  170. matrix_init_keymap();
  171. // Correct unicode
  172. #ifdef UNICODE_ENABLE
  173. set_unicode_input_mode(UC_LNX);
  174. #endif
  175. // Make beginning layer DVORAK
  176. set_single_persistent_default_layer(_DV);
  177. //--RGB light initialize base layer
  178. #ifdef RGBLIGHT_ENABLE
  179. // Base hue is white, and RGB disabled
  180. base_hue = 100;
  181. base_sat = 0;
  182. base_val = 255;
  183. base_mod = 2;
  184. base_tog = false;
  185. rgblight_enable();
  186. rgblight_mode(base_mod);
  187. rgblight_sethsv(base_hue,base_sat,base_val);
  188. rgblight_disable();
  189. rgblight_loadBase();
  190. #endif
  191. }
  192. /*---------------------*\
  193. |*-----MATRIX SCAN-----*|
  194. \*---------------------*/
  195. void matrix_scan_user (void) {
  196. // Keymap specific, do it first
  197. matrix_scan_keymap();
  198. }
  199. /*------------------*\
  200. |*-----KEYCODES-----*|
  201. \*------------------*/
  202. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  203. // Shift check
  204. bool is_capital = ( keyboard_report->mods & (MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)) );
  205. static bool lock_flag = false;
  206. uint8_t layer = biton32 (layer_state);
  207. switch (keycode) {
  208. // Secrets implementation
  209. #if (__has_include("secrets.h"))
  210. case SECRET1:
  211. if( !record->event.pressed ) {
  212. send_string_P( secret[ keycode - SECRET1 ] );
  213. }
  214. return false;
  215. break;
  216. case SECRET2:
  217. if( !record->event.pressed ) {
  218. send_string_P( secret[ keycode - SECRET2 ] );
  219. }
  220. return false;
  221. break;
  222. case SECRET3:
  223. if( !record->event.pressed ) {
  224. send_string_P( secret[ keycode - SECRET3 ] );
  225. }
  226. return false;
  227. break;
  228. #endif
  229. // If these keys are pressed, load base layer config, and mark saving
  230. #ifdef RGBLIGHT_ENABLE
  231. case RGB_TOG:
  232. case RGB_MOD:
  233. case RGB_VAI:
  234. case RGB_VAD:
  235. case RGB_SAI:
  236. case RGB_SAD:
  237. case RGB_HUI:
  238. case RGB_HUD:
  239. if ( !base_sta ) {
  240. rgblight_loadBase();
  241. }
  242. return true;
  243. break;
  244. #endif
  245. // Lock functionality: These layers are locked if the LOCKED buttons are
  246. // pressed. Otherwise, they are momentary toggles
  247. case K_LOCK:
  248. if (record->event.pressed) {
  249. lock_flag = !lock_flag;
  250. }
  251. return false;
  252. break;
  253. case K_MOUSE:
  254. if (record->event.pressed) {
  255. layer_on(_MO);
  256. lock_flag = false;
  257. } else {
  258. if ( lock_flag ) {
  259. lock_flag = false;
  260. } else {
  261. layer_off(_MO);
  262. }
  263. }
  264. return false;
  265. break;
  266. case K_NUMBR:
  267. if (record->event.pressed) {
  268. layer_on(_NU);
  269. lock_flag = false;
  270. } else {
  271. if ( lock_flag ) {
  272. lock_flag = false;
  273. } else {
  274. layer_off(_NU);
  275. }
  276. }
  277. return false;
  278. break;
  279. // Layer switches with sound
  280. case K_GAMES:
  281. if (record->event.pressed) {
  282. // On press, turn off layer if active
  283. if ( layer == _GA ) {
  284. #ifdef AUDIO_ENABLE
  285. stop_all_notes();
  286. PLAY_SONG(tone_return);
  287. #endif
  288. layer_off(_GA);
  289. }
  290. } else {
  291. // After click, turn on layer if accessed from setting
  292. if ( layer == _SE ) {
  293. #ifdef AUDIO_ENABLE
  294. stop_all_notes();
  295. PLAY_SONG(tone_game);
  296. #endif
  297. layer_on(_GA);
  298. layer_off(_SE);
  299. }
  300. }
  301. return false;
  302. break;
  303. case MU_TOG:
  304. if (record->event.pressed) {
  305. // On press, turn off layer if active
  306. if ( layer == _SE ) {
  307. layer_off(_SE);
  308. layer_on(_MU);
  309. } else {
  310. layer_off(_MU);
  311. }
  312. }
  313. return true;
  314. break;
  315. //------UNICODE
  316. // Unicode switches with sound
  317. #ifdef UNICODE_ENABLE
  318. case UNI_LI:
  319. if (record->event.pressed) {
  320. #ifdef AUDIO_ENABLE
  321. stop_all_notes();
  322. PLAY_SONG(tone_linux);
  323. #endif
  324. set_unicode_input_mode(UC_LNX);
  325. }
  326. return false;
  327. break;
  328. case UNI_WN:
  329. if (record->event.pressed) {
  330. #ifdef AUDIO_ENABLE
  331. stop_all_notes();
  332. PLAY_SONG(tone_windows);
  333. #endif
  334. set_unicode_input_mode(UC_WIN);
  335. }
  336. return false;
  337. break;
  338. // Turkish letters, with capital functionality
  339. case TUR_A:
  340. if (record->event.pressed) {
  341. if ( is_capital ) {
  342. unicode_input_start();
  343. register_hex(0x00c2);
  344. unicode_input_finish();
  345. } else {
  346. unicode_input_start();
  347. register_hex(0x00e2);
  348. unicode_input_finish();
  349. }
  350. }
  351. return false;
  352. break;
  353. case TUR_O:
  354. if (record->event.pressed) {
  355. if ( is_capital ) {
  356. unicode_input_start();
  357. register_hex(0x00d6);
  358. unicode_input_finish();
  359. } else {
  360. unicode_input_start();
  361. register_hex(0x00f6);
  362. unicode_input_finish();
  363. }
  364. }
  365. return false;
  366. break;
  367. case TUR_U:
  368. if (record->event.pressed) {
  369. if ( is_capital ) {
  370. unicode_input_start();
  371. register_hex(0x00dc);
  372. unicode_input_finish();
  373. } else {
  374. unicode_input_start();
  375. register_hex(0x00fc);
  376. unicode_input_finish();
  377. }
  378. }
  379. return false;
  380. break;
  381. case TUR_I:
  382. if (record->event.pressed) {
  383. if ( is_capital ) {
  384. unicode_input_start();
  385. register_hex(0x0130);
  386. unicode_input_finish();
  387. } else {
  388. unicode_input_start();
  389. register_hex(0x0131);
  390. unicode_input_finish();
  391. }
  392. }
  393. return false;
  394. break;
  395. case TUR_G:
  396. if (record->event.pressed) {
  397. if ( is_capital ) {
  398. unicode_input_start();
  399. register_hex(0x011e);
  400. unicode_input_finish();
  401. } else {
  402. unicode_input_start();
  403. register_hex(0x011f);
  404. unicode_input_finish();
  405. }
  406. }
  407. return false;
  408. break;
  409. case TUR_C:
  410. if (record->event.pressed) {
  411. if ( is_capital ) {
  412. unicode_input_start();
  413. register_hex(0x00c7);
  414. unicode_input_finish();
  415. } else {
  416. unicode_input_start();
  417. register_hex(0x00e7);
  418. unicode_input_finish();
  419. }
  420. }
  421. return false;
  422. break;
  423. case TUR_S:
  424. if (record->event.pressed) {
  425. if ( is_capital ) {
  426. unicode_input_start();
  427. register_hex(0x015e);
  428. unicode_input_finish();
  429. } else {
  430. unicode_input_start();
  431. register_hex(0x015f);
  432. unicode_input_finish();
  433. }
  434. }
  435. return false;
  436. break;
  437. #endif
  438. //-------Diagonal mouse movements
  439. #ifdef MOUSEKEY_ENABLE
  440. case MO_NE:
  441. if( record->event.pressed ) {
  442. mousekey_on(MO_N);
  443. mousekey_on(MO_E);
  444. mousekey_send();
  445. } else {
  446. mousekey_off(MO_N);
  447. mousekey_off(MO_E);
  448. mousekey_send();
  449. }
  450. return false;
  451. break;
  452. case MO_NW:
  453. if( record->event.pressed ) {
  454. mousekey_on(MO_N);
  455. mousekey_on(MO_W);
  456. mousekey_send();
  457. } else {
  458. mousekey_off(MO_N);
  459. mousekey_off(MO_W);
  460. mousekey_send();
  461. }
  462. return false;
  463. break;
  464. case MO_SE:
  465. if( record->event.pressed ) {
  466. mousekey_on(MO_S);
  467. mousekey_on(MO_E);
  468. mousekey_send();
  469. } else {
  470. mousekey_off(MO_S);
  471. mousekey_off(MO_E);
  472. mousekey_send();
  473. }
  474. return false;
  475. break;
  476. case MO_SW:
  477. if( record->event.pressed ) {
  478. mousekey_on(MO_S);
  479. mousekey_on(MO_W);
  480. mousekey_send();
  481. } else {
  482. mousekey_off(MO_S);
  483. mousekey_off(MO_W);
  484. mousekey_send();
  485. }
  486. return false;
  487. break;
  488. case MO_S_NE:
  489. if( record->event.pressed ) {
  490. mousekey_on(MO_S_N);
  491. mousekey_on(MO_S_E);
  492. mousekey_send();
  493. } else {
  494. mousekey_off(MO_S_N);
  495. mousekey_off(MO_S_E);
  496. mousekey_send();
  497. }
  498. return false;
  499. break;
  500. case MO_S_NW:
  501. if( record->event.pressed ) {
  502. mousekey_on(MO_S_N);
  503. mousekey_on(MO_S_W);
  504. mousekey_send();
  505. } else {
  506. mousekey_off(MO_S_N);
  507. mousekey_off(MO_S_W);
  508. mousekey_send();
  509. }
  510. return false;
  511. break;
  512. case MO_S_SE:
  513. if( record->event.pressed ) {
  514. mousekey_on(MO_S_S);
  515. mousekey_on(MO_S_E);
  516. mousekey_send();
  517. } else {
  518. mousekey_off(MO_S_S);
  519. mousekey_off(MO_S_E);
  520. mousekey_send();
  521. }
  522. return false;
  523. break;
  524. case MO_S_SW:
  525. if( record->event.pressed ) {
  526. mousekey_on(MO_S_S);
  527. mousekey_on(MO_S_W);
  528. mousekey_send();
  529. } else {
  530. mousekey_off(MO_S_S);
  531. mousekey_off(MO_S_W);
  532. mousekey_send();
  533. }
  534. return false;
  535. break;
  536. #endif
  537. //------DOUBLE PRESS, with added left navigation
  538. case DBL_SPC:
  539. if( record->event.pressed ) {
  540. SEND_STRING(" "SS_TAP(X_LEFT));
  541. }
  542. return false;
  543. break;
  544. case DBL_ANG:
  545. if( record->event.pressed ) {
  546. SEND_STRING("<>"SS_TAP(X_LEFT));
  547. }
  548. return false;
  549. break;
  550. case DBL_PAR:
  551. if( record->event.pressed ) {
  552. SEND_STRING("()"SS_TAP(X_LEFT));
  553. }
  554. return false;
  555. break;
  556. case DBL_SQR:
  557. if( record->event.pressed ) {
  558. SEND_STRING("[]"SS_TAP(X_LEFT));
  559. }
  560. return false;
  561. break;
  562. case DBL_BRC:
  563. if( record->event.pressed ) {
  564. SEND_STRING("{}"SS_TAP(X_LEFT));
  565. }
  566. return false;
  567. break;
  568. case DBL_QUO:
  569. if( record->event.pressed ) {
  570. SEND_STRING("\'\'"SS_TAP(X_LEFT));
  571. }
  572. return false;
  573. break;
  574. case DBL_DQT:
  575. if( record->event.pressed ) {
  576. SEND_STRING("\"\""SS_TAP(X_LEFT));
  577. }
  578. return false;
  579. break;
  580. case DBL_GRV:
  581. if( record->event.pressed ) {
  582. SEND_STRING("``"SS_TAP(X_LEFT));
  583. }
  584. return false;
  585. break;
  586. // END OF KEYCODES
  587. }
  588. return process_record_keymap(keycode, record);
  589. }
  590. /*----------------------*\
  591. |*-----LAYER CHANGE-----*|
  592. \*----------------------*/
  593. layer_state_t layer_state_set_user(layer_state_t state) {
  594. state = layer_state_set_keymap (state);
  595. #ifdef RGBLIGHT_ENABLE
  596. // Change RGB lighting depending on the last layer activated
  597. rgblight_change( biton32(state) );
  598. #endif
  599. return state;
  600. }