Hi. I’m having a very specific issue, and really obscure as well. If I add a second param to a subclass, program compiles and uploads to NodeMCU ESP32, but it doesn’t work properly.
Basically, I have a set of animations for an Adafruit Ring, and I’m using FastLed to create them.
I’m working with platformio v5.0.2b1, using CLion 20.04, and the toolchain for Clion is MinGW.
Anyway, the issue I’m about to tell you occurs even if I compile using Arduino IDE.
Basically, animations are polymorphic, and I’m kinda using the Strategy pattern to pass the animations to the led ring object I created.
Code structure is quite simple. Apart from the strategy pattern I’m using Adapter to wrap and decouple Fastled.
You can see the code structure here. It’s working, but not using Leds (only strings):
https://repl.it/repls/MeagerPrivateBoard#main.cpp
So problem is: whenever I add a second parameter to the constructor of a given animation (meaning, to a subclass of Animation class), the program compiles, but the animation stops working. Ring stays off (no lights at all)
FYC:
#pragma once
#include <FastLED.h>
#include "Animation.h"
#include "Ring.h"
class PlainColorAnimation : public Animation {
public:
PlainColorAnimation(Ring &aRing)
: Animation(aRing) {}
void execute() override {
ring.fill(Ring::colors["yellow"]); // TODO: make this dynamic by receiving a color param
}
};
Check now this. What I try to do, I try to add a second parameter (just like you can see in the working code I linked before). So:
PlainColorAnimation(Ring &aRing, CRGB aColor = CRGB::Green)
Just that, I’m not even setting aColor value to a member variable, and that param causes the animation to fail. Meaning, no lights will display, and… Serial console will display garbage (I think this may be important).
I wondered why the Repl example worked fine. It’s not a problem with polymorphism, is it? So, I discovered Repl uses c++17 and I had c++11. So…, I bumped my version adding some lines in my ini file.
FYC:
[esp32]
; upgrade XTensa32 GCC/G++ compiler to 8.2.0
; use bleeding edge arduino-esp32
platform_packages =
; toolchain-xtensa32 @ 2.80200.200226 ← this line here is maybe needed by fails in windows 10
framework-arduinoespressif32 @ GitHub - espressif/arduino-esp32: Arduino core for the ESP32
[common]
build_flags =
; do not redefine arduino
; -DARDUINO=10800
-DESP32=1
-DARDUINO_ARCH_ESP32=1
-DBOARD_HAS_PSRAM
-std=c++17
; only use C++17 now not GNU++17. This is an either-or relation.
; -std=gnu++17
build_unflags =
-std=gnu++11
[env:nodemcu-32s]
platform = espressif32@1.12.4
board = nodemcu-32s
framework = arduino
lib_deps = fastled/FastLED@^3.3.3
lib_ldf_mode = off
upload_port = COM5
platform_packages =
${esp32.platform_packages}
build_flags =
${common.build_flags}
build_unflags =
${common.build_unflags}
I’ve got that code from here:
Problem persist
Any clue?