mirror of
https://github.com/marcriera/ddgo-converter.git
synced 2025-04-19 18:39:29 +02:00
Implement subclasses for controllers
This commit is contained in:
parent
a5580bdbde
commit
ca6105a090
4 changed files with 43 additions and 21 deletions
|
@ -4,9 +4,15 @@ from hashlib import sha1
|
||||||
class EmulatedGamepad:
|
class EmulatedGamepad:
|
||||||
|
|
||||||
class GamepadType(Enum):
|
class GamepadType(Enum):
|
||||||
DGOC44U = 0
|
PC2HANDLE = 0
|
||||||
PS1 = 1
|
PS1 = 1
|
||||||
|
|
||||||
|
class PC2HandleGamepad(EmulatedGamepad):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
self.type = self.GamepadType.PC2HANDLE
|
||||||
self.type
|
|
||||||
|
def write_input(self):
|
||||||
|
print("Output to emulated DGOC-44U correct")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
|
import time
|
||||||
|
|
||||||
|
def create_gamepad(vid, pid, name):
|
||||||
|
match vid, pid:
|
||||||
|
case 0x0f0d, 0x00c1:
|
||||||
|
return SwitchGamepad(vid, pid, name)
|
||||||
|
return PhysicalGamepad(vid, pid, name)
|
||||||
|
|
||||||
class PhysicalGamepad:
|
class PhysicalGamepad:
|
||||||
|
|
||||||
class GamepadType(Enum):
|
class GamepadType(Enum):
|
||||||
UNKNOWN = 0
|
UNKNOWN = 0
|
||||||
CLASSIC = 1
|
CLASSIC = 1
|
||||||
NSWITCH = 2
|
SWITCH = 2
|
||||||
|
|
||||||
def __init__(self, vid, pid, name):
|
def __init__(self, vid, pid, name):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -15,7 +22,7 @@ class PhysicalGamepad:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.id = self._get_gamepad_id()
|
self.id = self._get_gamepad_id()
|
||||||
self.hash = self._get_gamepad_hash()
|
self.hash = self._get_gamepad_hash()
|
||||||
self.type = self.get_gamepad_type()
|
self.type = self.GamepadType.UNKNOWN
|
||||||
self.config = []
|
self.config = []
|
||||||
|
|
||||||
def _get_gamepad_id(self):
|
def _get_gamepad_id(self):
|
||||||
|
@ -28,8 +35,14 @@ class PhysicalGamepad:
|
||||||
hash = sha1(str(self.id + ":" + self.name).encode('utf-8')).hexdigest()
|
hash = sha1(str(self.id + ":" + self.name).encode('utf-8')).hexdigest()
|
||||||
return hash
|
return hash
|
||||||
|
|
||||||
def get_gamepad_type(self):
|
class SwitchGamepad(PhysicalGamepad):
|
||||||
match self.vid, self.pid:
|
|
||||||
case 0x0f0d, 0x00c1:
|
def __init__(self, * args):
|
||||||
return self.GamepadType.NSWITCH
|
super().__init__(* args)
|
||||||
return self.GamepadType.UNKNOWN
|
self.type = self.GamepadType.SWITCH
|
||||||
|
self.config = []
|
||||||
|
|
||||||
|
def read_input(self):
|
||||||
|
time.sleep(5)
|
||||||
|
print("Read from ZKNS-001 correct")
|
||||||
|
return 0
|
||||||
|
|
|
@ -2,7 +2,8 @@ import sys
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
from PyQt5.QtWidgets import QMainWindow, QTableWidgetItem, QHeaderView
|
from PyQt5.QtWidgets import QMainWindow, QTableWidgetItem, QHeaderView
|
||||||
from gui.main_ui import Ui_MainWindow
|
from gui.main_ui import Ui_MainWindow
|
||||||
from gamepads.physical import PhysicalGamepad
|
import gamepads.physical as gamepad_physical
|
||||||
|
import gamepads.emulated as gamepad_emulated
|
||||||
from models.gamepad import GamepadModel
|
from models.gamepad import GamepadModel
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
@ -22,7 +23,7 @@ class MainWindow(QMainWindow):
|
||||||
self._gui.tableView_physicalControllerList.selectRow(0)
|
self._gui.tableView_physicalControllerList.selectRow(0)
|
||||||
|
|
||||||
self._gui.pushButton_physicalControllerRefresh.clicked.connect(self.controller_list_refresh)
|
self._gui.pushButton_physicalControllerRefresh.clicked.connect(self.controller_list_refresh)
|
||||||
self._gui.pushButton_emulatedControllerStart.clicked.connect(self.start)
|
self._gui.pushButton_emulatedControllerStart.clicked.connect(self.controller_emulator_start)
|
||||||
|
|
||||||
def controller_list_refresh(self):
|
def controller_list_refresh(self):
|
||||||
self.gamepad_model.beginResetModel()
|
self.gamepad_model.beginResetModel()
|
||||||
|
@ -32,12 +33,14 @@ class MainWindow(QMainWindow):
|
||||||
def controller_list_selection_changed(self):
|
def controller_list_selection_changed(self):
|
||||||
enabled = False
|
enabled = False
|
||||||
rows = self._gui.tableView_physicalControllerList.selectionModel().selectedRows()
|
rows = self._gui.tableView_physicalControllerList.selectionModel().selectedRows()
|
||||||
if rows and self.gamepad_model.gamepads[rows[0].row()].type != PhysicalGamepad.GamepadType.UNKNOWN:
|
if rows and self.gamepad_model.gamepads[rows[0].row()].type != gamepad_physical.PhysicalGamepad.GamepadType.UNKNOWN:
|
||||||
enabled = True
|
enabled = True
|
||||||
self._gui.pushButton_emulatedControllerStart.setEnabled(enabled)
|
self._gui.pushButton_emulatedControllerStart.setEnabled(enabled)
|
||||||
|
|
||||||
def start(self):
|
def controller_emulator_start(self):
|
||||||
|
self._gui.pushButton_emulatedControllerStart.setEnabled(False)
|
||||||
rows = self._gui.tableView_physicalControllerList.selectionModel().selectedRows()
|
rows = self._gui.tableView_physicalControllerList.selectionModel().selectedRows()
|
||||||
if rows:
|
if rows:
|
||||||
gamepad = self.gamepad_model.gamepads[rows[0].row()]
|
gamepad = self.gamepad_model.gamepads[rows[0].row()]
|
||||||
print(gamepad.name)
|
emulated_gamepad = gamepad_emulated.PC2HandleGamepad()
|
||||||
|
self._gamepad_handler.start_gamepad_emulator(gamepad, emulated_gamepad)
|
|
@ -1,7 +1,7 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from evdev import InputDevice, list_devices, ecodes as e, UInput, AbsInfo
|
from evdev import InputDevice, list_devices, ecodes as e, UInput, AbsInfo
|
||||||
from gamepads.physical import PhysicalGamepad
|
import gamepads.physical as gamepad_physical
|
||||||
from gamepads.emulated import EmulatedGamepad
|
import gamepads.emulated as gamepad_emulated
|
||||||
|
|
||||||
class GamepadHandler:
|
class GamepadHandler:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -11,13 +11,13 @@ class GamepadHandler:
|
||||||
gamepads = []
|
gamepads = []
|
||||||
devices = [InputDevice(path) for path in list_devices()]
|
devices = [InputDevice(path) for path in list_devices()]
|
||||||
for device in devices:
|
for device in devices:
|
||||||
gamepads.append(PhysicalGamepad(device.info.vendor, device.info.product, device.name))
|
gamepads.append(gamepad_physical.create_gamepad(device.info.vendor, device.info.product, device.name))
|
||||||
return gamepads
|
return gamepads
|
||||||
|
|
||||||
def start_gamepad_emulator(gamepad, emulated_gamepad):
|
def start_gamepad_emulator(gamepad, emulated_gamepad):
|
||||||
realtype = gamepad.type
|
for i in range(2):
|
||||||
emutype = emulated_gamepad.type
|
gamepad.read_input()
|
||||||
print(str(realtype)+str(emutype))
|
emulated_gamepad.write_input()
|
||||||
|
|
||||||
|
|
||||||
""" cap = {
|
""" cap = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue