# New Plugin: Kaleidoscope-LED-Fire

**URL:** <https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872>\
**Category:** Plugins\
**Tags:** plugin, release\
**Created:** [May 18, 2019, 7:47am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872 "2019-05-18T07:47:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinriggle](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/kevinriggle/32/2764_2.png) [@kevinriggle](https://community.keyboard.io/u/kevinriggle)\
**Post date:** [May 18, 2019, 7:47am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/1 "2019-05-18T07:47:33Z")

</div>

Plugin name: Kaleidoscope-LED-Fire  
Author: kevinriggle  
Source URL: [https://github.com/kevinr/Kaleidoscope-LED-Fire](https://github.com/kevinr/Kaleidoscope-LED-Fire)

Description:

The FireEffect plugin makes flames that roar from the bottom of your keyboard and every keypress.

![fire-effect](https://canada1.discourse-cdn.com/flex031/uploads/keyboard/original/2X/f/f619e16fe4ac479dc68e2c99391337783f0b8fee.gif)

![fire-effect-keypress](https://canada1.discourse-cdn.com/flex031/uploads/keyboard/original/2X/2/2770e099dda86f3360fac58f0aeb8c5599c3edcb.gif)

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [May 18, 2019, 2:12pm UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/2 "2019-05-18T14:12:22Z")

</div>

Really cool LED effect!

@kevinriggle, `Kaleidoscope.use(...)` is gone for a while now. You might want to update README.md and example sketch of Kaleidoscope-LED-Fire to use `KALEIDOSCOPE_INIT_PLUGINS(...)`. Otherwise it will not work with current versions of the firmware.

---

<div class="post-metadata">

**Author:** ![kevinriggle](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/kevinriggle/32/2764_2.png) [@kevinriggle](https://community.keyboard.io/u/kevinriggle)\
**Post date:** [May 19, 2019, 6:50am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/3 "2019-05-19T06:50:00Z")

</div>

Oh that’s a very good catch @noseglasses, thank you! The code is actually up to date with the current plugin API, or should be (based on [https://github.com/ToyKeeper/Kaleidoscope-LED-Wavepool/pull/7](https://github.com/ToyKeeper/Kaleidoscope-LED-Wavepool/pull/7)), it’s just the documentation which is out of date. I’ll see about fixing that. Let me know if you have any trouble using it with the current firmware.

Update: Ported it to the yet more current plugin API and updated the docs.

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [May 19, 2019, 11:03am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/4 "2019-05-19T11:03:47Z")

</div>

I gave it a try and it looks really gorgeous.

On my Ubuntu system with Arduino 1.8.8 I encountered something strange. When building the example sketch that comes with Kaleidoscope-LED-Fire based on a fresh clone of the bundle and the fire plugin I get a linker error.

```auto
.../keyboardio/avr/libraries/Kaleidoscope-LED-Fire/src/Kaleidoscope/LED-Fire.cpp:135: undefined reference to `hsvToRgb(unsigned int, unsigned int, unsigned int)'

```

This is something that I never encountered before.

By adding `VERBOSE=1` to the build command line, it becomes visible that the linker sees `Kaleidoscope.a` before `Kaleidoscope-LED-Fire.a`. This is the reason for the error as the linker throws away the function `hsvToRgb` that is unused at the point where it is read from `Kaleidoscope.a`. Only when it encounters `Kaleidoscope-LED-Fire.a` later on, it notices that it actually needs that function and throws the error.

It seems that Arduino is having trouble generating a correct linker line. This can be fixed by changing the include order in `Kaleidoscope-LED-Fire/examples/LED-Fire/LED-Fire.ino` to

```cpp
#include <Kaleidoscope-LED-Fire.h>
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>

```

which reverses the order in which the libraries are passed to the linker.

I would be really curious if other people also experience this.

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [May 19, 2019, 5:07pm UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/5 "2019-05-19T17:07:02Z")

</div>

It had slipped my mind that a younger me had already documented the library link order problem [here](https://github.com/keyboardio/Kaleidoscope/wiki/Develop-interdependent-Kaleidoscope-Plugins).

---

<div class="post-metadata">

**Author:** ![kevinriggle](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/kevinriggle/32/2764_2.png) [@kevinriggle](https://community.keyboard.io/u/kevinriggle)\
**Post date:** [May 22, 2019, 4:26am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/6 "2019-05-22T04:26:29Z")

</div>

Thanks for trying it out!

I also observe this issue when compiling with the example sketch, but not when adding `#include <Kaleidoscope-LED-Fire.h>` to the default `Model01-Firmware.ino` following the `#include <Kaleidoscope-LEDControl.h` line. I wonder why.

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [May 22, 2019, 4:07pm UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/7 "2019-05-22T16:07:02Z")

</div>

> [@kevinriggle](#):
>
> I also observe this issue when compiling with the example sketch, but not when adding `#include <Kaleidoscope-LED-Fire.h>` to the default `Model01-Firmware.ino` following the `#include <Kaleidoscope-LEDControl.h` line. I wonder why.

Yeah, I can reproduce that.

As I am really interested in understanding this, I did a thorough investigation of the matter and found the following explanation (which is unfortunately a bit complicated). @algernon, this might be interesting to you as well.

Arduino always adds the sketch object at the start of the linker command line, before any other library archives. Because of this, if the sketch directly or indirectly references a function from `Kaleidoscope.a`, that function will will never be removed during garbage collection.

Unfortunately, this only works with non-virtual function functions because the virtual function that is actually called is only known at runtime. `Kaleidoscope-LED-Fire`, however calls `hsvToRgb(...)` in the plugin’s `update()` method which is a virtual function of the `LEDMode` interface. That’s why `hsvToRgb(...)`, being called ‘virtually’, is garbage collected in the case of the example sketch.

The default sketch on the other hand uses the `BootGreetingEffect` which has a non-virtual event handler method `afterEachCycle()` that indirectly calls `hsvToRgb(...)` as

```auto
kaleidoscope::plugin::BootGreetingEffect::afterEachCycle()
-> breath_compute(...)
   -> hsvToRgb(...)

```

Thus, when the linker encounters `Kaleidoscope.a` in the case of the default sketch, it knows that it is not allowed to garbage collect `hsvToRgb(...)` and everything works as expected.

There is a solution for this problem but it is not at zero cost: We can force the sketch to access `hsvToRgb(...)` directly and only if the `Kaleidoscope-LED-Fire` plugin is actually used. This can be achieved by adding an inlined `onSetup()` event handler to `Kaleidoscope-LED-Fire` that does a dummy call to `hsvToRgb(...)`. As this call is inlined when the sketch is compiled, the linker will see the sketch calling `hsvToRgb(...)` which is thus protected from being garbage collected.

Here’s the PR:

> <https://github.com/kevinr/Kaleidoscope-LED-Fire/pull/1>
>
> …collected
> 
> Signed-off-by: Florian Fleissner \<florian.fleissner@inpartik.de\>

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [May 22, 2019, 5:36pm UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/9 "2019-05-22T17:36:56Z")

</div>

It turns out that this problem does not only happen with virtual functions but in any occasions where a library (plugin) `A` calls a function of another library (plugin) `B` that ends up in the linker command line before `A` and the function called is neither directly nor indirectly called from the sketch.

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [May 23, 2019, 3:33am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/10 "2019-05-23T03:33:14Z")

</div>

I think I’ve seen this, too, but I lacked the expertise to debug the linker, so I just tried a bunch of things until I got it to compile. I’ll have to keep this in mind next time I get an inexplicable linker error…

---

<div class="post-metadata">

**Author:** ![noseglasses](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/noseglasses/32/429_2.png) [@noseglasses](https://community.keyboard.io/u/noseglasses)\
**Post date:** [May 23, 2019, 10:16am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/11 "2019-05-23T10:16:05Z")

</div>

I found a fix for this problem and submitted a [PR](https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio/pull/15) against the bundle repo. It fixes the build system in a way that should hopefully do away with any future link/include order problems.

---

<div class="post-metadata">

**Author:** ![jesse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jesse/32/361_2.png) [@jesse](https://community.keyboard.io/u/jesse)\
**Post date:** [May 24, 2019, 1:27am UTC](https://community.keyboard.io/t/new-plugin-kaleidoscope-led-fire/2872/12 "2019-05-24T01:27:09Z")

</div>

Thank you. That PR has now been merged.
