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.

150 lines
4.3 KiB

  1. /*
  2. Copyright 2020 Dan White <opensource@bluetufa.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "ortho.h"
  15. #include "badger.h"
  16. int _currentLayer;
  17. bool _capsLock;
  18. #ifdef AUDIO_ENABLE
  19. float capsOnSong[][2] = SONG(CAPS_ON);
  20. float capsOffSong[][2] = SONG(CAPS_OFF);
  21. float defaultLayerSong[][2] = SONG(QWERTY_LAYER_SONG);
  22. float moveLayerSong[][2] = SONG(MOVE_LAYER_SONG);
  23. float macLayerSong[][2] = SONG(MAC_LAYER_SONG);
  24. float raiseLayerSong[][2] = SONG(RAISE_LAYER_SONG);
  25. float lowerLayerSong[][2] = SONG(LOWER_LAYER_SONG);
  26. float agSwapSong[][2] = SONG(LONG_AG_SWAP);
  27. float agNormSong[][2] = SONG(LONG_AG_NORM);
  28. #endif
  29. __attribute__ ((weak))
  30. void keyboard_post_init_user(void) {
  31. _capsLock = false;
  32. _currentLayer = _QWERTY_MAC_ORTHO;
  33. layer_on(_currentLayer);
  34. }
  35. __attribute__ ((weak))
  36. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  37. dprintf("Key event recorded. KEYCODE: %u , event: %u\n", keycode, record->event.pressed);
  38. switch (keycode) {
  39. case CS_RIGHT:
  40. if (record->event.pressed) {
  41. SEND_STRING(SS_LALT(SS_TAP(X_B)SS_TAP(X_ENTER)));
  42. return false;
  43. }
  44. break;
  45. case CS_DOWN:
  46. if (record->event.pressed) {
  47. SEND_STRING(SS_LALT(SS_TAP(X_V)SS_TAP(X_ENTER)));
  48. return false;
  49. }
  50. break;
  51. case KC_CAPS:
  52. if (record->event.pressed) {
  53. dprintf("CAPS_LOCK state: %u\n", _capsLock);
  54. _capsLock = !_capsLock;
  55. #ifdef AUDIO_ENABLE
  56. _capsLock ? PLAY_SONG(capsOnSong) : PLAY_SONG(capsOffSong);
  57. #endif
  58. return true;
  59. }
  60. break;
  61. case AG_SWAP:
  62. #ifdef AUDIO_ENABLE
  63. PLAY_SONG(agSwapSong);
  64. #endif
  65. return true;
  66. break;
  67. case AG_NORM:
  68. #ifdef AUDIO_ENABLE
  69. PLAY_SONG(agNormSong);
  70. #endif
  71. return true;
  72. break;
  73. case KC_MAC2:
  74. if (record->event.pressed) {
  75. SEND_STRING("ll\n");
  76. return false;
  77. }
  78. break;
  79. case KC_MAC1:
  80. if (record->event.pressed) {
  81. SEND_STRING("open https://www.reddit.com/r/mechanicalkeyboards\n");
  82. return false;
  83. }
  84. break;
  85. case KC_FIRST:
  86. if (record->event.pressed) {
  87. // don't turn off the QWERTY layer
  88. if (_currentLayer != _QWERTY_MAC_ORTHO) {
  89. layer_off(_currentLayer);
  90. }
  91. _currentLayer = _QWERTY_MAC_ORTHO;
  92. layer_on(_currentLayer);
  93. playSongForLayer(_currentLayer);
  94. return false;
  95. }
  96. break;
  97. case KC_LYRC:
  98. if (record->event.pressed) {
  99. dprintf("LYR CYCLE pressed %u, CURRENT_LAYER: %u\n", keycode, _currentLayer);
  100. // don't turn off the QWERTY layer or the ADJUST layer
  101. if (_currentLayer != _QWERTY_MAC_ORTHO) {
  102. layer_off(_currentLayer);
  103. }
  104. // don't lock the ADJUST layer
  105. // since this key is accessible via the ADJUST
  106. // layer, as it will require tricky state management
  107. if (++_currentLayer == _ADJUST_ORTHO) {
  108. _currentLayer = _QWERTY_MAC_ORTHO;
  109. } else {
  110. layer_on(_currentLayer);
  111. }
  112. playSongForLayer(_currentLayer);
  113. return false;
  114. }
  115. break;
  116. }
  117. return true;
  118. }
  119. void playSongForLayer(int currentLayer) {
  120. #ifdef AUDIO_ENABLE
  121. switch (currentLayer) {
  122. case _QWERTY_LINUX:
  123. PLAY_SONG(defaultLayerSong);
  124. break;
  125. case _MOVE_LINUX:
  126. PLAY_SONG(moveLayerSong);
  127. break;
  128. case _QWERTY_MAC:
  129. PLAY_SONG(macLayerSong);
  130. break;
  131. case _MOVE_MAC:
  132. PLAY_SONG(moveLayerSong);
  133. break;
  134. case _RAISE:
  135. PLAY_SONG(raiseLayerSong);
  136. break;
  137. case _LOWER:
  138. PLAY_SONG(lowerLayerSong);
  139. break;
  140. default:
  141. break;
  142. }
  143. #endif
  144. }