-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macOS] Add Raw HID device detection
- Loading branch information
Showing
7 changed files
with
119 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Foundation | ||
|
||
class HIDDevice: Equatable, CustomStringConvertible { | ||
let hidDevice: IOHIDDevice | ||
|
||
var usagePage: UInt16 { | ||
HIDDevice.uint16Property(kIOHIDDeviceUsagePageKey, for: hidDevice)! | ||
} | ||
|
||
var usage: UInt16 { | ||
HIDDevice.uint16Property(kIOHIDDeviceUsageKey, for: hidDevice)! | ||
} | ||
|
||
var manufacturer: String? { | ||
HIDDevice.stringProperty(kIOHIDManufacturerKey, for: hidDevice) | ||
} | ||
|
||
var product: String? { | ||
HIDDevice.stringProperty(kIOHIDProductKey, for: hidDevice) | ||
} | ||
|
||
var vendorID: UInt16 { | ||
HIDDevice.uint16Property(kIOHIDVendorIDKey, for: hidDevice)! | ||
} | ||
|
||
var productID: UInt16 { | ||
HIDDevice.uint16Property(kIOHIDProductIDKey, for: hidDevice)! | ||
} | ||
|
||
var revisionBCD: UInt16 { | ||
HIDDevice.uint16Property(kIOHIDVersionNumberKey, for: hidDevice)! | ||
} | ||
|
||
init(_ device: IOHIDDevice) { | ||
hidDevice = device | ||
} | ||
|
||
var description: String { | ||
String(format: "%@ %@ (%04X:%04X:%04X)", manufacturer ?? "", product ?? "", vendorID, productID, revisionBCD) | ||
} | ||
|
||
static func == (lhs: HIDDevice, rhs: HIDDevice) -> Bool { | ||
return lhs.hidDevice === rhs.hidDevice | ||
} | ||
|
||
static func stringProperty(_ propertyName: String, for device: IOHIDDevice) -> String? { | ||
return IOHIDDeviceGetProperty(device, propertyName as CFString) as! String? | ||
} | ||
|
||
static func uint16Property(_ propertyName: String, for device: IOHIDDevice) -> UInt16? { | ||
return (IOHIDDeviceGetProperty(device, propertyName as CFString) as! NSNumber?)!.uint16Value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Foundation | ||
|
||
class RawDevice: HIDDevice {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters