DualShock 4触摸垫,带C#



我一直在使用DS4及其在PC上的交互作用。到目前为止,我有一个按钮和所有轴的列表。

现在我期待的问题是,有没有任何方法可以访问触摸板(而不是按钮)。又名,我可以检查是否触摸了触摸板的某些X/Y?如果是这样,如何?

我正在使用Slimdx。

我使用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/master/gamepad/gamepad/gamepad/dualshock4controller.swift

还检查https://www.psdevwiki.com/ps4/dualshock_4
它提到以下规格可能对您有用:

大小52mmx23mm(外部大约),分辨率:型号CuH-ZCT1X系列(零售)1920x943(44.86点/mm)

最新更新