server_GPIO.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <esp_log.h>
  2. #include <esp_http_server.h>
  3. #include <map>
  4. //#include "ClassControllCamera.h"
  5. static const char *TAGPARTGPIO = "server_GPIO";
  6. typedef enum {
  7. GPIO_PIN_MODE_DISABLED = 0x0,
  8. GPIO_PIN_MODE_INPUT = 0x1,
  9. GPIO_PIN_MODE_INPUT_PULLUP = 0x2,
  10. GPIO_PIN_MODE_INPUT_PULLDOWN = 0x3,
  11. GPIO_PIN_MODE_OUTPUT = 0x4,
  12. GPIO_PIN_MODE_OUTPUT_PWM = 0x5,
  13. GPIO_PIN_MODE_EXTERNAL_FLASH_PWM = 0x5,
  14. GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X = 0x5,
  15. } gpio_pin_mode_t;
  16. class GpioPin {
  17. public:
  18. GpioPin(gpio_num_t gpio, const char* name, gpio_pin_mode_t mode, gpio_int_type_t interruptType, uint8_t dutyResolution, bool mqttEnable, bool httpEnable);
  19. ~GpioPin();
  20. bool getValue(std::string* errorText);
  21. void setValue(bool value, std::string* errorText);
  22. void init();
  23. private:
  24. gpio_num_t _gpio;
  25. const char* _name;
  26. gpio_pin_mode_t _mode;
  27. gpio_int_type_t _interruptType;
  28. };
  29. esp_err_t callHandleHttpRequest(httpd_req_t *req);
  30. void taskGpioHandler(void *pvParameter);
  31. class GpioHandler {
  32. public:
  33. GpioHandler(std::string configFile, httpd_handle_t httpServer);
  34. ~GpioHandler();
  35. void init();
  36. void clear();
  37. void registerGpioUri();
  38. esp_err_t handleHttpRequest(httpd_req_t *req);
  39. private:
  40. std::string _configFile;
  41. httpd_handle_t _httpServer;
  42. std::map<gpio_num_t, GpioPin*> *gpioMap = NULL;
  43. TaskHandle_t xHandletaskGpioHandler = NULL;
  44. bool readConfig();
  45. gpio_num_t resolvePinNr(uint8_t pinNr);
  46. gpio_pin_mode_t resolvePinMode(std::string input);
  47. gpio_int_type_t resolveIntType(std::string input);
  48. };
  49. void GpioHandlerStart();