Implemented custom contrast for flashes

This commit is contained in:
Maximilian Giller 2023-12-23 20:28:35 +01:00
parent f90bfe5090
commit 393b14374b
2 changed files with 16 additions and 7 deletions

View file

@ -20,6 +20,11 @@ class MatrixDisplay:
self.device.contrast(self.contrast) self.device.contrast(self.contrast)
def set_contrast(self, contrast: int): def set_contrast(self, contrast: int):
"""Set contrast for all actions.
Args:
contrast (int): [0, 255]
"""
self.contrast = contrast self.contrast = contrast
self.device.contrast(self.contrast) self.device.contrast(self.contrast)
@ -36,8 +41,12 @@ class MatrixDisplay:
virtual.set_position((offset, 0)) virtual.set_position((offset, 0))
time.sleep(self.text_speed) time.sleep(self.text_speed)
def flash(self, count=1): def flash(self, count=1, contrast=None):
self.device.contrast(self.contrast) if contrast:
self.device.contrast(contrast)
else:
self.device.contrast(self.contrast)
while count > 0: while count > 0:
with canvas(self.device) as draw: with canvas(self.device) as draw:
draw.rectangle((0, 0, 31, 7), outline="white", fill="white") draw.rectangle((0, 0, 31, 7), outline="white", fill="white")

View file

@ -1,8 +1,7 @@
import asyncio import asyncio
from typing import Optional from typing import Optional
import requests from fastapi import FastAPI
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from actions import dht22_sensor, display_time, log_temperature, matrix_display from actions import dht22_sensor, display_time, log_temperature, matrix_display
@ -85,9 +84,10 @@ async def history():
@app.post("/flash") @app.post("/flash")
async def flash(count: int = 1): async def flash(count: int = 1, contrast: Optional[int] = None):
await queue.add_action_to_queue(matrix_display.flash, count) await queue.add_action_to_queue(
matrix_display.flash, count=count, contrast=contrast
)
return {"message": "Display flashed"} return {"message": "Display flashed"}