mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
Merge branch 'dev' into mcuboot_support
This commit is contained in:
commit
f1cc9db821
57 changed files with 1466 additions and 139 deletions
|
@ -58,6 +58,7 @@ esphome/components/beken_spi_led_strip/* @Mat931
|
||||||
esphome/components/bh1750/* @OttoWinter
|
esphome/components/bh1750/* @OttoWinter
|
||||||
esphome/components/binary_sensor/* @esphome/core
|
esphome/components/binary_sensor/* @esphome/core
|
||||||
esphome/components/bk72xx/* @kuba2k2
|
esphome/components/bk72xx/* @kuba2k2
|
||||||
|
esphome/components/bl0906/* @athom-tech @jesserockz @tarontop
|
||||||
esphome/components/bl0939/* @ziceva
|
esphome/components/bl0939/* @ziceva
|
||||||
esphome/components/bl0940/* @tobias-
|
esphome/components/bl0940/* @tobias-
|
||||||
esphome/components/bl0942/* @dbuezas
|
esphome/components/bl0942/* @dbuezas
|
||||||
|
|
|
@ -1107,6 +1107,19 @@ enum MediaPlayerCommand {
|
||||||
MEDIA_PLAYER_COMMAND_MUTE = 3;
|
MEDIA_PLAYER_COMMAND_MUTE = 3;
|
||||||
MEDIA_PLAYER_COMMAND_UNMUTE = 4;
|
MEDIA_PLAYER_COMMAND_UNMUTE = 4;
|
||||||
}
|
}
|
||||||
|
enum MediaPlayerFormatPurpose {
|
||||||
|
MEDIA_PLAYER_FORMAT_PURPOSE_DEFAULT = 0;
|
||||||
|
MEDIA_PLAYER_FORMAT_PURPOSE_ANNOUNCEMENT = 1;
|
||||||
|
}
|
||||||
|
message MediaPlayerSupportedFormat {
|
||||||
|
option (id) = 119;
|
||||||
|
option (ifdef) = "USE_MEDIA_PLAYER";
|
||||||
|
|
||||||
|
string format = 1;
|
||||||
|
uint32 sample_rate = 2;
|
||||||
|
uint32 num_channels = 3;
|
||||||
|
MediaPlayerFormatPurpose purpose = 4;
|
||||||
|
}
|
||||||
message ListEntitiesMediaPlayerResponse {
|
message ListEntitiesMediaPlayerResponse {
|
||||||
option (id) = 63;
|
option (id) = 63;
|
||||||
option (source) = SOURCE_SERVER;
|
option (source) = SOURCE_SERVER;
|
||||||
|
@ -1122,6 +1135,8 @@ message ListEntitiesMediaPlayerResponse {
|
||||||
EntityCategory entity_category = 7;
|
EntityCategory entity_category = 7;
|
||||||
|
|
||||||
bool supports_pause = 8;
|
bool supports_pause = 8;
|
||||||
|
|
||||||
|
repeated MediaPlayerSupportedFormat supported_formats = 9;
|
||||||
}
|
}
|
||||||
message MediaPlayerStateResponse {
|
message MediaPlayerStateResponse {
|
||||||
option (id) = 64;
|
option (id) = 64;
|
||||||
|
|
|
@ -179,6 +179,7 @@ void APIConnection::loop() {
|
||||||
SubscribeHomeAssistantStateResponse resp;
|
SubscribeHomeAssistantStateResponse resp;
|
||||||
resp.entity_id = it.entity_id;
|
resp.entity_id = it.entity_id;
|
||||||
resp.attribute = it.attribute.value();
|
resp.attribute = it.attribute.value();
|
||||||
|
resp.once = it.once;
|
||||||
if (this->send_subscribe_home_assistant_state_response(resp)) {
|
if (this->send_subscribe_home_assistant_state_response(resp)) {
|
||||||
state_subs_at_++;
|
state_subs_at_++;
|
||||||
}
|
}
|
||||||
|
@ -1025,6 +1026,15 @@ bool APIConnection::send_media_player_info(media_player::MediaPlayer *media_play
|
||||||
auto traits = media_player->get_traits();
|
auto traits = media_player->get_traits();
|
||||||
msg.supports_pause = traits.get_supports_pause();
|
msg.supports_pause = traits.get_supports_pause();
|
||||||
|
|
||||||
|
for (auto &supported_format : traits.get_supported_formats()) {
|
||||||
|
MediaPlayerSupportedFormat media_format;
|
||||||
|
media_format.format = supported_format.format;
|
||||||
|
media_format.sample_rate = supported_format.sample_rate;
|
||||||
|
media_format.num_channels = supported_format.num_channels;
|
||||||
|
media_format.purpose = static_cast<enums::MediaPlayerFormatPurpose>(supported_format.purpose);
|
||||||
|
msg.supported_formats.push_back(media_format);
|
||||||
|
}
|
||||||
|
|
||||||
return this->send_list_entities_media_player_response(msg);
|
return this->send_list_entities_media_player_response(msg);
|
||||||
}
|
}
|
||||||
void APIConnection::media_player_command(const MediaPlayerCommandRequest &msg) {
|
void APIConnection::media_player_command(const MediaPlayerCommandRequest &msg) {
|
||||||
|
|
|
@ -387,6 +387,18 @@ template<> const char *proto_enum_to_string<enums::MediaPlayerCommand>(enums::Me
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
template<> const char *proto_enum_to_string<enums::MediaPlayerFormatPurpose>(enums::MediaPlayerFormatPurpose value) {
|
||||||
|
switch (value) {
|
||||||
|
case enums::MEDIA_PLAYER_FORMAT_PURPOSE_DEFAULT:
|
||||||
|
return "MEDIA_PLAYER_FORMAT_PURPOSE_DEFAULT";
|
||||||
|
case enums::MEDIA_PLAYER_FORMAT_PURPOSE_ANNOUNCEMENT:
|
||||||
|
return "MEDIA_PLAYER_FORMAT_PURPOSE_ANNOUNCEMENT";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
template<>
|
template<>
|
||||||
const char *proto_enum_to_string<enums::BluetoothDeviceRequestType>(enums::BluetoothDeviceRequestType value) {
|
const char *proto_enum_to_string<enums::BluetoothDeviceRequestType>(enums::BluetoothDeviceRequestType value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
|
@ -5123,6 +5135,64 @@ void ButtonCommandRequest::dump_to(std::string &out) const {
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
bool MediaPlayerSupportedFormat::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||||
|
switch (field_id) {
|
||||||
|
case 2: {
|
||||||
|
this->sample_rate = value.as_uint32();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
this->num_channels = value.as_uint32();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case 4: {
|
||||||
|
this->purpose = value.as_enum<enums::MediaPlayerFormatPurpose>();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool MediaPlayerSupportedFormat::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
|
||||||
|
switch (field_id) {
|
||||||
|
case 1: {
|
||||||
|
this->format = value.as_string();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void MediaPlayerSupportedFormat::encode(ProtoWriteBuffer buffer) const {
|
||||||
|
buffer.encode_string(1, this->format);
|
||||||
|
buffer.encode_uint32(2, this->sample_rate);
|
||||||
|
buffer.encode_uint32(3, this->num_channels);
|
||||||
|
buffer.encode_enum<enums::MediaPlayerFormatPurpose>(4, this->purpose);
|
||||||
|
}
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void MediaPlayerSupportedFormat::dump_to(std::string &out) const {
|
||||||
|
__attribute__((unused)) char buffer[64];
|
||||||
|
out.append("MediaPlayerSupportedFormat {\n");
|
||||||
|
out.append(" format: ");
|
||||||
|
out.append("'").append(this->format).append("'");
|
||||||
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" sample_rate: ");
|
||||||
|
sprintf(buffer, "%" PRIu32, this->sample_rate);
|
||||||
|
out.append(buffer);
|
||||||
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" num_channels: ");
|
||||||
|
sprintf(buffer, "%" PRIu32, this->num_channels);
|
||||||
|
out.append(buffer);
|
||||||
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" purpose: ");
|
||||||
|
out.append(proto_enum_to_string<enums::MediaPlayerFormatPurpose>(this->purpose));
|
||||||
|
out.append("\n");
|
||||||
|
out.append("}");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
bool ListEntitiesMediaPlayerResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
bool ListEntitiesMediaPlayerResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||||
switch (field_id) {
|
switch (field_id) {
|
||||||
case 6: {
|
case 6: {
|
||||||
|
@ -5159,6 +5229,10 @@ bool ListEntitiesMediaPlayerResponse::decode_length(uint32_t field_id, ProtoLeng
|
||||||
this->icon = value.as_string();
|
this->icon = value.as_string();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case 9: {
|
||||||
|
this->supported_formats.push_back(value.as_message<MediaPlayerSupportedFormat>());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5182,6 +5256,9 @@ void ListEntitiesMediaPlayerResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_bool(6, this->disabled_by_default);
|
buffer.encode_bool(6, this->disabled_by_default);
|
||||||
buffer.encode_enum<enums::EntityCategory>(7, this->entity_category);
|
buffer.encode_enum<enums::EntityCategory>(7, this->entity_category);
|
||||||
buffer.encode_bool(8, this->supports_pause);
|
buffer.encode_bool(8, this->supports_pause);
|
||||||
|
for (auto &it : this->supported_formats) {
|
||||||
|
buffer.encode_message<MediaPlayerSupportedFormat>(9, it, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const {
|
void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const {
|
||||||
|
@ -5219,6 +5296,12 @@ void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const {
|
||||||
out.append(" supports_pause: ");
|
out.append(" supports_pause: ");
|
||||||
out.append(YESNO(this->supports_pause));
|
out.append(YESNO(this->supports_pause));
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
|
|
||||||
|
for (const auto &it : this->supported_formats) {
|
||||||
|
out.append(" supported_formats: ");
|
||||||
|
it.dump_to(out);
|
||||||
|
out.append("\n");
|
||||||
|
}
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -156,6 +156,10 @@ enum MediaPlayerCommand : uint32_t {
|
||||||
MEDIA_PLAYER_COMMAND_MUTE = 3,
|
MEDIA_PLAYER_COMMAND_MUTE = 3,
|
||||||
MEDIA_PLAYER_COMMAND_UNMUTE = 4,
|
MEDIA_PLAYER_COMMAND_UNMUTE = 4,
|
||||||
};
|
};
|
||||||
|
enum MediaPlayerFormatPurpose : uint32_t {
|
||||||
|
MEDIA_PLAYER_FORMAT_PURPOSE_DEFAULT = 0,
|
||||||
|
MEDIA_PLAYER_FORMAT_PURPOSE_ANNOUNCEMENT = 1,
|
||||||
|
};
|
||||||
enum BluetoothDeviceRequestType : uint32_t {
|
enum BluetoothDeviceRequestType : uint32_t {
|
||||||
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT = 0,
|
BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT = 0,
|
||||||
BLUETOOTH_DEVICE_REQUEST_TYPE_DISCONNECT = 1,
|
BLUETOOTH_DEVICE_REQUEST_TYPE_DISCONNECT = 1,
|
||||||
|
@ -1267,6 +1271,21 @@ class ButtonCommandRequest : public ProtoMessage {
|
||||||
protected:
|
protected:
|
||||||
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
bool decode_32bit(uint32_t field_id, Proto32Bit value) override;
|
||||||
};
|
};
|
||||||
|
class MediaPlayerSupportedFormat : public ProtoMessage {
|
||||||
|
public:
|
||||||
|
std::string format{};
|
||||||
|
uint32_t sample_rate{0};
|
||||||
|
uint32_t num_channels{0};
|
||||||
|
enums::MediaPlayerFormatPurpose purpose{};
|
||||||
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
void dump_to(std::string &out) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||||
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
|
};
|
||||||
class ListEntitiesMediaPlayerResponse : public ProtoMessage {
|
class ListEntitiesMediaPlayerResponse : public ProtoMessage {
|
||||||
public:
|
public:
|
||||||
std::string object_id{};
|
std::string object_id{};
|
||||||
|
@ -1277,6 +1296,7 @@ class ListEntitiesMediaPlayerResponse : public ProtoMessage {
|
||||||
bool disabled_by_default{false};
|
bool disabled_by_default{false};
|
||||||
enums::EntityCategory entity_category{};
|
enums::EntityCategory entity_category{};
|
||||||
bool supports_pause{false};
|
bool supports_pause{false};
|
||||||
|
std::vector<MediaPlayerSupportedFormat> supported_formats{};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
|
|
|
@ -311,6 +311,14 @@ bool APIServerConnectionBase::send_list_entities_button_response(const ListEntit
|
||||||
#ifdef USE_BUTTON
|
#ifdef USE_BUTTON
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
|
bool APIServerConnectionBase::send_media_player_supported_format(const MediaPlayerSupportedFormat &msg) {
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "send_media_player_supported_format: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
return this->send_message_<MediaPlayerSupportedFormat>(msg, 119);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef USE_MEDIA_PLAYER
|
||||||
bool APIServerConnectionBase::send_list_entities_media_player_response(const ListEntitiesMediaPlayerResponse &msg) {
|
bool APIServerConnectionBase::send_list_entities_media_player_response(const ListEntitiesMediaPlayerResponse &msg) {
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
ESP_LOGVV(TAG, "send_list_entities_media_player_response: %s", msg.dump().c_str());
|
ESP_LOGVV(TAG, "send_list_entities_media_player_response: %s", msg.dump().c_str());
|
||||||
|
@ -1135,6 +1143,17 @@ bool APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
||||||
ESP_LOGVV(TAG, "on_update_command_request: %s", msg.dump().c_str());
|
ESP_LOGVV(TAG, "on_update_command_request: %s", msg.dump().c_str());
|
||||||
#endif
|
#endif
|
||||||
this->on_update_command_request(msg);
|
this->on_update_command_request(msg);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 119: {
|
||||||
|
#ifdef USE_MEDIA_PLAYER
|
||||||
|
MediaPlayerSupportedFormat msg;
|
||||||
|
msg.decode(msg_data, msg_size);
|
||||||
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
|
ESP_LOGVV(TAG, "on_media_player_supported_format: %s", msg.dump().c_str());
|
||||||
|
#endif
|
||||||
|
this->on_media_player_supported_format(msg);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,6 +145,10 @@ class APIServerConnectionBase : public ProtoService {
|
||||||
#ifdef USE_BUTTON
|
#ifdef USE_BUTTON
|
||||||
virtual void on_button_command_request(const ButtonCommandRequest &value){};
|
virtual void on_button_command_request(const ButtonCommandRequest &value){};
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_MEDIA_PLAYER
|
||||||
|
bool send_media_player_supported_format(const MediaPlayerSupportedFormat &msg);
|
||||||
|
virtual void on_media_player_supported_format(const MediaPlayerSupportedFormat &value){};
|
||||||
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
bool send_list_entities_media_player_response(const ListEntitiesMediaPlayerResponse &msg);
|
bool send_list_entities_media_player_response(const ListEntitiesMediaPlayerResponse &msg);
|
||||||
#endif
|
#endif
|
||||||
|
|
1
esphome/components/bl0906/__init__.py
Normal file
1
esphome/components/bl0906/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CODEOWNERS = ["@athom-tech", "@tarontop", "@jesserockz"]
|
238
esphome/components/bl0906/bl0906.cpp
Normal file
238
esphome/components/bl0906/bl0906.cpp
Normal file
|
@ -0,0 +1,238 @@
|
||||||
|
#include "bl0906.h"
|
||||||
|
#include "constants.h"
|
||||||
|
|
||||||
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace bl0906 {
|
||||||
|
|
||||||
|
static const char *const TAG = "bl0906";
|
||||||
|
|
||||||
|
constexpr uint32_t to_uint32_t(ube24_t input) { return input.h << 16 | input.m << 8 | input.l; }
|
||||||
|
|
||||||
|
constexpr int32_t to_int32_t(sbe24_t input) { return input.h << 16 | input.m << 8 | input.l; }
|
||||||
|
|
||||||
|
// The SUM byte is (Addr+Data_L+Data_M+Data_H)&0xFF negated;
|
||||||
|
constexpr uint8_t bl0906_checksum(const uint8_t address, const DataPacket *data) {
|
||||||
|
return (address + data->l + data->m + data->h) ^ 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BL0906::loop() {
|
||||||
|
if (this->current_channel_ == UINT8_MAX) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (this->available())
|
||||||
|
this->flush();
|
||||||
|
|
||||||
|
if (this->current_channel_ == 0) {
|
||||||
|
// Temperature
|
||||||
|
this->read_data_(BL0906_TEMPERATURE, BL0906_TREF, this->temperature_sensor_);
|
||||||
|
} else if (this->current_channel_ == 1) {
|
||||||
|
this->read_data_(BL0906_I_1_RMS, BL0906_IREF, this->current_1_sensor_);
|
||||||
|
this->read_data_(BL0906_WATT_1, BL0906_PREF, this->power_1_sensor_);
|
||||||
|
this->read_data_(BL0906_CF_1_CNT, BL0906_EREF, this->energy_1_sensor_);
|
||||||
|
} else if (this->current_channel_ == 2) {
|
||||||
|
this->read_data_(BL0906_I_2_RMS, BL0906_IREF, this->current_2_sensor_);
|
||||||
|
this->read_data_(BL0906_WATT_2, BL0906_PREF, this->power_2_sensor_);
|
||||||
|
this->read_data_(BL0906_CF_2_CNT, BL0906_EREF, this->energy_2_sensor_);
|
||||||
|
} else if (this->current_channel_ == 3) {
|
||||||
|
this->read_data_(BL0906_I_3_RMS, BL0906_IREF, this->current_3_sensor_);
|
||||||
|
this->read_data_(BL0906_WATT_3, BL0906_PREF, this->power_3_sensor_);
|
||||||
|
this->read_data_(BL0906_CF_3_CNT, BL0906_EREF, this->energy_3_sensor_);
|
||||||
|
} else if (this->current_channel_ == 4) {
|
||||||
|
this->read_data_(BL0906_I_4_RMS, BL0906_IREF, this->current_4_sensor_);
|
||||||
|
this->read_data_(BL0906_WATT_4, BL0906_PREF, this->power_4_sensor_);
|
||||||
|
this->read_data_(BL0906_CF_4_CNT, BL0906_EREF, this->energy_4_sensor_);
|
||||||
|
} else if (this->current_channel_ == 5) {
|
||||||
|
this->read_data_(BL0906_I_5_RMS, BL0906_IREF, this->current_5_sensor_);
|
||||||
|
this->read_data_(BL0906_WATT_5, BL0906_PREF, this->power_5_sensor_);
|
||||||
|
this->read_data_(BL0906_CF_5_CNT, BL0906_EREF, this->energy_5_sensor_);
|
||||||
|
} else if (this->current_channel_ == 6) {
|
||||||
|
this->read_data_(BL0906_I_6_RMS, BL0906_IREF, this->current_6_sensor_);
|
||||||
|
this->read_data_(BL0906_WATT_6, BL0906_PREF, this->power_6_sensor_);
|
||||||
|
this->read_data_(BL0906_CF_6_CNT, BL0906_EREF, this->energy_6_sensor_);
|
||||||
|
} else if (this->current_channel_ == UINT8_MAX - 2) {
|
||||||
|
// Frequency
|
||||||
|
this->read_data_(BL0906_FREQUENCY, BL0906_FREF, frequency_sensor_);
|
||||||
|
// Voltage
|
||||||
|
this->read_data_(BL0906_V_RMS, BL0906_UREF, voltage_sensor_);
|
||||||
|
} else if (this->current_channel_ == UINT8_MAX - 1) {
|
||||||
|
// Total power
|
||||||
|
this->read_data_(BL0906_WATT_SUM, BL0906_WATT, this->total_power_sensor_);
|
||||||
|
// Total Energy
|
||||||
|
this->read_data_(BL0906_CF_SUM_CNT, BL0906_CF, this->total_energy_sensor_);
|
||||||
|
} else {
|
||||||
|
this->current_channel_ = UINT8_MAX - 2; // Go to frequency and voltage
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->current_channel_++;
|
||||||
|
this->handle_actions_();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BL0906::setup() {
|
||||||
|
while (this->available())
|
||||||
|
this->flush();
|
||||||
|
this->write_array(USR_WRPROT_WITABLE, sizeof(USR_WRPROT_WITABLE));
|
||||||
|
// Calibration (1: register address; 2: value before calibration; 3: value after calibration)
|
||||||
|
this->bias_correction_(BL0906_RMSOS_1, 0.01600, 0); // Calibration current_1
|
||||||
|
this->bias_correction_(BL0906_RMSOS_2, 0.01500, 0);
|
||||||
|
this->bias_correction_(BL0906_RMSOS_3, 0.01400, 0);
|
||||||
|
this->bias_correction_(BL0906_RMSOS_4, 0.01300, 0);
|
||||||
|
this->bias_correction_(BL0906_RMSOS_5, 0.01200, 0);
|
||||||
|
this->bias_correction_(BL0906_RMSOS_6, 0.01200, 0); // Calibration current_6
|
||||||
|
|
||||||
|
this->write_array(USR_WRPROT_ONLYREAD, sizeof(USR_WRPROT_ONLYREAD));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BL0906::update() { this->current_channel_ = 0; }
|
||||||
|
|
||||||
|
size_t BL0906::enqueue_action_(ActionCallbackFuncPtr function) {
|
||||||
|
this->action_queue_.push_back(function);
|
||||||
|
return this->action_queue_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BL0906::handle_actions_() {
|
||||||
|
if (this->action_queue_.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ActionCallbackFuncPtr ptr_func = nullptr;
|
||||||
|
for (int i = 0; i < this->action_queue_.size(); i++) {
|
||||||
|
ptr_func = this->action_queue_[i];
|
||||||
|
if (ptr_func) {
|
||||||
|
ESP_LOGI(TAG, "HandleActionCallback[%d]...", i);
|
||||||
|
(this->*ptr_func)();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (this->available()) {
|
||||||
|
this->read();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->action_queue_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset energy
|
||||||
|
void BL0906::reset_energy_() {
|
||||||
|
this->write_array(BL0906_INIT[0], 6);
|
||||||
|
delay(1);
|
||||||
|
this->flush();
|
||||||
|
|
||||||
|
ESP_LOGW(TAG, "RMSOS:%02X%02X%02X%02X%02X%02X", BL0906_INIT[0][0], BL0906_INIT[0][1], BL0906_INIT[0][2],
|
||||||
|
BL0906_INIT[0][3], BL0906_INIT[0][4], BL0906_INIT[0][5]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read data
|
||||||
|
void BL0906::read_data_(const uint8_t address, const float reference, sensor::Sensor *sensor) {
|
||||||
|
if (sensor == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DataPacket buffer;
|
||||||
|
ube24_t data_u24;
|
||||||
|
sbe24_t data_s24;
|
||||||
|
float value = 0;
|
||||||
|
|
||||||
|
bool signed_result = reference == BL0906_TREF || reference == BL0906_WATT || reference == BL0906_PREF;
|
||||||
|
|
||||||
|
this->write_byte(BL0906_READ_COMMAND);
|
||||||
|
this->write_byte(address);
|
||||||
|
if (this->read_array((uint8_t *) &buffer, sizeof(buffer) - 1)) {
|
||||||
|
if (bl0906_checksum(address, &buffer) == buffer.checksum) {
|
||||||
|
if (signed_result) {
|
||||||
|
data_s24.l = buffer.l;
|
||||||
|
data_s24.m = buffer.m;
|
||||||
|
data_s24.h = buffer.h;
|
||||||
|
} else {
|
||||||
|
data_u24.l = buffer.l;
|
||||||
|
data_u24.m = buffer.m;
|
||||||
|
data_u24.h = buffer.h;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");
|
||||||
|
while (read() >= 0)
|
||||||
|
;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Power
|
||||||
|
if (reference == BL0906_PREF) {
|
||||||
|
value = (float) to_int32_t(data_s24) * reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Total power
|
||||||
|
if (reference == BL0906_WATT) {
|
||||||
|
value = (float) to_int32_t(data_s24) * reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Voltage, current, power, total power
|
||||||
|
if (reference == BL0906_UREF || reference == BL0906_IREF || reference == BL0906_EREF || reference == BL0906_CF) {
|
||||||
|
value = (float) to_uint32_t(data_u24) * reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Frequency
|
||||||
|
if (reference == BL0906_FREF) {
|
||||||
|
value = reference / (float) to_uint32_t(data_u24);
|
||||||
|
}
|
||||||
|
// Chip temperature
|
||||||
|
if (reference == BL0906_TREF) {
|
||||||
|
value = (float) to_int32_t(data_s24);
|
||||||
|
value = (value - 64) * 12.5 / 59 - 40;
|
||||||
|
}
|
||||||
|
sensor->publish_state(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// RMS offset correction
|
||||||
|
void BL0906::bias_correction_(uint8_t address, float measurements, float correction) {
|
||||||
|
DataPacket data;
|
||||||
|
float ki = 12875 * 1 * (5.1 + 5.1) * 1000 / 2000 / 1.097; // Current coefficient
|
||||||
|
float i_rms0 = measurements * ki;
|
||||||
|
float i_rms = correction * ki;
|
||||||
|
int32_t value = (i_rms * i_rms - i_rms0 * i_rms0) / 256;
|
||||||
|
data.l = value << 24 >> 24;
|
||||||
|
data.m = value << 16 >> 24;
|
||||||
|
if (value < 0) {
|
||||||
|
data.h = (value << 8 >> 24) | 0b10000000;
|
||||||
|
}
|
||||||
|
data.address = bl0906_checksum(address, &data);
|
||||||
|
ESP_LOGV(TAG, "RMSOS:%02X%02X%02X%02X%02X%02X", BL0906_WRITE_COMMAND, address, data.l, data.m, data.h, data.address);
|
||||||
|
this->write_byte(BL0906_WRITE_COMMAND);
|
||||||
|
this->write_byte(address);
|
||||||
|
this->write_byte(data.l);
|
||||||
|
this->write_byte(data.m);
|
||||||
|
this->write_byte(data.h);
|
||||||
|
this->write_byte(data.address);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BL0906::dump_config() {
|
||||||
|
ESP_LOGCONFIG(TAG, "BL0906:");
|
||||||
|
LOG_SENSOR(" ", "Voltage", this->voltage_sensor_);
|
||||||
|
|
||||||
|
LOG_SENSOR(" ", "Current1", this->current_1_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Current2", this->current_2_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Current3", this->current_3_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Current4", this->current_4_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Current5", this->current_5_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Current6", this->current_6_sensor_);
|
||||||
|
|
||||||
|
LOG_SENSOR(" ", "Power1", this->power_1_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Power2", this->power_2_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Power3", this->power_3_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Power4", this->power_4_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Power5", this->power_5_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Power6", this->power_6_sensor_);
|
||||||
|
|
||||||
|
LOG_SENSOR(" ", "Energy1", this->energy_1_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Energy2", this->energy_2_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Energy3", this->energy_3_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Energy4", this->energy_4_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Energy5", this->energy_5_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Energy6", this->energy_6_sensor_);
|
||||||
|
|
||||||
|
LOG_SENSOR(" ", "Total Power", this->total_power_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Total Energy", this->total_energy_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Frequency", this->frequency_sensor_);
|
||||||
|
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace bl0906
|
||||||
|
} // namespace esphome
|
96
esphome/components/bl0906/bl0906.h
Normal file
96
esphome/components/bl0906/bl0906.h
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "esphome/components/sensor/sensor.h"
|
||||||
|
#include "esphome/components/uart/uart.h"
|
||||||
|
#include "esphome/core/automation.h"
|
||||||
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/datatypes.h"
|
||||||
|
|
||||||
|
// https://www.belling.com.cn/media/file_object/bel_product/BL0906/datasheet/BL0906_V1.02_cn.pdf
|
||||||
|
// https://www.belling.com.cn/media/file_object/bel_product/BL0906/guide/BL0906%20APP%20Note_V1.02.pdf
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace bl0906 {
|
||||||
|
|
||||||
|
struct DataPacket { // NOLINT(altera-struct-pack-align)
|
||||||
|
uint8_t l{0};
|
||||||
|
uint8_t m{0};
|
||||||
|
uint8_t h{0};
|
||||||
|
uint8_t checksum; // checksum
|
||||||
|
uint8_t address;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct ube24_t { // NOLINT(readability-identifier-naming,altera-struct-pack-align)
|
||||||
|
uint8_t l{0};
|
||||||
|
uint8_t m{0};
|
||||||
|
uint8_t h{0};
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct sbe24_t { // NOLINT(readability-identifier-naming,altera-struct-pack-align)
|
||||||
|
uint8_t l{0};
|
||||||
|
uint8_t m{0};
|
||||||
|
int8_t h{0};
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
template<typename... Ts> class ResetEnergyAction;
|
||||||
|
|
||||||
|
class BL0906;
|
||||||
|
|
||||||
|
using ActionCallbackFuncPtr = void (BL0906::*)();
|
||||||
|
|
||||||
|
class BL0906 : public PollingComponent, public uart::UARTDevice {
|
||||||
|
SUB_SENSOR(voltage)
|
||||||
|
SUB_SENSOR(current_1)
|
||||||
|
SUB_SENSOR(current_2)
|
||||||
|
SUB_SENSOR(current_3)
|
||||||
|
SUB_SENSOR(current_4)
|
||||||
|
SUB_SENSOR(current_5)
|
||||||
|
SUB_SENSOR(current_6)
|
||||||
|
SUB_SENSOR(power_1)
|
||||||
|
SUB_SENSOR(power_2)
|
||||||
|
SUB_SENSOR(power_3)
|
||||||
|
SUB_SENSOR(power_4)
|
||||||
|
SUB_SENSOR(power_5)
|
||||||
|
SUB_SENSOR(power_6)
|
||||||
|
SUB_SENSOR(total_power)
|
||||||
|
SUB_SENSOR(energy_1)
|
||||||
|
SUB_SENSOR(energy_2)
|
||||||
|
SUB_SENSOR(energy_3)
|
||||||
|
SUB_SENSOR(energy_4)
|
||||||
|
SUB_SENSOR(energy_5)
|
||||||
|
SUB_SENSOR(energy_6)
|
||||||
|
SUB_SENSOR(total_energy)
|
||||||
|
SUB_SENSOR(frequency)
|
||||||
|
SUB_SENSOR(temperature)
|
||||||
|
|
||||||
|
public:
|
||||||
|
void loop() override;
|
||||||
|
|
||||||
|
void update() override;
|
||||||
|
void setup() override;
|
||||||
|
void dump_config() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
template<typename... Ts> friend class ResetEnergyAction;
|
||||||
|
|
||||||
|
void reset_energy_();
|
||||||
|
|
||||||
|
void read_data_(uint8_t address, float reference, sensor::Sensor *sensor);
|
||||||
|
|
||||||
|
void bias_correction_(uint8_t address, float measurements, float correction);
|
||||||
|
|
||||||
|
uint8_t current_channel_{0};
|
||||||
|
size_t enqueue_action_(ActionCallbackFuncPtr function);
|
||||||
|
void handle_actions_();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<ActionCallbackFuncPtr> action_queue_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename... Ts> class ResetEnergyAction : public Action<Ts...>, public Parented<BL0906> {
|
||||||
|
public:
|
||||||
|
void play(Ts... x) override { this->parent_->enqueue_action_(&BL0906::reset_energy_); }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace bl0906
|
||||||
|
} // namespace esphome
|
4
esphome/components/bl0906/const.py
Normal file
4
esphome/components/bl0906/const.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# const.py
|
||||||
|
ICON_ENERGY = "mdi:lightning-bolt"
|
||||||
|
ICON_FREQUENCY = "mdi:cosine-wave"
|
||||||
|
ICON_VOLTAGE = "mdi:sine-wave"
|
122
esphome/components/bl0906/constants.h
Normal file
122
esphome/components/bl0906/constants.h
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace bl0906 {
|
||||||
|
|
||||||
|
// Total power conversion
|
||||||
|
static const float BL0906_WATT = 16 * 1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) /
|
||||||
|
(40.41259 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000);
|
||||||
|
// Total Energy conversion
|
||||||
|
static const float BL0906_CF = 16 * 4194304 * 0.032768 * 16 /
|
||||||
|
(3600000 * 16 *
|
||||||
|
(40.4125 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000 /
|
||||||
|
(1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000))));
|
||||||
|
// Frequency conversion
|
||||||
|
static const float BL0906_FREF = 10000000;
|
||||||
|
// Temperature conversion
|
||||||
|
static const float BL0906_TREF = 12.5 / 59 - 40;
|
||||||
|
// Current conversion
|
||||||
|
static const float BL0906_IREF = 1.097 / (12875 * 1 * (5.1 + 5.1) * 1000 / 2000);
|
||||||
|
// Voltage conversion
|
||||||
|
static const float BL0906_UREF = 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) / (13162 * 1 * 100 * 1000);
|
||||||
|
// Power conversion
|
||||||
|
static const float BL0906_PREF = 1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) /
|
||||||
|
(40.41259 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000);
|
||||||
|
// Energy conversion
|
||||||
|
static const float BL0906_EREF = 4194304 * 0.032768 * 16 /
|
||||||
|
(3600000 * 16 *
|
||||||
|
(40.4125 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000 /
|
||||||
|
(1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000))));
|
||||||
|
// Current coefficient
|
||||||
|
static const float BL0906_KI = 12875 * 1 * (5.1 + 5.1) * 1000 / 2000 / 1.097;
|
||||||
|
// Power coefficient
|
||||||
|
static const float BL0906_KP = 40.4125 * ((5.1 + 5.1) * 1000 / 2000) * 1 * 100 * 1 * 1000 / 1.097 / 1.097 /
|
||||||
|
(20000 + 20000 + 20000 + 20000 + 20000);
|
||||||
|
|
||||||
|
static const uint8_t USR_WRPROT_WITABLE[6] = {0xCA, 0x9E, 0x55, 0x55, 0x00, 0xB7};
|
||||||
|
static const uint8_t USR_WRPROT_ONLYREAD[6] = {0xCA, 0x9E, 0x00, 0x00, 0x00, 0x61};
|
||||||
|
|
||||||
|
static const uint8_t BL0906_READ_COMMAND = 0x35;
|
||||||
|
static const uint8_t BL0906_WRITE_COMMAND = 0xCA;
|
||||||
|
|
||||||
|
// Register address
|
||||||
|
// Voltage
|
||||||
|
static const uint8_t BL0906_V_RMS = 0x16;
|
||||||
|
|
||||||
|
// Total power
|
||||||
|
static const uint8_t BL0906_WATT_SUM = 0X2C;
|
||||||
|
|
||||||
|
// Current1~6
|
||||||
|
static const uint8_t BL0906_I_1_RMS = 0x0D; // current_1
|
||||||
|
static const uint8_t BL0906_I_2_RMS = 0x0E;
|
||||||
|
static const uint8_t BL0906_I_3_RMS = 0x0F;
|
||||||
|
static const uint8_t BL0906_I_4_RMS = 0x10;
|
||||||
|
static const uint8_t BL0906_I_5_RMS = 0x13;
|
||||||
|
static const uint8_t BL0906_I_6_RMS = 0x14; // current_6
|
||||||
|
|
||||||
|
// Power1~6
|
||||||
|
static const uint8_t BL0906_WATT_1 = 0X23; // power_1
|
||||||
|
static const uint8_t BL0906_WATT_2 = 0X24;
|
||||||
|
static const uint8_t BL0906_WATT_3 = 0X25;
|
||||||
|
static const uint8_t BL0906_WATT_4 = 0X26;
|
||||||
|
static const uint8_t BL0906_WATT_5 = 0X29;
|
||||||
|
static const uint8_t BL0906_WATT_6 = 0X2A; // power_6
|
||||||
|
|
||||||
|
// Active pulse count, unsigned
|
||||||
|
static const uint8_t BL0906_CF_1_CNT = 0X30; // Channel_1
|
||||||
|
static const uint8_t BL0906_CF_2_CNT = 0X31;
|
||||||
|
static const uint8_t BL0906_CF_3_CNT = 0X32;
|
||||||
|
static const uint8_t BL0906_CF_4_CNT = 0X33;
|
||||||
|
static const uint8_t BL0906_CF_5_CNT = 0X36;
|
||||||
|
static const uint8_t BL0906_CF_6_CNT = 0X37; // Channel_6
|
||||||
|
|
||||||
|
// Total active pulse count, unsigned
|
||||||
|
static const uint8_t BL0906_CF_SUM_CNT = 0X39;
|
||||||
|
|
||||||
|
// Voltage frequency cycle
|
||||||
|
static const uint8_t BL0906_FREQUENCY = 0X4E;
|
||||||
|
|
||||||
|
// Internal temperature
|
||||||
|
static const uint8_t BL0906_TEMPERATURE = 0X5E;
|
||||||
|
|
||||||
|
// Calibration register
|
||||||
|
// RMS gain adjustment register
|
||||||
|
static const uint8_t BL0906_RMSGN_1 = 0x6D; // Channel_1
|
||||||
|
static const uint8_t BL0906_RMSGN_2 = 0x6E;
|
||||||
|
static const uint8_t BL0906_RMSGN_3 = 0x6F;
|
||||||
|
static const uint8_t BL0906_RMSGN_4 = 0x70;
|
||||||
|
static const uint8_t BL0906_RMSGN_5 = 0x73;
|
||||||
|
static const uint8_t BL0906_RMSGN_6 = 0x74; // Channel_6
|
||||||
|
|
||||||
|
// RMS offset correction register
|
||||||
|
static const uint8_t BL0906_RMSOS_1 = 0x78; // Channel_1
|
||||||
|
static const uint8_t BL0906_RMSOS_2 = 0x79;
|
||||||
|
static const uint8_t BL0906_RMSOS_3 = 0x7A;
|
||||||
|
static const uint8_t BL0906_RMSOS_4 = 0x7B;
|
||||||
|
static const uint8_t BL0906_RMSOS_5 = 0x7E;
|
||||||
|
static const uint8_t BL0906_RMSOS_6 = 0x7F; // Channel_6
|
||||||
|
|
||||||
|
// Active power gain adjustment register
|
||||||
|
static const uint8_t BL0906_WATTGN_1 = 0xB7; // Channel_1
|
||||||
|
static const uint8_t BL0906_WATTGN_2 = 0xB8;
|
||||||
|
static const uint8_t BL0906_WATTGN_3 = 0xB9;
|
||||||
|
static const uint8_t BL0906_WATTGN_4 = 0xBA;
|
||||||
|
static const uint8_t BL0906_WATTGN_5 = 0xBD;
|
||||||
|
static const uint8_t BL0906_WATTGN_6 = 0xBE; // Channel_6
|
||||||
|
|
||||||
|
// User write protection setting register,
|
||||||
|
// You must first write 0x5555 to the write protection setting register before writing to other registers.
|
||||||
|
static const uint8_t BL0906_USR_WRPROT = 0x9E;
|
||||||
|
|
||||||
|
// Reset Register
|
||||||
|
static const uint8_t BL0906_SOFT_RESET = 0x9F;
|
||||||
|
|
||||||
|
const uint8_t BL0906_INIT[2][6] = {
|
||||||
|
// Reset to default
|
||||||
|
{BL0906_WRITE_COMMAND, BL0906_SOFT_RESET, 0x5A, 0x5A, 0x5A, 0x52},
|
||||||
|
// Enable User Operation Write
|
||||||
|
{BL0906_WRITE_COMMAND, BL0906_USR_WRPROT, 0x55, 0x55, 0x00, 0xB7}};
|
||||||
|
|
||||||
|
} // namespace bl0906
|
||||||
|
} // namespace esphome
|
184
esphome/components/bl0906/sensor.py
Normal file
184
esphome/components/bl0906/sensor.py
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
from esphome import automation
|
||||||
|
from esphome.automation import maybe_simple_id
|
||||||
|
import esphome.codegen as cg
|
||||||
|
from esphome.components import sensor, uart
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
from esphome.const import (
|
||||||
|
CONF_CHANNEL,
|
||||||
|
CONF_CURRENT,
|
||||||
|
CONF_ENERGY,
|
||||||
|
CONF_FREQUENCY,
|
||||||
|
CONF_ID,
|
||||||
|
CONF_NAME,
|
||||||
|
CONF_POWER,
|
||||||
|
CONF_TEMPERATURE,
|
||||||
|
CONF_TOTAL_POWER,
|
||||||
|
CONF_VOLTAGE,
|
||||||
|
DEVICE_CLASS_CURRENT,
|
||||||
|
DEVICE_CLASS_ENERGY,
|
||||||
|
DEVICE_CLASS_FREQUENCY,
|
||||||
|
DEVICE_CLASS_POWER,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
DEVICE_CLASS_VOLTAGE,
|
||||||
|
ICON_CURRENT_AC,
|
||||||
|
ICON_POWER,
|
||||||
|
ICON_THERMOMETER,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
UNIT_AMPERE,
|
||||||
|
UNIT_CELSIUS,
|
||||||
|
UNIT_HERTZ,
|
||||||
|
UNIT_KILOWATT_HOURS,
|
||||||
|
UNIT_VOLT,
|
||||||
|
UNIT_WATT,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Import ICONS not included in esphome's const.py, from the local components const.py
|
||||||
|
from .const import ICON_ENERGY, ICON_FREQUENCY, ICON_VOLTAGE
|
||||||
|
|
||||||
|
DEPENDENCIES = ["uart"]
|
||||||
|
AUTO_LOAD = ["bl0906"]
|
||||||
|
CONF_TOTAL_ENERGY = "total_energy"
|
||||||
|
|
||||||
|
bl0906_ns = cg.esphome_ns.namespace("bl0906")
|
||||||
|
BL0906 = bl0906_ns.class_("BL0906", cg.PollingComponent, uart.UARTDevice)
|
||||||
|
ResetEnergyAction = bl0906_ns.class_("ResetEnergyAction", automation.Action)
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = (
|
||||||
|
cv.Schema(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.declare_id(BL0906),
|
||||||
|
cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(
|
||||||
|
icon=ICON_FREQUENCY,
|
||||||
|
accuracy_decimals=0,
|
||||||
|
device_class=DEVICE_CLASS_FREQUENCY,
|
||||||
|
unit_of_measurement=UNIT_HERTZ,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
||||||
|
icon=ICON_THERMOMETER,
|
||||||
|
accuracy_decimals=0,
|
||||||
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||||
|
unit_of_measurement=UNIT_CELSIUS,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(
|
||||||
|
icon=ICON_VOLTAGE,
|
||||||
|
accuracy_decimals=1,
|
||||||
|
device_class=DEVICE_CLASS_VOLTAGE,
|
||||||
|
unit_of_measurement=UNIT_VOLT,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_TOTAL_POWER): sensor.sensor_schema(
|
||||||
|
icon=ICON_POWER,
|
||||||
|
accuracy_decimals=3,
|
||||||
|
device_class=DEVICE_CLASS_POWER,
|
||||||
|
unit_of_measurement=UNIT_WATT,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_TOTAL_ENERGY): sensor.sensor_schema(
|
||||||
|
icon=ICON_ENERGY,
|
||||||
|
accuracy_decimals=3,
|
||||||
|
device_class=DEVICE_CLASS_ENERGY,
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
unit_of_measurement=UNIT_KILOWATT_HOURS,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.extend(
|
||||||
|
cv.Schema(
|
||||||
|
{
|
||||||
|
cv.Optional(f"{CONF_CHANNEL}_{i + 1}"): cv.Schema(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_CURRENT): cv.maybe_simple_value(
|
||||||
|
sensor.sensor_schema(
|
||||||
|
icon=ICON_CURRENT_AC,
|
||||||
|
accuracy_decimals=3,
|
||||||
|
device_class=DEVICE_CLASS_CURRENT,
|
||||||
|
unit_of_measurement=UNIT_AMPERE,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
key=CONF_NAME,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_POWER): cv.maybe_simple_value(
|
||||||
|
sensor.sensor_schema(
|
||||||
|
icon=ICON_POWER,
|
||||||
|
accuracy_decimals=0,
|
||||||
|
device_class=DEVICE_CLASS_POWER,
|
||||||
|
unit_of_measurement=UNIT_WATT,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
key=CONF_NAME,
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ENERGY): cv.maybe_simple_value(
|
||||||
|
sensor.sensor_schema(
|
||||||
|
icon=ICON_ENERGY,
|
||||||
|
accuracy_decimals=3,
|
||||||
|
device_class=DEVICE_CLASS_ENERGY,
|
||||||
|
unit_of_measurement=UNIT_KILOWATT_HOURS,
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
),
|
||||||
|
key=CONF_NAME,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
for i in range(6)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.extend(uart.UART_DEVICE_SCHEMA)
|
||||||
|
.extend(cv.polling_component_schema("60s"))
|
||||||
|
)
|
||||||
|
|
||||||
|
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
||||||
|
"bl0906", baud_rate=19200, require_tx=True, require_rx=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@automation.register_action(
|
||||||
|
"bl0906.reset_energy",
|
||||||
|
ResetEnergyAction,
|
||||||
|
maybe_simple_id(
|
||||||
|
{
|
||||||
|
cv.Required(CONF_ID): cv.use_id(BL0906),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def reset_energy_to_code(config, action_id, template_arg, args):
|
||||||
|
paren = await cg.get_variable(config[CONF_ID])
|
||||||
|
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
|
|
||||||
|
|
||||||
|
async def to_code(config):
|
||||||
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
await cg.register_component(var, config)
|
||||||
|
await uart.register_uart_device(var, config)
|
||||||
|
if frequency_config := config.get(CONF_FREQUENCY):
|
||||||
|
sens = await sensor.new_sensor(frequency_config)
|
||||||
|
cg.add(var.set_frequency_sensor(sens))
|
||||||
|
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||||
|
sens = await sensor.new_sensor(temperature_config)
|
||||||
|
cg.add(var.set_temperature_sensor(sens))
|
||||||
|
if voltage_config := config.get(CONF_VOLTAGE):
|
||||||
|
sens = await sensor.new_sensor(voltage_config)
|
||||||
|
cg.add(var.set_voltage_sensor(sens))
|
||||||
|
|
||||||
|
for i in range(6):
|
||||||
|
if channel_config := config.get(f"{CONF_CHANNEL}_{i + 1}"):
|
||||||
|
if current_config := channel_config.get(CONF_CURRENT):
|
||||||
|
sens = await sensor.new_sensor(current_config)
|
||||||
|
cg.add(getattr(var, f"set_current_{i + 1}_sensor")(sens))
|
||||||
|
if power_config := channel_config.get(CONF_POWER):
|
||||||
|
sens = await sensor.new_sensor(power_config)
|
||||||
|
cg.add(getattr(var, f"set_power_{i + 1}_sensor")(sens))
|
||||||
|
if energy_config := channel_config.get(CONF_ENERGY):
|
||||||
|
sens = await sensor.new_sensor(energy_config)
|
||||||
|
cg.add(getattr(var, f"set_energy_{i + 1}_sensor")(sens))
|
||||||
|
|
||||||
|
if total_power_config := config.get(CONF_TOTAL_POWER):
|
||||||
|
sens = await sensor.new_sensor(total_power_config)
|
||||||
|
cg.add(var.set_total_power_sensor(sens))
|
||||||
|
|
||||||
|
if total_energy_config := config.get(CONF_TOTAL_ENERGY):
|
||||||
|
sens = await sensor.new_sensor(total_energy_config)
|
||||||
|
cg.add(var.set_total_energy_sensor(sens))
|
|
@ -2,6 +2,8 @@
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
|
// Datasheet: https://www.belling.com.cn/media/file_object/bel_product/BL0942/datasheet/BL0942_V1.06_en.pdf
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace bl0942 {
|
namespace bl0942 {
|
||||||
|
|
||||||
|
@ -12,33 +14,41 @@ static const uint8_t BL0942_FULL_PACKET = 0xAA;
|
||||||
static const uint8_t BL0942_PACKET_HEADER = 0x55;
|
static const uint8_t BL0942_PACKET_HEADER = 0x55;
|
||||||
|
|
||||||
static const uint8_t BL0942_WRITE_COMMAND = 0xA8;
|
static const uint8_t BL0942_WRITE_COMMAND = 0xA8;
|
||||||
static const uint8_t BL0942_REG_I_FAST_RMS_CTRL = 0x10;
|
|
||||||
static const uint8_t BL0942_REG_MODE = 0x18;
|
static const uint8_t BL0942_REG_I_RMSOS = 0x12;
|
||||||
static const uint8_t BL0942_REG_SOFT_RESET = 0x19;
|
static const uint8_t BL0942_REG_WA_CREEP = 0x14;
|
||||||
static const uint8_t BL0942_REG_USR_WRPROT = 0x1A;
|
static const uint8_t BL0942_REG_I_FAST_RMS_TH = 0x15;
|
||||||
|
static const uint8_t BL0942_REG_I_FAST_RMS_CYC = 0x16;
|
||||||
|
static const uint8_t BL0942_REG_FREQ_CYC = 0x17;
|
||||||
|
static const uint8_t BL0942_REG_OT_FUNX = 0x18;
|
||||||
|
static const uint8_t BL0942_REG_MODE = 0x19;
|
||||||
|
static const uint8_t BL0942_REG_SOFT_RESET = 0x1C;
|
||||||
|
static const uint8_t BL0942_REG_USR_WRPROT = 0x1D;
|
||||||
static const uint8_t BL0942_REG_TPS_CTRL = 0x1B;
|
static const uint8_t BL0942_REG_TPS_CTRL = 0x1B;
|
||||||
|
|
||||||
// TODO: Confirm insialisation works as intended
|
static const uint32_t BL0942_REG_MODE_RESV = 0x03;
|
||||||
const uint8_t BL0942_INIT[5][6] = {
|
static const uint32_t BL0942_REG_MODE_CF_EN = 0x04;
|
||||||
// Reset to default
|
static const uint32_t BL0942_REG_MODE_RMS_UPDATE_SEL = 0x08;
|
||||||
{BL0942_WRITE_COMMAND, BL0942_REG_SOFT_RESET, 0x5A, 0x5A, 0x5A, 0x38},
|
static const uint32_t BL0942_REG_MODE_FAST_RMS_SEL = 0x10;
|
||||||
// Enable User Operation Write
|
static const uint32_t BL0942_REG_MODE_AC_FREQ_SEL = 0x20;
|
||||||
{BL0942_WRITE_COMMAND, BL0942_REG_USR_WRPROT, 0x55, 0x00, 0x00, 0xF0},
|
static const uint32_t BL0942_REG_MODE_CF_CNT_CLR_SEL = 0x40;
|
||||||
// 0x0100 = CF_UNABLE energy pulse, AC_FREQ_SEL 50Hz, RMS_UPDATE_SEL 800mS
|
static const uint32_t BL0942_REG_MODE_CF_CNT_ADD_SEL = 0x80;
|
||||||
{BL0942_WRITE_COMMAND, BL0942_REG_MODE, 0x00, 0x10, 0x00, 0x37},
|
static const uint32_t BL0942_REG_MODE_UART_RATE_19200 = 0x200;
|
||||||
// 0x47FF = Over-current and leakage alarm on, Automatic temperature measurement, Interval 100mS
|
static const uint32_t BL0942_REG_MODE_UART_RATE_38400 = 0x300;
|
||||||
{BL0942_WRITE_COMMAND, BL0942_REG_TPS_CTRL, 0xFF, 0x47, 0x00, 0xFE},
|
static const uint32_t BL0942_REG_MODE_DEFAULT =
|
||||||
// 0x181C = Half cycle, Fast RMS threshold 6172
|
BL0942_REG_MODE_RESV | BL0942_REG_MODE_CF_EN | BL0942_REG_MODE_CF_CNT_ADD_SEL;
|
||||||
{BL0942_WRITE_COMMAND, BL0942_REG_I_FAST_RMS_CTRL, 0x1C, 0x18, 0x00, 0x1B}};
|
|
||||||
|
static const uint32_t BL0942_REG_SOFT_RESET_MAGIC = 0x5a5a5a;
|
||||||
|
static const uint32_t BL0942_REG_USR_WRPROT_MAGIC = 0x55;
|
||||||
|
|
||||||
void BL0942::loop() {
|
void BL0942::loop() {
|
||||||
DataPacket buffer;
|
DataPacket buffer;
|
||||||
if (!this->available()) {
|
if (!this->available()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (read_array((uint8_t *) &buffer, sizeof(buffer))) {
|
if (this->read_array((uint8_t *) &buffer, sizeof(buffer))) {
|
||||||
if (validate_checksum(&buffer)) {
|
if (this->validate_checksum_(&buffer)) {
|
||||||
received_package_(&buffer);
|
this->received_package_(&buffer);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");
|
ESP_LOGW(TAG, "Junk on wire. Throwing away partial message");
|
||||||
|
@ -47,8 +57,8 @@ void BL0942::loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BL0942::validate_checksum(DataPacket *data) {
|
bool BL0942::validate_checksum_(DataPacket *data) {
|
||||||
uint8_t checksum = BL0942_READ_COMMAND;
|
uint8_t checksum = BL0942_READ_COMMAND | this->address_;
|
||||||
// Whole package but checksum
|
// Whole package but checksum
|
||||||
uint8_t *raw = (uint8_t *) data;
|
uint8_t *raw = (uint8_t *) data;
|
||||||
for (uint32_t i = 0; i < sizeof(*data) - 1; i++) {
|
for (uint32_t i = 0; i < sizeof(*data) - 1; i++) {
|
||||||
|
@ -61,17 +71,58 @@ bool BL0942::validate_checksum(DataPacket *data) {
|
||||||
return checksum == data->checksum;
|
return checksum == data->checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BL0942::update() {
|
void BL0942::write_reg_(uint8_t reg, uint32_t val) {
|
||||||
|
uint8_t pkt[6];
|
||||||
|
|
||||||
this->flush();
|
this->flush();
|
||||||
this->write_byte(BL0942_READ_COMMAND);
|
pkt[0] = BL0942_WRITE_COMMAND | this->address_;
|
||||||
|
pkt[1] = reg;
|
||||||
|
pkt[2] = (val & 0xff);
|
||||||
|
pkt[3] = (val >> 8) & 0xff;
|
||||||
|
pkt[4] = (val >> 16) & 0xff;
|
||||||
|
pkt[5] = (pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4]) ^ 0xff;
|
||||||
|
this->write_array(pkt, 6);
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int BL0942::read_reg_(uint8_t reg) {
|
||||||
|
union {
|
||||||
|
uint8_t b[4];
|
||||||
|
uint32_le_t le32;
|
||||||
|
} resp;
|
||||||
|
|
||||||
|
this->write_byte(BL0942_READ_COMMAND | this->address_);
|
||||||
|
this->write_byte(reg);
|
||||||
|
this->flush();
|
||||||
|
if (this->read_array(resp.b, 4) &&
|
||||||
|
resp.b[3] ==
|
||||||
|
(uint8_t) ((BL0942_READ_COMMAND + this->address_ + reg + resp.b[0] + resp.b[1] + resp.b[2]) ^ 0xff)) {
|
||||||
|
resp.b[3] = 0;
|
||||||
|
return resp.le32;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BL0942::update() {
|
||||||
|
this->write_byte(BL0942_READ_COMMAND | this->address_);
|
||||||
this->write_byte(BL0942_FULL_PACKET);
|
this->write_byte(BL0942_FULL_PACKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BL0942::setup() {
|
void BL0942::setup() {
|
||||||
for (auto *i : BL0942_INIT) {
|
this->write_reg_(BL0942_REG_USR_WRPROT, BL0942_REG_USR_WRPROT_MAGIC);
|
||||||
this->write_array(i, 6);
|
this->write_reg_(BL0942_REG_SOFT_RESET, BL0942_REG_SOFT_RESET_MAGIC);
|
||||||
delay(1);
|
|
||||||
}
|
uint32_t mode = BL0942_REG_MODE_DEFAULT;
|
||||||
|
mode |= BL0942_REG_MODE_RMS_UPDATE_SEL; /* 800ms refresh time */
|
||||||
|
if (this->line_freq_ == LINE_FREQUENCY_60HZ)
|
||||||
|
mode |= BL0942_REG_MODE_AC_FREQ_SEL;
|
||||||
|
this->write_reg_(BL0942_REG_MODE, mode);
|
||||||
|
|
||||||
|
this->write_reg_(BL0942_REG_USR_WRPROT, 0);
|
||||||
|
|
||||||
|
if (this->read_reg_(BL0942_REG_MODE) != mode)
|
||||||
|
this->status_set_warning("BL0942 setup failed!");
|
||||||
|
|
||||||
this->flush();
|
this->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,13 +155,15 @@ void BL0942::received_package_(DataPacket *data) {
|
||||||
if (frequency_sensor_ != nullptr) {
|
if (frequency_sensor_ != nullptr) {
|
||||||
frequency_sensor_->publish_state(frequency);
|
frequency_sensor_->publish_state(frequency);
|
||||||
}
|
}
|
||||||
|
this->status_clear_warning();
|
||||||
ESP_LOGV(TAG, "BL0942: U %fV, I %fA, P %fW, Cnt %" PRId32 ", ∫P %fkWh, frequency %fHz, status 0x%08X", v_rms, i_rms,
|
ESP_LOGV(TAG, "BL0942: U %fV, I %fA, P %fW, Cnt %" PRId32 ", ∫P %fkWh, frequency %fHz, status 0x%08X", v_rms, i_rms,
|
||||||
watt, cf_cnt, total_energy_consumption, frequency, data->status);
|
watt, cf_cnt, total_energy_consumption, frequency, data->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BL0942::dump_config() { // NOLINT(readability-function-cognitive-complexity)
|
void BL0942::dump_config() { // NOLINT(readability-function-cognitive-complexity)
|
||||||
ESP_LOGCONFIG(TAG, "BL0942:");
|
ESP_LOGCONFIG(TAG, "BL0942:");
|
||||||
|
ESP_LOGCONFIG(TAG, " Address: %d", this->address_);
|
||||||
|
ESP_LOGCONFIG(TAG, " Nominal line frequency: %d Hz", this->line_freq_);
|
||||||
LOG_SENSOR("", "Voltage", this->voltage_sensor_);
|
LOG_SENSOR("", "Voltage", this->voltage_sensor_);
|
||||||
LOG_SENSOR("", "Current", this->current_sensor_);
|
LOG_SENSOR("", "Current", this->current_sensor_);
|
||||||
LOG_SENSOR("", "Power", this->power_sensor_);
|
LOG_SENSOR("", "Power", this->power_sensor_);
|
||||||
|
|
|
@ -28,6 +28,11 @@ struct DataPacket {
|
||||||
uint8_t checksum;
|
uint8_t checksum;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
enum LineFrequency : uint8_t {
|
||||||
|
LINE_FREQUENCY_50HZ = 50,
|
||||||
|
LINE_FREQUENCY_60HZ = 60,
|
||||||
|
};
|
||||||
|
|
||||||
class BL0942 : public PollingComponent, public uart::UARTDevice {
|
class BL0942 : public PollingComponent, public uart::UARTDevice {
|
||||||
public:
|
public:
|
||||||
void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
|
void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
|
||||||
|
@ -35,9 +40,10 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
|
||||||
void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
|
void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
|
||||||
void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
|
void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
|
||||||
void set_frequency_sensor(sensor::Sensor *frequency_sensor) { frequency_sensor_ = frequency_sensor; }
|
void set_frequency_sensor(sensor::Sensor *frequency_sensor) { frequency_sensor_ = frequency_sensor; }
|
||||||
|
void set_line_freq(LineFrequency freq) { this->line_freq_ = freq; }
|
||||||
|
void set_address(uint8_t address) { this->address_ = address; }
|
||||||
|
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
@ -59,9 +65,12 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
|
||||||
float current_reference_ = BL0942_IREF;
|
float current_reference_ = BL0942_IREF;
|
||||||
// Divide by this to turn into kWh
|
// Divide by this to turn into kWh
|
||||||
float energy_reference_ = BL0942_EREF;
|
float energy_reference_ = BL0942_EREF;
|
||||||
|
uint8_t address_ = 0;
|
||||||
|
LineFrequency line_freq_ = LINE_FREQUENCY_50HZ;
|
||||||
|
|
||||||
static bool validate_checksum(DataPacket *data);
|
bool validate_checksum_(DataPacket *data);
|
||||||
|
int read_reg_(uint8_t reg);
|
||||||
|
void write_reg_(uint8_t reg, uint32_t val);
|
||||||
void received_package_(DataPacket *data);
|
void received_package_(DataPacket *data);
|
||||||
};
|
};
|
||||||
} // namespace bl0942
|
} // namespace bl0942
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome.components import sensor, uart
|
from esphome.components import sensor, uart
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
|
CONF_ADDRESS,
|
||||||
CONF_CURRENT,
|
CONF_CURRENT,
|
||||||
CONF_ENERGY,
|
CONF_ENERGY,
|
||||||
|
CONF_FREQUENCY,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
|
CONF_LINE_FREQUENCY,
|
||||||
CONF_POWER,
|
CONF_POWER,
|
||||||
CONF_VOLTAGE,
|
CONF_VOLTAGE,
|
||||||
CONF_FREQUENCY,
|
|
||||||
DEVICE_CLASS_CURRENT,
|
DEVICE_CLASS_CURRENT,
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
|
DEVICE_CLASS_FREQUENCY,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
DEVICE_CLASS_VOLTAGE,
|
DEVICE_CLASS_VOLTAGE,
|
||||||
DEVICE_CLASS_FREQUENCY,
|
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
UNIT_AMPERE,
|
UNIT_AMPERE,
|
||||||
|
UNIT_HERTZ,
|
||||||
UNIT_KILOWATT_HOURS,
|
UNIT_KILOWATT_HOURS,
|
||||||
UNIT_VOLT,
|
UNIT_VOLT,
|
||||||
UNIT_WATT,
|
UNIT_WATT,
|
||||||
UNIT_HERTZ,
|
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
DEPENDENCIES = ["uart"]
|
DEPENDENCIES = ["uart"]
|
||||||
|
@ -27,6 +29,12 @@ DEPENDENCIES = ["uart"]
|
||||||
bl0942_ns = cg.esphome_ns.namespace("bl0942")
|
bl0942_ns = cg.esphome_ns.namespace("bl0942")
|
||||||
BL0942 = bl0942_ns.class_("BL0942", cg.PollingComponent, uart.UARTDevice)
|
BL0942 = bl0942_ns.class_("BL0942", cg.PollingComponent, uart.UARTDevice)
|
||||||
|
|
||||||
|
LineFrequency = bl0942_ns.enum("LineFrequency")
|
||||||
|
LINE_FREQS = {
|
||||||
|
50: LineFrequency.LINE_FREQUENCY_50HZ,
|
||||||
|
60: LineFrequency.LINE_FREQUENCY_60HZ,
|
||||||
|
}
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
|
@ -61,6 +69,14 @@ CONFIG_SCHEMA = (
|
||||||
device_class=DEVICE_CLASS_FREQUENCY,
|
device_class=DEVICE_CLASS_FREQUENCY,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_LINE_FREQUENCY, default="50HZ"): cv.All(
|
||||||
|
cv.frequency,
|
||||||
|
cv.enum(
|
||||||
|
LINE_FREQS,
|
||||||
|
int=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ADDRESS, default=0): cv.int_range(min=0, max=3),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.extend(cv.polling_component_schema("60s"))
|
.extend(cv.polling_component_schema("60s"))
|
||||||
|
@ -88,3 +104,5 @@ async def to_code(config):
|
||||||
if frequency_config := config.get(CONF_FREQUENCY):
|
if frequency_config := config.get(CONF_FREQUENCY):
|
||||||
sens = await sensor.new_sensor(frequency_config)
|
sens = await sensor.new_sensor(frequency_config)
|
||||||
cg.add(var.set_frequency_sensor(sens))
|
cg.add(var.set_frequency_sensor(sens))
|
||||||
|
cg.add(var.set_line_freq(config[CONF_LINE_FREQUENCY]))
|
||||||
|
cg.add(var.set_address(config[CONF_ADDRESS]))
|
||||||
|
|
|
@ -186,7 +186,7 @@ async def datetime_date_set_to_code(config, action_id, template_arg, args):
|
||||||
|
|
||||||
date_config = config[CONF_DATE]
|
date_config = config[CONF_DATE]
|
||||||
if cg.is_template(date_config):
|
if cg.is_template(date_config):
|
||||||
template_ = await cg.templatable(date_config, [], cg.ESPTime)
|
template_ = await cg.templatable(date_config, args, cg.ESPTime)
|
||||||
cg.add(action_var.set_date(template_))
|
cg.add(action_var.set_date(template_))
|
||||||
else:
|
else:
|
||||||
date_struct = cg.StructInitializer(
|
date_struct = cg.StructInitializer(
|
||||||
|
@ -217,7 +217,7 @@ async def datetime_time_set_to_code(config, action_id, template_arg, args):
|
||||||
|
|
||||||
time_config = config[CONF_TIME]
|
time_config = config[CONF_TIME]
|
||||||
if cg.is_template(time_config):
|
if cg.is_template(time_config):
|
||||||
template_ = await cg.templatable(time_config, [], cg.ESPTime)
|
template_ = await cg.templatable(time_config, args, cg.ESPTime)
|
||||||
cg.add(action_var.set_time(template_))
|
cg.add(action_var.set_time(template_))
|
||||||
else:
|
else:
|
||||||
time_struct = cg.StructInitializer(
|
time_struct = cg.StructInitializer(
|
||||||
|
@ -248,7 +248,7 @@ async def datetime_datetime_set_to_code(config, action_id, template_arg, args):
|
||||||
|
|
||||||
datetime_config = config[CONF_DATETIME]
|
datetime_config = config[CONF_DATETIME]
|
||||||
if cg.is_template(datetime_config):
|
if cg.is_template(datetime_config):
|
||||||
template_ = await cg.templatable(datetime_config, [], cg.ESPTime)
|
template_ = await cg.templatable(datetime_config, args, cg.ESPTime)
|
||||||
cg.add(action_var.set_datetime(template_))
|
cg.add(action_var.set_datetime(template_))
|
||||||
else:
|
else:
|
||||||
datetime_struct = cg.StructInitializer(
|
datetime_struct = cg.StructInitializer(
|
||||||
|
|
|
@ -111,6 +111,7 @@ canbus::Error ESP32Can::send_message(struct canbus::CanFrame *frame) {
|
||||||
.flags = flags,
|
.flags = flags,
|
||||||
.identifier = frame->can_id,
|
.identifier = frame->can_id,
|
||||||
.data_length_code = frame->can_data_length_code,
|
.data_length_code = frame->can_data_length_code,
|
||||||
|
.data = {}, // to suppress warning, data is initialized properly below
|
||||||
};
|
};
|
||||||
if (!frame->remote_transmission_request) {
|
if (!frame->remote_transmission_request) {
|
||||||
memcpy(message.data, frame->data, frame->can_data_length_code);
|
memcpy(message.data, frame->data, frame->can_data_length_code);
|
||||||
|
|
|
@ -38,7 +38,8 @@ void ESP32RMTLEDStripLightOutput::setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ExternalRAMAllocator<rmt_item32_t> rmt_allocator(ExternalRAMAllocator<rmt_item32_t>::ALLOW_FAILURE);
|
ExternalRAMAllocator<rmt_item32_t> rmt_allocator(ExternalRAMAllocator<rmt_item32_t>::ALLOW_FAILURE);
|
||||||
this->rmt_buf_ = rmt_allocator.allocate(buffer_size * 8); // 8 bits per byte, 1 rmt_item32_t per bit
|
this->rmt_buf_ = rmt_allocator.allocate(buffer_size * 8 +
|
||||||
|
1); // 8 bits per byte, 1 rmt_item32_t per bit + 1 rmt_item32_t for reset
|
||||||
|
|
||||||
rmt_config_t config;
|
rmt_config_t config;
|
||||||
memset(&config, 0, sizeof(config));
|
memset(&config, 0, sizeof(config));
|
||||||
|
@ -66,7 +67,7 @@ void ESP32RMTLEDStripLightOutput::setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP32RMTLEDStripLightOutput::set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high,
|
void ESP32RMTLEDStripLightOutput::set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high,
|
||||||
uint32_t bit1_low) {
|
uint32_t bit1_low, uint32_t reset_time_high, uint32_t reset_time_low) {
|
||||||
float ratio = (float) RMT_CLK_FREQ / RMT_CLK_DIV / 1e09f;
|
float ratio = (float) RMT_CLK_FREQ / RMT_CLK_DIV / 1e09f;
|
||||||
|
|
||||||
// 0-bit
|
// 0-bit
|
||||||
|
@ -79,6 +80,11 @@ void ESP32RMTLEDStripLightOutput::set_led_params(uint32_t bit0_high, uint32_t bi
|
||||||
this->bit1_.level0 = 1;
|
this->bit1_.level0 = 1;
|
||||||
this->bit1_.duration1 = (uint32_t) (ratio * bit1_low);
|
this->bit1_.duration1 = (uint32_t) (ratio * bit1_low);
|
||||||
this->bit1_.level1 = 0;
|
this->bit1_.level1 = 0;
|
||||||
|
// reset
|
||||||
|
this->reset_.duration0 = (uint32_t) (ratio * reset_time_high);
|
||||||
|
this->reset_.level0 = 1;
|
||||||
|
this->reset_.duration1 = (uint32_t) (ratio * reset_time_low);
|
||||||
|
this->reset_.level1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) {
|
void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) {
|
||||||
|
@ -118,6 +124,12 @@ void ESP32RMTLEDStripLightOutput::write_state(light::LightState *state) {
|
||||||
psrc++;
|
psrc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->reset_.duration0 > 0 || this->reset_.duration1 > 0) {
|
||||||
|
pdest->val = this->reset_.val;
|
||||||
|
pdest++;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
if (rmt_write_items(this->channel_, this->rmt_buf_, len, false) != ESP_OK) {
|
if (rmt_write_items(this->channel_, this->rmt_buf_, len, false) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "RMT TX error");
|
ESP_LOGE(TAG, "RMT TX error");
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
|
|
|
@ -49,7 +49,8 @@ class ESP32RMTLEDStripLightOutput : public light::AddressableLight {
|
||||||
/// Set a maximum refresh rate in µs as some lights do not like being updated too often.
|
/// Set a maximum refresh rate in µs as some lights do not like being updated too often.
|
||||||
void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
|
void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
|
||||||
|
|
||||||
void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low);
|
void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
|
||||||
|
uint32_t reset_time_high, uint32_t reset_time_low);
|
||||||
|
|
||||||
void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
|
void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
|
||||||
void set_rmt_channel(rmt_channel_t channel) { this->channel_ = channel; }
|
void set_rmt_channel(rmt_channel_t channel) { this->channel_ = channel; }
|
||||||
|
@ -75,7 +76,7 @@ class ESP32RMTLEDStripLightOutput : public light::AddressableLight {
|
||||||
bool is_rgbw_;
|
bool is_rgbw_;
|
||||||
bool is_wrgb_;
|
bool is_wrgb_;
|
||||||
|
|
||||||
rmt_item32_t bit0_, bit1_;
|
rmt_item32_t bit0_, bit1_, reset_;
|
||||||
RGBOrder rgb_order_;
|
RGBOrder rgb_order_;
|
||||||
rmt_channel_t channel_;
|
rmt_channel_t channel_;
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,16 @@ class LEDStripTimings:
|
||||||
bit0_low: int
|
bit0_low: int
|
||||||
bit1_high: int
|
bit1_high: int
|
||||||
bit1_low: int
|
bit1_low: int
|
||||||
|
reset_high: int
|
||||||
|
reset_low: int
|
||||||
|
|
||||||
|
|
||||||
CHIPSETS = {
|
CHIPSETS = {
|
||||||
"WS2812": LEDStripTimings(400, 1000, 1000, 400),
|
"WS2811": LEDStripTimings(300, 1090, 1090, 320, 0, 300000),
|
||||||
"SK6812": LEDStripTimings(300, 900, 600, 600),
|
"WS2812": LEDStripTimings(400, 1000, 1000, 400, 0, 0),
|
||||||
"APA106": LEDStripTimings(350, 1360, 1360, 350),
|
"SK6812": LEDStripTimings(300, 900, 600, 600, 0, 0),
|
||||||
"SM16703": LEDStripTimings(300, 900, 900, 300),
|
"APA106": LEDStripTimings(350, 1360, 1360, 350, 0, 0),
|
||||||
|
"SM16703": LEDStripTimings(300, 900, 900, 300, 0, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +61,8 @@ CONF_BIT0_HIGH = "bit0_high"
|
||||||
CONF_BIT0_LOW = "bit0_low"
|
CONF_BIT0_LOW = "bit0_low"
|
||||||
CONF_BIT1_HIGH = "bit1_high"
|
CONF_BIT1_HIGH = "bit1_high"
|
||||||
CONF_BIT1_LOW = "bit1_low"
|
CONF_BIT1_LOW = "bit1_low"
|
||||||
|
CONF_RESET_HIGH = "reset_high"
|
||||||
|
CONF_RESET_LOW = "reset_low"
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
|
@ -88,6 +93,14 @@ CONFIG_SCHEMA = cv.All(
|
||||||
CONF_BIT1_LOW,
|
CONF_BIT1_LOW,
|
||||||
"custom",
|
"custom",
|
||||||
): cv.positive_time_period_nanoseconds,
|
): cv.positive_time_period_nanoseconds,
|
||||||
|
cv.Optional(
|
||||||
|
CONF_RESET_HIGH,
|
||||||
|
default="0 us",
|
||||||
|
): cv.positive_time_period_nanoseconds,
|
||||||
|
cv.Optional(
|
||||||
|
CONF_RESET_LOW,
|
||||||
|
default="0 us",
|
||||||
|
): cv.positive_time_period_nanoseconds,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
cv.has_exactly_one_key(CONF_CHIPSET, CONF_BIT0_HIGH),
|
cv.has_exactly_one_key(CONF_CHIPSET, CONF_BIT0_HIGH),
|
||||||
|
@ -113,6 +126,8 @@ async def to_code(config):
|
||||||
chipset.bit0_low,
|
chipset.bit0_low,
|
||||||
chipset.bit1_high,
|
chipset.bit1_high,
|
||||||
chipset.bit1_low,
|
chipset.bit1_low,
|
||||||
|
chipset.reset_high,
|
||||||
|
chipset.reset_low,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@ -122,6 +137,8 @@ async def to_code(config):
|
||||||
config[CONF_BIT0_LOW],
|
config[CONF_BIT0_LOW],
|
||||||
config[CONF_BIT1_HIGH],
|
config[CONF_BIT1_HIGH],
|
||||||
config[CONF_BIT1_LOW],
|
config[CONF_BIT1_LOW],
|
||||||
|
config[CONF_RESET_HIGH],
|
||||||
|
config[CONF_RESET_LOW],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome import core, pins
|
from esphome import core, pins
|
||||||
from esphome.components import display, spi, font
|
import esphome.codegen as cg
|
||||||
|
from esphome.components import display, font, spi
|
||||||
from esphome.components.display import validate_rotation
|
from esphome.components.display import validate_rotation
|
||||||
from esphome.core import CORE, HexInt
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
|
CONF_COLOR_ORDER,
|
||||||
CONF_COLOR_PALETTE,
|
CONF_COLOR_PALETTE,
|
||||||
CONF_DC_PIN,
|
CONF_DC_PIN,
|
||||||
CONF_ID,
|
|
||||||
CONF_LAMBDA,
|
|
||||||
CONF_MODEL,
|
|
||||||
CONF_RAW_DATA_ID,
|
|
||||||
CONF_PAGES,
|
|
||||||
CONF_RESET_PIN,
|
|
||||||
CONF_DIMENSIONS,
|
CONF_DIMENSIONS,
|
||||||
CONF_WIDTH,
|
|
||||||
CONF_HEIGHT,
|
CONF_HEIGHT,
|
||||||
CONF_ROTATION,
|
CONF_ID,
|
||||||
|
CONF_INVERT_COLORS,
|
||||||
|
CONF_LAMBDA,
|
||||||
CONF_MIRROR_X,
|
CONF_MIRROR_X,
|
||||||
CONF_MIRROR_Y,
|
CONF_MIRROR_Y,
|
||||||
CONF_SWAP_XY,
|
CONF_MODEL,
|
||||||
CONF_COLOR_ORDER,
|
|
||||||
CONF_OFFSET_HEIGHT,
|
CONF_OFFSET_HEIGHT,
|
||||||
CONF_OFFSET_WIDTH,
|
CONF_OFFSET_WIDTH,
|
||||||
|
CONF_PAGES,
|
||||||
|
CONF_RAW_DATA_ID,
|
||||||
|
CONF_RESET_PIN,
|
||||||
|
CONF_ROTATION,
|
||||||
|
CONF_SWAP_XY,
|
||||||
CONF_TRANSFORM,
|
CONF_TRANSFORM,
|
||||||
CONF_INVERT_COLORS,
|
CONF_WIDTH,
|
||||||
)
|
)
|
||||||
|
from esphome.core import CORE, HexInt
|
||||||
|
|
||||||
DEPENDENCIES = ["spi"]
|
DEPENDENCIES = ["spi"]
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.Optional(CONF_INVERT_DISPLAY): cv.invalid(
|
cv.Optional(CONF_INVERT_DISPLAY): cv.invalid(
|
||||||
"'invert_display' has been replaced by 'invert_colors'"
|
"'invert_display' has been replaced by 'invert_colors'"
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_INVERT_COLORS): cv.boolean,
|
cv.Required(CONF_INVERT_COLORS): cv.boolean,
|
||||||
cv.Optional(CONF_COLOR_ORDER): cv.one_of(*COLOR_ORDERS.keys(), upper=True),
|
cv.Optional(CONF_COLOR_ORDER): cv.one_of(*COLOR_ORDERS.keys(), upper=True),
|
||||||
cv.Exclusive(CONF_ROTATION, CONF_ROTATION): validate_rotation,
|
cv.Exclusive(CONF_ROTATION, CONF_ROTATION): validate_rotation,
|
||||||
cv.Exclusive(CONF_TRANSFORM, CONF_ROTATION): cv.Schema(
|
cv.Exclusive(CONF_TRANSFORM, CONF_ROTATION): cv.Schema(
|
||||||
|
@ -287,5 +287,4 @@ async def to_code(config):
|
||||||
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
|
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
|
||||||
cg.add(var.set_palette(prog_arr))
|
cg.add(var.set_palette(prog_arr))
|
||||||
|
|
||||||
if CONF_INVERT_COLORS in config:
|
cg.add(var.invert_colors(config[CONF_INVERT_COLORS]))
|
||||||
cg.add(var.invert_colors(config[CONF_INVERT_COLORS]))
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ void ILI9XXXDisplay::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, " Swap_xy: %s", YESNO(this->swap_xy_));
|
ESP_LOGCONFIG(TAG, " Swap_xy: %s", YESNO(this->swap_xy_));
|
||||||
ESP_LOGCONFIG(TAG, " Mirror_x: %s", YESNO(this->mirror_x_));
|
ESP_LOGCONFIG(TAG, " Mirror_x: %s", YESNO(this->mirror_x_));
|
||||||
ESP_LOGCONFIG(TAG, " Mirror_y: %s", YESNO(this->mirror_y_));
|
ESP_LOGCONFIG(TAG, " Mirror_y: %s", YESNO(this->mirror_y_));
|
||||||
|
ESP_LOGCONFIG(TAG, " Invert colors: %s", YESNO(this->pre_invertcolors_));
|
||||||
|
|
||||||
if (this->is_failed()) {
|
if (this->is_failed()) {
|
||||||
ESP_LOGCONFIG(TAG, " => Failed to init Memory: YES!");
|
ESP_LOGCONFIG(TAG, " => Failed to init Memory: YES!");
|
||||||
|
@ -154,7 +155,6 @@ void ILI9XXXDisplay::fill(Color color) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
new_color = display::ColorUtil::color_to_332(color, display::ColorOrder::COLOR_ORDER_RGB);
|
new_color = display::ColorUtil::color_to_332(color, display::ColorOrder::COLOR_ORDER_RGB);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -28,8 +28,8 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
|
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
|
||||||
public:
|
public:
|
||||||
ILI9XXXDisplay() = default;
|
ILI9XXXDisplay() = default;
|
||||||
ILI9XXXDisplay(uint8_t const *init_sequence, int16_t width, int16_t height, bool invert_colors)
|
ILI9XXXDisplay(uint8_t const *init_sequence, int16_t width, int16_t height)
|
||||||
: init_sequence_{init_sequence}, width_{width}, height_{height}, pre_invertcolors_{invert_colors} {
|
: init_sequence_{init_sequence}, width_{width}, height_{height} {
|
||||||
uint8_t cmd, num_args, bits;
|
uint8_t cmd, num_args, bits;
|
||||||
const uint8_t *addr = init_sequence;
|
const uint8_t *addr = init_sequence;
|
||||||
while ((cmd = *addr++) != 0) {
|
while ((cmd = *addr++) != 0) {
|
||||||
|
@ -144,7 +144,7 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
bool need_update_ = false;
|
bool need_update_ = false;
|
||||||
bool is_18bitdisplay_ = false;
|
bool is_18bitdisplay_ = false;
|
||||||
PixelMode pixel_mode_{};
|
PixelMode pixel_mode_{};
|
||||||
bool pre_invertcolors_ = false;
|
bool pre_invertcolors_{};
|
||||||
display::ColorOrder color_order_{display::COLOR_ORDER_BGR};
|
display::ColorOrder color_order_{display::COLOR_ORDER_BGR};
|
||||||
bool swap_xy_{};
|
bool swap_xy_{};
|
||||||
bool mirror_x_{};
|
bool mirror_x_{};
|
||||||
|
@ -154,54 +154,54 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
|
||||||
//----------- M5Stack display --------------
|
//----------- M5Stack display --------------
|
||||||
class ILI9XXXM5Stack : public ILI9XXXDisplay {
|
class ILI9XXXM5Stack : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXM5Stack() : ILI9XXXDisplay(INITCMD_M5STACK, 320, 240, true) {}
|
ILI9XXXM5Stack() : ILI9XXXDisplay(INITCMD_M5STACK, 320, 240) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- M5Stack display --------------
|
//----------- M5Stack display --------------
|
||||||
class ILI9XXXM5CORE : public ILI9XXXDisplay {
|
class ILI9XXXM5CORE : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXM5CORE() : ILI9XXXDisplay(INITCMD_M5CORE, 320, 240, true) {}
|
ILI9XXXM5CORE() : ILI9XXXDisplay(INITCMD_M5CORE, 320, 240) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ST7789V display --------------
|
//----------- ST7789V display --------------
|
||||||
class ILI9XXXST7789V : public ILI9XXXDisplay {
|
class ILI9XXXST7789V : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXST7789V() : ILI9XXXDisplay(INITCMD_ST7789V, 240, 320, false) {}
|
ILI9XXXST7789V() : ILI9XXXDisplay(INITCMD_ST7789V, 240, 320) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9XXX_24_TFT display --------------
|
//----------- ILI9XXX_24_TFT display --------------
|
||||||
class ILI9XXXILI9341 : public ILI9XXXDisplay {
|
class ILI9XXXILI9341 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXILI9341() : ILI9XXXDisplay(INITCMD_ILI9341, 240, 320, false) {}
|
ILI9XXXILI9341() : ILI9XXXDisplay(INITCMD_ILI9341, 240, 320) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9XXX_24_TFT rotated display --------------
|
//----------- ILI9XXX_24_TFT rotated display --------------
|
||||||
class ILI9XXXILI9342 : public ILI9XXXDisplay {
|
class ILI9XXXILI9342 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXILI9342() : ILI9XXXDisplay(INITCMD_ILI9341, 320, 240, false) {}
|
ILI9XXXILI9342() : ILI9XXXDisplay(INITCMD_ILI9341, 320, 240) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9XXX_??_TFT rotated display --------------
|
//----------- ILI9XXX_??_TFT rotated display --------------
|
||||||
class ILI9XXXILI9481 : public ILI9XXXDisplay {
|
class ILI9XXXILI9481 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXILI9481() : ILI9XXXDisplay(INITCMD_ILI9481, 480, 320, false) {}
|
ILI9XXXILI9481() : ILI9XXXDisplay(INITCMD_ILI9481, 480, 320) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9481 in 18 bit mode --------------
|
//----------- ILI9481 in 18 bit mode --------------
|
||||||
class ILI9XXXILI948118 : public ILI9XXXDisplay {
|
class ILI9XXXILI948118 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXILI948118() : ILI9XXXDisplay(INITCMD_ILI9481_18, 320, 480, true) {}
|
ILI9XXXILI948118() : ILI9XXXDisplay(INITCMD_ILI9481_18, 320, 480) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9XXX_35_TFT rotated display --------------
|
//----------- ILI9XXX_35_TFT rotated display --------------
|
||||||
class ILI9XXXILI9486 : public ILI9XXXDisplay {
|
class ILI9XXXILI9486 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXILI9486() : ILI9XXXDisplay(INITCMD_ILI9486, 480, 320, false) {}
|
ILI9XXXILI9486() : ILI9XXXDisplay(INITCMD_ILI9486, 480, 320) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ILI9XXXILI9488 : public ILI9XXXDisplay {
|
class ILI9XXXILI9488 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXILI9488(const uint8_t *seq = INITCMD_ILI9488) : ILI9XXXDisplay(seq, 480, 320, true) {}
|
ILI9XXXILI9488(const uint8_t *seq = INITCMD_ILI9488) : ILI9XXXDisplay(seq, 480, 320) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void set_madctl() override {
|
void set_madctl() override {
|
||||||
|
@ -246,34 +246,34 @@ class WAVESHARERES35 : public ILI9XXXILI9488 {
|
||||||
//----------- ILI9XXX_35_TFT origin colors rotated display --------------
|
//----------- ILI9XXX_35_TFT origin colors rotated display --------------
|
||||||
class ILI9XXXILI9488A : public ILI9XXXDisplay {
|
class ILI9XXXILI9488A : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXILI9488A() : ILI9XXXDisplay(INITCMD_ILI9488_A, 480, 320, true) {}
|
ILI9XXXILI9488A() : ILI9XXXDisplay(INITCMD_ILI9488_A, 480, 320) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9XXX_35_TFT rotated display --------------
|
//----------- ILI9XXX_35_TFT rotated display --------------
|
||||||
class ILI9XXXST7796 : public ILI9XXXDisplay {
|
class ILI9XXXST7796 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXST7796() : ILI9XXXDisplay(INITCMD_ST7796, 320, 480, false) {}
|
ILI9XXXST7796() : ILI9XXXDisplay(INITCMD_ST7796, 320, 480) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ILI9XXXS3Box : public ILI9XXXDisplay {
|
class ILI9XXXS3Box : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXS3Box() : ILI9XXXDisplay(INITCMD_S3BOX, 320, 240, false) {}
|
ILI9XXXS3Box() : ILI9XXXDisplay(INITCMD_S3BOX, 320, 240) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ILI9XXXS3BoxLite : public ILI9XXXDisplay {
|
class ILI9XXXS3BoxLite : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXS3BoxLite() : ILI9XXXDisplay(INITCMD_S3BOXLITE, 320, 240, true) {}
|
ILI9XXXS3BoxLite() : ILI9XXXDisplay(INITCMD_S3BOXLITE, 320, 240) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ILI9XXXGC9A01A : public ILI9XXXDisplay {
|
class ILI9XXXGC9A01A : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXGC9A01A() : ILI9XXXDisplay(INITCMD_GC9A01A, 240, 240, true) {}
|
ILI9XXXGC9A01A() : ILI9XXXDisplay(INITCMD_GC9A01A, 240, 240) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------- ILI9XXX_24_TFT display --------------
|
//----------- ILI9XXX_24_TFT display --------------
|
||||||
class ILI9XXXST7735 : public ILI9XXXDisplay {
|
class ILI9XXXST7735 : public ILI9XXXDisplay {
|
||||||
public:
|
public:
|
||||||
ILI9XXXST7735() : ILI9XXXDisplay(INITCMD_ST7735, 128, 160, false) {}
|
ILI9XXXST7735() : ILI9XXXDisplay(INITCMD_ST7735, 128, 160) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ili9xxx
|
} // namespace ili9xxx
|
||||||
|
|
|
@ -101,7 +101,6 @@ static const uint8_t PROGMEM INITCMD_ILI9481[] = {
|
||||||
ILI9XXX_MADCTL , 1, MADCTL_MV | MADCTL_BGR, // Memory Access Control
|
ILI9XXX_MADCTL , 1, MADCTL_MV | MADCTL_BGR, // Memory Access Control
|
||||||
ILI9XXX_CSCON , 1, 0x01,
|
ILI9XXX_CSCON , 1, 0x01,
|
||||||
ILI9XXX_PIXFMT, 1, 0x55, // 16 bit mode
|
ILI9XXX_PIXFMT, 1, 0x55, // 16 bit mode
|
||||||
ILI9XXX_INVON, 0,
|
|
||||||
ILI9XXX_DISPON, 0x80, // Set display on
|
ILI9XXX_DISPON, 0x80, // Set display on
|
||||||
0x00 // end
|
0x00 // end
|
||||||
};
|
};
|
||||||
|
@ -121,7 +120,6 @@ static const uint8_t PROGMEM INITCMD_ILI9481_18[] = {
|
||||||
ILI9XXX_MADCTL , 1, MADCTL_MX| MADCTL_BGR, // Memory Access Control
|
ILI9XXX_MADCTL , 1, MADCTL_MX| MADCTL_BGR, // Memory Access Control
|
||||||
ILI9XXX_CSCON , 1, 0x01,
|
ILI9XXX_CSCON , 1, 0x01,
|
||||||
ILI9XXX_PIXFMT, 1, 0x66, // 18 bit mode
|
ILI9XXX_PIXFMT, 1, 0x66, // 18 bit mode
|
||||||
ILI9XXX_INVON, 0,
|
|
||||||
ILI9XXX_DISPON, 0x80, // Set display on
|
ILI9XXX_DISPON, 0x80, // Set display on
|
||||||
0x00 // end
|
0x00 // end
|
||||||
};
|
};
|
||||||
|
@ -204,7 +202,6 @@ static const uint8_t PROGMEM INITCMD_ILI9488_A[] = {
|
||||||
|
|
||||||
|
|
||||||
ILI9XXX_SLPOUT, 0x80, // Exit sleep mode
|
ILI9XXX_SLPOUT, 0x80, // Exit sleep mode
|
||||||
//ILI9XXX_INVON , 0,
|
|
||||||
ILI9XXX_DISPON, 0x80, // Set display on
|
ILI9XXX_DISPON, 0x80, // Set display on
|
||||||
0x00 // end
|
0x00 // end
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,8 +21,8 @@ from esphome.final_validate import full_config
|
||||||
from esphome.helpers import write_file_if_changed
|
from esphome.helpers import write_file_if_changed
|
||||||
|
|
||||||
from . import defines as df, helpers, lv_validation as lvalid
|
from . import defines as df, helpers, lv_validation as lvalid
|
||||||
from .automation import disp_update, update_to_code
|
from .automation import disp_update, focused_widgets, update_to_code
|
||||||
from .defines import CONF_SKIP
|
from .defines import CONF_ADJUSTABLE, CONF_SKIP
|
||||||
from .encoders import ENCODERS_CONFIG, encoders_to_code, initial_focus_to_code
|
from .encoders import ENCODERS_CONFIG, encoders_to_code, initial_focus_to_code
|
||||||
from .lv_validation import lv_bool, lv_images_used
|
from .lv_validation import lv_bool, lv_images_used
|
||||||
from .lvcode import LvContext, LvglComponent
|
from .lvcode import LvContext, LvglComponent
|
||||||
|
@ -67,7 +67,7 @@ from .widgets.lv_bar import bar_spec
|
||||||
from .widgets.meter import meter_spec
|
from .widgets.meter import meter_spec
|
||||||
from .widgets.msgbox import MSGBOX_SCHEMA, msgboxes_to_code
|
from .widgets.msgbox import MSGBOX_SCHEMA, msgboxes_to_code
|
||||||
from .widgets.obj import obj_spec
|
from .widgets.obj import obj_spec
|
||||||
from .widgets.page import add_pages, page_spec
|
from .widgets.page import add_pages, generate_page_triggers, page_spec
|
||||||
from .widgets.roller import roller_spec
|
from .widgets.roller import roller_spec
|
||||||
from .widgets.slider import slider_spec
|
from .widgets.slider import slider_spec
|
||||||
from .widgets.spinbox import spinbox_spec
|
from .widgets.spinbox import spinbox_spec
|
||||||
|
@ -182,6 +182,14 @@ def final_validation(config):
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
"Using RGBA or RGB24 in image config not compatible with LVGL", path
|
"Using RGBA or RGB24 in image config not compatible with LVGL", path
|
||||||
)
|
)
|
||||||
|
for w in focused_widgets:
|
||||||
|
path = global_config.get_path_for_id(w)
|
||||||
|
widget_conf = global_config.get_config_for_path(path[:-1])
|
||||||
|
if CONF_ADJUSTABLE in widget_conf and not widget_conf[CONF_ADJUSTABLE]:
|
||||||
|
raise cv.Invalid(
|
||||||
|
"A non adjustable arc may not be focused",
|
||||||
|
path,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
@ -271,6 +279,7 @@ async def to_code(config):
|
||||||
Widget.set_completed()
|
Widget.set_completed()
|
||||||
async with LvContext(lv_component):
|
async with LvContext(lv_component):
|
||||||
await generate_triggers(lv_component)
|
await generate_triggers(lv_component)
|
||||||
|
await generate_page_triggers(lv_component, config)
|
||||||
for conf in config.get(CONF_ON_IDLE, ()):
|
for conf in config.get(CONF_ON_IDLE, ()):
|
||||||
templ = await cg.templatable(conf[CONF_TIMEOUT], [], cg.uint32)
|
templ = await cg.templatable(conf[CONF_TIMEOUT], [], cg.uint32)
|
||||||
idle_trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], lv_component, templ)
|
idle_trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], lv_component, templ)
|
||||||
|
@ -318,6 +327,8 @@ CONFIG_SCHEMA = (
|
||||||
{
|
{
|
||||||
cv.Optional(df.CONF_GRID_CELL_X_ALIGN): grid_alignments,
|
cv.Optional(df.CONF_GRID_CELL_X_ALIGN): grid_alignments,
|
||||||
cv.Optional(df.CONF_GRID_CELL_Y_ALIGN): grid_alignments,
|
cv.Optional(df.CONF_GRID_CELL_Y_ALIGN): grid_alignments,
|
||||||
|
cv.Optional(df.CONF_PAD_ROW): lvalid.pixels,
|
||||||
|
cv.Optional(df.CONF_PAD_COLUMN): lvalid.pixels,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
|
@ -4,13 +4,15 @@ from typing import Callable
|
||||||
from esphome import automation
|
from esphome import automation
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ID, CONF_TIMEOUT
|
from esphome.const import CONF_ACTION, CONF_GROUP, CONF_ID, CONF_TIMEOUT
|
||||||
from esphome.cpp_generator import RawExpression
|
from esphome.cpp_generator import RawExpression, get_variable
|
||||||
from esphome.cpp_types import nullptr
|
from esphome.cpp_types import nullptr
|
||||||
|
|
||||||
from .defines import (
|
from .defines import (
|
||||||
CONF_DISP_BG_COLOR,
|
CONF_DISP_BG_COLOR,
|
||||||
CONF_DISP_BG_IMAGE,
|
CONF_DISP_BG_IMAGE,
|
||||||
|
CONF_EDITING,
|
||||||
|
CONF_FREEZE,
|
||||||
CONF_LVGL_ID,
|
CONF_LVGL_ID,
|
||||||
CONF_SHOW_SNOW,
|
CONF_SHOW_SNOW,
|
||||||
literal,
|
literal,
|
||||||
|
@ -30,6 +32,7 @@ from .lvcode import (
|
||||||
lv_expr,
|
lv_expr,
|
||||||
lv_obj,
|
lv_obj,
|
||||||
lvgl_comp,
|
lvgl_comp,
|
||||||
|
static_cast,
|
||||||
)
|
)
|
||||||
from .schemas import DISP_BG_SCHEMA, LIST_ACTION_SCHEMA, LVGL_SCHEMA
|
from .schemas import DISP_BG_SCHEMA, LIST_ACTION_SCHEMA, LVGL_SCHEMA
|
||||||
from .types import (
|
from .types import (
|
||||||
|
@ -38,7 +41,9 @@ from .types import (
|
||||||
LvglCondition,
|
LvglCondition,
|
||||||
ObjUpdateAction,
|
ObjUpdateAction,
|
||||||
lv_disp_t,
|
lv_disp_t,
|
||||||
|
lv_group_t,
|
||||||
lv_obj_t,
|
lv_obj_t,
|
||||||
|
lv_pseudo_button_t,
|
||||||
)
|
)
|
||||||
from .widgets import (
|
from .widgets import (
|
||||||
Widget,
|
Widget,
|
||||||
|
@ -48,6 +53,9 @@ from .widgets import (
|
||||||
wait_for_widgets,
|
wait_for_widgets,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Record widgets that are used in a focused action here
|
||||||
|
focused_widgets = set()
|
||||||
|
|
||||||
|
|
||||||
async def action_to_code(
|
async def action_to_code(
|
||||||
widgets: list[Widget],
|
widgets: list[Widget],
|
||||||
|
@ -234,3 +242,72 @@ async def obj_show_to_code(config, action_id, template_arg, args):
|
||||||
return await action_to_code(
|
return await action_to_code(
|
||||||
await get_widgets(config), do_show, action_id, template_arg, args
|
await get_widgets(config), do_show, action_id, template_arg, args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def focused_id(value):
|
||||||
|
value = cv.use_id(lv_pseudo_button_t)(value)
|
||||||
|
focused_widgets.add(value)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
@automation.register_action(
|
||||||
|
"lvgl.widget.focus",
|
||||||
|
ObjUpdateAction,
|
||||||
|
cv.Any(
|
||||||
|
cv.maybe_simple_value(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_GROUP): cv.use_id(lv_group_t),
|
||||||
|
cv.Required(CONF_ACTION): cv.one_of(
|
||||||
|
"MARK", "RESTORE", "NEXT", "PREVIOUS", upper=True
|
||||||
|
),
|
||||||
|
cv.GenerateID(CONF_LVGL_ID): cv.use_id(LvglComponent),
|
||||||
|
cv.Optional(CONF_FREEZE, default=False): cv.boolean,
|
||||||
|
},
|
||||||
|
key=CONF_ACTION,
|
||||||
|
),
|
||||||
|
cv.maybe_simple_value(
|
||||||
|
{
|
||||||
|
cv.Required(CONF_ID): focused_id,
|
||||||
|
cv.Optional(CONF_FREEZE, default=False): cv.boolean,
|
||||||
|
cv.Optional(CONF_EDITING, default=False): cv.boolean,
|
||||||
|
},
|
||||||
|
key=CONF_ID,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def widget_focus(config, action_id, template_arg, args):
|
||||||
|
widget = await get_widgets(config)
|
||||||
|
if widget:
|
||||||
|
widget = widget[0]
|
||||||
|
group = static_cast(
|
||||||
|
lv_group_t.operator("ptr"), lv_expr.obj_get_group(widget.obj)
|
||||||
|
)
|
||||||
|
elif group := config.get(CONF_GROUP):
|
||||||
|
group = await get_variable(group)
|
||||||
|
else:
|
||||||
|
group = lv_expr.group_get_default()
|
||||||
|
|
||||||
|
async with LambdaContext(parameters=args, where=action_id) as context:
|
||||||
|
if widget:
|
||||||
|
lv.group_focus_freeze(group, False)
|
||||||
|
lv.group_focus_obj(widget.obj)
|
||||||
|
if config[CONF_EDITING]:
|
||||||
|
lv.group_set_editing(group, True)
|
||||||
|
else:
|
||||||
|
action = config[CONF_ACTION]
|
||||||
|
lv_comp = await get_variable(config[CONF_LVGL_ID])
|
||||||
|
if action == "MARK":
|
||||||
|
context.add(lv_comp.set_focus_mark(group))
|
||||||
|
else:
|
||||||
|
lv.group_focus_freeze(group, False)
|
||||||
|
if action == "RESTORE":
|
||||||
|
context.add(lv_comp.restore_focus_mark(group))
|
||||||
|
elif action == "NEXT":
|
||||||
|
lv.group_focus_next(group)
|
||||||
|
else:
|
||||||
|
lv.group_focus_prev(group)
|
||||||
|
|
||||||
|
if config[CONF_FREEZE]:
|
||||||
|
lv.group_focus_freeze(group, True)
|
||||||
|
var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda())
|
||||||
|
return var
|
||||||
|
|
|
@ -148,6 +148,7 @@ LV_EVENT_MAP = {
|
||||||
"DEFOCUS": "DEFOCUSED",
|
"DEFOCUS": "DEFOCUSED",
|
||||||
"READY": "READY",
|
"READY": "READY",
|
||||||
"CANCEL": "CANCEL",
|
"CANCEL": "CANCEL",
|
||||||
|
"ALL_EVENTS": "ALL",
|
||||||
}
|
}
|
||||||
|
|
||||||
LV_EVENT_TRIGGERS = tuple(f"on_{x.lower()}" for x in LV_EVENT_MAP)
|
LV_EVENT_TRIGGERS = tuple(f"on_{x.lower()}" for x in LV_EVENT_MAP)
|
||||||
|
@ -390,6 +391,7 @@ CONF_DEFAULT_FONT = "default_font"
|
||||||
CONF_DEFAULT_GROUP = "default_group"
|
CONF_DEFAULT_GROUP = "default_group"
|
||||||
CONF_DIR = "dir"
|
CONF_DIR = "dir"
|
||||||
CONF_DISPLAYS = "displays"
|
CONF_DISPLAYS = "displays"
|
||||||
|
CONF_EDITING = "editing"
|
||||||
CONF_ENCODERS = "encoders"
|
CONF_ENCODERS = "encoders"
|
||||||
CONF_END_ANGLE = "end_angle"
|
CONF_END_ANGLE = "end_angle"
|
||||||
CONF_END_VALUE = "end_value"
|
CONF_END_VALUE = "end_value"
|
||||||
|
@ -401,6 +403,7 @@ CONF_FLEX_ALIGN_MAIN = "flex_align_main"
|
||||||
CONF_FLEX_ALIGN_CROSS = "flex_align_cross"
|
CONF_FLEX_ALIGN_CROSS = "flex_align_cross"
|
||||||
CONF_FLEX_ALIGN_TRACK = "flex_align_track"
|
CONF_FLEX_ALIGN_TRACK = "flex_align_track"
|
||||||
CONF_FLEX_GROW = "flex_grow"
|
CONF_FLEX_GROW = "flex_grow"
|
||||||
|
CONF_FREEZE = "freeze"
|
||||||
CONF_FULL_REFRESH = "full_refresh"
|
CONF_FULL_REFRESH = "full_refresh"
|
||||||
CONF_GRID_CELL_ROW_POS = "grid_cell_row_pos"
|
CONF_GRID_CELL_ROW_POS = "grid_cell_row_pos"
|
||||||
CONF_GRID_CELL_COLUMN_POS = "grid_cell_column_pos"
|
CONF_GRID_CELL_COLUMN_POS = "grid_cell_column_pos"
|
||||||
|
@ -428,9 +431,9 @@ CONF_MSGBOXES = "msgboxes"
|
||||||
CONF_OBJ = "obj"
|
CONF_OBJ = "obj"
|
||||||
CONF_OFFSET_X = "offset_x"
|
CONF_OFFSET_X = "offset_x"
|
||||||
CONF_OFFSET_Y = "offset_y"
|
CONF_OFFSET_Y = "offset_y"
|
||||||
|
CONF_ONE_CHECKED = "one_checked"
|
||||||
CONF_ONE_LINE = "one_line"
|
CONF_ONE_LINE = "one_line"
|
||||||
CONF_ON_SELECT = "on_select"
|
CONF_ON_SELECT = "on_select"
|
||||||
CONF_ONE_CHECKED = "one_checked"
|
|
||||||
CONF_NEXT = "next"
|
CONF_NEXT = "next"
|
||||||
CONF_PAD_ROW = "pad_row"
|
CONF_PAD_ROW = "pad_row"
|
||||||
CONF_PAD_COLUMN = "pad_column"
|
CONF_PAD_COLUMN = "pad_column"
|
||||||
|
|
|
@ -52,9 +52,7 @@ opacity = LValidator(opacity_validator, uint32, retmapper=literal)
|
||||||
def color(value):
|
def color(value):
|
||||||
if value == SCHEMA_EXTRACT:
|
if value == SCHEMA_EXTRACT:
|
||||||
return ["hex color value", "color ID"]
|
return ["hex color value", "color ID"]
|
||||||
if isinstance(value, int):
|
return cv.Any(cv.int_, cv.use_id(ColorStruct))(value)
|
||||||
return value
|
|
||||||
return cv.use_id(ColorStruct)(value)
|
|
||||||
|
|
||||||
|
|
||||||
def color_retmapper(value):
|
def color_retmapper(value):
|
||||||
|
@ -82,10 +80,10 @@ def pixels_or_percent_validator(value):
|
||||||
"""A length in one axis - either a number (pixels) or a percentage"""
|
"""A length in one axis - either a number (pixels) or a percentage"""
|
||||||
if value == SCHEMA_EXTRACT:
|
if value == SCHEMA_EXTRACT:
|
||||||
return ["pixels", "..%"]
|
return ["pixels", "..%"]
|
||||||
|
value = cv.Any(cv.int_, cv.percentage)(value)
|
||||||
if isinstance(value, int):
|
if isinstance(value, int):
|
||||||
return cv.int_(value)
|
return value
|
||||||
# Will throw an exception if not a percentage.
|
return f"lv_pct({int(value * 100)})"
|
||||||
return f"lv_pct({int(cv.percentage(value) * 100)})"
|
|
||||||
|
|
||||||
|
|
||||||
pixels_or_percent = LValidator(pixels_or_percent_validator, uint32, retmapper=literal)
|
pixels_or_percent = LValidator(pixels_or_percent_validator, uint32, retmapper=literal)
|
||||||
|
@ -116,10 +114,7 @@ def size_validator(value):
|
||||||
if value.upper() == "SIZE_CONTENT":
|
if value.upper() == "SIZE_CONTENT":
|
||||||
return "LV_SIZE_CONTENT"
|
return "LV_SIZE_CONTENT"
|
||||||
raise cv.Invalid("must be 'size_content', a percentage or an integer (pixels)")
|
raise cv.Invalid("must be 'size_content', a percentage or an integer (pixels)")
|
||||||
if isinstance(value, int):
|
return pixels_or_percent_validator(value)
|
||||||
return cv.int_(value)
|
|
||||||
# Will throw an exception if not a percentage.
|
|
||||||
return f"lv_pct({int(cv.percentage(value) * 100)})"
|
|
||||||
|
|
||||||
|
|
||||||
size = LValidator(size_validator, uint32, retmapper=literal)
|
size = LValidator(size_validator, uint32, retmapper=literal)
|
||||||
|
|
|
@ -28,7 +28,7 @@ LVGL_COMP = "lv_component" # used as a lambda argument in lvgl_comp()
|
||||||
LvglComponent = lvgl_ns.class_("LvglComponent", cg.PollingComponent)
|
LvglComponent = lvgl_ns.class_("LvglComponent", cg.PollingComponent)
|
||||||
LVGL_COMP_ARG = [(LvglComponent.operator("ptr"), LVGL_COMP)]
|
LVGL_COMP_ARG = [(LvglComponent.operator("ptr"), LVGL_COMP)]
|
||||||
lv_event_t_ptr = cg.global_ns.namespace("lv_event_t").operator("ptr")
|
lv_event_t_ptr = cg.global_ns.namespace("lv_event_t").operator("ptr")
|
||||||
EVENT_ARG = [(lv_event_t_ptr, "ev")]
|
EVENT_ARG = [(lv_event_t_ptr, "event")]
|
||||||
# Two custom events; API_EVENT is fired when an entity is updated remotely by an API interaction;
|
# Two custom events; API_EVENT is fired when an entity is updated remotely by an API interaction;
|
||||||
# UPDATE_EVENT is fired when an entity is programmatically updated locally.
|
# UPDATE_EVENT is fired when an entity is programmatically updated locally.
|
||||||
# VALUE_CHANGED is the event generated by LVGL when an entity's value changes through user interaction.
|
# VALUE_CHANGED is the event generated by LVGL when an entity's value changes through user interaction.
|
||||||
|
@ -291,6 +291,10 @@ class LvExpr(MockLv):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def static_cast(type, value):
|
||||||
|
return literal(f"static_cast<{type}>({value})")
|
||||||
|
|
||||||
|
|
||||||
# Top level mock for generic lv_ calls to be recorded
|
# Top level mock for generic lv_ calls to be recorded
|
||||||
lv = MockLv("lv_")
|
lv = MockLv("lv_")
|
||||||
# Just generate an expression
|
# Just generate an expression
|
||||||
|
|
|
@ -15,6 +15,60 @@ static void log_cb(const char *buf) {
|
||||||
}
|
}
|
||||||
#endif // LV_USE_LOG
|
#endif // LV_USE_LOG
|
||||||
|
|
||||||
|
static const char *const EVENT_NAMES[] = {
|
||||||
|
"NONE",
|
||||||
|
"PRESSED",
|
||||||
|
"PRESSING",
|
||||||
|
"PRESS_LOST",
|
||||||
|
"SHORT_CLICKED",
|
||||||
|
"LONG_PRESSED",
|
||||||
|
"LONG_PRESSED_REPEAT",
|
||||||
|
"CLICKED",
|
||||||
|
"RELEASED",
|
||||||
|
"SCROLL_BEGIN",
|
||||||
|
"SCROLL_END",
|
||||||
|
"SCROLL",
|
||||||
|
"GESTURE",
|
||||||
|
"KEY",
|
||||||
|
"FOCUSED",
|
||||||
|
"DEFOCUSED",
|
||||||
|
"LEAVE",
|
||||||
|
"HIT_TEST",
|
||||||
|
"COVER_CHECK",
|
||||||
|
"REFR_EXT_DRAW_SIZE",
|
||||||
|
"DRAW_MAIN_BEGIN",
|
||||||
|
"DRAW_MAIN",
|
||||||
|
"DRAW_MAIN_END",
|
||||||
|
"DRAW_POST_BEGIN",
|
||||||
|
"DRAW_POST",
|
||||||
|
"DRAW_POST_END",
|
||||||
|
"DRAW_PART_BEGIN",
|
||||||
|
"DRAW_PART_END",
|
||||||
|
"VALUE_CHANGED",
|
||||||
|
"INSERT",
|
||||||
|
"REFRESH",
|
||||||
|
"READY",
|
||||||
|
"CANCEL",
|
||||||
|
"DELETE",
|
||||||
|
"CHILD_CHANGED",
|
||||||
|
"CHILD_CREATED",
|
||||||
|
"CHILD_DELETED",
|
||||||
|
"SCREEN_UNLOAD_START",
|
||||||
|
"SCREEN_LOAD_START",
|
||||||
|
"SCREEN_LOADED",
|
||||||
|
"SCREEN_UNLOADED",
|
||||||
|
"SIZE_CHANGED",
|
||||||
|
"STYLE_CHANGED",
|
||||||
|
"LAYOUT_CHANGED",
|
||||||
|
"GET_SELF_SIZE",
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string lv_event_code_name_for(uint8_t event_code) {
|
||||||
|
if (event_code < sizeof(EVENT_NAMES) / sizeof(EVENT_NAMES[0])) {
|
||||||
|
return EVENT_NAMES[event_code];
|
||||||
|
}
|
||||||
|
return str_sprintf("%2d", event_code);
|
||||||
|
}
|
||||||
static void rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area) {
|
static void rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area) {
|
||||||
// make sure all coordinates are even
|
// make sure all coordinates are even
|
||||||
if (area->x1 & 1)
|
if (area->x1 & 1)
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace lvgl {
|
||||||
|
|
||||||
extern lv_event_code_t lv_api_event; // NOLINT
|
extern lv_event_code_t lv_api_event; // NOLINT
|
||||||
extern lv_event_code_t lv_update_event; // NOLINT
|
extern lv_event_code_t lv_update_event; // NOLINT
|
||||||
|
extern std::string lv_event_code_name_for(uint8_t event_code);
|
||||||
extern bool lv_is_pre_initialise();
|
extern bool lv_is_pre_initialise();
|
||||||
#ifdef USE_LVGL_COLOR
|
#ifdef USE_LVGL_COLOR
|
||||||
inline lv_color_t lv_color_from(Color color) { return lv_color_make(color.red, color.green, color.blue); }
|
inline lv_color_t lv_color_from(Color color) { return lv_color_make(color.red, color.green, color.blue); }
|
||||||
|
@ -143,6 +144,13 @@ class LvglComponent : public PollingComponent {
|
||||||
void show_next_page(lv_scr_load_anim_t anim, uint32_t time);
|
void show_next_page(lv_scr_load_anim_t anim, uint32_t time);
|
||||||
void show_prev_page(lv_scr_load_anim_t anim, uint32_t time);
|
void show_prev_page(lv_scr_load_anim_t anim, uint32_t time);
|
||||||
void set_page_wrap(bool wrap) { this->page_wrap_ = wrap; }
|
void set_page_wrap(bool wrap) { this->page_wrap_ = wrap; }
|
||||||
|
void set_focus_mark(lv_group_t *group) { this->focus_marks_[group] = lv_group_get_focused(group); }
|
||||||
|
void restore_focus_mark(lv_group_t *group) {
|
||||||
|
auto *mark = this->focus_marks_[group];
|
||||||
|
if (mark != nullptr) {
|
||||||
|
lv_group_focus_obj(mark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void write_random_();
|
void write_random_();
|
||||||
|
@ -158,6 +166,7 @@ class LvglComponent : public PollingComponent {
|
||||||
bool show_snow_{};
|
bool show_snow_{};
|
||||||
lv_coord_t snow_line_{};
|
lv_coord_t snow_line_{};
|
||||||
bool page_wrap_{true};
|
bool page_wrap_{true};
|
||||||
|
std::map<lv_group_t *, lv_obj_t *> focus_marks_{};
|
||||||
|
|
||||||
std::vector<std::function<void(LvglComponent *lv_component)>> init_lambdas_;
|
std::vector<std::function<void(LvglComponent *lv_component)>> init_lambdas_;
|
||||||
CallbackManager<void(uint32_t)> idle_callbacks_{};
|
CallbackManager<void(uint32_t)> idle_callbacks_{};
|
||||||
|
|
|
@ -20,7 +20,7 @@ from . import defines as df, lv_validation as lvalid
|
||||||
from .defines import CONF_TIME_FORMAT
|
from .defines import CONF_TIME_FORMAT
|
||||||
from .helpers import add_lv_use, requires_component, validate_printf
|
from .helpers import add_lv_use, requires_component, validate_printf
|
||||||
from .lv_validation import lv_color, lv_font, lv_image
|
from .lv_validation import lv_color, lv_font, lv_image
|
||||||
from .lvcode import LvglComponent
|
from .lvcode import LvglComponent, lv_event_t_ptr
|
||||||
from .types import (
|
from .types import (
|
||||||
LVEncoderListener,
|
LVEncoderListener,
|
||||||
LvType,
|
LvType,
|
||||||
|
@ -215,14 +215,12 @@ def automation_schema(typ: LvType):
|
||||||
events = df.LV_EVENT_TRIGGERS + (CONF_ON_VALUE,)
|
events = df.LV_EVENT_TRIGGERS + (CONF_ON_VALUE,)
|
||||||
else:
|
else:
|
||||||
events = df.LV_EVENT_TRIGGERS
|
events = df.LV_EVENT_TRIGGERS
|
||||||
if isinstance(typ, LvType):
|
args = [typ.get_arg_type()] if isinstance(typ, LvType) else []
|
||||||
template = Trigger.template(typ.get_arg_type())
|
args.append(lv_event_t_ptr)
|
||||||
else:
|
|
||||||
template = Trigger.template()
|
|
||||||
return {
|
return {
|
||||||
cv.Optional(event): validate_automation(
|
cv.Optional(event): validate_automation(
|
||||||
{
|
{
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(template),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(Trigger.template(*args)),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
for event in events
|
for event in events
|
||||||
|
@ -361,7 +359,13 @@ LVGL_SCHEMA = cv.Schema(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
ALL_STYLES = {**STYLE_PROPS, **GRID_CELL_SCHEMA, **FLEX_OBJ_SCHEMA}
|
ALL_STYLES = {
|
||||||
|
**STYLE_PROPS,
|
||||||
|
**GRID_CELL_SCHEMA,
|
||||||
|
**FLEX_OBJ_SCHEMA,
|
||||||
|
cv.Optional(df.CONF_PAD_ROW): lvalid.pixels,
|
||||||
|
cv.Optional(df.CONF_PAD_COLUMN): lvalid.pixels,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def container_validator(schema, widget_type: WidgetType):
|
def container_validator(schema, widget_type: WidgetType):
|
||||||
|
|
|
@ -19,6 +19,7 @@ from .lvcode import (
|
||||||
LvConditional,
|
LvConditional,
|
||||||
lv,
|
lv,
|
||||||
lv_add,
|
lv_add,
|
||||||
|
lv_event_t_ptr,
|
||||||
)
|
)
|
||||||
from .types import LV_EVENT
|
from .types import LV_EVENT
|
||||||
from .widgets import widget_map
|
from .widgets import widget_map
|
||||||
|
@ -65,10 +66,10 @@ async def generate_triggers(lv_component):
|
||||||
async def add_trigger(conf, lv_component, w, *events):
|
async def add_trigger(conf, lv_component, w, *events):
|
||||||
tid = conf[CONF_TRIGGER_ID]
|
tid = conf[CONF_TRIGGER_ID]
|
||||||
trigger = cg.new_Pvariable(tid)
|
trigger = cg.new_Pvariable(tid)
|
||||||
args = w.get_args()
|
args = w.get_args() + [(lv_event_t_ptr, "event")]
|
||||||
value = w.get_value()
|
value = w.get_value()
|
||||||
await automation.build_automation(trigger, args, conf)
|
await automation.build_automation(trigger, args, conf)
|
||||||
async with LambdaContext(EVENT_ARG, where=tid) as context:
|
async with LambdaContext(EVENT_ARG, where=tid) as context:
|
||||||
with LvConditional(w.is_selected()):
|
with LvConditional(w.is_selected()):
|
||||||
lv_add(trigger.trigger(value))
|
lv_add(trigger.trigger(value, literal("event")))
|
||||||
lv_add(lv_component.add_event_cb(w.obj, await context.get_lambda(), *events))
|
lv_add(lv_component.add_event_cb(w.obj, await context.get_lambda(), *events))
|
||||||
|
|
|
@ -57,7 +57,7 @@ lv_group_t = cg.global_ns.struct("lv_group_t")
|
||||||
LVTouchListener = lvgl_ns.class_("LVTouchListener")
|
LVTouchListener = lvgl_ns.class_("LVTouchListener")
|
||||||
LVEncoderListener = lvgl_ns.class_("LVEncoderListener")
|
LVEncoderListener = lvgl_ns.class_("LVEncoderListener")
|
||||||
lv_obj_t = LvType("lv_obj_t")
|
lv_obj_t = LvType("lv_obj_t")
|
||||||
lv_page_t = cg.global_ns.class_("LvPageType", LvCompound)
|
lv_page_t = LvType("LvPageType", parents=(LvCompound,))
|
||||||
lv_img_t = LvType("lv_img_t")
|
lv_img_t = LvType("lv_img_t")
|
||||||
|
|
||||||
LV_EVENT = MockObj(base="LV_EVENT_", op="")
|
LV_EVENT = MockObj(base="LV_EVENT_", op="")
|
||||||
|
|
|
@ -225,7 +225,7 @@ def get_widget_generator(wid):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
async def get_widget_(wid: Widget):
|
async def get_widget_(wid):
|
||||||
if obj := widget_map.get(wid):
|
if obj := widget_map.get(wid):
|
||||||
return obj
|
return obj
|
||||||
return await FakeAwaitable(get_widget_generator(wid))
|
return await FakeAwaitable(get_widget_generator(wid))
|
||||||
|
@ -348,8 +348,6 @@ async def set_obj_properties(w: Widget, config):
|
||||||
if group := config.get(CONF_GROUP):
|
if group := config.get(CONF_GROUP):
|
||||||
group = await cg.get_variable(group)
|
group = await cg.get_variable(group)
|
||||||
lv.group_add_obj(group, w.obj)
|
lv.group_add_obj(group, w.obj)
|
||||||
flag_clr = set()
|
|
||||||
flag_set = set()
|
|
||||||
props = parts[CONF_MAIN][CONF_DEFAULT]
|
props = parts[CONF_MAIN][CONF_DEFAULT]
|
||||||
lambs = {}
|
lambs = {}
|
||||||
flag_set = set()
|
flag_set = set()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
|
CONF_GROUP,
|
||||||
CONF_MAX_VALUE,
|
CONF_MAX_VALUE,
|
||||||
CONF_MIN_VALUE,
|
CONF_MIN_VALUE,
|
||||||
CONF_MODE,
|
CONF_MODE,
|
||||||
|
@ -20,7 +21,7 @@ from ..defines import (
|
||||||
literal,
|
literal,
|
||||||
)
|
)
|
||||||
from ..lv_validation import angle, get_start_value, lv_float
|
from ..lv_validation import angle, get_start_value, lv_float
|
||||||
from ..lvcode import lv, lv_obj
|
from ..lvcode import lv, lv_expr, lv_obj
|
||||||
from ..types import LvNumber, NumberType
|
from ..types import LvNumber, NumberType
|
||||||
from . import Widget
|
from . import Widget
|
||||||
|
|
||||||
|
@ -69,6 +70,9 @@ class ArcType(NumberType):
|
||||||
if config.get(CONF_ADJUSTABLE) is False:
|
if config.get(CONF_ADJUSTABLE) is False:
|
||||||
lv_obj.remove_style(w.obj, nullptr, literal("LV_PART_KNOB"))
|
lv_obj.remove_style(w.obj, nullptr, literal("LV_PART_KNOB"))
|
||||||
w.clear_flag("LV_OBJ_FLAG_CLICKABLE")
|
w.clear_flag("LV_OBJ_FLAG_CLICKABLE")
|
||||||
|
elif CONF_GROUP not in config:
|
||||||
|
# For some reason arc does not get automatically added to the default group
|
||||||
|
lv.group_add_obj(lv_expr.group_get_default(), w.obj)
|
||||||
|
|
||||||
value = await get_start_value(config)
|
value = await get_start_value(config)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
|
|
@ -13,11 +13,13 @@ from ..defines import (
|
||||||
CONF_KEY_CODE,
|
CONF_KEY_CODE,
|
||||||
CONF_MAIN,
|
CONF_MAIN,
|
||||||
CONF_ONE_CHECKED,
|
CONF_ONE_CHECKED,
|
||||||
|
CONF_PAD_COLUMN,
|
||||||
|
CONF_PAD_ROW,
|
||||||
CONF_ROWS,
|
CONF_ROWS,
|
||||||
CONF_SELECTED,
|
CONF_SELECTED,
|
||||||
)
|
)
|
||||||
from ..helpers import lvgl_components_required
|
from ..helpers import lvgl_components_required
|
||||||
from ..lv_validation import key_code, lv_bool
|
from ..lv_validation import key_code, lv_bool, pixels
|
||||||
from ..lvcode import lv, lv_add, lv_expr
|
from ..lvcode import lv, lv_add, lv_expr
|
||||||
from ..schemas import automation_schema
|
from ..schemas import automation_schema
|
||||||
from ..types import (
|
from ..types import (
|
||||||
|
@ -57,6 +59,8 @@ BUTTONMATRIX_BUTTON_SCHEMA = cv.Schema(
|
||||||
BUTTONMATRIX_SCHEMA = cv.Schema(
|
BUTTONMATRIX_SCHEMA = cv.Schema(
|
||||||
{
|
{
|
||||||
cv.Optional(CONF_ONE_CHECKED, default=False): lv_bool,
|
cv.Optional(CONF_ONE_CHECKED, default=False): lv_bool,
|
||||||
|
cv.Optional(CONF_PAD_ROW): pixels,
|
||||||
|
cv.Optional(CONF_PAD_COLUMN): pixels,
|
||||||
cv.GenerateID(CONF_BUTTON_TEXT_LIST_ID): cv.declare_id(char_ptr),
|
cv.GenerateID(CONF_BUTTON_TEXT_LIST_ID): cv.declare_id(char_ptr),
|
||||||
cv.Required(CONF_ROWS): cv.ensure_list(
|
cv.Required(CONF_ROWS): cv.ensure_list(
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
from esphome.config_validation import Optional
|
||||||
from esphome.const import CONF_TEXT
|
from esphome.const import CONF_TEXT
|
||||||
|
|
||||||
from ..defines import CONF_INDICATOR, CONF_MAIN
|
from ..defines import CONF_INDICATOR, CONF_MAIN, CONF_PAD_COLUMN
|
||||||
from ..lv_validation import lv_text
|
from ..lv_validation import lv_text, pixels
|
||||||
from ..lvcode import lv
|
from ..lvcode import lv
|
||||||
from ..schemas import TEXT_SCHEMA
|
from ..schemas import TEXT_SCHEMA
|
||||||
from ..types import LvBoolean
|
from ..types import LvBoolean
|
||||||
|
@ -16,7 +17,11 @@ class CheckboxType(WidgetType):
|
||||||
CONF_CHECKBOX,
|
CONF_CHECKBOX,
|
||||||
LvBoolean("lv_checkbox_t"),
|
LvBoolean("lv_checkbox_t"),
|
||||||
(CONF_MAIN, CONF_INDICATOR),
|
(CONF_MAIN, CONF_INDICATOR),
|
||||||
TEXT_SCHEMA,
|
TEXT_SCHEMA.extend(
|
||||||
|
{
|
||||||
|
Optional(CONF_PAD_COLUMN): pixels,
|
||||||
|
}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def to_code(self, w: Widget, config):
|
async def to_code(self, w: Widget, config):
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from esphome import automation, codegen as cg
|
from esphome import automation, codegen as cg
|
||||||
|
from esphome.automation import Trigger
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ID, CONF_PAGES, CONF_TIME
|
from esphome.const import CONF_ID, CONF_PAGES, CONF_TIME, CONF_TRIGGER_ID
|
||||||
|
|
||||||
from ..defines import (
|
from ..defines import (
|
||||||
CONF_ANIMATION,
|
CONF_ANIMATION,
|
||||||
|
@ -9,12 +10,39 @@ from ..defines import (
|
||||||
CONF_PAGE_WRAP,
|
CONF_PAGE_WRAP,
|
||||||
CONF_SKIP,
|
CONF_SKIP,
|
||||||
LV_ANIM,
|
LV_ANIM,
|
||||||
|
literal,
|
||||||
)
|
)
|
||||||
from ..lv_validation import lv_bool, lv_milliseconds
|
from ..lv_validation import lv_bool, lv_milliseconds
|
||||||
from ..lvcode import LVGL_COMP_ARG, LambdaContext, add_line_marks, lv_add, lvgl_comp
|
from ..lvcode import (
|
||||||
|
EVENT_ARG,
|
||||||
|
LVGL_COMP_ARG,
|
||||||
|
LambdaContext,
|
||||||
|
add_line_marks,
|
||||||
|
lv_add,
|
||||||
|
lvgl_comp,
|
||||||
|
)
|
||||||
from ..schemas import LVGL_SCHEMA
|
from ..schemas import LVGL_SCHEMA
|
||||||
from ..types import LvglAction, lv_page_t
|
from ..types import LvglAction, lv_page_t
|
||||||
from . import Widget, WidgetType, add_widgets, set_obj_properties
|
from . import Widget, WidgetType, add_widgets, get_widgets, set_obj_properties
|
||||||
|
|
||||||
|
CONF_ON_LOAD = "on_load"
|
||||||
|
CONF_ON_UNLOAD = "on_unload"
|
||||||
|
|
||||||
|
PAGE_SCHEMA = cv.Schema(
|
||||||
|
{
|
||||||
|
cv.Optional(CONF_SKIP, default=False): lv_bool,
|
||||||
|
cv.Optional(CONF_ON_LOAD): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(Trigger.template()),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_UNLOAD): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(Trigger.template()),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PageType(WidgetType):
|
class PageType(WidgetType):
|
||||||
|
@ -23,9 +51,8 @@ class PageType(WidgetType):
|
||||||
CONF_PAGE,
|
CONF_PAGE,
|
||||||
lv_page_t,
|
lv_page_t,
|
||||||
(),
|
(),
|
||||||
{
|
PAGE_SCHEMA,
|
||||||
cv.Optional(CONF_SKIP, default=False): lv_bool,
|
modify_schema={},
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def to_code(self, w: Widget, config: dict):
|
async def to_code(self, w: Widget, config: dict):
|
||||||
|
@ -39,7 +66,6 @@ SHOW_SCHEMA = LVGL_SCHEMA.extend(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
page_spec = PageType()
|
page_spec = PageType()
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,3 +137,21 @@ async def add_pages(lv_component, config):
|
||||||
await set_obj_properties(page, config)
|
await set_obj_properties(page, config)
|
||||||
await set_obj_properties(page, pconf)
|
await set_obj_properties(page, pconf)
|
||||||
await add_widgets(page, pconf)
|
await add_widgets(page, pconf)
|
||||||
|
|
||||||
|
|
||||||
|
async def generate_page_triggers(lv_component, config):
|
||||||
|
for pconf in config.get(CONF_PAGES, ()):
|
||||||
|
page = (await get_widgets(pconf))[0]
|
||||||
|
for ev in (CONF_ON_LOAD, CONF_ON_UNLOAD):
|
||||||
|
for loaded in pconf.get(ev, ()):
|
||||||
|
trigger = cg.new_Pvariable(loaded[CONF_TRIGGER_ID])
|
||||||
|
await automation.build_automation(trigger, [], loaded)
|
||||||
|
async with LambdaContext(EVENT_ARG, where=id) as context:
|
||||||
|
lv_add(trigger.trigger())
|
||||||
|
lv_add(
|
||||||
|
lv_component.add_event_cb(
|
||||||
|
page.obj,
|
||||||
|
await context.get_lambda(),
|
||||||
|
literal(f"LV_EVENT_SCREEN_{ev[3:].upper()}_START"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from esphome import automation
|
from esphome import automation
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ID, CONF_ON_VALUE, CONF_ROW, CONF_TRIGGER_ID
|
from esphome.const import CONF_ID, CONF_ROW
|
||||||
|
|
||||||
from ..automation import action_to_code
|
from ..automation import action_to_code
|
||||||
from ..defines import (
|
from ..defines import (
|
||||||
|
@ -29,6 +29,7 @@ lv_tileview_t = LvType(
|
||||||
"lv_tileview_t",
|
"lv_tileview_t",
|
||||||
largs=[(lv_obj_t_ptr, "tile")],
|
largs=[(lv_obj_t_ptr, "tile")],
|
||||||
lvalue=lambda w: w.get_property("tile_act"),
|
lvalue=lambda w: w.get_property("tile_act"),
|
||||||
|
has_on_value=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
tile_spec = WidgetType("lv_tileview_tile_t", lv_tile_t, (CONF_MAIN,), {})
|
tile_spec = WidgetType("lv_tileview_tile_t", lv_tile_t, (CONF_MAIN,), {})
|
||||||
|
@ -46,13 +47,6 @@ TILEVIEW_SCHEMA = cv.Schema(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_ON_VALUE): automation.validate_automation(
|
|
||||||
{
|
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
|
||||||
automation.Trigger.template(lv_obj_t_ptr)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,18 @@ enum MediaPlayerCommand : uint8_t {
|
||||||
};
|
};
|
||||||
const char *media_player_command_to_string(MediaPlayerCommand command);
|
const char *media_player_command_to_string(MediaPlayerCommand command);
|
||||||
|
|
||||||
|
enum class MediaPlayerFormatPurpose : uint8_t {
|
||||||
|
PURPOSE_DEFAULT = 0,
|
||||||
|
PURPOSE_ANNOUNCEMENT = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MediaPlayerSupportedFormat {
|
||||||
|
std::string format;
|
||||||
|
uint32_t sample_rate;
|
||||||
|
uint32_t num_channels;
|
||||||
|
MediaPlayerFormatPurpose purpose;
|
||||||
|
};
|
||||||
|
|
||||||
class MediaPlayer;
|
class MediaPlayer;
|
||||||
|
|
||||||
class MediaPlayerTraits {
|
class MediaPlayerTraits {
|
||||||
|
@ -37,8 +49,11 @@ class MediaPlayerTraits {
|
||||||
|
|
||||||
bool get_supports_pause() const { return this->supports_pause_; }
|
bool get_supports_pause() const { return this->supports_pause_; }
|
||||||
|
|
||||||
|
std::vector<MediaPlayerSupportedFormat> &get_supported_formats() { return this->supported_formats_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool supports_pause_{false};
|
bool supports_pause_{false};
|
||||||
|
std::vector<MediaPlayerSupportedFormat> supported_formats_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class MediaPlayerCall {
|
class MediaPlayerCall {
|
||||||
|
|
|
@ -153,6 +153,13 @@ build_flags =
|
||||||
-DUSE_ESP32_FRAMEWORK_ESP_IDF
|
-DUSE_ESP32_FRAMEWORK_ESP_IDF
|
||||||
extra_scripts = post:esphome/components/esp32/post_build.py.script
|
extra_scripts = post:esphome/components/esp32/post_build.py.script
|
||||||
|
|
||||||
|
; This are common settings for the ESP32 using the latest ESP-IDF version.
|
||||||
|
[common:esp32-idf-5_3]
|
||||||
|
extends = common:esp32-idf
|
||||||
|
platform = platformio/espressif32@6.8.0
|
||||||
|
platform_packages =
|
||||||
|
platformio/framework-espidf@~3.50300.0
|
||||||
|
|
||||||
; These are common settings for the RP2040 using Arduino.
|
; These are common settings for the RP2040 using Arduino.
|
||||||
[common:rp2040-arduino]
|
[common:rp2040-arduino]
|
||||||
extends = common:arduino
|
extends = common:arduino
|
||||||
|
@ -229,6 +236,15 @@ build_flags =
|
||||||
${flags:runtime.build_flags}
|
${flags:runtime.build_flags}
|
||||||
-DUSE_ESP32_VARIANT_ESP32
|
-DUSE_ESP32_VARIANT_ESP32
|
||||||
|
|
||||||
|
[env:esp32-idf-5_3]
|
||||||
|
extends = common:esp32-idf-5_3
|
||||||
|
board = esp32dev
|
||||||
|
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32-idf
|
||||||
|
build_flags =
|
||||||
|
${common:esp32-idf.build_flags}
|
||||||
|
${flags:runtime.build_flags}
|
||||||
|
-DUSE_ESP32_VARIANT_ESP32
|
||||||
|
|
||||||
[env:esp32-idf-tidy]
|
[env:esp32-idf-tidy]
|
||||||
extends = common:esp32-idf
|
extends = common:esp32-idf
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
|
@ -265,6 +281,15 @@ build_flags =
|
||||||
${flags:runtime.build_flags}
|
${flags:runtime.build_flags}
|
||||||
-DUSE_ESP32_VARIANT_ESP32C3
|
-DUSE_ESP32_VARIANT_ESP32C3
|
||||||
|
|
||||||
|
[env:esp32c3-idf-5_3]
|
||||||
|
extends = common:esp32-idf-5_3
|
||||||
|
board = esp32-c3-devkitm-1
|
||||||
|
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32c3-idf
|
||||||
|
build_flags =
|
||||||
|
${common:esp32-idf.build_flags}
|
||||||
|
${flags:runtime.build_flags}
|
||||||
|
-DUSE_ESP32_VARIANT_ESP32C3
|
||||||
|
|
||||||
[env:esp32c3-idf-tidy]
|
[env:esp32c3-idf-tidy]
|
||||||
extends = common:esp32-idf
|
extends = common:esp32-idf
|
||||||
board = esp32-c3-devkitm-1
|
board = esp32-c3-devkitm-1
|
||||||
|
@ -301,6 +326,15 @@ build_flags =
|
||||||
${flags:runtime.build_flags}
|
${flags:runtime.build_flags}
|
||||||
-DUSE_ESP32_VARIANT_ESP32S2
|
-DUSE_ESP32_VARIANT_ESP32S2
|
||||||
|
|
||||||
|
[env:esp32s2-idf-5_3]
|
||||||
|
extends = common:esp32-idf-5_3
|
||||||
|
board = esp32-s2-kaluga-1
|
||||||
|
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32s2-idf
|
||||||
|
build_flags =
|
||||||
|
${common:esp32-idf.build_flags}
|
||||||
|
${flags:runtime.build_flags}
|
||||||
|
-DUSE_ESP32_VARIANT_ESP32S2
|
||||||
|
|
||||||
[env:esp32s2-idf-tidy]
|
[env:esp32s2-idf-tidy]
|
||||||
extends = common:esp32-idf
|
extends = common:esp32-idf
|
||||||
board = esp32-s2-kaluga-1
|
board = esp32-s2-kaluga-1
|
||||||
|
@ -337,6 +371,15 @@ build_flags =
|
||||||
${flags:runtime.build_flags}
|
${flags:runtime.build_flags}
|
||||||
-DUSE_ESP32_VARIANT_ESP32S3
|
-DUSE_ESP32_VARIANT_ESP32S3
|
||||||
|
|
||||||
|
[env:esp32s3-idf-5_3]
|
||||||
|
extends = common:esp32-idf-5_3
|
||||||
|
board = esp32-s3-devkitc-1
|
||||||
|
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32s3-idf
|
||||||
|
build_flags =
|
||||||
|
${common:esp32-idf.build_flags}
|
||||||
|
${flags:runtime.build_flags}
|
||||||
|
-DUSE_ESP32_VARIANT_ESP32S3
|
||||||
|
|
||||||
[env:esp32s3-idf-tidy]
|
[env:esp32s3-idf-tidy]
|
||||||
extends = common:esp32-idf
|
extends = common:esp32-idf
|
||||||
board = esp32-s3-devkitc-1
|
board = esp32-s3-devkitc-1
|
||||||
|
|
62
tests/components/bl0906/common.yaml
Normal file
62
tests/components/bl0906/common.yaml
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
uart:
|
||||||
|
- id: uart_bl0906
|
||||||
|
tx_pin:
|
||||||
|
number: ${tx_pin}
|
||||||
|
rx_pin:
|
||||||
|
number: ${rx_pin}
|
||||||
|
baud_rate: 19200
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: bl0906
|
||||||
|
frequency:
|
||||||
|
name: 'Frequency'
|
||||||
|
temperature:
|
||||||
|
name: 'Temperature'
|
||||||
|
voltage:
|
||||||
|
name: 'Voltage'
|
||||||
|
channel_1:
|
||||||
|
current:
|
||||||
|
name: 'Current_1'
|
||||||
|
power:
|
||||||
|
name: 'Power_1'
|
||||||
|
energy:
|
||||||
|
name: 'Energy_1'
|
||||||
|
channel_2:
|
||||||
|
current:
|
||||||
|
name: 'Current_2'
|
||||||
|
power:
|
||||||
|
name: 'Power_2'
|
||||||
|
energy:
|
||||||
|
name: 'Energy_2'
|
||||||
|
channel_3:
|
||||||
|
current:
|
||||||
|
name: 'Current_3'
|
||||||
|
power:
|
||||||
|
name: 'Power_3'
|
||||||
|
energy:
|
||||||
|
name: 'Energy_3'
|
||||||
|
channel_4:
|
||||||
|
current:
|
||||||
|
name: 'Current_4'
|
||||||
|
power:
|
||||||
|
name: 'Power_4'
|
||||||
|
energy:
|
||||||
|
name: 'Energy_4'
|
||||||
|
channel_5:
|
||||||
|
current:
|
||||||
|
name: 'Current_5'
|
||||||
|
power:
|
||||||
|
name: 'Power_5'
|
||||||
|
energy:
|
||||||
|
name: 'Energy_5'
|
||||||
|
channel_6:
|
||||||
|
current:
|
||||||
|
name: 'Current_6'
|
||||||
|
power:
|
||||||
|
name: 'Power_6'
|
||||||
|
energy:
|
||||||
|
name: 'Energy_6'
|
||||||
|
total_energy:
|
||||||
|
name: 'Total_Energy'
|
||||||
|
total_power:
|
||||||
|
name: 'Total_Power'
|
5
tests/components/bl0906/test.esp32-ard.yaml
Normal file
5
tests/components/bl0906/test.esp32-ard.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
substitutions:
|
||||||
|
tx_pin: GPIO12
|
||||||
|
rx_pin: GPIO14
|
||||||
|
|
||||||
|
<<: !include common.yaml
|
5
tests/components/bl0906/test.esp32-c3-ard.yaml
Normal file
5
tests/components/bl0906/test.esp32-c3-ard.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
substitutions:
|
||||||
|
tx_pin: GPIO7
|
||||||
|
rx_pin: GPIO8
|
||||||
|
|
||||||
|
<<: !include common.yaml
|
5
tests/components/bl0906/test.esp32-c3-idf.yaml
Normal file
5
tests/components/bl0906/test.esp32-c3-idf.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
substitutions:
|
||||||
|
tx_pin: GPIO7
|
||||||
|
rx_pin: GPIO8
|
||||||
|
|
||||||
|
<<: !include common.yaml
|
5
tests/components/bl0906/test.esp32-idf.yaml
Normal file
5
tests/components/bl0906/test.esp32-idf.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
substitutions:
|
||||||
|
tx_pin: GPIO12
|
||||||
|
rx_pin: GPIO14
|
||||||
|
|
||||||
|
<<: !include common.yaml
|
5
tests/components/bl0906/test.esp8266-ard.yaml
Normal file
5
tests/components/bl0906/test.esp8266-ard.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
substitutions:
|
||||||
|
tx_pin: GPIO1
|
||||||
|
rx_pin: GPIO3
|
||||||
|
|
||||||
|
<<: !include common.yaml
|
5
tests/components/bl0906/test.rp2040-ard.yaml
Normal file
5
tests/components/bl0906/test.rp2040-ard.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
substitutions:
|
||||||
|
tx_pin: GPIO4
|
||||||
|
rx_pin: GPIO5
|
||||||
|
|
||||||
|
<<: !include common.yaml
|
22
tests/components/bl0942/test.bk72xx-ard.yaml
Normal file
22
tests/components/bl0942/test.bk72xx-ard.yaml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
uart:
|
||||||
|
- id: uart_bl0942
|
||||||
|
tx_pin:
|
||||||
|
number: TX1
|
||||||
|
rx_pin:
|
||||||
|
number: RX1
|
||||||
|
baud_rate: 2400
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: bl0942
|
||||||
|
address: 0
|
||||||
|
line_frequency: 50Hz
|
||||||
|
voltage:
|
||||||
|
name: BL0942 Voltage
|
||||||
|
current:
|
||||||
|
name: BL0942 Current
|
||||||
|
power:
|
||||||
|
name: BL0942 Power
|
||||||
|
energy:
|
||||||
|
name: BL0942 Energy
|
||||||
|
frequency:
|
||||||
|
name: BL0942 Frequency
|
|
@ -19,6 +19,7 @@ display:
|
||||||
lambda: |-
|
lambda: |-
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
- platform: ili9xxx
|
- platform: ili9xxx
|
||||||
|
invert_colors: false
|
||||||
dimensions:
|
dimensions:
|
||||||
width: 320
|
width: 320
|
||||||
height: 240
|
height: 240
|
||||||
|
|
|
@ -20,6 +20,7 @@ display:
|
||||||
lambda: |-
|
lambda: |-
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
- platform: ili9xxx
|
- platform: ili9xxx
|
||||||
|
invert_colors: false
|
||||||
dimensions:
|
dimensions:
|
||||||
width: 320
|
width: 320
|
||||||
height: 240
|
height: 240
|
||||||
|
|
|
@ -20,6 +20,7 @@ display:
|
||||||
lambda: |-
|
lambda: |-
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
- platform: ili9xxx
|
- platform: ili9xxx
|
||||||
|
invert_colors: false
|
||||||
dimensions:
|
dimensions:
|
||||||
width: 320
|
width: 320
|
||||||
height: 240
|
height: 240
|
||||||
|
|
|
@ -20,6 +20,7 @@ display:
|
||||||
lambda: |-
|
lambda: |-
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
- platform: ili9xxx
|
- platform: ili9xxx
|
||||||
|
invert_colors: false
|
||||||
dimensions:
|
dimensions:
|
||||||
width: 320
|
width: 320
|
||||||
height: 240
|
height: 240
|
||||||
|
|
|
@ -20,6 +20,7 @@ display:
|
||||||
lambda: |-
|
lambda: |-
|
||||||
it.rectangle(0, 0, it.get_width(), it.get_height());
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
- platform: ili9xxx
|
- platform: ili9xxx
|
||||||
|
invert_colors: false
|
||||||
dimensions:
|
dimensions:
|
||||||
width: 320
|
width: 320
|
||||||
height: 240
|
height: 240
|
||||||
|
|
|
@ -54,6 +54,17 @@ lvgl:
|
||||||
long_press_time: 500ms
|
long_press_time: 500ms
|
||||||
pages:
|
pages:
|
||||||
- id: page1
|
- id: page1
|
||||||
|
on_load:
|
||||||
|
- logger.log: page loaded
|
||||||
|
- lvgl.widget.focus:
|
||||||
|
action: restore
|
||||||
|
on_unload:
|
||||||
|
- logger.log: page unloaded
|
||||||
|
- lvgl.widget.focus: mark
|
||||||
|
on_all_events:
|
||||||
|
logger.log:
|
||||||
|
format: "Event %s"
|
||||||
|
args: ['lv_event_code_name_for(event->code).c_str()']
|
||||||
skip: true
|
skip: true
|
||||||
layout:
|
layout:
|
||||||
type: flex
|
type: flex
|
||||||
|
@ -70,6 +81,10 @@ lvgl:
|
||||||
repeat_count: 10
|
repeat_count: 10
|
||||||
duration: 1s
|
duration: 1s
|
||||||
auto_start: true
|
auto_start: true
|
||||||
|
on_all_events:
|
||||||
|
logger.log:
|
||||||
|
format: "Event %s"
|
||||||
|
args: ['lv_event_code_name_for(event->code).c_str()']
|
||||||
- label:
|
- label:
|
||||||
id: hello_label
|
id: hello_label
|
||||||
text: Hello world
|
text: Hello world
|
||||||
|
@ -229,6 +244,16 @@ lvgl:
|
||||||
- label:
|
- label:
|
||||||
text: Button
|
text: Button
|
||||||
on_click:
|
on_click:
|
||||||
|
- lvgl.widget.focus: spin_up
|
||||||
|
- lvgl.widget.focus: next
|
||||||
|
- lvgl.widget.focus: previous
|
||||||
|
- lvgl.widget.focus:
|
||||||
|
action: previous
|
||||||
|
freeze: true
|
||||||
|
- lvgl.widget.focus:
|
||||||
|
id: spin_up
|
||||||
|
freeze: true
|
||||||
|
editing: true
|
||||||
- lvgl.label.update:
|
- lvgl.label.update:
|
||||||
id: hello_label
|
id: hello_label
|
||||||
bg_color: 0x123456
|
bg_color: 0x123456
|
||||||
|
@ -312,11 +337,25 @@ lvgl:
|
||||||
- tileview:
|
- tileview:
|
||||||
id: tileview_id
|
id: tileview_id
|
||||||
scrollbar_mode: active
|
scrollbar_mode: active
|
||||||
|
on_value:
|
||||||
|
then:
|
||||||
|
- if:
|
||||||
|
condition:
|
||||||
|
lambda: return tile == id(tile_1);
|
||||||
|
then:
|
||||||
|
- logger.log: "tile 1 is now showing"
|
||||||
tiles:
|
tiles:
|
||||||
- id: page_1
|
- id: tile_1
|
||||||
row: 0
|
row: 0
|
||||||
column: 0
|
column: 0
|
||||||
dir: HOR
|
dir: ALL
|
||||||
|
widgets:
|
||||||
|
- obj:
|
||||||
|
bg_color: 0x000000
|
||||||
|
- id: tile_2
|
||||||
|
row: 1
|
||||||
|
column: 0
|
||||||
|
dir: [VER, HOR]
|
||||||
widgets:
|
widgets:
|
||||||
- obj:
|
- obj:
|
||||||
bg_color: 0x000000
|
bg_color: 0x000000
|
||||||
|
|
Loading…
Reference in a new issue