GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(haptic): use persistent actuator and actuation ID 6 for reliable … · feelsodev/louder@35f9233

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • hooks
    • louder-hook.js
  • native
    • HapticEngine.swift
    • HapticEngine
  • opencode-plugin
    • louder.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎hooks/louder-hook.js‎

Copy file name to clipboardExpand all lines: hooks/louder-hook.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ async function playSound(soundType, soundPath) {
5858
} catch {}
5959
}
6060

61-
const ACTUATION_STRONG = 15;
62-
const ACTUATION_WEAK = 6;
61+
const ACTUATION_STRONG = 6;
62+
const ACTUATION_WEAK = 3;
6363

6464
const HAPTIC_ACTUATION_MAP = {
6565
success: ACTUATION_STRONG,
Collapse file

‎native/HapticEngine‎

Copy file name to clipboard
17.3 KB
Binary file not shown.
Collapse file

‎native/HapticEngine.swift‎

Copy file name to clipboardExpand all lines: native/HapticEngine.swift
+91-10Lines changed: 91 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ func MTActuatorOpen(_ actuator: OpaquePointer) -> Int32
1313
func MTActuatorClose(_ actuator: OpaquePointer) -> Int32
1414

1515
@_silgen_name("MTActuatorActuate")
16-
func MTActuatorActuate(_ actuator: OpaquePointer, _ actuationID: Int32, _ unknown1: UInt32, _ unknown2: Float, _ intensity: Float) -> Int32
16+
func MTActuatorActuate(_ actuator: OpaquePointer, _ actuationID: Int32, _ unknown1: UInt32, _ unknown2: Float, _ unknown3: Float) -> Int32
17+
18+
// MARK: - Persistent Actuator State
19+
20+
var persistentActuator: OpaquePointer? = nil
21+
var persistentDeviceID: UInt64 = 0
1722

1823
// MARK: - IOKit Device Discovery
1924

@@ -49,6 +54,18 @@ func findTrackpadDeviceID() -> UInt64? {
4954
continue
5055
}
5156

57+
var isBuiltIn = false
58+
if let builtInRef = IORegistryEntryCreateCFProperty(
59+
service,
60+
"MT Built-In" as CFString,
61+
kCFAllocatorDefault,
62+
0
63+
)?.takeRetainedValue() {
64+
if CFGetTypeID(builtInRef) == CFBooleanGetTypeID() {
65+
isBuiltIn = CFBooleanGetValue((builtInRef as! CFBoolean))
66+
}
67+
}
68+
5269
guard let deviceIDRef = IORegistryEntryCreateCFProperty(
5370
service,
5471
"Multitouch ID" as CFString,
@@ -65,37 +82,101 @@ func findTrackpadDeviceID() -> UInt64? {
6582
var deviceID: Int64 = 0
6683
CFNumberGetValue((deviceIDRef as! CFNumber), .sInt64Type, &deviceID)
6784

68-
return UInt64(bitPattern: deviceID)
85+
let id = UInt64(bitPattern: deviceID)
86+
87+
if isBuiltIn {
88+
return id
89+
}
90+
91+
if persistentDeviceID == 0 {
92+
persistentDeviceID = id
93+
}
6994
}
7095

71-
return nil
96+
return persistentDeviceID != 0 ? persistentDeviceID : nil
7297
}
7398

7499
// MARK: - Haptic Feedback
75100

76-
/// Actuation IDs: 1=very weak, 3=weak, 4=medium, 5=medium-strong, 6=strong, 15=very strong
77-
let ACTUATION_STRONG: Int32 = 15
78-
let ACTUATION_WEAK: Int32 = 6
101+
let ACTUATION_STRONG: Int32 = 6
102+
let ACTUATION_MEDIUM: Int32 = 4
103+
let ACTUATION_WEAK: Int32 = 3
79104

80-
func triggerHaptic(actuationID: Int32, intensity: Float) -> Bool {
105+
func openActuator() -> Bool {
106+
if persistentActuator != nil {
107+
return true
108+
}
109+
81110
guard let deviceID = findTrackpadDeviceID() else {
111+
if ProcessInfo.processInfo.environment["DEBUG"] != nil {
112+
fputs("DEBUG: No trackpad found\n", stderr)
113+
}
82114
return false
83115
}
84116

117+
persistentDeviceID = deviceID
118+
85119
guard let actuator = MTActuatorCreateFromDeviceID(deviceID) else {
120+
if ProcessInfo.processInfo.environment["DEBUG"] != nil {
121+
fputs("DEBUG: Failed to create actuator for device \(deviceID)\n", stderr)
122+
}
86123
return false
87124
}
88125

89126
let openResult = MTActuatorOpen(actuator)
90127
if openResult != 0 {
128+
if ProcessInfo.processInfo.environment["DEBUG"] != nil {
129+
fputs("DEBUG: MTActuatorOpen failed with \(openResult)\n", stderr)
130+
}
131+
return false
132+
}
133+
134+
persistentActuator = actuator
135+
136+
if ProcessInfo.processInfo.environment["DEBUG"] != nil {
137+
fputs("DEBUG: Actuator opened for device \(deviceID)\n", stderr)
138+
}
139+
140+
return true
141+
}
142+
143+
func closeActuator() {
144+
if let actuator = persistentActuator {
91145
_ = MTActuatorClose(actuator)
146+
persistentActuator = nil
147+
}
148+
}
149+
150+
func triggerHaptic(actuationID: Int32, intensity: Float) -> Bool {
151+
if !openActuator() {
92152
return false
93153
}
94154

95-
let clampedActuationID = max(0, min(15, actuationID))
155+
guard let actuator = persistentActuator else {
156+
return false
157+
}
158+
159+
let clampedActuationID = max(1, min(16, actuationID))
96160
let clampedIntensity = max(0.0, min(2.0, intensity))
97-
let actuateResult = MTActuatorActuate(actuator, clampedActuationID, 0, 0.0, clampedIntensity)
98-
_ = MTActuatorClose(actuator)
161+
162+
var actuateResult = MTActuatorActuate(actuator, clampedActuationID, 0, 0.0, clampedIntensity)
163+
164+
if ProcessInfo.processInfo.environment["DEBUG"] != nil {
165+
fputs("DEBUG: MTActuatorActuate(id=\(clampedActuationID), intensity=\(clampedIntensity)) = \(actuateResult)\n", stderr)
166+
}
167+
168+
if actuateResult != 0 {
169+
if ProcessInfo.processInfo.environment["DEBUG"] != nil {
170+
fputs("DEBUG: Retrying after close/reopen\n", stderr)
171+
}
172+
closeActuator()
173+
if openActuator(), let retryActuator = persistentActuator {
174+
actuateResult = MTActuatorActuate(retryActuator, clampedActuationID, 0, 0.0, clampedIntensity)
175+
if ProcessInfo.processInfo.environment["DEBUG"] != nil {
176+
fputs("DEBUG: Retry result = \(actuateResult)\n", stderr)
177+
}
178+
}
179+
}
99180

100181
return actuateResult == 0
101182
}
Collapse file

‎opencode-plugin/louder.js‎

Copy file name to clipboardExpand all lines: opencode-plugin/louder.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function playSound(type = "success") {
9595
async function playHaptic(intensity = 2.0) {
9696
const engine = await getHapticEngine()
9797
if (engine) {
98-
engine.write(`15,${intensity}`)
98+
engine.write(`6,${intensity}`)
9999
}
100100
}
101101

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.