You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PS4Parser.h
+44-1Lines changed: 44 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,14 @@ struct touchpadXY {
81
81
} __attribute__((packed)) finger[2]; // 0 = first finger, 1 = second finger
82
82
} __attribute__((packed));
83
83
84
+
structPS4Status {
85
+
uint8_t battery : 4;
86
+
uint8_t usb : 1;
87
+
uint8_t audio : 1;
88
+
uint8_t mic : 1;
89
+
uint8_t unknown : 1; // Extension port?
90
+
} __attribute__((packed));
91
+
84
92
structPS4Data {
85
93
/* Button and joystick values */
86
94
uint8_t hatValue[4];
@@ -92,8 +100,11 @@ struct PS4Data {
92
100
int16_t gyroY, gyroZ, gyroX;
93
101
int16_t accX, accZ, accY;
94
102
103
+
uint8_t dummy2[5];
104
+
PS4Status status;
105
+
uint8_t dummy3[3];
106
+
95
107
/* The rest is data for the touchpad */
96
-
uint8_t dummy2[9]; // Byte 5 looks like some kind of status (maybe battery status), bit 1 of byte 8 is set every time a finger is moving around the touchpad
97
108
touchpadXY xy[3]; // It looks like it sends out three coordinates each time, this might be because the microcontroller inside the PS4 controller is much faster than the Bluetooth connection.
98
109
// The last data is read from the last position in the array while the oldest measurement is from the first position.
99
110
// The first position will also keep it's value after the finger is released, while the other two will set them to zero.
@@ -245,6 +256,38 @@ class PS4Parser {
245
256
}
246
257
};
247
258
259
+
/**
260
+
* Return the battery level of the PS4 controller.
261
+
* @return The battery level in the range 0-15.
262
+
*/
263
+
uint8_tgetBatteryLevel() {
264
+
return ps4Data.status.battery;
265
+
};
266
+
267
+
/**
268
+
* Use this to check if an USB cable is connected to the PS4 controller.
269
+
* @return Returns true if an USB cable is connected.
270
+
*/
271
+
boolgetUsbStatus() {
272
+
return ps4Data.status.usb;
273
+
};
274
+
275
+
/**
276
+
* Use this to check if an audio jack cable is connected to the PS4 controller.
277
+
* @return Returns true if an audio jack cable is connected.
278
+
*/
279
+
boolgetAudioStatus() {
280
+
return ps4Data.status.audio;
281
+
};
282
+
283
+
/**
284
+
* Use this to check if a microphone is connected to the PS4 controller.
285
+
* @return Returns true if a microphone is connected.
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ It enables me to see the Bluetooth communication between my Mac and any device.
122
122
123
123
The PS4BT library is split up into the [PS4BT](PS4BT.h) and the [PS4USB](PS4USB.h) library. These allow you to use the Sony PS4 controller via Bluetooth and USB.
124
124
125
-
The [PS4BT.ino](examples/Bluetooth/PS4BT/PS4BT.ino) and [PS4USB.ino](examples/PS4USB/PS4USB.ino) examples shows how to easily read the buttons, joysticks, touchpad and IMU on the controller via Bluetooth and USB respectively. It is also possible to control the rumble and light on the controller.
125
+
The [PS4BT.ino](examples/Bluetooth/PS4BT/PS4BT.ino) and [PS4USB.ino](examples/PS4USB/PS4USB.ino) examples shows how to easily read the buttons, joysticks, touchpad and IMU on the controller via Bluetooth and USB respectively. It is also possible to control the rumble and light on the controller and get the battery level.
126
126
127
127
Before you can use the PS4 controller via Bluetooth you will need to pair with it.
0 commit comments