Legacy
To provide maximum compatibility for Arduino libraries, and still support hundreds of libraries that were ported from Arduino to Particle, we include Arduino defines by default now.
In the past, users would get Arduino defines without the need to add #include "Arduino.h"
to their code. And there was no Arduino.h, so that had to be commented out in libraries for them to compile.
Present
Now Arduino.h just includes Particle.h (which in turn includes the legacy application.h). Also legacy libraries would include application.h directly in many cases. If application.h is included, PARTICLE_ARDUINO_COMPATIBILITY will be defined. And by default it will be included and set to 1. If that is the case, all of the defines in spark_wiring_arduino.h
will be included in your code. So RwReg will be defined.
There is no way to get ahead of the application.h include if it is included in a library and that is added to your app in the Web IDE. It appears to compile the library first.
If we could get the app to compile first, and compile the library once the include for the library is found, we could juggle something like this perhaps:
#include "Particle.h"
#ifdef RwReg
#undef RwReg
#endif
#include "FastLED.h"
FASTLED_USING_NAMESPACE;
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
void setup() { FastLED.addLeds<NEOPIXEL, 6>(leds, NUM_LEDS); }
void loop() {
leds[0] = CRGB::White; FastLED.show(); delay(30);
leds[0] = CRGB::Black; FastLED.show(); delay(30);
}
But that’s going to be a mess I think because there’s bound to be a bunch of things to redefine.
Suggested Way Forward (0.6.1)
I think the proper thing to do here to maintain compatibility with the library and older AND newer firmware, is to wrap the arduino-based defines embedded in the library with
#ifndef MY_ARDUINO_SYMBOL
#define MY_ARDUINO_SYMBOL
#endif
These defines would have been needed in the past for older firmware when we didn’t have a lot of arduino defines by default. Now that we include everything and the kitchen sink, you don’t need to include these any more.
If you have your arduino defines grouped in one place, a test for ARDUINO might be a good way to include them all. That way you don’t have to put #ifndef on each of them, even though it’s still a good idea.
So that might look like this:
#ifndef ARDUINO
// add my arduino defines here to be included for firmware < 0.6.1-rc.2 !
#endif
##Future Thoughts
A way around some of the issues we are having now might have been to not include the new big list of arduino defines by default, but instead just include the small list of defines from 0.6.0 by default and require users to include #include Arduino.h
to get the big list. That sounds easy enough, but still might be tricky depending on when Arduino.h is included. It would likely involve undef/redef of the small list of defines from 0.6.0. This could also allow above proposed changes to libraries for 0.6.1 to remain working for >=0.7.0 as the small list of defines did not include ARDUINO
.