aboutsummaryrefslogtreecommitdiff
path: root/turtetris_master/usb_input.py
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2017-07-20 11:10:22 +0200
committerKarel Kočí <karel.koci@nic.cz>2017-07-20 11:16:07 +0200
commitfcf67c83f4ea61330abf125dbe88910e46734c66 (patch)
tree0dda674631985b884da689d3ea35a6aa3d80370d /turtetris_master/usb_input.py
parent1784c9bc91ea5cc63a85887d813fe37906a8234d (diff)
downloadturris-tetris-fcf67c83f4ea61330abf125dbe88910e46734c66.tar.gz
turris-tetris-fcf67c83f4ea61330abf125dbe88910e46734c66.tar.bz2
turris-tetris-fcf67c83f4ea61330abf125dbe88910e46734c66.zip
Input trigger
Diffstat (limited to 'turtetris_master/usb_input.py')
-rw-r--r--turtetris_master/usb_input.py11
1 files changed, 10 insertions, 1 deletions
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