evert-arias / EasyBuzzer

The Beep Library For Arduino

Home Page:https://evert-arias.github.io/EasyBuzzer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dangerous defines

proddy opened this issue · comments

not a bug as such, but be careful with the #DEFINES in EasyBuzzer.h

#ifdef ESP8266
#define min _min
#define max _max
#endif
#ifdef ESP32
#define min _min
#define max _max
#endif

(regardless that they are the same) Any other code that uses the words min or max will be substituted at compile time.

I've tried the examples and it's run, i included easybuzzer and added some testing line into my code and the CLI don't compile. in my code there are two variables Min and Max. what i can do? thanks.
EDIT: i've changed oders variables names, but same error. I've deleted "IFDEF ESP ecc." lines as above (i use an arduino mega clone) but same error.
here is error log:

Using library EasyBuzzer-master at version 1.0.4 in folder: /Users/Mastro/Documents/Arduino/libraries/EasyBuzzer-master 
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

ok, maybe is other kind of error:

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_13'
/var/folders/_6/21prk2wd4dj9btzv4287bzsm0000gn/T/arduino_build_739363/libraries/IRremote/IRremote.cpp.o (symbol from plugin):(.text+0x0): first defined here
/Users/Mastro/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
collect2: error: ld returned 1 exit status

It was a conflict with IRremote, this (https://forum.arduino.cc/index.php?topic=120955.0) solved for me.

I agree with @proddy; these redefinitions cause a lot of problems with other code.

Delete

#ifdef ESP8266
#define min _min
#define max _max
#endif
#ifdef ESP32
#define min _min
#define max _max
#endif

in EasyBuzzer.h
Change to:

/* Beep sequence at a given frequency. /
void EasyBuzzerClass::beep(unsigned int frequency, unsigned int const onDuration, unsigned int const offDuration, byte const beeps, unsigned int const pauseDuration, unsigned int const sequences)
{
mFreq = frequency;
mOnDuration = onDuration ? _max(MINIMUM_INTERVAL, onDuration) : 0;
mOffDuration = offDuration ? _max(MINIMUM_INTERVAL, offDuration) : 0;
mBeeps = beeps;
mPauseDuration = pauseDuration ? _max(MINIMUM_INTERVAL, pauseDuration) : 0;
mSequences = sequences;
mFinishedCallbackFunction = NULL;
mStartTime = _max(millis(), 1);
mLastRunTime = 0;
update();
}
/
Beep sequence at a given frequency, with callback functionality. */
void EasyBuzzerClass::beep(unsigned int frequency, unsigned int const onDuration, unsigned int const offDuration, byte const beeps, unsigned int const pauseDuration, unsigned int const sequences, void (*finishedCallbackFunction)())
{
mFreq = frequency;
mOnDuration = onDuration ? _max(MINIMUM_INTERVAL, onDuration) : 0;
mOffDuration = offDuration ? _max(MINIMUM_INTERVAL, offDuration) : 0;
mBeeps = beeps;
mPauseDuration = pauseDuration ? _max(MINIMUM_INTERVAL, pauseDuration) : 0;
mSequences = sequences;
mFinishedCallbackFunction = finishedCallbackFunction;
mStartTime = _max(millis(), 1);
mLastRunTime = 0;
update();
}

in EasyBuzzer.cpp

commented

I think there is also conflict with #include <unordered_set>, if I include unordered_set after EasyBuzzer it will not compile with error code 1, I use ESP32 DOIT Devkit V1.
also I had _min error when I used ArduinoSTL IIRC.