Add all documented switches

This commit is contained in:
sqozz 2024-09-18 23:14:13 +02:00
parent d79ddf918c
commit 02b6d374ef
4 changed files with 136 additions and 56 deletions

View file

@ -10,39 +10,36 @@ CODEOWNERS = ["@sqozz"]
tw7100Switch = tw7100_ns.class_("tw7100Switch", switch.Switch, cg.Component) tw7100Switch = tw7100_ns.class_("tw7100Switch", switch.Switch, cg.Component)
CONFIG_SCHEMA = cv.Schema( switches = [
{ ("PWR","mdi:power"),
cv.GenerateID(): cv.use_id(tw7100), ("BTAUDIO","mdi:speaker-bluetooth"),
cv.Optional("PWR"): switch.switch_schema( ("MUTE","mdi:video-box-off"),
tw7100Switch ("WLPWR","mdi:access-point"),
), ("AUTOHOME","mdi:cog-clockwise"),
cv.Optional("BTAUDIO"): switch.switch_schema( # ("PRODUCT",""), # present in datasheet but tw7100 only responds with "ERR" (no details)
tw7100Switch ("STANDBYCONF","mdi:frequently-asked-questions"),
), ("ILLUM","mdi:sunglasses"),
cv.Optional("MUTE"): switch.switch_schema( ("VREVERSE","mdi:arrow-expand-vertical"),
tw7100Switch ("HREVERSE","mdi:arrow-expand-horizontal"),
), ("AUDIOOUT","mdi:audio-input-stereo-minijack"),
} ("IMGPROC",""),
) ("4KENHANCE","mdi:video-4k-box"),
("LOGTO",""),
]
schema={cv.GenerateID(): cv.use_id(tw7100)}
for name,icon in switches:
schema.update({cv.Optional(name): switch.switch_schema(tw7100Switch, icon=icon)})
CONFIG_SCHEMA = cv.Schema(schema)
async def to_code(config): async def to_code(config):
parent = await cg.get_variable(config[CONF_ID]) parent = await cg.get_variable(config[CONF_ID])
if "PWR" in config: for name,icon in switches:
switch_ = await switch.new_switch(config["PWR"]) if name in config:
cg.add(switch_.set_cmd("PWR")) switch_ = await switch.new_switch(config[name])
cg.add(switch_.set_cmd(name))
cg.add(switch_.set_tw7100_parent(parent)) cg.add(switch_.set_tw7100_parent(parent))
cg.add(parent.set_set_power(switch_)) cg.add(getattr(parent, "set_set_{}".format(name.lower()))(switch_))
if "BTAUDIO" in config:
switch_ = await switch.new_switch(config["BTAUDIO"])
cg.add(switch_.set_cmd("BTAUDIO"))
cg.add(switch_.set_tw7100_parent(parent))
cg.add(parent.set_set_btaudio(switch_))
if "MUTE" in config:
switch_ = await switch.new_switch(config["MUTE"])
cg.add(switch_.set_cmd("MUTE"))
cg.add(switch_.set_tw7100_parent(parent))
cg.add(parent.set_set_mute(switch_))

View file

