NUM_STRIPS no longer required with compile-time strip defaults

This commit is contained in:
cschwinne 2021-04-16 01:01:24 +02:00
parent 01dd41bdbf
commit afde7940d8
6 changed files with 46 additions and 30 deletions

View File

@ -2,6 +2,11 @@
### Builds after release 0.12.0 ### 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 #### Build 2104150
- Added ability to add multiple busses as compile time defaults using the esp32_multistrip usermod define syntax - Added ability to add multiple busses as compile time defaults using the esp32_multistrip usermod define syntax

View File

@ -44,15 +44,10 @@
*/ */
//factory defaults LED setup //factory defaults LED setup
//#define NUM_STRIPS 4
//#define PIXEL_COUNTS 30, 30, 30, 30 //#define PIXEL_COUNTS 30, 30, 30, 30
//#define DATA_PINS 16, 1, 3, 4 //#define DATA_PINS 16, 1, 3, 4
//#define DEFAULT_LED_TYPE TYPE_WS2812_RGB //#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 #ifndef PIXEL_COUNTS
#define PIXEL_COUNTS 30 #define PIXEL_COUNTS 30
#endif #endif
@ -79,13 +74,18 @@ void WS2812FX::finalizeInit(uint16_t countPixels, bool skipFirst)
//if busses failed to load, add default (FS issue...) //if busses failed to load, add default (FS issue...)
if (busses.getNumBusses() == 0) { if (busses.getNumBusses() == 0) {
const uint8_t defDataPins[NUM_STRIPS] = {DATA_PINS}; const uint8_t defDataPins[] = {DATA_PINS};
const uint16_t defCounts[NUM_STRIPS] = {PIXEL_COUNTS}; 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; 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]}; uint8_t defPin[] = {defDataPins[i]};
uint16_t start = prevLen; 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; prevLen += count;
BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, COL_ORDER_GRB); BusConfig defCfg = BusConfig(DEFAULT_LED_TYPE, defPin, start, count, COL_ORDER_GRB);
busses.add(defCfg); busses.add(defCfg);

View File

@ -461,7 +461,6 @@ void serializeConfig() {
Bus *bus = busses.getBus(s); Bus *bus = busses.getBus(s);
if (!bus || bus->getLength()==0) break; if (!bus || bus->getLength()==0) break;
JsonObject ins = hw_led_ins.createNestedObject(); JsonObject ins = hw_led_ins.createNestedObject();
ins["en"] = true;
ins[F("start")] = bus->getStart(); ins[F("start")] = bus->getStart();
ins[F("len")] = bus->getLength(); ins[F("len")] = bus->getLength();
JsonArray ins_pin = ins.createNestedArray("pin"); JsonArray ins_pin = ins.createNestedArray("pin");

View File

@ -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 //1. first calculate the day of the year
float N1 = 275 * month / 9; float N1 = 275 * month / 9;
float N2 = (month + 9) / 12; 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; float N = N1 - (N2 * N3) + day - 30;
//2. convert the longitude to hour value and calculate an approximate time //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); float t = N + (((sunset ? 18 : 6) - lngHour) / 24);
//3. calculate the Sun's mean anomaly //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 //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 //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 //5b. right ascension value needs to be in the same quadrant as L
float Lquadrant = floor( L/90) * 90; float Lquadrant = floor_t( L/90) * 90;
float RAquadrant = floor(RA/90) * 90; float RAquadrant = floor_t(RA/90) * 90;
RA = RA + (Lquadrant - RAquadrant); RA = RA + (Lquadrant - RAquadrant);
//5c. right ascension value needs to be converted into hours //5c. right ascension value needs to be converted into hours
RA /= 15.; RA /= 15.0f;
//6. calculate the Sun's declination //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)); float cosDec = cos_t(asin_t(sinDec));
//7a. calculate the Sun's local hour angle //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 //7b. finish calculating H and convert into hours
float H = sunset ? RAD_TO_DEG*acos_t(cosH) : 360 - RAD_TO_DEG*acos_t(cosH); 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 //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 //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 in minutes from midnight
return UT*60; return UT*60;

View File

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // 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 //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG

View File

@ -13,7 +13,7 @@
#define modd(x, y) ((x) - (int)((x) / (y)) * (y)) #define modd(x, y) ((x) - (int)((x) / (y)) * (y))
double cos_t(double x) float cos_t(float x)
{ {
x = modd(x, TWO_PI); x = modd(x, TWO_PI);
char sign = 1; char sign = 1;
@ -22,17 +22,17 @@ double cos_t(double x)
x -= PI; x -= PI;
sign = -1; 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))); 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); return cos_t(HALF_PI - x);
} }
double tan_t(double x) { float tan_t(float x) {
double c = cos_t(x); float c = cos_t(x);
if (c==0.0) return 0; if (c==0.0) return 0;
return sin_t(x) / c; return sin_t(x) / c;
} }
@ -63,9 +63,21 @@ float asin_t(float x) {
#define B -0.287434475393028 #define B -0.287434475393028
#define C ((HALF_PI/2) - A - B) #define C ((HALF_PI/2) - A - B)
double atan_t(double x) { float atan_t(float x) {
double xx = x * x; float xx = x * x;
return ((A*xx + B)*xx + C)*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 #endif