More code optimizations, remove unnecessary checks

This commit is contained in:
Djuri Baars 2024-12-26 22:20:30 +01:00
parent 66c662e1fd
commit 698c3a3a43
5 changed files with 24 additions and 20 deletions

View file

@ -6,7 +6,7 @@ Adafruit_NeoPixel pixels(NEOPIXEL_COUNT, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
uint ledTaskParams; uint ledTaskParams;
#ifdef HAS_FRONTLIGHT #ifdef HAS_FRONTLIGHT
#define FL_FADE_STEP 25 constexpr uint16_t FL_FADE_STEP = 25;
bool frontlightOn = false; bool frontlightOn = false;
bool flInTransition = false; bool flInTransition = false;
@ -68,18 +68,15 @@ void frontlightFadeInAll(int flDelayTime)
void frontlightFadeInAll(int flDelayTime, bool staggered) void frontlightFadeInAll(int flDelayTime, bool staggered)
{ {
if (preferences.getBool("flDisable")) if (preferences.getBool("flDisable") || frontlightIsOn() || flInTransition)
return;
if (frontlightIsOn())
return;
if (flInTransition)
return; return;
flInTransition = true; flInTransition = true;
const int maxBrightness = preferences.getUInt("flMaxBrightness");
if (staggered) if (staggered)
{ {
int maxBrightness = preferences.getUInt("flMaxBrightness");
int step = FL_FADE_STEP; int step = FL_FADE_STEP;
int staggerDelay = flDelayTime / NUM_SCREENS; int staggerDelay = flDelayTime / NUM_SCREENS;
@ -100,7 +97,7 @@ void frontlightFadeInAll(int flDelayTime, bool staggered)
} }
else else
{ {
for (int dutyCycle = 0; dutyCycle <= preferences.getUInt("flMaxBrightness"); dutyCycle += FL_FADE_STEP) for (int dutyCycle = 0; dutyCycle <= maxBrightness; dutyCycle += FL_FADE_STEP)
{ {
for (int ledPin = 0; ledPin <= NUM_SCREENS; ledPin++) for (int ledPin = 0; ledPin <= NUM_SCREENS; ledPin++)
{ {
@ -179,7 +176,7 @@ std::vector<uint16_t> frontlightGetStatus()
return statuses; return statuses;
} }
bool frontlightIsOn() inline bool frontlightIsOn()
{ {
return frontlightOn; return frontlightOn;
} }
@ -225,7 +222,7 @@ void ledTask(void *parameter)
continue; continue;
} }
uint32_t oldLights[NEOPIXEL_COUNT]; std::array<uint32_t, NEOPIXEL_COUNT> oldLights;
// get current state // get current state
for (int i = 0; i < NEOPIXEL_COUNT; i++) for (int i = 0; i < NEOPIXEL_COUNT; i++)
@ -498,7 +495,7 @@ void blinkDelay(int d, int times)
pixels.show(); pixels.show();
} }
void blinkDelayColor(int d, int times, uint r, uint g, uint b) void blinkDelayColor(int d, int times, uint r, uint g, uint b)
{ {
for (int j = 0; j < times; j++) for (int j = 0; j < times; j++)
{ {
@ -518,7 +515,7 @@ void blinkDelayColor(int d, int times, uint r, uint g, uint b)
pixels.show(); pixels.show();
} }
void blinkDelayTwoColor(int d, int times, uint32_t c1, uint32_t c2) void blinkDelayTwoColor(int d, int times, const uint32_t& c1, const uint32_t& c2)
{ {
for (int j = 0; j < times; j++) for (int j = 0; j < times; j++)
{ {

View file

@ -49,7 +49,7 @@ void setupLeds();
void setupLedTask(); void setupLedTask();
void blinkDelay(int d, int times); void blinkDelay(int d, int times);
void blinkDelayColor(int d, int times, uint r, uint g, uint b); void blinkDelayColor(int d, int times, uint r, uint g, uint b);
void blinkDelayTwoColor(int d, int times, uint32_t c1, uint32_t c2); void blinkDelayTwoColor(int d, int times, const uint32_t& c1, const uint32_t& c2);
void clearLeds(); void clearLeds();
void saveLedState(); void saveLedState();
void restoreLedState(); void restoreLedState();

View file

@ -63,9 +63,7 @@ void setupNostrNotify(bool asDatasource, bool zapNotify)
nostrIsConnected = (status == nostr::ConnectionStatus::CONNECTED); nostrIsConnected = (status == nostr::ConnectionStatus::CONNECTED);
if (!nostrIsConnected) { if (!nostrIsConnected) {
nostrIsSubscribed = false; nostrIsSubscribed = false;
} }
Serial.println("[ Nostr ] Connection status changed: " + String(STATUS_STRINGS[statusIndex]));
}); });
} }

View file

@ -34,11 +34,12 @@ namespace V2Notify
switch (type) switch (type)
{ {
case WStype_DISCONNECTED: case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n"); Serial.print(F("[WSc] Disconnected!\n"));
break; break;
case WStype_CONNECTED: case WStype_CONNECTED:
{ {
Serial.printf("[WSc] Connected to url: %s\n", payload); Serial.print(F("[WSc] Connected to url:"));
Serial.println((char *)payload);
JsonDocument response; JsonDocument response;
@ -81,7 +82,8 @@ namespace V2Notify
break; break;
} }
case WStype_TEXT: case WStype_TEXT:
Serial.printf("[WSc] get text: %s\n", payload); Serial.print(F("[WSc] get text: "));
Serial.println((char *)payload);
// send message to server // send message to server
// webSocket.sendTXT("message here"); // webSocket.sendTXT("message here");

View file

@ -102,6 +102,7 @@ void checkMissedBlocks() {
void monitorDataConnections() { void monitorDataConnections() {
// Price notification monitoring // Price notification monitoring
if (getPriceNotifyInit() && !preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE) && !isPriceNotifyConnected()) { if (getPriceNotifyInit() && !preferences.getBool("fetchEurPrice", DEFAULT_FETCH_EUR_PRICE) && !isPriceNotifyConnected()) {
handlePriceNotifyDisconnection(); handlePriceNotifyDisconnection();
@ -134,6 +135,9 @@ extern "C" void app_main() {
Serial.begin(115200); Serial.begin(115200);
setup(); setup();
bool ownDataSource = preferences.getBool("ownDataSource", DEFAULT_OWN_DATA_SOURCE);
while (true) { while (true) {
if (eventSourceTaskHandle != NULL) { if (eventSourceTaskHandle != NULL) {
xTaskNotifyGive(eventSourceTaskHandle); xTaskNotifyGive(eventSourceTaskHandle);
@ -142,7 +146,10 @@ extern "C" void app_main() {
if (!getIsOTAUpdating()) { if (!getIsOTAUpdating()) {
handleFrontlight(); handleFrontlight();
checkWiFiConnection(); checkWiFiConnection();
monitorDataConnections();
if (!ownDataSource) {
monitorDataConnections();
}
if (getUptime() - getLastTimeSync() > 24 * 60 * 60) { if (getUptime() - getLastTimeSync() > 24 * 60 * 60) {
Serial.println(F("Last time update is longer than 24 hours ago, sync again")); Serial.println(F("Last time update is longer than 24 hours ago, sync again"));