ESPHome  2024.5.0
alpha3.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #ifdef USE_ESP32
9 
10 #include <esp_gattc_api.h>
11 
12 namespace esphome {
13 namespace alpha3 {
14 
16 
17 static const espbt::ESPBTUUID ALPHA3_GENI_SERVICE_UUID = espbt::ESPBTUUID::from_uint16(0xfe5d);
18 static const espbt::ESPBTUUID ALPHA3_GENI_CHARACTERISTIC_UUID =
19  espbt::ESPBTUUID::from_raw({static_cast<char>(0xa9), 0x7b, static_cast<char>(0xb8), static_cast<char>(0x85), 0x0,
20  0x1a, 0x28, static_cast<char>(0xaa), 0x2a, 0x43, 0x6e, 0x3, static_cast<char>(0xd1),
21  static_cast<char>(0xff), static_cast<char>(0x9c), static_cast<char>(0x85)});
22 static const int16_t GENI_RESPONSE_HEADER_LENGTH = 13;
23 static const size_t GENI_RESPONSE_TYPE_LENGTH = 8;
24 
25 static const uint8_t GENI_RESPONSE_TYPE_FLOW_HEAD[GENI_RESPONSE_TYPE_LENGTH] = {31, 0, 1, 48, 1, 0, 0, 24};
26 static const int16_t GENI_RESPONSE_FLOW_OFFSET = 0;
27 static const int16_t GENI_RESPONSE_HEAD_OFFSET = 4;
28 
29 static const uint8_t GENI_RESPONSE_TYPE_POWER[GENI_RESPONSE_TYPE_LENGTH] = {44, 0, 1, 0, 1, 0, 0, 37};
30 static const int16_t GENI_RESPONSE_VOLTAGE_AC_OFFSET = 0;
31 static const int16_t GENI_RESPONSE_VOLTAGE_DC_OFFSET = 4;
32 static const int16_t GENI_RESPONSE_CURRENT_OFFSET = 8;
33 static const int16_t GENI_RESPONSE_POWER_OFFSET = 12;
34 static const int16_t GENI_RESPONSE_MOTOR_POWER_OFFSET = 16; // not sure
35 static const int16_t GENI_RESPONSE_MOTOR_SPEED_OFFSET = 20;
36 
38  public:
39  void setup() override;
40  void update() override;
41  void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
42  esp_ble_gattc_cb_param_t *param) override;
43  void dump_config() override;
44  float get_setup_priority() const override { return setup_priority::DATA; }
45  void set_flow_sensor(sensor::Sensor *sensor) { this->flow_sensor_ = sensor; }
46  void set_head_sensor(sensor::Sensor *sensor) { this->head_sensor_ = sensor; }
47  void set_power_sensor(sensor::Sensor *sensor) { this->power_sensor_ = sensor; }
48  void set_current_sensor(sensor::Sensor *sensor) { this->current_sensor_ = sensor; }
49  void set_speed_sensor(sensor::Sensor *sensor) { this->speed_sensor_ = sensor; }
50  void set_voltage_sensor(sensor::Sensor *sensor) { this->voltage_sensor_ = sensor; }
51 
52  protected:
59  uint16_t geni_handle_;
62  uint8_t response_type_[GENI_RESPONSE_TYPE_LENGTH];
63  uint8_t buffer_[4];
64  void extract_publish_sensor_value_(const uint8_t *response, int16_t length, int16_t response_offset,
65  int16_t value_offset, sensor::Sensor *sensor, float factor);
66  void handle_geni_response_(const uint8_t *response, uint16_t length);
67  void send_request_(uint8_t *request, size_t len);
68  bool is_current_response_type_(const uint8_t *response_type);
69 };
70 } // namespace alpha3
71 } // namespace esphome
72 
73 #endif
void set_head_sensor(sensor::Sensor *sensor)
Definition: alpha3.h:46
sensor::Sensor * power_sensor_
Definition: alpha3.h:55
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void handle_geni_response_(const uint8_t *response, uint16_t length)
Definition: alpha3.cpp:57
int16_t response_offset_
Definition: alpha3.h:61
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
Definition: alpha3.cpp:97
bool is_current_response_type_(const uint8_t *response_type)
Definition: alpha3.cpp:53
uint8_t buffer_[4]
Definition: alpha3.h:63
void set_flow_sensor(sensor::Sensor *sensor)
Definition: alpha3.h:45
sensor::Sensor * flow_sensor_
Definition: alpha3.h:53
float get_setup_priority() const override
Definition: alpha3.h:44
void set_speed_sensor(sensor::Sensor *sensor)
Definition: alpha3.h:49
void extract_publish_sensor_value_(const uint8_t *response, int16_t length, int16_t response_offset, int16_t value_offset, sensor::Sensor *sensor, float factor)
Definition: alpha3.cpp:25
void dump_config() override
Definition: alpha3.cpp:13
void update() override
Definition: alpha3.cpp:170
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void setup() override
Definition: alpha3.cpp:23
uint16_t geni_handle_
Definition: alpha3.h:59
sensor::Sensor * voltage_sensor_
Definition: alpha3.h:58
static ESPBTUUID from_uint16(uint16_t uuid)
Definition: ble_uuid.cpp:16
sensor::Sensor * speed_sensor_
Definition: alpha3.h:57
void send_request_(uint8_t *request, size_t len)
Definition: alpha3.cpp:162
void set_voltage_sensor(sensor::Sensor *sensor)
Definition: alpha3.h:50
std::string size_t len
Definition: helpers.h:292
void set_current_sensor(sensor::Sensor *sensor)
Definition: alpha3.h:48
uint16_t length
Definition: tt21100.cpp:12
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
static ESPBTUUID from_raw(const uint8_t *data)
Definition: ble_uuid.cpp:28
Base-class for all sensors.
Definition: sensor.h:57
int16_t response_length_
Definition: alpha3.h:60
void set_power_sensor(sensor::Sensor *sensor)
Definition: alpha3.h:47
uint8_t response_type_[GENI_RESPONSE_TYPE_LENGTH]
Definition: alpha3.h:62
sensor::Sensor * head_sensor_
Definition: alpha3.h:54
sensor::Sensor * current_sensor_
Definition: alpha3.h:56