ESPHome  2024.11.1
seeed_mr24hpc1.h
Go to the documentation of this file.
1 #pragma once
3 #include "esphome/core/defines.h"
4 #ifdef USE_BINARY_SENSOR
6 #endif
7 #ifdef USE_SENSOR
9 #endif
10 #ifdef USE_NUMBER
12 #endif
13 #ifdef USE_SWITCH
15 #endif
16 #ifdef USE_BUTTON
18 #endif
19 #ifdef USE_SELECT
21 #endif
22 #ifdef USE_TEXT_SENSOR
24 #endif
27 #include "esphome/core/helpers.h"
28 
30 
31 #include <map>
32 
33 namespace esphome {
34 namespace seeed_mr24hpc1 {
35 
36 enum FrameState {
47 };
48 
53  STANDARD_FUNCTION_QUERY_HARDWARE_MODE, // Above is the equipment information
62  STANDARD_FUNCTION_QUERY_HEARTBEAT_STATE, // Above is the basic function
63 
71 
78 };
79 
84 };
85 
86 static const char *const S_SCENE_STR[5] = {"None", "Living Room", "Bedroom", "Washroom", "Area Detection"};
87 static const bool S_SOMEONE_EXISTS_STR[2] = {false, true};
88 static const char *const S_MOTION_STATUS_STR[3] = {"None", "Motionless", "Active"};
89 static const char *const S_KEEP_AWAY_STR[3] = {"None", "Close", "Away"};
90 static const char *const S_UNMANNED_TIME_STR[9] = {"None", "10s", "30s", "1min", "2min",
91  "5min", "10min", "30min", "60min"};
92 static const char *const S_BOUNDARY_STR[10] = {"0.5m", "1.0m", "1.5m", "2.0m", "2.5m",
93  "3.0m", "3.5m", "4.0m", "4.5m", "5.0m"}; // uint: m
94 static const float S_PRESENCE_OF_DETECTION_RANGE_STR[7] = {0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f}; // uint: m
95 
97  public uart::UARTDevice { // The class name must be the name defined by text_sensor.py
98 #ifdef USE_TEXT_SENSOR
99  SUB_TEXT_SENSOR(heartbeat_state)
100  SUB_TEXT_SENSOR(product_model)
101  SUB_TEXT_SENSOR(product_id)
102  SUB_TEXT_SENSOR(hardware_model)
103  SUB_TEXT_SENSOR(firware_version)
104  SUB_TEXT_SENSOR(keep_away)
105  SUB_TEXT_SENSOR(motion_status)
106  SUB_TEXT_SENSOR(custom_mode_end)
107 #endif
108 #ifdef USE_BINARY_SENSOR
109  SUB_BINARY_SENSOR(has_target)
110 #endif
111 #ifdef USE_SENSOR
112  SUB_SENSOR(custom_presence_of_detection)
113  SUB_SENSOR(movement_signs)
114  SUB_SENSOR(custom_motion_distance)
115  SUB_SENSOR(custom_spatial_static_value)
116  SUB_SENSOR(custom_spatial_motion_value)
117  SUB_SENSOR(custom_motion_speed)
118  SUB_SENSOR(custom_mode_num)
119 #endif
120 #ifdef USE_SWITCH
121  SUB_SWITCH(underlying_open_function)
122 #endif
123 #ifdef USE_BUTTON
124  SUB_BUTTON(restart)
125  SUB_BUTTON(custom_set_end)
126 #endif
127 #ifdef USE_SELECT
128  SUB_SELECT(scene_mode)
129  SUB_SELECT(unman_time)
130  SUB_SELECT(existence_boundary)
131  SUB_SELECT(motion_boundary)
132 #endif
133 #ifdef USE_NUMBER
134  SUB_NUMBER(sensitivity)
135  SUB_NUMBER(custom_mode)
136  SUB_NUMBER(existence_threshold)
137  SUB_NUMBER(motion_threshold)
138  SUB_NUMBER(motion_trigger)
139  SUB_NUMBER(motion_to_rest)
140  SUB_NUMBER(custom_unman_time)
141 #endif
142 
143  protected:
144  char c_product_mode_[PRODUCT_BUF_MAX_SIZE + 1];
145  char c_product_id_[PRODUCT_BUF_MAX_SIZE + 1];
146  char c_hardware_model_[PRODUCT_BUF_MAX_SIZE + 1];
147  char c_firmware_version_[PRODUCT_BUF_MAX_SIZE + 1];
148  uint8_t s_output_info_switch_flag_;
149  uint8_t sg_recv_data_state_;
150  uint8_t sg_frame_len_;
151  uint8_t sg_data_len_;
152  uint8_t sg_frame_buf_[FRAME_BUF_MAX_SIZE];
153  uint8_t sg_frame_prase_buf_[FRAME_BUF_MAX_SIZE];
154  int sg_start_query_data_;
155  bool check_dev_inf_sign_;
156  bool poll_time_base_func_check_;
157 
158  void update_();
159  void r24_split_data_frame_(uint8_t value);
160  void r24_parse_data_frame_(uint8_t *data, uint8_t len);
161  void r24_frame_parse_open_underlying_information_(uint8_t *data);
162  void r24_frame_parse_work_status_(uint8_t *data);
163  void r24_frame_parse_product_information_(uint8_t *data);
164  void r24_frame_parse_human_information_(uint8_t *data);
165  void send_query_(const uint8_t *query, size_t string_length);
166 
167  public:
168  float get_setup_priority() const override { return esphome::setup_priority::LATE; }
169  void setup() override;
170  void dump_config() override;
171  void loop() override;
172 
173  void get_heartbeat_packet();
175  void get_product_mode();
176  void get_product_id();
177  void get_hardware_model();
178  void get_firmware_version();
179  void get_human_status();
180  void get_human_motion_info();
181  void get_body_motion_params();
182  void get_keep_away();
183  void get_scene_mode();
184  void get_sensitivity();
185  void get_unmanned_time();
186  void get_custom_mode();
187  void get_existence_boundary();
188  void get_motion_boundary();
195  void get_motion_threshold();
198  void get_custom_unman_time();
199 
200  void set_scene_mode(uint8_t value);
201  void set_underlying_open_function(bool enable);
202  void set_sensitivity(uint8_t value);
203  void set_restart();
204  void set_unman_time(uint8_t value);
205  void set_custom_mode(uint8_t mode);
206  void set_custom_end_mode();
207  void set_existence_boundary(uint8_t value);
208  void set_motion_boundary(uint8_t value);
209  void set_existence_threshold(uint8_t value);
210  void set_motion_threshold(uint8_t value);
211  void set_motion_trigger_time(uint8_t value);
212  void set_motion_to_rest_time(uint16_t value);
213  void set_custom_unman_time(uint16_t value);
214 };
215 
216 } // namespace seeed_mr24hpc1
217 } // namespace esphome
const float LATE
For components that should be initialized at the very end of the setup process.
Definition: component.cpp:28
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:183
std::string size_t len
Definition: helpers.h:293
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7