Skip to content

Commit

Permalink
Fix for #66
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Dec 6, 2023
1 parent e3fe479 commit e2fda80
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
20 changes: 16 additions & 4 deletions joystick_diagrams/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import sys
import os
import logging
import os
import sys
import threading
from pathlib import Path
from PyQt5 import QtWidgets, QtGui, QtCore

from PyQt5 import QtCore, QtGui, QtWidgets

QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)

from joystick_diagrams import config
from joystick_diagrams.ui import ui
from joystick_diagrams.adaptors.dcs.dcs_world import DCSWorldParser
from joystick_diagrams.adaptors.joystick_gremlin.joystick_gremlin import JoystickGremlin
from joystick_diagrams.adaptors.star_citizen.star_citizen import StarCitizen
from joystick_diagrams.classes import export
from joystick_diagrams.classes.version import version
from joystick_diagrams.devices import device_manager
from joystick_diagrams.ui import ui

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -313,7 +320,12 @@ def get_log_level():
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()

x = threading.Thread(target=device_manager.run, daemon=True)
x.start()

app.exec()

# manager.ParserPluginManager()
except Exception as error: # pylint: disable=broad-except
_logger.exception(error)
51 changes: 51 additions & 0 deletions joystick_diagrams/devices/device_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import logging
from time import sleep
from typing import Any

from joystick_diagrams.devices import dill

_LOGGER = logging.getLogger(__name__)
_ACTIVE_DEViCES = {}

# Action mappings for device changes
DEVICE_ACTIONS = {1: "DEVICE_ADDED", 2: "DEVICE_REMOVED"}

_device_changes = []


# Cannot debug?
def _update_device_register(data: dill._DeviceSummary, action):
_LOGGER.info(f"Device was altered, added to device changes")
_device_changes.append([dill.DeviceSummary(data), action])


dill.DILL.set_device_change_callback(_update_device_register) # Figure out this callable


# CAN BE DEBUGGED
def process_device_changes():
if len(_device_changes) == 0:
return

for changes in _device_changes:
device, action = changes.pop(0)
_LOGGER.info(f"Device was changed: {device.__repr__}")
_LOGGER.info(f"Device was : {DEVICE_ACTIONS[action]}")


def run():
# Setup initial devices
while True:
_LOGGER.info(f"Devices {dill.DILL.get_device_count()}")
process_device_changes()
sleep(1)


if __name__ == "__main__":
lst = [1, 2, 3, 4, 5]

while len(lst) != 0:
i = lst.pop(0)
print(f"Popped {i}")

print("finished")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import copy
import ctypes
import ctypes.wintypes as ctwt
import logging
import os
import uuid
from enum import Enum
import os
import time
from typing import Callable
import logging

_logger = logging.getLogger(__name__)
_DILL_PATH = "./dill.dll"


class DILLError(Exception):
Expand Down Expand Up @@ -396,7 +396,7 @@ def set_vjoy_id(self, vjoy_id: int) -> None:
C_EVENT_CALLBACK = ctypes.CFUNCTYPE(None, _JoystickInputData)
C_DEVICE_CHANGE_CALLBACK = ctypes.CFUNCTYPE(None, _DeviceSummary, ctypes.c_uint8)

_dll_path = os.path.join(os.path.dirname(__file__), "includes\dill.dll")
_dll_path = os.path.join(os.path.dirname(__file__), _DILL_PATH)
_di_listener_dll = ctypes.cdll.LoadLibrary(_dll_path)

_di_listener_dll.get_device_information_by_index.argtypes = [ctypes.c_uint]
Expand All @@ -409,7 +409,7 @@ class DILL:

# Attempt to find the correct location of the dll for development
# and installed use cases.
_dev_path = os.path.join(os.path.dirname(__file__), "includes\dill.dll")
_dev_path = os.path.join(os.path.dirname(__file__), _DILL_PATH)
if os.path.isfile("dill.dll"):
_dll_path = "dill.dll"
elif os.path.isfile(_dev_path):
Expand Down Expand Up @@ -581,18 +581,6 @@ def initialize_capi() -> None:
dll_fn.restype = params["returns"]


def main():
# Initialize the class
DILL.initialize_capi()

dll = DILL()

dll.init()

devices = dll.get_device_count()
_logger.info(devices)

device = dll.get_device_information_by_index(1)
_logger.info(device)

return True
# Initialize the class
DILL.initialize_capi()
DILL.init()

0 comments on commit e2fda80

Please sign in to comment.