2
0

bbaserdem.c 18 KB

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