mirror of
https://github.com/apirrone/Open_Duck_Mini_Runtime.git
synced 2025-09-01 10:44:00 +00:00
dpad
This commit is contained in:
parent
595cac4eaa
commit
0b86d8c5de
1 changed files with 25 additions and 6 deletions
|
@ -13,7 +13,11 @@ class Button:
|
||||||
if self.is_pressed and not value:
|
if self.is_pressed and not value:
|
||||||
self.released = True
|
self.released = True
|
||||||
self.is_pressed = value
|
self.is_pressed = value
|
||||||
if self.released and self.is_pressed and (time.time() - self.last_pressed_time > self.timeout):
|
if (
|
||||||
|
self.released
|
||||||
|
and self.is_pressed
|
||||||
|
and (time.time() - self.last_pressed_time > self.timeout)
|
||||||
|
):
|
||||||
self.triggered = True
|
self.triggered = True
|
||||||
self.last_pressed_time = time.time()
|
self.last_pressed_time = time.time()
|
||||||
else:
|
else:
|
||||||
|
@ -23,7 +27,6 @@ class Button:
|
||||||
self.released = False
|
self.released = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Buttons:
|
class Buttons:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.A = Button()
|
self.A = Button()
|
||||||
|
@ -32,14 +35,19 @@ class Buttons:
|
||||||
self.Y = Button()
|
self.Y = Button()
|
||||||
self.LB = Button()
|
self.LB = Button()
|
||||||
self.RB = Button()
|
self.RB = Button()
|
||||||
|
self.dpad_up = Button()
|
||||||
|
self.dpad_down = Button()
|
||||||
|
|
||||||
def update(self, A, B, X, Y, LB, RB):
|
def update(self, A, B, X, Y, LB, RB, dpad_up, dpad_down):
|
||||||
self.A.update(A)
|
self.A.update(A)
|
||||||
self.B.update(B)
|
self.B.update(B)
|
||||||
self.X.update(X)
|
self.X.update(X)
|
||||||
self.Y.update(Y)
|
self.Y.update(Y)
|
||||||
self.LB.update(LB)
|
self.LB.update(LB)
|
||||||
self.RB.update(RB)
|
self.RB.update(RB)
|
||||||
|
self.dpad_up.update(dpad_up)
|
||||||
|
self.dpad_down.update(dpad_down)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from mini_bdx_runtime.xbox_controller import XBoxController
|
from mini_bdx_runtime.xbox_controller import XBoxController
|
||||||
|
@ -56,11 +64,22 @@ if __name__ == "__main__":
|
||||||
Y_pressed,
|
Y_pressed,
|
||||||
LB_pressed,
|
LB_pressed,
|
||||||
RB_pressed,
|
RB_pressed,
|
||||||
_, _, _
|
_,
|
||||||
|
_,
|
||||||
|
up_down,
|
||||||
) = xbox_controller.get_last_command()
|
) = xbox_controller.get_last_command()
|
||||||
|
|
||||||
buttons.update(A_pressed, B_pressed, X_pressed, Y_pressed, LB_pressed, RB_pressed)
|
buttons.update(
|
||||||
|
A_pressed,
|
||||||
|
B_pressed,
|
||||||
|
X_pressed,
|
||||||
|
Y_pressed,
|
||||||
|
LB_pressed,
|
||||||
|
RB_pressed,
|
||||||
|
up_down == 1,
|
||||||
|
up_down == -1,
|
||||||
|
)
|
||||||
|
|
||||||
print(buttons.A.triggered, buttons.A.is_pressed)
|
print(buttons.dpad_up.triggered, buttons.dpad_up.is_pressed, buttons.dpad_down.triggered, buttons.dpad_down.is_pressed)
|
||||||
|
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
|
Loading…
Reference in a new issue