This article assumes that you are working with the source code downloaded from MassDrop.
Open the file lib /key-functions/public/basic.c and add the following line below after all the #define statements.
extern uint8_t keyboard_leds;
Then go to the push function of the layer you want the LEDs to light up on. Let’s assume we want to turn on NumLock LED when layer 2 is active. In kbfun_layer_push_2 function, we add the following line:
keyboard_leds = 0x01;
So the function will look like this:
/*
* [name]
* Layer push #2
*
* [description]
* Push a layer element containing the layer value specified in the keymap to
* the top of the stack, and record the id of that layer element
*/
void kbfun_layer_push_2(void) {
keyboard_leds = keyboard_leds | 0x01;
layer_push(2);
}
/*
* [name]
* Layer pop #2
*
* [description]
* Pop the layer element created by the corresponding "layer push" function
* out of the layer stack (no matter where it is in the stack, without
* touching any other elements)
*/
void kbfun_layer_pop_2(void) {
keyboard_leds = keyboard_leds & ~(uint8_t)0x01;
layer_pop(2);
}
You will notice that there is a keyboard_leds = keyboard_leds & 0x01 in the pop function for layer 2. This will turn the LED off when we exit the layer. For CapsLock LED set keyboard_leds to 0x02 and set it to 0x04 for scroll lock.
What if you want to turn on multiple LEDs when you are on a specific layer? If you want the NumLock and Scroll Lock LED to turn on when you are on layer 2, you would write the following:
keyboard_leds = keyboard_leds | 0x01 | 0x02;
//To turn them off
keyboard_leds = keyboard_leds & ~(uint8_t)0x01 & ~(uint8_t)0x02;
Leave a Reply