Turning on specific leds when hitting a specific layer

Sure thing! I’ll also try to update the UPGRADE docs so they’re less vague. I think I wrote a more detailed guide somewhere, will update the upgrade docs with that.

For the time being, a minimal example in spirit of the original:

class LayerColorOverride_: public kaleidoscope::Plugin {
public:
  LayerColorOverride_() {}

  kaleidoscope::EventHandlerResult afterEachCycle() {
    LEDControl.setCrgbAt(0, 0, CRGB(255, 0, 0));
    return kaleidoscope::EventHandlerResult::OK;
  }
};

LayerColorOverride_ LayerColorOverride;

KALEIDOSCOPE_INIT_PLUGINS(
  LEDControl,
  LayerColorOverride,
  ...
)

You can get the highest active layer with Layer.top(), and can implement the coloring logic based on that.

Hope this helps!

2 Likes

Perhaps I’m just being dense, but I tried something like this, and I put Kaleidoscope.useLoopHook(layerColorOverride); as the last line in the method called setup() in my Model01-Firmware.ino file, and when I try to compile it, I get the error 'class kaleidoscope::Kaleidoscope_' has no member named 'useLoopHook'. Has anyone else encountered this?

We changed the API to something much more efficient, and the old API doesn’t work anymore. There’s an updated example here, which works with the new API.

2 Likes

Trying to reconstruct my firmware that I had working three years ago after losing the original file and needing to re-flash everything.

So given this comment above:

You can get the highest active layer with Layer.top() , and can implement the coloring logic based on that.

I’m trying to do something like this:

...
  kaleidoscope::EventHandlerResult afterEachCycle() {
    switch(Layer.top()) {
      case 0:
        LedRainbowWaveEffect.activate();
        break;
      case 1:
        // set different effect/colors for layer 1, etc.
        ...
...

However am seeing the following compilation error: error: 'class kaleidoscope::Layer_' has no member named 'top'

I am also getting an error that LEDControl.setCrgbAt(int, int, cRGB) is not valid. ???

That’s an old version of the API. There are other options for you to use now, some of which are a big improvement. In particular, you can implement the onLayerChange() handler (which is called only after a change to the active layer stack) in your plugin, rather than using afterEachCycle(). Layer.top() has been replaced by Layer.mostRecent(), a perhaps less intuitive name. And LEDControl.setCrgbAt() now has two versions, but neither uses row and column numbers. I believe the one you want is LEDControl.setCrgbAt(KeyAddr(x, y), color).

2 Likes