Add select
This commit is contained in:
@@ -56,6 +56,29 @@ void OptomaRS232Component::update() {
|
||||
write_array(reinterpret_cast<const uint8_t *>(QUERIES[last_query_]), strlen(QUERIES[last_query_]));
|
||||
}
|
||||
|
||||
void OptomaRS232Component::beamer_input_select_changed(const std::string &state, size_t) {
|
||||
const char *data;
|
||||
Inputs inp{UNKNOWN};
|
||||
if (state == "Unknown")
|
||||
return;
|
||||
if (state == "HDMI 1") {
|
||||
inp = HDMI_1;
|
||||
data = "~0012 1\r";
|
||||
} else if (state == "HDMI 2") {
|
||||
inp = HDMI_2;
|
||||
data = "~0012 15\r";
|
||||
} else if (state == "VGA") {
|
||||
inp = VGA;
|
||||
data = "~0012 5\r"; // VGA 1
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (inp == current_input_)
|
||||
return;
|
||||
current_input_ = inp;
|
||||
write_array(reinterpret_cast<const uint8_t *>(data), strlen(data));
|
||||
}
|
||||
|
||||
void OptomaRS232Component::process_line_(const std::string &str) {
|
||||
// if we are waiting for the projector to respond to a command.
|
||||
// it will respond P (pass) or F (fail) before giving us the actual response to the command.
|
||||
@@ -110,19 +133,23 @@ void OptomaRS232Component::process_query_response_(const std::string &str) {
|
||||
// publish(beamer_firmware_,strtol(buf + 10, 0, 10));
|
||||
buf[10] = 0;
|
||||
|
||||
int input = -1; // atol(buf + 8); BUGGY
|
||||
int input = strtol(buf + 8, 0, 10); // BUGGY
|
||||
switch (input) {
|
||||
case Inputs::HDMI_1:
|
||||
current_input_ = Inputs::HDMI_1;
|
||||
publish(beamer_input_text_sensor_, "HDMI 1");
|
||||
break;
|
||||
case Inputs::HDMI_2:
|
||||
current_input_ = Inputs::HDMI_2;
|
||||
publish(beamer_input_text_sensor_, "HDMI 2");
|
||||
break;
|
||||
case Inputs::VGA:
|
||||
current_input_ = Inputs::VGA;
|
||||
publish(beamer_input_text_sensor_, "VGA");
|
||||
break;
|
||||
default:
|
||||
case Inputs::UNKNOWN:
|
||||
current_input_ = Inputs::UNKNOWN;
|
||||
publish(beamer_input_text_sensor_, "Unknown");
|
||||
break;
|
||||
}
|
||||
@@ -139,5 +166,14 @@ void OptomaRS232Component::process_query_response_(const std::string &str) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_SELECT
|
||||
void InputSelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
auto index = this->index_of(value);
|
||||
if (index.has_value())
|
||||
this->parent_->beamer_input_select_changed(value, *index);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace optoma_rs232
|
||||
} // namespace esphome
|
||||
|
||||
Reference in New Issue
Block a user