Generated IDs
This commit is contained in:
@@ -14,10 +14,28 @@ GPIO_I2C_BUTTONS_SCL = "GPIO2" #I2C SCL > Buttons
|
|||||||
GPIO_I2C_SENSORS_SDA = "GPIO47" #I2C SDA > Temperature & Ambient Sensor
|
GPIO_I2C_SENSORS_SDA = "GPIO47" #I2C SDA > Temperature & Ambient Sensor
|
||||||
GPIO_I2C_SENSORS_SCL = "GPIO48" #I2S SCL > Temperature & Ambient Sensor
|
GPIO_I2C_SENSORS_SCL = "GPIO48" #I2S SCL > Temperature & Ambient Sensor
|
||||||
|
|
||||||
class BarSide(StrEnum):
|
class Side(StrEnum):
|
||||||
LEFT = "left"
|
LEFT = "left"
|
||||||
RIGHT = "right"
|
RIGHT = "right"
|
||||||
|
|
||||||
|
class Direction(StrEnum):
|
||||||
|
FRONT = "front"
|
||||||
|
BACK = "back"
|
||||||
|
|
||||||
|
class IdSuffix(StrEnum):
|
||||||
|
LED = "rgb_led"
|
||||||
|
BUTTON = "btn"
|
||||||
|
BACKLIGHT = "backlight"
|
||||||
|
DISPLAY = "disp"
|
||||||
|
|
||||||
|
EVENT_BUTTON = "btn_event"
|
||||||
|
|
||||||
|
BACKLIGHT_PWM = "backlight_pwm"
|
||||||
|
CS_PIN = "cs_pin"
|
||||||
|
|
||||||
|
SCRIPT_UPDATE = "script_update"
|
||||||
|
SCRIPT_DRAW = "script_draw"
|
||||||
|
|
||||||
class ClickType(StrEnum):
|
class ClickType(StrEnum):
|
||||||
SINGLE = "click"
|
SINGLE = "click"
|
||||||
DOUBLE = "double_click"
|
DOUBLE = "double_click"
|
||||||
@@ -27,7 +45,7 @@ class ClickType(StrEnum):
|
|||||||
class Color():
|
class Color():
|
||||||
|
|
||||||
def __init__(self, hex: str):
|
def __init__(self, hex: str):
|
||||||
self.hex = hex.lstrip("#")
|
self.hex: str = hex.lstrip("#")
|
||||||
|
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
@@ -42,10 +60,6 @@ class Color():
|
|||||||
self.g = int(self.hex[(offset):(offset*2)], 16)
|
self.g = int(self.hex[(offset):(offset*2)], 16)
|
||||||
self.b = int(self.hex[(offset*2):(offset*3)], 16)
|
self.b = int(self.hex[(offset*2):(offset*3)], 16)
|
||||||
|
|
||||||
def hex(self) -> str:
|
|
||||||
return "#" + self.hex
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TIMING_SINGLE_CLICK = [
|
TIMING_SINGLE_CLICK = [
|
||||||
"ON for at most 300ms",
|
"ON for at most 300ms",
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from buttonplus_generator.snippets.services import config_services
|
|||||||
from buttonplus_generator.merger import deep_merge
|
from buttonplus_generator.merger import deep_merge
|
||||||
from buttonplus_generator.utils import list_to_click_type
|
from buttonplus_generator.utils import list_to_click_type
|
||||||
|
|
||||||
|
|
||||||
def compose_config(
|
def compose_config(
|
||||||
device_name: str,
|
device_name: str,
|
||||||
version: int,
|
version: int,
|
||||||
@@ -65,7 +64,6 @@ def compose_config(
|
|||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def yaml_dumper(config: Dict[str, Any], fh) -> str:
|
def yaml_dumper(config: Dict[str, Any], fh) -> str:
|
||||||
|
|
||||||
## Handle multiline strings
|
## Handle multiline strings
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from typing import Dict, Any, List
|
from typing import Dict, Any, List
|
||||||
from buttonplus_generator.constants import *
|
from buttonplus_generator.constants import *
|
||||||
from buttonplus_generator.merger import deep_merge
|
from buttonplus_generator.merger import deep_merge
|
||||||
from buttonplus_generator.utils import get_light_effects
|
from buttonplus_generator.utils import bar_id, get_light_effects
|
||||||
|
|
||||||
|
|
||||||
def config_bars(version: int, num_bars: int, page_names: List[str], add_effects: bool) -> Dict[str, Any]:
|
def config_bars(version: int, num_bars: int, page_names: List[str], add_effects: bool) -> Dict[str, Any]:
|
||||||
@@ -30,7 +30,7 @@ def bars_backlight() -> Dict[str, Any]:
|
|||||||
{
|
{
|
||||||
"platform": "ledc",
|
"platform": "ledc",
|
||||||
"pin": GPIO_BACKLIGHT_MINI,
|
"pin": GPIO_BACKLIGHT_MINI,
|
||||||
"id": "displays_mini_backlight_pwm",
|
"id": bar_id(IdSuffix.BACKLIGHT_PWM, None),
|
||||||
"inverted": True,
|
"inverted": True,
|
||||||
"max_power": 0.6,
|
"max_power": 0.6,
|
||||||
"frequency": "500Hz",
|
"frequency": "500Hz",
|
||||||
@@ -39,10 +39,10 @@ def bars_backlight() -> Dict[str, Any]:
|
|||||||
"light": [
|
"light": [
|
||||||
{
|
{
|
||||||
"platform": "monochromatic",
|
"platform": "monochromatic",
|
||||||
"output": "displays_mini_backlight_pwm",
|
"output": bar_id(IdSuffix.BACKLIGHT_PWM, None),
|
||||||
"gamma_correct": 2.2,
|
"gamma_correct": 2.2,
|
||||||
"name": "Bars Display Backlight",
|
"name": "Bars Display Backlight",
|
||||||
"id": "displays_mini_backlight",
|
"id": bar_id(IdSuffix.BACKLIGHT, None),
|
||||||
"restore_mode": "ALWAYS_ON",
|
"restore_mode": "ALWAYS_ON",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -50,7 +50,7 @@ def bars_backlight() -> Dict[str, Any]:
|
|||||||
|
|
||||||
|
|
||||||
def bars_setup(num_bars: int = 3) -> Dict[str, Any]:
|
def bars_setup(num_bars: int = 3) -> Dict[str, Any]:
|
||||||
bar_dict = {"mcp23008": []}
|
bar_dict: Dict[str, Any] = {"mcp23008": []}
|
||||||
|
|
||||||
# esphome.on_boot.then.[]
|
# esphome.on_boot.then.[]
|
||||||
scripts = []
|
scripts = []
|
||||||
@@ -66,8 +66,8 @@ def bars_setup(num_bars: int = 3) -> Dict[str, Any]:
|
|||||||
|
|
||||||
scripts.extend(
|
scripts.extend(
|
||||||
[
|
[
|
||||||
{"script.execute": "update_bar1_left"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 1, Side.LEFT)},
|
||||||
{"script.execute": "update_bar1_right"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 1, Side.RIGHT)},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -79,8 +79,8 @@ def bars_setup(num_bars: int = 3) -> Dict[str, Any]:
|
|||||||
|
|
||||||
scripts.extend(
|
scripts.extend(
|
||||||
[
|
[
|
||||||
{"script.execute": "update_bar2_left"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 2, Side.LEFT)},
|
||||||
{"script.execute": "update_bar2_right"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 2, Side.RIGHT)},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -92,8 +92,8 @@ def bars_setup(num_bars: int = 3) -> Dict[str, Any]:
|
|||||||
|
|
||||||
scripts.extend(
|
scripts.extend(
|
||||||
[
|
[
|
||||||
{"script.execute": "update_bar3_left"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 3, Side.LEFT)},
|
||||||
{"script.execute": "update_bar3_right"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 3, Side.RIGHT)},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -105,8 +105,8 @@ def bars_setup(num_bars: int = 3) -> Dict[str, Any]:
|
|||||||
|
|
||||||
scripts.extend(
|
scripts.extend(
|
||||||
[
|
[
|
||||||
{"script.execute": "update_bar4_left"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 4, Side.LEFT)},
|
||||||
{"script.execute": "update_bar4_right"},
|
{"script.execute": bar_id(IdSuffix.SCRIPT_UPDATE, 4, Side.RIGHT)},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ def _bar_button_entry(bar_nr: int, base_id: str) -> List[Dict[str, Any]]:
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"platform": "gpio",
|
"platform": "gpio",
|
||||||
"id": f"bar{bar_nr}_btn_left",
|
"id": bar_id(IdSuffix.BUTTON, bar_nr, Side.LEFT),
|
||||||
"name": f"BAR {bar_nr} button Left",
|
"name": f"BAR {bar_nr} button Left",
|
||||||
"internal": True,
|
"internal": True,
|
||||||
"pin": {
|
"pin": {
|
||||||
@@ -158,7 +158,7 @@ def _bar_button_entry(bar_nr: int, base_id: str) -> List[Dict[str, Any]]:
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "gpio",
|
"platform": "gpio",
|
||||||
"id": f"bar{bar_nr}_btn_right",
|
"id": bar_id(IdSuffix.BUTTON, bar_nr, Side.RIGHT),
|
||||||
"name": f"BAR {bar_nr} button Right",
|
"name": f"BAR {bar_nr} button Right",
|
||||||
"internal": True,
|
"internal": True,
|
||||||
"pin": {
|
"pin": {
|
||||||
@@ -202,28 +202,28 @@ def _bar_lights_entry(bar_nr: int, offset: int, add_effects: bool) -> List[Dict[
|
|||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": f"BAR {bar_nr} Left RGB Front",
|
"name": f"BAR {bar_nr} Left RGB Front",
|
||||||
"id": f"bar{bar_nr}_left_rgb_front",
|
"id": bar_id(IdSuffix.LED, bar_nr, Side.LEFT, Direction.FRONT),
|
||||||
"segments": [{"id": "neopixels", "from": offset + 0, "to": offset + 0}],
|
"segments": [{"id": "neopixels", "from": offset + 0, "to": offset + 0}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": f"BAR {bar_nr} Left RGB Back",
|
"name": f"BAR {bar_nr} Left RGB Back",
|
||||||
"id": f"bar{bar_nr}_left_rgb_back",
|
"id": bar_id(IdSuffix.LED, bar_nr, Side.LEFT, Direction.BACK),
|
||||||
"segments": [{"id": "neopixels", "from": offset + 1, "to": offset + 1}],
|
"segments": [{"id": "neopixels", "from": offset + 1, "to": offset + 1}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": f"BAR {bar_nr} Right RGB Front",
|
"name": f"BAR {bar_nr} Right RGB Front",
|
||||||
"id": f"bar{bar_nr}_right_rgb_front",
|
"id": bar_id(IdSuffix.LED, bar_nr, Side.RIGHT, Direction.FRONT),
|
||||||
"segments": [{"id": "neopixels", "from": offset + 2, "to": offset + 2}],
|
"segments": [{"id": "neopixels", "from": offset + 2, "to": offset + 2}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": f"BAR {bar_nr} Right RGB Back",
|
"name": f"BAR {bar_nr} Right RGB Back",
|
||||||
"id": f"bar{bar_nr}_right_rgb_back",
|
"id": bar_id(IdSuffix.LED, bar_nr, Side.RIGHT, Direction.BACK),
|
||||||
"segments": [{"id": "neopixels", "from": offset + 3, "to": offset + 3}],
|
"segments": [{"id": "neopixels", "from": offset + 3, "to": offset + 3}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
@@ -261,7 +261,7 @@ def _bar_display_output_entry(bar_nr: int, base_id: str) -> List[Dict[str, Any]]
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"platform": "gpio",
|
"platform": "gpio",
|
||||||
"id": f"cs_pin_bar{bar_nr}_left",
|
"id": bar_id(IdSuffix.CS_PIN, bar_nr, Side.LEFT),
|
||||||
"pin": {
|
"pin": {
|
||||||
"mcp23xxx": base_id,
|
"mcp23xxx": base_id,
|
||||||
"number": 5,
|
"number": 5,
|
||||||
@@ -271,7 +271,7 @@ def _bar_display_output_entry(bar_nr: int, base_id: str) -> List[Dict[str, Any]]
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "gpio",
|
"platform": "gpio",
|
||||||
"id": f"cs_pin_bar{bar_nr}_right",
|
"id": bar_id(IdSuffix.CS_PIN, bar_nr, Side.RIGHT),
|
||||||
"pin": {
|
"pin": {
|
||||||
"mcp23xxx": base_id,
|
"mcp23xxx": base_id,
|
||||||
"number": 1,
|
"number": 1,
|
||||||
@@ -310,32 +310,32 @@ def bars_scripts(num_bars: int) -> Dict[str, Any]:
|
|||||||
setup_cpp = ""
|
setup_cpp = ""
|
||||||
|
|
||||||
if num_bars > 0:
|
if num_bars > 0:
|
||||||
bar_dict["script"].append(_bars_script_update_entry(1, BarSide.LEFT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(1, Side.LEFT, num_bars))
|
||||||
bar_dict["script"].append(_bars_script_update_entry(1, BarSide.RIGHT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(1, Side.RIGHT, num_bars))
|
||||||
|
|
||||||
setup_cpp += _bars_script_setup_entry(1, BarSide.LEFT)
|
setup_cpp += _bars_script_setup_entry(1, Side.LEFT)
|
||||||
setup_cpp += _bars_script_setup_entry(1, BarSide.RIGHT)
|
setup_cpp += _bars_script_setup_entry(1, Side.RIGHT)
|
||||||
|
|
||||||
if num_bars > 1:
|
if num_bars > 1:
|
||||||
bar_dict["script"].append(_bars_script_update_entry(2, BarSide.LEFT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(2, Side.LEFT, num_bars))
|
||||||
bar_dict["script"].append(_bars_script_update_entry(2, BarSide.RIGHT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(2, Side.RIGHT, num_bars))
|
||||||
|
|
||||||
setup_cpp += _bars_script_setup_entry(2, BarSide.LEFT)
|
setup_cpp += _bars_script_setup_entry(2, Side.LEFT)
|
||||||
setup_cpp += _bars_script_setup_entry(2, BarSide.RIGHT)
|
setup_cpp += _bars_script_setup_entry(2, Side.RIGHT)
|
||||||
|
|
||||||
if num_bars > 2:
|
if num_bars > 2:
|
||||||
bar_dict["script"].append(_bars_script_update_entry(3, BarSide.LEFT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(3, Side.LEFT, num_bars))
|
||||||
bar_dict["script"].append(_bars_script_update_entry(3, BarSide.RIGHT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(3, Side.RIGHT, num_bars))
|
||||||
|
|
||||||
setup_cpp += _bars_script_setup_entry(3, BarSide.LEFT)
|
setup_cpp += _bars_script_setup_entry(3, Side.LEFT)
|
||||||
setup_cpp += _bars_script_setup_entry(3, BarSide.RIGHT)
|
setup_cpp += _bars_script_setup_entry(3, Side.RIGHT)
|
||||||
|
|
||||||
if num_bars > 3:
|
if num_bars > 3:
|
||||||
bar_dict["script"].append(_bars_script_update_entry(4, BarSide.LEFT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(4, Side.LEFT, num_bars))
|
||||||
bar_dict["script"].append(_bars_script_update_entry(4, BarSide.RIGHT, num_bars))
|
bar_dict["script"].append(_bars_script_update_entry(4, Side.RIGHT, num_bars))
|
||||||
|
|
||||||
setup_cpp += _bars_script_setup_entry(4, BarSide.LEFT)
|
setup_cpp += _bars_script_setup_entry(4, Side.LEFT)
|
||||||
setup_cpp += _bars_script_setup_entry(4, BarSide.RIGHT)
|
setup_cpp += _bars_script_setup_entry(4, Side.RIGHT)
|
||||||
|
|
||||||
bar_dict["script"].append(
|
bar_dict["script"].append(
|
||||||
{"id": "setup_bar_displays", "then": [{"lambda": setup_cpp}]}
|
{"id": "setup_bar_displays", "then": [{"lambda": setup_cpp}]}
|
||||||
@@ -345,19 +345,19 @@ def bars_scripts(num_bars: int) -> Dict[str, Any]:
|
|||||||
|
|
||||||
|
|
||||||
def _bars_script_update_entry(
|
def _bars_script_update_entry(
|
||||||
bar_nr: int, bar_side: BarSide, num_bars: int
|
bar_nr: int, bar_side: Side, num_bars: int
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
|
|
||||||
# Generate all possible bars
|
# Generate all possible bars
|
||||||
bars_ids = [
|
bars_ids = [
|
||||||
f"cs_pin_bar{nr}_{side}"
|
bar_id(IdSuffix.CS_PIN, nr, side)
|
||||||
for nr in range(1, num_bars + 1)
|
for nr in range(1, num_bars + 1)
|
||||||
for side in [BarSide.LEFT, BarSide.RIGHT]
|
for side in [Side.LEFT, Side.RIGHT]
|
||||||
]
|
]
|
||||||
bars_state = [
|
bars_state = [
|
||||||
"on" if (nr is bar_nr and side is bar_side) else "off"
|
"on" if (nr is bar_nr and side is bar_side) else "off"
|
||||||
for nr in range(1, num_bars + 1)
|
for nr in range(1, num_bars + 1)
|
||||||
for side in [BarSide.LEFT, BarSide.RIGHT]
|
for side in [Side.LEFT, Side.RIGHT]
|
||||||
]
|
]
|
||||||
|
|
||||||
generated_cpp = ""
|
generated_cpp = ""
|
||||||
@@ -366,26 +366,32 @@ def _bars_script_update_entry(
|
|||||||
for bar, state in zip(bars_ids, bars_state):
|
for bar, state in zip(bars_ids, bars_state):
|
||||||
generated_cpp += f"id({bar}).turn_{state}();\n"
|
generated_cpp += f"id({bar}).turn_{state}();\n"
|
||||||
|
|
||||||
rotation = "90" if bar_side is BarSide.RIGHT else "270"
|
rotation = "90" if bar_side is Side.RIGHT else "270"
|
||||||
|
|
||||||
|
draw_script_id = bar_id(IdSuffix.SCRIPT_DRAW, bar_nr, bar_side)
|
||||||
|
update_script_id = bar_id(IdSuffix.SCRIPT_UPDATE, bar_nr, bar_side)
|
||||||
|
cs_pin_id = bar_id(IdSuffix.CS_PIN, bar_nr, bar_side)
|
||||||
|
|
||||||
generated_cpp += (
|
generated_cpp += (
|
||||||
"id(bar_display).clear();\n"
|
"id(bar_display).clear();\n"
|
||||||
f"id(bar_display).set_rotation(display::DisplayRotation::DISPLAY_ROTATION_{rotation}_DEGREES);\n"
|
f"id(bar_display).set_rotation(display::DisplayRotation::DISPLAY_ROTATION_{rotation}_DEGREES);\n"
|
||||||
f"id(bar{bar_nr}_{bar_side}_draw).execute();\n"
|
f"id({draw_script_id}).execute();\n"
|
||||||
"id(bar_display).update();\n"
|
"id(bar_display).update();\n"
|
||||||
"delay(1);\n"
|
"delay(1);\n"
|
||||||
f"id(cs_pin_bar{bar_nr}_{bar_side}).turn_off();"
|
f"id({cs_pin_id}).turn_off();"
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"id": f"update_bar{bar_nr}_{bar_side}", "then": [{"lambda": generated_cpp}]}
|
return {"id": f"{update_script_id}", "then": [{"lambda": generated_cpp}]}
|
||||||
|
|
||||||
|
|
||||||
def _bars_script_setup_entry(bar_nr: int, bar_side: BarSide) -> str:
|
def _bars_script_setup_entry(bar_nr: int, bar_side: Side) -> str:
|
||||||
|
cs_pin_id = bar_id(IdSuffix.CS_PIN, bar_nr, bar_side)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
f"id(cs_pin_bar{bar_nr}_{bar_side}).turn_on();\n"
|
f"id({cs_pin_id}).turn_on();\n"
|
||||||
"id(bar_display).setup();\n"
|
"id(bar_display).setup();\n"
|
||||||
"delay(5);\n"
|
"delay(5);\n"
|
||||||
f"id(cs_pin_bar{bar_nr}_{bar_side}).turn_off();\n"
|
f"id({cs_pin_id}).turn_off();\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -398,32 +404,32 @@ def bars_draw_scripts(num_bars: int, page_names: List[str]) -> Dict[str, Any]:
|
|||||||
update_list = []
|
update_list = []
|
||||||
|
|
||||||
if num_bars > 0:
|
if num_bars > 0:
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(1, BarSide.LEFT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(1, Side.LEFT, page_names))
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(1, BarSide.RIGHT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(1, Side.RIGHT, page_names))
|
||||||
|
|
||||||
update_list.extend(_bars_script_execute_entry(1, BarSide.LEFT))
|
update_list.extend(_bars_script_execute_entry(1, Side.LEFT))
|
||||||
update_list.extend(_bars_script_execute_entry(1, BarSide.RIGHT))
|
update_list.extend(_bars_script_execute_entry(1, Side.RIGHT))
|
||||||
|
|
||||||
if num_bars > 1:
|
if num_bars > 1:
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(2, BarSide.LEFT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(2, Side.LEFT, page_names))
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(2, BarSide.RIGHT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(2, Side.RIGHT, page_names))
|
||||||
|
|
||||||
update_list.extend(_bars_script_execute_entry(2, BarSide.LEFT))
|
update_list.extend(_bars_script_execute_entry(2, Side.LEFT))
|
||||||
update_list.extend(_bars_script_execute_entry(2, BarSide.RIGHT))
|
update_list.extend(_bars_script_execute_entry(2, Side.RIGHT))
|
||||||
|
|
||||||
if num_bars > 2:
|
if num_bars > 2:
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(3, BarSide.LEFT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(3, Side.LEFT, page_names))
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(3, BarSide.RIGHT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(3, Side.RIGHT, page_names))
|
||||||
|
|
||||||
update_list.extend(_bars_script_execute_entry(3, BarSide.LEFT))
|
update_list.extend(_bars_script_execute_entry(3, Side.LEFT))
|
||||||
update_list.extend(_bars_script_execute_entry(3, BarSide.RIGHT))
|
update_list.extend(_bars_script_execute_entry(3, Side.RIGHT))
|
||||||
|
|
||||||
if num_bars > 3:
|
if num_bars > 3:
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(4, BarSide.LEFT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(4, Side.LEFT, page_names))
|
||||||
bar_dict["script"].append(_bars_script_draw_entry(4, BarSide.RIGHT, page_names))
|
bar_dict["script"].append(_bars_script_draw_entry(4, Side.RIGHT, page_names))
|
||||||
|
|
||||||
update_list.extend(_bars_script_execute_entry(3, BarSide.LEFT))
|
update_list.extend(_bars_script_execute_entry(3, Side.LEFT))
|
||||||
update_list.extend(_bars_script_execute_entry(3, BarSide.RIGHT))
|
update_list.extend(_bars_script_execute_entry(3, Side.RIGHT))
|
||||||
|
|
||||||
bar_dict["script"].append({"id": "update_bars", "then": update_list[:-1]})
|
bar_dict["script"].append({"id": "update_bars", "then": update_list[:-1]})
|
||||||
|
|
||||||
@@ -431,7 +437,7 @@ def bars_draw_scripts(num_bars: int, page_names: List[str]) -> Dict[str, Any]:
|
|||||||
|
|
||||||
|
|
||||||
def _bars_script_draw_entry(
|
def _bars_script_draw_entry(
|
||||||
bar_nr: int, bar_side: BarSide, page_names: List[str]
|
bar_nr: int, bar_side: Side, page_names: List[str]
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
|
|
||||||
generated_cpp = "switch (id(active_page_nr)){\n"
|
generated_cpp = "switch (id(active_page_nr)){\n"
|
||||||
@@ -447,13 +453,18 @@ def _bars_script_draw_entry(
|
|||||||
|
|
||||||
generated_cpp += "}\n"
|
generated_cpp += "}\n"
|
||||||
|
|
||||||
return {"id": f"bar{bar_nr}_{bar_side}_draw", "then": [{"lambda": generated_cpp}]}
|
draw_script_id = bar_id(IdSuffix.SCRIPT_DRAW, bar_nr, bar_side)
|
||||||
|
|
||||||
|
return {"id": f"{draw_script_id}", "then": [{"lambda": generated_cpp}]}
|
||||||
|
|
||||||
|
|
||||||
def _bars_script_execute_entry(bar_nr: int, bar_side: BarSide) -> List[Dict[str, str]]:
|
def _bars_script_execute_entry(bar_nr: int, bar_side: Side) -> List[Dict[str, str]]:
|
||||||
|
|
||||||
|
update_script_id = bar_id(IdSuffix.SCRIPT_UPDATE, bar_nr, bar_side)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"script.execute": f"update_bar{bar_nr}_{bar_side}",
|
"script.execute": f"{update_script_id}",
|
||||||
},
|
},
|
||||||
{"delay": "0.1s"},
|
{"delay": "0.1s"},
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import Dict, Any, List
|
from typing import Dict, Any, List
|
||||||
from buttonplus_generator.constants import *
|
from buttonplus_generator.constants import *
|
||||||
from buttonplus_generator.utils import get_display_id, get_display_address, get_light_effects
|
from buttonplus_generator.utils import display_id, get_display_mcp_id, get_display_mcp_address, get_light_effects
|
||||||
from buttonplus_generator.merger import deep_merge
|
from buttonplus_generator.merger import deep_merge
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ def display_backlight(num_bars: int) -> Dict[str, Any]:
|
|||||||
{
|
{
|
||||||
"platform": "ledc",
|
"platform": "ledc",
|
||||||
"pin": GPIO_BACKLIGHT_MAIN,
|
"pin": GPIO_BACKLIGHT_MAIN,
|
||||||
"id": "display_main_backlight_pwm",
|
"id": display_id(IdSuffix.BACKLIGHT_PWM),
|
||||||
"inverted": True,
|
"inverted": True,
|
||||||
"max_power": 1,
|
"max_power": 1,
|
||||||
"frequency": "500Hz",
|
"frequency": "500Hz",
|
||||||
@@ -31,16 +31,16 @@ def display_backlight(num_bars: int) -> Dict[str, Any]:
|
|||||||
"light": [
|
"light": [
|
||||||
{
|
{
|
||||||
"platform": "monochromatic",
|
"platform": "monochromatic",
|
||||||
"output": "display_main_backlight_pwm",
|
"output": display_id(IdSuffix.BACKLIGHT_PWM),
|
||||||
"gamma_correct": 2.2,
|
"gamma_correct": 2.2,
|
||||||
"name": "Main Display Backlight",
|
"name": "Main Display Backlight",
|
||||||
"id": "display_main_backlight",
|
"id": display_id(IdSuffix.BACKLIGHT),
|
||||||
"restore_mode": "ALWAYS_ON",
|
"restore_mode": "ALWAYS_ON",
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"display": [
|
"display": [
|
||||||
{
|
{
|
||||||
"id": "main_display",
|
"id": display_id(IdSuffix.DISPLAY),
|
||||||
"platform": "ili9xxx",
|
"platform": "ili9xxx",
|
||||||
"model": "ili9341",
|
"model": "ili9341",
|
||||||
"invert_colors": False,
|
"invert_colors": False,
|
||||||
@@ -48,7 +48,7 @@ def display_backlight(num_bars: int) -> Dict[str, Any]:
|
|||||||
"update_interval": "30s",
|
"update_interval": "30s",
|
||||||
"dc_pin": {"number": GPIO_SPI_REG, "allow_other_uses": True},
|
"dc_pin": {"number": GPIO_SPI_REG, "allow_other_uses": True},
|
||||||
"cs_pin": {
|
"cs_pin": {
|
||||||
"mcp23xxx": get_display_id(num_bars),
|
"mcp23xxx": get_display_mcp_id(num_bars),
|
||||||
"number": 5,
|
"number": 5,
|
||||||
"mode": {"output": True},
|
"mode": {"output": True},
|
||||||
"inverted": False,
|
"inverted": False,
|
||||||
@@ -56,7 +56,7 @@ def display_backlight(num_bars: int) -> Dict[str, Any]:
|
|||||||
"show_test_card": False,
|
"show_test_card": False,
|
||||||
"dimensions": {"height": 240, "width": 320},
|
"dimensions": {"height": 240, "width": 320},
|
||||||
"rotation": 180,
|
"rotation": 180,
|
||||||
"lambda": "id(main_draw).execute();"
|
"lambda": f"id({display_id(IdSuffix.SCRIPT_DRAW)}).execute();"
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -70,9 +70,9 @@ def display_setup(num_bars: int) -> Dict[str, Any]:
|
|||||||
return {
|
return {
|
||||||
"mcp23008": [
|
"mcp23008": [
|
||||||
{
|
{
|
||||||
"id": get_display_id(num_bars),
|
"id": get_display_mcp_id(num_bars),
|
||||||
"i2c_id": "buttons",
|
"i2c_id": "buttons",
|
||||||
"address": get_display_address(num_bars),
|
"address": get_display_mcp_address(num_bars),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -86,11 +86,11 @@ def display_buttons(num_bars: int) -> Dict[str, Any]:
|
|||||||
"binary_sensor": [
|
"binary_sensor": [
|
||||||
{
|
{
|
||||||
"platform": "gpio",
|
"platform": "gpio",
|
||||||
"id": "main_display_btn_left",
|
"id": display_id(IdSuffix.BUTTON, Side.LEFT),
|
||||||
"name": "Main Display button Left",
|
"name": "Main Display button Left",
|
||||||
"internal": True,
|
"internal": True,
|
||||||
"pin": {
|
"pin": {
|
||||||
"mcp23xxx": get_display_id(num_bars),
|
"mcp23xxx": get_display_mcp_id(num_bars),
|
||||||
"number": 6,
|
"number": 6,
|
||||||
"mode": "INPUT_PULLUP",
|
"mode": "INPUT_PULLUP",
|
||||||
"inverted": True,
|
"inverted": True,
|
||||||
@@ -98,11 +98,11 @@ def display_buttons(num_bars: int) -> Dict[str, Any]:
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "gpio",
|
"platform": "gpio",
|
||||||
"id": "main_display_btn_right",
|
"id": display_id(IdSuffix.BUTTON, Side.RIGHT),
|
||||||
"name": "Main Display button Right",
|
"name": "Main Display button Right",
|
||||||
"internal": True,
|
"internal": True,
|
||||||
"pin": {
|
"pin": {
|
||||||
"mcp23xxx": get_display_id(num_bars),
|
"mcp23xxx": get_display_mcp_id(num_bars),
|
||||||
"number": 2,
|
"number": 2,
|
||||||
"mode": "INPUT_PULLUP",
|
"mode": "INPUT_PULLUP",
|
||||||
"inverted": True,
|
"inverted": True,
|
||||||
@@ -126,28 +126,28 @@ def display_lights(num_bars: int, display_has_leds: bool, add_effects: bool) ->
|
|||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": "Main Display Left RGB Front",
|
"name": "Main Display Left RGB Front",
|
||||||
"id": "main_display_left_rgb_front",
|
"id": display_id(IdSuffix.LED, Side.LEFT, Direction.FRONT),
|
||||||
"segments": [{"id": "neopixels", "from": 0, "to": 0}],
|
"segments": [{"id": "neopixels", "from": 0, "to": 0}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": "Main Display Left RGB Back",
|
"name": "Main Display Left RGB Back",
|
||||||
"id": "main_display_left_rgb_back",
|
"id": display_id(IdSuffix.LED, Side.LEFT, Direction.BACK),
|
||||||
"segments": [{"id": "neopixels", "from": 1, "to": 1}],
|
"segments": [{"id": "neopixels", "from": 1, "to": 1}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": "Main Display Right RGB Front",
|
"name": "Main Display Right RGB Front",
|
||||||
"id": "main_display_right_rgb_front",
|
"id": display_id(IdSuffix.LED, Side.RIGHT, Direction.FRONT),
|
||||||
"segments": [{"id": "neopixels", "from": 2, "to": 2}],
|
"segments": [{"id": "neopixels", "from": 2, "to": 2}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"platform": "partition",
|
"platform": "partition",
|
||||||
"name": "Main Display Right RGB Back",
|
"name": "Main Display Right RGB Back",
|
||||||
"id": "main_display_right_rgb_back",
|
"id": display_id(IdSuffix.LED, Side.RIGHT, Direction.BACK),
|
||||||
"segments": [{"id": "neopixels", "from": 3, "to": 3}],
|
"segments": [{"id": "neopixels", "from": 3, "to": 3}],
|
||||||
"effects": light_effects
|
"effects": light_effects
|
||||||
},
|
},
|
||||||
@@ -159,10 +159,10 @@ def update_scripts(page_names: List[str]) -> Dict[str, Any]:
|
|||||||
|
|
||||||
display_dict["script"].append(
|
display_dict["script"].append(
|
||||||
{
|
{
|
||||||
"id": "update_main",
|
"id": display_id(IdSuffix.SCRIPT_UPDATE),
|
||||||
"then": [
|
"then": [
|
||||||
{
|
{
|
||||||
"component.update": "main_display",
|
"component.update": display_id(IdSuffix.DISPLAY),
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -170,12 +170,12 @@ def update_scripts(page_names: List[str]) -> Dict[str, Any]:
|
|||||||
|
|
||||||
generated_cpp = (
|
generated_cpp = (
|
||||||
"// All pages\n"
|
"// All pages\n"
|
||||||
"id(main_display).image(0, 235, id(icon_prev_page), ImageAlign::BOTTOM_LEFT, id(grey));\n"
|
f"id({display_id(IdSuffix.DISPLAY)}).image(0, 235, id(icon_prev_page), ImageAlign::BOTTOM_LEFT, id(grey));\n"
|
||||||
"id(main_display).image(320, 235, id(icon_next_page), ImageAlign::BOTTOM_RIGHT, id(grey));\n"
|
f"id({display_id(IdSuffix.DISPLAY)}).image(320, 235, id(icon_next_page), ImageAlign::BOTTOM_RIGHT, id(grey));\n"
|
||||||
"id(main_display).print(160, 235, id(font_arial20), id(white), TextAlign::BOTTOM_CENTER, id(active_page_name).c_str());\n"
|
f"id({display_id(IdSuffix.DISPLAY)}).print(160, 235, id(font_arial20), id(white), TextAlign::BOTTOM_CENTER, id(active_page_name).c_str());\n"
|
||||||
"\n"
|
"\n"
|
||||||
"id(main_display).strftime(160, 5, id(font_arial20), TextAlign::TOP_CENTER, \"%H:%M\", id(datetime).now());\n"
|
f"id({display_id(IdSuffix.DISPLAY)}).strftime(160, 5, id(font_arial20), TextAlign::TOP_CENTER, \"%H:%M\", id(datetime).now());\n"
|
||||||
"id(main_display).strftime(160, 80, id(font_arial20), TextAlign::TOP_CENTER, \"%d-%m-%Y\", id(datetime).now());\n"
|
f"id({display_id(IdSuffix.DISPLAY)}).strftime(160, 80, id(font_arial20), TextAlign::TOP_CENTER, \"%d-%m-%Y\", id(datetime).now());\n"
|
||||||
"\n"
|
"\n"
|
||||||
"switch (id(active_page_nr)){\n"
|
"switch (id(active_page_nr)){\n"
|
||||||
)
|
)
|
||||||
@@ -191,7 +191,7 @@ def update_scripts(page_names: List[str]) -> Dict[str, Any]:
|
|||||||
|
|
||||||
display_dict["script"].append(
|
display_dict["script"].append(
|
||||||
{
|
{
|
||||||
"id": "main_draw",
|
"id": display_id(IdSuffix.SCRIPT_DRAW),
|
||||||
"then": [
|
"then": [
|
||||||
{"lambda": generated_cpp}
|
{"lambda": generated_cpp}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from typing import Any, Dict, List
|
|||||||
|
|
||||||
from buttonplus_generator.constants import *
|
from buttonplus_generator.constants import *
|
||||||
from buttonplus_generator.merger import deep_merge
|
from buttonplus_generator.merger import deep_merge
|
||||||
from buttonplus_generator.utils import click_type_color, click_type_timing
|
from buttonplus_generator.utils import bar_id, click_type_color, click_type_timing, display_id
|
||||||
|
|
||||||
|
|
||||||
def config_events(
|
def config_events(
|
||||||
@@ -38,33 +38,33 @@ def events(
|
|||||||
event_dict["event"] = []
|
event_dict["event"] = []
|
||||||
|
|
||||||
if num_bars < 4:
|
if num_bars < 4:
|
||||||
event_dict["event"].extend(_event_display_entry(BarSide.LEFT))
|
event_dict["event"].extend(_event_display_entry(Side.LEFT))
|
||||||
event_dict["event"].extend(_event_display_entry(BarSide.RIGHT))
|
event_dict["event"].extend(_event_display_entry(Side.RIGHT))
|
||||||
|
|
||||||
if num_bars > 0:
|
if num_bars > 0:
|
||||||
event_dict["event"].extend(_event_bar_entry(1, BarSide.LEFT))
|
event_dict["event"].extend(_event_bar_entry(1, Side.LEFT))
|
||||||
event_dict["event"].extend(_event_bar_entry(1, BarSide.RIGHT))
|
event_dict["event"].extend(_event_bar_entry(1, Side.RIGHT))
|
||||||
|
|
||||||
if num_bars > 1:
|
if num_bars > 1:
|
||||||
event_dict["event"].extend(_event_bar_entry(2, BarSide.LEFT))
|
event_dict["event"].extend(_event_bar_entry(2, Side.LEFT))
|
||||||
event_dict["event"].extend(_event_bar_entry(2, BarSide.RIGHT))
|
event_dict["event"].extend(_event_bar_entry(2, Side.RIGHT))
|
||||||
|
|
||||||
if num_bars > 2:
|
if num_bars > 2:
|
||||||
event_dict["event"].extend(_event_bar_entry(3, BarSide.LEFT))
|
event_dict["event"].extend(_event_bar_entry(3, Side.LEFT))
|
||||||
event_dict["event"].extend(_event_bar_entry(3, BarSide.RIGHT))
|
event_dict["event"].extend(_event_bar_entry(3, Side.RIGHT))
|
||||||
|
|
||||||
if num_bars > 3:
|
if num_bars > 3:
|
||||||
event_dict["event"].extend(_event_bar_entry(4, BarSide.LEFT))
|
event_dict["event"].extend(_event_bar_entry(4, Side.LEFT))
|
||||||
event_dict["event"].extend(_event_bar_entry(4, BarSide.RIGHT))
|
event_dict["event"].extend(_event_bar_entry(4, Side.RIGHT))
|
||||||
|
|
||||||
return event_dict
|
return event_dict
|
||||||
|
|
||||||
|
|
||||||
def _event_display_entry(display_side: BarSide) -> List[Dict[str, Any]]:
|
def _event_display_entry(display_side: Side) -> List[Dict[str, Any]]:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"platform": "template",
|
"platform": "template",
|
||||||
"id": f"display_btn_{display_side}_event",
|
"id": display_id(IdSuffix.EVENT_BUTTON, display_side),
|
||||||
"name": f"DISPLAY Button {str(display_side).capitalize()}",
|
"name": f"DISPLAY Button {str(display_side).capitalize()}",
|
||||||
"device_class": "button",
|
"device_class": "button",
|
||||||
"event_types": r"${button_events}",
|
"event_types": r"${button_events}",
|
||||||
@@ -72,11 +72,11 @@ def _event_display_entry(display_side: BarSide) -> List[Dict[str, Any]]:
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _event_bar_entry(bar_nr: int, bar_side: BarSide) -> List[Dict[str, Any]]:
|
def _event_bar_entry(bar_nr: int, bar_side: Side) -> List[Dict[str, Any]]:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"platform": "template",
|
"platform": "template",
|
||||||
"id": f"bar{bar_nr}_btn_{bar_side}_event",
|
"id": bar_id(IdSuffix.EVENT_BUTTON, bar_nr, bar_side),
|
||||||
"name": f"BAR {bar_nr} Button {str(bar_side).capitalize()}",
|
"name": f"BAR {bar_nr} Button {str(bar_side).capitalize()}",
|
||||||
"device_class": "button",
|
"device_class": "button",
|
||||||
"event_types": r"${button_events}",
|
"event_types": r"${button_events}",
|
||||||
@@ -133,49 +133,49 @@ def events_timing(
|
|||||||
|
|
||||||
if num_bars < 4:
|
if num_bars < 4:
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_display_button_entry(version, BarSide.LEFT, click_types, click_confirm)
|
_display_button_entry(version, Side.LEFT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_display_button_entry(version, BarSide.RIGHT, click_types, click_confirm)
|
_display_button_entry(version, Side.RIGHT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
|
|
||||||
if num_bars > 0:
|
if num_bars > 0:
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(1, BarSide.LEFT, click_types, click_confirm)
|
_bar_button_entry(1, Side.LEFT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(1, BarSide.RIGHT, click_types, click_confirm)
|
_bar_button_entry(1, Side.RIGHT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
|
|
||||||
if num_bars > 1:
|
if num_bars > 1:
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(2, BarSide.LEFT, click_types, click_confirm)
|
_bar_button_entry(2, Side.LEFT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(2, BarSide.RIGHT, click_types, click_confirm)
|
_bar_button_entry(2, Side.RIGHT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
|
|
||||||
if num_bars > 2:
|
if num_bars > 2:
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(3, BarSide.LEFT, click_types, click_confirm)
|
_bar_button_entry(3, Side.LEFT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(3, BarSide.RIGHT, click_types, click_confirm)
|
_bar_button_entry(3, Side.RIGHT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
|
|
||||||
if num_bars > 3:
|
if num_bars > 3:
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(3, BarSide.LEFT, click_types, click_confirm)
|
_bar_button_entry(3, Side.LEFT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
event_dict["binary_sensor"].extend(
|
event_dict["binary_sensor"].extend(
|
||||||
_bar_button_entry(3, BarSide.RIGHT, click_types, click_confirm)
|
_bar_button_entry(3, Side.RIGHT, click_types, click_confirm)
|
||||||
)
|
)
|
||||||
|
|
||||||
return event_dict
|
return event_dict
|
||||||
|
|
||||||
|
|
||||||
def _bar_button_entry(
|
def _bar_button_entry(
|
||||||
bar_nr: int, bar_side: BarSide, click_types: List[ClickType], click_confirm: bool
|
bar_nr: int, bar_side: Side, click_types: List[ClickType], click_confirm: bool
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
multi_click_list = []
|
multi_click_list = []
|
||||||
|
|
||||||
@@ -184,8 +184,8 @@ def _bar_button_entry(
|
|||||||
for ct in click_types:
|
for ct in click_types:
|
||||||
multi_click_list.extend(
|
multi_click_list.extend(
|
||||||
_timing_entry(
|
_timing_entry(
|
||||||
event_id=f"bar{bar_nr}_btn_{bar_side}_event",
|
event_id=bar_id(IdSuffix.EVENT_BUTTON, bar_nr, bar_side),
|
||||||
led_id=f"bar{bar_nr}_{bar_side}_rgb_front",
|
led_id=bar_id(IdSuffix.LED, bar_nr, bar_side, Direction.FRONT),
|
||||||
event_type=ct,
|
event_type=ct,
|
||||||
timing=click_type_timing(ct),
|
timing=click_type_timing(ct),
|
||||||
color=click_type_color(ct),
|
color=click_type_color(ct),
|
||||||
@@ -194,7 +194,7 @@ def _bar_button_entry(
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"id": f"bar{bar_nr}_btn_{bar_side}",
|
"id": bar_id(IdSuffix.BUTTON, bar_nr, bar_side),
|
||||||
"filters": [{"delayed_off": "10ms"}],
|
"filters": [{"delayed_off": "10ms"}],
|
||||||
"on_multi_click": multi_click_list,
|
"on_multi_click": multi_click_list,
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ def _bar_button_entry(
|
|||||||
|
|
||||||
def _display_button_entry(
|
def _display_button_entry(
|
||||||
version: int,
|
version: int,
|
||||||
display_side: BarSide,
|
display_side: Side,
|
||||||
click_types: List[ClickType],
|
click_types: List[ClickType],
|
||||||
click_confirm: bool,
|
click_confirm: bool,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
@@ -211,13 +211,13 @@ def _display_button_entry(
|
|||||||
|
|
||||||
# TODO click_confirm implement
|
# TODO click_confirm implement
|
||||||
|
|
||||||
led_id = f"main_display_{display_side}_rgb_front"
|
led_id = display_id(IdSuffix.LED, display_side, Direction.FRONT)
|
||||||
|
|
||||||
if version == 1: # No leds
|
if version == 1: # No leds
|
||||||
led_id = YAMLLambda("return nullptr;")
|
led_id = YAMLLambda("return nullptr;")
|
||||||
|
|
||||||
# Add special page changer events
|
# Add special page changer events
|
||||||
script = "prev_page" if display_side == BarSide.LEFT else "next_page"
|
script = "prev_page" if display_side == Side.LEFT else "next_page"
|
||||||
multi_click_list.append(
|
multi_click_list.append(
|
||||||
{
|
{
|
||||||
"timing": click_type_timing(ClickType.SINGLE),
|
"timing": click_type_timing(ClickType.SINGLE),
|
||||||
@@ -232,7 +232,7 @@ def _display_button_entry(
|
|||||||
for ct in other_click_types:
|
for ct in other_click_types:
|
||||||
multi_click_list.extend(
|
multi_click_list.extend(
|
||||||
_timing_entry(
|
_timing_entry(
|
||||||
event_id=f"display_btn_{display_side}_event",
|
event_id=display_id(IdSuffix.EVENT_BUTTON, display_side),
|
||||||
led_id=led_id,
|
led_id=led_id,
|
||||||
event_type=ct,
|
event_type=ct,
|
||||||
timing=click_type_timing(ct),
|
timing=click_type_timing(ct),
|
||||||
@@ -242,7 +242,7 @@ def _display_button_entry(
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"id": f"main_display_btn_{display_side}",
|
"id": display_id(IdSuffix.BUTTON, display_side),
|
||||||
"filters": [{"delayed_off": "10ms"}],
|
"filters": [{"delayed_off": "10ms"}],
|
||||||
"on_multi_click": multi_click_list,
|
"on_multi_click": multi_click_list,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from typing import Dict, Any, List
|
from typing import Dict, Any, List
|
||||||
from buttonplus_generator.merger import deep_merge
|
from buttonplus_generator.merger import deep_merge
|
||||||
from buttonplus_generator.constants import *
|
from buttonplus_generator.constants import *
|
||||||
|
from buttonplus_generator.utils import bar_id, display_id
|
||||||
|
|
||||||
|
|
||||||
def config_services(version: int) -> Dict[str, Any]:
|
def config_services(version: int) -> Dict[str, Any]:
|
||||||
@@ -16,9 +17,9 @@ def toast_service() -> Dict[str, Any]:
|
|||||||
generated_cpp = (
|
generated_cpp = (
|
||||||
"if(id(internal_toast).size() > 0){\n"
|
"if(id(internal_toast).size() > 0){\n"
|
||||||
" // Draw white box over existing text\n"
|
" // Draw white box over existing text\n"
|
||||||
" id(main_display).filled_rectangle(0, 200, 320, 40, white);\n"
|
f" id({display_id(IdSuffix.DISPLAY)}).filled_rectangle(0, 200, 320, 40, white);\n"
|
||||||
" // Show toast message\n"
|
" // Show toast message\n"
|
||||||
" id(main_display).print(160, 235, id(font_arial20), id(black), TextAlign::BOTTOM_CENTER, id(internal_toast).c_str());\n"
|
f" id({display_id(IdSuffix.DISPLAY)}).print(160, 235, id(font_arial20), id(black), TextAlign::BOTTOM_CENTER, id(internal_toast).c_str());\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ def toast_service() -> Dict[str, Any]:
|
|||||||
"globals": [
|
"globals": [
|
||||||
{"id": "internal_toast", "type": "std::string", "initial_value": ""}
|
{"id": "internal_toast", "type": "std::string", "initial_value": ""}
|
||||||
],
|
],
|
||||||
"script": [{"id": "main_draw", "then": [{"lambda": generated_cpp}]}],
|
"script": [{"id": display_id(IdSuffix.SCRIPT_DRAW), "then": [{"lambda": generated_cpp}]}],
|
||||||
"api": {
|
"api": {
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
@@ -39,7 +40,7 @@ def toast_service() -> Dict[str, Any]:
|
|||||||
"value": YAMLLambda("return message;"),
|
"value": YAMLLambda("return message;"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"script.execute": "update_main"},
|
{"script.execute": display_id(IdSuffix.SCRIPT_UPDATE)},
|
||||||
{"delay": YAMLLambda("return timeout * 1000;")},
|
{"delay": YAMLLambda("return timeout * 1000;")},
|
||||||
{
|
{
|
||||||
"globals.set": {
|
"globals.set": {
|
||||||
@@ -47,7 +48,7 @@ def toast_service() -> Dict[str, Any]:
|
|||||||
"value": YAMLLambda("return std::string();"),
|
"value": YAMLLambda("return std::string();"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"script.execute": "update_main"},
|
{"script.execute": display_id(IdSuffix.SCRIPT_UPDATE)},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -59,30 +60,30 @@ def notification_service(version: int) -> Dict[str, Any]:
|
|||||||
generated_cpp = (
|
generated_cpp = (
|
||||||
"if(id(internal_notify).size() > 0){\n"
|
"if(id(internal_notify).size() > 0){\n"
|
||||||
" // Draw white box over existing text\n"
|
" // Draw white box over existing text\n"
|
||||||
" id(main_display).filled_rectangle(0, 200, 320, 40, white);\n"
|
f" id({display_id(IdSuffix.DISPLAY)}).filled_rectangle(0, 200, 320, 40, white);\n"
|
||||||
" id(main_display).rectangle(0, 200, 320, 40, accent);\n"
|
f" id({display_id(IdSuffix.DISPLAY)}).rectangle(0, 200, 320, 40, accent);\n"
|
||||||
" // Show notification message\n"
|
" // Show notification message\n"
|
||||||
" id(main_display).print(160, 235, id(font_arial20), id(black), TextAlign::BOTTOM_CENTER, id(internal_notify).c_str());\n"
|
f" id({display_id(IdSuffix.DISPLAY)}).print(160, 235, id(font_arial20), id(black), TextAlign::BOTTOM_CENTER, id(internal_notify).c_str());\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
notification_led_partition_left = 0
|
notification_led_partition_left = 0
|
||||||
notification_led_partition_right = 2
|
notification_led_partition_right = 2
|
||||||
notification_led_left = "main_display_left_rgb_front"
|
notification_led_left = display_id(IdSuffix.LED, Side.LEFT, Direction.FRONT)
|
||||||
notification_led_right = "main_display_right_rgb_front"
|
notification_led_right = display_id(IdSuffix.LED, Side.RIGHT, Direction.FRONT)
|
||||||
|
|
||||||
# No display leds, switch to BAR 1 wall leds
|
# No display leds, switch to BAR 1 wall leds
|
||||||
if version == 1:
|
if version == 1:
|
||||||
notification_led_partition_left = 1
|
notification_led_partition_left = 1
|
||||||
notification_led_partition_right = 3
|
notification_led_partition_right = 3
|
||||||
notification_led_left = "bar1_left_rgb_back"
|
notification_led_left = bar_id(IdSuffix.LED, 1, Side.LEFT, Direction.BACK)
|
||||||
notification_led_right = "bar1_right_rgb_back"
|
notification_led_right = bar_id(IdSuffix.LED, 1, Side.RIGHT, Direction.BACK)
|
||||||
|
|
||||||
service_dict = {
|
service_dict = {
|
||||||
"globals": [
|
"globals": [
|
||||||
{"id": "internal_notify", "type": "std::string", "initial_value": ""}
|
{"id": "internal_notify", "type": "std::string", "initial_value": ""}
|
||||||
],
|
],
|
||||||
"script": [{"id": "main_draw", "then": [{"lambda": generated_cpp}]}],
|
"script": [{"id": display_id(IdSuffix.SCRIPT_DRAW), "then": [{"lambda": generated_cpp}]}],
|
||||||
"api": {
|
"api": {
|
||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
@@ -95,7 +96,7 @@ def notification_service(version: int) -> Dict[str, Any]:
|
|||||||
"value": YAMLLambda("return message;"),
|
"value": YAMLLambda("return message;"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"script.execute": "update_main"},
|
{"script.execute": display_id(IdSuffix.SCRIPT_UPDATE)},
|
||||||
{
|
{
|
||||||
"while": {
|
"while": {
|
||||||
"condition": {
|
"condition": {
|
||||||
@@ -136,7 +137,7 @@ def notification_service(version: int) -> Dict[str, Any]:
|
|||||||
"value": YAMLLambda("return std::string();"),
|
"value": YAMLLambda("return std::string();"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{"script.execute": "update_main"},
|
{"script.execute": display_id(IdSuffix.SCRIPT_UPDATE)},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -175,7 +176,7 @@ def notification_service(version: int) -> Dict[str, Any]:
|
|||||||
"value": YAMLLambda("return std::string();"),
|
"value": YAMLLambda("return std::string();"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{"script.execute": "update_main"},
|
{"script.execute": display_id(IdSuffix.SCRIPT_UPDATE)},
|
||||||
{"script.stop": "next_page"},
|
{"script.stop": "next_page"},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import List, Dict, Any
|
from typing import List, Dict, Any, Optional
|
||||||
|
|
||||||
from buttonplus_generator.constants import *
|
from buttonplus_generator.constants import *
|
||||||
|
|
||||||
@@ -17,20 +17,51 @@ def slugify(input : str) -> str:
|
|||||||
s = s[1:]
|
s = s[1:]
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def display_id(suffix: IdSuffix, side: Optional[Side] = None, dir: Optional[Direction] = None) -> str:
|
||||||
|
if side is None and dir is None:
|
||||||
|
return f"display_{suffix}"
|
||||||
|
|
||||||
|
if side is None:
|
||||||
|
return f"display_{dir}_{suffix}"
|
||||||
|
|
||||||
|
if dir is None:
|
||||||
|
return f"display_{side}_{suffix}"
|
||||||
|
|
||||||
|
return f"display_{side}_{dir}_{suffix}"
|
||||||
|
|
||||||
|
def bar_id(suffix: IdSuffix, bar_nr: Optional[int], side: Optional[Side] = None, dir: Optional[Direction] = None) -> str:
|
||||||
|
bar_name = f"bars"
|
||||||
|
if bar_nr is not None:
|
||||||
|
bar_name = f"bar{bar_nr}"
|
||||||
|
|
||||||
|
if side is None and dir is None:
|
||||||
|
return f"{bar_name}_{suffix}"
|
||||||
|
|
||||||
|
if side is None:
|
||||||
|
return f"{bar_name}_{dir}_{suffix}"
|
||||||
|
|
||||||
|
if dir is None:
|
||||||
|
return f"{bar_name}_{side}_{suffix}"
|
||||||
|
|
||||||
|
return f"{bar_name}_{side}_{dir}_{suffix}"
|
||||||
|
|
||||||
def array_to_cpp_vector(string_array : List[str]) -> str:
|
def array_to_cpp_vector(string_array : List[str]) -> str:
|
||||||
return "{" + ', '.join(f'"{entry}"' for entry in string_array) + "}"
|
return "{" + ', '.join(f'"{entry}"' for entry in string_array) + "}"
|
||||||
|
|
||||||
def get_display_id(num_bars : int) -> str:
|
def array_to_cpp_vector_raw(string_array: List[str]) -> str:
|
||||||
|
return "{" + ', '.join(entry for entry in string_array) + "}"
|
||||||
|
|
||||||
|
def get_display_mcp_id(num_bars : int) -> str:
|
||||||
if(num_bars < 1 or num_bars > 3):
|
if(num_bars < 1 or num_bars > 3):
|
||||||
raise ValueError("Can't have a display with this number of bars")
|
raise ValueError("Can't have a display with this number of bars")
|
||||||
|
|
||||||
return "base_J" + str(3 - num_bars)
|
return "base_J" + str(3 - num_bars)
|
||||||
|
|
||||||
def get_display_address(num_bars : int) -> str:
|
def get_display_mcp_address(num_bars : int) -> str:
|
||||||
if(num_bars < 1 or num_bars > 3):
|
if(num_bars < 1 or num_bars > 3):
|
||||||
raise ValueError("Can't have a display with this number of bars")
|
raise ValueError("Can't have a display with this number of bars")
|
||||||
|
|
||||||
return 0x23 - num_bars
|
return f"{0x23 - num_bars}"
|
||||||
|
|
||||||
def get_light_effects(enabled: bool) -> List[Dict[str, Any]]:
|
def get_light_effects(enabled: bool) -> List[Dict[str, Any]]:
|
||||||
if not enabled:
|
if not enabled:
|
||||||
@@ -64,6 +95,8 @@ def string_to_click_type(ct:str) -> ClickType:
|
|||||||
return ClickType.TRIPLE
|
return ClickType.TRIPLE
|
||||||
elif ct == "hold":
|
elif ct == "hold":
|
||||||
return ClickType.HOLD
|
return ClickType.HOLD
|
||||||
|
|
||||||
|
return ClickType.SINGLE
|
||||||
|
|
||||||
def list_to_click_type(str_list:List[str]) -> List[ClickType]:
|
def list_to_click_type(str_list:List[str]) -> List[ClickType]:
|
||||||
ct_list: List[ClickType] = []
|
ct_list: List[ClickType] = []
|
||||||
@@ -97,4 +130,4 @@ def click_type_timing(ct: ClickType) -> List[str]:
|
|||||||
elif(ct is ClickType.HOLD):
|
elif(ct is ClickType.HOLD):
|
||||||
return TIMING_HOLD_CLICK
|
return TIMING_HOLD_CLICK
|
||||||
|
|
||||||
return TIMING_SINGLE_CLICK
|
return TIMING_SINGLE_CLICK
|
||||||
|
|||||||
Reference in New Issue
Block a user