|
@@ -8,7 +8,10 @@
|
|
|
#include <esp_http_server.h>
|
|
#include <esp_http_server.h>
|
|
|
#include <map>
|
|
#include <map>
|
|
|
#include <string>
|
|
#include <string>
|
|
|
|
|
+#include <mutex>
|
|
|
#include "driver/gpio.h"
|
|
#include "driver/gpio.h"
|
|
|
|
|
+#include "freertos/queue.h"
|
|
|
|
|
+#include "freertos/semphr.h"
|
|
|
|
|
|
|
|
#include "SmartLeds.h"
|
|
#include "SmartLeds.h"
|
|
|
|
|
|
|
@@ -27,6 +30,12 @@ typedef enum {
|
|
|
struct GpioResult {
|
|
struct GpioResult {
|
|
|
gpio_num_t gpio;
|
|
gpio_num_t gpio;
|
|
|
int value;
|
|
int value;
|
|
|
|
|
+ bool stopEvent;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+struct GpioIsrContext {
|
|
|
|
|
+ QueueHandle_t eventQueue;
|
|
|
|
|
+ gpio_num_t gpio;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
|
typedef enum {
|
|
@@ -40,7 +49,7 @@ public:
|
|
|
GpioPin(gpio_num_t gpio, const char* name, gpio_pin_mode_t mode, gpio_int_type_t interruptType, uint8_t dutyResolution, std::string mqttTopic, bool httpEnable);
|
|
GpioPin(gpio_num_t gpio, const char* name, gpio_pin_mode_t mode, gpio_int_type_t interruptType, uint8_t dutyResolution, std::string mqttTopic, bool httpEnable);
|
|
|
~GpioPin();
|
|
~GpioPin();
|
|
|
|
|
|
|
|
- bool init();
|
|
|
|
|
|
|
+ bool init(QueueHandle_t eventQueue);
|
|
|
bool getValue(std::string* errorText);
|
|
bool getValue(std::string* errorText);
|
|
|
void setValue(bool value, gpio_set_source setSource, std::string* errorText);
|
|
void setValue(bool value, gpio_set_source setSource, std::string* errorText);
|
|
|
#ifdef ENABLE_MQTT
|
|
#ifdef ENABLE_MQTT
|
|
@@ -61,11 +70,11 @@ private:
|
|
|
std::string _mqttTopic;
|
|
std::string _mqttTopic;
|
|
|
bool _httpEnable = false;
|
|
bool _httpEnable = false;
|
|
|
bool _isrRegistered = false;
|
|
bool _isrRegistered = false;
|
|
|
|
|
+ GpioIsrContext _isrContext = {};
|
|
|
int currentState = -1;
|
|
int currentState = -1;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
esp_err_t callHandleHttpRequest(httpd_req_t *req);
|
|
esp_err_t callHandleHttpRequest(httpd_req_t *req);
|
|
|
-void taskGpioHandler(void *pvParameter);
|
|
|
|
|
|
|
|
|
|
class GpioHandler {
|
|
class GpioHandler {
|
|
|
public:
|
|
public:
|
|
@@ -79,7 +88,7 @@ public:
|
|
|
void taskHandler();
|
|
void taskHandler();
|
|
|
void gpioInterrupt(GpioResult* gpioResult);
|
|
void gpioInterrupt(GpioResult* gpioResult);
|
|
|
void flashLightEnable(bool value);
|
|
void flashLightEnable(bool value);
|
|
|
- bool isEnabled() { return _isEnabled; }
|
|
|
|
|
|
|
+ bool isEnabled() const { return _isEnabled; }
|
|
|
#ifdef ENABLE_MQTT
|
|
#ifdef ENABLE_MQTT
|
|
|
void handleMQTTconnect();
|
|
void handleMQTTconnect();
|
|
|
#endif //ENABLE_MQTT
|
|
#endif //ENABLE_MQTT
|
|
@@ -88,7 +97,10 @@ private:
|
|
|
std::string _configFile;
|
|
std::string _configFile;
|
|
|
httpd_handle_t _httpServer;
|
|
httpd_handle_t _httpServer;
|
|
|
std::map<gpio_num_t, GpioPin*> *gpioMap = NULL;
|
|
std::map<gpio_num_t, GpioPin*> *gpioMap = NULL;
|
|
|
- TaskHandle_t xHandleTaskGpio = NULL;
|
|
|
|
|
|
|
+ QueueHandle_t _eventQueue = NULL;
|
|
|
|
|
+ TaskHandle_t _workerTask = NULL;
|
|
|
|
|
+ SemaphoreHandle_t _workerStopped = NULL;
|
|
|
|
|
+ std::mutex _mapMutex;
|
|
|
bool _isEnabled = false;
|
|
bool _isEnabled = false;
|
|
|
|
|
|
|
|
int LEDNumbers = 2;
|
|
int LEDNumbers = 2;
|
|
@@ -100,6 +112,9 @@ private:
|
|
|
|
|
|
|
|
bool readConfig();
|
|
bool readConfig();
|
|
|
void clear();
|
|
void clear();
|
|
|
|
|
+ void clearUnlocked();
|
|
|
|
|
+ static void taskEntry(void *arg);
|
|
|
|
|
+ void workerLoop();
|
|
|
|
|
|
|
|
gpio_pin_mode_t resolvePinMode(std::string input);
|
|
gpio_pin_mode_t resolvePinMode(std::string input);
|
|
|
gpio_int_type_t resolveIntType(std::string input);
|
|
gpio_int_type_t resolveIntType(std::string input);
|