server_GPIO.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef SERVER_GPIO_H
  2. #define SERVER_GPIO_H
  3. #include <esp_log.h>
  4. #include <esp_http_server.h>
  5. #include <map>
  6. #include "driver/gpio.h"
  7. //#include "ClassControllCamera.h"
  8. typedef enum {
  9. GPIO_PIN_MODE_DISABLED = 0x0,
  10. GPIO_PIN_MODE_INPUT = 0x1,
  11. GPIO_PIN_MODE_INPUT_PULLUP = 0x2,
  12. GPIO_PIN_MODE_INPUT_PULLDOWN = 0x3,
  13. GPIO_PIN_MODE_OUTPUT = 0x4,
  14. GPIO_PIN_MODE_OUTPUT_PWM = 0x5,
  15. GPIO_PIN_MODE_EXTERNAL_FLASH_PWM = 0x5,
  16. GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X = 0x5,
  17. } gpio_pin_mode_t;
  18. class GpioPin {
  19. public:
  20. 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);
  21. ~GpioPin();
  22. bool getValue(std::string* errorText);
  23. void setValue(bool value, std::string* errorText);
  24. void init();
  25. bool handleMQTT(std::string, char* data, int data_len);
  26. void gpioInterrupt();
  27. private:
  28. gpio_num_t _gpio;
  29. const char* _name;
  30. gpio_pin_mode_t _mode;
  31. gpio_int_type_t _interruptType;
  32. std::string _mqttTopic;
  33. };
  34. esp_err_t callHandleHttpRequest(httpd_req_t *req);
  35. void taskGpioHandler(void *pvParameter);
  36. class GpioHandler {
  37. public:
  38. GpioHandler(std::string configFile, httpd_handle_t httpServer);
  39. ~GpioHandler();
  40. void init();
  41. void destroy();
  42. void registerGpioUri();
  43. esp_err_t handleHttpRequest(httpd_req_t *req);
  44. private:
  45. std::string _configFile;
  46. httpd_handle_t _httpServer;
  47. std::map<gpio_num_t, GpioPin*> *gpioMap = NULL;
  48. TaskHandle_t xHandletaskGpioHandler = NULL;
  49. bool readConfig();
  50. void clear();
  51. gpio_num_t resolvePinNr(uint8_t pinNr);
  52. gpio_pin_mode_t resolvePinMode(std::string input);
  53. gpio_int_type_t resolveIntType(std::string input);
  54. };
  55. void GpioHandlerStart();
  56. #endif //SERVER_GPIO_H