esphome_optoma_rs232/optoma_rs232.h

86 lines
2.2 KiB
C
Raw Normal View History

2025-03-14 15:23:22 +01:00
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/uart/uart.h"
#ifdef USE_SELECT
#include "esphome/components/sensor/sensor.h"
#endif
#ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif
#ifdef USE_TEXT_SENSOR
#include "esphome/components/text_sensor/text_sensor.h"
#endif
#ifdef USE_SELECT
#include "esphome/components/select/select.h"
#endif
namespace esphome {
namespace optoma_rs232 {
// clang-format off
class DummySensor { public: template<typename M> static void publish_state(M) {} };
class DummySelect {};
// clang-format on
enum Inputs {
UNKNOWN = 0,
VGA = 2,
HDMI_1 = 7,
HDMI_2 = 8,
};
class OptomaRS232Component : public uart::UARTDevice, public PollingComponent {
public:
void dump_config() override;
void loop() override;
float get_setup_priority() const override { return setup_priority::DATA; }
void update() override;
2025-03-14 17:57:43 +01:00
void beamer_input_select_changed(const std::string &, size_t);
2025-03-14 15:23:22 +01:00
// clang-format off
#ifndef USE_SENSOR
#define SUB_SENSOR(name) protected: DummySensor *name##_sensor_{nullptr}; public:
#endif
#ifndef USE_BINARY_SENSOR
#define SUB_BINARY_SENSOR(name) protected: DummySensor *name##_binary_sensor_{nullptr}; public:
#endif
#ifndef USE_TEXT_SENSOR
#define SUB_TEXT_SENSOR(name) protected: DummySensor *name##_text_sensor_{nullptr}; public:
#endif
#ifndef USE_SELECT
#define SUB_SELECT(name) protected: DummySelect *name##_select_{nullptr}; public:
#endif
// clang-format on
SUB_SENSOR(beamer_temp)
SUB_SENSOR(beamer_lamp_time)
SUB_SENSOR(beamer_fan1)
SUB_SENSOR(beamer_color_mode)
SUB_BINARY_SENSOR(beamer_power)
SUB_TEXT_SENSOR(beamer_input)
SUB_SELECT(beamer_input)
protected:
2025-03-14 17:57:43 +01:00
Inputs current_input_{UNKNOWN};
2025-03-14 15:23:22 +01:00
void process_line_(const std::string &str);
void process_query_response_(const std::string &str);
bool waiting_for_command_response_ = false;
int last_query_ = -1;
private:
char buffer_[128]{};
size_t cursor_ = 0;
};
2025-03-14 17:57:43 +01:00
#ifdef USE_SELECT
class InputSelect : public select::Select, public Parented<OptomaRS232Component> {
protected:
void control(const std::string &value) override;
};
#endif
2025-03-14 15:23:22 +01:00
} // namespace optoma_rs232
} // namespace esphome