Implemented full-screen endpoint and contrast setting
This commit is contained in:
parent
fa16909572
commit
f90bfe5090
2 changed files with 26 additions and 3 deletions
|
@ -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:
|
||||
|
|
15
src/main.py
15
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")
|
||||
|
|
Loading…
Reference in a new issue