@ -17,19 +17,39 @@ void tw7100Switch::dump_config() {
void tw7100Switch::write_state(bool state) { void tw7100Switch::write_state(bool state) {
static const char *const TAG = "write_state()"; static const char *const TAG = "write_state()";
ESP_LOGV(TAG, "write switch state for cmd: %s, new state: %i", this->cmd_.c_str(), state); ESP_LOGV(TAG, "write switch state for cmd: %s, new state: %i", this->cmd_.c_str(), state);
if (cmd_ == "PWR") { std::string param = "";
std::string param = state ? "ON" : "OFF"; char param_char[3];
ESP_LOGV(TAG, "pushing back cmd %s with param %s", cmd_.c_str(), param.c_str()); param_char[0] = 0;
parent_->push_cmd(cmd_, param);
if ((cmd_ == "PWR")||(cmd_ == "MUTE")||(cmd_ == "HREVERSE")||(cmd_ == "VREVERSE")) {
param = state ? "ON" : "OFF";
} else if (cmd_ == "IMGPROC") {
sprintf(param_char, "%02d", ((uint8_t)state) + 1);
} else if (cmd_ == "AUDIOOUT") {
sprintf(param_char, "%02d", 10 + state);
} else if (cmd_ == "4KENHANCE") {
sprintf(param_char, "%02d", state);
} else if (cmd_ == "BTAUDIO") { } else if (cmd_ == "BTAUDIO") {
char param [3]; sprintf(param_char, "%02d", state);
sprintf(param, "%02d", state); } else if (cmd_ == "ILLUM") {
ESP_LOGV(TAG, "pushing back cmd %s with param %s", cmd_.c_str(), param); sprintf(param_char, "%02d", state);
parent_->push_cmd(cmd_, param); } else if (cmd_ == "STANDBYCONF") {
} else if (cmd_ == "MUTE") { sprintf(param_char, "%02d", state);
std::string param = state ? "ON" : "OFF"; } else if (cmd_ == "AUTOHOME") {
ESP_LOGV(TAG, "pushing back cmd %s with param %s", cmd_.c_str(), param.c_str()); sprintf(param_char, "%02d", state);
} else if (cmd_ == "WLPWR") {
sprintf(param_char, "%02d", state);
} else if (cmd_ == "LOGTO") {
sprintf(param_char, "%02d", state);
}
if(strlen(param_char) > 0) {
param = param_char;
}
if (param.length() > 0) {
parent_->push_cmd(cmd_, param); parent_->push_cmd(cmd_, param);
ESP_LOGV("", "CMD: %s, PARAM: %s", cmd_.c_str(), param.c_str());
} }
} }

View file

@ -52,7 +52,9 @@ std::vector<std::string> pwr_on_query_cmds{
/* /*
"GAMMA?", "GAMMA?",
"CSEL?", "CSEL?",
*/
"4KENHANCE?", "4KENHANCE?",
/*
"IMGPRESET?", "IMGPRESET?",
*/ */
"SHRF?", "SHRF?",
@ -65,38 +67,39 @@ std::vector<std::string> pwr_on_query_cmds{
"DYNRANGE?", "DYNRANGE?",
"HDRPQ?", "HDRPQ?",
"HDRHLG?", "HDRHLG?",
"IMGPROC?",
*/ */
// "IMGPROC?",
// Sound settings // Sound settings
"VOL?", "VOL?",
/*
"AUDIOOUT?", "AUDIOOUT?",
*/
//
"MUTE?", "MUTE?",
// Environment settings // Environment settings
/*
"HREVERSE?", "HREVERSE?",
"VREVERSE?", "VREVERSE?",
/*
"MSEL?", "MSEL?",
"SPEED?", "SPEED?",
*/
"ILLUM?", "ILLUM?",
"STANDBYCONF?", "STANDBYCONF?",
*/ // "PRODUCT?", // produces ERR
// "PRODUCT?",
//
// Home Screen settings // Home Screen settings
// "AUTOHOME?", // TODO: implement parser "AUTOHOME?",
// Network settings // Network settings
// "WLPWR?", // TODO: implement parser "WLPWR?",
// Bluetooth // Bluetooth
"BTAUDIO?", // TODO: implement parser "BTAUDIO?",
// Information // Information
"SIGNAL?", "SIGNAL?",
// "SOURCELIST?" // Pushed on demand if sensor value is empty (e.g. after boot-up) // "SOURCELIST?" // Pushed on demand if sensor value is empty (e.g. after boot-up)
// "SOURCELISTA?", // same as SOURCELIST // "SOURCELISTA?", // same as SOURCELIST
// "LOGTO?", // TODO: implement parser "LOGTO?", // produces ERR
// "SNO?" // Pushed on demand if sensor value is empty (e.g. after boot-up) // "SNO?" // Pushed on demand if sensor value is empty (e.g. after boot-up)
}; };
@ -248,6 +251,44 @@ void tw7100Component::update_sensor(std::pair<std::string, std::string> data) {
ESP_LOGV(TAG, "updating btaudio switch"); ESP_LOGV(TAG, "updating btaudio switch");
int value = std::stoi(value_string); int value = std::stoi(value_string);
btaudio_switch_->publish_state(value > 0); btaudio_switch_->publish_state(value > 0);
} else if (cmd == "4KENHANCE") {
ESP_LOGV(TAG, "updating 4kenhance switch");
int value = std::stoi(value_string);
_4kenhance_switch_->publish_state(value > 0);
} else if (cmd == "IMGPROC") {
ESP_LOGV(TAG, "updating imgproc switch");
int value = std::stoi(value_string);
img_processing_switch_->publish_state(value > 1);
} else if (cmd == "AUDIOOUT") {
ESP_LOGV(TAG, "updating audioout switch");
int value = std::stoi(value_string);
audioout_switch_->publish_state(value == 11);
} else if (cmd == "HREVERSE") {
ESP_LOGV(TAG, "updating hflip switch");
hflip_switch_->publish_state(value_string == "ON");
} else if (cmd == "VREVERSE") {
ESP_LOGV(TAG, "updating vflip switch");
vflip_switch_->publish_state(value_string == "ON");
} else if (cmd == "ILLUM") {
ESP_LOGV(TAG, "updating illumination switch");
int value = std::stoi(value_string);
illumination_switch_->publish_state(value == 1);
} else if (cmd == "STANDBYCONF") {
ESP_LOGV(TAG, "updating standbyconf switch");
int value = std::stoi(value_string);
standbyconf_switch_->publish_state(value == 1);
} else if (cmd == "AUTOHOME") {
ESP_LOGV(TAG, "updating autohome switch");
int value = std::stoi(value_string);
autohome_switch_->publish_state(value == 1);
} else if (cmd == "WLPWR") {
ESP_LOGV(TAG, "updating wlan power switch");
int value = std::stoi(value_string);
wlan_power_switch_->publish_state(value == 1);
} else if (cmd == "LOGTO") {
ESP_LOGV(TAG, "updating logto switch");
int value = std::stoi(value_string);
logto_switch_->publish_state(value == 1);
} else if (cmd == "SOURCE") { } else if (cmd == "SOURCE") {
ESP_LOGV(TAG, "updating source select"); ESP_LOGV(TAG, "updating source select");
auto call = source_select_->make_call(); auto call = source_select_->make_call();

View file

@ -41,9 +41,20 @@ class tw7100Component : public PollingComponent, public uart::UARTDevice {
void set_signal_status(sensor::Sensor *signal_status) { this->signal_status_ = signal_status; } void set_signal_status(sensor::Sensor *signal_status) { this->signal_status_ = signal_status; }
void set_luminance_level(sensor::Sensor *luminance_level) { this->luminance_level_ = luminance_level; } void set_luminance_level(sensor::Sensor *luminance_level) { this->luminance_level_ = luminance_level; }
void set_serial(text_sensor::TextSensor *serial) { this->serial_ = serial; } void set_serial(text_sensor::TextSensor *serial) { this->serial_ = serial; }
void set_set_power(switch_::Switch *switch_) { this->power_switch_ = switch_; } void set_set_pwr(switch_::Switch *switch_) { this->power_switch_ = switch_; }
void set_set_btaudio(switch_::Switch *switch_) { this->btaudio_switch_ = switch_; } void set_set_btaudio(switch_::Switch *switch_) { this->btaudio_switch_ = switch_; }
void set_set_mute(switch_::Switch *switch_) { this->mute_switch_ = switch_; } void set_set_mute(switch_::Switch *switch_) { this->mute_switch_ = switch_; }
void set_set_wlpwr(switch_::Switch *switch_) { this->wlan_power_switch_ = switch_; }
void set_set_autohome(switch_::Switch *switch_) { this->autohome_switch_ = switch_; }
void set_set_product(switch_::Switch *switch_) { this->product_switch_ = switch_; }
void set_set_standbyconf(switch_::Switch *switch_) { this->standbyconf_switch_ = switch_; }
void set_set_illum(switch_::Switch *switch_) { this->illumination_switch_ = switch_; }
void set_set_vreverse(switch_::Switch *switch_) { this->vflip_switch_ = switch_; }
void set_set_hreverse(switch_::Switch *switch_) { this->hflip_switch_ = switch_; }
void set_set_audioout(switch_::Switch *switch_) { this->audioout_switch_ = switch_; }
void set_set_imgproc(switch_::Switch *switch_) { this->img_processing_switch_ = switch_; }
void set_set_4kenhance(switch_::Switch *switch_) { this->_4kenhance_switch_ = switch_; }
void set_set_logto(switch_::Switch *switch_) { this->logto_switch_ = switch_; }
void set_set_source(tw7100::tw7100Select *source_) { this->source_select_ = source_; } void set_set_source(tw7100::tw7100Select *source_) { this->source_select_ = source_; }
void set_set_luminance(tw7100::tw7100Select *luminance_) { this->luminance_select_ = luminance_; } void set_set_luminance(tw7100::tw7100Select *luminance_) { this->luminance_select_ = luminance_; }
void set_set_vol(tw7100::tw7100Number *number_) { this->volume_number_ = number_; } void set_set_vol(tw7100::tw7100Number *number_) { this->volume_number_ = number_; }
@ -80,6 +91,17 @@ class tw7100Component : public PollingComponent, public uart::UARTDevice {
switch_::Switch *power_switch_{nullptr}; switch_::Switch *power_switch_{nullptr};
switch_::Switch *btaudio_switch_{nullptr}; switch_::Switch *btaudio_switch_{nullptr};
switch_::Switch *mute_switch_{nullptr}; switch_::Switch *mute_switch_{nullptr};
switch_::Switch *wlan_power_switch_{nullptr};
switch_::Switch *autohome_switch_{nullptr};
switch_::Switch *product_switch_{nullptr};
switch_::Switch *standbyconf_switch_{nullptr};
switch_::Switch *illumination_switch_{nullptr};
switch_::Switch *vflip_switch_{nullptr};
switch_::Switch *hflip_switch_{nullptr};
switch_::Switch *audioout_switch_{nullptr};
switch_::Switch *img_processing_switch_{nullptr};
switch_::Switch *_4kenhance_switch_{nullptr};
switch_::Switch *logto_switch_{nullptr};
tw7100::tw7100Select *source_select_{nullptr}; tw7100::tw7100Select *source_select_{nullptr};
tw7100::tw7100Select *luminance_select_{nullptr}; tw7100::tw7100Select *luminance_select_{nullptr};
tw7100::tw7100Number *volume_number_{nullptr}; tw7100::tw7100Number *volume_number_{nullptr};