diff options
-rw-r--r-- | turtetris_master/game.py | 3 | ||||
-rw-r--r-- | turtetris_master/usb_input.py | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/turtetris_master/game.py b/turtetris_master/game.py index 1da176e..cae6ff4 100644 --- a/turtetris_master/game.py +++ b/turtetris_master/game.py @@ -103,6 +103,9 @@ class Game: for b in range(len(stone[a])): sx = 11 - a - x sy = 9 - b - y + print("sx:{0} sy:{1} mx:{2}:{3}".format( + sx, sy, len(self.mx), len(self.mx[0]) + )) if stone[a][b] != 0 and ( sx < 0 or sy < 0 or sx > 11 or sy > 9 or self.mx[sx][sy] != 0): diff --git a/turtetris_master/usb_input.py b/turtetris_master/usb_input.py index 0bb9d56..e19a98e 100644 --- a/turtetris_master/usb_input.py +++ b/turtetris_master/usb_input.py @@ -44,11 +44,15 @@ class Gamepad: ) assert self.ep is not None + self.state = {} + for key in ['left', 'right', 'up', 'down', 'select', 'start']: + self.state[key] = False + def check(self): "Check the input state" data = self.dev.read(self.ep.bEndpointAddress, self.ep.wMaxPacketSize*2, 1000).tolist() - return { + new_state = { "left": data[3] < 120 or bool(data[5] & 0x80), "right": data[3] > 140 or bool(data[5] & 0x20), "up": data[4] < 120 or bool(data[5] & 0x10), @@ -56,3 +60,8 @@ class Gamepad: "select": bool(data[6] & 0x10), "start": bool(data[6] & 0x20), } + changed = {} + for key in ['left', 'right', 'up', 'down', 'select', 'start']: + changed[key] = new_state[key] and not self.state[key] + self.state = new_state + return changed |