Unique mDNS name

Various optimizations
This commit is contained in:
cschwinne 2019-02-05 19:40:24 +01:00
parent b7b6d0a6bc
commit d1ce23c5ac
8 changed files with 63 additions and 88 deletions

View File

@ -6,7 +6,7 @@
//see https://github.com/Aircoookie/WLED/issues/2 for flicker free ESP32 support
//PIN CONFIGURATION
#define LEDPIN 5 //strip pin. Any for ESP32, gpio2 is recommended for ESP8266
#define LEDPIN 3 //strip pin. Any for ESP32, gpio2 is recommended for ESP8266
#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
#define IR_PIN 4 //infrared pin.
#define AUXPIN 15 //unused auxiliary output pin

View File

@ -892,10 +892,10 @@ uint16_t WS2812FX::mode_theater_chase_rainbow(void) {
* Running lights effect with smooth sine transition.
*/
uint16_t WS2812FX::mode_running_lights(void) {
uint8_t x_scale = (SEGMENT.intensity >> 3) + (SEGMENT.intensity >> 4);
uint8_t x_scale = SEGMENT.intensity >> 2;
for(uint16_t i=0; i < SEGMENT_LENGTH; i++) {
uint8_t s = sin8(i*x_scale +(SEGMENT_RUNTIME.counter_mode_step >> 3));
uint8_t s = sin8(i*x_scale + (SEGMENT_RUNTIME.counter_mode_step >> 4));
setPixelColor(SEGMENT.start + i, color_blend(SEGMENT.colors[1], color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 0), s));
}
SEGMENT_RUNTIME.counter_mode_step += SEGMENT.speed;
@ -1547,35 +1547,29 @@ uint16_t WS2812FX::mode_fire_flicker(void) {
/*
* Gradient run
* Gradient run base function
*/
uint16_t WS2812FX::mode_gradient(void) {
uint16_t WS2812FX::gradient_base(bool loading) {
if (SEGMENT_RUNTIME.counter_mode_call == 0) SEGMENT_RUNTIME.counter_mode_step = 0;
byte p_w = (SEGMENT.colors[0] & 0xFF000000) >> 24;
byte p_r = (SEGMENT.colors[0] & 0xFF0000) >> 16;
byte p_g = (SEGMENT.colors[0] & 0xFF00) >> 8;
byte p_b = SEGMENT.colors[0] & 0xFF;
byte p_w2 = (SEGMENT.colors[1] & 0xFF000000) >> 24;
byte p_r2 = (SEGMENT.colors[1] & 0xFF0000) >> 16;
byte p_g2 = (SEGMENT.colors[1] & 0xFF00) >> 8;
byte p_b2 = SEGMENT.colors[1] & 0xFF;
byte nw,nr,ng,nb;
float per,val; //0.0 = sec 1.0 = pri
float brd = SEGMENT.intensity/2; if (brd <1.0) brd = 1.0;
float brd = SEGMENT.intensity;
if (!loading) brd = SEGMENT.intensity/2;
if (brd <1.0) brd = 1.0;
int pp = SEGMENT_RUNTIME.counter_mode_step;
int p1 = pp-SEGMENT_LENGTH;
int p2 = pp+SEGMENT_LENGTH;
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++)
{
if (loading)
{
val = abs(((i>pp) ? p2:pp) -i);
} else {
val = min(abs(pp-i),min(abs(p1-i),abs(p2-i)));
}
per = val/brd;
if (per >1.0) per = 1.0;
nw = p_w+((p_w2 - p_w)*per);
nr = p_r+((p_r2 - p_r)*per);
ng = p_g+((p_g2 - p_g)*per);
nb = p_b+((p_b2 - p_b)*per);
setPixelColor(i,nr,ng,nb,nw);
setPixelColor(SEGMENT.start + i, color_blend(SEGMENT.colors[0], color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 1), per*255));
}
SEGMENT_RUNTIME.counter_mode_step++;
@ -1585,43 +1579,19 @@ uint16_t WS2812FX::mode_gradient(void) {
}
/*
* Gradient run
*/
uint16_t WS2812FX::mode_gradient(void) {
return gradient_base(false);
}
/*
* Gradient run with hard transition
*/
uint16_t WS2812FX::mode_loading(void) {
if (SEGMENT_RUNTIME.counter_mode_call == 0) SEGMENT_RUNTIME.counter_mode_step = 0;
byte p_w = (SEGMENT.colors[0] & 0xFF000000) >> 24;
byte p_r = (SEGMENT.colors[0] & 0x00FF0000) >> 16;
byte p_g = (SEGMENT.colors[0] & 0x0000FF00) >> 8;
byte p_b = (SEGMENT.colors[0] & 0x000000FF) >> 0;
byte p_w2 = (SEGMENT.colors[1] & 0xFF000000) >> 24;
byte p_r2 = (SEGMENT.colors[1] & 0x00FF0000) >> 16;
byte p_g2 = (SEGMENT.colors[1] & 0x0000FF00) >> 8;
byte p_b2 = (SEGMENT.colors[1] & 0x000000FF) >> 0;
byte nw,nr,ng,nb;
float per,val; //0.0 = sec 1.0 = pri
float brd = SEGMENT.intensity; if (brd <1.0) brd = 1.0;
int pp = SEGMENT_RUNTIME.counter_mode_step;
int p1 = pp+SEGMENT_LENGTH;
for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++)
{
pp = SEGMENT_RUNTIME.counter_mode_step;
if (i > pp) pp+=SEGMENT_LENGTH;
val = abs(pp-i);
per = val/brd;
if (per >1.0) per = 1.0;
nw = p_w+((p_w2 - p_w)*per);
nr = p_r+((p_r2 - p_r)*per);
ng = p_g+((p_g2 - p_g)*per);
nb = p_b+((p_b2 - p_b)*per);
setPixelColor(i,nr,ng,nb,nw);
}
SEGMENT_RUNTIME.counter_mode_step++;
if (SEGMENT_RUNTIME.counter_mode_step > SEGMENT.stop) SEGMENT_RUNTIME.counter_mode_step = SEGMENT.start;
if (SEGMENT.speed == 0) SEGMENT_RUNTIME.counter_mode_step = SEGMENT.stop;
return SPEED_FORMULA_L;
return gradient_base(true);
}
@ -2276,7 +2246,7 @@ uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8
if (SEGMENT.palette == 0 && mcol < 3) return SEGMENT.colors[mcol]; //WS2812FX default
uint8_t paletteIndex = i;
if (mapping) paletteIndex = map(i,SEGMENT.start,SEGMENT.stop,0,255);
if (!wrap) paletteIndex = map(paletteIndex, 0, 255, 0, 240); //cut off blend at palette "end"
if (!wrap) paletteIndex = scale8(paletteIndex, 240); //cut off blend at palette "end"
CRGB fastled_col;
fastled_col = ColorFromPalette( currentPalette, paletteIndex, pbri, (paletteBlend == 3)? NOBLEND:LINEARBLEND);
return fastled_col.r*65536 + fastled_col.g*256 + fastled_col.b;

View File

@ -373,6 +373,7 @@ class WS2812FX {
twinkle(uint32_t),
dissolve(uint32_t),
chase(uint32_t, uint32_t, uint32_t, uint8_t),
gradient_base(bool),
running(uint32_t, uint32_t),
fireworks(uint32_t),
tricolor_chase(uint32_t, uint32_t, uint32_t);

View File

@ -78,7 +78,7 @@
//version code in format yymmddb (b = daily build)
#define VERSION 1902021
#define VERSION 1902051
char versionString[] = "0.8.3-dev";
@ -102,7 +102,7 @@ char ntpServerName[] = "0.wled.pool.ntp.org"; //NTP server to use
//WiFi CONFIG (all these can be changed via web UI, no need to set them here)
char clientSSID[33] = "Your_Network";
char clientPass[65] = "";
char cmDNS[33] = "led"; //mDNS address (x.local), only for Apple and Windows, if Bonjour installed
char cmDNS[33] = "x"; //mDNS address (placeholder, will be replaced by wledXXXXXXXXXXXX.local)
char apSSID[65] = ""; //AP off by default (unless setup)
byte apChannel = 1; //2.4GHz WiFi AP channel (1-13)
byte apHide = 0; //hidden AP SSID

View File

@ -53,7 +53,9 @@ void XML_response(bool isHTTP, bool includeTheme)
oappendi(whiteSec);
oappend("</ws><md>");
oappendi(useHSB);
oappend("</md><ds>");
oappend("</md><cy>");
oappendi(presetCyclingEnabled);
oappend("</cy><ds>");
oappend(serverDescription);
oappend("</ds>");
if (includeTheme)

View File

@ -476,6 +476,7 @@ bool handleSet(String req)
pos = req.indexOf("FX=");
if (pos > 0) {
effectCurrent = getNumVal(&req, pos);
presetCyclingEnabled = false;
}
//set effect speed
pos = req.indexOf("SX=");

View File

@ -11,11 +11,11 @@ void wledInit()
#ifdef ARDUINO_ARCH_ESP32
if (ledCount > 600) ledCount = 600;
#endif
if (!EEPROM.read(397)) strip.init(EEPROM.read(372),ledCount,EEPROM.read(2204)); //quick init
Serial.begin(115200);
Serial.setTimeout(50);
if (!EEPROM.read(397)) strip.init(EEPROM.read(372),ledCount,EEPROM.read(2204)); //quick init
#ifdef USEFS
SPIFFS.begin();
#endif
@ -58,6 +58,11 @@ void wledInit()
}
prepareIds(); //UUID from MAC (for Alexa and MQTT)
if (strcmp(cmDNS,"x") == 0) //fill in unique mdns default
{
strcpy(cmDNS, "wled-");
strcat(cmDNS, escapedMac.c_str());
}
if (mqttDeviceTopic[0] == 0)
{
strcpy(mqttDeviceTopic, "wled/");
@ -108,6 +113,7 @@ void wledInit()
DEBUG_PRINTLN("mDNS responder started");
// Add service to MDNS
MDNS.addService("http", "tcp", 80);
MDNS.addService("wled", "tcp", 80);
}
if (!initLedsLast) strip.service();

View File

@ -187,13 +187,8 @@ void handleTransitions()
setLedsStandard();
return;
}
if (tper - tperLast < 0.004)
{
return;
}
if (tper - tperLast < 0.004) return;
tperLast = tper;
if (fadeTransition)
{
for (byte i = 0; i<3; i++)
{
colT[i] = colOld[i]+((col[i] - colOld[i])*tper);
@ -202,8 +197,8 @@ void handleTransitions()
whiteT = whiteOld +((white - whiteOld )*tper);
whiteSecT = whiteSecOld +((whiteSec - whiteSecOld )*tper);
briT = briOld +((bri - briOld )*tper);
}
if (fadeTransition) setAllLeds();
setAllLeds();
}
}