Skip to content

Commit 53a4ea6

Browse files
committed
Merge branch 'master' into SPPClient
2 parents b8aecac + 2c5f5e8 commit 53a4ea6

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

PS4Parser.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ struct touchpadXY {
8181
} __attribute__((packed)) finger[2]; // 0 = first finger, 1 = second finger
8282
} __attribute__((packed));
8383

84+
struct PS4Status {
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+
8492
struct PS4Data {
8593
/* Button and joystick values */
8694
uint8_t hatValue[4];
@@ -92,8 +100,11 @@ struct PS4Data {
92100
int16_t gyroY, gyroZ, gyroX;
93101
int16_t accX, accZ, accY;
94102

103+
uint8_t dummy2[5];
104+
PS4Status status;
105+
uint8_t dummy3[3];
106+
95107
/* 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
97108
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.
98109
// The last data is read from the last position in the array while the oldest measurement is from the first position.
99110
// 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 {
245256
}
246257
};
247258

259+
/**
260+
* Return the battery level of the PS4 controller.
261+
* @return The battery level in the range 0-15.
262+
*/
263+
uint8_t getBatteryLevel() {
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+
bool getUsbStatus() {
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+
bool getAudioStatus() {
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.
286+
*/
287+
bool getMicStatus() {
288+
return ps4Data.status.mic;
289+
};
290+
248291
/** Turn both rumble and the LEDs off. */
249292
void setAllOff() {
250293
setRumbleOff();

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ It enables me to see the Bluetooth communication between my Mac and any device.
123123
124124
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.
125125
126-
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.
126+
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.
127127
128128
Before you can use the PS4 controller via Bluetooth you will need to pair with it.
129129

keywords.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ getX KEYWORD2
8282
getY KEYWORD2
8383
getTouchCounter KEYWORD2
8484

85+
getUsbStatus KEYWORD2
86+
getAudioStatus KEYWORD2
87+
getMicStatus KEYWORD2
88+
8589
####################################################
8690
# Constants and enums (LITERAL1)
8791
####################################################

0 commit comments

Comments
 (0)