2

I've been playing a little with the DS4 and its' interaction on PC. So far I've got a list of buttons and all the Axis.

Now the question I'm looking forward to is, is there any way to access the Touch Pad (not the button). Aka, can I check if a certain X/Y of the touch pad is being touched? If so, how?

I'm using SlimDX.

Johnaudi
  • 257
  • 1
  • 23

1 Answers1

0

I did this with Swift, but the usb report indexes are the same. You should be able to translate this to C#. The tricky part is reading the bytes and transforming them into an integer 16.

The touchpad supports two simultaneous fingers, so you need to keep track of the touch Ids somehow if you want to process gestures later on.

The code below is only reading 1 of the 4 packets it can send in a single report.

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)
}

The click is read in a separate portion of the report.

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

The full code is in my repo, albeit the IMU and battery portions are not finished: https://github.com/MarcoLuglio/ds4mac/blob/master/GamePad/DualShock4Controller.swift

Also check https://www.psdevwiki.com/ps4/DualShock_4
It mentions the following specs that may be useful for you:

Size 52mmx23mm (external approximately) with resolution: Model CUH-ZCT1x series (Retail) 1920x943 (44.86 dots/mm)

Marco Luglio
  • 3,503
  • 1
  • 21
  • 27