Macros are executed twice

I get those same warnings.

So this happens on both Linux and MacOS. I think we can rule out this being OS-specific. I have a couple of ideas that may cause this, and am trying to verify them. Will report back if I find anything, or if I have anything to test.

Ok, this was easy: reproduced!

The difference in our cases was that I had the legacy plugin API disabled. Once I enabled it, double-triggers are there.

I should have a fix for this soon.

DUH. So obvious in hindsight. Got the problem nailed down, working on a fix. The same issue might affect other plugins too.

The root of this is the compatibility layer, and one particular assumption it made: it assumed that plugins that have a non-empty begin method will always be old-style plugins. For this reason, the default onSetup hook will call ->begin (which is a no-op for v2 plugins). This in turn allows the end-user to use KALEIDOSCOPE_INIT_PLUGINS with old-style plugins as well.

However, this presents a problem when we have v2 plugins that implement a compatibility layer: because now their hooks will run twice! Once called by the v2 layer, once by the v1 compatibility stuff.

There are two solutions here:

  • Implement onSetup() for all the v2 plugins, so that it overrides the default that calls ->begin.
  • Remove the ability to initialize v1 plugins with KALEIDOSCOPE_INIT_PLUGINS.

As we want to remove the compatibility layer soon, I’d go with the second option.

Until we figure out how to handle the case, those affected can comment out this line in Kaleidoscope/src/plugin.h locally, for the time being.

2 Likes

Macros work, unicode works. Thank you!!

I’m relieved because I had gotten addicted to those macros.

Twisted Syster is not working but that might be my fault.

Feel free to open a GitHub issue or a thread here, if you feel you are seeing a bug, or if you need help.

How does one disable the legacy API?

If you use the command-line, add the following line to either ~/.kaleidoscope-builder.conf, or .kaleidoscope-builder.conf in the root directory of your sketch (usually the same as the sketch itself):

LOCAL_CFLAGS="-DKALEIDOSCOPE_ENABLE_V1_PLUGIN_API=0"

Mind you, the affected plugins have been fixed since, so if you update them, you won’t need to do this dance. You still can, mind you, and you’ll save a bunch of PROGMEM, lots of RAM, and gain a little speed too.

1 Like

Does this mean that by running git pull --recurse-submodules or such and recompiling, I no longer have to disable the line in Kaleidoscope/src/plugin.h you mentioned?

Yes, once updated, you do not need to disable that line.

1 Like