Created
July 2, 2021 19:55
-
-
Save nthState/3db8b5a82c7a038c2baef88f256e8d4f to your computer and use it in GitHub Desktop.
Run Core Haptics on PS5 Dual Sense
This file contains hidden or 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
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