1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-09 23:02:23 +01:00

feat: add lamp output management and index retrieval in DynamicLamp

This commit is contained in:
Oliver Kleinecke
2025-02-14 15:38:01 +01:00
parent 1a73a7de01
commit 8de13bda8f
2 changed files with 24 additions and 0 deletions

View File

@@ -23,6 +23,11 @@ void DynamicLamp::setup() {
this->restore_lamp_values_(i);
}
}
// for testing only
this->add_lamp_output_(0, this->available_outputs_[0]);
this->add_lamp_output_(0, this->available_outputs_[1]);
this->add_lamp_output_(0, this->available_outputs_[2]);
this->add_lamp_output_(0, this->available_outputs_[3]);
}
void DynamicLamp::loop() {
@@ -100,6 +105,12 @@ void DynamicLamp::set_available_outputs(std::string output_list) {
}
}
void add_lamp_output_(uint8_t lamp_number, LinkedOutput output) {
uint8_t output_index;
output_index = this->index_of_(this->available_outputs_, this->available_outputs_ + 16, output);
this->active_lamps_[lamp_number].used_outputs[output_index] = true;
}
void DynamicLamp::set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value) {
}
@@ -108,6 +119,15 @@ void DynamicLamp::restore_lamp_values_(uint8_t lamp_number) {
this->active_lamps_[lamp_number].active = false;
}
template <typename Iter>
size_t DynamicLamp::index_of_(Iter first, Iter last, typename const std::iterator_traits<Iter>::value_type& x)
{
size_t i = 0;
while (first != last && *first != x)
++first, ++i;
return i;
}
std::string_view DynamicLamp::ltrim_(std::string_view str)
{
const auto pos(str.find_first_not_of(" \t\n\r\f\v"));