Commit 90ac8836 authored by Vladislav's avatar Vladislav

Added hotplug

parent 891da8b2
import subprocess import subprocess
import threading import threading
import time
from typing import Union from typing import Union
import pygame import pygame
from pygame.joystick import Joystick from pygame.joystick import Joystick
class Gamepad: class Gamepad:
LB_BUTTON = 4 LB_BUTTON = 4
RB_BUTTON = 5 RB_BUTTON = 5
...@@ -44,15 +44,28 @@ class Gamepad: ...@@ -44,15 +44,28 @@ class Gamepad:
pygame.joystick.init() pygame.joystick.init()
def run(self): def run(self):
joystick_count = pygame.joystick.get_count() def hotplug():
if joystick_count == 0: joystick_init = 0
print("No joysticks found.") while True:
else: joystick_count = pygame.joystick.get_count()
self.joystick = pygame.joystick.Joystick(0) if joystick_count == 0:
self.joystick.init() print("No joysticks found.")
joystick_init = 0
self.thread = threading.Thread(target=lambda t, _exec: t.cycle(), args=(self, exec)) pygame.event.wait()
self.thread.start() time.sleep(1)
else:
if joystick_init != 1:
self.joystick = pygame.joystick.Joystick(0)
self.joystick.init()
self.thread = threading.Thread(target=lambda t, _exec: t.cycle(), args=(self, exec))
self.thread.start()
joystick_init = 1
if joystick_init == 1:
time.sleep(5)
hotplug = threading.Thread(name='hotplug', target=hotplug)
hotplug.start()
def cycle(self): def cycle(self):
try: try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment