Skip to content

Commit

Permalink
Now supporting 4 USB devices
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Dec 22, 2024
1 parent 7980f6a commit 3879884
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 31 deletions.
8 changes: 4 additions & 4 deletions GUI/Dialogs/Preferences/DeviceDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 4 additions & 10 deletions GUI/Dialogs/Preferences/DevicesPrefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? "-"
Expand All @@ -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
Expand Down Expand Up @@ -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 = ""
}

Expand Down
4 changes: 2 additions & 2 deletions GUI/Peripherals/GamePad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 9 additions & 7 deletions GUI/Peripherals/GamePadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand All @@ -269,7 +269,9 @@ class GamePadManager {
InputDevice.keyset1,
InputDevice.keyset2,
InputDevice.joystick1,
InputDevice.joystick2
InputDevice.joystick2,
InputDevice.joystick3,
InputDevice.joystick4
]

for s in slots {
Expand Down
18 changes: 15 additions & 3 deletions GUI/XIB files/Configuration.xib
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="646" height="496"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
<rect key="screenRect" x="0.0" y="0.0" width="1496" height="933"/>
<value key="minSize" type="size" width="646" height="486"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="646" height="496"/>
Expand Down Expand Up @@ -1597,10 +1597,16 @@ DQ
<menuItem title="Joystick Keyset 2" image="devKeys2Template" tag="2" id="q1n-uy-S88">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB Device" image="devGamepad1Template" tag="3" id="SSd-tY-Yc0">
<menuItem title="USB Device 1" image="devGamepad1Template" tag="3" id="SSd-tY-Yc0">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB Device" image="devGamepad2Template" tag="4" id="Q9K-Fv-psl">
<menuItem title="USB Device 2" image="devGamepad2Template" tag="4" id="Q9K-Fv-psl">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB Device 3" image="devGamepad2Template" tag="5" id="0zC-tM-HuV">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB Device 4" image="devGamepad2Template" tag="6" id="1Qp-nL-BKt">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
Expand Down Expand Up @@ -1654,6 +1660,12 @@ DQ
<menuItem title="USB Device 2" image="devGamepad2Template" tag="4" id="lqy-6f-2Mr">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB Device 3" image="devGamepad2Template" tag="5" id="WYc-s8-eLC">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB Device 4" image="devGamepad2Template" tag="6" id="6I5-Pz-Tr4">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
Expand Down
8 changes: 5 additions & 3 deletions GUI/XIB files/Preferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -1109,13 +1109,15 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
</box>
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="V9X-FA-6vA">
<rect key="frame" x="179" y="391" width="239" height="24"/>
<rect key="frame" x="168" y="391" width="266" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="W3f-XA-JgR">
<font key="font" metaFont="system"/>
<segments>
<segment label="External Device 1" selected="YES"/>
<segment label="External Device 2" tag="1"/>
<segment label="Device 1" selected="YES" tag="3"/>
<segment label="Device 2" tag="4"/>
<segment label="Device 3" tag="5"/>
<segment label="Device 4" tag="6"/>
</segments>
</segmentedCell>
<connections>
Expand Down
16 changes: 14 additions & 2 deletions GUI/XIB files/en.lproj/MyDocument.xib
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
<toolbarItem implicitItemIdentifier="F19B641C-3162-47E1-8228-6B75CA6F1A5A" label="Port 1" paletteLabel="Port 1" tag="10" image="devNoneTemplate" title="None" sizingBehavior="auto" id="kR6-IR-lNs">
<nil key="toolTip"/>
<popUpButton key="view" tag="10" id="L2b-nG-yBo" userLabel="Port 1">
<rect key="frame" x="0.0" y="14" width="45" height="24"/>
<rect key="frame" x="0.0" y="14" width="49" height="24"/>
<autoresizingMask key="autoresizingMask"/>
<popUpButtonCell key="cell" type="roundTextured" title="None" bezelStyle="texturedRounded" imagePosition="only" alignment="center" lineBreakMode="truncatingTail" state="on" tag="-1" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" selectedItem="VD3-Wr-Ufe" id="Oxd-8A-P5o" userLabel="PopupButtonCell">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -355,6 +355,12 @@
<menuItem title="USB device" image="devGamepad2Template" tag="4" id="7sJ-UA-Pfj">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB device" image="devGamepad2Template" tag="5" id="lrS-Hd-EqN">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB device" image="devGamepad2Template" tag="6" id="wsd-ge-Hpw">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
Expand All @@ -366,7 +372,7 @@
<toolbarItem implicitItemIdentifier="B42FBC61-316F-46F4-B1B7-C136C71316EC" label="Port 2" paletteLabel="Port 2" tag="11" image="devNoneTemplate" title="None" sizingBehavior="auto" id="Klt-YL-0mv" userLabel="Port 2">
<nil key="toolTip"/>
<popUpButton key="view" tag="11" id="4MP-rV-xX2" userLabel="Port 2">
<rect key="frame" x="0.0" y="14" width="45" height="24"/>
<rect key="frame" x="0.0" y="14" width="49" height="24"/>
<autoresizingMask key="autoresizingMask"/>
<popUpButtonCell key="cell" type="roundTextured" title="None" bezelStyle="texturedRounded" imagePosition="only" alignment="center" lineBreakMode="truncatingTail" state="on" tag="-1" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" selectedItem="xyt-eC-0im" id="skK-6M-sib" userLabel="PopupButtonCell">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -383,6 +389,12 @@
<menuItem title="USB device" image="devGamepad2Template" tag="4" id="L3T-8p-gOj">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB device" image="devGamepad2Template" tag="5" id="grO-r3-dQc">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="USB device" image="devGamepad2Template" tag="6" id="Q85-B8-HQ4">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
</items>
</menu>
</popUpButtonCell>
Expand Down

0 comments on commit 3879884

Please sign in to comment.