From cf5ee5d4b25204ffd4609916fcd73a72818a7939 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Sun, 12 May 2019 13:19:44 -0700 Subject: [PATCH] Resolves an OverflowError in matrix scans (board-breaking) --- kmk/matrix.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kmk/matrix.py b/kmk/matrix.py index e1be0d5..754cc7b 100644 --- a/kmk/matrix.py +++ b/kmk/matrix.py @@ -73,8 +73,19 @@ class MatrixScanner: opin.value(True) for iidx, ipin in enumerate(self.inputs): + # cast to int to avoid + # + # >>> xyz = bytearray(3) + # >>> xyz[2] = True + # Traceback (most recent call last): + # File "", line 1, in + # OverflowError: value would overflow a 1 byte buffer + # + # I haven't dived too far into what causes this, but it's + # almost certainly because bool types in Python aren't just + # aliases to int values, but are proper pseudo-types + new_val = int(ipin.value()) old_val = self.state[ba_idx] - new_val = ipin.value() if old_val != new_val: if self.translate_coords: @@ -97,6 +108,7 @@ class MatrixScanner: self.report[2] = new_val self.state[ba_idx] = new_val + any_changed = True break