aboutsummaryrefslogtreecommitdiffstats
path: root/users/badger/ortho.c
blob: ff84e1706f06237243199b04c0208f1b35b6a1f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
Copyright 2020 Dan White <opensource@bluetufa.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "ortho.h"
#include "badger.h"

int       _currentLayer;
bool      _capsLock;

#ifdef AUDIO_ENABLE
float capsOnSong[][2]                  = SONG(CAPS_ON);
float capsOffSong[][2]                 = SONG(CAPS_OFF);
float defaultLayerSong[][2]            = SONG(QWERTY_LAYER_SONG);
float moveLayerSong[][2]               = SONG(MOVE_LAYER_SONG);
float macLayerSong[][2]                = SONG(MAC_LAYER_SONG);
float raiseLayerSong[][2]              = SONG(RAISE_LAYER_SONG);
float lowerLayerSong[][2]              = SONG(LOWER_LAYER_SONG);
float agSwapSong[][2]                  = SONG(LONG_AG_SWAP);
float agNormSong[][2]                  = SONG(LONG_AG_NORM);
#endif 

__attribute__ ((weak))
void keyboard_post_init_user(void) {
  _capsLock = false;
  _currentLayer = _QWERTY_MAC_ORTHO;
  layer_on(_currentLayer);
}

__attribute__ ((weak))
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  dprintf("Key event recorded. KEYCODE: %u , event: %u\n", keycode, record->event.pressed);
  switch (keycode) {
    case CS_RIGHT:
      if (record->event.pressed) {
        SEND_STRING(SS_LALT(SS_TAP(X_B)SS_TAP(X_ENTER)));
        return false;
      }
      break;
    case CS_DOWN:
      if (record->event.pressed) {
        SEND_STRING(SS_LALT(SS_TAP(X_V)SS_TAP(X_ENTER)));
        return false;
      }
      break;
    case KC_CAPS:
      if (record->event.pressed) {
        dprintf("CAPS_LOCK state: %u\n", _capsLock);
        _capsLock = !_capsLock;
        #ifdef AUDIO_ENABLE
          _capsLock ? PLAY_SONG(capsOnSong) : PLAY_SONG(capsOffSong);
        #endif
        return true;
      }
      break;
    case AG_SWAP:
      #ifdef AUDIO_ENABLE
        PLAY_SONG(agSwapSong);
      #endif
      return true;
      break;
    case AG_NORM:
      #ifdef AUDIO_ENABLE
        PLAY_SONG(agNormSong);
      #endif
      return true;
      break;
    case KC_MAC2:
      if (record->event.pressed) {
        SEND_STRING("ll\n");
        return false;
      }
      break;
    case KC_MAC1:
      if (record->event.pressed) {
        SEND_STRING("open https://www.reddit.com/r/mechanicalkeyboards\n");
        return false;
      }
      break;
    case KC_FIRST:
      if (record->event.pressed) {
        // don't turn off the QWERTY layer
        if (_currentLayer != _QWERTY_MAC_ORTHO) {
          layer_off(_currentLayer);
        }
        _currentLayer = _QWERTY_MAC_ORTHO;
        layer_on(_currentLayer);
        playSongForLayer(_currentLayer);
        return false;
      }
      break;
    case KC_LYRC:
      if (record->event.pressed) {
        dprintf("LYR CYCLE pressed %u, CURRENT_LAYER: %u\n", keycode, _currentLayer);
        // don't turn off the QWERTY layer or the ADJUST layer
        if (_currentLayer != _QWERTY_MAC_ORTHO) {
          layer_off(_currentLayer);
        }
        // don't lock the ADJUST layer
        // since this key is accessible via the ADJUST
        // layer, as it will require tricky state management
        if (++_currentLayer == _ADJUST_ORTHO) {
          _currentLayer = _QWERTY_MAC_ORTHO;
        } else {
          layer_on(_currentLayer);
        }

        playSongForLayer(_currentLayer);
        return false;
      }
      break;
  }
  return true;
}

void playSongForLayer(int currentLayer) {
  #ifdef AUDIO_ENABLE
  switch (currentLayer) {
    case   _QWERTY_LINUX:
      PLAY_SONG(defaultLayerSong);
      break;
    case  _MOVE_LINUX:
      PLAY_SONG(moveLayerSong);
      break;
    case  _QWERTY_MAC:
      PLAY_SONG(macLayerSong);
      break;
    case  _MOVE_MAC:
      PLAY_SONG(moveLayerSong);
      break;
    case  _RAISE:
      PLAY_SONG(raiseLayerSong);
      break;
    case  _LOWER:
      PLAY_SONG(lowerLayerSong);
      break;
    default:
      break;
  }
  #endif
}