diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b4a9e9..59a4bad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ### Builds after release 0.12.0 +#### Build 2104151 + +- `NUM_STRIPS` no longer required with compile-time strip defaults +- Further optimizations in wled_math.h + #### Build 2104150 - Added ability to add multiple busses as compile time defaults using the esp32_multistrip usermod define syntax diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index c2f8ff47..7d964cb4 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -44,15 +44,10 @@ */ //factory defaults LED setup -//#define NUM_STRIPS 4 //#define PIXEL_COUNTS 30, 30, 30, 30 //#define DATA_PINS 16, 1, 3, 4 //#define DEFAULT_LED_TYPE TYPE_WS2812_RGB -#if (!defined(NUM_STRIPS) || NUM_STRIPS < 1 || NUM_STRIPS > WLED_MAX_BUSSES) - #define NUM_STRIPS 1 -#endif - #ifndef PIXEL_COUNTS #define PIXEL_COUNTS 30 #endif @@ -79,13 +74,18 @@ void WS2812FX::finalizeInit(uint16_t countPixels, bool skipFirst) //if busses failed to load, add default (FS issue...) if (busses.getNumBusses() == 0) { - const uint8_t defDataPins[NUM_STRIPS] = {DATA_PINS}; - const uint16_t defCounts[NUM_STRIPS] = {PIXEL_COUNTS}; + const uint8_t defDataPins[] = {DATA_PINS}; + const uint16_t defCounts[] = {PIXEL_COUNTS}; + const uint8_t defNumBusses = ((sizeof defDataPins) / (sizeof defDataPins[0])); + const uint8_t defNumCounts = ((sizeof defCounts) / (sizeof defCounts[0])); uint16_t prevLen = 0; - for (uint8_t i = 0; i < NUM_STRIPS; i++) { + for (uint8_t i = 0; i < defNumBusses; i++) { uint8_t defPin[] = {defDataPins[i]}; uint16_t start = prevLen; - uint16_t count = (NUM_STRIPS > 1) ? defCounts[i] : _lengthRaw; + uint16_t count = _lengthRaw; + if (defNumBusses > 1 && defNumCounts) { + count = defCounts[(i < defNumCounts) ? i : defNumCounts -1]; + } prevLen += count; BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, COL_ORDER_GRB); busses.add(defCfg); diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 6c33dfd1..fcfecaae 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -461,7 +461,6 @@ void serializeConfig() { Bus *bus = busses.getBus(s); if (!bus || bus->getLength()==0) break; JsonObject ins = hw_led_ins.createNestedObject(); - ins["en"] = true; ins[F("start")] = bus->getStart(); ins[F("len")] = bus->getLength(); JsonArray ins_pin = ins.createNestedArray("pin"); diff --git a/wled00/ntp.cpp b/wled00/ntp.cpp index 00d33623..3a3d8310 100644 --- a/wled00/ntp.cpp +++ b/wled00/ntp.cpp @@ -319,32 +319,32 @@ int getSunriseUTC(int year, int month, int day, float lat, float lon, bool sunse //1. first calculate the day of the year float N1 = 275 * month / 9; float N2 = (month + 9) / 12; - float N3 = (1 + floor((year - 4 * floor(year / 4) + 2) / 3)); + float N3 = (1 + floor_t((year - 4 * floor_t(year / 4) + 2) / 3)); float N = N1 - (N2 * N3) + day - 30; //2. convert the longitude to hour value and calculate an approximate time - float lngHour = lon / 15.0; + float lngHour = lon / 15.0f; float t = N + (((sunset ? 18 : 6) - lngHour) / 24); //3. calculate the Sun's mean anomaly - float M = (0.9856 * t) - 3.289; + float M = (0.9856f * t) - 3.289f; //4. calculate the Sun's true longitude - float L = fmod(M + (1.916 * sin_t(DEG_TO_RAD*M)) + (0.020 * sin_t(2*DEG_TO_RAD*M)) + 282.634, 360.0); + float L = fmod_t(M + (1.916f * sin_t(DEG_TO_RAD*M)) + (0.02f * sin_t(2*DEG_TO_RAD*M)) + 282.634f, 360.0f); //5a. calculate the Sun's right ascension - float RA = fmod(RAD_TO_DEG*atan_t(0.91764 * tan_t(DEG_TO_RAD*L)), 360.0); + float RA = fmod_t(RAD_TO_DEG*atan_t(0.91764f * tan_t(DEG_TO_RAD*L)), 360.0f); //5b. right ascension value needs to be in the same quadrant as L - float Lquadrant = floor( L/90) * 90; - float RAquadrant = floor(RA/90) * 90; + float Lquadrant = floor_t( L/90) * 90; + float RAquadrant = floor_t(RA/90) * 90; RA = RA + (Lquadrant - RAquadrant); //5c. right ascension value needs to be converted into hours - RA /= 15.; + RA /= 15.0f; //6. calculate the Sun's declination - float sinDec = 0.39782 * sin_t(DEG_TO_RAD*L); + float sinDec = 0.39782f * sin_t(DEG_TO_RAD*L); float cosDec = cos_t(asin_t(sinDec)); //7a. calculate the Sun's local hour angle @@ -354,13 +354,13 @@ int getSunriseUTC(int year, int month, int day, float lat, float lon, bool sunse //7b. finish calculating H and convert into hours float H = sunset ? RAD_TO_DEG*acos_t(cosH) : 360 - RAD_TO_DEG*acos_t(cosH); - H /= 15.; + H /= 15.0f; //8. calculate local mean time of rising/setting - float T = H + RA - (0.06571 * t) - 6.622; + float T = H + RA - (0.06571f * t) - 6.622f; //9. adjust back to UTC - float UT = fmod(T - lngHour, 24.0); + float UT = fmod_t(T - lngHour, 24.0f); // return in minutes from midnight return UT*60; diff --git a/wled00/wled.h b/wled00/wled.h index b955ea4d..5294f8cc 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2104150 +#define VERSION 2104151 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG diff --git a/wled00/wled_math.h b/wled00/wled_math.h index 8184dcf2..88d24179 100644 --- a/wled00/wled_math.h +++ b/wled00/wled_math.h @@ -13,7 +13,7 @@ #define modd(x, y) ((x) - (int)((x) / (y)) * (y)) -double cos_t(double x) +float cos_t(float x) { x = modd(x, TWO_PI); char sign = 1; @@ -22,17 +22,17 @@ double cos_t(double x) x -= PI; sign = -1; } - double xx = x * x; + float xx = x * x; return sign * (1 - ((xx) / (2)) + ((xx * xx) / (24)) - ((xx * xx * xx) / (720)) + ((xx * xx * xx * xx) / (40320)) - ((xx * xx * xx * xx * xx) / (3628800)) + ((xx * xx * xx * xx * xx * xx) / (479001600))); } -double sin_t(double x) { +float sin_t(float x) { return cos_t(HALF_PI - x); } -double tan_t(double x) { - double c = cos_t(x); +float tan_t(float x) { + float c = cos_t(x); if (c==0.0) return 0; return sin_t(x) / c; } @@ -63,9 +63,21 @@ float asin_t(float x) { #define B -0.287434475393028 #define C ((HALF_PI/2) - A - B) -double atan_t(double x) { - double xx = x * x; +float atan_t(float x) { + float xx = x * x; return ((A*xx + B)*xx + C)*x; } +float floor_t(float x) { + bool neg = x < 0; + int val = x; + if (neg) val--; + return val; +} + +float fmod_t(float num, float denom) { + int tquot = num / denom; + return num - tquot * denom; +} + #endif \ No newline at end of file