Ignore Lamp time when power off
This commit is contained in:
parent
76f27cdfeb
commit
2866b79ff4
@ -7,11 +7,18 @@ namespace optoma_rs232 {
|
|||||||
|
|
||||||
[[maybe_unused]] static const char *const TAG = "optoma_rs232";
|
[[maybe_unused]] static const char *const TAG = "optoma_rs232";
|
||||||
|
|
||||||
static const char *QUERIES[] = {
|
enum QUERIES {
|
||||||
|
INFO = 0,
|
||||||
|
TEMP,
|
||||||
|
LAMP_TIME,
|
||||||
|
FAN_1,
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr const char *QUERY_DATA[] = {
|
||||||
|
"~00150 1\r", // Info
|
||||||
"~00150 18\r", // Temp
|
"~00150 18\r", // Temp
|
||||||
"~00108 1\r", // Lamp time
|
"~00108 1\r", // Lamp time
|
||||||
"~00351 1\r", // Fan 1
|
"~00351 1\r", // Fan 1
|
||||||
"~00150 1\r", // Info
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename C, typename M> static void publish(C *c, const M &m) {
|
template<typename C, typename M> static void publish(C *c, const M &m) {
|
||||||
@ -62,8 +69,8 @@ void OptomaRS232Component::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OptomaRS232Component::update() {
|
void OptomaRS232Component::update() {
|
||||||
last_query_ = (last_query_ + 1) % std::size(QUERIES);
|
last_query_ = (last_query_ + 1) % std::size(QUERY_DATA);
|
||||||
write_array(reinterpret_cast<const uint8_t *>(QUERIES[last_query_]), strlen(QUERIES[last_query_]));
|
write_array(reinterpret_cast<const uint8_t *>(QUERY_DATA[last_query_]), strlen(QUERY_DATA[last_query_]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptomaRS232Component::beamer_input_select_changed(const std::string &state, size_t) {
|
void OptomaRS232Component::beamer_input_select_changed(const std::string &state, size_t) {
|
||||||
@ -118,7 +125,7 @@ void OptomaRS232Component::process_line_(const std::string &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (str_startswith(str, "OK")) {
|
if (str_startswith(str, "OK")) {
|
||||||
// ESP_LOGD(TAG, "OK-message: %s", str.c_str());
|
ESP_LOGD(TAG, "OK-message: %s", str.c_str());
|
||||||
process_query_response_(str);
|
process_query_response_(str);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,27 +136,36 @@ void OptomaRS232Component::process_line_(const std::string &str) {
|
|||||||
void OptomaRS232Component::process_query_response_(const std::string &str) {
|
void OptomaRS232Component::process_query_response_(const std::string &str) {
|
||||||
if (str.length() >= 3) {
|
if (str.length() >= 3) {
|
||||||
switch (last_query_) {
|
switch (last_query_) {
|
||||||
case 0:
|
case QUERIES::TEMP:
|
||||||
publish(beamer_temp_sensor_, strtol(str.c_str() + 2, 0, 10));
|
publish(beamer_temp_sensor_, strtol(str.c_str() + 2, 0, 10));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case QUERIES::LAMP_TIME:
|
||||||
publish(beamer_lamp_time_sensor_, strtol(str.c_str() + 2, 0, 10));
|
if (str.length() == 7)
|
||||||
|
publish(beamer_lamp_time_sensor_, strtol(str.c_str() + 2, 0, 10));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case QUERIES::FAN_1:
|
||||||
publish(beamer_fan1_sensor_, strtol(str.c_str() + 2, 0, 10));
|
publish(beamer_fan1_sensor_, strtol(str.c_str() + 2, 0, 10));
|
||||||
break;
|
break;
|
||||||
case 3:
|
case QUERIES::INFO:
|
||||||
if (str.length() >= 13) {
|
if (str.length() >= 13) {
|
||||||
char buf[17]{};
|
char buf[17]{};
|
||||||
strncpy(buf, str.c_str(), sizeof(buf));
|
strncpy(buf, str.c_str(), sizeof(buf));
|
||||||
publish(beamer_color_mode_sensor_, strtol(buf + 14, 0, 10));
|
const auto color_mode = strtol(buf + 14, 0, 10);
|
||||||
buf[14] = 0;
|
buf[14] = 0;
|
||||||
|
const auto firmware = strtol(buf + 10, 0, 10);
|
||||||
// publish(beamer_firmware_,strtol(buf + 10, 0, 10));
|
|
||||||
buf[10] = 0;
|
buf[10] = 0;
|
||||||
|
const auto input = strtol(buf + 8, 0, 10);
|
||||||
int input = strtol(buf + 8, 0, 10); // OK10041700C00900
|
|
||||||
buf[8] = 0;
|
buf[8] = 0;
|
||||||
|
const auto lamp_time = strtol(buf + 3, 0, 10);
|
||||||
|
buf[3] = 0;
|
||||||
|
const auto power = strtol(buf + 2, 0, 10);
|
||||||
|
|
||||||
|
publish_power_(power);
|
||||||
|
// publish(beamer_firmware_, firmware);
|
||||||
|
if (power)
|
||||||
|
publish(beamer_lamp_time_sensor_, lamp_time);
|
||||||
|
publish(beamer_color_mode_sensor_, color_mode);
|
||||||
|
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case Inputs::HDMI_1:
|
case Inputs::HDMI_1:
|
||||||
current_input_ = Inputs::HDMI_1;
|
current_input_ = Inputs::HDMI_1;
|
||||||
@ -169,11 +185,6 @@ void OptomaRS232Component::process_query_response_(const std::string &str) {
|
|||||||
publish_input_("Unknown");
|
publish_input_("Unknown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
publish(beamer_lamp_time_sensor_, strtol(buf + 3, 0, 10));
|
|
||||||
buf[3] = 0;
|
|
||||||
|
|
||||||
publish_power_(strtol(buf + 2, 0, 10));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:;
|
default:;
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/components/uart/uart.h"
|
#include "esphome/components/uart/uart.h"
|
||||||
|
|
||||||
#undef USE_SENSOR
|
// #undef USE_SENSOR
|
||||||
#undef USE_BINARY_SENSOR
|
// #undef USE_BINARY_SENSOR
|
||||||
#undef USE_TEXT_SENSOR
|
// #undef USE_TEXT_SENSOR
|
||||||
#undef USE_SELECT
|
// #undef USE_SELECT
|
||||||
#undef USE_SWITCH
|
// #undef USE_SWITCH
|
||||||
|
|
||||||
#ifdef USE_SENSOR
|
#ifdef USE_SENSOR
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
@ -52,19 +52,19 @@ class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#ifndef USE_SENSOR
|
#ifndef USE_SENSOR
|
||||||
#define SUB_SENSOR(name) protected: DummySensor *name## _sensor_{nullptr}; public:
|
#define SUB_SENSOR(name) protected: DummySensor *name##_sensor_{nullptr}; public:
|
||||||
#endif
|
#endif
|
||||||
#ifndef USE_BINARY_SENSOR
|
#ifndef USE_BINARY_SENSOR
|
||||||
#define SUB_BINARY_SENSOR(name) protected: DummySensor *name## _binary_sensor_{nullptr}; public:
|
#define SUB_BINARY_SENSOR(name) protected: DummySensor *name##_binary_sensor_{nullptr}; public:
|
||||||
#endif
|
#endif
|
||||||
#ifndef USE_TEXT_SENSOR
|
#ifndef USE_TEXT_SENSOR
|
||||||
#define SUB_TEXT_SENSOR(name) protected: DummySensor *name## _text_sensor_{nullptr}; public:
|
#define SUB_TEXT_SENSOR(name) protected: DummySensor *name##_text_sensor_{nullptr}; public:
|
||||||
#endif
|
#endif
|
||||||
#ifndef USE_SELECT
|
#ifndef USE_SELECT
|
||||||
#define SUB_SELECT(name) protected: DummySelect *name## _select_{nullptr}; public:
|
#define SUB_SELECT(name) protected: DummySelect *name##_select_{nullptr}; public:
|
||||||
#endif
|
#endif
|
||||||
#ifndef USE_SWITCH
|
#ifndef USE_SWITCH
|
||||||
#define SUB_SWITCH(name) protected: DummySwitch *name## _switch_{nullptr}; public:
|
#define SUB_SWITCH(name) protected: DummySwitch *name##_switch_{nullptr}; public:
|
||||||
#endif
|
#endif
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user