【问题标题】:Dualshock 4 Touch Pad with C#带有 C# 的 Dualshock 4 触摸板
【发布时间】:2014-01-30 09:36:21
【问题描述】:

我一直在玩一些 DS4 及其在 PC 上的交互。 到目前为止,我已经有了一个按钮列表和所有轴。

现在我期待的问题是,有没有办法访问触摸板(而不是按钮)。 Aka,我可以检查触摸板的某个 X/Y 是否被触摸吗? 如果有,怎么做?

我正在使用 SlimDX。

【问题讨论】:

    标签: c# slimdx joystick


    【解决方案1】:

    我是用 Swift 做的,但是 USB 报告索引是一样的。 您应该能够将其翻译成 C#。棘手的部分是读取字节并将它们转换为整数 16。

    触摸板支持同时使用两个手指,因此如果您想稍后处理手势,则需要以某种方式跟踪触摸 ID。

    下面的代码只读取它可以在单个报告中发送的 4 个数据包中的 1 个。

    let bluetoothOffset = self.isBluetooth ? 2 : 0
    
    // trackpad can send up to 4 packets per report
    // it is sampled at a higher frequency than the reports
    let numberOfPackets = report[33 + bluetoothOffset] // 1 to 4
    // report[34 + bluetoothOffset] // not sure what this is, packet counter maybe?
    self.touchpadTouch0IsActive = report[35 + bluetoothOffset] & 0b1000_0000 != 0b1000_0000
    
    if self.touchpadTouch0IsActive {
        self.touchpadTouch0Id = report[35 + bluetoothOffset] & 0b0111_1111
        // 12 bits only
        self.touchpadTouch0X = Int16((UInt16(report[37 + bluetoothOffset]) << 8 | UInt16(report[36 + bluetoothOffset]))      & 0b0000_1111_1111_1111)
        self.touchpadTouch0Y = Int16((UInt16(report[38 + bluetoothOffset]) << 4 | UInt16(report[37 + bluetoothOffset]) >> 4) & 0b0000_1111_1111_1111)
    }
    
    self.touchpadTouch1IsActive = report[39 + bluetoothOffset] & 0b1000_0000 != 0b1000_0000 // if not active, no need to parse the rest
    if self.touchpadTouch1IsActive {
        self.touchpadTouch1Id = report[39 + bluetoothOffset] & 0b0111_1111
        // 12 bits only
        self.touchpadTouch1X = Int16((UInt16(report[41 + bluetoothOffset]) << 8 | UInt16(report[40 + bluetoothOffset]))      & 0b0000_1111_1111_1111)
        self.touchpadTouch1Y = Int16((UInt16(report[42 + bluetoothOffset]) << 4 | UInt16(report[41 + bluetoothOffset]) >> 4) & 0b0000_1111_1111_1111)
    }
    

    点击在报告的单独部分中读取。

    self.touchpadButton = report[7 + bluetoothOffset] & 0b0000_0010 == 0b0000_0010
    

    完整代码在我的仓库中,尽管 IMU 和电池部分尚未完成:https://github.com/MarcoLuglio/ds4mac/blob/master/GamePad/DualShock4Controller.swift

    同时检查https://www.psdevwiki.com/ps4/DualShock_4
    它提到了以下可能对您有用的规范:

    尺寸 52mmx23mm(外部约) 分辨率:型号 CUH-ZCT1x 系列(零售)1920x943(44.86 点/毫米)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多