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:
@@ -23,6 +23,11 @@ void DynamicLamp::setup() {
|
|||||||
this->restore_lamp_values_(i);
|
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() {
|
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) {
|
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;
|
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)
|
std::string_view DynamicLamp::ltrim_(std::string_view str)
|
||||||
{
|
{
|
||||||
const auto pos(str.find_first_not_of(" \t\n\r\f\v"));
|
const auto pos(str.find_first_not_of(" \t\n\r\f\v"));
|
||||||
|
@@ -28,6 +28,7 @@ struct LinkedOutput {
|
|||||||
|
|
||||||
struct CombinedLamp {
|
struct CombinedLamp {
|
||||||
bool active = false;
|
bool active = false;
|
||||||
|
bool[16] used_outputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DynamicLamp : public Component {
|
class DynamicLamp : public Component {
|
||||||
@@ -39,8 +40,11 @@ class DynamicLamp : public Component {
|
|||||||
void set_save_mode(uint8_t save_mode);
|
void set_save_mode(uint8_t save_mode);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
int[16] get_lamp_outputs_(uint8_t lamp_number);
|
||||||
|
void add_lamp_output_(uint8_t lamp_number, LinkedOutput output);
|
||||||
void restore_lamp_values_(uint8_t lamp_number);
|
void restore_lamp_values_(uint8_t lamp_number);
|
||||||
void set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value);
|
void set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value);
|
||||||
|
size_t index_of_(Iter first, Iter last, typename const std::iterator_traits<Iter>::value_type& x)
|
||||||
std::string_view ltrim_(std::string_view str);
|
std::string_view ltrim_(std::string_view str);
|
||||||
std::string_view rtrim_(std::string_view str);
|
std::string_view rtrim_(std::string_view str);
|
||||||
std::string_view trim_(std::string_view str);
|
std::string_view trim_(std::string_view str);
|
||||||
|
Reference in New Issue
Block a user