From 3bac768b06606573911331513cc8763ee855535c Mon Sep 17 00:00:00 2001 From: waltem01 Date: Thu, 23 Nov 2023 10:46:15 +0100 Subject: [PATCH] set pixel endpoint --- API/main.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/API/main.py b/API/main.py index 70ab195..eee855d 100644 --- a/API/main.py +++ b/API/main.py @@ -27,6 +27,23 @@ def display_text(): return jsonify(response) +@api.route('/pixel', methods=['POST']) +def set_pixel(): + response = { 'success': True } + try: + global matrix + + data = request.get_json() + x_coord = data.get('x') + y_coord = data.get('y') + + matrix.pixel(x_coord, y_coord) + except Exception as e: + print(e) + response['success'] = False + + return jsonify(response) + @api.route('/update', methods=['GET']) def update_matrix(): response = { 'success': True } @@ -63,6 +80,12 @@ class Matrix(SampleBase): self.canvas = self.matrix.SwapOnVSync(self.canvas) self.clear() + def set_color(self, r, g, b): + self.color = graphics.Color(r, g, b) + + def pixel(self, x, y): + self.canvas.SetPixel(x, y, self.color.red, self.color.green, self.color.blue) + def text(self, x, y, t): graphics.DrawText(self.canvas, self.font, x*9, (y+1)*18, self.color, t)