This commit is contained in:
apirrone 2025-04-09 12:06:30 +02:00
parent 595cac4eaa
commit 0b86d8c5de

View file

@ -13,7 +13,11 @@ class Button:
if self.is_pressed and not value:
self.released = True
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.last_pressed_time = time.time()
else:
@ -23,7 +27,6 @@ class Button:
self.released = False
class Buttons:
def __init__(self):
self.A = Button()
@ -32,14 +35,19 @@ class Buttons:
self.Y = Button()
self.LB = 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.B.update(B)
self.X.update(X)
self.Y.update(Y)
self.LB.update(LB)
self.RB.update(RB)
self.dpad_up.update(dpad_up)
self.dpad_down.update(dpad_down)
if __name__ == "__main__":
from mini_bdx_runtime.xbox_controller import XBoxController
@ -56,11 +64,22 @@ if __name__ == "__main__":
Y_pressed,
LB_pressed,
RB_pressed,
_, _, _
_,
_,
up_down,
) = 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)