digistump / OakCore

Arduino/Platformio Core for Oak including Particle library
GNU Lesser General Public License v2.1
55 stars 28 forks source link

Test Servo Library #9

Closed digistump closed 8 years ago

ripred commented 8 years ago

Erik, once I renamed the older Arduino Servo folder it found and used the esp8266 version. It initially failed while compiling the esp8266 version of Servo.cpp with errors about min(...) and max(...) being undefined.

I could not get the existing code to work so I added two local functions in my Servo.cpp called getmin(int x, int y) and getmax(int x, int y) and it all compiles and is working for me. So the only issue seems to be the definition of min and max.

One odd thing to note: After this I went back into the original Arduino/Libraries folder and restored the name of the Servo folder. I exited and restarted the Arduino IDE but for some reason it always finds the correct version now. No idea why it didn't revert back to the older warnings/errors but oh well, it works!

ripred commented 8 years ago

Aha! I had also removed the (really old) residue Servo folder that used to reside under /Users/USERNAME/Documents/Arduino/Libraries/Servo which I believe was residue from the way things worked back in the Arduino 1.0.5 days. So the correct resolution of which version of Servo to use might not be an issue for anyone except really older Arduino users.

Cheers, Trent

joeycortez42 commented 8 years ago

I'm using OS X and I had a similar problem to @ripred. After renaming the default Arduino folder I added this to my Servo.h

#define min(a,b) (((a)<(b))?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b))

And that got it working!

ripred commented 8 years ago

@nokemono42: Yes that will fix it as well. I know that on last check Erik had those exact macros commented out from inside the core. Not sure why other than I suspect they got in the way of something. Not to mention that macro-based min/max definitions have some possibly bad results such as passing argument expressions that modify existing state such as calling max(x += 1, 0) &c but I'm sure you're aware of these traps.

I opted for a more error-safe version that used static functions that copied the passed values into their stack-based arguments just because I'm a bit of a purist :).

All the Best!
Trent