arduino / node_modulino_firmware

Mozilla Public License 2.0
1 stars 0 forks source link

Rename the Color class to avoid collisions #4

Open alranel opened 7 months ago

alranel commented 7 months ago

Unfortunately, the ArduinoIoTCloud library declares its own Color class. This makes it impossible to use Modulino.h in an IoT Cloud project. Likely, other third-party libraries may declare a Color class considering it's a pretty generic name, as well as variables or constants named RED, BLUE, GREEN...

We need to find a future-proof solution to avoid collisions.

Proposal 1 (easy)

Let's not expose any class for colors nor constants in Modulino. To set LED color we'll use this basic signature:

void ModulinoPixels::set(int idx, uint8_t r, uint8_t g, uint8_t b, uint8_t brightness = 255);

Proposal 2 (more ambitious)

Let's create an official Arduino_Color library exporting an Arduino_Color class providing a very generic and versatile API that any third-party library can implement. This library would also export a Color alias in the global namespace, except when a user tells it to not do so:

#define ARDUINO_COLOR_NO_GLOBAL
#include <Arduino_Color.h>

Then, we modify the ArduinoIoTCloud library to use this one as a dependency. Ta-dah, we'd get magic interoperability between cloud and Modulinos:

pixels.set(0, my_cloud_color);