Connecting LED to CapsLock state

I use Neo2 on the OS (Linux) and adapted my firmware to it. I am satisfied so far.

One thing that bothers my a bit is that Neo2 has a different way to lock in CapsLock. In Neo2 a CapsLock behaviour is activated by pressing both shift keys simultaneously. On ordinaty keyboards this sets the CapsLock LED which even the cheapest keyboard has. If I press SHIFT_L+SHIFT_R on my Model01, the CapsLock LED on the other connected keyboard gets activated.

I would like to configure some key’s LED to show whether CapsLock is activated or not. I am quite sure that I would have to catch some OS event. Could anyone give me some hints to get started on this, please?

You might try something like this in your loop() method:

bool capsState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_CAPS_LOCK);

if (capsState) {
  LEDControl.setCrgbAt(0, 0, CRGB(160, 0, 0));
} else {
  LEDControl.refreshAt(0, 0);
}

This should turn the Prog key red when Caps is active, and turn it off when it isn’t. Mind you, caps lock tracking is known to be a bit unreliable at the moment. I didn’t have the time yet to dig into the issue, but the suspicion is that we aren’t catching some host-side events properly yet.

2 Likes

Awesome, thank you! It works.

Instead of calling refreshAt(…) I call setCrgbAt(…) in the else branch now. Could you please explain me what the former would do here? Why did you not just ommit the else branch?

refreshAt() will reset the color to whatever the active LEDmode would set it to, while setCrgbAt forcibly sets it to a given color. The reason for not omitting the else branch is to turn the highlight off when CapsLock is inactive. If we skip the else branch, the key will remain lit until a LEDMode turns it off (or changes its color).

1 Like

Thank you. I will play around with this.