diff --git a/src/actions.py b/src/actions.py index 5e88b28..f369f2e 100644 --- a/src/actions.py +++ b/src/actions.py @@ -40,5 +40,12 @@ async def display_time(): async def display_pattern(*args, **kwargs): - while True: - await matrix_display.pattern(*args, **kwargs) + old_contrast = matrix_display.contrast + if "contrast" in kwargs.keys(): + matrix_display.set_contrast(int(kwargs["contrast"])) + try: + while True: + await matrix_display.pattern(*args, **kwargs) + except: + if "contrast" in kwargs.keys(): + matrix_display.set_contrast(old_contrast) diff --git a/src/main.py b/src/main.py index 13dbfe5..d5a5367 100644 --- a/src/main.py +++ b/src/main.py @@ -101,8 +101,12 @@ async def flash(count: int = 1, contrast: Optional[int] = None): @app.post("/pattern") -async def flash(pattern: str = "01", step_ms: int = 500): - await queue.set_idle_action(display_pattern, pattern=pattern, step_ms=step_ms) +async def flash( + pattern: str = "01", step_ms: int = 500, contrast: Optional[int] = None +): + await queue.set_idle_action( + display_pattern, pattern=pattern, step_ms=step_ms, contrast=contrast + ) return {"message": "Activated pattern."}