‹ projects

reverb-m1

Native wired VR on Apple silicon: Reverb G1 display bring-up and stereo demo
git clone https://umhau.org/code/reverb-m1.git
Log | Files | Refs

hidcmd.swift (1144B)


      1 // One-shot headset commands: hidcmd on | off | wake
      2 import Foundation
      3 import IOKit.hid
      4 let m = IOHIDManagerCreate(kCFAllocatorDefault, IOOptionBits(kIOHIDOptionsTypeNone))
      5 IOHIDManagerSetDeviceMatching(m, [kIOHIDVendorIDKey: 0x03f0, kIOHIDProductIDKey: 0x0c6a] as CFDictionary)
      6 IOHIDManagerOpen(m, IOOptionBits(kIOHIDOptionsTypeNone))
      7 guard let d = (IOHIDManagerCopyDevices(m) as? Set<IOHIDDevice>)?.first else { print("QHMD not found"); exit(1) }
      8 func set(_ b: [UInt8]) -> IOReturn { IOHIDDeviceSetReport(d, kIOHIDReportTypeFeature, CFIndex(b[0]), b, b.count) }
      9 switch CommandLine.arguments.dropFirst().first ?? "" {
     10 case "on": print("screen_on", set([0x04, 0x01]))
     11 case "off": print("screen_off", set([0x04, 0x00]))
     12 case "wake":
     13     for _ in 0..<4 {
     14         var c = [UInt8](repeating: 0, count: 64); c[0] = 0x50; c[1] = 0x01; _ = set(c)
     15         var g = [UInt8](repeating: 0, count: 64); g[0] = 0x50; var n = CFIndex(64)
     16         _ = IOHIDDeviceGetReport(d, kIOHIDReportTypeFeature, 0x50, &g, &n); usleep(10_000)
     17     }
     18     print("activate+screen_on", set([0x04, 0x01]))
     19 default: print("usage: hidcmd on|off|wake")
     20 }
     21 withExtendedLifetime(m) {}