Fix the daylight unit issue, fix the log back display issue of startup banble.
This commit is contained in:
parent
6d9ab93c3f
commit
7b19149f61
|
|
@ -22,8 +22,7 @@ void LD2410Component::dump_config() {
|
|||
LOG_SENSOR(" ", "Still Energy", this->still_target_energy_sensor_);
|
||||
LOG_SENSOR(" ", "Detection Distance", this->detection_distance_sensor_);
|
||||
|
||||
// 回显光线模块设置(23年3月13日_17时28分_)
|
||||
LOG_SENSOR(" ", "Light", this->light_sensor_);
|
||||
LOG_SENSOR(" ", "Light", this->light_sensor_);
|
||||
#endif
|
||||
this->set_config_mode_(true);
|
||||
this->get_version_();
|
||||
|
|
@ -36,7 +35,7 @@ void LD2410Component::setup() {
|
|||
ESP_LOGCONFIG(TAG, "Setting up LD2410...");
|
||||
// ESP_LOGCONFIG(TAG, "Apply screek patch...");
|
||||
this->set_config_mode_(true);
|
||||
// 使用蓝牙配置,取消这里的参数定义选项。(23年3月10日_20时50分_)
|
||||
|
||||
/*
|
||||
this->set_max_distances_timeout_(this->max_move_distance_, this->max_still_distance_, this->timeout_);
|
||||
// Configure Gates sensitivity
|
||||
|
|
@ -53,8 +52,6 @@ void LD2410Component::setup() {
|
|||
this->get_version_();
|
||||
this->set_config_mode_(false);
|
||||
|
||||
// 开启工程模式!(23年3月13日_18时03分_)
|
||||
// 因为会自动开启,这里就不太合适继续需要了。
|
||||
// this->factory_mode(true);
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Firmware Version : %u.%u.%u%u%u%u", this->version_[0], this->version_[1], this->version_[2],
|
||||
|
|
@ -71,7 +68,6 @@ void LD2410Component::loop() {
|
|||
}
|
||||
}
|
||||
|
||||
// 发送命令给雷达!(23年3月13日_14时46分_)
|
||||
void LD2410Component::send_command_(uint8_t command, uint8_t *command_value, int command_value_len) {
|
||||
// lastCommandSuccess->publish_state(false);
|
||||
|
||||
|
|
@ -100,7 +96,6 @@ void LD2410Component::send_command_(uint8_t command, uint8_t *command_value, int
|
|||
delay(50); // NOLINT
|
||||
}
|
||||
|
||||
// https://cdn.arduino.cc/reference/en/language/functions/math/map/
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
|
@ -186,7 +181,7 @@ void LD2410Component::handle_periodic_data_(uint8_t *buffer, int len) {
|
|||
if (this->light_sensor_ != nullptr) {
|
||||
int data_type = buffer[6];
|
||||
int new_light = -1;
|
||||
if (data_type == 0x01){ // 0x01 = factory mode
|
||||
if (data_type == 0x01){ // 0x01 = 工程模式!
|
||||
new_light = buffer[37];
|
||||
|
||||
new_light = map(new_light, 85, 255, 0, 100);
|
||||
|
|
@ -196,10 +191,14 @@ void LD2410Component::handle_periodic_data_(uint8_t *buffer, int len) {
|
|||
if (new_light > 100){
|
||||
new_light = 100;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG,"LD2410 Sun Light: %d%%", new_light);
|
||||
}else{
|
||||
int32_t now_millis = millis();
|
||||
|
||||
if (now_millis - last_change_fatory_mode_millis > 2000){
|
||||
ESP_LOGD(TAG,"Normal mode no light, change to factory mode");
|
||||
|
||||
this->factory_mode(true);
|
||||
last_change_fatory_mode_millis = now_millis;
|
||||
}
|
||||
|
|
@ -357,7 +356,6 @@ void LD2410Component::set_gate_threshold_(uint8_t gate, uint8_t motionsens, uint
|
|||
this->send_command_(CMD_GATE_SENS, value, 18);
|
||||
}
|
||||
|
||||
// 额外增加的命令到这里去(23年3月13日_14时57分_)
|
||||
void LD2410Component::factoryReset()
|
||||
{
|
||||
this->set_config_mode_(true);
|
||||
|
|
@ -387,9 +385,9 @@ void LD2410Component::ble_control(bool enable)
|
|||
if (enable){
|
||||
cmd_value[0] = 0x01;
|
||||
|
||||
ESP_LOGD(TAG, "Disable BLE...");
|
||||
}else{
|
||||
ESP_LOGD(TAG, "Enable BLE...");
|
||||
}else{
|
||||
ESP_LOGD(TAG, "Disable BLE...");
|
||||
}
|
||||
|
||||
this -> send_command_(CMD_BLE_CONF, cmd_value, 2);
|
||||
|
|
|
|||
|
|
@ -112,25 +112,14 @@ class LD2410Component : public Component, public uart::UARTDevice {
|
|||
|
||||
int32_t last_periodic_millis = millis();
|
||||
|
||||
/// @brief 上次改变工程模式的时间,用来防止改变频率太高了。(23年3月13日_18时07分_)
|
||||
int32_t last_change_fatory_mode_millis = 0;
|
||||
|
||||
// 增加一些额外的命令,比如重启,开关蓝牙。(23年3月13日_14时44分_)
|
||||
// https://github.com/rain931215/ESPHome-LD2410/blob/main/ld2410_uart.h
|
||||
|
||||
/// 恢复出厂设置!(23年3月13日_14时48分_)
|
||||
void factoryReset();
|
||||
|
||||
// 重启(23年3月13日_14时48分_)
|
||||
void reboot();
|
||||
|
||||
/// @brief 蓝牙开关
|
||||
/// (23年3月13日_15时22分_)
|
||||
void ble_control(bool enable);
|
||||
|
||||
/// @brief 开关工程模式
|
||||
/// @param enable 开关
|
||||
/// 用来快速切换工程模式用的。(23年3月13日_17时59分_)
|
||||
void factory_mode(bool enable);
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ from esphome.const import (
|
|||
DEVICE_CLASS_ENERGY,
|
||||
UNIT_CENTIMETER,
|
||||
UNIT_PERCENT,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
STATE_CLASS_NONE,
|
||||
ICON_BRIGHTNESS_5,
|
||||
UNIT_EMPTY,
|
||||
UNIT_LUX,
|
||||
|
||||
)
|
||||
from . import CONF_LD2410_ID, LD2410Component
|
||||
|
||||
|
|
@ -37,8 +39,11 @@ CONFIG_SCHEMA = {
|
|||
cv.Optional(CONF_DETECTION_DISTANCE): sensor.sensor_schema(
|
||||
device_class=DEVICE_CLASS_DISTANCE, unit_of_measurement=UNIT_CENTIMETER
|
||||
),
|
||||
|
||||
cv.Optional(CONF_LIGHT): sensor.sensor_schema(
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE, unit_of_measurement=UNIT_PERCENT
|
||||
device_class=STATE_CLASS_NONE,
|
||||
icon=ICON_BRIGHTNESS_5,
|
||||
unit_of_measurement=UNIT_PERCENT
|
||||
),
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +64,7 @@ async def to_code(config):
|
|||
if CONF_DETECTION_DISTANCE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_DETECTION_DISTANCE])
|
||||
cg.add(ld2410_component.set_detection_distance_sensor(sens))
|
||||
|
||||
if CONF_LIGHT in config:
|
||||
sens = await sensor.new_sensor(config[CONF_LIGHT])
|
||||
cg.add(ld2410_component.set_light_sensor(sens))
|
||||
|
|
@ -22,8 +22,7 @@ void LD2410Component::dump_config() {
|
|||
LOG_SENSOR(" ", "Still Energy", this->still_target_energy_sensor_);
|
||||
LOG_SENSOR(" ", "Detection Distance", this->detection_distance_sensor_);
|
||||
|
||||
// 回显光线模块设置(23年3月13日_17时28分_)
|
||||
LOG_SENSOR(" ", "Light", this->light_sensor_);
|
||||
LOG_SENSOR(" ", "Light", this->light_sensor_);
|
||||
#endif
|
||||
this->set_config_mode_(true);
|
||||
this->get_version_();
|
||||
|
|
@ -36,7 +35,7 @@ void LD2410Component::setup() {
|
|||
ESP_LOGCONFIG(TAG, "Setting up LD2410...");
|
||||
// ESP_LOGCONFIG(TAG, "Apply screek patch...");
|
||||
this->set_config_mode_(true);
|
||||
// 使用蓝牙配置,取消这里的参数定义选项。(23年3月10日_20时50分_)
|
||||
|
||||
/*
|
||||
this->set_max_distances_timeout_(this->max_move_distance_, this->max_still_distance_, this->timeout_);
|
||||
// Configure Gates sensitivity
|
||||
|
|
@ -53,8 +52,6 @@ void LD2410Component::setup() {
|
|||
this->get_version_();
|
||||
this->set_config_mode_(false);
|
||||
|
||||
// 开启工程模式!(23年3月13日_18时03分_)
|
||||
// 因为会自动开启,这里就不太合适继续需要了。
|
||||
// this->factory_mode(true);
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Firmware Version : %u.%u.%u%u%u%u", this->version_[0], this->version_[1], this->version_[2],
|
||||
|
|
@ -71,7 +68,6 @@ void LD2410Component::loop() {
|
|||
}
|
||||
}
|
||||
|
||||
// 发送命令给雷达!(23年3月13日_14时46分_)
|
||||
void LD2410Component::send_command_(uint8_t command, uint8_t *command_value, int command_value_len) {
|
||||
// lastCommandSuccess->publish_state(false);
|
||||
|
||||
|
|
@ -100,7 +96,6 @@ void LD2410Component::send_command_(uint8_t command, uint8_t *command_value, int
|
|||
delay(50); // NOLINT
|
||||
}
|
||||
|
||||
// https://cdn.arduino.cc/reference/en/language/functions/math/map/
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
|
@ -186,7 +181,7 @@ void LD2410Component::handle_periodic_data_(uint8_t *buffer, int len) {
|
|||
if (this->light_sensor_ != nullptr) {
|
||||
int data_type = buffer[6];
|
||||
int new_light = -1;
|
||||
if (data_type == 0x01){ // 0x01 = factory mode
|
||||
if (data_type == 0x01){ // 0x01 = 工程模式!
|
||||
new_light = buffer[37];
|
||||
|
||||
new_light = map(new_light, 85, 255, 0, 100);
|
||||
|
|
@ -196,10 +191,14 @@ void LD2410Component::handle_periodic_data_(uint8_t *buffer, int len) {
|
|||
if (new_light > 100){
|
||||
new_light = 100;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG,"LD2410 Sun Light: %d%%", new_light);
|
||||
}else{
|
||||
int32_t now_millis = millis();
|
||||
|
||||
if (now_millis - last_change_fatory_mode_millis > 2000){
|
||||
ESP_LOGD(TAG,"Normal mode no light, change to factory mode");
|
||||
|
||||
this->factory_mode(true);
|
||||
last_change_fatory_mode_millis = now_millis;
|
||||
}
|
||||
|
|
@ -357,7 +356,6 @@ void LD2410Component::set_gate_threshold_(uint8_t gate, uint8_t motionsens, uint
|
|||
this->send_command_(CMD_GATE_SENS, value, 18);
|
||||
}
|
||||
|
||||
// 额外增加的命令到这里去(23年3月13日_14时57分_)
|
||||
void LD2410Component::factoryReset()
|
||||
{
|
||||
this->set_config_mode_(true);
|
||||
|
|
@ -387,9 +385,9 @@ void LD2410Component::ble_control(bool enable)
|
|||
if (enable){
|
||||
cmd_value[0] = 0x01;
|
||||
|
||||
ESP_LOGD(TAG, "Disable BLE...");
|
||||
}else{
|
||||
ESP_LOGD(TAG, "Enable BLE...");
|
||||
}else{
|
||||
ESP_LOGD(TAG, "Disable BLE...");
|
||||
}
|
||||
|
||||
this -> send_command_(CMD_BLE_CONF, cmd_value, 2);
|
||||
|
|
@ -112,25 +112,14 @@ class LD2410Component : public Component, public uart::UARTDevice {
|
|||
|
||||
int32_t last_periodic_millis = millis();
|
||||
|
||||
/// @brief 上次改变工程模式的时间,用来防止改变频率太高了。(23年3月13日_18时07分_)
|
||||
int32_t last_change_fatory_mode_millis = 0;
|
||||
|
||||
// 增加一些额外的命令,比如重启,开关蓝牙。(23年3月13日_14时44分_)
|
||||
// https://github.com/rain931215/ESPHome-LD2410/blob/main/ld2410_uart.h
|
||||
|
||||
/// 恢复出厂设置!(23年3月13日_14时48分_)
|
||||
void factoryReset();
|
||||
|
||||
// 重启(23年3月13日_14时48分_)
|
||||
void reboot();
|
||||
|
||||
/// @brief 蓝牙开关
|
||||
/// (23年3月13日_15时22分_)
|
||||
void ble_control(bool enable);
|
||||
|
||||
/// @brief 开关工程模式
|
||||
/// @param enable 开关
|
||||
/// 用来快速切换工程模式用的。(23年3月13日_17时59分_)
|
||||
void factory_mode(bool enable);
|
||||
|
||||
protected:
|
||||
|
|
@ -6,9 +6,11 @@ from esphome.const import (
|
|||
DEVICE_CLASS_ENERGY,
|
||||
UNIT_CENTIMETER,
|
||||
UNIT_PERCENT,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
STATE_CLASS_NONE,
|
||||
ICON_BRIGHTNESS_5,
|
||||
UNIT_EMPTY,
|
||||
UNIT_LUX,
|
||||
|
||||
)
|
||||
from . import CONF_LD2410_ID, LD2410Component
|
||||
|
||||
|
|
@ -37,8 +39,11 @@ CONFIG_SCHEMA = {
|
|||
cv.Optional(CONF_DETECTION_DISTANCE): sensor.sensor_schema(
|
||||
device_class=DEVICE_CLASS_DISTANCE, unit_of_measurement=UNIT_CENTIMETER
|
||||
),
|
||||
|
||||
cv.Optional(CONF_LIGHT): sensor.sensor_schema(
|
||||
device_class=DEVICE_CLASS_ILLUMINANCE, unit_of_measurement=UNIT_PERCENT
|
||||
device_class=STATE_CLASS_NONE,
|
||||
icon=ICON_BRIGHTNESS_5,
|
||||
unit_of_measurement=UNIT_PERCENT
|
||||
),
|
||||
}
|
||||
|
||||
|
|
@ -59,6 +64,7 @@ async def to_code(config):
|
|||
if CONF_DETECTION_DISTANCE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_DETECTION_DISTANCE])
|
||||
cg.add(ld2410_component.set_detection_distance_sensor(sens))
|
||||
|
||||
if CONF_LIGHT in config:
|
||||
sens = await sensor.new_sensor(config[CONF_LIGHT])
|
||||
cg.add(ld2410_component.set_light_sensor(sens))
|
||||
Loading…
Reference in New Issue
Block a user