Skip to content

Commit

Permalink
Small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed May 26, 2021
1 parent 8431d0b commit 6c8bf09
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 302 deletions.
5 changes: 4 additions & 1 deletion wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,10 @@ function requestJson(command, rinfo = true, verbose = true) {
d.getElementById('sliderIntensity').value = i.ix;

// Effects
e1.querySelector(`input[name="fx"][value="${i.fx}"]`).checked = true;
var selFx = e1.querySelector(`input[name="fx"][value="${i.fx}"]`);
if (selFx) selFx.checked = true;
else location.reload(); //effect list is gone (e.g. if restoring tab). Reload.

var selElement = e1.querySelector('.selected');
if (selElement) {
selElement.classList.remove('selected')
Expand Down
1 change: 1 addition & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ bool initMqtt();
void publishMqtt();

//ntp.cpp
void handleTime();
void handleNetworkTime();
void sendNTPPacket();
bool checkNTPResponse();
Expand Down
540 changes: 271 additions & 269 deletions wled00/html_ui.h

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions wled00/ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ void updateTimezone() {
tz = new Timezone(tcrDaylight, tcrStandard);
}

void handleTime() {
handleNetworkTime();

toki.millisecond();
toki.setTick();

if (toki.isTick()) //true only in the first loop after a new second started
{
updateLocalTime();
checkTimers();
checkCountdown();
handleOverlays();
}
}

void handleNetworkTime()
{
if (ntpEnabled && ntpConnected && millis() - ntpLastSyncTime > 50000000L && WLED_CONNECTED)
Expand Down
30 changes: 9 additions & 21 deletions wled00/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,24 @@

void initCronixie()
{
if (overlayCurrent == 3 && !cronixieInit)
if (overlayCurrent == 3 && dP[0] == 255) //if dP[0] is 255, cronixie is not yet init'ed
{
setCronixie();
strip.getSegment(0).grouping = 10; //10 LEDs per digit
cronixieInit = true;
} else if (cronixieInit && overlayCurrent != 3)
} else if (dP[0] < 255 && overlayCurrent != 3)
{
strip.getSegment(0).grouping = 1;
cronixieInit = false;
dP[0] = 255;
}
}


void handleOverlays()
{
if (toki.isTick())
{
initCronixie();
updateLocalTime();
checkTimers();
checkCountdown();
if (overlayCurrent == 3) {
_overlayCronixie();//Diamex cronixie clock kit
strip.trigger();
}
overlayRefreshedTime = millis();
initCronixie();
if (overlayCurrent == 3) {
_overlayCronixie();//Diamex cronixie clock kit
strip.trigger();
}
}

Expand Down Expand Up @@ -76,7 +68,6 @@ void _overlayAnalogClock()
if (!analogClockSecondsTrail) strip.setPixelColor(secondPixel, 0xFF0000);
strip.setPixelColor(minutePixel, 0x00FF00);
strip.setPixelColor(hourPixel, 0x0000FF);
overlayRefreshMs = 998;
}


Expand Down Expand Up @@ -118,7 +109,6 @@ void _overlayAnalogCountdown()
strip.setRange(analogClock12pixel, analogClock12pixel + pixelCnt, ((uint32_t)colSec[3] << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]);
}
}
overlayRefreshMs = 998;
}


Expand Down Expand Up @@ -222,8 +212,6 @@ void setCronixie()

DEBUG_PRINT("cset ");
DEBUG_PRINTLN(cronixieDisplay);

overlayRefreshMs = 1997; //Only refresh every 2secs if no seconds are displayed

for (int i = 0; i < 6; i++)
{
Expand All @@ -244,8 +232,8 @@ void setCronixie()
case 'a': dP[i] = 58; i++; break;
case 'm': dP[i] = 74 + getSameCodeLength('m',i,cronixieDisplay); i = i+dP[i]-74; break;
case 'M': dP[i] = 24 + getSameCodeLength('M',i,cronixieDisplay); i = i+dP[i]-24; break;
case 's': dP[i] = 80 + getSameCodeLength('s',i,cronixieDisplay); i = i+dP[i]-80; overlayRefreshMs = 497; break; //refresh more often bc. of secs
case 'S': dP[i] = 30 + getSameCodeLength('S',i,cronixieDisplay); i = i+dP[i]-30; overlayRefreshMs = 497; break;
case 's': dP[i] = 80 + getSameCodeLength('s',i,cronixieDisplay); i = i+dP[i]-80; break; //refresh more often bc. of secs
case 'S': dP[i] = 30 + getSameCodeLength('S',i,cronixieDisplay); i = i+dP[i]-30; break;
case 'Y': dP[i] = 36 + getSameCodeLength('Y',i,cronixieDisplay); i = i+dP[i]-36; break;
case 'y': dP[i] = 86 + getSameCodeLength('y',i,cronixieDisplay); i = i+dP[i]-86; break;
case 'I': dP[i] = 39 + getSameCodeLength('I',i,cronixieDisplay); i = i+dP[i]-39; break; //Month. Don't ask me why month and minute both start with M.
Expand Down
1 change: 0 additions & 1 deletion wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
if (pos > 0) //sets backlight
{
cronixieBacklight = (req.charAt(pos+3) != '0');
overlayRefreshedTime = 0;
}
#endif

Expand Down
6 changes: 2 additions & 4 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ void WiFiEvent(WiFiEvent_t event)

void WLED::loop()
{
toki.millisecond();
toki.setTick();
handleTime();

handleIR(); // 2nd call to function needed for ESP32 to return valid results -- should be good for ESP8266, too
handleConnection();
handleSerial();
Expand All @@ -193,10 +193,8 @@ void WLED::loop()
yield();
handleIO();
handleIR();
handleNetworkTime();
handleAlexa();

handleOverlays();
yield();

if (doReboot)
Expand Down
8 changes: 2 additions & 6 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ WLED_GLOBAL bool useAMPM _INIT(false); // 12h/24h clock format
WLED_GLOBAL byte currentTimezone _INIT(0); // Timezone ID. Refer to timezones array in wled10_ntp.ino
WLED_GLOBAL int utcOffsetSecs _INIT(0); // Seconds to offset from UTC before timzone calculation

WLED_GLOBAL byte overlayDefault _INIT(0); // 0: no overlay 1: analog clock 2: single-digit clocl 3: cronixie
WLED_GLOBAL byte overlayDefault _INIT(0); // 0: no overlay 1: analog clock 2: single-digit clock 3: cronixie
WLED_GLOBAL byte overlayMin _INIT(0), overlayMax _INIT(ledCount - 1); // boundaries of overlay mode

WLED_GLOBAL byte analogClock12pixel _INIT(0); // The pixel in your strip where "midnight" would be
Expand Down Expand Up @@ -448,13 +448,9 @@ WLED_GLOBAL bool hueStoreAllowed _INIT(false), hueNewKey _INIT(false);

// overlays
WLED_GLOBAL byte overlayCurrent _INIT(overlayDefault);
WLED_GLOBAL byte overlaySpeed _INIT(200);
WLED_GLOBAL unsigned long overlayRefreshMs _INIT(200);
WLED_GLOBAL unsigned long overlayRefreshedTime;

// cronixie
WLED_GLOBAL byte dP[] _INIT_N(({ 0, 0, 0, 0, 0, 0 }));
WLED_GLOBAL bool cronixieInit _INIT(false);
WLED_GLOBAL byte dP[] _INIT_N(({ 255, 255, 255, 255, 255, 255 }));

// countdown
WLED_GLOBAL unsigned long countdownTime _INIT(1514764800L);
Expand Down

0 comments on commit 6c8bf09

Please sign in to comment.