#!/usr/bin/env python from deps.samplebase import SampleBase from rgbmatrix import graphics from flask import Flask, request, jsonify from waitress import serve import time, threading api = Flask(__name__) class Matrix(SampleBase): def __init__(self, *args, **kwargs): super(Matrix, self).__init__(*args, **kwargs) def run(self): self.font = graphics.Font() self.font.LoadFont("deps/fonts/9x18B.bdf") self.color = graphics.Color(255, 255, 255) self.canvas = self.matrix.CreateFrameCanvas() self.canvas.Clear() while True: time.sleep(.05) def update(self): self.canvas = self.matrix.SwapOnVSync(self.canvas) self.canvas.Clear() def text(self, x, y, t): graphics.DrawText(self.canvas, self.font, x*9, (y+1)*18, self.color, t) matrix = None if __name__ == "__main__": matrix = Matrix() threading.Thread(target=lambda: serve(api, host="0.0.0.0", port=8080)).start() if not matrix.process(): matrix.print_help()