diff --git a/API/main.py b/API/main.py index a73c560..ddc9c7f 100644 --- a/API/main.py +++ b/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()