-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/arduino compatibility regression #1283
Feature/arduino compatibility regression #1283
Conversation
Internal Design
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be #if PARTICLE_WIRING_ARDUINO_COMPATIBILITY == 1
just in case PARTICLE_WIRING_ARDUINO_COMPATIBILITY is defined as 0 by the user for some reason? Not even sure if that's a valid use case, but from Arduino.h it seems like it's supported.
Did you check what happens when multiple include files are included? Are the Arduino symbols defined "as expected"? For example:
and Or
It can get hairy with symbol redefinitions in libraries so it would be fine if some cases don't work, but it would be nice if the easy case (both Arduino.h and Particle.h included, libraries don't redefine Arduino symbols) works. |
wiring/inc/spark_wiring_spi.h
Outdated
@@ -137,7 +137,7 @@ class SPISettings : public Printable { | |||
} | |||
|
|||
#ifdef PARTICLE_WIRING_ARDUINO_COMPATIBILITY | |||
typedef particle::SPISettings SPISettings; | |||
typedef particle::__SPISettings __SPISettings; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be typedef particle::__SPISettings SPISettings
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes...good catch. I had the IDE do the renaming...
780000e
to
a4229e1
Compare
…es from spark_wiring_arduino.h to Ardino.h.
…lude `Arduino.h` in your project.
…es so they are not redefined as macros later. If we are splitting hairs, this could be a potential compatibility issue when porting Arduino libraries, in cases where the macro behaves differently from the template, since our version is included by the particle preprocessor for .ino files. The workaround is to disable the preprocessor and then include “Arduino.h” to get the arduino macros rather than the particle templates. I mention this only as a possibility and hope it is seldom needed in practice.
…om the partial API are undefined.
…rduino.h is included to prevent clashes with libraries that define this.
…e C functions `isnan`, `isinf` from being available.
…or SPISettings API and arduino dependency.
a4229e1
to
1292314
Compare
Github can't tell if the changes I requested were implemented... but I think they were? |
force push kind of ruined the review linking -_-
…rain/round are not rredefined. adds more tests
Once the arduino header is included, the symbols remain visible until the end of the compilation unit (and for all subsequent headers.) For example, in this case
The second library is not expecting the arduino symbols to be defined (e.g. it might declare it's own copy of In the example above, reversing the order of the headers would fix the problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Attempts to restore 0.6.0-style arduino compatibility as outlined by issue #1278
In a nutshell:
ARDUINO
and bring in many more additional defines to complete the Arduino API. We'll call this full compatibility.Mixing libraries that require partial and full Arduino compatibility
Libraries that require full Arduino compatibility may include Arduino.h in their library header file, while libraries that depend on partial compatibility (because they themselves define missing symbols) don't include Arduino.h. If a library requiring partial compatibility is included after one requiring full compatibility then the partial compatibility library may break, since Arduino symbols that it's not expecting will be defined.
The workaround for this is to include all libraries requiring partial compatibility before libraries requiring full compatibility in the application file.
Doneness:
ENHANCEMENT / BUG FIX