mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-11-12 16:03:50 +00:00
first api test
This commit is contained in:
parent
82e5259e4b
commit
cb26cc6b0a
31
API/main.py
31
API/main.py
@ -1,13 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
from deps.samplebase import SampleBase
|
||||
from rgbmatrix import graphics
|
||||
|
||||
from flask import Flask, jsonify
|
||||
import time
|
||||
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
class Text(SampleBase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(Text, self).__init__(*args, **kwargs)
|
||||
self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="Hello world!")
|
||||
self.text = ""
|
||||
|
||||
def run(self):
|
||||
offscreen_canvas = self.matrix.CreateFrameCanvas()
|
||||
@ -15,15 +28,17 @@ class Text(SampleBase):
|
||||
font.LoadFont("deps/fonts/9x18B.bdf")
|
||||
text_color = graphics.Color(255, 255, 255)
|
||||
|
||||
offscreen_canvas.Clear()
|
||||
graphics.DrawText(offscreen_canvas, font, 0, 18, text_color, self.args.text)
|
||||
self.matrix.SwapOnVSync(offscreen_canvas)
|
||||
|
||||
while True:
|
||||
offscreen_canvas.Clear()
|
||||
graphics.DrawText(offscreen_canvas, font, 0, 18, text_color, self.text)
|
||||
offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
|
||||
|
||||
time.sleep(0.05)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
text = Text()
|
||||
if not text.process():
|
||||
text.print_help()
|
||||
app.matrix = Text()
|
||||
app.run(debug=True)
|
||||
|
||||
if not app.matrix.process():
|
||||
app.matrix.print_help()
|
||||
|
Loading…
Reference in New Issue
Block a user