esphome-tw7100/select/tw7100_select.cpp

82 lines
2.7 KiB
C++
Raw Normal View History

2024-09-17 00:58:39 +02:00
#include "../tw7100.h"
2024-09-16 22:38:48 +02:00
#include "tw7100_select.h"
#include "esphome/core/log.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
namespace esphome {
namespace tw7100 {
2024-09-17 00:58:39 +02:00
std::vector<std::string> get_map_keys(std::map<std::string, std::string> map_) {
2024-09-16 22:38:48 +02:00
std::vector<std::string> map_keys;
for (auto element : map_) { map_keys.push_back(element.first); }
return map_keys;
};
2024-09-17 00:58:39 +02:00
std::vector<std::string> get_map_values(std::map<std::string, std::string> map_) {
std::vector<std::string> map_values;
for (auto element : map_) { map_values.push_back(element.second); }
return map_values;
};
2024-09-16 22:38:48 +02:00
void tw7100Select::setup() {
static const char *const TAG = "tw7100Select::setup()";
if (cmd_ == "SOURCE") {
2024-09-17 00:58:39 +02:00
traits.set_options(get_map_values(sources));
} else if (cmd_ == "LUMINANCE") {
traits.set_options(get_map_values(luminance));
2024-09-19 22:44:44 +02:00
} else if (cmd_ == "ASPECT") {
traits.set_options(get_map_values(aspect));
} else if (cmd_ == "OVSCAN") {
traits.set_options(get_map_values(ovscan));
} else if (cmd_ == "CMODE") {
traits.set_options(get_map_values(cmode));
} else if (cmd_ == "GAMMA") {
traits.set_options(get_map_values(gamma));
} else if (cmd_ == "IMGPRESET") {
traits.set_options(get_map_values(imgpreset));
} else if (cmd_ == "MCFI") {
traits.set_options(get_map_values(mcfi));
} else if (cmd_ == "CLRSPACE") {
traits.set_options(get_map_values(clrspace));
} else if (cmd_ == "DYNRANGE") {
traits.set_options(get_map_values(dynrange));
} else if (cmd_ == "MSEL") {
traits.set_options(get_map_values(msel));
} else if (cmd_ == "SPEED") {
traits.set_options(get_map_values(speed));
2024-09-16 22:38:48 +02:00
}
2024-09-17 00:58:39 +02:00
ESP_LOGV(TAG, "setup done");
2024-09-16 22:38:48 +02:00
}
void tw7100Select::dump_config() {
static const char *const TAG = "dump_config()";
ESP_LOGCONFIG(TAG, "TW7100:");
LOG_SELECT(TAG, "tw7100Select", this);
}
void tw7100Select::control(const std::string &value) {
static const char *const TAG = "tw7100Select::control()";
2024-09-17 00:58:39 +02:00
std::string param;
2024-09-16 22:38:48 +02:00
if (cmd_ == "SOURCE") {
2024-09-17 00:58:39 +02:00
for (auto element : sources) { if (element.second == value) { param = element.first; break; } }
} else if (cmd_ == "LUMINANCE") {
for (auto element : luminance) { if (element.second == value) { param = element.first; break; } }
2024-09-19 22:44:44 +02:00
} else if (cmd_ == "ASPECT") {
for (auto element : aspect) { if (element.second == value) { param = element.first; break; } }
2024-09-16 22:38:48 +02:00
}
2024-09-17 00:58:39 +02:00
2024-09-19 22:44:44 +02:00
if (param.length() > 0) {
if (active_index() != index_of(value)) { // only send out commands if the value actually changed
parent_->push_cmd(cmd_, param);
ESP_LOGV("", "CMD: %s, PARAM: %s", cmd_.c_str(), param.c_str());
}
2024-09-17 00:58:39 +02:00
}
2024-09-19 22:44:44 +02:00
publish_state(value); // but acknowledge everything
2024-09-17 00:58:39 +02:00
2024-09-16 22:38:48 +02:00
ESP_LOGV(TAG, "control done");
};
} // namespace tw7100
} // namespace esphome