Skip to content

Commit

Permalink
Selective disable of interrupts
Browse files Browse the repository at this point in the history
  • Loading branch information
netmindz committed Oct 21, 2023
1 parent cb89e45 commit 0b5894c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sensor/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lib_deps =
https://github.com/dawidchyrzynski/arduino-home-assistant.git#2.0.0
links2004/WebSockets@^2.3.7
https://github.com/EinarArnason/ArduinoQueue.git@^1.2.5
https://github.com/scottchiefbaker/ESP-WebOTA.git#aefb6c1a9190601b12b973a0c1cce39cb4e0f453
https://github.com/netmindz/ESP-WebOTA.git#disable-interrupts


[env:wemos_d1_mini32]
Expand Down
37 changes: 32 additions & 5 deletions sensor/src/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ void IRAM_ATTR panelSelected() {
clearRXbuffer();
}

/**
* @brief enable interrupt for pin5 falling level change so we can clear the rx buffer
* every time our panel is selected
*/
void attachPanelInterrupt() {
attachInterrupt(digitalPinToInterrupt(PIN_5_PIN), panelSelected, FALLING);
}

void sendCommand(String command, int count) {
Serial.printf("Sending %s - %u times\n", command.c_str(), count);
for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -356,9 +364,30 @@ void setup() {
TX_PIN); // added here to see if line about was where the hang was
tub.updateBaudRate(115200);
#endif
// enable interrupt for pin5 falling level change so we can clear the rx buffer
// everytime our panel is selected
attachInterrupt(digitalPinToInterrupt(PIN_5_PIN), panelSelected, FALLING);

attachPanelInterrupt();

webota
.onStart([]() {
Serial.println("Start updating");
detachInterrupt(digitalPinToInterrupt(PIN_5_PIN));
})
.onEnd([]() {
Serial.println("\nOTA End");
attachPanelInterrupt();
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
attachPanelInterrupt();
});

init_wifi(ssid, passphrase, "hottub-sensor");
webota.init(8080, "/update");
Expand Down Expand Up @@ -560,9 +589,7 @@ void loop() {

mqtt.loop();

detachInterrupt(digitalPinToInterrupt(PIN_5_PIN));
webota.handle();
attachInterrupt(digitalPinToInterrupt(PIN_5_PIN), panelSelected, FALLING);

telnetLoop();

Expand Down

0 comments on commit 0b5894c

Please sign in to comment.