Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions firmware-arduino/src/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ void audioStreamTask(void *parameter) {
}
}


class WebsocketStream : public Print {
public:
// micTask -> micToWsCopier.copyBytes() -> wsStream.write()
Expand Down Expand Up @@ -398,4 +397,4 @@ void networkTask(void *parameter) {

vTaskDelay(1);
}
}
}
2 changes: 1 addition & 1 deletion firmware-arduino/src/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ void audioStreamTask(void *parameter);
// AUDIO INPUT
void micTask(void *parameter);

#endif
#endif
2 changes: 1 addition & 1 deletion firmware-arduino/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ VQD9F6Na/+zmXCc=
-----END CERTIFICATE-----
)EOF";

#endif
#endif
10 changes: 4 additions & 6 deletions firmware-arduino/src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
extern Preferences preferences;
extern bool factory_reset_status;

enum OtaStatus {
enum OtaStatus : uint8_t
{
OTA_IDLE,
OTA_IN_PROGRESS,
OTA_COMPLETE
};

extern OtaStatus otaState;

enum DeviceState
enum DeviceState : uint8_t
{
SETUP,
SOFT_AP,
Expand All @@ -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
Expand Down Expand Up @@ -99,4 +97,4 @@ extern const char *Vercel_CA_cert;
void factoryResetDevice();
void processSleepRequest();

#endif
#endif
9 changes: 5 additions & 4 deletions firmware-arduino/src/FactoryReset.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <ESPAsyncWebServer.h> //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
Expand Down Expand Up @@ -45,7 +46,6 @@ void setResetComplete() {

// Clear NVS
factoryResetDevice();

}

// TODO(@akdeb): Update this to use `false` as default
Expand All @@ -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
Expand All @@ -82,4 +83,4 @@ void factoryResetDevice() {
}
}

#endif
#endif
2 changes: 1 addition & 1 deletion firmware-arduino/src/LEDHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
}
}
}
4 changes: 1 addition & 3 deletions firmware-arduino/src/LEDHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
12 changes: 4 additions & 8 deletions firmware-arduino/src/OTA.cpp
Original file line number Diff line number Diff line change
@@ -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 = "<YOUR S3 OTA FIRMWARE URL HERE> - TOUCH MODE";
static const char *ota_firmware_url = "<YOUR S3 OTA FIRMWARE URL HERE> - TOUCH MODE";
#else
const char *ota_firmware_url = "<YOUR S3 OTA FIRMWARE URL HERE> - BUTTON MODE";
static const char *ota_firmware_url = "<YOUR S3 OTA FIRMWARE URL HERE> - BUTTON MODE";
#endif

const char *server_certificate = R"EOF(
static const char *server_certificate = R"EOF(
-----BEGIN CERTIFICATE-----

<YOUR S3 HOST CERTIFICATE HERE>
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -123,4 +120,3 @@ void performOTAUpdate()
HttpsOTA.onHttpEvent(HttpEvent);
HttpsOTA.begin(ota_firmware_url, server_certificate);
}

4 changes: 1 addition & 3 deletions firmware-arduino/src/OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
12 changes: 6 additions & 6 deletions firmware-arduino/src/PitchShift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions firmware-arduino/src/PitchShift.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
#endif
11 changes: 5 additions & 6 deletions firmware-arduino/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -253,4 +252,4 @@ void loop(){
{
loopOTA();
}
}
}