Browse Source

Implementd actions for activating a preset group or a specific preset.

pull/9/head
Maurice Makaay 3 years ago
parent
commit
207bcd5508
3 changed files with 68 additions and 48 deletions
  1. +2
    -2
      front_panel_hal.h
  2. +65
    -45
      light/presets.h
  3. +1
    -1
      sensor/slider_sensor.h

+ 2
- 2
front_panel_hal.h View File

@ -185,8 +185,8 @@ public:
}
void dump_config() {
ESP_LOGCONFIG(TAG, "I2C interrupt");
LOG_PIN(" Interrupt pin: ", trigger_pin_);
ESP_LOGCONFIG(TAG, "FrontPanelHAL:");
LOG_PIN(" I2C interrupt pin: ", trigger_pin_);
}
void loop() {


+ 65
- 45
light/presets.h View File

@ -10,15 +10,19 @@ class Preset {
public:
std::string name;
Preset *next_preset = nullptr;
std::string group_name;
light::LightCall *light_call;
explicit Preset(std::string name) : name(name) {}
explicit Preset(std::string name, std::string group_name) :
name(name), group_name(group_name) {}
void set_light_call(light::LightCall *light_call) {
this->light_call = light_call;
}
void apply() {
ESP_LOGI(TAG, "Activating light preset: %s/%s",
group_name.c_str(), name.c_str());
light_call->perform();
}
};
@ -36,7 +40,7 @@ public:
Preset *make_preset(std::string p_name) {
auto p = get_preset(p_name);
if (p == nullptr) {
p = new Preset(p_name);
p = new Preset(p_name, this->name);
if (first_preset == nullptr) {
first_preset = last_preset = active_preset = p;
} else {
@ -59,14 +63,18 @@ public:
class PresetsContainer : public Component {
public:
PresetGroup *first_group = nullptr;
PresetGroup *last_group = nullptr;
PresetGroup *active_group = nullptr;
explicit PresetsContainer(light::LightState *light) : _light(light) { }
void dump_config() {
if (first_group_ == nullptr) {
if (first_group == nullptr) {
return;
}
ESP_LOGCONFIG(TAG, "Light Presets:");
for (auto g = first_group_; g != nullptr; g = g->next_group) {
for (auto g = first_group; g != nullptr; g = g->next_group) {
ESP_LOGCONFIG(TAG, " Preset group: %s", g->name.c_str());
for (auto p = g->first_preset; p != nullptr; p = p->next_preset) {
ESP_LOGCONFIG(TAG, " Preset: %s", p->name.c_str());
@ -76,9 +84,7 @@ public:
void add(std::string g_name, std::string p_name, float r, float g, float b) {
auto call = make_preset_call_(g_name, p_name);
call->set_red(r);
call->set_green(g);
call->set_blue(b);
call->set_rgb(r, g, b);
}
void add(std::string g_name, std::string p_name, float t) {
@ -86,81 +92,95 @@ public:
call->set_color_temperature(t);
}
PresetGroup *get_group(std::string g_name) {
for (auto g = first_group; g != nullptr; g = g->next_group) {
if (g->name == g_name) {
return g;
}
}
return nullptr;
}
void activate_next_group() {
if (active_group_ == nullptr) {
if (active_group == nullptr) {
ESP_LOGW(TAG, "activate_next_group(): no preset groups defined");
return;
}
active_group_ = active_group_->next_group == nullptr
? first_group_ : active_group_->next_group;
if (active_group_->active_preset == nullptr) {
active_group = active_group->next_group == nullptr
? first_group : active_group->next_group;
if (active_group->active_preset == nullptr) {
ESP_LOGW(TAG, "activate_next_group(): no presets defined for group %s",
active_group_->name.c_str());
active_group->name.c_str());
return;
}
ESP_LOGW(TAG, "activate_next_group(): activating %s/%s",
active_group_->name.c_str(),
active_group_->active_preset->name.c_str());
active_group_->active_preset->apply();
active_group->active_preset->apply();
}
void activate_next_preset() {
if (active_group_ == nullptr) {
if (active_group == nullptr) {
ESP_LOGW(TAG, "activate_next_preset(): no preset groups defined");
return;
}
auto p = active_group_->active_preset;
auto p = active_group->active_preset;
if (p == nullptr) {
ESP_LOGW(TAG, "activate_next_preset(): no presets defined for group %s",
active_group_->name.c_str());
active_group->name.c_str());
return;
}
active_group_->active_preset = p->next_preset == nullptr
? active_group_->first_preset : p->next_preset;
ESP_LOGW(TAG, "activate_next_preset(): activating %s/%s",
active_group_->name.c_str(),
active_group_->active_preset->name.c_str());
active_group_->active_preset->apply();
active_group->active_preset = p->next_preset == nullptr
? active_group->first_preset : p->next_preset;
active_group->active_preset->apply();
}
void activate_group(std::string g_name) {
ESP_LOGI(TAG, "Activate group %s", g_name.c_str());
auto g = get_group(g_name);
if (g == nullptr) {
ESP_LOGE(TAG, "activate_group(%s): preset group does not exist",
g_name.c_str());
return;
}
auto p = g->active_preset;
if (p == nullptr) {
ESP_LOGW(TAG, "activate_group(%s): no presets defined for group",
g_name.c_str());
return;
}
p->apply();
}
void activate_preset(std::string g_name, std::string p_name) {
ESP_LOGI(TAG, "Activate preset %s/%s", g_name.c_str(), p_name.c_str());
auto g = get_group(g_name);
if (g == nullptr) {
ESP_LOGE(TAG, "activate_preset(%s, %s): preset group %s does not exist",
g_name.c_str(), p_name.c_str(), g_name.c_str());
return;
}
auto p = g->get_preset(p_name);
if (p == nullptr) {
ESP_LOGE(TAG, "activate_preset(%s, %s): preset %s does not exist in group %s",
g_name.c_str(), p_name.c_str(), p_name.c_str(), g_name.c_str());
return;
}
p->apply();
}
protected:
light::LightState *_light;
PresetGroup *first_group_ = nullptr;
PresetGroup *last_group_ = nullptr;
PresetGroup *active_group_ = nullptr;
PresetGroup *make_preset_group_(std::string g_name) {
auto g = get_group_(g_name);
auto g = get_group(g_name);
if (g == nullptr) {
g = new PresetGroup(g_name);
if (first_group_ == nullptr) {
first_group_ = last_group_ = active_group_ = g;
if (first_group == nullptr) {
first_group = last_group = active_group = g;
} else {
last_group_->next_group = g;
last_group_ = g;
last_group->next_group = g;
last_group = g;
}
}
return g;
}
PresetGroup *get_group_(std::string g_name) {
for (auto g = first_group_; g != nullptr; g = g->next_group) {
if (g->name == g_name) {
return g;
}
}
return nullptr;
}
light::LightCall *make_preset_call_(std::string g_name, std::string p_name) {
auto g = make_preset_group_(g_name);
auto p = g->make_preset(p_name);


+ 1
- 1
sensor/slider_sensor.h View File

@ -48,7 +48,7 @@ public:
}
void dump_config() {
ESP_LOGCONFIG(TAG, "Front Panel slider sensor:");
ESP_LOGCONFIG(TAG, "Front panel slider sensor:");
ESP_LOGCONFIG(TAG, " Range from: %f", range_from_);
ESP_LOGCONFIG(TAG, " Range to: %f", range_to_);
}


Loading…
Cancel
Save