esp32_improv.h.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include <improv.h>
  3. #include "esp_bt.h"
  4. #include "esp_bt_main.h"
  5. #include "esp_gap_bt_api.h"
  6. #include "bt_app_core.h"
  7. #include "BLECharacteristic.h"
  8. //#include "esphome/components/esp32_ble_server/ble_server.h"
  9. namespace esp32_improv {
  10. class ESP32Improv {
  11. public:
  12. ESP32Improv();
  13. void dump_config() ;
  14. void loop() ;
  15. void setup() ;
  16. void setup_characteristics();
  17. void on_client_disconnect() ;
  18. float get_setup_priority() ;
  19. void start() ;
  20. void stop() ;
  21. bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
  22. void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
  23. void set_status_indicator(output::BinaryOutput *status_indicator) { this->status_indicator_ = status_indicator; }
  24. void set_identify_duration(uint32_t identify_duration) { this->identify_duration_ = identify_duration; }
  25. void set_authorized_duration(uint32_t authorized_duration) { this->authorized_duration_ = authorized_duration; }
  26. protected:
  27. bool should_start_{false};
  28. bool setup_complete_{false};
  29. uint32_t identify_start_{0};
  30. uint32_t identify_duration_;
  31. uint32_t authorized_start_{0};
  32. uint32_t authorized_duration_;
  33. std::vector<uint8_t> incoming_data_;
  34. wifi::WiFiAP connecting_sta_;
  35. std::shared_ptr<BLEService> service_;
  36. BLECharacteristic *status_;
  37. BLECharacteristic *error_;
  38. BLECharacteristic *rpc_;
  39. BLECharacteristic *rpc_response_;
  40. BLECharacteristic *capabilities_;
  41. binary_sensor::BinarySensor *authorizer_{nullptr};
  42. output::BinaryOutput *status_indicator_{nullptr};
  43. improv::State state_{improv::STATE_STOPPED};
  44. improv::Error error_state_{improv::ERROR_NONE};
  45. void set_state_(improv::State state);
  46. void set_error_(improv::Error error);
  47. void send_response_(std::vector<uint8_t> &response);
  48. void process_incoming_data_();
  49. void on_wifi_connect_timeout_();
  50. bool check_identify_();
  51. };
  52. // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
  53. extern ESP32ImprovComponent *global_improv_component;
  54. } // namespace esp32_improv