mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 01:34:18 +01:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
d3de631a54
33 changed files with 406 additions and 211 deletions
|
@ -168,7 +168,8 @@ esphome/components/homeassistant/* @OttoWinter
|
|||
esphome/components/honeywell_hih_i2c/* @Benichou34
|
||||
esphome/components/honeywellabp/* @RubyBailey
|
||||
esphome/components/honeywellabp2_i2c/* @jpfaff
|
||||
esphome/components/host/* @esphome/core
|
||||
esphome/components/host/* @clydebarrow @esphome/core
|
||||
esphome/components/host/time/* @clydebarrow
|
||||
esphome/components/hrxl_maxsonar_wr/* @netmikey
|
||||
esphome/components/hte501/* @Stock-M
|
||||
esphome/components/htu31d/* @betterengineering
|
||||
|
|
|
@ -100,6 +100,9 @@ RUN --mount=type=tmpfs,target=/root/.cargo if [ "$TARGETARCH$TARGETVARIANT" = "a
|
|||
--break-system-packages --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \
|
||||
&& /platformio_install_deps.py /platformio.ini --libraries
|
||||
|
||||
# Avoid unsafe git error when container user and file config volume permissions don't match
|
||||
RUN git config --system --add safe.directory '/config/*'
|
||||
|
||||
|
||||
# ======================= docker-type image =======================
|
||||
FROM base AS docker
|
||||
|
|
|
@ -11,6 +11,7 @@ from esphome.components.esp32.const import (
|
|||
from esphome.const import (
|
||||
CONF_DOMAIN,
|
||||
CONF_ID,
|
||||
CONF_VALUE,
|
||||
CONF_MANUAL_IP,
|
||||
CONF_STATIC_IP,
|
||||
CONF_TYPE,
|
||||
|
@ -26,6 +27,8 @@ from esphome.const import (
|
|||
CONF_INTERRUPT_PIN,
|
||||
CONF_RESET_PIN,
|
||||
CONF_SPI,
|
||||
CONF_PAGE_ID,
|
||||
CONF_ADDRESS,
|
||||
)
|
||||
from esphome.core import CORE, coroutine_with_priority
|
||||
from esphome.components.network import IPAddress
|
||||
|
@ -36,11 +39,13 @@ DEPENDENCIES = ["esp32"]
|
|||
AUTO_LOAD = ["network"]
|
||||
|
||||
ethernet_ns = cg.esphome_ns.namespace("ethernet")
|
||||
PHYRegister = ethernet_ns.struct("PHYRegister")
|
||||
CONF_PHY_ADDR = "phy_addr"
|
||||
CONF_MDC_PIN = "mdc_pin"
|
||||
CONF_MDIO_PIN = "mdio_pin"
|
||||
CONF_CLK_MODE = "clk_mode"
|
||||
CONF_POWER_PIN = "power_pin"
|
||||
CONF_PHY_REGISTERS = "phy_registers"
|
||||
|
||||
CONF_CLOCK_SPEED = "clock_speed"
|
||||
|
||||
|
@ -117,6 +122,13 @@ BASE_SCHEMA = cv.Schema(
|
|||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
PHY_REGISTER_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Required(CONF_ADDRESS): cv.hex_int,
|
||||
cv.Required(CONF_VALUE): cv.hex_int,
|
||||
cv.Optional(CONF_PAGE_ID): cv.hex_int,
|
||||
}
|
||||
)
|
||||
RMII_SCHEMA = BASE_SCHEMA.extend(
|
||||
cv.Schema(
|
||||
{
|
||||
|
@ -127,6 +139,7 @@ RMII_SCHEMA = BASE_SCHEMA.extend(
|
|||
),
|
||||
cv.Optional(CONF_PHY_ADDR, default=0): cv.int_range(min=0, max=31),
|
||||
cv.Optional(CONF_POWER_PIN): pins.internal_gpio_output_pin_number,
|
||||
cv.Optional(CONF_PHY_REGISTERS): cv.ensure_list(PHY_REGISTER_SCHEMA),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
@ -198,6 +211,15 @@ def manual_ip(config):
|
|||
)
|
||||
|
||||
|
||||
def phy_register(address: int, value: int, page: int):
|
||||
return cg.StructInitializer(
|
||||
PHYRegister,
|
||||
("address", address),
|
||||
("value", value),
|
||||
("page", page),
|
||||
)
|
||||
|
||||
|
||||
@coroutine_with_priority(60.0)
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
|
@ -225,6 +247,13 @@ async def to_code(config):
|
|||
cg.add(var.set_clk_mode(*CLK_MODES[config[CONF_CLK_MODE]]))
|
||||
if CONF_POWER_PIN in config:
|
||||
cg.add(var.set_power_pin(config[CONF_POWER_PIN]))
|
||||
for register_value in config.get(CONF_PHY_REGISTERS, []):
|
||||
reg = phy_register(
|
||||
register_value.get(CONF_ADDRESS),
|
||||
register_value.get(CONF_VALUE),
|
||||
register_value.get(CONF_PAGE_ID),
|
||||
)
|
||||
cg.add(var.add_phy_register(reg))
|
||||
|
||||
cg.add(var.set_type(ETHERNET_TYPES[config[CONF_TYPE]]))
|
||||
cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
|
||||
|
|
|
@ -28,6 +28,13 @@ EthernetComponent *global_eth_component; // NOLINT(cppcoreguidelines-avoid-non-
|
|||
return; \
|
||||
}
|
||||
|
||||
#define ESPHL_ERROR_CHECK_RET(err, message, ret) \
|
||||
if ((err) != ESP_OK) { \
|
||||
ESP_LOGE(TAG, message ": (%d) %s", err, esp_err_to_name(err)); \
|
||||
this->mark_failed(); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
EthernetComponent::EthernetComponent() { global_eth_component = this; }
|
||||
|
||||
void EthernetComponent::setup() {
|
||||
|
@ -188,9 +195,9 @@ void EthernetComponent::setup() {
|
|||
// KSZ8081RNA default is incorrect. It expects a 25MHz clock instead of the 50MHz we provide.
|
||||
this->ksz8081_set_clock_reference_(mac);
|
||||
}
|
||||
if (this->type_ == ETHERNET_TYPE_RTL8201 && this->clk_mode_ == EMAC_CLK_EXT_IN) {
|
||||
// Change in default behavior of RTL8201FI may require register setting to enable external clock
|
||||
this->rtl8201_set_rmii_mode_(mac);
|
||||
|
||||
for (const auto &phy_register : this->phy_registers_) {
|
||||
this->write_phy_register_(mac, phy_register);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -498,22 +505,9 @@ void EthernetComponent::dump_connect_params_() {
|
|||
}
|
||||
#endif /* USE_NETWORK_IPV6 */
|
||||
|
||||
esp_err_t err;
|
||||
|
||||
uint8_t mac[6];
|
||||
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_MAC_ADDR, &mac);
|
||||
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_MAC error");
|
||||
ESP_LOGCONFIG(TAG, " MAC Address: %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
eth_duplex_t duplex_mode;
|
||||
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_DUPLEX_MODE, &duplex_mode);
|
||||
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_DUPLEX_MODE error");
|
||||
ESP_LOGCONFIG(TAG, " Is Full Duplex: %s", YESNO(duplex_mode == ETH_DUPLEX_FULL));
|
||||
|
||||
eth_speed_t speed;
|
||||
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_SPEED, &speed);
|
||||
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_SPEED error");
|
||||
ESP_LOGCONFIG(TAG, " Link Speed: %u", speed == ETH_SPEED_100M ? 100 : 10);
|
||||
ESP_LOGCONFIG(TAG, " MAC Address: %s", this->get_eth_mac_address_pretty().c_str());
|
||||
ESP_LOGCONFIG(TAG, " Is Full Duplex: %s", YESNO(this->get_duplex_mode() == ETH_DUPLEX_FULL));
|
||||
ESP_LOGCONFIG(TAG, " Link Speed: %u", this->get_link_speed() == ETH_SPEED_100M ? 100 : 10);
|
||||
}
|
||||
|
||||
#ifdef USE_ETHERNET_SPI
|
||||
|
@ -533,6 +527,7 @@ void EthernetComponent::set_clk_mode(emac_rmii_clock_mode_t clk_mode, emac_rmii_
|
|||
this->clk_mode_ = clk_mode;
|
||||
this->clk_gpio_ = clk_gpio;
|
||||
}
|
||||
void EthernetComponent::add_phy_register(PHYRegister register_value) { this->phy_registers_.push_back(register_value); }
|
||||
#endif
|
||||
void EthernetComponent::set_type(EthernetType type) { this->type_ = type; }
|
||||
void EthernetComponent::set_manual_ip(const ManualIP &manual_ip) { this->manual_ip_ = manual_ip; }
|
||||
|
@ -546,6 +541,34 @@ std::string EthernetComponent::get_use_address() const {
|
|||
|
||||
void EthernetComponent::set_use_address(const std::string &use_address) { this->use_address_ = use_address; }
|
||||
|
||||
void EthernetComponent::get_eth_mac_address_raw(uint8_t *mac) {
|
||||
esp_err_t err;
|
||||
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_MAC_ADDR, mac);
|
||||
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_MAC error");
|
||||
}
|
||||
|
||||
std::string EthernetComponent::get_eth_mac_address_pretty() {
|
||||
uint8_t mac[6];
|
||||
get_mac_address_raw(mac);
|
||||
return str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
eth_duplex_t EthernetComponent::get_duplex_mode() {
|
||||
esp_err_t err;
|
||||
eth_duplex_t duplex_mode;
|
||||
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_DUPLEX_MODE, &duplex_mode);
|
||||
ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_DUPLEX_MODE error", ETH_DUPLEX_HALF);
|
||||
return duplex_mode;
|
||||
}
|
||||
|
||||
eth_speed_t EthernetComponent::get_link_speed() {
|
||||
esp_err_t err;
|
||||
eth_speed_t speed;
|
||||
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_SPEED, &speed);
|
||||
ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_SPEED error", ETH_SPEED_10M);
|
||||
return speed;
|
||||
}
|
||||
|
||||
bool EthernetComponent::powerdown() {
|
||||
ESP_LOGI(TAG, "Powering down ethernet PHY");
|
||||
if (this->phy_ == nullptr) {
|
||||
|
@ -591,44 +614,27 @@ void EthernetComponent::ksz8081_set_clock_reference_(esp_eth_mac_t *mac) {
|
|||
ESP_LOGVV(TAG, "KSZ8081 PHY Control 2: %s", format_hex_pretty((u_int8_t *) &phy_control_2, 2).c_str());
|
||||
}
|
||||
}
|
||||
constexpr uint8_t RTL8201_RMSR_REG_ADDR = 0x10;
|
||||
void EthernetComponent::rtl8201_set_rmii_mode_(esp_eth_mac_t *mac) {
|
||||
|
||||
void EthernetComponent::write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data) {
|
||||
esp_err_t err;
|
||||
uint32_t phy_rmii_mode;
|
||||
err = mac->write_phy_reg(mac, this->phy_addr_, 0x1f, 0x07);
|
||||
ESPHL_ERROR_CHECK(err, "Setting Page 7 failed");
|
||||
constexpr uint8_t eth_phy_psr_reg_addr = 0x1F;
|
||||
|
||||
/*
|
||||
* RTL8201 RMII Mode Setting Register (RMSR)
|
||||
* Page 7 Register 16
|
||||
*
|
||||
* bit 0 Reserved 0
|
||||
* bit 1 Rg_rmii_rxdsel 1 (default)
|
||||
* bit 2 Rg_rmii_rxdv_sel: 0 (default)
|
||||
* bit 3 RMII Mode: 1 (RMII Mode)
|
||||
* bit 4~7 Rg_rmii_rx_offset: 1111 (default)
|
||||
* bit 8~11 Rg_rmii_tx_offset: 1111 (default)
|
||||
* bit 12 Rg_rmii_clkdir: 1 (Input)
|
||||
* bit 13~15 Reserved 000
|
||||
*
|
||||
* Binary: 0001 1111 1111 1010
|
||||
* Hex: 0x1FFA
|
||||
*
|
||||
*/
|
||||
if (this->type_ == ETHERNET_TYPE_RTL8201 && register_data.page) {
|
||||
ESP_LOGD(TAG, "Select PHY Register Page: 0x%02" PRIX32, register_data.page);
|
||||
err = mac->write_phy_reg(mac, this->phy_addr_, eth_phy_psr_reg_addr, register_data.page);
|
||||
ESPHL_ERROR_CHECK(err, "Select PHY Register page failed");
|
||||
}
|
||||
|
||||
err = mac->read_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, &(phy_rmii_mode));
|
||||
ESPHL_ERROR_CHECK(err, "Read PHY RMSR Register failed");
|
||||
ESP_LOGV(TAG, "Hardware default RTL8201 RMII Mode Register is: 0x%04" PRIX32, phy_rmii_mode);
|
||||
ESP_LOGD(TAG, "Writing to PHY Register Address: 0x%02" PRIX32, register_data.address);
|
||||
ESP_LOGD(TAG, "Writing to PHY Register Value: 0x%04" PRIX32, register_data.value);
|
||||
err = mac->write_phy_reg(mac, this->phy_addr_, register_data.address, register_data.value);
|
||||
ESPHL_ERROR_CHECK(err, "Writing PHY Register failed");
|
||||
|
||||
err = mac->write_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, 0x1FFA);
|
||||
ESPHL_ERROR_CHECK(err, "Setting Register 16 RMII Mode Setting failed");
|
||||
|
||||
err = mac->read_phy_reg(mac, this->phy_addr_, RTL8201_RMSR_REG_ADDR, &(phy_rmii_mode));
|
||||
ESPHL_ERROR_CHECK(err, "Read PHY RMSR Register failed");
|
||||
ESP_LOGV(TAG, "Setting RTL8201 RMII Mode Register to: 0x%04" PRIX32, phy_rmii_mode);
|
||||
|
||||
err = mac->write_phy_reg(mac, this->phy_addr_, 0x1f, 0x0);
|
||||
ESPHL_ERROR_CHECK(err, "Setting Page 0 failed");
|
||||
if (this->type_ == ETHERNET_TYPE_RTL8201 && register_data.page) {
|
||||
ESP_LOGD(TAG, "Select PHY Register Page 0x%02" PRIX32, 0x0);
|
||||
err = mac->write_phy_reg(mac, this->phy_addr_, eth_phy_psr_reg_addr, 0x0);
|
||||
ESPHL_ERROR_CHECK(err, "Select PHY Register Page 0 failed");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,12 @@ struct ManualIP {
|
|||
network::IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
|
||||
};
|
||||
|
||||
struct PHYRegister {
|
||||
uint32_t address;
|
||||
uint32_t value;
|
||||
uint32_t page;
|
||||
};
|
||||
|
||||
enum class EthernetComponentState {
|
||||
STOPPED,
|
||||
CONNECTING,
|
||||
|
@ -66,6 +72,7 @@ class EthernetComponent : public Component {
|
|||
void set_mdc_pin(uint8_t mdc_pin);
|
||||
void set_mdio_pin(uint8_t mdio_pin);
|
||||
void set_clk_mode(emac_rmii_clock_mode_t clk_mode, emac_rmii_clock_gpio_t clk_gpio);
|
||||
void add_phy_register(PHYRegister register_value);
|
||||
#endif
|
||||
void set_type(EthernetType type);
|
||||
void set_manual_ip(const ManualIP &manual_ip);
|
||||
|
@ -74,6 +81,10 @@ class EthernetComponent : public Component {
|
|||
network::IPAddress get_dns_address(uint8_t num);
|
||||
std::string get_use_address() const;
|
||||
void set_use_address(const std::string &use_address);
|
||||
void get_eth_mac_address_raw(uint8_t *mac);
|
||||
std::string get_eth_mac_address_pretty();
|
||||
eth_duplex_t get_duplex_mode();
|
||||
eth_speed_t get_link_speed();
|
||||
bool powerdown();
|
||||
|
||||
protected:
|
||||
|
@ -87,8 +98,8 @@ class EthernetComponent : public Component {
|
|||
void dump_connect_params_();
|
||||
/// @brief Set `RMII Reference Clock Select` bit for KSZ8081.
|
||||
void ksz8081_set_clock_reference_(esp_eth_mac_t *mac);
|
||||
/// @brief Set `RMII Mode Setting Register` for RTL8201.
|
||||
void rtl8201_set_rmii_mode_(esp_eth_mac_t *mac);
|
||||
/// @brief Set arbitratry PHY registers from config.
|
||||
void write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data);
|
||||
|
||||
std::string use_address_;
|
||||
#ifdef USE_ETHERNET_SPI
|
||||
|
@ -107,6 +118,7 @@ class EthernetComponent : public Component {
|
|||
uint8_t mdio_pin_{18};
|
||||
emac_rmii_clock_mode_t clk_mode_{EMAC_CLK_EXT_IN};
|
||||
emac_rmii_clock_gpio_t clk_gpio_{EMAC_CLK_IN_GPIO};
|
||||
std::vector<PHYRegister> phy_registers_{};
|
||||
#endif
|
||||
EthernetType type_{ETHERNET_TYPE_UNKNOWN};
|
||||
optional<ManualIP> manual_ip_{};
|
||||
|
|
|
@ -10,6 +10,7 @@ static const char *const TAG = "ethernet_info";
|
|||
|
||||
void IPAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo IPAddress", this); }
|
||||
void DNSAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo DNS Address", this); }
|
||||
void MACAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo MAC Address", this); }
|
||||
|
||||
} // namespace ethernet_info
|
||||
} // namespace esphome
|
||||
|
|
|
@ -59,6 +59,13 @@ class DNSAddressEthernetInfo : public PollingComponent, public text_sensor::Text
|
|||
std::string last_results_;
|
||||
};
|
||||
|
||||
class MACAddressEthernetInfo : public Component, public text_sensor::TextSensor {
|
||||
public:
|
||||
void setup() override { this->publish_state(ethernet::global_eth_component->get_eth_mac_address_pretty()); }
|
||||
std::string unique_id() override { return get_mac_address() + "-ethernetinfo-mac"; }
|
||||
void dump_config() override;
|
||||
};
|
||||
|
||||
} // namespace ethernet_info
|
||||
} // namespace esphome
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from esphome.components import text_sensor
|
|||
from esphome.const import (
|
||||
CONF_IP_ADDRESS,
|
||||
CONF_DNS_ADDRESS,
|
||||
CONF_MAC_ADDRESS,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
)
|
||||
|
||||
|
@ -19,6 +20,10 @@ DNSAddressEthernetInfo = ethernet_info_ns.class_(
|
|||
"DNSAddressEthernetInfo", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
|
||||
MACAddressEthernetInfo = ethernet_info_ns.class_(
|
||||
"MACAddressEthernetInfo", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Optional(CONF_IP_ADDRESS): text_sensor.text_sensor_schema(
|
||||
|
@ -36,6 +41,9 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
cv.Optional(CONF_DNS_ADDRESS): text_sensor.text_sensor_schema(
|
||||
DNSAddressEthernetInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
|
||||
).extend(cv.polling_component_schema("1s")),
|
||||
cv.Optional(CONF_MAC_ADDRESS): text_sensor.text_sensor_schema(
|
||||
MACAddressEthernetInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -51,3 +59,6 @@ async def to_code(config):
|
|||
if conf := config.get(CONF_DNS_ADDRESS):
|
||||
dns_info = await text_sensor.new_text_sensor(config[CONF_DNS_ADDRESS])
|
||||
await cg.register_component(dns_info, config[CONF_DNS_ADDRESS])
|
||||
if conf := config.get(CONF_MAC_ADDRESS):
|
||||
mac_info = await text_sensor.new_text_sensor(config[CONF_MAC_ADDRESS])
|
||||
await cg.register_component(mac_info, config[CONF_MAC_ADDRESS])
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from esphome import pins
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
|
||||
from esphome.components import i2c, touchscreen
|
||||
from esphome.const import CONF_ID
|
||||
from esphome.const import CONF_ID, CONF_INTERRUPT_PIN
|
||||
from .. import ft5x06_ns
|
||||
|
||||
FT5x06ButtonListener = ft5x06_ns.class_("FT5x06ButtonListener")
|
||||
|
@ -16,6 +17,7 @@ FT5x06Touchscreen = ft5x06_ns.class_(
|
|||
CONFIG_SCHEMA = touchscreen.TOUCHSCREEN_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(FT5x06Touchscreen),
|
||||
cv.Optional(CONF_INTERRUPT_PIN): pins.internal_gpio_input_pin_schema,
|
||||
}
|
||||
).extend(i2c.i2c_device_schema(0x48))
|
||||
|
||||
|
@ -24,3 +26,7 @@ async def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await i2c.register_i2c_device(var, config)
|
||||
await touchscreen.register_touchscreen(var, config)
|
||||
|
||||
if interrupt_pin := config.get(CONF_INTERRUPT_PIN):
|
||||
pin = await cg.gpio_pin_expression(interrupt_pin)
|
||||
cg.add(var.set_interrupt_pin(pin))
|
||||
|
|
102
esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp
Normal file
102
esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
#include "ft5x06_touchscreen.h"
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ft5x06 {
|
||||
|
||||
static const char *const TAG = "ft5x06.touchscreen";
|
||||
|
||||
void FT5x06Touchscreen::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up FT5x06 Touchscreen...");
|
||||
if (this->interrupt_pin_ != nullptr) {
|
||||
this->interrupt_pin_->setup();
|
||||
this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
this->interrupt_pin_->setup();
|
||||
this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE);
|
||||
}
|
||||
|
||||
// wait 200ms after reset.
|
||||
this->set_timeout(200, [this] { this->continue_setup_(); });
|
||||
}
|
||||
|
||||
void FT5x06Touchscreen::continue_setup_() {
|
||||
uint8_t data[4];
|
||||
if (!this->set_mode_(FT5X06_OP_MODE))
|
||||
return;
|
||||
|
||||
if (!this->err_check_(this->read_register(FT5X06_VENDOR_ID_REG, data, 1), "Read Vendor ID"))
|
||||
return;
|
||||
switch (data[0]) {
|
||||
case FT5X06_ID_1:
|
||||
case FT5X06_ID_2:
|
||||
case FT5X06_ID_3:
|
||||
this->vendor_id_ = (VendorId) data[0];
|
||||
ESP_LOGD(TAG, "Read vendor ID 0x%X", data[0]);
|
||||
break;
|
||||
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unknown vendor ID 0x%X", data[0]);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
// reading the chip registers to get max x/y does not seem to work.
|
||||
if (this->display_ != nullptr) {
|
||||
if (this->x_raw_max_ == this->x_raw_min_) {
|
||||
this->x_raw_max_ = this->display_->get_native_width();
|
||||
}
|
||||
if (this->y_raw_max_ == this->y_raw_min_) {
|
||||
this->y_raw_max_ = this->display_->get_native_height();
|
||||
}
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, "FT5x06 Touchscreen setup complete");
|
||||
}
|
||||
|
||||
void FT5x06Touchscreen::update_touches() {
|
||||
uint8_t touch_cnt;
|
||||
uint8_t data[MAX_TOUCHES][6];
|
||||
|
||||
if (!this->read_byte(FT5X06_TD_STATUS, &touch_cnt) || touch_cnt > MAX_TOUCHES) {
|
||||
ESP_LOGW(TAG, "Failed to read status");
|
||||
return;
|
||||
}
|
||||
if (touch_cnt == 0)
|
||||
return;
|
||||
|
||||
if (!this->read_bytes(FT5X06_TOUCH_DATA, (uint8_t *) data, touch_cnt * 6)) {
|
||||
ESP_LOGW(TAG, "Failed to read touch data");
|
||||
return;
|
||||
}
|
||||
for (uint8_t i = 0; i != touch_cnt; i++) {
|
||||
uint8_t status = data[i][0] >> 6;
|
||||
uint8_t id = data[i][2] >> 3;
|
||||
uint16_t x = encode_uint16(data[i][0] & 0x0F, data[i][1]);
|
||||
uint16_t y = encode_uint16(data[i][2] & 0xF, data[i][3]);
|
||||
|
||||
ESP_LOGD(TAG, "Read %X status, id: %d, pos %d/%d", status, id, x, y);
|
||||
if (status == 0 || status == 2) {
|
||||
this->add_raw_touch_position_(id, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FT5x06Touchscreen::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "FT5x06 Touchscreen:");
|
||||
ESP_LOGCONFIG(TAG, " Address: 0x%02X", this->address_);
|
||||
ESP_LOGCONFIG(TAG, " Vendor ID: 0x%X", (int) this->vendor_id_);
|
||||
}
|
||||
|
||||
bool FT5x06Touchscreen::err_check_(i2c::ErrorCode err, const char *msg) {
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->mark_failed();
|
||||
ESP_LOGE(TAG, "%s failed - err 0x%X", msg, err);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool FT5x06Touchscreen::set_mode_(FTMode mode) {
|
||||
return this->err_check_(this->write_register(FT5X06_MODE_REG, (uint8_t *) &mode, 1), "Set mode");
|
||||
}
|
||||
|
||||
} // namespace ft5x06
|
||||
} // namespace esphome
|
|
@ -3,14 +3,12 @@
|
|||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/components/touchscreen/touchscreen.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/gpio.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ft5x06 {
|
||||
|
||||
static const char *const TAG = "ft5x06.touchscreen";
|
||||
|
||||
enum VendorId {
|
||||
FT5X06_ID_UNKNOWN = 0,
|
||||
FT5X06_ID_1 = 0x51,
|
||||
|
@ -39,91 +37,19 @@ static const size_t MAX_TOUCHES = 5; // max number of possible touches reported
|
|||
|
||||
class FT5x06Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice {
|
||||
public:
|
||||
void setup() override {
|
||||
esph_log_config(TAG, "Setting up FT5x06 Touchscreen...");
|
||||
// wait 200ms after reset.
|
||||
this->set_timeout(200, [this] { this->continue_setup_(); });
|
||||
}
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void update_touches() override;
|
||||
|
||||
void continue_setup_(void) {
|
||||
uint8_t data[4];
|
||||
if (!this->set_mode_(FT5X06_OP_MODE))
|
||||
return;
|
||||
|
||||
if (!this->err_check_(this->read_register(FT5X06_VENDOR_ID_REG, data, 1), "Read Vendor ID"))
|
||||
return;
|
||||
switch (data[0]) {
|
||||
case FT5X06_ID_1:
|
||||
case FT5X06_ID_2:
|
||||
case FT5X06_ID_3:
|
||||
this->vendor_id_ = (VendorId) data[0];
|
||||
esph_log_d(TAG, "Read vendor ID 0x%X", data[0]);
|
||||
break;
|
||||
|
||||
default:
|
||||
esph_log_e(TAG, "Unknown vendor ID 0x%X", data[0]);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
// reading the chip registers to get max x/y does not seem to work.
|
||||
if (this->display_ != nullptr) {
|
||||
if (this->x_raw_max_ == this->x_raw_min_) {
|
||||
this->x_raw_max_ = this->display_->get_native_width();
|
||||
}
|
||||
if (this->y_raw_max_ == this->y_raw_min_) {
|
||||
this->y_raw_max_ = this->display_->get_native_height();
|
||||
}
|
||||
}
|
||||
esph_log_config(TAG, "FT5x06 Touchscreen setup complete");
|
||||
}
|
||||
|
||||
void update_touches() override {
|
||||
uint8_t touch_cnt;
|
||||
uint8_t data[MAX_TOUCHES][6];
|
||||
|
||||
if (!this->read_byte(FT5X06_TD_STATUS, &touch_cnt) || touch_cnt > MAX_TOUCHES) {
|
||||
esph_log_w(TAG, "Failed to read status");
|
||||
return;
|
||||
}
|
||||
if (touch_cnt == 0)
|
||||
return;
|
||||
|
||||
if (!this->read_bytes(FT5X06_TOUCH_DATA, (uint8_t *) data, touch_cnt * 6)) {
|
||||
esph_log_w(TAG, "Failed to read touch data");
|
||||
return;
|
||||
}
|
||||
for (uint8_t i = 0; i != touch_cnt; i++) {
|
||||
uint8_t status = data[i][0] >> 6;
|
||||
uint8_t id = data[i][2] >> 3;
|
||||
uint16_t x = encode_uint16(data[i][0] & 0x0F, data[i][1]);
|
||||
uint16_t y = encode_uint16(data[i][2] & 0xF, data[i][3]);
|
||||
|
||||
esph_log_d(TAG, "Read %X status, id: %d, pos %d/%d", status, id, x, y);
|
||||
if (status == 0 || status == 2) {
|
||||
this->add_raw_touch_position_(id, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dump_config() override {
|
||||
esph_log_config(TAG, "FT5x06 Touchscreen:");
|
||||
esph_log_config(TAG, " Address: 0x%02X", this->address_);
|
||||
esph_log_config(TAG, " Vendor ID: 0x%X", (int) this->vendor_id_);
|
||||
}
|
||||
void set_interrupt_pin(InternalGPIOPin *interrupt_pin) { this->interrupt_pin_ = interrupt_pin; }
|
||||
|
||||
protected:
|
||||
bool err_check_(i2c::ErrorCode err, const char *msg) {
|
||||
if (err != i2c::ERROR_OK) {
|
||||
this->mark_failed();
|
||||
esph_log_e(TAG, "%s failed - err 0x%X", msg, err);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool set_mode_(FTMode mode) {
|
||||
return this->err_check_(this->write_register(FT5X06_MODE_REG, (uint8_t *) &mode, 1), "Set mode");
|
||||
}
|
||||
void continue_setup_();
|
||||
bool err_check_(i2c::ErrorCode err, const char *msg);
|
||||
bool set_mode_(FTMode mode);
|
||||
VendorId vendor_id_{FT5X06_ID_UNKNOWN};
|
||||
|
||||
InternalGPIOPin *interrupt_pin_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace ft5x06
|
||||
|
|
|
@ -16,7 +16,7 @@ from .const import KEY_HOST
|
|||
# force import gpio to register pin schema
|
||||
from .gpio import host_pin_to_code # noqa
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
CODEOWNERS = ["@esphome/core", "@clydebarrow"]
|
||||
AUTO_LOAD = ["network"]
|
||||
|
||||
|
||||
|
|
20
esphome/components/host/time/__init__.py
Normal file
20
esphome/components/host/time/__init__.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import esphome.codegen as cg
|
||||
from esphome.const import CONF_ID
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import time as time_
|
||||
|
||||
CODEOWNERS = ["@clydebarrow"]
|
||||
|
||||
time_ns = cg.esphome_ns.namespace("host")
|
||||
HostTime = time_ns.class_("HostTime", time_.RealTimeClock)
|
||||
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(HostTime),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await time_.register_time(var, config)
|
15
esphome/components/host/time/host_time.h
Normal file
15
esphome/components/host/time/host_time.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/time/real_time_clock.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace host {
|
||||
|
||||
class HostTime : public time::RealTimeClock {
|
||||
public:
|
||||
void update() override {}
|
||||
};
|
||||
|
||||
} // namespace host
|
||||
} // namespace esphome
|
|
@ -109,6 +109,7 @@ void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
|
|||
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
case logger::UART_SELECTION_USB_SERIAL_JTAG:
|
||||
usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS);
|
||||
usb_serial_jtag_ll_txfifo_flush(); // fixes for issue in IDF 4.4.7
|
||||
break;
|
||||
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32S3
|
||||
default:
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
|
||||
defined(USE_ESP32_VARIANT_ESP32H2)
|
||||
#include <driver/usb_serial_jtag.h>
|
||||
#include <hal/usb_serial_jtag_ll.h>
|
||||
#endif
|
||||
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
|
||||
#include <esp_private/usb_console.h>
|
||||
|
|
|
@ -1769,7 +1769,17 @@ def aeha_dumper(var, config):
|
|||
pass
|
||||
|
||||
|
||||
@register_action("aeha", AEHAAction, AEHA_SCHEMA)
|
||||
@register_action(
|
||||
"aeha",
|
||||
AEHAAction,
|
||||
AEHA_SCHEMA.extend(
|
||||
{
|
||||
cv.Optional(CONF_CARRIER_FREQUENCY, default="38000Hz"): cv.All(
|
||||
cv.frequency, cv.int_
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
async def aeha_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_ADDRESS], args, cg.uint16)
|
||||
cg.add(var.set_address(template_))
|
||||
|
@ -1777,6 +1787,8 @@ async def aeha_action(var, config, args):
|
|||
config[CONF_DATA], args, cg.std_vector.template(cg.uint8)
|
||||
)
|
||||
cg.add(var.set_data(template_))
|
||||
templ = await cg.templatable(config[CONF_CARRIER_FREQUENCY], args, cg.uint32)
|
||||
cg.add(var.set_carrier_frequency(templ))
|
||||
|
||||
|
||||
# Haier
|
||||
|
|
|
@ -16,7 +16,6 @@ static const uint16_t BIT_ZERO_LOW_US = BITWISE;
|
|||
static const uint16_t TRAILER = BITWISE;
|
||||
|
||||
void AEHAProtocol::encode(RemoteTransmitData *dst, const AEHAData &data) {
|
||||
dst->set_carrier_frequency(38000);
|
||||
dst->reserve(2 + 32 + (data.data.size() * 2) + 1);
|
||||
|
||||
dst->item(HEADER_HIGH_US, HEADER_LOW_US);
|
||||
|
|
|
@ -30,12 +30,14 @@ template<typename... Ts> class AEHAAction : public RemoteTransmitterActionBase<T
|
|||
public:
|
||||
TEMPLATABLE_VALUE(uint16_t, address)
|
||||
TEMPLATABLE_VALUE(std::vector<uint8_t>, data)
|
||||
TEMPLATABLE_VALUE(uint32_t, carrier_frequency);
|
||||
|
||||
void set_data(const std::vector<uint8_t> &data) { data_ = data; }
|
||||
void encode(RemoteTransmitData *dst, Ts... x) override {
|
||||
AEHAData data{};
|
||||
data.address = this->address_.value(x...);
|
||||
data.data = this->data_.value(x...);
|
||||
dst->set_carrier_frequency(this->carrier_frequency_.value(x...));
|
||||
AEHAProtocol().encode(dst, data);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,7 +20,6 @@ namespace sntp {
|
|||
static const char *const TAG = "sntp";
|
||||
|
||||
void SNTPComponent::setup() {
|
||||
#ifndef USE_HOST
|
||||
ESP_LOGCONFIG(TAG, "Setting up SNTP...");
|
||||
#if defined(USE_ESP_IDF)
|
||||
if (esp_sntp_enabled()) {
|
||||
|
@ -44,7 +43,6 @@ void SNTPComponent::setup() {
|
|||
#endif
|
||||
|
||||
sntp_init();
|
||||
#endif
|
||||
}
|
||||
void SNTPComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "SNTP Time:");
|
||||
|
@ -54,7 +52,7 @@ void SNTPComponent::dump_config() {
|
|||
ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str());
|
||||
}
|
||||
void SNTPComponent::update() {
|
||||
#if !defined(USE_ESP_IDF) && !defined(USE_HOST)
|
||||
#if !defined(USE_ESP_IDF)
|
||||
// force resync
|
||||
if (sntp_enabled()) {
|
||||
sntp_stop();
|
||||
|
|
|
@ -2,24 +2,41 @@ from esphome.components import time as time_
|
|||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.core import CORE
|
||||
from esphome.const import CONF_ID, CONF_SERVERS
|
||||
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_SERVERS,
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_ESP8266,
|
||||
PLATFORM_RP2040,
|
||||
PLATFORM_RTL87XX,
|
||||
PLATFORM_BK72XX,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["network"]
|
||||
sntp_ns = cg.esphome_ns.namespace("sntp")
|
||||
SNTPComponent = sntp_ns.class_("SNTPComponent", time_.RealTimeClock)
|
||||
|
||||
|
||||
DEFAULT_SERVERS = ["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"]
|
||||
|
||||
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend(
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
time_.TIME_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(SNTPComponent),
|
||||
cv.Optional(CONF_SERVERS, default=DEFAULT_SERVERS): cv.All(
|
||||
cv.ensure_list(cv.Any(cv.domain, cv.hostname)), cv.Length(min=1, max=3)
|
||||
),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
).extend(cv.COMPONENT_SCHEMA),
|
||||
cv.only_on(
|
||||
[
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_ESP8266,
|
||||
PLATFORM_RP2040,
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_RTL87XX,
|
||||
]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
|
|
@ -189,8 +189,6 @@ CONFIG_SCHEMA = cv.All(
|
|||
cv.has_at_least_one_key(CONF_TARGET_TEMPERATURE_DATAPOINT, CONF_SWITCH_DATAPOINT),
|
||||
validate_temperature_multipliers,
|
||||
validate_cooling_values,
|
||||
cv.has_at_most_one_key(CONF_ACTIVE_STATE, CONF_HEATING_STATE_PIN),
|
||||
cv.has_at_most_one_key(CONF_ACTIVE_STATE, CONF_COOLING_STATE_PIN),
|
||||
)
|
||||
|
||||
|
||||
|
@ -207,6 +205,12 @@ async def to_code(config):
|
|||
if switch_datapoint := config.get(CONF_SWITCH_DATAPOINT):
|
||||
cg.add(var.set_switch_id(switch_datapoint))
|
||||
|
||||
if heating_state_pin_config := config.get(CONF_HEATING_STATE_PIN):
|
||||
heating_state_pin = await cg.gpio_pin_expression(heating_state_pin_config)
|
||||
cg.add(var.set_heating_state_pin(heating_state_pin))
|
||||
if cooling_state_pin_config := config.get(CONF_COOLING_STATE_PIN):
|
||||
cooling_state_pin = await cg.gpio_pin_expression(cooling_state_pin_config)
|
||||
cg.add(var.set_cooling_state_pin(cooling_state_pin))
|
||||
if active_state_config := config.get(CONF_ACTIVE_STATE):
|
||||
cg.add(var.set_active_state_id(active_state_config.get(CONF_DATAPOINT)))
|
||||
if (heating_value := active_state_config.get(CONF_HEATING_VALUE)) is not None:
|
||||
|
@ -217,13 +221,6 @@ async def to_code(config):
|
|||
cg.add(var.set_active_state_drying_value(drying_value))
|
||||
if (fanonly_value := active_state_config.get(CONF_FANONLY_VALUE)) is not None:
|
||||
cg.add(var.set_active_state_fanonly_value(fanonly_value))
|
||||
else:
|
||||
if heating_state_pin_config := config.get(CONF_HEATING_STATE_PIN):
|
||||
heating_state_pin = await cg.gpio_pin_expression(heating_state_pin_config)
|
||||
cg.add(var.set_heating_state_pin(heating_state_pin))
|
||||
if cooling_state_pin_config := config.get(CONF_COOLING_STATE_PIN):
|
||||
cooling_state_pin = await cg.gpio_pin_expression(cooling_state_pin_config)
|
||||
cg.add(var.set_cooling_state_pin(cooling_state_pin))
|
||||
|
||||
if target_temperature_datapoint := config.get(CONF_TARGET_TEMPERATURE_DATAPOINT):
|
||||
cg.add(var.set_target_temperature_id(target_temperature_datapoint))
|
||||
|
|
|
@ -24,14 +24,6 @@ void TuyaClimate::setup() {
|
|||
this->publish_state();
|
||||
});
|
||||
}
|
||||
if (this->active_state_id_.has_value()) {
|
||||
this->parent_->register_listener(*this->active_state_id_, [this](const TuyaDatapoint &datapoint) {
|
||||
ESP_LOGV(TAG, "MCU reported active state is: %u", datapoint.value_enum);
|
||||
this->active_state_ = datapoint.value_enum;
|
||||
this->compute_state_();
|
||||
this->publish_state();
|
||||
});
|
||||
} else {
|
||||
if (this->heating_state_pin_ != nullptr) {
|
||||
this->heating_state_pin_->setup();
|
||||
this->heating_state_ = this->heating_state_pin_->digital_read();
|
||||
|
@ -40,6 +32,13 @@ void TuyaClimate::setup() {
|
|||
this->cooling_state_pin_->setup();
|
||||
this->cooling_state_ = this->cooling_state_pin_->digital_read();
|
||||
}
|
||||
if (this->active_state_id_.has_value()) {
|
||||
this->parent_->register_listener(*this->active_state_id_, [this](const TuyaDatapoint &datapoint) {
|
||||
ESP_LOGV(TAG, "MCU reported active state is: %u", datapoint.value_enum);
|
||||
this->active_state_ = datapoint.value_enum;
|
||||
this->compute_state_();
|
||||
this->publish_state();
|
||||
});
|
||||
}
|
||||
if (this->target_temperature_id_.has_value()) {
|
||||
this->parent_->register_listener(*this->target_temperature_id_, [this](const TuyaDatapoint &datapoint) {
|
||||
|
@ -113,9 +112,6 @@ void TuyaClimate::setup() {
|
|||
}
|
||||
|
||||
void TuyaClimate::loop() {
|
||||
if (this->active_state_id_.has_value())
|
||||
return;
|
||||
|
||||
bool state_changed = false;
|
||||
if (this->heating_state_pin_ != nullptr) {
|
||||
bool heating_state = this->heating_state_pin_->digital_read();
|
||||
|
@ -147,6 +143,7 @@ void TuyaClimate::control(const climate::ClimateCall &call) {
|
|||
this->parent_->set_boolean_datapoint_value(*this->switch_id_, switch_state);
|
||||
const climate::ClimateMode new_mode = *call.get_mode();
|
||||
|
||||
if (this->active_state_id_.has_value()) {
|
||||
if (new_mode == climate::CLIMATE_MODE_HEAT && this->supports_heat_) {
|
||||
this->parent_->set_enum_datapoint_value(*this->active_state_id_, *this->active_state_heating_value_);
|
||||
} else if (new_mode == climate::CLIMATE_MODE_COOL && this->supports_cool_) {
|
||||
|
@ -156,6 +153,9 @@ void TuyaClimate::control(const climate::ClimateCall &call) {
|
|||
} else if (new_mode == climate::CLIMATE_MODE_FAN_ONLY && this->active_state_fanonly_value_.has_value()) {
|
||||
this->parent_->set_enum_datapoint_value(*this->active_state_id_, *this->active_state_fanonly_value_);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Active state (mode) datapoint not configured");
|
||||
}
|
||||
}
|
||||
|
||||
control_swing_mode_(call);
|
||||
|
@ -422,7 +422,32 @@ void TuyaClimate::compute_state_() {
|
|||
}
|
||||
|
||||
climate::ClimateAction target_action = climate::CLIMATE_ACTION_IDLE;
|
||||
if (this->heating_state_pin_ != nullptr || this->cooling_state_pin_ != nullptr) {
|
||||
// Use state from input pins
|
||||
if (this->heating_state_) {
|
||||
target_action = climate::CLIMATE_ACTION_HEATING;
|
||||
this->mode = climate::CLIMATE_MODE_HEAT;
|
||||
} else if (this->cooling_state_) {
|
||||
target_action = climate::CLIMATE_ACTION_COOLING;
|
||||
this->mode = climate::CLIMATE_MODE_COOL;
|
||||
}
|
||||
if (this->active_state_id_.has_value()) {
|
||||
// Both are available, use MCU datapoint as mode
|
||||
if (this->supports_heat_ && this->active_state_heating_value_.has_value() &&
|
||||
this->active_state_ == this->active_state_heating_value_) {
|
||||
this->mode = climate::CLIMATE_MODE_HEAT;
|
||||
} else if (this->supports_cool_ && this->active_state_cooling_value_.has_value() &&
|
||||
this->active_state_ == this->active_state_cooling_value_) {
|
||||
this->mode = climate::CLIMATE_MODE_COOL;
|
||||
} else if (this->active_state_drying_value_.has_value() &&
|
||||
this->active_state_ == this->active_state_drying_value_) {
|
||||
this->mode = climate::CLIMATE_MODE_DRY;
|
||||
} else if (this->active_state_fanonly_value_.has_value() &&
|
||||
this->active_state_ == this->active_state_fanonly_value_) {
|
||||
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
|
||||
}
|
||||
}
|
||||
} else if (this->active_state_id_.has_value()) {
|
||||
// Use state from MCU datapoint
|
||||
if (this->supports_heat_ && this->active_state_heating_value_.has_value() &&
|
||||
this->active_state_ == this->active_state_heating_value_) {
|
||||
|
@ -441,15 +466,6 @@ void TuyaClimate::compute_state_() {
|
|||
target_action = climate::CLIMATE_ACTION_FAN;
|
||||
this->mode = climate::CLIMATE_MODE_FAN_ONLY;
|
||||
}
|
||||
} else if (this->heating_state_pin_ != nullptr || this->cooling_state_pin_ != nullptr) {
|
||||
// Use state from input pins
|
||||
if (this->heating_state_) {
|
||||
target_action = climate::CLIMATE_ACTION_HEATING;
|
||||
this->mode = climate::CLIMATE_MODE_HEAT;
|
||||
} else if (this->cooling_state_) {
|
||||
target_action = climate::CLIMATE_ACTION_COOLING;
|
||||
this->mode = climate::CLIMATE_MODE_COOL;
|
||||
}
|
||||
} else {
|
||||
// Fallback to active state calc based on temp and hysteresis
|
||||
const float temp_diff = this->target_temperature - this->current_temperature;
|
||||
|
|
|
@ -16,6 +16,7 @@ CONF_DIRECTION_DATAPOINT = "direction_datapoint"
|
|||
CONF_POSITION_DATAPOINT = "position_datapoint"
|
||||
CONF_POSITION_REPORT_DATAPOINT = "position_report_datapoint"
|
||||
CONF_INVERT_POSITION = "invert_position"
|
||||
CONF_INVERT_POSITION_REPORT = "invert_position_report"
|
||||
|
||||
TuyaCover = tuya_ns.class_("TuyaCover", cover.Cover, cg.Component)
|
||||
|
||||
|
@ -47,6 +48,7 @@ CONFIG_SCHEMA = cv.All(
|
|||
cv.Optional(CONF_MIN_VALUE, default=0): cv.int_,
|
||||
cv.Optional(CONF_MAX_VALUE, default=100): cv.int_,
|
||||
cv.Optional(CONF_INVERT_POSITION, default=False): cv.boolean,
|
||||
cv.Optional(CONF_INVERT_POSITION_REPORT, default=False): cv.boolean,
|
||||
cv.Optional(CONF_RESTORE_MODE, default="RESTORE"): cv.enum(
|
||||
RESTORE_MODES, upper=True
|
||||
),
|
||||
|
@ -71,6 +73,7 @@ async def to_code(config):
|
|||
cg.add(var.set_min_value(config[CONF_MIN_VALUE]))
|
||||
cg.add(var.set_max_value(config[CONF_MAX_VALUE]))
|
||||
cg.add(var.set_invert_position(config[CONF_INVERT_POSITION]))
|
||||
cg.add(var.set_invert_position_report(config[CONF_INVERT_POSITION_REPORT]))
|
||||
cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))
|
||||
paren = await cg.get_variable(config[CONF_TUYA_ID])
|
||||
cg.add(var.set_tuya_parent(paren))
|
||||
|
|
|
@ -51,7 +51,7 @@ void TuyaCover::setup() {
|
|||
return;
|
||||
}
|
||||
auto pos = float(datapoint.value_uint - this->min_value_) / this->value_range_;
|
||||
this->position = 1.0f - pos;
|
||||
this->position = this->invert_position_report_ ? pos : 1.0f - pos;
|
||||
this->publish_state();
|
||||
});
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ void TuyaCover::control(const cover::CoverCall &call) {
|
|||
this->parent_->force_set_enum_datapoint_value(*this->control_id_, COMMAND_STOP);
|
||||
} else {
|
||||
auto pos = this->position;
|
||||
pos = 1.0f - pos;
|
||||
pos = this->invert_position_report_ ? pos : 1.0f - pos;
|
||||
auto position_int = static_cast<uint32_t>(pos * this->value_range_);
|
||||
position_int = position_int + this->min_value_;
|
||||
|
||||
|
@ -78,7 +78,7 @@ void TuyaCover::control(const cover::CoverCall &call) {
|
|||
this->parent_->force_set_enum_datapoint_value(*this->control_id_, COMMAND_CLOSE);
|
||||
}
|
||||
} else {
|
||||
pos = 1.0f - pos;
|
||||
pos = this->invert_position_report_ ? pos : 1.0f - pos;
|
||||
auto position_int = static_cast<uint32_t>(pos * this->value_range_);
|
||||
position_int = position_int + this->min_value_;
|
||||
|
||||
|
@ -112,6 +112,9 @@ void TuyaCover::dump_config() {
|
|||
ESP_LOGCONFIG(TAG, " Configured as Inverted, but direction_datapoint isn't configured");
|
||||
}
|
||||
}
|
||||
if (this->invert_position_report_) {
|
||||
ESP_LOGCONFIG(TAG, " Position Reporting Inverted");
|
||||
}
|
||||
if (this->control_id_.has_value()) {
|
||||
ESP_LOGCONFIG(TAG, " Control has datapoint ID %u", *this->control_id_);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ class TuyaCover : public cover::Cover, public Component {
|
|||
void set_min_value(uint32_t min_value) { min_value_ = min_value; }
|
||||
void set_max_value(uint32_t max_value) { max_value_ = max_value; }
|
||||
void set_invert_position(bool invert_position) { invert_position_ = invert_position; }
|
||||
void set_invert_position_report(bool invert_position_report) { invert_position_report_ = invert_position_report; }
|
||||
void set_restore_mode(TuyaCoverRestoreMode restore_mode) { restore_mode_ = restore_mode; }
|
||||
|
||||
protected:
|
||||
|
@ -42,6 +43,7 @@ class TuyaCover : public cover::Cover, public Component {
|
|||
uint32_t max_value_;
|
||||
uint32_t value_range_;
|
||||
bool invert_position_;
|
||||
bool invert_position_report_;
|
||||
};
|
||||
|
||||
} // namespace tuya
|
||||
|
|
|
@ -7,7 +7,10 @@ from esphome.const import (
|
|||
CONF_TIME_ID,
|
||||
CONF_ADDRESS,
|
||||
CONF_REBOOT_TIMEOUT,
|
||||
KEY_CORE,
|
||||
KEY_FRAMEWORK_VERSION,
|
||||
)
|
||||
from esphome.components.esp32 import CORE, add_idf_sdkconfig_option
|
||||
from esphome.components import time
|
||||
from esphome.core import TimePeriod
|
||||
from esphome import automation
|
||||
|
@ -117,6 +120,13 @@ async def to_code(config):
|
|||
if config[CONF_REQUIRE_CONNECTION_TO_PROCEED]:
|
||||
cg.add(var.disable_auto_proceed())
|
||||
|
||||
# Workaround for crash on IDF 5+
|
||||
# See https://github.com/trombik/esp_wireguard/issues/33#issuecomment-1568503651
|
||||
if CORE.using_esp_idf and CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] >= cv.Version(
|
||||
5, 0, 0
|
||||
):
|
||||
add_idf_sdkconfig_option("CONFIG_LWIP_PPP_SUPPORT", True)
|
||||
|
||||
# This flag is added here because the esp_wireguard library statically
|
||||
# set the size of its allowed_ips list at compile time using this value;
|
||||
# the '+1' modifier is relative to the device's own address that will
|
||||
|
|
|
@ -13,11 +13,6 @@ if [ ! -n "$DEVCONTAINER" ] && [ ! -n "$VIRTUAL_ENV" ] && [ ! "$ESPHOME_NO_VENV"
|
|||
source $location
|
||||
fi
|
||||
|
||||
# Avoid unsafe git error when running inside devcontainer
|
||||
if [ -n "$DEVCONTAINER" ]; then
|
||||
git config --global --add safe.directory "$PWD"
|
||||
fi
|
||||
|
||||
pip3 install -r requirements.txt -r requirements_optional.txt -r requirements_test.txt -r requirements_dev.txt
|
||||
pip3 install setuptools wheel
|
||||
pip3 install -e ".[dev,test,displays]" --config-settings editable_mode=compat
|
||||
|
|
|
@ -17,3 +17,5 @@ text_sensor:
|
|||
name: IP Address
|
||||
dns_address:
|
||||
name: DNS Address
|
||||
mac_address:
|
||||
name: MAC Address
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
time:
|
||||
- platform: sntp
|
||||
- platform: host
|
||||
id: esptime
|
||||
timezone: Australia/Sydney
|
||||
|
||||
logger:
|
||||
level: VERBOSE
|
||||
logs:
|
||||
lvgl: INFO
|
||||
display: DEBUG
|
||||
sensor: INFO
|
||||
vnc: DEBUG
|
||||
|
||||
host:
|
||||
mac_address: "62:23:45:AF:B3:DD"
|
||||
|
|
|
@ -118,6 +118,7 @@ button:
|
|||
on_press:
|
||||
remote_transmitter.transmit_aeha:
|
||||
address: 0x8008
|
||||
carrier_frequency: 36700Hz
|
||||
data:
|
||||
[
|
||||
0x00,
|
||||
|
|
1
tests/components/sntp/test.bk72xx.yaml
Normal file
1
tests/components/sntp/test.bk72xx.yaml
Normal file
|
@ -0,0 +1 @@
|
|||
<<: !include common.yaml
|
|
@ -2906,6 +2906,7 @@ switch:
|
|||
turn_on_action:
|
||||
remote_transmitter.transmit_aeha:
|
||||
address: 0x8008
|
||||
carrier_frequency: 36700Hz
|
||||
data:
|
||||
[
|
||||
0x00,
|
||||
|
|
Loading…
Reference in a new issue