#ifndef QTHING_H #define QTHING_H #include <string> #include <string> #include <functional> #include "driver/gpio.h" // types enum pull_resistor_t { none, pullup, pulldown }; enum connection_status_t { uninitialized, disconnected, connecting, connected }; typedef std::function<void(std::string)> message_callback_t; typedef std::function<void(connection_status_t)> connection_status_callback_t; typedef std::function<void()> mqtt_connect_callback_t; typedef struct { const std::string& topic; const char* payload; const uint32_t length; const uint32_t offset; const uint32_t total_length; } multipart_message_t; typedef std::function<void(multipart_message_t)> binary_message_callback_t; enum ota_state_t { start, progress, success, error }; typedef struct { const ota_state_t state; const esp_err_t error; const uint32_t bytes_written; const uint32_t bytes_total; } ota_event_t; typedef std::function<void(ota_event_t)> ota_callback_t; // network void enable_wlan(); // mqtt void publish_message(const std::string& topic, const std::string& message); void add_message_callback(const std::string& topic, message_callback_t callback); void add_binary_message_callback(const std::string& topic, binary_message_callback_t callback); void add_ota_callback(ota_callback_t handler); void add_mqtt_connect_callback(mqtt_connect_callback_t callback); // common IO void enable_oled(); void add_digital_input(gpio_num_t gpio_num, pull_resistor_t pull_resistor, std::function<void()> on_falling_edge, std::function<void()> on_rising_edge); void add_digital_input(gpio_num_t gpio_num, pull_resistor_t pull_resistor, std::string topic); void add_button(gpio_num_t gpio, std::function<void()> on_press = NULL, std::function<void()> on_release = NULL); void add_button(gpio_num_t gpio, std::string topic, std::string message); void add_relay(const std::string& topic, gpio_num_t gpio_off, gpio_num_t gpio_on); // event handler void add_wlan_connection_status_handler(connection_status_callback_t handler); void add_mqtt_connection_status_handler(connection_status_callback_t handler); #endif