]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/hadron/keymaps/default/keymap.c
Merge pull request #3229 from qmk/hf/shinydox
[qmk_firmware.git] / keyboards / hadron / keymaps / default / keymap.c
1 #include QMK_KEYBOARD_H
2 #include "LUFA/Drivers/Peripheral/TWI.h"
3 #ifdef AUDIO_ENABLE
4   #include "audio.h"
5 #endif
6 #ifdef USE_I2C
7 #include "i2c.h"
8 #endif
9 #ifdef SSD1306OLED
10 #include "ssd1306.h"
11 #endif
12 extern keymap_config_t keymap_config;
13
14 //Following line allows macro to read current RGB settings
15 extern rgblight_config_t rgblight_config;
16
17 // Each layer gets a name for readability, which is then used in the keymap matrix below.
18 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
19 // Layer names don't all need to be of the same length, obviously, and you can also skip them
20 // entirely and just use numbers.
21 #define _QWERTY 0
22 #define _COLEMAK 1
23 #define _DVORAK 2
24 #define _LOWER 3
25 #define _RAISE 4
26 #define _MOUSECURSOR 8
27 #define _ADJUST 16
28
29 enum preonic_keycodes {
30   QWERTY = SAFE_RANGE,
31   COLEMAK,
32   DVORAK,
33   LOWER,
34   RAISE,
35   BACKLIT,
36   RGBLED_TOGGLE,
37   RGBLED_STEP_MODE,
38   RGBLED_INCREASE_HUE,
39   RGBLED_DECREASE_HUE,
40   RGBLED_INCREASE_SAT,
41   RGBLED_DECREASE_SAT,
42   RGBLED_INCREASE_VAL,
43   RGBLED_DECREASE_VAL,
44 };
45
46 enum macro_keycodes {
47   KC_DEMOMACRO,
48 };
49
50 // Fillers to make layering more clear
51 #define _______ KC_TRNS
52 #define XXXXXXX KC_NO
53 // Custom macros
54 #define CTL_ESC     CTL_T(KC_ESC)               // Tap for Esc, hold for Ctrl
55 #define CTL_TTAB    CTL_T(KC_TAB)               // Tap for Esc, hold for Ctrl
56 #define CTL_ENT     CTL_T(KC_ENT)               // Tap for Enter, hold for Ctrl
57 #define SFT_ENT     SFT_T(KC_ENT)               // Tap for Enter, hold for Shift
58 // Requires KC_TRNS/_______ for the trigger key in the destination layer
59 #define LT_MC(kc)   LT(_MOUSECURSOR, kc)        // L-ayer T-ap M-ouse C-ursor
60 #define LT_RAI(kc)  LT(_RAISE, kc)              // L-ayer T-ap to Raise
61 #define DEMOMACRO   M(KC_DEMOMACRO)            // Sample for macros
62
63
64 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
65
66 /* Qwerty
67  * ,------+------+------+------+------+------------------------------------------------.
68  * | Esc  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |  F7  |  F8  |  F9  |  F10 |  DEL |
69  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
70  * | Tab  |   Q  |   W  |   E  |   R  |   T  |   7  |   8  |   9  |   Y  |   U  |   I  |   O  |   P  | Bksp |
71  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
72  * | CAPS |   A  |   S  |   D  |   F  |   G  |   4  |   5  |   6  |   H  |   J  |   K  |   L  | ;/Nav|  '   |
73  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
74  * | Shift|   Z  |   X  |   C  |   V  |   B  |   1  |   2  |   3  |   N  |   M  |   ,  |   .  |   /  |Ctl/Et|
75  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
76  * |  `   | Ctrl | Alt  | GUI  |Lower |Space |   0  |   .  |   =  |Space |Raise | Left | Down |  Up  |Right |
77  * `--------------------------------------------------------------------------------------------------------'
78  */
79 [_QWERTY] = LAYOUT(
80   KC_ESC,   KC_F1,    KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,    KC_F9,   KC_F10,  KC_DEL,\
81   KC_TAB,   KC_Q,     KC_W,    KC_E,    KC_R,    KC_T,    KC_P7,   KC_P8,   KC_P9,    KC_Y,    KC_U,    KC_I,   KC_O,    KC_P,     KC_BSPC, \
82   KC_CAPS,  KC_A,     KC_S,    KC_D,    KC_F,    KC_G,    KC_P4,   KC_P5,   KC_P6,    KC_H,    KC_J,    KC_K,   KC_L,LT_MC(KC_SCLN), KC_QUOT, \
83   KC_LSFT,  KC_Z,     KC_X,    KC_C,    KC_V,    KC_B,    KC_P1,   KC_P2,   KC_P3,    KC_N,    KC_M,    KC_COMM,KC_DOT,  KC_SLSH,  CTL_ENT, \
84   KC_GRV,   KC_LCTRL, KC_LGUI, KC_LALT, LOWER,   KC_SPC,  KC_P0,   KC_DOT,  KC_EQL,  KC_SPC,   RAISE,   KC_LEFT,KC_DOWN, KC_UP,    KC_RGHT  \
85 ),
86
87 /* Colemak
88  * ,------+------+------+------+------+------------------------------------------------.
89  * | Esc  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |  F7  |  F8  |  F9  |   0  |   -  |
90  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
91  * | Tab  |   Q  |   W  |   F  |   P  |   G  |   7  |   8  |   9  |   J  |   L  |   U  |   Y  |   ;  | Bksp |
92  * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
93  * | CAPS |   A  |   R  |   S  |   T  |   D  |   4  |   5  |   6  |   H  |   N  |   E  |   I  |   O  |  '   |
94  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
95  * | Shift|   Z  |   X  |   C  |   V  |   B  |   1  |   2  |   3  |   K  |   M  |   ,  |   .  |   /  |Ctl/Et|
96  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
97  * |   `  | Ctrl | Alt  | GUI  |Lower |Space |   0  |   .  |   =  |Space |Raise | Left | Down |  Up  |Right |
98  * `--------------------------------------------------------------------------------------------------------'
99  */
100 [_COLEMAK] = LAYOUT(
101   KC_ESC,   KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,    KC_F9,   KC_F10, KC_DEL,\
102   KC_TAB,   KC_Q,    KC_W,    KC_F,    KC_P,    KC_G,    KC_P7,   KC_P8,   KC_P9,    KC_J,    KC_L,    KC_U,    KC_Y,    KC_SCLN,  KC_BSPC, \
103   KC_LCTRL, KC_A,    KC_R,    KC_S,    KC_T,    KC_D,    KC_P4,   KC_P5,   KC_P6,    KC_H,    KC_N,    KC_E,    KC_I, LT_MC(KC_O), KC_QUOT, \
104   KC_LSFT,  KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_P1,   KC_P2,   KC_P3,    KC_K,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH,  CTL_ENT, \
105   KC_GRV,   KC_LCTRL, KC_LGUI, KC_LALT, LOWER,  KC_SPC,  KC_P0,   KC_DOT,  KC_EQL,   KC_SPC,  RAISE,   KC_LEFT, KC_DOWN, KC_UP,    KC_RGHT  \
106   ),
107
108 /* Dvorak
109  * ,------+------+------+------+------+------------------------------------------------.
110  * |  Esc |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |   -  |
111  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
112  * | Tab  |   "  |   ,  |   .  |   P  |   Y  |   7  |   8  |   9  |   F  |   G  |   C  |   R  |   L  | Bksp |
113  * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
114  * | Esc  |   A  |   O  |   E  |   U  |   I  |   4  |   5  |   6  |   D  |   H  |   T  |   N  |   S  |  /   |
115  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
116  * | Shift|   ;  |   Q  |   J  |   K  |   X  |   1  |   2  |   3  |   B  |   M  |   W  |   V  |   Z  |Ctl/Et|
117  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
118  * |   `  | Ctrl | Alt  | GUI  |Lower |Space |   0  |   .  |   =  |Space |Raise | Left | Down |  Up  |Right |
119  * `--------------------------------------------------------------------------------------------------------'
120  */
121 [_DVORAK] = LAYOUT(
122   KC_ESC,   KC_F1,    KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,    KC_F9,   KC_F10, KC_DEL,\
123   KC_TAB,   KC_QUOT,  KC_COMM, KC_DOT,  KC_P,    KC_Y,    KC_P7,   KC_P8,   KC_P9,    KC_F,    KC_G,   KC_C,    KC_R,    KC_L,     KC_BSPC, \
124   KC_LCTL,  KC_A,     KC_O,    KC_E,    KC_U,    KC_I,    KC_P4,   KC_P5,   KC_P6,    KC_D,    KC_H,   KC_T,    KC_N, LT_MC(KC_S), KC_SLSH, \
125   KC_LSFT,  KC_SCLN,  KC_Q,    KC_J,    KC_K,    KC_X,    KC_P1,   KC_P2,   KC_P3,    KC_B,    KC_M,   KC_W,    KC_V,    KC_Z,     CTL_ENT, \
126   KC_GRV,   KC_LCTRL, KC_LGUI, KC_LALT, LOWER,   KC_SPC,  KC_P0,   KC_DOT,  KC_EQL,   KC_SPC,  RAISE,  KC_LEFT, KC_DOWN, KC_UP,    KC_RGHT \
127 ),
128
129 /* Lower
130  * ,------+------+------+------+------+------------------------------------------------.
131  * |   ~  |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  | Bksp |
132  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
133  * |   ~  |   !  |   @  |   #  |   $  |   %  |      |      |      |   ^  |   &  |   *  |   (  |   )  | Del  |
134  * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
135  * |      |  F1  |  F2  |  F3  |  F4  |  F5  |      |      |      |  F6  |   _  |   +  |   {  |   }  |  |   |
136  * |------+------+------+------+------+------|------+------+------+------+------+------+------+------+------|
137  * |      |  F7  |  F8  |  F9  |  F10 |  F11 |      |      |      |  F12 |ISO ~ |ISO | |      |      |      |
138  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
139  * |      |      |      |      |      |      |      |      |      |      |      | Next | Vol- | Vol+ | Play |
140  * `--------------------------------------------------------------------------------------------------------'
141  */
142 [_LOWER] = LAYOUT(
143   KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, \
144   KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, _______, _______, _______, KC_CIRC, KC_AMPR, KC_ASTR,  KC_LPRN, KC_RPRN, KC_DEL, \
145   _______, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   _______, _______, _______, KC_F6,   KC_UNDS, KC_PLUS,  KC_LBRC, KC_RBRC, KC_PIPE, \
146   _______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  _______, _______, _______, KC_F12,S(KC_NUHS),S(KC_NUBS),_______,_______, _______, \
147   _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY \
148 ),
149
150 /* Raise
151  * ,------+------+------+------+------+------------------------------------------------.
152  * |  Esc |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |   -  |
153  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
154  * |   `  |   1  |   2  |   3  |   4  |   5  |      |      |      |   6  |   7  |   8  |   9  |   0  | Del  |
155  * |------+------+------+------+------+-------------+------+------+------+------+------+------+------+------|
156  * | Del  |  F1  |  F2  |  F3  |  F4  |  F5  |      |      |      |  F6  |   -  |   =  |   [  |   ]  |  \   |
157  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
158  * |      |  F7  |  F8  |  F9  |  F10 |  F11 |      |      |      |  F12 |ISO # |ISO / |      |      |      |
159  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
160  * |      |      |      |      |      |      |      |      |      |      |      | Next | Vol- | Vol+ | Play |
161  * `--------------------------------------------------------------------------------------------------------'
162  */
163 [_RAISE] = LAYOUT(
164   KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_BSPC, \
165   KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    _______, _______, _______, KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_DEL, \
166   KC_DEL,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   _______, _______, _______, KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSLS, \
167   _______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  _______, _______, _______, KC_F12,  KC_NUHS, KC_NUBS, _______, _______, _______, \
168   _______, _______, _______, _______,  _______, KC_SPC, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY   \
169 ),
170
171 /* Mouse Layer (semi-col)
172  * ,------+------+------+------+------+------------------------------------------------.
173  * | ACCL0| ACCL1| ACCL2|      |      |      |      |      |      |      |      |      |
174  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
175  * |      |      |      |      |      |      |      |      | Home | Wh_Up| WHL_L| M_Up | WHL_R| Macro|      |
176  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
177  * |      |      |      |      |      |      |      |      | End  | Wh_Dn| M_Lft| M_Dn | M_Rt |      |      |
178  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
179  * |      |      |      |      |      |      |      |      |      | BTN2 | BTN3 | BTN4 | BTN5 |      |      |
180  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
181  * |      |      |      |      |      | BTN1 |      |      |      | BTN1 |      |      |      |      |      |
182  * `--------------------------------------------------------------------------------------------------------'
183  */
184
185 [_MOUSECURSOR] = LAYOUT(
186   KC_ACL0, KC_ACL1, KC_ACL2, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
187   _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGUP, KC_WH_L, KC_MS_U, KC_WH_R,DEMOMACRO,_______, \
188   _______, _______, _______, _______, _______, _______, _______, _______, KC_END , KC_PGDN, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______, \
189   _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN2, KC_BTN3, KC_BTN4, KC_BTN5, _______, _______, \
190   _______, _______, _______, _______, _______, KC_BTN1, _______, _______, _______, KC_BTN1, _______, _______, _______, _______, _______  \
191 ),
192
193 /* Adjust (Lower + Raise)
194  * ,------+------+------+------+------+------------------------------------------------.
195  * |  Esc |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |   -  |
196  * |------+------+------+------+------+------+------+------+------+------+------+------+--------------------.
197  * | Reset|RGB TG|RGB ST|RGBH -|RGBH +|RGBS -|RGBS +|RGBV -|RGBV +|      |      |      |      |      |  Del |
198  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
199  * |      |      |      |Aud on|Audoff|AGnorm|      |      |      |AGswap|Qwerty|Colemk|      |      |      |
200  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
201  * |      |Voice-|Voice+|Mus on|Musoff|      |      |      |      |      |      |      | BL + |BL ST |BL TG |
202  * |------+------+------+------+------+------+------+------+------+------+------+------+------+------+------|
203  * |      |      |      |      |      |      |      |      |      |      |      |      |      |      |      |
204  * `--------------------------------------------------------------------------------------------------------'
205  */
206 [_ADJUST] = LAYOUT(
207   KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12, \
208   RESET,   RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, _______, _______, _______, KC_DEL, \
209   _______, _______, _______, AU_ON,   AU_OFF,  AG_NORM, _______, _______, _______, AG_SWAP, QWERTY,  COLEMAK, _______,  _______,  _______, \
210   _______, MUV_DE,  MUV_IN,  MU_ON,   MU_OFF,  MI_ON,   MI_OFF, _______, _______, _______,  _______, BL_DEC,  BL_INC,  BL_STEP, BL_TOGG, \
211   _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______\
212 )
213
214
215
216 };
217
218
219 #ifdef AUDIO_ENABLE
220
221 float tone_startup[][2]    = SONG(STARTUP_SOUND);
222 float tone_qwerty[][2]     = SONG(QWERTY_SOUND);
223 float tone_dvorak[][2]     = SONG(DVORAK_SOUND);
224 float tone_colemak[][2]    = SONG(COLEMAK_SOUND);
225 float music_scale[][2]     = SONG(MUSIC_SCALE_SOUND);
226 float tone_goodbye[][2]    = SONG(GOODBYE_SOUND);
227 #endif
228
229 // define variables for reactive RGB
230 bool RGB_INIT = false;
231 bool TOG_STATUS = false;
232 int RGB_current_mode;
233
234
235
236 void persistant_default_layer_set(uint16_t default_layer) {
237   eeconfig_update_default_layer(default_layer);
238   default_layer_set(default_layer);
239 }
240
241 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
242   if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
243     rgblight_mode(RGB_current_mode);
244     layer_on(layer3);
245   } else {
246     layer_off(layer3);
247   }
248 }
249
250 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
251   switch (keycode) {
252     case QWERTY:
253       if (record->event.pressed) {
254         #ifdef AUDIO_ENABLE
255           PLAY_SONG(tone_qwerty);
256         #endif
257         persistant_default_layer_set(1UL<<_QWERTY);
258       }
259       return false;
260       break;
261     case COLEMAK:
262       if (record->event.pressed) {
263         #ifdef AUDIO_ENABLE
264           PLAY_SONG(tone_colemak);
265         #endif
266         persistant_default_layer_set(1UL<<_COLEMAK);
267       }
268       return false;
269       break;
270     case LOWER:
271       if (record->event.pressed) {
272           //not sure how to have keyboard check mode and set it to a variable, so my work around
273           //uses another variable that would be set to true after the first time a reactive key is pressed.
274         if (RGB_INIT) {} else {
275           RGB_current_mode = rgblight_config.mode;
276           RGB_INIT = true;
277         }
278         if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
279         } else {
280           TOG_STATUS = !TOG_STATUS;
281           rgblight_mode(16);
282         }
283         layer_on(_LOWER);
284         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
285       } else {
286         rgblight_mode(RGB_current_mode);   // revert RGB to initial mode prior to RGB mode change
287         TOG_STATUS = false;
288         layer_off(_LOWER);
289         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
290       }
291       return false;
292       break;
293     case RAISE:
294       if (record->event.pressed) {
295         //not sure how to have keyboard check mode and set it to a variable, so my work around
296         //uses another variable that would be set to true after the first time a reactive key is pressed.
297         if (RGB_INIT) {} else {
298           RGB_current_mode = rgblight_config.mode;
299           RGB_INIT = true;
300         }
301         if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
302         } else {
303           TOG_STATUS = !TOG_STATUS;
304           rgblight_mode(15);
305         }
306         layer_on(_RAISE);
307         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
308       } else {
309         rgblight_mode(RGB_current_mode);  // revert RGB to initial mode prior to RGB mode change
310         layer_off(_RAISE);
311         TOG_STATUS = false;
312         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
313       }
314       return false;
315       break;
316     case BACKLIT:
317       if (record->event.pressed) {
318         register_code(KC_RSFT);
319         #ifdef BACKLIGHT_ENABLE
320           backlight_step();
321         #endif
322       } else {
323         unregister_code(KC_RSFT);
324       }
325       return false;
326       break;
327     case RGB_MOD:
328       //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
329       if (record->event.pressed) {
330         rgblight_mode(RGB_current_mode);
331         rgblight_step();
332         RGB_current_mode = rgblight_config.mode;
333       }
334       return false;
335       break;
336   }
337   return true;
338 }
339
340 void matrix_init_user(void) {
341   #ifdef USE_I2C
342     i2c_master_init();
343   #ifdef SSD1306OLED
344   // calls code for the SSD1306 OLED
345         _delay_ms(400);
346         TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 800000));
347         iota_gfx_init();   // turns on the display
348   #endif
349   #endif
350     #ifdef AUDIO_ENABLE
351         startup_user();
352     #endif
353 }
354
355 void matrix_scan_user(void) {
356     #ifdef SSD1306OLED
357      iota_gfx_task();  // this is what updates the display continuously
358     #endif
359 }
360
361 #ifdef AUDIO_ENABLE
362
363 void startup_user()
364 {
365     _delay_ms(20); // gets rid of tick
366     PLAY_SONG(tone_startup);
367 }
368
369 void shutdown_user()
370 {cc
371     PLAY_SONG(tone_goodbye);
372     _delay_ms(150);
373     stop_all_notes();
374 }
375
376 void music_on_user(void)
377 {
378     music_scale_user();
379 }
380
381 void music_scale_user(void)
382 {
383     PLAY_SONG(music_scale);
384 }
385
386 #endif
387
388 /*
389  * Macro definition
390  */
391 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
392 {
393     if (!eeconfig_is_enabled()) {
394       eeconfig_init();
395     }
396
397     switch (id) {
398       case KC_DEMOMACRO:
399         if (record->event.pressed){
400           return MACRO (I(1), T(H),T(E),T(L), T(L), T(O), T(SPACE), T(W), T(O), T(R), T(L), T(D),  END);
401         }
402     }
403
404     return MACRO_NONE;
405 }
406
407 void matrix_update(struct CharacterMatrix *dest,
408                           const struct CharacterMatrix *source) {
409   if (memcmp(dest->display, source->display, sizeof(dest->display))) {
410     memcpy(dest->display, source->display, sizeof(dest->display));
411     dest->dirty = true;
412   }
413 }
414
415 //assign the right code to your layers for OLED display
416 #define L_BASE 0
417 #define L_LOWER 8
418 #define L_RAISE 16
419 #define L_FNLAYER 64
420 #define L_NUMLAY 128
421 #define L_NLOWER 136
422 #define L_NFNLAYER 192
423 #define L_MOUSECURSOR 256
424 #define L_ADJUST 65560
425
426 void iota_gfx_task_user(void) {
427 #if DEBUG_TO_SCREEN
428   if (debug_enable) {
429     return;
430   }
431 #endif
432
433   struct CharacterMatrix matrix;
434
435   matrix_clear(&matrix);
436   matrix_write_P(&matrix, PSTR("USB: "));
437 #ifdef PROTOCOL_LUFA
438   switch (USB_DeviceState) {
439     case DEVICE_STATE_Unattached:
440       matrix_write_P(&matrix, PSTR("Unattached"));
441       break;
442     case DEVICE_STATE_Suspended:
443       matrix_write_P(&matrix, PSTR("Suspended"));
444       break;
445     case DEVICE_STATE_Configured:
446       matrix_write_P(&matrix, PSTR("Connected"));
447       break;
448     case DEVICE_STATE_Powered:
449       matrix_write_P(&matrix, PSTR("Powered"));
450       break;
451     case DEVICE_STATE_Default:
452       matrix_write_P(&matrix, PSTR("Default"));
453       break;
454     case DEVICE_STATE_Addressed:
455       matrix_write_P(&matrix, PSTR("Addressed"));
456       break;
457     default:
458       matrix_write_P(&matrix, PSTR("Invalid"));
459   }
460 #endif
461
462 // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
463
464   char buf[40];
465   snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
466   matrix_write_P(&matrix, PSTR("\n\nLayer: "));
467     switch (layer_state) {
468         case L_BASE:
469            matrix_write_P(&matrix, PSTR("Default"));
470            break;
471         case L_RAISE:
472            matrix_write_P(&matrix, PSTR("Raise"));
473            break;
474         case L_LOWER:
475            matrix_write_P(&matrix, PSTR("Lower"));
476            break;
477         case L_ADJUST:
478            matrix_write_P(&matrix, PSTR("ADJUST"));
479            break;
480         default:
481            matrix_write(&matrix, buf);
482  }
483
484   // Host Keyboard LED Status
485   char led[40];
486     snprintf(led, sizeof(led), "\n%s  %s  %s",
487             (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : "       ",
488             (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : "    ",
489             (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : "    ");
490   matrix_write(&matrix, led);
491   matrix_update(&display, &matrix);
492 }
493