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