Skip to content

Commit

Permalink
Stop neopixel matrix for OTA
Browse files Browse the repository at this point in the history
  • Loading branch information
oseiler2 committed Jan 31, 2023
1 parent aa62b14 commit 307fba9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/neopixelMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class NeopixelMatrix {

void update(uint16_t mask, TrafficLightStatus oldStatus, TrafficLightStatus newStatus);
TaskHandle_t start(const char* name, uint32_t stackSize, UBaseType_t priority, BaseType_t core);
void stop();

private:

Expand Down
10 changes: 7 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ void ICACHE_RAM_ATTR buttonHandler() {
lastBtnDebounceTime = millis();
}

void stopHub75DMA() {
void prepareOta() {
if (hasHub75 && hub75) hub75->stopDMA();
if (hasNeopixelMatrix && neopixelMatrix) {
hasNeopixelMatrix = false;
neopixelMatrix->stop();
}
}

void updateMessage(char const* msg) {
Expand Down Expand Up @@ -277,7 +281,7 @@ void setup() {

housekeeping::cyclicTimer.attach(30, housekeeping::doHousekeeping);

OTA::setupOta(stopHub75DMA);
OTA::setupOta(prepareOta);

attachInterrupt(TRIGGER_PIN, buttonHandler, CHANGE);

Expand All @@ -299,7 +303,7 @@ void loop() {
ESP_LOGD(TAG, "lastConfirmedBtnPressedTime - millis() %u", btnPressTime);
if (btnPressTime < 2000) {
digitalWrite(LED_PIN, LOW);
stopHub75DMA();
prepareOta();
WifiManager::startConfigPortal(updateMessage, setPriorityMessage, clearPriorityMessage);
} else if (btnPressTime > 5000) {
calibrateCo2SensorCallback(420);
Expand Down
12 changes: 12 additions & 0 deletions src/neopixelMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ TaskHandle_t NeopixelMatrix::start(const char* name, uint32_t stackSize, UBaseTy
return displayTask;
}

void NeopixelMatrix::stop() {
vTaskSuspend(displayTask);
updateQueue = NULL;
if (snakeTicker->active()) snakeTicker->detach();
if (cyclicTimer->active()) cyclicTimer->detach();
if (matrix) {
matrix->setBrightness(0);
matrix->fillScreen(0);
matrix->show();
}
}

/**
* Return the number of dots that represent the given PPM value, with ppm <= LOWER_LIMIT returning NUMBER_OF_DOTS (= full tank) and
* ppm >= UPPER_LIMIT returning 0 (= empty tank)
Expand Down
4 changes: 4 additions & 0 deletions src/ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace OTA {
if (preUpdateCallback) preUpdateCallback();
mqtt::publishStatusMsg("Starting OTA update");
esp32FOTA.execOTA();
delay(1000);
esp_restart();
} else {
ESP_LOGD(TAG, "No firmware update available");
}
Expand All @@ -61,6 +63,8 @@ namespace OTA {
forceUpdateURL = "";
ESP_LOGD(TAG, "Forced OTA done");
forceUpdateURL = "";
delay(1000);
esp_restart();
}

void otaLoop(void* pvParameters) {
Expand Down

0 comments on commit 307fba9

Please sign in to comment.