From cb26cc6b0aa539d97e12bf31caccc59c6a08e712 Mon Sep 17 00:00:00 2001 From: waltem01 Date: Thu, 23 Nov 2023 08:15:02 +0100 Subject: [PATCH] first api test --- API/main.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) 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()