-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hid.swift
More file actions
17 lines (16 loc) · 817 Bytes
/
test_hid.swift
File metadata and controls
17 lines (16 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import Foundation
import IOKit.hid
let manager = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))
IOHIDManagerSetDeviceMatching(manager, nil)
let _ = IOHIDManagerOpen(manager, IOOptionBits(kIOHIDOptionsTypeNone))
if let devices = IOHIDManagerCopyDevices(manager) as? [IOHIDDevice] {
for device in devices {
if let name = IOHIDDeviceGetProperty(device, kIOHIDProductKey as CFString) as? String {
if name.lowercased().contains("accelerometer") {
let page = IOHIDDeviceGetProperty(device, kIOHIDPrimaryUsagePageKey as CFString) as? Int ?? -1
let usage = IOHIDDeviceGetProperty(device, kIOHIDPrimaryUsageKey as CFString) as? Int ?? -1
print("Found \(name): Page=\(page), Usage=\(usage)")
}
}
}
}