Add available effects to info action
This commit is contained in:
@@ -6,6 +6,7 @@ from buttonplus_generator.utils import (
|
||||
array_to_cpp_vector_raw,
|
||||
display_id,
|
||||
bar_id,
|
||||
get_light_effects
|
||||
)
|
||||
|
||||
|
||||
@@ -22,11 +23,14 @@ def leds_actions(version: int, num_bars: int) -> Dict[str, Any]:
|
||||
all_led_ids = _get_list_leds(version, num_bars)
|
||||
generated_cpp = ""
|
||||
|
||||
#TODO add effect to page info, or not if --no-effects
|
||||
#TODO: add effect to page info, or not if --no-effects
|
||||
|
||||
for led_id in all_led_ids:
|
||||
generated_cpp += f'leds.add("{led_id}");\n'
|
||||
|
||||
for effect_name in get_light_effects(True, True):
|
||||
generated_cpp += f'effects.add("{effect_name}");\n'
|
||||
|
||||
return {
|
||||
"api": {
|
||||
"actions": [
|
||||
@@ -114,7 +118,7 @@ def leds_actions(version: int, num_bars: int) -> Dict[str, Any]:
|
||||
],
|
||||
},
|
||||
{
|
||||
"action": "get_page_info",
|
||||
"action": "get_info",
|
||||
"supports_response": "only",
|
||||
"then": [
|
||||
{
|
||||
@@ -126,6 +130,7 @@ def leds_actions(version: int, num_bars: int) -> Dict[str, Any]:
|
||||
"for(const std::string& page_name : id(page_names)){\n"
|
||||
" pages.add(page_name);\n"
|
||||
"}\n"
|
||||
'JsonArray effects = root["effects"].to<JsonArray>();\n'
|
||||
'JsonArray leds = root["leds"].to<JsonArray>();\n'
|
||||
)
|
||||
+ generated_cpp
|
||||
@@ -134,6 +139,23 @@ def leds_actions(version: int, num_bars: int) -> Dict[str, Any]:
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"action": "reset_all_page_leds",
|
||||
"then": [
|
||||
{
|
||||
"lambda": (
|
||||
"for(auto &kv : id(internal_page_leds_r)) std::fill(kv.second.begin(), kv.second.end(), 0.0);\n"
|
||||
"for(auto &kv : id(internal_page_leds_g)) std::fill(kv.second.begin(), kv.second.end(), 0.0);\n"
|
||||
"for(auto &kv : id(internal_page_leds_b)) std::fill(kv.second.begin(), kv.second.end(), 0.0);\n"
|
||||
"for(auto &kv : id(internal_page_leds_brightness)) std::fill(kv.second.begin(), kv.second.end(), 0.0);\n"
|
||||
"for(auto &kv : id(internal_page_leds_effect)) std::fill(kv.second.begin(), kv.second.end(), std::string());\n"
|
||||
)
|
||||
},
|
||||
{
|
||||
"script.execute": "update_all_page_leds"
|
||||
}
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,13 @@ def get_display_mcp_address(num_bars : int) -> str:
|
||||
|
||||
return f"{0x23 - num_bars}"
|
||||
|
||||
def get_light_effects(enabled: bool) -> List[Dict[str, Any]]:
|
||||
def get_light_effects(enabled: bool, names_only: bool = False) -> List[Dict[str, Any]] | List[str]:
|
||||
if not enabled:
|
||||
return []
|
||||
|
||||
if names_only:
|
||||
return ["None", "Breathe", "Blink"]
|
||||
|
||||
return [
|
||||
{
|
||||
"pulse": {
|
||||
@@ -85,6 +88,14 @@ def get_light_effects(enabled: bool) -> List[Dict[str, Any]]:
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
def get_light_effects_list(enabled: bool) -> List[str]:
|
||||
if not enabled:
|
||||
return []
|
||||
|
||||
return [
|
||||
"Breathe", "Blink"
|
||||
]
|
||||
|
||||
def string_to_click_type(ct:str) -> ClickType:
|
||||
if ct == "single":
|
||||
|
||||
Reference in New Issue
Block a user