mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-11-14 00:43: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
|
#!/usr/bin/env python
|
||||||
from deps.samplebase import SampleBase
|
from deps.samplebase import SampleBase
|
||||||
from rgbmatrix import graphics
|
from rgbmatrix import graphics
|
||||||
|
|
||||||
|
from flask import Flask, jsonify
|
||||||
import time
|
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):
|
class Text(SampleBase):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Text, self).__init__(*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):
|
def run(self):
|
||||||
offscreen_canvas = self.matrix.CreateFrameCanvas()
|
offscreen_canvas = self.matrix.CreateFrameCanvas()
|
||||||
@ -15,15 +28,17 @@ class Text(SampleBase):
|
|||||||
font.LoadFont("deps/fonts/9x18B.bdf")
|
font.LoadFont("deps/fonts/9x18B.bdf")
|
||||||
text_color = graphics.Color(255, 255, 255)
|
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:
|
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)
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
text = Text()
|
app.matrix = Text()
|
||||||
if not text.process():
|
app.run(debug=True)
|
||||||
text.print_help()
|
|
||||||
|
if not app.matrix.process():
|
||||||
|
app.matrix.print_help()
|
||||||
|
Loading…
Reference in New Issue
Block a user