ESPHome  2024.4.1
am43_base.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/log.h"
4 #include "esphome/core/helpers.h"
5 
6 namespace esphome {
7 namespace am43 {
8 
9 static const uint16_t AM43_SERVICE_UUID = 0xFE50;
10 static const uint16_t AM43_CHARACTERISTIC_UUID = 0xFE51;
11 //
12 // Tuya identifiers, only to detect and warn users as they are incompatible.
13 static const uint16_t AM43_TUYA_SERVICE_UUID = 0x1910;
14 static const uint16_t AM43_TUYA_CHARACTERISTIC_UUID = 0x2b11;
15 
16 struct Am43Packet {
17  uint8_t length;
18  uint8_t data[24];
19 };
20 
21 static const uint8_t CMD_GET_BATTERY_LEVEL = 0xA2;
22 static const uint8_t CMD_GET_LIGHT_LEVEL = 0xAA;
23 static const uint8_t CMD_GET_POSITION = 0xA7;
24 static const uint8_t CMD_SEND_PIN = 0x17;
25 static const uint8_t CMD_SET_STATE = 0x0A;
26 static const uint8_t CMD_SET_POSITION = 0x0D;
27 static const uint8_t CMD_NOTIFY_POSITION = 0xA1;
28 
29 static const uint8_t RESPONSE_ACK = 0x5A;
30 static const uint8_t RESPONSE_NACK = 0xA5;
31 
32 class Am43Encoder {
33  public:
34  Am43Packet *get_battery_level_request();
35  Am43Packet *get_light_level_request();
36  Am43Packet *get_position_request();
37  Am43Packet *get_send_pin_request(uint16_t pin);
38  Am43Packet *get_open_request();
39  Am43Packet *get_close_request();
40  Am43Packet *get_stop_request();
41  Am43Packet *get_set_position_request(uint8_t position);
42 
43  protected:
44  void checksum_();
45  Am43Packet *encode_(uint8_t command, uint8_t *data, uint8_t length);
47 };
48 
49 class Am43Decoder {
50  public:
51  void decode(const uint8_t *data, uint16_t length);
52  bool has_battery_level() { return this->has_battery_level_; }
53  bool has_light_level() { return this->has_light_level_; }
54  bool has_set_position_response() { return this->has_set_position_response_; }
55  bool has_set_state_response() { return this->has_set_state_response_; }
56  bool has_position() { return this->has_position_; }
57  bool has_pin_response() { return this->has_pin_response_; }
58 
59  union {
60  uint8_t position_;
61  uint8_t battery_level_;
62  float light_level_;
64  uint8_t set_state_ok_;
65  uint8_t pin_ok_;
66  };
67 
68  protected:
75 };
76 
77 } // namespace am43
78 } // namespace esphome
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
float position
Definition: cover.h:14