Optimize nvs even more with dual light attributes saving
This commit is contained in:
@@ -30,6 +30,7 @@ substitutions:
|
||||
LIGHT_INDIVIDUAL_RESTORE_MODE: RESTORE_DEFAULT_OFF
|
||||
|
||||
LIGHT_ATTRS_DEFAULT: '0x64FFFFFF' # brightness=100, RGB=255,255,255
|
||||
LIGHT_DUAL_ATTRS_DEFAULT: '0x64FFFFFF64FFFFFF' # Both lights: brightness=100, RGB=255,255,255
|
||||
|
||||
TAG_CORE_HW_LEDS: core.hw.leds
|
||||
|
||||
@@ -559,6 +560,22 @@ script:
|
||||
ESP_LOGI("${TAG_CORE_HW_LEDS}", "Restored light attributes: brightness=%d%%, RGB=(%d,%d,%d)",
|
||||
attrs.brightness, attrs.red, attrs.green, attrs.blue);
|
||||
|
||||
- id: light_attributes_restore_dual
|
||||
mode: parallel
|
||||
parameters:
|
||||
light_ptr: light::LightState*
|
||||
attr_global_ptr: uint64_t*
|
||||
group_index: uint8_t # 1 or 2
|
||||
then:
|
||||
- lambda: |-
|
||||
auto attrs_pair = tx_ultimate_easy::unpack_dual_light_attributes(*attr_global_ptr);
|
||||
tx_ultimate_easy::LightAttributes attrs = (group_index == 1) ? attrs_pair.first : attrs_pair.second;
|
||||
|
||||
auto call = light_ptr->make_call();
|
||||
call.set_brightness(attrs.brightness / 100.0f);
|
||||
call.set_rgb(attrs.red / 255.0f, attrs.green / 255.0f, attrs.blue / 255.0f);
|
||||
call.perform();
|
||||
|
||||
- id: light_attributes_save
|
||||
mode: parallel
|
||||
parameters:
|
||||
@@ -578,6 +595,32 @@ script:
|
||||
ESP_LOGD("${TAG_CORE_HW_LEDS}", "Saved light attributes: brightness=%d%%, RGB=(%d,%d,%d)",
|
||||
attrs.brightness, attrs.red, attrs.green, attrs.blue);
|
||||
|
||||
- id: light_attributes_save_dual
|
||||
mode: parallel
|
||||
parameters:
|
||||
light_ptr: light::LightState*
|
||||
attr_global_ptr: uint64_t*
|
||||
group_index: uint8_t # 1 or 2 (which group within the dual pack)
|
||||
then:
|
||||
- lambda: |-
|
||||
auto current = light_ptr->current_values;
|
||||
tx_ultimate_easy::LightAttributes new_attrs = {
|
||||
.brightness = uint8_t(current.get_brightness() * 100.0f),
|
||||
.red = uint8_t(current.get_red() * 255.0f),
|
||||
.green = uint8_t(current.get_green() * 255.0f),
|
||||
.blue = uint8_t(current.get_blue() * 255.0f)
|
||||
};
|
||||
|
||||
// Unpack existing dual attributes
|
||||
auto existing = tx_ultimate_easy::unpack_dual_light_attributes(*attr_global_ptr);
|
||||
|
||||
// Update the appropriate group
|
||||
if (group_index == 1) {
|
||||
*attr_global_ptr = tx_ultimate_easy::pack_dual_light_attributes(new_attrs, existing.second);
|
||||
} else {
|
||||
*attr_global_ptr = tx_ultimate_easy::pack_dual_light_attributes(existing.first, new_attrs);
|
||||
}
|
||||
|
||||
select:
|
||||
# EU relay light mode template
|
||||
- &relay_light_mode_eu
|
||||
|
||||
Reference in New Issue
Block a user