diff --git a/src/handler/matrix.py b/src/handler/matrix.py index 9d3de50..929111e 100644 --- a/src/handler/matrix.py +++ b/src/handler/matrix.py @@ -20,6 +20,11 @@ class MatrixDisplay: self.device.contrast(self.contrast) def set_contrast(self, contrast: int): + """Set contrast for all actions. + + Args: + contrast (int): [0, 255] + """ self.contrast = contrast self.device.contrast(self.contrast) @@ -36,8 +41,12 @@ class MatrixDisplay: virtual.set_position((offset, 0)) time.sleep(self.text_speed) - def flash(self, count=1): - self.device.contrast(self.contrast) + def flash(self, count=1, contrast=None): + if contrast: + self.device.contrast(contrast) + else: + self.device.contrast(self.contrast) + while count > 0: with canvas(self.device) as draw: draw.rectangle((0, 0, 31, 7), outline="white", fill="white") diff --git a/src/main.py b/src/main.py index 4b77ed6..9e4437e 100644 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,7 @@ import asyncio from typing import Optional -import requests -from fastapi import FastAPI, HTTPException +from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from actions import dht22_sensor, display_time, log_temperature, matrix_display @@ -85,9 +84,10 @@ async def history(): @app.post("/flash") -async def flash(count: int = 1): - await queue.add_action_to_queue(matrix_display.flash, count) - +async def flash(count: int = 1, contrast: Optional[int] = None): + await queue.add_action_to_queue( + matrix_display.flash, count=count, contrast=contrast + ) return {"message": "Display flashed"}