From 3879884da323daed5743602ec694cd5dfe8aed7d Mon Sep 17 00:00:00 2001 From: Dirk Hoffmann Date: Sun, 22 Dec 2024 10:22:50 +0100 Subject: [PATCH] Now supporting 4 USB devices --- GUI/Dialogs/Preferences/DeviceDatabase.swift | 8 ++++---- GUI/Dialogs/Preferences/DevicesPrefs.swift | 14 ++++---------- GUI/Peripherals/GamePad.swift | 4 ++-- GUI/Peripherals/GamePadManager.swift | 16 +++++++++------- GUI/XIB files/Configuration.xib | 18 +++++++++++++++--- GUI/XIB files/Preferences.xib | 8 +++++--- GUI/XIB files/en.lproj/MyDocument.xib | 16 ++++++++++++++-- 7 files changed, 53 insertions(+), 31 deletions(-) diff --git a/GUI/Dialogs/Preferences/DeviceDatabase.swift b/GUI/Dialogs/Preferences/DeviceDatabase.swift index c80028c52..d4655080b 100644 --- a/GUI/Dialogs/Preferences/DeviceDatabase.swift +++ b/GUI/Dialogs/Preferences/DeviceDatabase.swift @@ -175,10 +175,10 @@ class DeviceDatabase { ] // Add default values for the directional pad - result[.DPAD_UP]![0] = [0:[.PULL_UP], 1:[.RELEASE_Y]] - result[.DPAD_DOWN]![0] = [0:[.PULL_DOWN], 1:[.RELEASE_Y]] - result[.DPAD_RIGHT]![0] = [0:[.PULL_RIGHT], 1:[.RELEASE_X]] - result[.DPAD_LEFT]![0] = [0:[.PULL_LEFT], 1:[.RELEASE_X]] + result[.DPAD_UP]![0] = [0:[.RELEASE_Y], 1:[.PULL_UP]] + result[.DPAD_DOWN]![0] = [0:[.RELEASE_Y], 1:[.PULL_DOWN]] + result[.DPAD_RIGHT]![0] = [0:[.RELEASE_X,], 1:[.PULL_RIGHT]] + result[.DPAD_LEFT]![0] = [0:[.RELEASE_X,], 1:[.PULL_LEFT]] // Add default values for the hat switch result[.HATSWITCH]![0]![0] = [.RELEASE_XY] diff --git a/GUI/Dialogs/Preferences/DevicesPrefs.swift b/GUI/Dialogs/Preferences/DevicesPrefs.swift index aad4761bc..5ea733de8 100644 --- a/GUI/Dialogs/Preferences/DevicesPrefs.swift +++ b/GUI/Dialogs/Preferences/DevicesPrefs.swift @@ -9,13 +9,9 @@ extension PreferencesController { - var pad: GamePad? { - if devSelector.indexOfSelectedItem == 0 { - return parent.gamePadManager.gamePads[3] - } else { - return parent.gamePadManager.gamePads[4] - } - } + var pad: GamePad? { return gamePadManager.gamePads[devSelector.selectedTag()] } + var db: DeviceDatabase { return myAppDelegate.database } + var guid: GUID {return pad?.guid ?? GUID() } func property(_ key: String) -> String { return pad?.property(key: key) ?? "-" @@ -25,9 +21,6 @@ extension PreferencesController { return pad?.device?.usageDescription ?? property(kIOHIDPrimaryUsageKey) } - var db: DeviceDatabase { return myAppDelegate.database } - var guid: GUID {return pad?.guid ?? GUID() } - func refreshDevicesTab() { // Let us notify when the device is pulled @@ -82,6 +75,7 @@ extension PreferencesController { case .DPAD_DOWN: text = "DPad = Down" case .DPAD_RIGHT: text = "DPad = Right" case .DPAD_LEFT: text = "DPad = Left" + case .HATSWITCH: text = "h\(nr).\(value)" default: text = "" } diff --git a/GUI/Peripherals/GamePad.swift b/GUI/Peripherals/GamePad.swift index d62eea898..e38789315 100644 --- a/GUI/Peripherals/GamePad.swift +++ b/GUI/Peripherals/GamePad.swift @@ -268,10 +268,10 @@ class GamePad { func mapHatSwitch(value: IOHIDValue, element: IOHIDElement) -> Int? { - let min = IOHIDElementGetLogicalMin(element) - let max = IOHIDElementGetLogicalMax(element) let val = IOHIDValueGetIntegerValue(value) + let min = IOHIDElementGetLogicalMin(element) + // let max = IOHIDElementGetLogicalMax(element) // print("min = \(min) max = \(max) val = \(val)") switch (val - min) { diff --git a/GUI/Peripherals/GamePadManager.swift b/GUI/Peripherals/GamePadManager.swift index 283204d8a..da6c13b26 100644 --- a/GUI/Peripherals/GamePadManager.swift +++ b/GUI/Peripherals/GamePadManager.swift @@ -15,6 +15,8 @@ struct InputDevice { static let keyset2 = 2 static let joystick1 = 3 static let joystick2 = 4 + static let joystick3 = 5 + static let joystick4 = 6 } /* An object of this class holds and manages an array of GamePad objects. @@ -139,9 +141,9 @@ class GamePadManager { var nr = 0 while !isEmpty(slot: nr) { nr += 1 } - // We support up to 5 devices - if nr < 5 { return nr } - + // We support up to 7 devices + if nr < 7 { return nr } + warn("Maximum number of devices reached") return nil } @@ -247,9 +249,7 @@ class GamePadManager { func updateHidMapping() { - // Only GamePads 3 and 4 are HID devices - gamePads[3]?.updateMapping() - gamePads[4]?.updateMapping() + for (_, pad) in gamePads { pad.updateMapping() } } func listDevices() { @@ -269,7 +269,9 @@ class GamePadManager { InputDevice.keyset1, InputDevice.keyset2, InputDevice.joystick1, - InputDevice.joystick2 + InputDevice.joystick2, + InputDevice.joystick3, + InputDevice.joystick4 ] for s in slots { diff --git a/GUI/XIB files/Configuration.xib b/GUI/XIB files/Configuration.xib index 74c7a7d0c..8cc74b545 100644 --- a/GUI/XIB files/Configuration.xib +++ b/GUI/XIB files/Configuration.xib @@ -203,7 +203,7 @@ - + @@ -1597,10 +1597,16 @@ DQ - + - + + + + + + + @@ -1654,6 +1660,12 @@ DQ + + + + + + diff --git a/GUI/XIB files/Preferences.xib b/GUI/XIB files/Preferences.xib index 8634d94d9..7ed6f0a53 100644 --- a/GUI/XIB files/Preferences.xib +++ b/GUI/XIB files/Preferences.xib @@ -1109,13 +1109,15 @@ - + - - + + + + diff --git a/GUI/XIB files/en.lproj/MyDocument.xib b/GUI/XIB files/en.lproj/MyDocument.xib index e6ac0c65d..2f8265271 100644 --- a/GUI/XIB files/en.lproj/MyDocument.xib +++ b/GUI/XIB files/en.lproj/MyDocument.xib @@ -338,7 +338,7 @@ - + @@ -355,6 +355,12 @@ + + + + + + @@ -366,7 +372,7 @@ - + @@ -383,6 +389,12 @@ + + + + + +