aboutsummaryrefslogtreecommitdiff
path: root/turtetris_master/usb_input.py
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2017-07-20 15:20:22 +0200
committerKarel Kočí <karel.koci@nic.cz>2017-07-20 15:30:27 +0200
commit400bc2403da1c26b7d67a9786db0c3f94fbc4b65 (patch)
tree4e2ea6c2d8c382d9f09405c76f5b26eeaab1477c /turtetris_master/usb_input.py
parentc9a90b594752c70dba8326e0783c8007e7bd66f4 (diff)
downloadturris-tetris-400bc2403da1c26b7d67a9786db0c3f94fbc4b65.tar.gz
turris-tetris-400bc2403da1c26b7d67a9786db0c3f94fbc4b65.tar.bz2
turris-tetris-400bc2403da1c26b7d67a9786db0c3f94fbc4b65.zip
Add key repeat
Diffstat (limited to 'turtetris_master/usb_input.py')
-rw-r--r--turtetris_master/usb_input.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/turtetris_master/usb_input.py b/turtetris_master/usb_input.py
index dc01489..c452f7f 100644
--- a/turtetris_master/usb_input.py
+++ b/turtetris_master/usb_input.py
@@ -46,7 +46,7 @@ class Gamepad:
self.state = {}
for key in ['left', 'right', 'up', 'down', 'select', 'start']:
- self.state[key] = False
+ self.state[key] = 0
def check(self):
"Check the input state"
@@ -62,7 +62,12 @@ class Gamepad:
}
changed = {}
for key in ['left', 'right', 'up', 'down', 'select', 'start']:
- changed[key] = new_state[key] and not self.state[key]
- # TODO repeat
- self.state = new_state
+ changed[key] = False
+ if new_state[key]:
+ if self.state[key] == 0 or self.state[key] > 14:
+ changed[key] = True
+ self.state[key] = 0
+ self.state[key] += 1
+ else:
+ self.state[key] = 0
return changed