init
This commit is contained in:
75
optoma_rs232.h
Normal file
75
optoma_rs232.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#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;
|
||||
|
||||
// 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:
|
||||
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;
|
||||
};
|
||||
|
||||
} // namespace optoma_rs232
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user