Matrix/API/main.py
2023-11-23 08:49:47 +01:00

50 lines
1.1 KiB
Python

#!/usr/bin/env python
from deps.samplebase import SampleBase
from rgbmatrix import graphics
from flask import Flask, jsonify
from waitress import serve
import time, threading
app = 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):
def __init__(self, *args, **kwargs):
super(Text, self).__init__(*args, **kwargs)
def run(self):
self.font = graphics.Font()
self.font.LoadFont("deps/fonts/9x18B.bdf")
self.color = graphics.Color(255, 255, 255)
self.canvas = self.matrix.CreateFrameCanvas()
while True:
self.update()
time.sleep(.05)
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)
if __name__ == "__main__":
text = Text()
threading.Thread(target=lambda: serve(app, host="0.0.0.0", port=8080)).start()
if not text.process():
text.print_help()