diff --git a/usermods/SN_Photoresistor/usermod_sn_photoresistor.h b/usermods/SN_Photoresistor/usermod_sn_photoresistor.h index 6a7e9f5a..9c3be7cc 100644 --- a/usermods/SN_Photoresistor/usermod_sn_photoresistor.h +++ b/usermods/SN_Photoresistor/usermod_sn_photoresistor.h @@ -22,12 +22,12 @@ // 10 bits #ifndef USERMOD_SN_PHOTORESISTOR_ADC_PRECISION -#define USERMOD_SN_PHOTORESISTOR_ADC_PRECISION 1024.0 +#define USERMOD_SN_PHOTORESISTOR_ADC_PRECISION 1024.0f #endif // resistor size 10K hms #ifndef USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE -#define USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE 10000.0 +#define USERMOD_SN_PHOTORESISTOR_RESISTOR_VALUE 10000.0f #endif // only report if differance grater than offset value diff --git a/usermods/battery_status_basic/usermod_v2_battery_status_basic.h b/usermods/battery_status_basic/usermod_v2_battery_status_basic.h index ab9cba3b..cb3c0867 100644 --- a/usermods/battery_status_basic/usermod_v2_battery_status_basic.h +++ b/usermods/battery_status_basic/usermod_v2_battery_status_basic.h @@ -21,10 +21,10 @@ #ifndef USERMOD_BATTERY_ADC_PRECISION #ifdef ARDUINO_ARCH_ESP32 // 12 bits - #define USERMOD_BATTERY_ADC_PRECISION 4095.0 + #define USERMOD_BATTERY_ADC_PRECISION 4095.0f #else // 10 bits - #define USERMOD_BATTERY_ADC_PRECISION 1024.0 + #define USERMOD_BATTERY_ADC_PRECISION 1024.0f #endif #endif @@ -39,11 +39,11 @@ // https://batterybro.com/blogs/18650-wholesale-battery-reviews/18852515-when-to-recycle-18650-batteries-and-how-to-start-a-collection-center-in-your-vape-shop // Discharge voltage: 2.5 volt + .1 for personal safety #ifndef USERMOD_BATTERY_MIN_VOLTAGE - #define USERMOD_BATTERY_MIN_VOLTAGE 2.6 + #define USERMOD_BATTERY_MIN_VOLTAGE 2.6f #endif #ifndef USERMOD_BATTERY_MAX_VOLTAGE - #define USERMOD_BATTERY_MAX_VOLTAGE 4.2 + #define USERMOD_BATTERY_MAX_VOLTAGE 4.2f #endif class UsermodBatteryBasic : public Usermod diff --git a/wled00/wled_math.h b/wled00/wled_math.h index a13c95d5..bfaff06a 100644 --- a/wled00/wled_math.h +++ b/wled00/wled_math.h @@ -80,36 +80,41 @@ float asin_t(float x) { return res; } -//https://stackoverflow.com/a/42542593 -#define A 0.0776509570923569 -#define B -0.287434475393028 -#define C ((HALF_PI/2) - A - B) - -//polynominal factors for approximation between 1 and 5 -#define C0 0.089494f -#define C1 0.974207f -#define C2 -0.326175f -#define C3 0.05375f -#define C4 -0.003445f - +// declare a template with no implementation, and only one specialization +// this allows hiding the constants, while ensuring ODR causes optimizations +// to still apply. (Fixes issues with conflicting 3rd party #define's) +template T atan_t(T x); +template<> float atan_t(float x) { - bool neg = (x < 0); + //For A/B/C, see https://stackoverflow.com/a/42542593 + static const double A { 0.0776509570923569 }; + static const double B { -0.287434475393028 }; + static const double C { ((HALF_PI/2) - A - B) }; + // polynominal factors for approximation between 1 and 5 + static const float C0 { 0.089494f }; + static const float C1 { 0.974207f }; + static const float C2 { -0.326175f }; + static const float C3 { 0.05375f }; + static const float C4 { -0.003445f }; + #ifdef WLED_DEBUG_MATH float xinput = x; #endif + bool neg = (x < 0); x = std::abs(x); float res; - if (x > 5.0f) { //atan(x) converges to pi/2 - (1/x) for large values + if (x > 5.0f) { // atan(x) converges to pi/2 - (1/x) for large values res = HALF_PI - (1.0f/x); - } - else if (x > 1.0f) { //1 < x < 5 + } else if (x > 1.0f) { //1 < x < 5 float xx = x * x; res = (C4*xx*xx)+(C3*xx*x)+(C2*xx)+(C1*x)+C0; - } else { //this approximation is only for x <= 1 + } else { // this approximation is only for x <= 1 float xx = x * x; res = ((A*xx + B)*xx + C)*x; } - if (neg) res = -res; + if (neg) { + res = -res; + } #ifdef WLED_DEBUG_MATH Serial.printf("atan,%f,%f,%f\n",xinput,res,atan(xinput)); #endif diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index 11a3bb00..4f71721d 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -46,8 +46,6 @@ void handleSerial() static byte red = 0x00; static byte green = 0x00; - uint16_t nBytes = 0; - while (Serial.available() > 0) { yield();