Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env swift
- // script to enable audio haptics on the DualSense controller
- //
- // Run it with `swift dualsense_haptics.swift` in the command line after installing the Xcode developer tools
- import IOKit.hid
- import Foundation
- let hidMgr = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))
- IOHIDManagerSetDeviceMatching(hidMgr, nil)
- IOHIDManagerScheduleWithRunLoop(hidMgr, CFRunLoopGetCurrent(), CFRunLoopMode.defaultMode.rawValue)
- // we want only the DualSense controller
- var matchingDevices = NSMutableDictionary()
- matchingDevices[kIOHIDVendorIDKey] = 0x054c
- matchingDevices[kIOHIDProductIDKey] = 0x0ce6
- IOHIDManagerSetDeviceMatching(hidMgr, matchingDevices)
- // give the hid manager some time to start up
- while true {
- let res = CFRunLoopRunInMode(CFRunLoopMode.defaultMode, 0, false)
- if res == .finished || res == .timedOut {
- break
- }
- }
- if let devices = IOHIDManagerCopyDevices(hidMgr) {
- let devices = devices as NSSet
- if devices.count == 0 {
- print("could not find any connected DualSense controller")
- }
- for device in devices {
- let device = device as! IOHIDDevice
- if IOHIDDeviceOpen(device, IOOptionBits(kIOHIDOptionsTypeSeizeDevice)) == kIOReturnSuccess {
- var outputReport: [UInt8] = [0x2, 0x1]
- for _ in 0..<62 {
- outputReport.append(0)
- }
- if IOHIDDeviceSetReport(device, kIOHIDReportTypeOutput, 0, outputReport, 64) == kIOReturnSuccess {
- print("successfully enabled haptics")
- } else {
- print("could not enable haptics")
- }
- } else {
- print("could not connect to device")
- }
- }
- } else {
- print("could not get devices :(")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement