Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nthState/3db8b5a82c7a038c2baef88f256e8d4f to your computer and use it in GitHub Desktop.
Save nthState/3db8b5a82c7a038c2baef88f256e8d4f to your computer and use it in GitHub Desktop.
Run Core Haptics on PS5 Dual Sense
import Foundation
import GameController
import CoreHaptics
/**
Ensure the controller supports Haptics, then play
*/
class PlayStationHaptics {
var engine: CHHapticEngine?
func enableHaptics() {
guard let h = GCController.current?.haptics else {
print("Controller does not support Haptics")
return
}
engine = h.createEngine(withLocality: GCHapticsLocality.all)
}
func play(ahapURL: URL) {
do {
try engine?.playPattern(from: ahapURL)
} catch let error {
print(error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment