From a70376e28fe1cbc701edd4eaa23cb96fa422e754 Mon Sep 17 00:00:00 2001 From: embedded4ever Date: Tue, 2 Sep 2025 11:06:29 +0100 Subject: [PATCH] Unused functions and variables were removed --- firmware-arduino/src/Audio.cpp | 3 +-- firmware-arduino/src/Audio.h | 2 +- firmware-arduino/src/Config.cpp | 2 +- firmware-arduino/src/Config.h | 10 ++++------ firmware-arduino/src/FactoryReset.h | 9 +++++---- firmware-arduino/src/LEDHandler.cpp | 2 +- firmware-arduino/src/LEDHandler.h | 4 +--- firmware-arduino/src/OTA.cpp | 12 ++++-------- firmware-arduino/src/OTA.h | 4 +--- firmware-arduino/src/PitchShift.cpp | 12 ++++++------ firmware-arduino/src/PitchShift.h | 10 ++++------ firmware-arduino/src/main.cpp | 11 +++++------ 12 files changed, 34 insertions(+), 47 deletions(-) diff --git a/firmware-arduino/src/Audio.cpp b/firmware-arduino/src/Audio.cpp index 22bf5235..c1214cc1 100644 --- a/firmware-arduino/src/Audio.cpp +++ b/firmware-arduino/src/Audio.cpp @@ -172,7 +172,6 @@ void audioStreamTask(void *parameter) { } } - class WebsocketStream : public Print { public: // micTask -> micToWsCopier.copyBytes() -> wsStream.write() @@ -398,4 +397,4 @@ void networkTask(void *parameter) { vTaskDelay(1); } -} \ No newline at end of file +} diff --git a/firmware-arduino/src/Audio.h b/firmware-arduino/src/Audio.h index 1d4c5807..12873b01 100644 --- a/firmware-arduino/src/Audio.h +++ b/firmware-arduino/src/Audio.h @@ -54,4 +54,4 @@ void audioStreamTask(void *parameter); // AUDIO INPUT void micTask(void *parameter); -#endif \ No newline at end of file +#endif diff --git a/firmware-arduino/src/Config.cpp b/firmware-arduino/src/Config.cpp index 63f04f25..3a2c595c 100644 --- a/firmware-arduino/src/Config.cpp +++ b/firmware-arduino/src/Config.cpp @@ -171,4 +171,4 @@ VQD9F6Na/+zmXCc= -----END CERTIFICATE----- )EOF"; -#endif \ No newline at end of file +#endif diff --git a/firmware-arduino/src/Config.h b/firmware-arduino/src/Config.h index 2da90f9e..49f682fe 100644 --- a/firmware-arduino/src/Config.h +++ b/firmware-arduino/src/Config.h @@ -25,7 +25,8 @@ extern Preferences preferences; extern bool factory_reset_status; -enum OtaStatus { +enum OtaStatus : uint8_t +{ OTA_IDLE, OTA_IN_PROGRESS, OTA_COMPLETE @@ -33,7 +34,7 @@ enum OtaStatus { extern OtaStatus otaState; -enum DeviceState +enum DeviceState : uint8_t { SETUP, SOFT_AP, @@ -55,9 +56,6 @@ extern const char *EAP_USERNAME; extern const char *EAP_PASSWORD; extern const char *ssid; -extern const char *ssid_peronal; -extern const char *password_personal; - extern String authTokenGlobal; // WebSocket server details @@ -99,4 +97,4 @@ extern const char *Vercel_CA_cert; void factoryResetDevice(); void processSleepRequest(); -#endif \ No newline at end of file +#endif diff --git a/firmware-arduino/src/FactoryReset.h b/firmware-arduino/src/FactoryReset.h index 5da67a43..ba903fcc 100644 --- a/firmware-arduino/src/FactoryReset.h +++ b/firmware-arduino/src/FactoryReset.h @@ -5,7 +5,8 @@ #include //https://github.com/me-no-dev/ESPAsyncWebServer using the latest dev version from @me-no-dev #include "Config.h" -void setResetComplete() { +void setResetComplete() +{ HTTPClient http; WiFiClientSecure client; client.setCACert(Vercel_CA_cert); // Using the existing server certificate @@ -45,7 +46,6 @@ void setResetComplete() { // Clear NVS factoryResetDevice(); - } // TODO(@akdeb): Update this to use `false` as default @@ -64,7 +64,8 @@ void setFactoryResetStatusInNVS(bool status) factory_reset_status = status; } -void factoryResetDevice() { +void factoryResetDevice() +{ Serial.println("Factory reset device"); // Erase the NVS partition @@ -82,4 +83,4 @@ void factoryResetDevice() { } } -#endif \ No newline at end of file +#endif diff --git a/firmware-arduino/src/LEDHandler.cpp b/firmware-arduino/src/LEDHandler.cpp index c1f5ed61..a0544b17 100644 --- a/firmware-arduino/src/LEDHandler.cpp +++ b/firmware-arduino/src/LEDHandler.cpp @@ -310,4 +310,4 @@ void ledTask(void *parameter) // Delay for smoother LED transitions vTaskDelay(20 / portTICK_PERIOD_MS); // Approximate the delay from the original `pulsateLED()` } -} \ No newline at end of file +} diff --git a/firmware-arduino/src/LEDHandler.h b/firmware-arduino/src/LEDHandler.h index 60701519..67fa638e 100644 --- a/firmware-arduino/src/LEDHandler.h +++ b/firmware-arduino/src/LEDHandler.h @@ -7,8 +7,6 @@ void setLEDColor(uint8_t r, uint8_t g, uint8_t b); void turnOffLED(); void turnOnLED(); void setupRGBLED(); -void turnOnBlueLED(); -void turnOnRedLEDFlash(); void ledTask(void *parameter); -#endif \ No newline at end of file +#endif diff --git a/firmware-arduino/src/OTA.cpp b/firmware-arduino/src/OTA.cpp index db29b8da..d0cb010d 100644 --- a/firmware-arduino/src/OTA.cpp +++ b/firmware-arduino/src/OTA.cpp @@ -1,17 +1,14 @@ #include "OTA.h" #include "HttpsOTAUpdate.h" -#include "esp_ota_ops.h" - -HttpsOTAStatus_t otastatus; // OTA firmware url #ifdef TOUCH_MODE -const char *ota_firmware_url = " - TOUCH MODE"; +static const char *ota_firmware_url = " - TOUCH MODE"; #else -const char *ota_firmware_url = " - BUTTON MODE"; +static const char *ota_firmware_url = " - BUTTON MODE"; #endif -const char *server_certificate = R"EOF( +static const char *server_certificate = R"EOF( -----BEGIN CERTIFICATE----- @@ -75,7 +72,7 @@ void setOTAStatusInNVS(OtaStatus status) void loopOTA() { - otastatus = HttpsOTA.status(); + HttpsOTAStatus_t otastatus = HttpsOTA.status(); if (otastatus == HTTPS_OTA_SUCCESS) { Serial.println("Firmware written successfully. To reboot device, call API ESP.restart() or PUSH restart button on device"); @@ -123,4 +120,3 @@ void performOTAUpdate() HttpsOTA.onHttpEvent(HttpEvent); HttpsOTA.begin(ota_firmware_url, server_certificate); } - diff --git a/firmware-arduino/src/OTA.h b/firmware-arduino/src/OTA.h index 5d48d90f..105ff25b 100644 --- a/firmware-arduino/src/OTA.h +++ b/firmware-arduino/src/OTA.h @@ -3,12 +3,10 @@ #include "Config.h" -extern const char *server_certificate; -extern const char *ota_firmware_url; void performOTAUpdate(); void markOTAUpdateComplete(); void loopOTA(); void setOTAStatusInNVS(OtaStatus status); void getOTAStatusFromNVS(); -#endif \ No newline at end of file +#endif diff --git a/firmware-arduino/src/PitchShift.cpp b/firmware-arduino/src/PitchShift.cpp index a3a886f5..201753ca 100644 --- a/firmware-arduino/src/PitchShift.cpp +++ b/firmware-arduino/src/PitchShift.cpp @@ -8,19 +8,19 @@ static int16_t* buf_ = buf2; static unsigned long readAddress = 0; static unsigned long writeAddress = 0; -bool PitchShiftFixedOutput::begin(PitchShiftInfo info) { +bool PitchShiftFixedOutput::begin(const PitchShiftInfo& info) +{ TRACED(); cfg = info; AudioOutput::setAudioInfo(info); - this->pitchMul = (uint32_t)(info.pitch_shift * 256.0f + 0.5f); - //this->secondaryOffset = (uint32_t)( (1.0f - (info.pitch_shift - (int)(info.pitch_shift))) * GRAINSIZE + 0.5f); - this->secondaryOffset = GRAINSIZE - ((( this->pitchMul * GRAINSIZE ) >> 8 ) % GRAINSIZE); + pitchMul = (uint32_t)(info.pitch_shift * 256.0f + 0.5f); + secondaryOffset = GRAINSIZE - ((( pitchMul * GRAINSIZE ) >> 8 ) % GRAINSIZE); return true; } -int16_t PitchShiftFixedOutput::pitchShift(int16_t value) { - +int16_t PitchShiftFixedOutput::pitchShift(int16_t value) const +{ buf_[writeAddress] = value; int ii1 = (writeAddress * this->pitchMul) >> 8; diff --git a/firmware-arduino/src/PitchShift.h b/firmware-arduino/src/PitchShift.h index 8b52e197..f9877d84 100644 --- a/firmware-arduino/src/PitchShift.h +++ b/firmware-arduino/src/PitchShift.h @@ -14,7 +14,7 @@ class PitchShiftFixedOutput : public AudioOutput { return result; } - bool begin(PitchShiftInfo info); + bool begin(const PitchShiftInfo& info); size_t write(const uint8_t *data, size_t len) override { size_t result = 0; @@ -30,14 +30,12 @@ class PitchShiftFixedOutput : public AudioOutput { return result; } - void end() {} - -protected: +private: Print *p_out = nullptr; - int16_t pitchShift(int16_t value); + int16_t pitchShift(int16_t value) const; uint32_t pitchMul; unsigned long secondaryOffset; }; -#endif \ No newline at end of file +#endif diff --git a/firmware-arduino/src/main.cpp b/firmware-arduino/src/main.cpp index 943536d2..ce260721 100644 --- a/firmware-arduino/src/main.cpp +++ b/firmware-arduino/src/main.cpp @@ -4,13 +4,12 @@ #include "LEDHandler.h" #include "FactoryReset.h" -#define TOUCH_THRESHOLD 28000 +#define TOUCH_THRESHOLD 28000 #define REQUIRED_RELEASE_CHECKS 100 // how many consecutive times we need "below threshold" to confirm release -#define TOUCH_DEBOUNCE_DELAY 500 // milliseconds +#define TOUCH_DEBOUNCE_DELAY 500 // milliseconds AsyncWebServer webServer(80); WIFIMANAGER WifiManager; -esp_err_t getErr = ESP_OK; // Main Thread -> onButtonLongPressUpEventCb -> enterSleep() // Main Thread -> onButtonDoubleClickCb -> enterSleep() @@ -120,7 +119,7 @@ void setupWiFi() request->redirect("/wifi"); }); webServer.onNotFound([](AsyncWebServerRequest *request) { - request->send(404, "text/plain", "Not found"); + request->send(404, "text/plain", "Not found"); }); webServer.begin(); } @@ -193,7 +192,7 @@ void setup() #ifdef TOUCH_MODE xTaskCreate(touchTask, "Touch Task", 4096, NULL, configMAX_PRIORITIES-2, NULL); #else - getErr = esp_sleep_enable_ext0_wakeup(BUTTON_PIN, LOW); + esp_err_t getErr = esp_sleep_enable_ext0_wakeup(BUTTON_PIN, LOW); printOutESP32Error(getErr); Button *btn = new Button(BUTTON_PIN, false); btn->attachLongPressUpEventCb(&onButtonLongPressUpEventCb, NULL); @@ -253,4 +252,4 @@ void loop(){ { loopOTA(); } -} \ No newline at end of file +}