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

View file

@ -49,7 +49,7 @@ void setupLeds();
void setupLedTask();
void blinkDelay(int d, int times);
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 saveLedState();
void restoreLedState();

View file

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

View file

@ -34,11 +34,12 @@ namespace V2Notify
switch (type)
{
case WStype_DISCONNECTED:
Serial.printf("[WSc] Disconnected!\n");
Serial.print(F("[WSc] Disconnected!\n"));
break;
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;
@ -81,7 +82,8 @@ namespace V2Notify
break;
}
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
// webSocket.sendTXT("message here");

View file

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