Matrix/API/main.py

45 lines
955 B
Python
Raw Normal View History

2023-11-22 15:21:15 +00:00
#!/usr/bin/env python
2023-11-22 15:44:26 +00:00
from deps.samplebase import SampleBase
2023-11-22 15:21:15 +00:00
from rgbmatrix import graphics
2023-11-23 07:15:02 +00:00
from flask import Flask, jsonify
2023-11-22 15:21:15 +00:00
import time
2023-11-22 14:41:13 +00:00
2023-11-23 07:15:02 +00:00
app = Flask(__name__)
count = 0
@app.route('/api/test', methods=['GET'])
def get_data():
app.matrix.text = f"Test #{++count}"
data = {"success": True}
return jsonify(data)
2023-11-23 06:38:21 +00:00
class Text(SampleBase):
2023-11-22 15:22:19 +00:00
def __init__(self, *args, **kwargs):
2023-11-23 06:38:21 +00:00
super(Text, self).__init__(*args, **kwargs)
2023-11-23 07:15:02 +00:00
self.text = ""
2023-11-22 14:41:13 +00:00
2023-11-22 15:22:19 +00:00
def run(self):
2023-11-22 15:21:15 +00:00
offscreen_canvas = self.matrix.CreateFrameCanvas()
font = graphics.Font()
2023-11-22 15:44:26 +00:00
font.LoadFont("deps/fonts/9x18B.bdf")
text_color = graphics.Color(255, 255, 255)
2023-11-22 14:41:13 +00:00
2023-11-22 15:21:15 +00:00
while True:
2023-11-23 07:15:02 +00:00
offscreen_canvas.Clear()
graphics.DrawText(offscreen_canvas, font, 0, 18, text_color, self.text)
offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
2023-11-22 15:21:15 +00:00
time.sleep(0.05)
2023-11-22 14:41:13 +00:00
2023-11-22 15:21:15 +00:00
if __name__ == "__main__":
2023-11-23 07:15:02 +00:00
app.matrix = Text()
app.run(debug=True)
if not app.matrix.process():
app.matrix.print_help()