mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-12-25 11:31:46 +00:00
better naming and methods
This commit is contained in:
parent
e7e02b73b0
commit
36e6f95944
38
API/main.py
38
API/main.py
@ -2,48 +2,42 @@
|
|||||||
from deps.samplebase import SampleBase
|
from deps.samplebase import SampleBase
|
||||||
from rgbmatrix import graphics
|
from rgbmatrix import graphics
|
||||||
|
|
||||||
from flask import Flask, jsonify
|
from flask import Flask, request, jsonify
|
||||||
from waitress import serve
|
from waitress import serve
|
||||||
import time, threading
|
import time, threading
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
api = Flask(__name__)
|
||||||
display_text = ""
|
|
||||||
count = 0
|
|
||||||
|
|
||||||
@app.route('/api/test', methods=['GET'])
|
|
||||||
def get_data():
|
|
||||||
global display_text, count
|
|
||||||
count = count + 1
|
|
||||||
display_text = f"Test #{count}"
|
|
||||||
|
|
||||||
data = {"success": True, "count": count, "text": display_text}
|
|
||||||
return jsonify(data)
|
|
||||||
|
|
||||||
|
|
||||||
class Text(SampleBase):
|
|
||||||
|
class Matrix(SampleBase):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Text, self).__init__(*args, **kwargs)
|
super(Matrix, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.font = graphics.Font()
|
self.font = graphics.Font()
|
||||||
self.font.LoadFont("deps/fonts/9x18B.bdf")
|
self.font.LoadFont("deps/fonts/9x18B.bdf")
|
||||||
self.color = graphics.Color(255, 255, 255)
|
self.color = graphics.Color(255, 255, 255)
|
||||||
|
|
||||||
self.canvas = self.matrix.CreateFrameCanvas()
|
self.canvas = self.matrix.CreateFrameCanvas()
|
||||||
|
self.canvas.Clear()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
self.update()
|
|
||||||
time.sleep(.05)
|
time.sleep(.05)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.canvas.Clear()
|
|
||||||
graphics.DrawText(self.canvas, self.font, 0, 18, self.color, display_text)
|
|
||||||
self.canvas = self.matrix.SwapOnVSync(self.canvas)
|
self.canvas = self.matrix.SwapOnVSync(self.canvas)
|
||||||
|
self.canvas.Clear()
|
||||||
|
|
||||||
|
def text(self, x, y, t):
|
||||||
|
graphics.DrawText(self.canvas, self.font, x*9, (y+1)*18, self.color, t)
|
||||||
|
|
||||||
|
|
||||||
|
matrix = None
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
text = Text()
|
matrix = Matrix()
|
||||||
threading.Thread(target=lambda: serve(app, host="0.0.0.0", port=8080)).start()
|
threading.Thread(target=lambda: serve(api, host="0.0.0.0", port=8080)).start()
|
||||||
|
|
||||||
if not text.process():
|
if not matrix.process():
|
||||||
text.print_help()
|
matrix.print_help()
|
||||||
|
Loading…
Reference in New Issue
Block a user