mirror of
https://github.com/esphome/esphome.git
synced 2025-08-07 02:47:47 +00:00
Merge remote-tracking branch 'upstream/dev' into idf_webserver_ota
This commit is contained in:
commit
8e31316e3d
@ -182,7 +182,7 @@ async def to_code(config):
|
|||||||
# and plaintext disabled. Only a factory reset can remove it.
|
# and plaintext disabled. Only a factory reset can remove it.
|
||||||
cg.add_define("USE_API_PLAINTEXT")
|
cg.add_define("USE_API_PLAINTEXT")
|
||||||
cg.add_define("USE_API_NOISE")
|
cg.add_define("USE_API_NOISE")
|
||||||
cg.add_library("esphome/noise-c", "0.1.6")
|
cg.add_library("esphome/noise-c", "0.1.10")
|
||||||
else:
|
else:
|
||||||
cg.add_define("USE_API_PLAINTEXT")
|
cg.add_define("USE_API_PLAINTEXT")
|
||||||
|
|
||||||
|
@ -66,9 +66,10 @@ ETHERNET_TYPES = {
|
|||||||
"KSZ8081RNA": EthernetType.ETHERNET_TYPE_KSZ8081RNA,
|
"KSZ8081RNA": EthernetType.ETHERNET_TYPE_KSZ8081RNA,
|
||||||
"W5500": EthernetType.ETHERNET_TYPE_W5500,
|
"W5500": EthernetType.ETHERNET_TYPE_W5500,
|
||||||
"OPENETH": EthernetType.ETHERNET_TYPE_OPENETH,
|
"OPENETH": EthernetType.ETHERNET_TYPE_OPENETH,
|
||||||
|
"DM9051": EthernetType.ETHERNET_TYPE_DM9051,
|
||||||
}
|
}
|
||||||
|
|
||||||
SPI_ETHERNET_TYPES = ["W5500"]
|
SPI_ETHERNET_TYPES = ["W5500", "DM9051"]
|
||||||
SPI_ETHERNET_DEFAULT_POLLING_INTERVAL = TimePeriodMilliseconds(milliseconds=10)
|
SPI_ETHERNET_DEFAULT_POLLING_INTERVAL = TimePeriodMilliseconds(milliseconds=10)
|
||||||
|
|
||||||
emac_rmii_clock_mode_t = cg.global_ns.enum("emac_rmii_clock_mode_t")
|
emac_rmii_clock_mode_t = cg.global_ns.enum("emac_rmii_clock_mode_t")
|
||||||
@ -224,6 +225,7 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
"KSZ8081RNA": RMII_SCHEMA,
|
"KSZ8081RNA": RMII_SCHEMA,
|
||||||
"W5500": SPI_SCHEMA,
|
"W5500": SPI_SCHEMA,
|
||||||
"OPENETH": BASE_SCHEMA,
|
"OPENETH": BASE_SCHEMA,
|
||||||
|
"DM9051": SPI_SCHEMA,
|
||||||
},
|
},
|
||||||
upper=True,
|
upper=True,
|
||||||
),
|
),
|
||||||
@ -278,7 +280,7 @@ async def to_code(config):
|
|||||||
var = cg.new_Pvariable(config[CONF_ID])
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
if config[CONF_TYPE] == "W5500":
|
if config[CONF_TYPE] in SPI_ETHERNET_TYPES:
|
||||||
cg.add(var.set_clk_pin(config[CONF_CLK_PIN]))
|
cg.add(var.set_clk_pin(config[CONF_CLK_PIN]))
|
||||||
cg.add(var.set_miso_pin(config[CONF_MISO_PIN]))
|
cg.add(var.set_miso_pin(config[CONF_MISO_PIN]))
|
||||||
cg.add(var.set_mosi_pin(config[CONF_MOSI_PIN]))
|
cg.add(var.set_mosi_pin(config[CONF_MOSI_PIN]))
|
||||||
@ -296,7 +298,9 @@ async def to_code(config):
|
|||||||
cg.add_define("USE_ETHERNET_SPI")
|
cg.add_define("USE_ETHERNET_SPI")
|
||||||
if CORE.using_esp_idf:
|
if CORE.using_esp_idf:
|
||||||
add_idf_sdkconfig_option("CONFIG_ETH_USE_SPI_ETHERNET", True)
|
add_idf_sdkconfig_option("CONFIG_ETH_USE_SPI_ETHERNET", True)
|
||||||
add_idf_sdkconfig_option("CONFIG_ETH_SPI_ETHERNET_W5500", True)
|
add_idf_sdkconfig_option(
|
||||||
|
f"CONFIG_ETH_SPI_ETHERNET_{config[CONF_TYPE]}", True
|
||||||
|
)
|
||||||
elif config[CONF_TYPE] == "OPENETH":
|
elif config[CONF_TYPE] == "OPENETH":
|
||||||
cg.add_define("USE_ETHERNET_OPENETH")
|
cg.add_define("USE_ETHERNET_OPENETH")
|
||||||
add_idf_sdkconfig_option("CONFIG_ETH_USE_OPENETH", True)
|
add_idf_sdkconfig_option("CONFIG_ETH_USE_OPENETH", True)
|
||||||
|
@ -90,8 +90,8 @@ void EthernetComponent::setup() {
|
|||||||
|
|
||||||
#ifdef USE_ETHERNET_SPI // Configure SPI interface and Ethernet driver for specific SPI module
|
#ifdef USE_ETHERNET_SPI // Configure SPI interface and Ethernet driver for specific SPI module
|
||||||
spi_device_interface_config_t devcfg = {
|
spi_device_interface_config_t devcfg = {
|
||||||
.command_bits = 16, // Actually it's the address phase in W5500 SPI frame
|
.command_bits = 0,
|
||||||
.address_bits = 8, // Actually it's the control phase in W5500 SPI frame
|
.address_bits = 0,
|
||||||
.dummy_bits = 0,
|
.dummy_bits = 0,
|
||||||
.mode = 0,
|
.mode = 0,
|
||||||
.duty_cycle_pos = 0,
|
.duty_cycle_pos = 0,
|
||||||
@ -107,22 +107,43 @@ void EthernetComponent::setup() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(host, &devcfg);
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(host, &devcfg);
|
||||||
|
#endif
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||||
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(host, &devcfg);
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
spi_device_handle_t spi_handle = nullptr;
|
spi_device_handle_t spi_handle = nullptr;
|
||||||
err = spi_bus_add_device(host, &devcfg, &spi_handle);
|
err = spi_bus_add_device(host, &devcfg, &spi_handle);
|
||||||
ESPHL_ERROR_CHECK(err, "SPI bus add device error");
|
ESPHL_ERROR_CHECK(err, "SPI bus add device error");
|
||||||
|
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||||
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(spi_handle);
|
||||||
#endif
|
#endif
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||||
|
eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
|
||||||
|
#endif
|
||||||
|
#endif // ESP_IDF_VERSION_MAJOR >= 5
|
||||||
|
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||||
w5500_config.int_gpio_num = this->interrupt_pin_;
|
w5500_config.int_gpio_num = this->interrupt_pin_;
|
||||||
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||||
w5500_config.poll_period_ms = this->polling_interval_;
|
w5500_config.poll_period_ms = this->polling_interval_;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||||
|
dm9051_config.int_gpio_num = this->interrupt_pin_;
|
||||||
|
#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
|
||||||
|
dm9051_config.poll_period_ms = this->polling_interval_;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
phy_config.phy_addr = this->phy_addr_spi_;
|
phy_config.phy_addr = this->phy_addr_spi_;
|
||||||
phy_config.reset_gpio_num = this->reset_pin_;
|
phy_config.reset_gpio_num = this->reset_pin_;
|
||||||
|
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
esp_eth_mac_t *mac = nullptr;
|
||||||
#elif defined(USE_ETHERNET_OPENETH)
|
#elif defined(USE_ETHERNET_OPENETH)
|
||||||
esp_eth_mac_t *mac = esp_eth_mac_new_openeth(&mac_config);
|
esp_eth_mac_t *mac = esp_eth_mac_new_openeth(&mac_config);
|
||||||
#else
|
#else
|
||||||
@ -187,10 +208,20 @@ void EthernetComponent::setup() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ETHERNET_SPI
|
#ifdef USE_ETHERNET_SPI
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_W5500
|
||||||
case ETHERNET_TYPE_W5500: {
|
case ETHERNET_TYPE_W5500: {
|
||||||
|
mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
|
||||||
this->phy_ = esp_eth_phy_new_w5500(&phy_config);
|
this->phy_ = esp_eth_phy_new_w5500(&phy_config);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if CONFIG_ETH_SPI_ETHERNET_DM9051
|
||||||
|
case ETHERNET_TYPE_DM9051: {
|
||||||
|
mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
|
||||||
|
this->phy_ = esp_eth_phy_new_dm9051(&phy_config);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
default: {
|
default: {
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
@ -321,6 +352,10 @@ void EthernetComponent::dump_config() {
|
|||||||
eth_type = "OPENETH";
|
eth_type = "OPENETH";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ETHERNET_TYPE_DM9051:
|
||||||
|
eth_type = "DM9051";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
eth_type = "Unknown";
|
eth_type = "Unknown";
|
||||||
break;
|
break;
|
||||||
|
@ -26,6 +26,7 @@ enum EthernetType : uint8_t {
|
|||||||
ETHERNET_TYPE_KSZ8081RNA,
|
ETHERNET_TYPE_KSZ8081RNA,
|
||||||
ETHERNET_TYPE_W5500,
|
ETHERNET_TYPE_W5500,
|
||||||
ETHERNET_TYPE_OPENETH,
|
ETHERNET_TYPE_OPENETH,
|
||||||
|
ETHERNET_TYPE_DM9051,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ManualIP {
|
struct ManualIP {
|
||||||
|
@ -63,38 +63,105 @@ namespace ld2420 {
|
|||||||
|
|
||||||
static const char *const TAG = "ld2420";
|
static const char *const TAG = "ld2420";
|
||||||
|
|
||||||
float LD2420Component::get_setup_priority() const { return setup_priority::BUS; }
|
// Local const's
|
||||||
|
static const uint16_t REFRESH_RATE_MS = 1000;
|
||||||
|
|
||||||
void LD2420Component::dump_config() {
|
// Command sets
|
||||||
ESP_LOGCONFIG(TAG,
|
static const uint16_t CMD_DISABLE_CONF = 0x00FE;
|
||||||
"LD2420:\n"
|
static const uint16_t CMD_ENABLE_CONF = 0x00FF;
|
||||||
" Firmware version: %7s",
|
static const uint16_t CMD_PARM_HIGH_TRESH = 0x0012;
|
||||||
this->ld2420_firmware_ver_);
|
static const uint16_t CMD_PARM_LOW_TRESH = 0x0021;
|
||||||
#ifdef USE_NUMBER
|
static const uint16_t CMD_PROTOCOL_VER = 0x0002;
|
||||||
ESP_LOGCONFIG(TAG, "Number:");
|
static const uint16_t CMD_READ_ABD_PARAM = 0x0008;
|
||||||
LOG_NUMBER(TAG, " Gate Timeout:", this->gate_timeout_number_);
|
static const uint16_t CMD_READ_REG_ADDR = 0x0020;
|
||||||
LOG_NUMBER(TAG, " Gate Max Distance:", this->max_gate_distance_number_);
|
static const uint16_t CMD_READ_REGISTER = 0x0002;
|
||||||
LOG_NUMBER(TAG, " Gate Min Distance:", this->min_gate_distance_number_);
|
static const uint16_t CMD_READ_SERIAL_NUM = 0x0011;
|
||||||
LOG_NUMBER(TAG, " Gate Select:", this->gate_select_number_);
|
static const uint16_t CMD_READ_SYS_PARAM = 0x0013;
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
static const uint16_t CMD_READ_VERSION = 0x0000;
|
||||||
LOG_NUMBER(TAG, " Gate Move Threshold:", this->gate_move_threshold_numbers_[gate]);
|
static const uint16_t CMD_RESTART = 0x0068;
|
||||||
LOG_NUMBER(TAG, " Gate Still Threshold::", this->gate_still_threshold_numbers_[gate]);
|
static const uint16_t CMD_SYSTEM_MODE = 0x0000;
|
||||||
}
|
static const uint16_t CMD_SYSTEM_MODE_GR = 0x0003;
|
||||||
#endif
|
static const uint16_t CMD_SYSTEM_MODE_MTT = 0x0001;
|
||||||
#ifdef USE_BUTTON
|
static const uint16_t CMD_SYSTEM_MODE_SIMPLE = 0x0064;
|
||||||
LOG_BUTTON(TAG, " Apply Config:", this->apply_config_button_);
|
static const uint16_t CMD_SYSTEM_MODE_DEBUG = 0x0000;
|
||||||
LOG_BUTTON(TAG, " Revert Edits:", this->revert_config_button_);
|
static const uint16_t CMD_SYSTEM_MODE_ENERGY = 0x0004;
|
||||||
LOG_BUTTON(TAG, " Factory Reset:", this->factory_reset_button_);
|
static const uint16_t CMD_SYSTEM_MODE_VS = 0x0002;
|
||||||
LOG_BUTTON(TAG, " Restart Module:", this->restart_module_button_);
|
static const uint16_t CMD_WRITE_ABD_PARAM = 0x0007;
|
||||||
#endif
|
static const uint16_t CMD_WRITE_REGISTER = 0x0001;
|
||||||
ESP_LOGCONFIG(TAG, "Select:");
|
static const uint16_t CMD_WRITE_SYS_PARAM = 0x0012;
|
||||||
LOG_SELECT(TAG, " Operating Mode", this->operating_selector_);
|
|
||||||
if (LD2420Component::get_firmware_int(this->ld2420_firmware_ver_) < CALIBRATE_VERSION_MIN) {
|
static const uint8_t CMD_ABD_DATA_REPLY_SIZE = 0x04;
|
||||||
ESP_LOGW(TAG, "Firmware version %s and older supports Simple Mode only", this->ld2420_firmware_ver_);
|
static const uint8_t CMD_ABD_DATA_REPLY_START = 0x0A;
|
||||||
|
static const uint8_t CMD_MAX_BYTES = 0x64;
|
||||||
|
static const uint8_t CMD_REG_DATA_REPLY_SIZE = 0x02;
|
||||||
|
|
||||||
|
static const uint8_t LD2420_ERROR_NONE = 0x00;
|
||||||
|
static const uint8_t LD2420_ERROR_TIMEOUT = 0x02;
|
||||||
|
static const uint8_t LD2420_ERROR_UNKNOWN = 0x01;
|
||||||
|
|
||||||
|
// Register address values
|
||||||
|
static const uint16_t CMD_MIN_GATE_REG = 0x0000;
|
||||||
|
static const uint16_t CMD_MAX_GATE_REG = 0x0001;
|
||||||
|
static const uint16_t CMD_TIMEOUT_REG = 0x0004;
|
||||||
|
static const uint16_t CMD_GATE_MOVE_THRESH[TOTAL_GATES] = {0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015,
|
||||||
|
0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B,
|
||||||
|
0x001C, 0x001D, 0x001E, 0x001F};
|
||||||
|
static const uint16_t CMD_GATE_STILL_THRESH[TOTAL_GATES] = {0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025,
|
||||||
|
0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B,
|
||||||
|
0x002C, 0x002D, 0x002E, 0x002F};
|
||||||
|
static const uint32_t FACTORY_MOVE_THRESH[TOTAL_GATES] = {60000, 30000, 400, 250, 250, 250, 250, 250,
|
||||||
|
250, 250, 250, 250, 250, 250, 250, 250};
|
||||||
|
static const uint32_t FACTORY_STILL_THRESH[TOTAL_GATES] = {40000, 20000, 200, 200, 200, 200, 200, 150,
|
||||||
|
150, 100, 100, 100, 100, 100, 100, 100};
|
||||||
|
static const uint16_t FACTORY_TIMEOUT = 120;
|
||||||
|
static const uint16_t FACTORY_MIN_GATE = 1;
|
||||||
|
static const uint16_t FACTORY_MAX_GATE = 12;
|
||||||
|
|
||||||
|
// COMMAND_BYTE Header & Footer
|
||||||
|
static const uint32_t CMD_FRAME_FOOTER = 0x01020304;
|
||||||
|
static const uint32_t CMD_FRAME_HEADER = 0xFAFBFCFD;
|
||||||
|
static const uint32_t DEBUG_FRAME_FOOTER = 0xFAFBFCFD;
|
||||||
|
static const uint32_t DEBUG_FRAME_HEADER = 0x1410BFAA;
|
||||||
|
static const uint32_t ENERGY_FRAME_FOOTER = 0xF5F6F7F8;
|
||||||
|
static const uint32_t ENERGY_FRAME_HEADER = 0xF1F2F3F4;
|
||||||
|
static const int CALIBRATE_VERSION_MIN = 154;
|
||||||
|
static const uint8_t CMD_FRAME_COMMAND = 6;
|
||||||
|
static const uint8_t CMD_FRAME_DATA_LENGTH = 4;
|
||||||
|
static const uint8_t CMD_FRAME_STATUS = 7;
|
||||||
|
static const uint8_t CMD_ERROR_WORD = 8;
|
||||||
|
static const uint8_t ENERGY_SENSOR_START = 9;
|
||||||
|
static const uint8_t CALIBRATE_REPORT_INTERVAL = 4;
|
||||||
|
static const std::string OP_NORMAL_MODE_STRING = "Normal";
|
||||||
|
static const std::string OP_SIMPLE_MODE_STRING = "Simple";
|
||||||
|
|
||||||
|
// Memory-efficient lookup tables
|
||||||
|
struct StringToUint8 {
|
||||||
|
const char *str;
|
||||||
|
uint8_t value;
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr StringToUint8 OP_MODE_BY_STR[] = {
|
||||||
|
{"Normal", OP_NORMAL_MODE},
|
||||||
|
{"Calibrate", OP_CALIBRATE_MODE},
|
||||||
|
{"Simple", OP_SIMPLE_MODE},
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr const char *ERR_MESSAGE[] = {
|
||||||
|
"None",
|
||||||
|
"Unknown",
|
||||||
|
"Timeout",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper function for lookups
|
||||||
|
template<size_t N> uint8_t find_uint8(const StringToUint8 (&arr)[N], const std::string &str) {
|
||||||
|
for (const auto &entry : arr) {
|
||||||
|
if (str == entry.str)
|
||||||
|
return entry.value;
|
||||||
}
|
}
|
||||||
|
return 0xFF; // Not found
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t LD2420Component::calc_checksum(void *data, size_t size) {
|
static uint8_t calc_checksum(void *data, size_t size) {
|
||||||
uint8_t checksum = 0;
|
uint8_t checksum = 0;
|
||||||
uint8_t *data_bytes = (uint8_t *) data;
|
uint8_t *data_bytes = (uint8_t *) data;
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
@ -103,7 +170,7 @@ uint8_t LD2420Component::calc_checksum(void *data, size_t size) {
|
|||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LD2420Component::get_firmware_int(const char *version_string) {
|
static int get_firmware_int(const char *version_string) {
|
||||||
std::string version_str = version_string;
|
std::string version_str = version_string;
|
||||||
if (version_str[0] == 'v') {
|
if (version_str[0] == 'v') {
|
||||||
version_str = version_str.substr(1);
|
version_str = version_str.substr(1);
|
||||||
@ -113,6 +180,37 @@ int LD2420Component::get_firmware_int(const char *version_string) {
|
|||||||
return version_integer;
|
return version_integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float LD2420Component::get_setup_priority() const { return setup_priority::BUS; }
|
||||||
|
|
||||||
|
void LD2420Component::dump_config() {
|
||||||
|
ESP_LOGCONFIG(TAG,
|
||||||
|
"LD2420:\n"
|
||||||
|
" Firmware version: %7s",
|
||||||
|
this->firmware_ver_);
|
||||||
|
#ifdef USE_NUMBER
|
||||||
|
ESP_LOGCONFIG(TAG, "Number:");
|
||||||
|
LOG_NUMBER(" ", "Gate Timeout:", this->gate_timeout_number_);
|
||||||
|
LOG_NUMBER(" ", "Gate Max Distance:", this->max_gate_distance_number_);
|
||||||
|
LOG_NUMBER(" ", "Gate Min Distance:", this->min_gate_distance_number_);
|
||||||
|
LOG_NUMBER(" ", "Gate Select:", this->gate_select_number_);
|
||||||
|
for (uint8_t gate = 0; gate < TOTAL_GATES; gate++) {
|
||||||
|
LOG_NUMBER(" ", "Gate Move Threshold:", this->gate_move_threshold_numbers_[gate]);
|
||||||
|
LOG_NUMBER(" ", "Gate Still Threshold::", this->gate_still_threshold_numbers_[gate]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_BUTTON
|
||||||
|
LOG_BUTTON(" ", "Apply Config:", this->apply_config_button_);
|
||||||
|
LOG_BUTTON(" ", "Revert Edits:", this->revert_config_button_);
|
||||||
|
LOG_BUTTON(" ", "Factory Reset:", this->factory_reset_button_);
|
||||||
|
LOG_BUTTON(" ", "Restart Module:", this->restart_module_button_);
|
||||||
|
#endif
|
||||||
|
ESP_LOGCONFIG(TAG, "Select:");
|
||||||
|
LOG_SELECT(" ", "Operating Mode", this->operating_selector_);
|
||||||
|
if (ld2420::get_firmware_int(this->firmware_ver_) < CALIBRATE_VERSION_MIN) {
|
||||||
|
ESP_LOGW(TAG, "Firmware version %s and older supports Simple Mode only", this->firmware_ver_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LD2420Component::setup() {
|
void LD2420Component::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Running setup");
|
ESP_LOGCONFIG(TAG, "Running setup");
|
||||||
if (this->set_config_mode(true) == LD2420_ERROR_TIMEOUT) {
|
if (this->set_config_mode(true) == LD2420_ERROR_TIMEOUT) {
|
||||||
@ -125,24 +223,24 @@ void LD2420Component::setup() {
|
|||||||
this->init_gate_config_numbers();
|
this->init_gate_config_numbers();
|
||||||
#endif
|
#endif
|
||||||
this->get_firmware_version_();
|
this->get_firmware_version_();
|
||||||
const char *pfw = this->ld2420_firmware_ver_;
|
const char *pfw = this->firmware_ver_;
|
||||||
std::string fw_str(pfw);
|
std::string fw_str(pfw);
|
||||||
|
|
||||||
for (auto &listener : this->listeners_) {
|
for (auto &listener : this->listeners_) {
|
||||||
listener->on_fw_version(fw_str);
|
listener->on_fw_version(fw_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; gate++) {
|
||||||
delay_microseconds_safe(125);
|
delay_microseconds_safe(125);
|
||||||
this->get_gate_threshold_(gate);
|
this->get_gate_threshold_(gate);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&this->new_config, &this->current_config, sizeof(this->current_config));
|
memcpy(&this->new_config, &this->current_config, sizeof(this->current_config));
|
||||||
if (LD2420Component::get_firmware_int(this->ld2420_firmware_ver_) < CALIBRATE_VERSION_MIN) {
|
if (ld2420::get_firmware_int(this->firmware_ver_) < CALIBRATE_VERSION_MIN) {
|
||||||
this->set_operating_mode(OP_SIMPLE_MODE_STRING);
|
this->set_operating_mode(OP_SIMPLE_MODE_STRING);
|
||||||
this->operating_selector_->publish_state(OP_SIMPLE_MODE_STRING);
|
this->operating_selector_->publish_state(OP_SIMPLE_MODE_STRING);
|
||||||
this->set_mode_(CMD_SYSTEM_MODE_SIMPLE);
|
this->set_mode_(CMD_SYSTEM_MODE_SIMPLE);
|
||||||
ESP_LOGW(TAG, "Firmware version %s and older supports Simple Mode only", this->ld2420_firmware_ver_);
|
ESP_LOGW(TAG, "Firmware version %s and older supports Simple Mode only", this->firmware_ver_);
|
||||||
} else {
|
} else {
|
||||||
this->set_mode_(CMD_SYSTEM_MODE_ENERGY);
|
this->set_mode_(CMD_SYSTEM_MODE_ENERGY);
|
||||||
this->operating_selector_->publish_state(OP_NORMAL_MODE_STRING);
|
this->operating_selector_->publish_state(OP_NORMAL_MODE_STRING);
|
||||||
@ -167,7 +265,7 @@ void LD2420Component::apply_config_action() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->set_min_max_distances_timeout(this->new_config.max_gate, this->new_config.min_gate, this->new_config.timeout);
|
this->set_min_max_distances_timeout(this->new_config.max_gate, this->new_config.min_gate, this->new_config.timeout);
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; gate++) {
|
||||||
delay_microseconds_safe(125);
|
delay_microseconds_safe(125);
|
||||||
this->set_gate_threshold(gate);
|
this->set_gate_threshold(gate);
|
||||||
}
|
}
|
||||||
@ -193,7 +291,7 @@ void LD2420Component::factory_reset_action() {
|
|||||||
this->min_gate_distance_number_->state = FACTORY_MIN_GATE;
|
this->min_gate_distance_number_->state = FACTORY_MIN_GATE;
|
||||||
this->max_gate_distance_number_->state = FACTORY_MAX_GATE;
|
this->max_gate_distance_number_->state = FACTORY_MAX_GATE;
|
||||||
#endif
|
#endif
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; gate++) {
|
||||||
this->new_config.move_thresh[gate] = FACTORY_MOVE_THRESH[gate];
|
this->new_config.move_thresh[gate] = FACTORY_MOVE_THRESH[gate];
|
||||||
this->new_config.still_thresh[gate] = FACTORY_STILL_THRESH[gate];
|
this->new_config.still_thresh[gate] = FACTORY_STILL_THRESH[gate];
|
||||||
delay_microseconds_safe(125);
|
delay_microseconds_safe(125);
|
||||||
@ -241,7 +339,7 @@ void LD2420Component::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LD2420Component::update_radar_data(uint16_t const *gate_energy, uint8_t sample_number) {
|
void LD2420Component::update_radar_data(uint16_t const *gate_energy, uint8_t sample_number) {
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; ++gate) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; ++gate) {
|
||||||
this->radar_data[gate][sample_number] = gate_energy[gate];
|
this->radar_data[gate][sample_number] = gate_energy[gate];
|
||||||
}
|
}
|
||||||
this->total_sample_number_counter++;
|
this->total_sample_number_counter++;
|
||||||
@ -251,7 +349,7 @@ void LD2420Component::auto_calibrate_sensitivity() {
|
|||||||
// Calculate average and peak values for each gate
|
// Calculate average and peak values for each gate
|
||||||
const float move_factor = gate_move_sensitivity_factor + 1;
|
const float move_factor = gate_move_sensitivity_factor + 1;
|
||||||
const float still_factor = (gate_still_sensitivity_factor / 2) + 1;
|
const float still_factor = (gate_still_sensitivity_factor / 2) + 1;
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; ++gate) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; ++gate) {
|
||||||
uint32_t sum = 0;
|
uint32_t sum = 0;
|
||||||
uint16_t peak = 0;
|
uint16_t peak = 0;
|
||||||
|
|
||||||
@ -280,7 +378,7 @@ void LD2420Component::auto_calibrate_sensitivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LD2420Component::report_gate_data() {
|
void LD2420Component::report_gate_data() {
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; ++gate) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; ++gate) {
|
||||||
// Output results
|
// Output results
|
||||||
ESP_LOGI(TAG, "Gate: %2d Avg: %5d Peak: %5d", gate, this->gate_avg[gate], this->gate_peak[gate]);
|
ESP_LOGI(TAG, "Gate: %2d Avg: %5d Peak: %5d", gate, this->gate_avg[gate], this->gate_peak[gate]);
|
||||||
}
|
}
|
||||||
@ -289,13 +387,13 @@ void LD2420Component::report_gate_data() {
|
|||||||
|
|
||||||
void LD2420Component::set_operating_mode(const std::string &state) {
|
void LD2420Component::set_operating_mode(const std::string &state) {
|
||||||
// If unsupported firmware ignore mode select
|
// If unsupported firmware ignore mode select
|
||||||
if (LD2420Component::get_firmware_int(ld2420_firmware_ver_) >= CALIBRATE_VERSION_MIN) {
|
if (ld2420::get_firmware_int(firmware_ver_) >= CALIBRATE_VERSION_MIN) {
|
||||||
this->current_operating_mode = OP_MODE_TO_UINT.at(state);
|
this->current_operating_mode = find_uint8(OP_MODE_BY_STR, state);
|
||||||
// Entering Auto Calibrate we need to clear the privoiuos data collection
|
// Entering Auto Calibrate we need to clear the privoiuos data collection
|
||||||
this->operating_selector_->publish_state(state);
|
this->operating_selector_->publish_state(state);
|
||||||
if (current_operating_mode == OP_CALIBRATE_MODE) {
|
if (current_operating_mode == OP_CALIBRATE_MODE) {
|
||||||
this->set_calibration_(true);
|
this->set_calibration_(true);
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; gate++) {
|
||||||
this->gate_avg[gate] = 0;
|
this->gate_avg[gate] = 0;
|
||||||
this->gate_peak[gate] = 0;
|
this->gate_peak[gate] = 0;
|
||||||
for (uint8_t i = 0; i < CALIBRATE_SAMPLES; i++) {
|
for (uint8_t i = 0; i < CALIBRATE_SAMPLES; i++) {
|
||||||
@ -330,11 +428,12 @@ void LD2420Component::readline_(int rx_data, uint8_t *buffer, int len) {
|
|||||||
this->set_cmd_active_(false); // Set command state to inactive after responce.
|
this->set_cmd_active_(false); // Set command state to inactive after responce.
|
||||||
this->handle_ack_data_(buffer, pos);
|
this->handle_ack_data_(buffer, pos);
|
||||||
pos = 0;
|
pos = 0;
|
||||||
} else if ((buffer[pos - 2] == 0x0D && buffer[pos - 1] == 0x0A) && (get_mode_() == CMD_SYSTEM_MODE_SIMPLE)) {
|
} else if ((buffer[pos - 2] == 0x0D && buffer[pos - 1] == 0x0A) &&
|
||||||
|
(this->get_mode_() == CMD_SYSTEM_MODE_SIMPLE)) {
|
||||||
this->handle_simple_mode_(buffer, pos);
|
this->handle_simple_mode_(buffer, pos);
|
||||||
pos = 0;
|
pos = 0;
|
||||||
} else if ((memcmp(&buffer[pos - 4], &ENERGY_FRAME_FOOTER, sizeof(ENERGY_FRAME_FOOTER)) == 0) &&
|
} else if ((memcmp(&buffer[pos - 4], &ENERGY_FRAME_FOOTER, sizeof(ENERGY_FRAME_FOOTER)) == 0) &&
|
||||||
(get_mode_() == CMD_SYSTEM_MODE_ENERGY)) {
|
(this->get_mode_() == CMD_SYSTEM_MODE_ENERGY)) {
|
||||||
this->handle_energy_mode_(buffer, pos);
|
this->handle_energy_mode_(buffer, pos);
|
||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
@ -483,8 +582,8 @@ void LD2420Component::handle_ack_data_(uint8_t *buffer, int len) {
|
|||||||
ESP_LOGV(TAG, "Set system parameter(s): %2X %s", CMD_WRITE_SYS_PARAM, result);
|
ESP_LOGV(TAG, "Set system parameter(s): %2X %s", CMD_WRITE_SYS_PARAM, result);
|
||||||
break;
|
break;
|
||||||
case (CMD_READ_VERSION):
|
case (CMD_READ_VERSION):
|
||||||
memcpy(this->ld2420_firmware_ver_, &buffer[12], buffer[10]);
|
memcpy(this->firmware_ver_, &buffer[12], buffer[10]);
|
||||||
ESP_LOGV(TAG, "Firmware version: %7s %s", this->ld2420_firmware_ver_, result);
|
ESP_LOGV(TAG, "Firmware version: %7s %s", this->firmware_ver_, result);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -753,7 +852,7 @@ void LD2420Component::init_gate_config_numbers() {
|
|||||||
this->gate_move_sensitivity_factor_number_->publish_state(this->gate_move_sensitivity_factor);
|
this->gate_move_sensitivity_factor_number_->publish_state(this->gate_move_sensitivity_factor);
|
||||||
if (this->gate_still_sensitivity_factor_number_ != nullptr)
|
if (this->gate_still_sensitivity_factor_number_ != nullptr)
|
||||||
this->gate_still_sensitivity_factor_number_->publish_state(this->gate_still_sensitivity_factor);
|
this->gate_still_sensitivity_factor_number_->publish_state(this->gate_still_sensitivity_factor);
|
||||||
for (uint8_t gate = 0; gate < LD2420_TOTAL_GATES; gate++) {
|
for (uint8_t gate = 0; gate < TOTAL_GATES; gate++) {
|
||||||
if (this->gate_still_threshold_numbers_[gate] != nullptr) {
|
if (this->gate_still_threshold_numbers_[gate] != nullptr) {
|
||||||
this->gate_still_threshold_numbers_[gate]->publish_state(
|
this->gate_still_threshold_numbers_[gate]->publish_state(
|
||||||
static_cast<uint16_t>(this->current_config.still_thresh[gate]));
|
static_cast<uint16_t>(this->current_config.still_thresh[gate]));
|
||||||
|
@ -16,88 +16,18 @@
|
|||||||
#ifdef USE_BUTTON
|
#ifdef USE_BUTTON
|
||||||
#include "esphome/components/button/button.h"
|
#include "esphome/components/button/button.h"
|
||||||
#endif
|
#endif
|
||||||
#include <map>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ld2420 {
|
namespace ld2420 {
|
||||||
|
|
||||||
// Local const's
|
static const uint8_t TOTAL_GATES = 16;
|
||||||
static const uint16_t REFRESH_RATE_MS = 1000;
|
|
||||||
|
|
||||||
// Command sets
|
|
||||||
static const uint8_t CMD_ABD_DATA_REPLY_SIZE = 0x04;
|
|
||||||
static const uint8_t CMD_ABD_DATA_REPLY_START = 0x0A;
|
|
||||||
static const uint16_t CMD_DISABLE_CONF = 0x00FE;
|
|
||||||
static const uint16_t CMD_ENABLE_CONF = 0x00FF;
|
|
||||||
static const uint8_t CMD_MAX_BYTES = 0x64;
|
|
||||||
static const uint16_t CMD_PARM_HIGH_TRESH = 0x0012;
|
|
||||||
static const uint16_t CMD_PARM_LOW_TRESH = 0x0021;
|
|
||||||
static const uint16_t CMD_PROTOCOL_VER = 0x0002;
|
|
||||||
static const uint16_t CMD_READ_ABD_PARAM = 0x0008;
|
|
||||||
static const uint16_t CMD_READ_REG_ADDR = 0x0020;
|
|
||||||
static const uint16_t CMD_READ_REGISTER = 0x0002;
|
|
||||||
static const uint16_t CMD_READ_SERIAL_NUM = 0x0011;
|
|
||||||
static const uint16_t CMD_READ_SYS_PARAM = 0x0013;
|
|
||||||
static const uint16_t CMD_READ_VERSION = 0x0000;
|
|
||||||
static const uint8_t CMD_REG_DATA_REPLY_SIZE = 0x02;
|
|
||||||
static const uint16_t CMD_RESTART = 0x0068;
|
|
||||||
static const uint16_t CMD_SYSTEM_MODE = 0x0000;
|
|
||||||
static const uint16_t CMD_SYSTEM_MODE_GR = 0x0003;
|
|
||||||
static const uint16_t CMD_SYSTEM_MODE_MTT = 0x0001;
|
|
||||||
static const uint16_t CMD_SYSTEM_MODE_SIMPLE = 0x0064;
|
|
||||||
static const uint16_t CMD_SYSTEM_MODE_DEBUG = 0x0000;
|
|
||||||
static const uint16_t CMD_SYSTEM_MODE_ENERGY = 0x0004;
|
|
||||||
static const uint16_t CMD_SYSTEM_MODE_VS = 0x0002;
|
|
||||||
static const uint16_t CMD_WRITE_ABD_PARAM = 0x0007;
|
|
||||||
static const uint16_t CMD_WRITE_REGISTER = 0x0001;
|
|
||||||
static const uint16_t CMD_WRITE_SYS_PARAM = 0x0012;
|
|
||||||
|
|
||||||
static const uint8_t LD2420_ERROR_NONE = 0x00;
|
|
||||||
static const uint8_t LD2420_ERROR_TIMEOUT = 0x02;
|
|
||||||
static const uint8_t LD2420_ERROR_UNKNOWN = 0x01;
|
|
||||||
static const uint8_t LD2420_TOTAL_GATES = 16;
|
|
||||||
static const uint8_t CALIBRATE_SAMPLES = 64;
|
static const uint8_t CALIBRATE_SAMPLES = 64;
|
||||||
|
|
||||||
// Register address values
|
enum OpMode : uint8_t {
|
||||||
static const uint16_t CMD_MIN_GATE_REG = 0x0000;
|
OP_NORMAL_MODE = 1,
|
||||||
static const uint16_t CMD_MAX_GATE_REG = 0x0001;
|
OP_CALIBRATE_MODE = 2,
|
||||||
static const uint16_t CMD_TIMEOUT_REG = 0x0004;
|
OP_SIMPLE_MODE = 3,
|
||||||
static const uint16_t CMD_GATE_MOVE_THRESH[LD2420_TOTAL_GATES] = {0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015,
|
};
|
||||||
0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B,
|
|
||||||
0x001C, 0x001D, 0x001E, 0x001F};
|
|
||||||
static const uint16_t CMD_GATE_STILL_THRESH[LD2420_TOTAL_GATES] = {0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025,
|
|
||||||
0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B,
|
|
||||||
0x002C, 0x002D, 0x002E, 0x002F};
|
|
||||||
static const uint32_t FACTORY_MOVE_THRESH[LD2420_TOTAL_GATES] = {60000, 30000, 400, 250, 250, 250, 250, 250,
|
|
||||||
250, 250, 250, 250, 250, 250, 250, 250};
|
|
||||||
static const uint32_t FACTORY_STILL_THRESH[LD2420_TOTAL_GATES] = {40000, 20000, 200, 200, 200, 200, 200, 150,
|
|
||||||
150, 100, 100, 100, 100, 100, 100, 100};
|
|
||||||
static const uint16_t FACTORY_TIMEOUT = 120;
|
|
||||||
static const uint16_t FACTORY_MIN_GATE = 1;
|
|
||||||
static const uint16_t FACTORY_MAX_GATE = 12;
|
|
||||||
|
|
||||||
// COMMAND_BYTE Header & Footer
|
|
||||||
static const uint8_t CMD_FRAME_COMMAND = 6;
|
|
||||||
static const uint8_t CMD_FRAME_DATA_LENGTH = 4;
|
|
||||||
static const uint32_t CMD_FRAME_FOOTER = 0x01020304;
|
|
||||||
static const uint32_t CMD_FRAME_HEADER = 0xFAFBFCFD;
|
|
||||||
static const uint32_t DEBUG_FRAME_FOOTER = 0xFAFBFCFD;
|
|
||||||
static const uint32_t DEBUG_FRAME_HEADER = 0x1410BFAA;
|
|
||||||
static const uint32_t ENERGY_FRAME_FOOTER = 0xF5F6F7F8;
|
|
||||||
static const uint32_t ENERGY_FRAME_HEADER = 0xF1F2F3F4;
|
|
||||||
static const uint8_t CMD_FRAME_STATUS = 7;
|
|
||||||
static const uint8_t CMD_ERROR_WORD = 8;
|
|
||||||
static const uint8_t ENERGY_SENSOR_START = 9;
|
|
||||||
static const uint8_t CALIBRATE_REPORT_INTERVAL = 4;
|
|
||||||
static const int CALIBRATE_VERSION_MIN = 154;
|
|
||||||
static const std::string OP_NORMAL_MODE_STRING = "Normal";
|
|
||||||
static const std::string OP_SIMPLE_MODE_STRING = "Simple";
|
|
||||||
|
|
||||||
enum OpModeStruct : uint8_t { OP_NORMAL_MODE = 1, OP_CALIBRATE_MODE = 2, OP_SIMPLE_MODE = 3 };
|
|
||||||
static const std::map<std::string, uint8_t> OP_MODE_TO_UINT{
|
|
||||||
{"Normal", OP_NORMAL_MODE}, {"Calibrate", OP_CALIBRATE_MODE}, {"Simple", OP_SIMPLE_MODE}};
|
|
||||||
static constexpr const char *ERR_MESSAGE[] = {"None", "Unknown", "Timeout"};
|
|
||||||
|
|
||||||
class LD2420Listener {
|
class LD2420Listener {
|
||||||
public:
|
public:
|
||||||
@ -109,6 +39,23 @@ class LD2420Listener {
|
|||||||
|
|
||||||
class LD2420Component : public Component, public uart::UARTDevice {
|
class LD2420Component : public Component, public uart::UARTDevice {
|
||||||
public:
|
public:
|
||||||
|
struct CmdFrameT {
|
||||||
|
uint32_t header{0};
|
||||||
|
uint32_t footer{0};
|
||||||
|
uint16_t length{0};
|
||||||
|
uint16_t command{0};
|
||||||
|
uint16_t data_length{0};
|
||||||
|
uint8_t data[18];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RegConfigT {
|
||||||
|
uint32_t move_thresh[TOTAL_GATES];
|
||||||
|
uint32_t still_thresh[TOTAL_GATES];
|
||||||
|
uint16_t min_gate{0};
|
||||||
|
uint16_t max_gate{0};
|
||||||
|
uint16_t timeout{0};
|
||||||
|
};
|
||||||
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
void loop() override;
|
void loop() override;
|
||||||
@ -150,23 +97,6 @@ class LD2420Component : public Component, public uart::UARTDevice {
|
|||||||
#endif
|
#endif
|
||||||
void register_listener(LD2420Listener *listener) { this->listeners_.push_back(listener); }
|
void register_listener(LD2420Listener *listener) { this->listeners_.push_back(listener); }
|
||||||
|
|
||||||
struct CmdFrameT {
|
|
||||||
uint32_t header{0};
|
|
||||||
uint16_t length{0};
|
|
||||||
uint16_t command{0};
|
|
||||||
uint8_t data[18];
|
|
||||||
uint16_t data_length{0};
|
|
||||||
uint32_t footer{0};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RegConfigT {
|
|
||||||
uint16_t min_gate{0};
|
|
||||||
uint16_t max_gate{0};
|
|
||||||
uint16_t timeout{0};
|
|
||||||
uint32_t move_thresh[LD2420_TOTAL_GATES];
|
|
||||||
uint32_t still_thresh[LD2420_TOTAL_GATES];
|
|
||||||
};
|
|
||||||
|
|
||||||
void send_module_restart();
|
void send_module_restart();
|
||||||
void restart_module_action();
|
void restart_module_action();
|
||||||
void apply_config_action();
|
void apply_config_action();
|
||||||
@ -179,23 +109,28 @@ class LD2420Component : public Component, public uart::UARTDevice {
|
|||||||
void set_operating_mode(const std::string &state);
|
void set_operating_mode(const std::string &state);
|
||||||
void auto_calibrate_sensitivity();
|
void auto_calibrate_sensitivity();
|
||||||
void update_radar_data(uint16_t const *gate_energy, uint8_t sample_number);
|
void update_radar_data(uint16_t const *gate_energy, uint8_t sample_number);
|
||||||
static uint8_t calc_checksum(void *data, size_t size);
|
uint8_t set_config_mode(bool enable);
|
||||||
|
void set_min_max_distances_timeout(uint32_t max_gate_distance, uint32_t min_gate_distance, uint32_t timeout);
|
||||||
|
void set_gate_threshold(uint8_t gate);
|
||||||
|
void set_reg_value(uint16_t reg, uint16_t value);
|
||||||
|
void set_system_mode(uint16_t mode);
|
||||||
|
void ld2420_restart();
|
||||||
|
|
||||||
RegConfigT current_config;
|
float gate_move_sensitivity_factor{0.5};
|
||||||
RegConfigT new_config;
|
float gate_still_sensitivity_factor{0.5};
|
||||||
int32_t last_periodic_millis = millis();
|
int32_t last_periodic_millis = millis();
|
||||||
int32_t report_periodic_millis = millis();
|
int32_t report_periodic_millis = millis();
|
||||||
int32_t monitor_periodic_millis = millis();
|
int32_t monitor_periodic_millis = millis();
|
||||||
int32_t last_normal_periodic_millis = millis();
|
int32_t last_normal_periodic_millis = millis();
|
||||||
bool output_energy_state{false};
|
uint16_t radar_data[TOTAL_GATES][CALIBRATE_SAMPLES];
|
||||||
uint8_t current_operating_mode{OP_NORMAL_MODE};
|
uint16_t gate_avg[TOTAL_GATES];
|
||||||
uint16_t radar_data[LD2420_TOTAL_GATES][CALIBRATE_SAMPLES];
|
uint16_t gate_peak[TOTAL_GATES];
|
||||||
uint16_t gate_avg[LD2420_TOTAL_GATES];
|
|
||||||
uint16_t gate_peak[LD2420_TOTAL_GATES];
|
|
||||||
uint8_t sample_number_counter{0};
|
|
||||||
uint16_t total_sample_number_counter{0};
|
uint16_t total_sample_number_counter{0};
|
||||||
float gate_move_sensitivity_factor{0.5};
|
uint8_t current_operating_mode{OP_NORMAL_MODE};
|
||||||
float gate_still_sensitivity_factor{0.5};
|
uint8_t sample_number_counter{0};
|
||||||
|
bool output_energy_state{false};
|
||||||
|
RegConfigT current_config;
|
||||||
|
RegConfigT new_config;
|
||||||
#ifdef USE_SELECT
|
#ifdef USE_SELECT
|
||||||
select::Select *operating_selector_{nullptr};
|
select::Select *operating_selector_{nullptr};
|
||||||
#endif
|
#endif
|
||||||
@ -205,24 +140,17 @@ class LD2420Component : public Component, public uart::UARTDevice {
|
|||||||
button::Button *restart_module_button_{nullptr};
|
button::Button *restart_module_button_{nullptr};
|
||||||
button::Button *factory_reset_button_{nullptr};
|
button::Button *factory_reset_button_{nullptr};
|
||||||
#endif
|
#endif
|
||||||
void set_min_max_distances_timeout(uint32_t max_gate_distance, uint32_t min_gate_distance, uint32_t timeout);
|
|
||||||
void set_gate_threshold(uint8_t gate);
|
|
||||||
void set_reg_value(uint16_t reg, uint16_t value);
|
|
||||||
uint8_t set_config_mode(bool enable);
|
|
||||||
void set_system_mode(uint16_t mode);
|
|
||||||
void ld2420_restart();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct CmdReplyT {
|
struct CmdReplyT {
|
||||||
|
uint32_t data[4];
|
||||||
|
uint16_t error;
|
||||||
uint8_t command;
|
uint8_t command;
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint32_t data[4];
|
|
||||||
uint8_t length;
|
uint8_t length;
|
||||||
uint16_t error;
|
|
||||||
volatile bool ack;
|
volatile bool ack;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int get_firmware_int(const char *version_string);
|
|
||||||
void get_firmware_version_();
|
void get_firmware_version_();
|
||||||
int get_gate_threshold_(uint8_t gate);
|
int get_gate_threshold_(uint8_t gate);
|
||||||
void get_reg_value_(uint16_t reg);
|
void get_reg_value_(uint16_t reg);
|
||||||
@ -253,17 +181,17 @@ class LD2420Component : public Component, public uart::UARTDevice {
|
|||||||
std::vector<number::Number *> gate_move_threshold_numbers_ = std::vector<number::Number *>(16);
|
std::vector<number::Number *> gate_move_threshold_numbers_ = std::vector<number::Number *>(16);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint16_t gate_energy_[LD2420_TOTAL_GATES];
|
|
||||||
CmdReplyT cmd_reply_;
|
|
||||||
uint32_t max_distance_gate_;
|
uint32_t max_distance_gate_;
|
||||||
uint32_t min_distance_gate_;
|
uint32_t min_distance_gate_;
|
||||||
uint16_t system_mode_{CMD_SYSTEM_MODE_ENERGY};
|
uint16_t system_mode_;
|
||||||
bool cmd_active_{false};
|
uint16_t gate_energy_[TOTAL_GATES];
|
||||||
char ld2420_firmware_ver_[8]{"v0.0.0"};
|
|
||||||
bool presence_{false};
|
|
||||||
bool calibration_{false};
|
|
||||||
uint16_t distance_{0};
|
uint16_t distance_{0};
|
||||||
uint8_t config_checksum_{0};
|
uint8_t config_checksum_{0};
|
||||||
|
char firmware_ver_[8]{"v0.0.0"};
|
||||||
|
bool cmd_active_{false};
|
||||||
|
bool presence_{false};
|
||||||
|
bool calibration_{false};
|
||||||
|
CmdReplyT cmd_reply_;
|
||||||
std::vector<LD2420Listener *> listeners_{};
|
std::vector<LD2420Listener *> listeners_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class LD2420Sensor : public LD2420Listener, public Component, sensor::Sensor {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
sensor::Sensor *distance_sensor_{nullptr};
|
sensor::Sensor *distance_sensor_{nullptr};
|
||||||
std::vector<sensor::Sensor *> energy_sensors_ = std::vector<sensor::Sensor *>(LD2420_TOTAL_GATES);
|
std::vector<sensor::Sensor *> energy_sensors_ = std::vector<sensor::Sensor *>(TOTAL_GATES);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ld2420
|
} // namespace ld2420
|
||||||
|
@ -86,16 +86,16 @@ class LightColorValues {
|
|||||||
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion) {
|
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion) {
|
||||||
LightColorValues v;
|
LightColorValues v;
|
||||||
v.set_color_mode(end.color_mode_);
|
v.set_color_mode(end.color_mode_);
|
||||||
v.set_state(esphome::lerp(completion, start.get_state(), end.get_state()));
|
v.set_state(std::lerp(start.get_state(), end.get_state(), completion));
|
||||||
v.set_brightness(esphome::lerp(completion, start.get_brightness(), end.get_brightness()));
|
v.set_brightness(std::lerp(start.get_brightness(), end.get_brightness(), completion));
|
||||||
v.set_color_brightness(esphome::lerp(completion, start.get_color_brightness(), end.get_color_brightness()));
|
v.set_color_brightness(std::lerp(start.get_color_brightness(), end.get_color_brightness(), completion));
|
||||||
v.set_red(esphome::lerp(completion, start.get_red(), end.get_red()));
|
v.set_red(std::lerp(start.get_red(), end.get_red(), completion));
|
||||||
v.set_green(esphome::lerp(completion, start.get_green(), end.get_green()));
|
v.set_green(std::lerp(start.get_green(), end.get_green(), completion));
|
||||||
v.set_blue(esphome::lerp(completion, start.get_blue(), end.get_blue()));
|
v.set_blue(std::lerp(start.get_blue(), end.get_blue(), completion));
|
||||||
v.set_white(esphome::lerp(completion, start.get_white(), end.get_white()));
|
v.set_white(std::lerp(start.get_white(), end.get_white(), completion));
|
||||||
v.set_color_temperature(esphome::lerp(completion, start.get_color_temperature(), end.get_color_temperature()));
|
v.set_color_temperature(std::lerp(start.get_color_temperature(), end.get_color_temperature(), completion));
|
||||||
v.set_cold_white(esphome::lerp(completion, start.get_cold_white(), end.get_cold_white()));
|
v.set_cold_white(std::lerp(start.get_cold_white(), end.get_cold_white(), completion));
|
||||||
v.set_warm_white(esphome::lerp(completion, start.get_warm_white(), end.get_warm_white()));
|
v.set_warm_white(std::lerp(start.get_warm_white(), end.get_warm_white(), completion));
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ RemoteReceiverBinarySensorBase = ns.class_(
|
|||||||
RemoteReceiverTrigger = ns.class_(
|
RemoteReceiverTrigger = ns.class_(
|
||||||
"RemoteReceiverTrigger", automation.Trigger, RemoteReceiverListener
|
"RemoteReceiverTrigger", automation.Trigger, RemoteReceiverListener
|
||||||
)
|
)
|
||||||
RemoteTransmitterDumper = ns.class_("RemoteTransmitterDumper")
|
RemoteReceiverDumperBase = ns.class_("RemoteReceiverDumperBase")
|
||||||
RemoteTransmittable = ns.class_("RemoteTransmittable")
|
RemoteTransmittable = ns.class_("RemoteTransmittable")
|
||||||
RemoteTransmitterActionBase = ns.class_(
|
RemoteTransmitterActionBase = ns.class_(
|
||||||
"RemoteTransmitterActionBase", RemoteTransmittable, automation.Action
|
"RemoteTransmitterActionBase", RemoteTransmittable, automation.Action
|
||||||
@ -126,8 +126,10 @@ def register_trigger(name, type, data_type):
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
def register_dumper(name, type):
|
def register_dumper(name, type, schema=None):
|
||||||
registerer = DUMPER_REGISTRY.register(name, type, {})
|
if schema is None:
|
||||||
|
schema = {}
|
||||||
|
registerer = DUMPER_REGISTRY.register(name, type, schema)
|
||||||
|
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
async def new_func(config, dumper_id):
|
async def new_func(config, dumper_id):
|
||||||
@ -189,7 +191,7 @@ def declare_protocol(name):
|
|||||||
binary_sensor_ = ns.class_(f"{name}BinarySensor", RemoteReceiverBinarySensorBase)
|
binary_sensor_ = ns.class_(f"{name}BinarySensor", RemoteReceiverBinarySensorBase)
|
||||||
trigger = ns.class_(f"{name}Trigger", RemoteReceiverTrigger)
|
trigger = ns.class_(f"{name}Trigger", RemoteReceiverTrigger)
|
||||||
action = ns.class_(f"{name}Action", RemoteTransmitterActionBase)
|
action = ns.class_(f"{name}Action", RemoteTransmitterActionBase)
|
||||||
dumper = ns.class_(f"{name}Dumper", RemoteTransmitterDumper)
|
dumper = ns.class_(f"{name}Dumper", RemoteReceiverDumperBase)
|
||||||
return data, binary_sensor_, trigger, action, dumper
|
return data, binary_sensor_, trigger, action, dumper
|
||||||
|
|
||||||
|
|
||||||
@ -1405,7 +1407,7 @@ rc_switch_protocols = ns.RC_SWITCH_PROTOCOLS
|
|||||||
RCSwitchData = ns.struct("RCSwitchData")
|
RCSwitchData = ns.struct("RCSwitchData")
|
||||||
RCSwitchBase = ns.class_("RCSwitchBase")
|
RCSwitchBase = ns.class_("RCSwitchBase")
|
||||||
RCSwitchTrigger = ns.class_("RCSwitchTrigger", RemoteReceiverTrigger)
|
RCSwitchTrigger = ns.class_("RCSwitchTrigger", RemoteReceiverTrigger)
|
||||||
RCSwitchDumper = ns.class_("RCSwitchDumper", RemoteTransmitterDumper)
|
RCSwitchDumper = ns.class_("RCSwitchDumper", RemoteReceiverDumperBase)
|
||||||
RCSwitchRawAction = ns.class_("RCSwitchRawAction", RemoteTransmitterActionBase)
|
RCSwitchRawAction = ns.class_("RCSwitchRawAction", RemoteTransmitterActionBase)
|
||||||
RCSwitchTypeAAction = ns.class_("RCSwitchTypeAAction", RemoteTransmitterActionBase)
|
RCSwitchTypeAAction = ns.class_("RCSwitchTypeAAction", RemoteTransmitterActionBase)
|
||||||
RCSwitchTypeBAction = ns.class_("RCSwitchTypeBAction", RemoteTransmitterActionBase)
|
RCSwitchTypeBAction = ns.class_("RCSwitchTypeBAction", RemoteTransmitterActionBase)
|
||||||
|
@ -19,6 +19,22 @@ bool RemoteReceiveData::peek_mark(uint32_t length, uint32_t offset) const {
|
|||||||
return value >= 0 && lo <= value && value <= hi;
|
return value >= 0 && lo <= value && value <= hi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RemoteReceiveData::peek_mark_at_least(uint32_t length, uint32_t offset) const {
|
||||||
|
if (!this->is_valid(offset))
|
||||||
|
return false;
|
||||||
|
const int32_t value = this->peek(offset);
|
||||||
|
const int32_t lo = this->lower_bound_(length);
|
||||||
|
return value >= 0 && lo <= value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RemoteReceiveData::peek_mark_at_most(uint32_t length, uint32_t offset) const {
|
||||||
|
if (!this->is_valid(offset))
|
||||||
|
return false;
|
||||||
|
const int32_t value = this->peek(offset);
|
||||||
|
const int32_t hi = this->upper_bound_(length);
|
||||||
|
return value >= 0 && value <= hi;
|
||||||
|
}
|
||||||
|
|
||||||
bool RemoteReceiveData::peek_space(uint32_t length, uint32_t offset) const {
|
bool RemoteReceiveData::peek_space(uint32_t length, uint32_t offset) const {
|
||||||
if (!this->is_valid(offset))
|
if (!this->is_valid(offset))
|
||||||
return false;
|
return false;
|
||||||
@ -36,6 +52,14 @@ bool RemoteReceiveData::peek_space_at_least(uint32_t length, uint32_t offset) co
|
|||||||
return value <= 0 && lo <= -value;
|
return value <= 0 && lo <= -value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RemoteReceiveData::peek_space_at_most(uint32_t length, uint32_t offset) const {
|
||||||
|
if (!this->is_valid(offset))
|
||||||
|
return false;
|
||||||
|
const int32_t value = this->peek(offset);
|
||||||
|
const int32_t hi = this->upper_bound_(length);
|
||||||
|
return value <= 0 && -value <= hi;
|
||||||
|
}
|
||||||
|
|
||||||
bool RemoteReceiveData::expect_mark(uint32_t length) {
|
bool RemoteReceiveData::expect_mark(uint32_t length) {
|
||||||
if (!this->peek_mark(length))
|
if (!this->peek_mark(length))
|
||||||
return false;
|
return false;
|
||||||
|
@ -53,8 +53,11 @@ class RemoteReceiveData {
|
|||||||
bool is_valid(uint32_t offset = 0) const { return this->index_ + offset < this->data_.size(); }
|
bool is_valid(uint32_t offset = 0) const { return this->index_ + offset < this->data_.size(); }
|
||||||
int32_t peek(uint32_t offset = 0) const { return this->data_[this->index_ + offset]; }
|
int32_t peek(uint32_t offset = 0) const { return this->data_[this->index_ + offset]; }
|
||||||
bool peek_mark(uint32_t length, uint32_t offset = 0) const;
|
bool peek_mark(uint32_t length, uint32_t offset = 0) const;
|
||||||
|
bool peek_mark_at_least(uint32_t length, uint32_t offset = 0) const;
|
||||||
|
bool peek_mark_at_most(uint32_t length, uint32_t offset = 0) const;
|
||||||
bool peek_space(uint32_t length, uint32_t offset = 0) const;
|
bool peek_space(uint32_t length, uint32_t offset = 0) const;
|
||||||
bool peek_space_at_least(uint32_t length, uint32_t offset = 0) const;
|
bool peek_space_at_least(uint32_t length, uint32_t offset = 0) const;
|
||||||
|
bool peek_space_at_most(uint32_t length, uint32_t offset = 0) const;
|
||||||
bool peek_item(uint32_t mark, uint32_t space, uint32_t offset = 0) const {
|
bool peek_item(uint32_t mark, uint32_t space, uint32_t offset = 0) const {
|
||||||
return this->peek_space(space, offset + 1) && this->peek_mark(mark, offset);
|
return this->peek_space(space, offset + 1) && this->peek_mark(mark, offset);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ build_flags =
|
|||||||
; This are common settings for all environments.
|
; This are common settings for all environments.
|
||||||
[common]
|
[common]
|
||||||
lib_deps =
|
lib_deps =
|
||||||
esphome/noise-c@0.1.4 ; api
|
esphome/noise-c@0.1.10 ; api
|
||||||
improv/Improv@1.2.4 ; improv_serial / esp32_improv
|
improv/Improv@1.2.4 ; improv_serial / esp32_improv
|
||||||
bblanchon/ArduinoJson@6.18.5 ; json
|
bblanchon/ArduinoJson@6.18.5 ; json
|
||||||
wjtje/qr-code-generator-library@1.7.0 ; qr_code
|
wjtje/qr-code-generator-library@1.7.0 ; qr_code
|
||||||
@ -567,7 +567,7 @@ build_unflags =
|
|||||||
extends = common
|
extends = common
|
||||||
platform = platformio/native
|
platform = platformio/native
|
||||||
lib_deps =
|
lib_deps =
|
||||||
esphome/noise-c@0.1.1 ; used by api
|
esphome/noise-c@0.1.10 ; used by api
|
||||||
build_flags =
|
build_flags =
|
||||||
${common.build_flags}
|
${common.build_flags}
|
||||||
-DUSE_HOST
|
-DUSE_HOST
|
||||||
|
14
tests/components/ethernet/common-dm9051.yaml
Normal file
14
tests/components/ethernet/common-dm9051.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
ethernet:
|
||||||
|
type: DM9051
|
||||||
|
clk_pin: 19
|
||||||
|
mosi_pin: 21
|
||||||
|
miso_pin: 23
|
||||||
|
cs_pin: 18
|
||||||
|
interrupt_pin: 36
|
||||||
|
reset_pin: 22
|
||||||
|
clock_speed: 10Mhz
|
||||||
|
manual_ip:
|
||||||
|
static_ip: 192.168.178.56
|
||||||
|
gateway: 192.168.178.1
|
||||||
|
subnet: 255.255.255.0
|
||||||
|
domain: .local
|
1
tests/components/ethernet/test-dm9051.esp32-ard.yaml
Normal file
1
tests/components/ethernet/test-dm9051.esp32-ard.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<<: !include common-dm9051.yaml
|
1
tests/components/ethernet/test-dm9051.esp32-idf.yaml
Normal file
1
tests/components/ethernet/test-dm9051.esp32-idf.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<<: !include common-dm9051.yaml
|
Loading…
x
Reference in New Issue
Block a user