Created
September 16, 2018 00:15
-
-
Save chuckdee68/dacab0f75bcb7a06cc021fb84820c335 to your computer and use it in GitHub Desktop.
Clueboard Momentary Layer Lights Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "66.h" | |
#include "timer.h" | |
#define MODS_CTRL_MASK (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)) | |
//Run get_mods(); instead | |
// Each layer gets a name for readability, which is then used in the keymap matrix below. | |
// The underscores don't mean anything - you can have a layer called STUFF or any other name. | |
#define _BL 0 | |
#define _FL 1 | |
enum custom_keycodes { | |
CAPS_FN_SWITCH = SAFE_RANGE, | |
LEFT_SHIFT_CUSTOM, | |
RIGHT_SHIFT_CUSTOM, | |
KC_CUSTOMBK | |
}; | |
uint8_t capsOn; | |
uint8_t currLayer; | |
uint32_t total_t; | |
uint8_t lShState; // state of left and right shifts | |
uint8_t rShState; | |
uint16_t col_hue1=29; //White | |
uint8_t col_sat1=0; | |
uint8_t col_val1=255; | |
uint8_t col_mode1=1; | |
uint8_t col_val2=255; //Blue | |
uint8_t col_sat2=75; | |
uint16_t col_hue2=231; | |
uint8_t col_mode2=1; | |
uint8_t col_sat3=255; //Yellow | |
uint8_t col_val3=255; | |
uint16_t col_hue3=43; | |
uint8_t col_mode3=1; | |
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |
/* Keymap _BL: Base Layer (Default Layer) | |
*/ | |
[_BL] = LAYOUT( | |
KC_GESC,KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_GRV, KC_CUSTOMBK, KC_INS, | |
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, KC_DEL, | |
CAPS_FN_SWITCH,KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,KC_NUHS,KC_ENT, | |
LEFT_SHIFT_CUSTOM,KC_NUBS,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH,KC_RO, RIGHT_SHIFT_CUSTOM, KC_UP, | |
KC_LCTL,KC_LGUI,KC_LALT,KC_MHEN, KC_SPC, KC_SPC, KC_HENK,KC_RALT,KC_RGUI,MO(_FL),KC_LEFT,KC_DOWN,KC_RGHT), | |
/* Keymap _FL: Function Layer | |
*/ | |
[_FL] = LAYOUT( | |
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,KC_DEL, KC_VOLU, | |
_______,KC_HOME,KC_UP ,KC_END ,KC_PGUP,_______,_______,_______,_______,KC_MPRV,KC_MPLY,KC_MNXT,_______,KC_MUTE, KC_VOLD, | |
_______,KC_LEFT,KC_DOWN,KC_RGHT,KC_PGDN,_______,_______,_______,_______,_______,_______,_______,_______,_______, | |
_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______,_______, KC_PGUP, | |
_______,_______,_______,_______, _______,_______, _______,_______,_______,_______,KC_HOME,KC_PGDN,KC_END), | |
}; | |
void setLights(void){ | |
xprintf("SetLights\n"); | |
if(currLayer==0){ | |
if ( lShState || rShState) { | |
rgblight_sethsv_noeeprom(col_hue2,col_sat2,col_val2); | |
} else { | |
rgblight_sethsv_noeeprom(col_hue1,col_sat1,col_val1); | |
} | |
}else{ | |
if ( lShState || rShState) { | |
rgblight_sethsv_noeeprom(col_hue2,col_sat2,col_val2); | |
} else { | |
rgblight_sethsv_noeeprom(col_hue3,col_sat3,col_val3); | |
} | |
} | |
} | |
void clear_shift(void){ | |
if(MODS_CTRL_MASK){ | |
unregister_code(KC_DEL); | |
unregister_code(KC_BSPC); | |
} | |
} | |
void tap(uint16_t keycode){ | |
register_code(keycode); | |
unregister_code(keycode); | |
}; | |
void matrix_init_user(void) { | |
rgblight_enable(); | |
timer_init(); | |
capsOn=0; | |
rgblight_mode(col_mode1); | |
rgblight_sethsv(col_hue1,col_sat1,col_val1); | |
xprintf("SetLights\n"); | |
currLayer=0; | |
setLights(); | |
} | |
bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |
xprintf("Keycode %u \n", keycode); | |
switch (keycode) { | |
case CAPS_FN_SWITCH: //toggle capslock if tapped, always treat caps as function key | |
xprintf("Caps lock\n"); | |
if (record->event.pressed) { | |
layer_on(_FL); | |
timer_clear(); | |
xprintf("Caps pressed \n" ); | |
} else { | |
layer_off(_FL); | |
total_t=timer_read32(); | |
xprintf("Timer %u \n", total_t); | |
if (total_t<200){ | |
tap(KC_CAPS); | |
if(capsOn==0){ | |
//backlight_level(3); | |
capsOn=1; | |
}else{ | |
//backlight_level(0); | |
capsOn=0; | |
} | |
} | |
} | |
return false; | |
case LEFT_SHIFT_CUSTOM: //Track status of shift keys | |
if (record->event.pressed) { | |
lShState=1; | |
register_code(KC_LSHIFT); | |
setLights(); | |
} else{ | |
lShState=0; | |
unregister_code(KC_LSHIFT); | |
setLights(); | |
} | |
clear_shift(); | |
return false; // | |
case RIGHT_SHIFT_CUSTOM: | |
if (record->event.pressed) { | |
rShState=1; | |
register_code(KC_RSHIFT); | |
setLights(); | |
} else{ | |
rShState=0; | |
unregister_code(KC_RSHIFT); | |
setLights(); | |
} | |
clear_shift(); | |
return false; // | |
case KC_CUSTOMBK: | |
if (record->event.pressed) { | |
if( lShState || rShState){ | |
register_code(KC_DEL); | |
}else{ | |
register_code(KC_BSPC); | |
} | |
}else{ | |
if( lShState || rShState){ | |
unregister_code(KC_DEL); | |
}else{ | |
unregister_code(KC_BSPC); | |
} | |
} | |
return false; | |
default: | |
return true; // Process all other keycodes normally | |
} | |
} | |
uint32_t layer_state_set_kb(uint32_t state) { | |
#ifdef RGBLIGHT_ENABLE | |
// change the color any time a layer switches | |
// This function is called every time a layer switches, no matter how it switches | |
uint8_t bitWhat; | |
bitWhat=biton32(state); | |
switch (bitWhat) { | |
case _BL: | |
//white | |
currLayer=0; | |
lShState=0; // state of left and right shifts | |
rShState=0; | |
setLights(); | |
break; | |
case _FL: | |
//white | |
currLayer=1; | |
lShState=0; // state of left and right shifts | |
rShState=0; | |
setLights(); | |
break; | |
} | |
#endif | |
return state; // this is required, DO NOT REMOVE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment