Layers enum/ordering and NUMPAD (with LEDs)

Two things:

  1. If my layer enums are in a different ordering than the keymaps, I get a compiler error.
    ‘END_KEYMAPS’ are mentioned. I would think that the only thing the enum ordering did was determing where in the keymap array the different keymaps are. But I guess there is a whole lot of macro magic going on that depends on the two orderings to be the same. Can anyone elaborate or point to documentation? Layers — Kaleidoscope documentation doesn’t really mention anything about this particular thing.

  2. What are the “rules” for the NUMPAD layer? Depending on where in the keymap ordering I put it, the effects are different.

  • If I have two layers with NUMPAD first, the whole board lights up red. With numpad layer active the numpad keys turn OFF!
  • If I have something like CUSTOM, PRIMARY, NUMPAD, FUNCTION the numpad layer leds do not work.
  • But if I make sure to put NUMPAD second like so: CUSTOM, NUMPAD, FUNCTION, PRIMARY the numpad layer leds works as intended.

The layers listed in KEYMAPS() must be in the same order as in your enum. That’s a limitation of C++.

The Numpad stuff is handled by the NumPad plugin. You don’t need to use it if you don’t want to, you can just turn it off by removing it from the KALEIDOSCOPE_INIT_PLUGINS list. If you do want to use it, head over to your setup() function, and find a line like this: NumPad.numPadLayer = NUMPAD;. If you do not have such a line, the the plugin defaults to layer 0, and then all kinds of things will go crazy.

The NumPad plugin will iterate over all keys, and:

  • If it’s a LockLayer(NUMPAD) key, it will apply the breath effect
  • If any key is defined on the numpad layer (as in, it’s the same keycode as would be active for the key), and isn’t a blocked key, it will apply the numpad-specific color.

In all honesty, I’d just remove the numpad effect, it’s more hassle than it is worth in most cases.

1 Like

Well, I do have the line NumPad.numPadLayer = NUMPAD; in setup(), so I guess it is kind of crazy.

But you’re probably right in removing the effect. You’re not supposed to look at the keyboard anyway. But it would be nice if just the num key would still light up.

You can do that with the Colormap plugin, or if you want something lighter, you can write your custom one, something like this:

#include "kaleidoscope/plugin/LEDControl/LEDUtils.h"  // for breath_compute

namespace kaleidoscope {
class NumLockHighlight: public kaleidoscope::Plugin {
 public:
  EventHandlerResult afterEachCycle() {
    if (Layer.isActive(NUMPAD)) {
      cRGB lock_color = breath_compute(170);
      ::LEDControl.setCrgbAt(KeyAddr(0, 15), lock_color);
    } else {
      ::LEDControl.refreshAt(KeyAddr(0, 15));
    }
  }
};
}
kaleidoscope::NumLockHighLight NumLockHighLight;

This will apply the breath effect to the key at position 0, 15 (top right key on the right side, which is where numlock is mapped by default, change it to wherever your numlock is) if the NUMPAD layer is active. If the layer is not active, it will simply ask the active LED effect to color the key (basically turning the breath effect off).

This li’l plugin touches no other keys, so you’re free to do whatever you wish with them.

1 Like