From 5c457dfdbabd81acca811723a0565bf3379e18d4 Mon Sep 17 00:00:00 2001 From: Torsten Stauder Date: Sat, 8 Feb 2020 19:38:57 +0100 Subject: [PATCH] Datatype-refactoring was crap. So reverted... --- src/main.cpp | 532 +++++++++++++++++++++++++-------------------------- 1 file changed, 259 insertions(+), 273 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ea7dc5a..9f2f69b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -130,57 +130,53 @@ typedef struct { // Bit field } playProps; playProps playProperties; - -typedef struct { - // Neopixel - uint8_t initialLedBrightness = 16; // Initial brightness of Neopixel - uint8_t ledBrightness = initialLedBrightness; - uint8_t nightLedBrightness = 2; // Brightness of Neopixel in nightmode - // MQTT - bool enableMqtt = true; - uint8_t mqttFailCount = 3; // Number of times mqtt-reconnect is allowed to fail. If >= mqttFailCount to further reconnects take place - uint8_t const stillOnlineInterval = 60; // Interval 'I'm still alive' is sent via MQTT (in seconds) - // RFID - uint8_t const cardIdSize = 4; // RFID - // Volume - uint8_t maxVolume = 21; // Maximum volume that can be adjusted - uint8_t minVolume = 0; // Lowest volume that can be adjusted - uint8_t initVolume = 3; // 0...21 - // Sleep - uint8_t maxInactivityTime = 10; // Time in minutes, after uC is put to deep sleep because of inactivity - uint8_t sleepTimer = 30; // Sleep timer in minutes that can be optionally used (and modified later via MQTT or RFID) - // Button-configuration - uint8_t buttonDebounceInterval = 50; // Interval in ms to software-debounce buttons - uint16_t intervalToLongPress = 700; // Interval in ms to distinguish between short and long press of previous/next-button -} genConfig; -genConfig generalConfig; - -typedef struct { - // WiFi - unsigned long wifiCheckLastTimestamp = 0; - // Neopixel - bool showLedError: 1; - bool showLedOk: 1; - bool showPlaylistProgress: 1; - bool showRewind: 1; - // MQTT - unsigned long lastOnlineTimestamp = 0; - // RFID - unsigned long lastRfidCheckTimestamp = 0; - char *currentRfidTagId = NULL; - // Sleep - unsigned long lastTimeActiveTimestamp = 0; // Timestamp of last user-interaction - unsigned long sleepTimerStartTimestamp = 0; // Flag if sleep-timer is active - bool gotoSleep: 1; // Flag for turning uC immediately into deepsleep - bool lockControls: 1; // Flag if buttons and rotary encoder is locked - bool bootComplete: 1; - // Rotary encoder-helper - int32_t lastEncoderValue; - int32_t currentEncoderValue; - int32_t lastVolume = -1; // Don't change -1 as initial-value! - uint8_t currentVolume = generalConfig.initVolume; -} help; -help helper; +// Configuration goes here.... +// Neopixel +uint8_t initialLedBrightness = 16; // Initial brightness of Neopixel +uint8_t ledBrightness = initialLedBrightness; +uint8_t nightLedBrightness = 2; // Brightness of Neopixel in nightmode +// MQTT +bool enableMqtt = true; +uint8_t mqttFailCount = 3; // Number of times mqtt-reconnect is allowed to fail. If >= mqttFailCount to further reconnects take place +uint8_t const stillOnlineInterval = 60; // Interval 'I'm still alive' is sent via MQTT (in seconds) +// RFID +uint8_t const cardIdSize = 4; // RFID +// Volume +uint8_t maxVolume = 21; // Maximum volume that can be adjusted +uint8_t minVolume = 0; // Lowest volume that can be adjusted +uint8_t initVolume = 3; // 0...21 +// Sleep +uint8_t maxInactivityTime = 10; // Time in minutes, after uC is put to deep sleep because of inactivity +uint8_t sleepTimer = 30; // Sleep timer in minutes that can be optionally used (and modified later via MQTT or RFID) +// Button-configuration +uint8_t buttonDebounceInterval = 50; // Interval in ms to software-debounce buttons +uint16_t intervalToLongPress = 700; // Interval in ms to distinguish between short and long press of previous/next-button + + +// Don't change anything here unless you know what you're doing +// WiFi +unsigned long wifiCheckLastTimestamp = 0; +// Neopixel +bool showLedError = false; +bool showLedOk = false; +bool showPlaylistProgress = false; +bool showRewind = false; +// MQTT +unsigned long lastOnlineTimestamp = 0; +// RFID +unsigned long lastRfidCheckTimestamp = 0; +char *currentRfidTagId = NULL; +// Sleep +unsigned long lastTimeActiveTimestamp = 0; // Timestamp of last user-interaction +unsigned long sleepTimerStartTimestamp = 0; // Flag if sleep-timer is active +bool gotoSleep = false; // Flag for turning uC immediately into deepsleep +bool lockControls = false; // Flag if buttons and rotary encoder is locked +bool bootComplete = false; +// Rotary encoder-helper +int32_t lastEncoderValue; +int32_t currentEncoderValue; +int32_t lastVolume = -1; // Don't change -1 as initial-value! +uint8_t currentVolume = initVolume; // AP-WiFi static const char accessPointNetworkSSID[] PROGMEM = "Tonuino"; // Access-point's SSID @@ -401,7 +397,7 @@ void IRAM_ATTR onTimer() { // If timer-semaphore is set, read buttons (unless controls are locked) void buttonHandler() { if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE) { - if (helper.lockControls) { + if (lockControls) { return; } unsigned long currentTimestamp = millis(); @@ -412,7 +408,7 @@ void buttonHandler() { // Iterate over all buttons in struct-array for (uint8_t i=0; i < sizeof(buttons) / sizeof(buttons[0]); i++) { - if (buttons[i].currentState != buttons[i].lastState && currentTimestamp - buttons[i].lastPressedTimestamp > generalConfig.buttonDebounceInterval) { + if (buttons[i].currentState != buttons[i].lastState && currentTimestamp - buttons[i].lastPressedTimestamp > buttonDebounceInterval) { if (!buttons[i].currentState) { buttons[i].isPressed = true; buttons[i].lastPressedTimestamp = currentTimestamp; @@ -429,14 +425,14 @@ void buttonHandler() { // Do corresponding actions for all buttons void doButtonActions(void) { - if (helper.lockControls) { + if (lockControls) { return; // Avoid button-handling if buttons are locked } for (uint8_t i=0; i < sizeof(buttons) / sizeof(buttons[0]); i++) { if (buttons[i].isPressed) { if (buttons[i].lastReleasedTimestamp > buttons[i].lastPressedTimestamp) { - if (buttons[i].lastReleasedTimestamp - buttons[i].lastPressedTimestamp >= generalConfig.intervalToLongPress) { + if (buttons[i].lastReleasedTimestamp - buttons[i].lastPressedTimestamp >= intervalToLongPress) { switch (i) // Long-press-actions { case 0: @@ -455,7 +451,7 @@ void doButtonActions(void) { break; case 3: - helper.gotoSleep = true; + gotoSleep = true; break; } } else { @@ -519,8 +515,8 @@ bool publishMqtt(const char *topic, uint32_t payload, bool retained) { /* Cyclic posting via MQTT that ESP is still alive */ void postHeartbeatViaMqtt(void) { - if (millis() - helper.lastOnlineTimestamp >= generalConfig.stillOnlineInterval*1000) { - helper.lastOnlineTimestamp = millis(); + if (millis() - lastOnlineTimestamp >= stillOnlineInterval*1000) { + lastOnlineTimestamp = millis(); if (publishMqtt((char *) FPSTR(topicState), "Online", false)) { loggerNl((char *) FPSTR(stillOnlineMqtt), LOGLEVEL_DEBUG); } @@ -534,7 +530,7 @@ void postHeartbeatViaMqtt(void) { bool reconnect() { uint8_t maxRetries = 10; - while (!MQTTclient.connected() && generalConfig.mqttFailCount < maxRetries) { + while (!MQTTclient.connected() && mqttFailCount < maxRetries) { snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s %s", (char *) FPSTR(tryConnectMqttS), mqtt_server); loggerNl(logBuf, LOGLEVEL_NOTICE); @@ -569,11 +565,11 @@ bool reconnect() { // Publish some stuff publishMqtt((char *) FPSTR(topicState), "Online", false); publishMqtt((char *) FPSTR(topicTrackState), "---", false); - publishMqtt((char *) FPSTR(topicLoudnessState), helper.currentVolume, false); - publishMqtt((char *) FPSTR(topicSleepTimerState), helper.sleepTimerStartTimestamp, false); + publishMqtt((char *) FPSTR(topicLoudnessState), currentVolume, false); + publishMqtt((char *) FPSTR(topicSleepTimerState), sleepTimerStartTimestamp, false); publishMqtt((char *) FPSTR(topicLockControlsState), "OFF", false); publishMqtt((char *) FPSTR(topicPlaymodeState), playProperties.playMode, false); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); publishMqtt((char *) FPSTR(topicRepeatModeState), 0, false); char currentIPString[16]; @@ -582,9 +578,9 @@ bool reconnect() { return MQTTclient.connected(); } else { - snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: rc=%i (%d / %d)", (char *) FPSTR(mqttConnFailed), MQTTclient.state(), generalConfig.mqttFailCount+1, maxRetries); + snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: rc=%i (%d / %d)", (char *) FPSTR(mqttConnFailed), MQTTclient.state(), mqttFailCount+1, maxRetries); loggerNl(logBuf, LOGLEVEL_ERROR); - generalConfig.mqttFailCount++; + mqttFailCount++; delay(500); } } @@ -615,7 +611,7 @@ void callback(const char *topic, const byte *payload, uint32_t length) { // Go to sleep? if (strcmp_P(topic, topicSleepCmnd) == 0) { if ((strcmp(receivedString, "OFF") == 0) || (strcmp(receivedString, "0") == 0)) { - helper.gotoSleep = true; + gotoSleep = true; } } @@ -637,32 +633,32 @@ void callback(const char *topic, const byte *payload, uint32_t length) { if (strcmp(receivedString, "EOP") == 0) { playProperties.sleepAfterPlaylist = true; loggerNl((char *) FPSTR(sleepTimerEOP), LOGLEVEL_NOTICE); - helper.showLedOk = true; + showLedOk = true; return; } else if (strcmp(receivedString, "EOT") == 0) { playProperties.sleepAfterCurrentTrack = true; loggerNl((char *) FPSTR(sleepTimerEOT), LOGLEVEL_NOTICE); - helper.showLedOk = true; + showLedOk = true; return; } else if (strcmp(receivedString, "0") == 0) { - if (helper.sleepTimerStartTimestamp) { - helper.sleepTimerStartTimestamp = 0; + if (sleepTimerStartTimestamp) { + sleepTimerStartTimestamp = 0; loggerNl((char *) FPSTR(sleepTimerStop), LOGLEVEL_NOTICE); - helper.showLedOk = true; + showLedOk = true; publishMqtt((char *) FPSTR(topicSleepState), 0, false); return; } else { loggerNl((char *) FPSTR(sleepTimerAlreadyStopped), LOGLEVEL_INFO); - helper.showLedError = true; + showLedError = true; return; } } - generalConfig.sleepTimer = strtoul(receivedString, NULL, 10); - snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %lu Minute(n)", (char *) FPSTR(sleepTimerSetTo), generalConfig.sleepTimer); + sleepTimer = strtoul(receivedString, NULL, 10); + snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %lu Minute(n)", (char *) FPSTR(sleepTimerSetTo), sleepTimer); loggerNl(logBuf, LOGLEVEL_NOTICE); - helper.showLedOk = true; + showLedOk = true; - helper.sleepTimerStartTimestamp = millis(); // Activate timer + sleepTimerStartTimestamp = millis(); // Activate timer playProperties.sleepAfterPlaylist = false; playProperties.sleepAfterCurrentTrack = false; } @@ -675,14 +671,14 @@ void callback(const char *topic, const byte *payload, uint32_t length) { // Check if controls should be locked else if (strcmp_P(topic, topicLockControlsCmnd) == 0) { if (strcmp(receivedString, "OFF") == 0) { - helper.lockControls = false; + lockControls = false; loggerNl((char *) FPSTR(allowButtons), LOGLEVEL_NOTICE); - helper.showLedOk = true; + showLedOk = true; } else if (strcmp(receivedString, "ON") == 0) { - helper.lockControls = true; + lockControls = true; loggerNl((char *) FPSTR(lockButtons), LOGLEVEL_NOTICE); - helper.showLedOk = true; + showLedOk = true; } } @@ -696,7 +692,7 @@ void callback(const char *topic, const byte *payload, uint32_t length) { snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); loggerNl((char *) FPSTR(noPlaylistNotAllowedMqtt), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; } else { switch (repeatMode) { case NO_REPEAT: @@ -705,7 +701,7 @@ void callback(const char *topic, const byte *payload, uint32_t length) { snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); loggerNl((char *) FPSTR(modeRepeatNone), LOGLEVEL_INFO); - helper.showLedOk = true; + showLedOk = true; break; case TRACK: @@ -714,7 +710,7 @@ void callback(const char *topic, const byte *payload, uint32_t length) { snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); loggerNl((char *) FPSTR(modeRepeatTrack), LOGLEVEL_INFO); - helper.showLedOk = true; + showLedOk = true; break; case PLAYLIST: @@ -723,7 +719,7 @@ void callback(const char *topic, const byte *payload, uint32_t length) { snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); loggerNl((char *) FPSTR(modeRepeatPlaylist), LOGLEVEL_INFO); - helper.showLedOk = true; + showLedOk = true; break; case TRACK_N_PLAYLIST: @@ -732,11 +728,11 @@ void callback(const char *topic, const byte *payload, uint32_t length) { snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); loggerNl((char *) FPSTR(modeRepeatTracknPlaylist), LOGLEVEL_INFO); - helper.showLedOk = true; + showLedOk = true; break; default: - helper.showLedError = true; + showLedError = true; snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); break; @@ -747,14 +743,14 @@ void callback(const char *topic, const byte *payload, uint32_t length) { // Check if LEDs should be dimmed else if (strcmp_P(topic, topicLedBrightnessCmnd) == 0) { - generalConfig.ledBrightness = strtoul(receivedString, NULL, 10); + ledBrightness = strtoul(receivedString, NULL, 10); } // Requested something that isn't specified? else { snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(noValidTopic), topic); loggerNl(logBuf, LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; } free(receivedString); @@ -890,7 +886,7 @@ char ** returnPlaylistFromSD(File _fileOrDirectory) { files = (char **) malloc(sizeof(char *) * 2); // +1 because [0] is used for number of elements; [1] -> [n] is used for payload if (files == NULL) { loggerNl((char *) FPSTR(unableToAllocateMemForPlaylist), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; return NULL; } loggerNl((char *) FPSTR(fileModeDetected), LOGLEVEL_INFO); @@ -928,7 +924,7 @@ char ** returnPlaylistFromSD(File _fileOrDirectory) { loggerNl((char *) FPSTR(reallocCalled), LOGLEVEL_DEBUG); if (serializedPlaylist == NULL) { loggerNl((char *) FPSTR(unableToAllocateMemForLinearPlaylist), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; return files; } } @@ -950,7 +946,7 @@ char ** returnPlaylistFromSD(File _fileOrDirectory) { files = (char **) malloc(sizeof(char *) * cnt + 1); if (files == NULL) { loggerNl((char *) FPSTR(unableToAllocateMemForPlaylist), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; free(serializedPlaylist); return NULL; } @@ -969,7 +965,7 @@ char ** returnPlaylistFromSD(File _fileOrDirectory) { files[0] = (char *) malloc(sizeof(char) * 5); if (files[0] == NULL) { loggerNl((char *) FPSTR(unableToAllocateMemForPlaylist), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; return NULL; } sprintf(files[0], "%u", cnt); @@ -1011,7 +1007,7 @@ size_t nvsRfidWriteWrapper (const char *_rfidCardId, const char *_track, const u void playAudio(void *parameter) { static Audio audio; audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); - audio.setVolume(generalConfig.initVolume); + audio.setVolume(initVolume); uint8_t currentVolume; static BaseType_t trackQStatus; @@ -1042,7 +1038,7 @@ void playAudio(void *parameter) { // If we're in audiobook-mode and apply a modification-card, we don't // want to save lastPlayPosition for the mod-card but for the card that holds the playlist - strncpy(playProperties.playRfidTag, helper.currentRfidTagId, sizeof(playProperties.playRfidTag) / sizeof(playProperties.playRfidTag[0])); + strncpy(playProperties.playRfidTag, currentRfidTagId, sizeof(playProperties.playRfidTag) / sizeof(playProperties.playRfidTag[0])); } if (playProperties.trackFinished) { playProperties.trackFinished = false; @@ -1057,20 +1053,20 @@ void playAudio(void *parameter) { } } if (playProperties.sleepAfterCurrentTrack) { // Go to sleep if "sleep after track" was requested - helper.gotoSleep = true; + gotoSleep = true; } if (!playProperties.repeatCurrentTrack) { // If endless-loop requested, track-number will not be incremented playProperties.currentTrackNumber++; } else { loggerNl((char *) FPSTR(repeatTrackDueToPlaymode), LOGLEVEL_INFO); - helper.showRewind = true; + showRewind = true; } } if (playProperties.playlistFinished && trackCommand != 0) { loggerNl((char *) FPSTR(noPlaymodeChangeIfIdle), LOGLEVEL_NOTICE); trackCommand = 0; - helper.showLedError = true; + showLedError = true; continue; } /* Check if track-control was called @@ -1119,7 +1115,7 @@ void playAudio(void *parameter) { } else { loggerNl((char *) FPSTR(lastTrackAlreadyActive), LOGLEVEL_NOTICE); trackCommand = 0; - helper.showLedError = true; + showLedError = true; continue; } trackCommand = 0; @@ -1150,7 +1146,7 @@ void playAudio(void *parameter) { } else { if (playProperties.playMode == WEBSTREAM) { loggerNl((char *) FPSTR(trackChangeWebstream), LOGLEVEL_INFO); - helper.showLedError = true; + showLedError = true; trackCommand = 0; continue; } @@ -1158,7 +1154,7 @@ void playAudio(void *parameter) { nvsRfidWriteWrapper(playProperties.playRfidTag, *(playProperties.playlist + playProperties.currentTrackNumber), 0, playProperties.playMode, playProperties.currentTrackNumber, playProperties.numberOfTracks); } audio.stopSong(); - helper.showRewind = true; + showRewind = true; audio.connecttoSD(*(playProperties.playlist + playProperties.currentTrackNumber)); loggerNl((char *) FPSTR(trackStart), LOGLEVEL_INFO); trackCommand = 0; @@ -1184,7 +1180,7 @@ void playAudio(void *parameter) { } } else { loggerNl((char *) FPSTR(firstTrackAlreadyActive), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; trackCommand = 0; continue; } @@ -1208,7 +1204,7 @@ void playAudio(void *parameter) { } } else { loggerNl((char *) FPSTR(lastTrackAlreadyActive), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; trackCommand = 0; continue; } @@ -1221,7 +1217,7 @@ void playAudio(void *parameter) { default: trackCommand = 0; loggerNl((char *) FPSTR(cmndDoesNotExist), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; continue; } @@ -1239,14 +1235,14 @@ void playAudio(void *parameter) { playProperties.currentTrackNumber = 0; playProperties.numberOfTracks = 0; if (playProperties.sleepAfterPlaylist) { - helper.gotoSleep = true; + gotoSleep = true; } continue; } else { // Check if sleep after current track/playlist was requested if (playProperties.sleepAfterPlaylist || playProperties.sleepAfterCurrentTrack) { playProperties.playlistFinished = true; playProperties.playMode = NO_PLAYLIST; - helper.gotoSleep = true; + gotoSleep = true; continue; } // Repeat playlist; set current track number back to 0 loggerNl((char *) FPSTR(repeatPlaylistDueToPlaymode), LOGLEVEL_NOTICE); @@ -1269,7 +1265,7 @@ void playAudio(void *parameter) { continue; } else { audio.connecttoSD(*(playProperties.playlist + playProperties.currentTrackNumber)); - helper.showPlaylistProgress = true; + showPlaylistProgress = true; if (playProperties.startAtFilePos > 0) { audio.setFilePos(playProperties.startAtFilePos); snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s %u", (char *) FPSTR(trackStartatPos), audio.getFilePos()); @@ -1299,7 +1295,7 @@ void playAudio(void *parameter) { if (playProperties.playlistFinished || playProperties.pausePlay) { vTaskDelay(portTICK_PERIOD_MS*10); // Waste some time if playlist is not active } else { - helper.lastTimeActiveTimestamp = millis(); // Refresh if playlist is active so uC will not fall asleep due to reaching inactivity-time + lastTimeActiveTimestamp = millis(); // Refresh if playlist is active so uC will not fall asleep due to reaching inactivity-time } esp_task_wdt_reset(); // Don't forget to feed the dog! @@ -1315,14 +1311,14 @@ void rfidScanner(void *parameter) { mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader detail delay(4); loggerNl((char *) FPSTR(rfidScannerReady), LOGLEVEL_DEBUG); - byte cardId[generalConfig.cardIdSize]; + byte cardId[cardIdSize]; char *cardIdString; for (;;) { esp_task_wdt_reset(); vTaskDelay(10); - if ((millis() - helper.lastRfidCheckTimestamp) >= 300) { - helper.lastRfidCheckTimestamp = millis(); + if ((millis() - lastRfidCheckTimestamp) >= 300) { + lastRfidCheckTimestamp = millis(); // Reset the loop if no new card is present on the sensor/reader. This saves the entire process when idle. if (!mfrc522.PICC_IsNewCardPresent()) { @@ -1338,23 +1334,23 @@ void rfidScanner(void *parameter) { mfrc522.PICC_HaltA(); mfrc522.PCD_StopCrypto1(); - cardIdString = (char *) malloc(generalConfig.cardIdSize*3 +1); + cardIdString = (char *) malloc(cardIdSize*3 +1); if (cardIdString == NULL) { logger((char *) FPSTR(unableToAllocateMem), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; continue; } uint8_t n = 0; logger((char *) FPSTR(rfidTagDetected), LOGLEVEL_NOTICE); - for (uint8_t i=0; i(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); - FastLED.setBrightness(generalConfig.ledBrightness); + FastLED.setBrightness(ledBrightness); for (;;) { - if (!helper.bootComplete) { + if (!bootComplete) { FastLED.clear(); FastLED.show(); vTaskDelay(portTICK_RATE_MS*10); esp_task_wdt_reset(); continue; } - if (lastLedBrightness != generalConfig.ledBrightness) { - FastLED.setBrightness(generalConfig.ledBrightness); - lastLedBrightness = generalConfig.ledBrightness; + if (lastLedBrightness != ledBrightness) { + FastLED.setBrightness(ledBrightness); + lastLedBrightness = ledBrightness; } if (!buttons[3].currentState) { @@ -1413,12 +1409,12 @@ void showLed(void *parameter) { break; } FastLED.show(); - vTaskDelay(generalConfig.intervalToLongPress / NUM_LEDS * portTICK_RATE_MS); + vTaskDelay(intervalToLongPress / NUM_LEDS * portTICK_RATE_MS); } } - if (helper.showLedError) { // If error occured (e.g. RFID-modification not accepted) - helper.showLedError = false; + if (showLedError) { // If error occured (e.g. RFID-modification not accepted) + showLedError = false; notificationShown = true; FastLED.clear(); @@ -1429,8 +1425,8 @@ void showLed(void *parameter) { vTaskDelay(portTICK_RATE_MS * 200); } - if (helper.showLedOk) { // If action was accepted - helper.showLedOk = false; + if (showLedOk) { // If action was accepted + showLedOk = false; notificationShown = true; FastLED.clear(); @@ -1441,9 +1437,9 @@ void showLed(void *parameter) { vTaskDelay(portTICK_RATE_MS * 400); } - if (hlastVolume != helper.currentVolume) { // If volume has been changed - uint8_t numLedsToLight = map(helper.currentVolume, 0, generalConfig.maxVolume, 0, NUM_LEDS); - hlastVolume = helper.currentVolume; + if (hlastVolume != currentVolume) { // If volume has been changed + uint8_t numLedsToLight = map(currentVolume, 0, maxVolume, 0, NUM_LEDS); + hlastVolume = currentVolume; volumeChangeShown = true; FastLED.clear(); @@ -1453,8 +1449,8 @@ void showLed(void *parameter) { FastLED.show(); for (uint8_t i=0; i<=50; i++) { - if (hlastVolume != helper.currentVolume || helper.showLedError || helper.showLedOk || !buttons[3].currentState) { - if (hlastVolume != helper.currentVolume) { + if (hlastVolume != currentVolume || showLedError || showLedOk || !buttons[3].currentState) { + if (hlastVolume != currentVolume) { volumeChangeShown = false; } break; @@ -1464,12 +1460,12 @@ void showLed(void *parameter) { } } - if (helper.showRewind) { - helper.showRewind = false; + if (showRewind) { + showRewind = false; for (uint8_t i=NUM_LEDS-1; i>0; i--) { leds[i] = CRGB::Black; FastLED.show(); - if (hlastVolume != helper.currentVolume || lastLedBrightness != generalConfig.ledBrightness || helper.showLedError || helper.showLedOk || !buttons[3].currentState) { + if (hlastVolume != currentVolume || lastLedBrightness != ledBrightness || showLedError || showLedOk || !buttons[3].currentState) { break; } else { vTaskDelay(portTICK_RATE_MS*30); @@ -1477,15 +1473,15 @@ void showLed(void *parameter) { } } - if (helper.showPlaylistProgress) { - helper.showPlaylistProgress = false; + if (showPlaylistProgress) { + showPlaylistProgress = false; if (playProperties.numberOfTracks > 1 && playProperties.currentTrackNumber < playProperties.numberOfTracks) { uint8_t numLedsToLight = map(playProperties.currentTrackNumber, 0, playProperties.numberOfTracks-1, 0, NUM_LEDS); FastLED.clear(); for (uint8_t i=0; i < numLedsToLight; i++) { leds[i] = CRGB::Blue; FastLED.show(); - if (hlastVolume != helper.currentVolume || lastLedBrightness != generalConfig.ledBrightness || helper.showLedError || helper.showLedOk || !buttons[3].currentState) { + if (hlastVolume != currentVolume || lastLedBrightness != ledBrightness || showLedError || showLedOk || !buttons[3].currentState) { break; } else { vTaskDelay(portTICK_RATE_MS*30); @@ -1493,7 +1489,7 @@ void showLed(void *parameter) { } for (uint8_t i=0; i<=100; i++) { - if (hlastVolume != helper.currentVolume || lastLedBrightness != generalConfig.ledBrightness || helper.showLedError || helper.showLedOk || !buttons[3].currentState) { + if (hlastVolume != currentVolume || lastLedBrightness != ledBrightness || showLedError || showLedOk || !buttons[3].currentState) { break; } else { vTaskDelay(portTICK_RATE_MS*15); @@ -1503,7 +1499,7 @@ void showLed(void *parameter) { for (uint8_t i=numLedsToLight; i>0; i--) { leds[i-1] = CRGB::Black; FastLED.show(); - if (hlastVolume != helper.currentVolume || lastLedBrightness != generalConfig.ledBrightness || helper.showLedError || helper.showLedOk || !buttons[3].currentState) { + if (hlastVolume != currentVolume || lastLedBrightness != ledBrightness || showLedError || showLedOk || !buttons[3].currentState) { break; } else { vTaskDelay(portTICK_RATE_MS*30); @@ -1514,7 +1510,7 @@ void showLed(void *parameter) { switch (playProperties.playMode) { case NO_PLAYLIST: // If no playlist is active (idle) - if (hlastVolume == helper.currentVolume && lastLedBrightness == generalConfig.ledBrightness) { + if (hlastVolume == currentVolume && lastLedBrightness == ledBrightness) { for (uint8_t i=0; i < NUM_LEDS; i++) { FastLED.clear(); if (i == 0) { @@ -1530,7 +1526,7 @@ void showLed(void *parameter) { } FastLED.show(); for (uint8_t i=0; i<=50; i++) { - if (hlastVolume != helper.currentVolume || lastLedBrightness != generalConfig.ledBrightness || helper.showLedError || helper.showLedOk || playProperties.playMode != NO_PLAYLIST || !buttons[3].currentState) { + if (hlastVolume != currentVolume || lastLedBrightness != ledBrightness || showLedError || showLedOk || playProperties.playMode != NO_PLAYLIST || !buttons[3].currentState) { break; } else { vTaskDelay(portTICK_RATE_MS * 10); @@ -1565,9 +1561,9 @@ void showLed(void *parameter) { default: // If playlist is active (doesn't matter which type) if (!playProperties.playlistFinished) { - if (playProperties.pausePlay != lastPlayState || helper.lockControls != lastLockState || notificationShown || ledBusyShown || volumeChangeShown || !buttons[3].currentState) { + if (playProperties.pausePlay != lastPlayState || lockControls != lastLockState || notificationShown || ledBusyShown || volumeChangeShown || !buttons[3].currentState) { lastPlayState = playProperties.pausePlay; - lastLockState = helper.lockControls; + lastLockState = lockControls; notificationShown = false; volumeChangeShown = false; if (ledBusyShown) { @@ -1585,7 +1581,7 @@ void showLed(void *parameter) { uint8_t numLedsToLight = map(playProperties.currentRelPos, 0, 98, 0, NUM_LEDS); FastLED.clear(); for(uint8_t led = 0; led < numLedsToLight; led++) { - if (helper.lockControls) { + if (lockControls) { leds[led] = CRGB::Red; } else if (!playProperties.pausePlay) { // Hue-rainbow leds[led].setHue((uint8_t) (((double) 255 / NUM_LEDS) * led)); @@ -1604,7 +1600,7 @@ void showLed(void *parameter) { } else { ledPosWebstream = 0; } - if (helper.lockControls) { + if (lockControls) { leds[ledPosWebstream] = CRGB::Red; leds[(ledPosWebstream+NUM_LEDS/2) % NUM_LEDS] = CRGB::Red; } else if (!playProperties.pausePlay) { @@ -1628,13 +1624,13 @@ void showLed(void *parameter) { // Sets deep-sleep-flag if necessary void sleepHandler(void) { unsigned long m = millis(); - if (m >= helper.lastTimeActiveTimestamp && (m - helper.lastTimeActiveTimestamp >= generalConfig.maxInactivityTime * 1000 * 60)) { + if (m >= lastTimeActiveTimestamp && (m - lastTimeActiveTimestamp >= maxInactivityTime * 1000 * 60)) { loggerNl((char *) FPSTR(goToSleepDueToIdle), LOGLEVEL_INFO); - helper.gotoSleep = true; - } else if (helper.sleepTimerStartTimestamp > 0) { - if (m - helper.sleepTimerStartTimestamp >= generalConfig.sleepTimer * 1000 * 60) { + gotoSleep = true; + } else if (sleepTimerStartTimestamp > 0) { + if (m - sleepTimerStartTimestamp >= sleepTimer * 1000 * 60) { loggerNl((char *) FPSTR(goToSleepDueToTimer), LOGLEVEL_INFO); - helper.gotoSleep = true; + gotoSleep = true; } } } @@ -1642,7 +1638,7 @@ void sleepHandler(void) { // Puts uC to deep-sleep if flag is set void deepSleepManager(void) { - if (helper.gotoSleep) { + if (gotoSleep) { loggerNl((char *) FPSTR(goToSleepNow), LOGLEVEL_NOTICE); Serial.flush(); publishMqtt((char *) FPSTR(topicState), "Offline", false); @@ -1662,10 +1658,10 @@ void deepSleepManager(void) { // Puts new volume to volume-queue void volumeToQueueSender(const int32_t _newVolume) { uint32_t _volume; - if (_newVolume <= generalConfig.minVolume) { - _volume = generalConfig.minVolume; - } else if (_newVolume > generalConfig.maxVolume) { - _volume = generalConfig.maxVolume; + if (_newVolume <= minVolume) { + _volume = minVolume; + } else if (_newVolume > maxVolume) { + _volume = maxVolume; } else { _volume = _newVolume; } @@ -1681,32 +1677,32 @@ void trackControlToQueueSender(const uint8_t trackCommand) { // Handles volume directed by rotary encoder void volumeHandler(const int32_t _minVolume, const int32_t _maxVolume) { - if (helper.lockControls) { + if (lockControls) { encoder.clearCount(); - encoder.setCount(helper.currentVolume*2); + encoder.setCount(currentVolume*2); return; } - helper.currentEncoderValue = encoder.getCount(); + currentEncoderValue = encoder.getCount(); // Only if initial run or value has changed. And only after "full step" of rotary encoder - if (((helper.lastEncoderValue != helper.currentEncoderValue) || helper.lastVolume == -1) && (helper.currentEncoderValue % 2 == 0)) { - helper.lastTimeActiveTimestamp = millis(); // Set inactive back if rotary encoder was used - if (_maxVolume * 2 < helper.currentEncoderValue) { + if (((lastEncoderValue != currentEncoderValue) || lastVolume == -1) && (currentEncoderValue % 2 == 0)) { + lastTimeActiveTimestamp = millis(); // Set inactive back if rotary encoder was used + if (_maxVolume * 2 < currentEncoderValue) { encoder.clearCount(); encoder.setCount(_maxVolume * 2); loggerNl((char *) FPSTR(maxLoudnessReached), LOGLEVEL_INFO); - helper.currentEncoderValue = encoder.getCount(); - } else if (helper.currentEncoderValue < _minVolume) { + currentEncoderValue = encoder.getCount(); + } else if (currentEncoderValue < _minVolume) { encoder.clearCount(); encoder.setCount(_minVolume); loggerNl((char *) FPSTR(minLoudnessReached), LOGLEVEL_INFO); - helper.currentEncoderValue = encoder.getCount(); + currentEncoderValue = encoder.getCount(); } - helper.lastEncoderValue = helper.currentEncoderValue; - helper.currentVolume = helper.lastEncoderValue / 2; - if (helper.currentVolume != helper.lastVolume) { - helper.lastVolume = helper.currentVolume; - volumeToQueueSender(helper.currentVolume); + lastEncoderValue = currentEncoderValue; + currentVolume = lastEncoderValue / 2; + if (currentVolume != lastVolume) { + lastVolume = currentVolume; + volumeToQueueSender(currentVolume); } } } @@ -1730,16 +1726,16 @@ void trackQueueDispatcher(const char *_itemToPlay, const uint32_t _lastPlayPos, } else { musicFiles = returnPlaylistFromWebstream(filename); } - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); if (musicFiles == NULL) { loggerNl((char *) FPSTR(errorOccured), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; playProperties.playMode = NO_PLAYLIST; return; } else if (!strcmp(*(musicFiles-1), "0")) { loggerNl((char *) FPSTR(noMp3FilesInDir), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; playProperties.playMode = NO_PLAYLIST; free (filename); return; @@ -1846,7 +1842,7 @@ void trackQueueDispatcher(const char *_itemToPlay, const uint32_t _lastPlayPos, default: loggerNl((char *) FPSTR(modeDoesNotExist), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; } free (filename); } @@ -1857,142 +1853,142 @@ void trackQueueDispatcher(const char *_itemToPlay, const uint32_t _lastPlayPos, void doRfidCardModifications(const uint32_t mod) { switch (mod) { case LOCK_BUTTONS_MOD: // Locks/unlocks all buttons - helper.lockControls = !helper.lockControls; - if (helper.lockControls) { + lockControls = !lockControls; + if (lockControls) { loggerNl((char *) FPSTR(modificatorAllButtonsLocked), LOGLEVEL_NOTICE); publishMqtt((char *) FPSTR(topicLockControlsState), "ON", false); - helper.showLedOk = true; + showLedOk = true; } else { loggerNl((char *) FPSTR(modificatorAllButtonsUnlocked), LOGLEVEL_NOTICE); publishMqtt((char *) FPSTR(topicLockControlsState), "OFF", false); - helper.showLedOk = true; + showLedOk = true; } break; case SLEEP_TIMER_MOD_15: // Puts/undo uC to sleep after 15 minutes - if (generalConfig.sleepTimer == 15) { - helper.sleepTimerStartTimestamp = 0; - generalConfig.ledBrightness = generalConfig.initialLedBrightness; + if (sleepTimer == 15) { + sleepTimerStartTimestamp = 0; + ledBrightness = initialLedBrightness; loggerNl((char *) FPSTR(modificatorSleepd), LOGLEVEL_NOTICE); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); } else { - generalConfig.sleepTimer = 15; - helper.sleepTimerStartTimestamp = millis(); - generalConfig.ledBrightness = generalConfig.nightLedBrightness; + sleepTimer = 15; + sleepTimerStartTimestamp = millis(); + ledBrightness = nightLedBrightness; loggerNl((char *) FPSTR(modificatorSleepTimer15), LOGLEVEL_NOTICE); loggerNl((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO); - publishMqtt((char *) FPSTR(topicSleepTimerState), generalConfig.sleepTimer, false); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.nightLedBrightness, false); + publishMqtt((char *) FPSTR(topicSleepTimerState), sleepTimer, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), nightLedBrightness, false); } playProperties.sleepAfterCurrentTrack = false; // deactivate/overwrite if already active playProperties.sleepAfterPlaylist = false; // deactivate/overwrite if already active - helper.showLedOk = true; + showLedOk = true; break; case SLEEP_TIMER_MOD_30: // Puts/undo uC to sleep after 30 minutes - if (generalConfig.sleepTimer == 30) { - helper.sleepTimerStartTimestamp = 0; - generalConfig.ledBrightness = generalConfig.initialLedBrightness; + if (sleepTimer == 30) { + sleepTimerStartTimestamp = 0; + ledBrightness = initialLedBrightness; loggerNl((char *) FPSTR(modificatorSleepd), LOGLEVEL_NOTICE); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); } else { - generalConfig.sleepTimer = 30; - helper.sleepTimerStartTimestamp = millis(); - generalConfig.ledBrightness = generalConfig.nightLedBrightness; + sleepTimer = 30; + sleepTimerStartTimestamp = millis(); + ledBrightness = nightLedBrightness; loggerNl((char *) FPSTR(modificatorSleepTimer30), LOGLEVEL_NOTICE); loggerNl((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO); - publishMqtt((char *) FPSTR(topicSleepTimerState), generalConfig.sleepTimer, false); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.nightLedBrightness, false); + publishMqtt((char *) FPSTR(topicSleepTimerState), sleepTimer, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), nightLedBrightness, false); } playProperties.sleepAfterCurrentTrack = false; // deactivate/overwrite if already active playProperties.sleepAfterPlaylist = false; // deactivate/overwrite if already active - helper.showLedOk = true; + showLedOk = true; break; case SLEEP_TIMER_MOD_60: // Puts/undo uC to sleep after 60 minutes - if (generalConfig.sleepTimer == 60) { - helper.sleepTimerStartTimestamp = 0; - generalConfig.ledBrightness = generalConfig.initialLedBrightness; + if (sleepTimer == 60) { + sleepTimerStartTimestamp = 0; + ledBrightness = initialLedBrightness; loggerNl((char *) FPSTR(modificatorSleepd), LOGLEVEL_NOTICE); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); } else { - generalConfig.sleepTimer = 60; - helper.sleepTimerStartTimestamp = millis(); - generalConfig.ledBrightness = generalConfig.nightLedBrightness; + sleepTimer = 60; + sleepTimerStartTimestamp = millis(); + ledBrightness = nightLedBrightness; loggerNl((char *) FPSTR(modificatorSleepTimer60), LOGLEVEL_NOTICE); loggerNl((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO); - publishMqtt((char *) FPSTR(topicSleepTimerState), generalConfig.sleepTimer, false); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.nightLedBrightness, false); + publishMqtt((char *) FPSTR(topicSleepTimerState), sleepTimer, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), nightLedBrightness, false); } playProperties.sleepAfterCurrentTrack = false; // deactivate/overwrite if already active playProperties.sleepAfterPlaylist = false; // deactivate/overwrite if already active - helper.showLedOk = true; + showLedOk = true; break; case SLEEP_TIMER_MOD_120: // Puts/undo uC to sleep after 2 hrs - if (generalConfig.sleepTimer == 120) { - helper.sleepTimerStartTimestamp = 0; - generalConfig.ledBrightness = generalConfig.initialLedBrightness; + if (sleepTimer == 120) { + sleepTimerStartTimestamp = 0; + ledBrightness = initialLedBrightness; loggerNl((char *) FPSTR(modificatorSleepd), LOGLEVEL_NOTICE); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); } else { - generalConfig.sleepTimer = 120; - helper.sleepTimerStartTimestamp = millis(); - generalConfig.ledBrightness = generalConfig.nightLedBrightness; + sleepTimer = 120; + sleepTimerStartTimestamp = millis(); + ledBrightness = nightLedBrightness; loggerNl((char *) FPSTR(modificatorSleepTimer120), LOGLEVEL_NOTICE); loggerNl((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO); - publishMqtt((char *) FPSTR(topicSleepTimerState), generalConfig.sleepTimer, false); - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.nightLedBrightness, false); + publishMqtt((char *) FPSTR(topicSleepTimerState), sleepTimer, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), nightLedBrightness, false); } playProperties.sleepAfterCurrentTrack = false; // deactivate/overwrite if already active playProperties.sleepAfterPlaylist = false; // deactivate/overwrite if already active - helper.showLedOk = true; + showLedOk = true; break; case SLEEP_AFTER_END_OF_TRACK: // Puts uC to sleep after end of current track if (playProperties.playMode == NO_PLAYLIST) { loggerNl((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; return; } if (playProperties.sleepAfterCurrentTrack) { loggerNl((char *) FPSTR(modificatorSleepAtEOTd), LOGLEVEL_NOTICE); publishMqtt((char *) FPSTR(topicSleepTimerState), "0", false); - generalConfig.ledBrightness = generalConfig.initialLedBrightness; + ledBrightness = initialLedBrightness; } else { loggerNl((char *) FPSTR(modificatorSleepAtEOT), LOGLEVEL_NOTICE); publishMqtt((char *) FPSTR(topicSleepTimerState), "EOT", false); - generalConfig.ledBrightness = generalConfig.nightLedBrightness; + ledBrightness = nightLedBrightness; loggerNl((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO); } playProperties.sleepAfterCurrentTrack = !playProperties.sleepAfterCurrentTrack; playProperties.sleepAfterPlaylist = false; - helper.sleepTimerStartTimestamp = 0; + sleepTimerStartTimestamp = 0; - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); - helper.showLedOk = true; + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); + showLedOk = true; break; case SLEEP_AFTER_END_OF_PLAYLIST: // Puts uC to sleep after end of whole playlist (can take a while :->) if (playProperties.playMode == NO_PLAYLIST) { loggerNl((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; return; } if (playProperties.sleepAfterCurrentTrack) { publishMqtt((char *) FPSTR(topicSleepTimerState), "0", false); - generalConfig.ledBrightness = generalConfig.initialLedBrightness; + ledBrightness = initialLedBrightness; loggerNl((char *) FPSTR(modificatorSleepAtEOPd), LOGLEVEL_NOTICE); } else { - generalConfig.ledBrightness = generalConfig.nightLedBrightness; + ledBrightness = nightLedBrightness; loggerNl((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO); loggerNl((char *) FPSTR(modificatorSleepAtEOP), LOGLEVEL_NOTICE); publishMqtt((char *) FPSTR(topicSleepTimerState), "EOP", false); @@ -2000,15 +1996,15 @@ void doRfidCardModifications(const uint32_t mod) { playProperties.sleepAfterCurrentTrack = false; playProperties.sleepAfterPlaylist = !playProperties.sleepAfterPlaylist; - helper.sleepTimerStartTimestamp = 0; - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); - helper.showLedOk = true; + sleepTimerStartTimestamp = 0; + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); + showLedOk = true; break; case REPEAT_PLAYLIST: if (playProperties.playMode == NO_PLAYLIST) { loggerNl((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; } else { if (playProperties.repeatPlaylist) { loggerNl((char *) FPSTR(modificatorPlaylistLoopDeactive), LOGLEVEL_NOTICE); @@ -2019,14 +2015,14 @@ void doRfidCardModifications(const uint32_t mod) { char rBuf[2]; snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); - helper.showLedOk = true; + showLedOk = true; } break; case REPEAT_TRACK: // Introduces looping for track-mode if (playProperties.playMode == NO_PLAYLIST) { loggerNl((char *) FPSTR(modificatorNotallowedWhenIdle), LOGLEVEL_NOTICE); - helper.showLedError = true; + showLedError = true; } else { if (playProperties.repeatCurrentTrack) { loggerNl((char *) FPSTR(modificatorTrackDeactive), LOGLEVEL_NOTICE); @@ -2037,21 +2033,21 @@ void doRfidCardModifications(const uint32_t mod) { char rBuf[2]; snprintf(rBuf, 2, "%u", getRepeatMode()); publishMqtt((char *) FPSTR(topicRepeatModeState), rBuf, false); - helper.showLedOk = true; + showLedOk = true; } break; case DIMM_LEDS_NIGHTMODE: - publishMqtt((char *) FPSTR(topicLedBrightnessState), generalConfig.ledBrightness, false); + publishMqtt((char *) FPSTR(topicLedBrightnessState), ledBrightness, false); loggerNl((char *) FPSTR(ledsDimmedToNightmode), LOGLEVEL_INFO); - generalConfig.ledBrightness = generalConfig.nightLedBrightness; - helper.showLedOk = true; + ledBrightness = nightLedBrightness; + showLedOk = true; break; default: snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s %d !", (char *) FPSTR(modificatorDoesNotExist), mod); loggerNl(logBuf, LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; } } @@ -2067,15 +2063,15 @@ void rfidPreferenceLookupHandler (void) { rfidStatus = xQueueReceive(rfidCardQueue, &rfidTagId, 0); if (rfidStatus == pdPASS) { - helper.lastTimeActiveTimestamp = millis(); + lastTimeActiveTimestamp = millis(); snprintf(logBuf, sizeof(logBuf)/sizeof(logBuf[0]), "%s: %s", (char *) FPSTR(rfidTagReceived), rfidTagId); - helper.currentRfidTagId = strdup(rfidTagId); + currentRfidTagId = strdup(rfidTagId); loggerNl(logBuf, LOGLEVEL_INFO); String s = prefsRfid.getString(rfidTagId, "-1"); // Try to lookup rfidId in NVS if (!s.compareTo("-1")) { loggerNl((char *) FPSTR(rfidTagUnknownInNvs), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; return; } @@ -2098,7 +2094,7 @@ void rfidPreferenceLookupHandler (void) { if (i != 5) { loggerNl((char *) FPSTR(errorOccuredNvs), LOGLEVEL_ERROR); - helper.showLedError = true; + showLedError = true; } else { // Only pass file to queue if strtok revealed 3 items if (_playMode >= 100) { @@ -2179,7 +2175,7 @@ void accessPointStart(const char *SSID, IPAddress ip, IPAddress netmask) { wl_status_t wifiManager(void) { - if (helper.wifiCheckLastTimestamp == 0) { + if (wifiCheckLastTimestamp == 0) { // Get credentials from NVS String strSSID = prefsSettings.getString("SSID", "-1"); if (!strSSID.compareTo("-1")) { @@ -2200,7 +2196,7 @@ wl_status_t wifiManager(void) { delay(500); Serial.print(F(".")); tryCount++; - helper.wifiCheckLastTimestamp = millis(); + wifiCheckLastTimestamp = millis(); if (tryCount >= 4 && WiFi.status() == WL_CONNECT_FAILED) { WiFi.begin(_ssid, _pwd); // ESP32-workaround } @@ -2221,16 +2217,6 @@ wl_status_t wifiManager(void) { void setup() { - // Helpers - don't change! - helper.bootComplete = 0; - helper.showLedOk = 0; - helper.showLedError = 0; - helper.showPlaylistProgress = 0; - helper.showRewind = 0; - helper.gotoSleep = 0; - helper.lockControls = 0; - helper.bootComplete = 0; - Serial.begin(115200); srand(esp_random()); pinMode(POWER, OUTPUT); @@ -2296,7 +2282,7 @@ void setup() { loggerNl((char *) FPSTR(unableToCreateVolQ), LOGLEVEL_ERROR); } - rfidCardQueue = xQueueCreate(1, (generalConfig.cardIdSize + 1) * sizeof(char)); + rfidCardQueue = xQueueCreate(1, (cardIdSize + 1) * sizeof(char)); if (rfidCardQueue == NULL) { loggerNl((char *) FPSTR(unableToCreateRfidQ), LOGLEVEL_ERROR); } @@ -2316,22 +2302,22 @@ void setup() { // Get initial LED-brightness from NVS uint8_t nvsILedBrightness = prefsSettings.getUChar("iLedBrightness", 0); if (nvsILedBrightness) { - generalConfig.initialLedBrightness = nvsILedBrightness; + initialLedBrightness = nvsILedBrightness; snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %d", (char *) FPSTR(initialBrightnessfromNvs), nvsILedBrightness); loggerNl(logBuf, LOGLEVEL_INFO); } else { - prefsSettings.putUChar("iLedBrightness", generalConfig.initialLedBrightness); + prefsSettings.putUChar("iLedBrightness", initialLedBrightness); loggerNl((char *) FPSTR(wroteInitialBrightnessToNvs), LOGLEVEL_ERROR); } // Get night LED-brightness from NVS uint8_t nvsNLedBrightness = prefsSettings.getUChar("nLedBrightness", 0); if (nvsNLedBrightness) { - generalConfig.nightLedBrightness = nvsNLedBrightness; + nightLedBrightness = nvsNLedBrightness; snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %d", (char *) FPSTR(loadedInitialBrightnessForNmFromNvs), nvsNLedBrightness); loggerNl(logBuf, LOGLEVEL_INFO); } else { - prefsSettings.putUChar("nLedBrightness", generalConfig.nightLedBrightness); + prefsSettings.putUChar("nLedBrightness", nightLedBrightness); loggerNl((char *) FPSTR(wroteNmBrightnessToNvs), LOGLEVEL_ERROR); } @@ -2360,33 +2346,33 @@ void setup() { // Get maximum inactivity-time from NVS uint32_t nvsMInactivityTime = prefsSettings.getUInt("mInactiviyT", 0); if (nvsMInactivityTime) { - generalConfig.maxInactivityTime = nvsMInactivityTime; + maxInactivityTime = nvsMInactivityTime; snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMaxInactivityFromNvs), nvsMInactivityTime); loggerNl(logBuf, LOGLEVEL_INFO); } else { - prefsSettings.putUInt("mInactiviyT", generalConfig.maxInactivityTime); + prefsSettings.putUInt("mInactiviyT", maxInactivityTime); loggerNl((char *) FPSTR(wroteMaxInactivityToNvs), LOGLEVEL_ERROR); } // Get initial volume from NVS uint32_t nvsInitialVolume = prefsSettings.getUInt("initVolume", 0); if (nvsInitialVolume) { - generalConfig.initVolume = nvsInitialVolume; + initVolume = nvsInitialVolume; snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedInitialLoudnessFromNvs), nvsInitialVolume); loggerNl(logBuf, LOGLEVEL_INFO); } else { - prefsSettings.putUInt("initVolume", generalConfig.initVolume); + prefsSettings.putUInt("initVolume", initVolume); loggerNl((char *) FPSTR(wroteInitialLoudnessToNvs), LOGLEVEL_ERROR); } // Get maximum volume from NVS uint32_t nvsMaxVolume = prefsSettings.getUInt("maxVolume", 0); if (nvsMaxVolume) { - generalConfig.maxVolume = nvsMaxVolume; + maxVolume = nvsMaxVolume; snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMaxLoudnessFromNvs), nvsMaxVolume); loggerNl(logBuf, LOGLEVEL_INFO); } else { - prefsSettings.putUInt("maxVolume", generalConfig.maxVolume); + prefsSettings.putUInt("maxVolume", maxVolume); loggerNl((char *) FPSTR(wroteMaxLoudnessToNvs), LOGLEVEL_ERROR); } @@ -2398,12 +2384,12 @@ void setup() { loggerNl((char *) FPSTR(wroteMqttFlagToNvs), LOGLEVEL_ERROR); break; case 1: - prefsSettings.putUChar("enableMQTT", generalConfig.enableMqtt); + prefsSettings.putUChar("enableMQTT", enableMqtt); snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMqttActiveFromNvs), nvsEnableMqtt); loggerNl(logBuf, LOGLEVEL_INFO); break; case 0: - generalConfig.enableMqtt = nvsEnableMqtt; + enableMqtt = nvsEnableMqtt; snprintf(logBuf, sizeof(logBuf) / sizeof(logBuf[0]), "%s: %u", (char *) FPSTR(loadedMqttDeactiveFromNvs), nvsEnableMqtt); loggerNl(logBuf, LOGLEVEL_INFO); break; @@ -2469,18 +2455,18 @@ void setup() { // Init rotary encoder encoder.attachHalfQuad(DREHENCODER_CLK, DREHENCODER_DT); encoder.clearCount(); - encoder.setCount(generalConfig.initVolume*2); // Ganzes Raster ist immer +2, daher initiale Lautstärke mit 2 multiplizieren + encoder.setCount(initVolume*2); // Ganzes Raster ist immer +2, daher initiale Lautstärke mit 2 multiplizieren // Only enable MQTT if requested - if (generalConfig.enableMqtt) { + if (enableMqtt) { MQTTclient.setServer(mqtt_server, 1883); MQTTclient.setCallback(callback); } wifiManager(); - helper.lastTimeActiveTimestamp = millis(); // initial set after boot + lastTimeActiveTimestamp = millis(); // initial set after boot wServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(200, "text/plain", "Hello, world"); @@ -2494,7 +2480,7 @@ void setup() { } else { message = "No message sent"; } - request->send(200, "text/plain", "Hello, GET: " + String(playProperties.playMode) + String(helper.currentRfidTagId)); + request->send(200, "text/plain", "Hello, GET: " + String(playProperties.playMode) + String(currentRfidTagId)); }); // Send a POST request to /post with a form field message set to @@ -2511,7 +2497,7 @@ void setup() { wServer.onNotFound(notFound); wServer.begin(); - helper.bootComplete = true; + bootComplete = true; /*char *sdC = (char *) calloc(16384, sizeof(char)); printSdContent(SD.open("/", FILE_READ), 16384, 1, sdC, 2); @@ -2525,14 +2511,14 @@ void setup() { void loop() { - volumeHandler(generalConfig.minVolume, generalConfig.maxVolume); + volumeHandler(minVolume, maxVolume); buttonHandler(); doButtonActions(); sleepHandler(); deepSleepManager(); rfidPreferenceLookupHandler(); if (wifiManager() == WL_CONNECTED) { - if (generalConfig.enableMqtt) { + if (enableMqtt) { reconnect(); MQTTclient.loop(); postHeartbeatViaMqtt(); @@ -2540,7 +2526,7 @@ void loop() { ftpSrv.handleFTP(); } if (ftpSrv.isConnected()) { - helper.lastTimeActiveTimestamp = millis(); // Re-adjust timer while client is connected to avoid ESP falling asleep + lastTimeActiveTimestamp = millis(); // Re-adjust timer while client is connected to avoid ESP falling asleep } server.handleClient(); }