From 80b301d4e9ce1a8ca1902000152914905a28f4a4 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:47:22 +0800 Subject: [PATCH] Use digitalRead instead of attachInterrupt for reset pin due to conflict with Camera Add automatic restart after reset when Reset Pin is triggered --- .vscode/extensions.json | 17 ++- .vscode/settings.json | 3 +- .../src/modules/recovery/recovery_service.cpp | 122 ++++++++---------- 3 files changed, 69 insertions(+), 73 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 0f0d7401..080e70d0 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,10 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 2c55d928..24e61dba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,6 @@ "files.associations": { "*.tcc": "cpp", "fstream": "cpp" - } + }, + "cmake.configureOnOpen": false } \ No newline at end of file diff --git a/esp3d/src/modules/recovery/recovery_service.cpp b/esp3d/src/modules/recovery/recovery_service.cpp index 3223a0b4..f7bd703d 100644 --- a/esp3d/src/modules/recovery/recovery_service.cpp +++ b/esp3d/src/modules/recovery/recovery_service.cpp @@ -27,80 +27,72 @@ RecoveryService recovery_service; #ifdef PIN_RESET_FEATURE #include "../../core/esp3d.h" -volatile bool interruptswitch =false; -#ifdef ARDUINO_ARCH_ESP32 -portMUX_TYPE espmux = portMUX_INITIALIZER_UNLOCKED; -#endif //ARDUINO_ARCH_ESP32 +bool interruptswitch =false; -#ifdef ARDUINO_ARCH_ESP8266 -void handlePinResetInterrupt() + +RecoveryService::RecoveryService() { -#endif //ARDUINO_ARCH_ESP8266 -#ifdef ARDUINO_ARCH_ESP32 - void IRAM_ATTR handlePinResetInterrupt() { - portENTER_CRITICAL_ISR(&espmux); -#endif //ARDUINO_ARCH_ESP32 - interruptswitch = true; -#ifdef ARDUINO_ARCH_ESP32 - portEXIT_CRITICAL_ISR(&espmux); -#endif //ARDUINO_ARCH_ESP32 - } -#endif //PIN_RESET_FEATURE + _started = false; +} +RecoveryService::~RecoveryService() +{ + end(); +} - RecoveryService::RecoveryService() { - _started = false; - } - RecoveryService::~RecoveryService() { +bool RecoveryService::begin() +{ + bool res = true; + end(); + +#if defined (PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && ESP3D_RESET_PIN !=-1 + pinMode(ESP3D_RESET_PIN, INPUT_PULLUP); + //attach interrupt to pin is conflicting with camera device because it already attach interrupt to pin +#endif //PIN_RESET_FEATURE + if (!res) { end(); } + _started = res; + return _started; +} - bool RecoveryService::begin() { - bool res = true; - end(); -#if defined (PIN_RESET_FEATURE) -#if defined(ESP3D_RESET_PIN) && ESP3D_RESET_PIN !=-1 - pinMode(ESP3D_RESET_PIN, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(ESP3D_RESET_PIN), handlePinResetInterrupt, FALLING); -#endif //ESP3D_RESET_PIN + +void RecoveryService::end() +{ + if(!_started) { + return; + } + _started = false; +} + + +bool RecoveryService::started() +{ + return _started; +} + +void RecoveryService::handle() +{ + if (_started) { +#if defined(PIN_RESET_FEATURE) && defined(ESP3D_RESET_PIN) && ESP3D_RESET_PIN !=-1 + //attach interrupt to pin is conflicting with camera device because it already attach interrupt to pin + //so use digitalread to check pin state + interruptswitch = !digitalRead(ESP3D_RESET_PIN); #endif //PIN_RESET_FEATURE - if (!res) { - end(); - } - _started = res; - return _started; - } - - - void RecoveryService::end() { - if(!_started) { - return; - } -#ifdef PIN_RESET_FEATURE - detachInterrupt(digitalPinToInterrupt(ESP3D_RESET_PIN)); -#endif //PIN_RESET_FEATURE - _started = false; - } - - - bool RecoveryService::started() { - return _started; - } - - void RecoveryService::handle() { - if (_started) { -#ifdef PIN_RESET_FEATURE - if (interruptswitch) { - static uint32_t lastreset = 0; - interruptswitch = false; - if ((millis() - lastreset) > 1000) { - lastreset = millis(); - ESP3DOutput output(ESP_ALL_CLIENTS); - output.printMSG("Reset requested"); - Esp3D::reset(); - } + if (interruptswitch) { + static uint32_t lastreset = 0; + interruptswitch = false; + if ((millis() - lastreset) > 1000) { + lastreset = millis(); + ESP3DOutput output(ESP_ALL_CLIENTS); + output.printMSG("Reset requested"); + Esp3D::reset(); + output.flush(); + Hal::wait(100); + Esp3D::restart_esp(); } -#endif //PIN_RESET_FEATURE } +#endif //PIN_RESET_FEATURE } +} #endif //RECOVERY_FEATURE