4 #ifdef USE_BINARY_SENSOR 22 #ifdef USE_TEXT_SENSOR 34 #define CHECK_BIT(var, pos) (((var) >> (pos)) & 1) 37 static const uint8_t CMD_ENABLE_CONF = 0x00FF;
38 static const uint8_t CMD_DISABLE_CONF = 0x00FE;
39 static const uint8_t CMD_ENABLE_ENG = 0x0062;
40 static const uint8_t CMD_DISABLE_ENG = 0x0063;
41 static const uint8_t CMD_MAXDIST_DURATION = 0x0060;
42 static const uint8_t CMD_QUERY = 0x0061;
43 static const uint8_t CMD_GATE_SENS = 0x0064;
44 static const uint8_t CMD_VERSION = 0x00A0;
45 static const uint8_t CMD_QUERY_DISTANCE_RESOLUTION = 0x00AB;
46 static const uint8_t CMD_SET_DISTANCE_RESOLUTION = 0x00AA;
47 static const uint8_t CMD_QUERY_LIGHT_CONTROL = 0x00AE;
48 static const uint8_t CMD_SET_LIGHT_CONTROL = 0x00AD;
49 static const uint8_t CMD_SET_BAUD_RATE = 0x00A1;
50 static const uint8_t CMD_BT_PASSWORD = 0x00A9;
51 static const uint8_t CMD_MAC = 0x00A5;
52 static const uint8_t CMD_RESET = 0x00A2;
53 static const uint8_t CMD_RESTART = 0x00A3;
54 static const uint8_t CMD_BLUETOOTH = 0x00A4;
67 static const std::map<std::string, uint8_t> BAUD_RATE_ENUM_TO_INT{
85 static const std::map<std::string, uint8_t> LIGHT_FUNCTION_ENUM_TO_INT{
87 static const std::map<uint8_t, std::string> LIGHT_FUNCTION_INT_TO_ENUM{
92 static const std::map<std::string, uint8_t> OUT_PIN_LEVEL_ENUM_TO_INT{{
"low",
OUT_PIN_LEVEL_LOW},
94 static const std::map<uint8_t, std::string> OUT_PIN_LEVEL_INT_TO_ENUM{{
OUT_PIN_LEVEL_LOW,
"low"},
98 static const uint8_t CMD_MAX_MOVE_VALUE = 0x0000;
99 static const uint8_t CMD_MAX_STILL_VALUE = 0x0001;
100 static const uint8_t CMD_DURATION_VALUE = 0x0002;
102 static const uint8_t CMD_FRAME_HEADER[4] = {0xFD, 0xFC, 0xFB, 0xFA};
103 static const uint8_t CMD_FRAME_END[4] = {0x04, 0x03, 0x02, 0x01};
105 static const uint8_t DATA_FRAME_HEADER[4] = {0xF4, 0xF3, 0xF2, 0xF1};
106 static const uint8_t DATA_FRAME_END[4] = {0xF8, 0xF7, 0xF6, 0xF5};
139 SUB_SENSOR(moving_target_distance)
140 SUB_SENSOR(still_target_distance)
141 SUB_SENSOR(moving_target_energy)
142 SUB_SENSOR(still_target_energy)
144 SUB_SENSOR(detection_distance)
146 #ifdef USE_BINARY_SENSOR 147 SUB_BINARY_SENSOR(target)
148 SUB_BINARY_SENSOR(moving_target)
149 SUB_BINARY_SENSOR(still_target)
150 SUB_BINARY_SENSOR(out_pin_presence_status)
152 #ifdef USE_TEXT_SENSOR 157 SUB_SELECT(distance_resolution)
158 SUB_SELECT(baud_rate)
159 SUB_SELECT(light_function)
160 SUB_SELECT(out_pin_level)
163 SUB_SWITCH(engineering_mode)
164 SUB_SWITCH(bluetooth)
172 SUB_NUMBER(max_still_distance_gate)
173 SUB_NUMBER(max_move_distance_gate)
175 SUB_NUMBER(light_threshold)
180 void setup()
override;
181 void dump_config()
override;
182 void loop()
override;
183 void set_light_out_control();
185 void set_gate_still_threshold_number(
int gate,
number::Number *n);
187 void set_max_distances_timeout();
188 void set_gate_threshold(uint8_t gate);
194 void set_throttle(uint16_t value) { this->
throttle_ = value; };
195 void set_bluetooth_password(
const std::string &password);
196 void set_engineering_mode(
bool enable);
197 void read_all_info();
198 void restart_and_read_all_info();
199 void set_bluetooth(
bool enable);
200 void set_distance_resolution(
const std::string &
state);
201 void set_baud_rate(
const std::string &state);
202 void factory_reset();
205 int two_byte_to_int_(
char firstbyte,
char secondbyte) {
return (int16_t) (secondbyte << 8) + firstbyte; }
206 void send_command_(uint8_t command_str,
const uint8_t *command_value,
int command_value_len);
210 void readline_(
int readch, uint8_t *buffer,
int len);
void set_config_mode_(bool enable)
DistanceResolutionStructure
void readline_(int readch, uint8_t *buffer, int len)
std::string light_function_
void get_distance_resolution_()
std::vector< number::Number * > gate_move_threshold_numbers_
uint32_t IRAM_ATTR HOT millis()
void get_light_control_()
int32_t last_engineering_mode_change_millis_
Base-class for all numbers.
std::vector< number::Number * > gate_still_threshold_numbers_
bool handle_ack_data_(uint8_t *buffer, int len)
std::vector< sensor::Sensor * > gate_move_sensors_
Implementation of SPI Controller mode.
std::vector< sensor::Sensor * > gate_still_sensors_
void send_command_(uint8_t command_str, const uint8_t *command_value, int command_value_len)
int two_byte_to_int_(char firstbyte, char secondbyte)
void handle_periodic_data_(uint8_t *buffer, int len)
Base-class for all sensors.
std::string out_pin_level_
int32_t last_periodic_millis_