diff --git a/esp32-cam-webserver.ino b/esp32-cam-webserver.ino index 972c535..f85b9e7 100644 --- a/esp32-cam-webserver.ino +++ b/esp32-cam-webserver.ino @@ -1,3 +1,4 @@ +#include #include "src/app_config.h" // global definitions #include "src/storage.h" // Filesystem @@ -6,6 +7,10 @@ #include "src/app_httpd.h" // Web server #include "src/camera_pins.h" // Pin Mappings +#include "esp_task_wdt.h" +#include "soc/periph_defs.h" +#include "esp_private/periph_ctrl.h" +#include "freertos/timers.h" /* * This sketch is a extension/expansion/rework of the ESP32 Camera webserer example. * @@ -177,7 +182,11 @@ void flashLED(int flashtime) { } void scheduleReboot(int delay) { - esp_task_wdt_init(delay,true); + esp_task_wdt_config_t wdt_config = { + .timeout_ms = delay, // Timeout in milliseconds + .trigger_panic = true, // Trigger a panic when the timeout is reached + }; + esp_task_wdt_init(&wdt_config); // schedule a a watchdog panic event for 3 seconds in the future esp_task_wdt_add(NULL); } @@ -188,4 +197,3 @@ void resetI2CBus() { periph_module_reset(PERIPH_I2C0_MODULE); periph_module_reset(PERIPH_I2C1_MODULE); } - diff --git a/src/app_cam.h b/src/app_cam.h index ef180e5..7975941 100644 --- a/src/app_cam.h +++ b/src/app_cam.h @@ -4,8 +4,8 @@ #define CAM_DUMP_BUFFER_SIZE 1024 #include -#include -#include +#include +#include #include "app_component.h" #include "camera_pins.h" @@ -85,4 +85,4 @@ class CLAppCam : public CLAppComponent { extern CLAppCam AppCam; -#endif \ No newline at end of file +#endif diff --git a/src/app_httpd.cpp b/src/app_httpd.cpp index 71f19e7..c17ee13 100644 --- a/src/app_httpd.cpp +++ b/src/app_httpd.cpp @@ -1,5 +1,11 @@ +#include "freertos/FreeRTOS.h" #include "app_httpd.h" +#include "soc/periph_defs.h" +#include "soc/periph_defs.h" +#include "esp_private/periph_ctrl.h" +#include "esp_private/esp_int_wdt.h" +#include "esp_task_wdt.h" CLAppHttpd::CLAppHttpd() { // Gather static values used when dumping status; these are slow functions, so just do them once during startup sketchSize = ESP.getSketchSize();; @@ -373,7 +379,11 @@ void onControl(AsyncWebServerRequest *request) { request->send(200); if (AppHttpd.getLamp() != -1) AppHttpd.setLamp(0); // kill the lamp; otherwise it can remain on during the soft-reboot Storage.getFS().end(); // close file storage - esp_task_wdt_init(3,true); // schedule a a watchdog panic event for 3 seconds in the future + esp_task_wdt_config_t wdt_config = { + .timeout_ms = 3000, // Timeout in milliseconds + .trigger_panic = true, // Trigger a panic when the timeout is reached + }; + esp_task_wdt_init(&wdt_config); // schedule a a watchdog panic event for 3 seconds in the future esp_task_wdt_add(NULL); periph_module_disable(PERIPH_I2C0_MODULE); // try to shut I2C down properly periph_module_disable(PERIPH_I2C1_MODULE); diff --git a/src/app_httpd.h b/src/app_httpd.h index 8dd9f6f..2862bbd 100644 --- a/src/app_httpd.h +++ b/src/app_httpd.h @@ -1,8 +1,8 @@ #ifndef app_httpd_h #define app_httpd_h -#include -#include +#include +#include #include #include "esp32pwm.h" @@ -198,4 +198,4 @@ class CLAppHttpd : public CLAppComponent { extern CLAppHttpd AppHttpd; -#endif \ No newline at end of file +#endif diff --git a/src/esp32pwm.cpp b/src/esp32pwm.cpp index ac5b41f..b80edeb 100644 --- a/src/esp32pwm.cpp +++ b/src/esp32pwm.cpp @@ -44,13 +44,13 @@ ESP32PWM::ESP32PWM() { ESP32PWM::~ESP32PWM() { if (attached()) { - ledcDetachPin(pin); + ledcDetach(pin); } deallocate(); } double ESP32PWM::_ledcSetupTimerFreq(uint8_t chan, double freq, uint8_t bit_num) { - return ledcSetup(chan, freq, bit_num); + return ledcAttach(chan, freq, bit_num); } int ESP32PWM::timerAndIndexToChannel(int timerNum, int index) { @@ -142,12 +142,11 @@ double ESP32PWM::setup(double freq, uint8_t resolution_bits) { resolutionBits = resolution_bits; if (attached()) { - ledcDetachPin(pin); - double val = ledcSetup(getChannel(), freq, resolution_bits); - attachPin(pin); + ledcDetach(pin); + double val = ledcAttach(pin, freq, resolution_bits); return val; } - return ledcSetup(getChannel(), freq, resolution_bits); + return ledcAttach(pin, freq, resolution_bits); } double ESP32PWM::getDutyScaled() { return mapf((double) myDuty, 0, (double) ((1 << resolutionBits) - 1), 0.0, @@ -171,13 +170,13 @@ void ESP32PWM::adjustFrequencyLocal(double freq, double dutyScaled) { timerFreqSet[getTimer()] = (long) freq; myFreq = freq; if (attached()) { - ledcDetachPin(pin); + ledcDetach(pin); // Remove the PWM during frequency adjust - _ledcSetupTimerFreq(getChannel(), freq, resolutionBits); + ledcAttach(getChannel(), freq, resolutionBits); writeScaled(dutyScaled); - ledcAttachPin(pin, getChannel()); // re-attach the pin after frequency adjust + //ledcAttach(pin, getChannel()); // re-attach the pin after frequency adjust } else { - _ledcSetupTimerFreq(getChannel(), freq, resolutionBits); + ledcAttach(getChannel(), freq, resolutionBits); writeScaled(dutyScaled); } } @@ -209,7 +208,7 @@ void ESP32PWM::attachPin(uint8_t pin) { if (hasPwm(pin)) { attach(pin); - ledcAttachPin(pin, getChannel()); + //ledcAttach(pin, getChannel()); } else { Serial.println( "ERROR PWM channel unavailable on pin requested! " + String(pin) @@ -230,7 +229,7 @@ void ESP32PWM::attachPin(uint8_t pin, double freq, uint8_t resolution_bits) { attachPin(pin); } void ESP32PWM::detachPin(int pin) { - ledcDetachPin(pin); + ledcDetach(pin); deallocate(); } /* Side effects of frequency changes happen because of shared timers