67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "esphome/components/esp32_ble/ble.h"
|
|
#include "esphome/core/component.h"
|
|
|
|
#ifdef USE_ESP32
|
|
|
|
#include <array>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <esp_gap_ble_api.h>
|
|
|
|
namespace esphome::ibeacon_rotator {
|
|
|
|
using namespace esp32_ble;
|
|
|
|
class IBeaconRotator : public Component {
|
|
public:
|
|
explicit IBeaconRotator(const std::array<uint8_t, 10> &prefix) : prefix_(prefix) {}
|
|
|
|
void setup() override;
|
|
void loop() override;
|
|
void dump_config() override;
|
|
float get_setup_priority() const override { return setup_priority::AFTER_BLUETOOTH; }
|
|
|
|
void set_broadcast_length(uint32_t ms) { this->broadcast_length_ms_ = ms; }
|
|
void set_min_interval(uint32_t ms) { this->min_interval_ = static_cast<uint16_t>(ms); }
|
|
void set_max_interval(uint32_t ms) { this->max_interval_ = static_cast<uint16_t>(ms); }
|
|
void set_major(uint16_t v) { this->major_ = v; }
|
|
void set_minor(uint16_t v) { this->minor_ = v; }
|
|
void set_measured_power(int8_t v) { this->measured_power_ = v; }
|
|
|
|
void add_mac(const uint8_t mac[6]);
|
|
bool add_mac_from_string(const std::string &mac_str);
|
|
|
|
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
|
|
|
|
protected:
|
|
struct Entry {
|
|
uint8_t mac[6];
|
|
uint32_t expires_at_ms;
|
|
};
|
|
|
|
void apply_current_payload_();
|
|
void stop_advertising_();
|
|
void evict_expired_();
|
|
|
|
std::array<uint8_t, 10> prefix_;
|
|
std::vector<Entry> entries_;
|
|
size_t cursor_{0};
|
|
uint32_t last_rotate_ms_{0};
|
|
bool advertising_{false};
|
|
|
|
uint32_t broadcast_length_ms_{30000};
|
|
uint16_t min_interval_{100};
|
|
uint16_t max_interval_{100};
|
|
uint16_t major_{0};
|
|
uint16_t minor_{0};
|
|
int8_t measured_power_{-59};
|
|
esp_ble_adv_params_t ble_adv_params_{};
|
|
};
|
|
|
|
} // namespace esphome::ibeacon_rotator
|
|
|
|
#endif // USE_ESP32
|