From ba22224a22858eca7146e4ffd5dda019c326cc6f Mon Sep 17 00:00:00 2001 From: Lucas Magasweran Date: Sat, 13 Nov 2021 14:58:31 +0100 Subject: [PATCH 1/2] emulator: convert from Python 2 to 3 using 2to3 --- emulator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/emulator.py b/emulator.py index 6050ec4..7644735 100755 --- a/emulator.py +++ b/emulator.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @@ -69,7 +69,7 @@ def recv_data(self): Grab the next frame and put it on the matrix. """ data, addr = self.sock.recvfrom(self.packetsize) - matrix = map(ord, data.strip()) + matrix = list(map(ord, data.strip())) if len(matrix) == self.packetsize: self.matrix = matrix[:-4] From 2e566e6886bfb12a67c3b7f7133f7282aace670f Mon Sep 17 00:00:00 2001 From: Lucas Magasweran Date: Sat, 13 Nov 2021 20:57:53 +0100 Subject: [PATCH 2/2] emulator: drop CRC if present and fix the out of bounds issue --- emulator.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/emulator.py b/emulator.py index 7644735..7f5e43d 100755 --- a/emulator.py +++ b/emulator.py @@ -69,9 +69,8 @@ def recv_data(self): Grab the next frame and put it on the matrix. """ data, addr = self.sock.recvfrom(self.packetsize) - matrix = list(map(ord, data.strip())) - if len(matrix) == self.packetsize: - self.matrix = matrix[:-4] + self.matrix = list(data.strip())[:self.packetsize-4] + def update(self): """ @@ -81,8 +80,7 @@ def update(self): for x in range(self.width): for y in range(self.height): pixel = y * self.width * 3 + x * 3 - #TODO: sometimes the matrix is not as big as it should - if pixel < pixels: + if pixel < pixels - 2: pygame.draw.circle(self.screen, (self.matrix[pixel], self.matrix[pixel + 1], self.matrix[pixel + 2]), (x * self.dotsize + self.dotsize / 2, y * self.dotsize + self.dotsize / 2), self.dotsize / 2, 0)