Skip to content

Commit

Permalink
Add helper functions to ev3dev.button class
Browse files Browse the repository at this point in the history
  • Loading branch information
ddemidov committed Oct 14, 2015
1 parent b57ba6a commit f535ed6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ev3dev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,24 @@ def update(self):
"""
self.frame_buffer[:] = self.img.tobytes("raw", "1;IR")

#---------------------------------------------------------------------------
# Add helper functions to the button class
#---------------------------------------------------------------------------
button.keys = {
'back' : button.back,
'left' : button.left,
'right' : button.right,
'up' : button.up,
'down' : button.down,
'enter' : button.enter
}

def button_key_pressed(k):
return button.keys[k].pressed

def button_any_pressed():
return any([key.pressed for key in button.keys.values()])

button.key_pressed = button_key_pressed
button.any_pressed = button_any_pressed

0 comments on commit f535ed6

Please sign in to comment.