From f90bfe50909b69ef2db15f0d9991e2fb01587d1e Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 23 Dec 2023 19:19:17 +0100 Subject: [PATCH] Implemented full-screen endpoint and contrast setting --- src/handler/matrix.py | 14 +++++++++++--- src/main.py | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/handler/matrix.py b/src/handler/matrix.py index dcef105..9d3de50 100644 --- a/src/handler/matrix.py +++ b/src/handler/matrix.py @@ -19,7 +19,12 @@ class MatrixDisplay: self.device.contrast(self.contrast) + def set_contrast(self, contrast: int): + self.contrast = contrast + self.device.contrast(self.contrast) + def show_text(self, text): + self.device.contrast(self.contrast) width = len(text) * 8 + 4 * 8 virtual = viewport(self.device, width + 4 * 8, height=8) with canvas(virtual) as draw: @@ -32,7 +37,7 @@ class MatrixDisplay: time.sleep(self.text_speed) def flash(self, count=1): - self.device.contrast(255) + self.device.contrast(self.contrast) while count > 0: with canvas(self.device) as draw: draw.rectangle((0, 0, 31, 7), outline="white", fill="white") @@ -43,15 +48,18 @@ class MatrixDisplay: time.sleep(0.1) count -= 1 - self.device.contrast(self.contrast) def turn_off(self): - self.device.contrast(0) with canvas(self.device) as draw: draw.rectangle((0, 0, 31, 7), outline="black", fill="black") + + def turn_full(self): self.device.contrast(self.contrast) + with canvas(self.device) as draw: + draw.rectangle((0, 0, 31, 7), outline="white", fill="white") def show_current_time(self): + self.device.contrast(self.contrast) hour = str(datetime.now().hour).rjust(2, "0") minute = str(datetime.now().minute).rjust(2, "0") with canvas(self.device) as draw: diff --git a/src/main.py b/src/main.py index 650926a..4b77ed6 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import asyncio +from typing import Optional import requests from fastapi import FastAPI, HTTPException @@ -39,6 +40,12 @@ async def start_time_loop(): return {"message": "Time loop started"} +@app.post("/full") +async def turn_full(): + await queue.set_idle_action(matrix_display.turn_full) + return {"message": "Full screen turned on"} + + @app.post("/off") async def turn_off(): await queue.set_idle_action(matrix_display.turn_off) @@ -84,6 +91,14 @@ async def flash(count: int = 1): return {"message": "Display flashed"} +@app.post("/contrast") +async def contrast(contrast: Optional[int] = None): + if contrast: + matrix_display.set_contrast(contrast) + + return {"contrast": matrix_display.contrast} + + @app.post("/message") async def display_message(body: dict): message_text = body.get("message")