Merge branch 'master' into SPPClient

This commit is contained in:
Kristian Lauszus 2014-04-23 23:54:58 +02:00
commit 53a4ea63f2
3 changed files with 49 additions and 2 deletions

View file

@ -81,6 +81,14 @@ struct touchpadXY {
} __attribute__((packed)) finger[2]; // 0 = first finger, 1 = second finger } __attribute__((packed)) finger[2]; // 0 = first finger, 1 = second finger
} __attribute__((packed)); } __attribute__((packed));
struct PS4Status {
uint8_t battery : 4;
uint8_t usb : 1;
uint8_t audio : 1;
uint8_t mic : 1;
uint8_t unknown : 1; // Extension port?
} __attribute__((packed));
struct PS4Data { struct PS4Data {
/* Button and joystick values */ /* Button and joystick values */
uint8_t hatValue[4]; uint8_t hatValue[4];
@ -92,8 +100,11 @@ struct PS4Data {
int16_t gyroY, gyroZ, gyroX; int16_t gyroY, gyroZ, gyroX;
int16_t accX, accZ, accY; int16_t accX, accZ, accY;
uint8_t dummy2[5];
PS4Status status;
uint8_t dummy3[3];
/* The rest is data for the touchpad */ /* The rest is data for the touchpad */
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
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. 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.
// The last data is read from the last position in the array while the oldest measurement is from the first position. // The last data is read from the last position in the array while the oldest measurement is from the first position.
// The first position will also keep it's value after the finger is released, while the other two will set them to zero. // 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 @@ public:
} }
}; };
/**
* Return the battery level of the PS4 controller.
* @return The battery level in the range 0-15.
*/
uint8_t getBatteryLevel() {
return ps4Data.status.battery;
};
/**
* Use this to check if an USB cable is connected to the PS4 controller.
* @return Returns true if an USB cable is connected.
*/
bool getUsbStatus() {
return ps4Data.status.usb;
};
/**
* Use this to check if an audio jack cable is connected to the PS4 controller.
* @return Returns true if an audio jack cable is connected.
*/
bool getAudioStatus() {
return ps4Data.status.audio;
};
/**
* Use this to check if a microphone is connected to the PS4 controller.
* @return Returns true if a microphone is connected.
*/
bool getMicStatus() {
return ps4Data.status.mic;
};
/** Turn both rumble and the LEDs off. */ /** Turn both rumble and the LEDs off. */
void setAllOff() { void setAllOff() {
setRumbleOff(); setRumbleOff();

View file

@ -123,7 +123,7 @@ It enables me to see the Bluetooth communication between my Mac and any device.
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. 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.
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. 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.
Before you can use the PS4 controller via Bluetooth you will need to pair with it. Before you can use the PS4 controller via Bluetooth you will need to pair with it.

View file

@ -82,6 +82,10 @@ getX KEYWORD2
getY KEYWORD2 getY KEYWORD2
getTouchCounter KEYWORD2 getTouchCounter KEYWORD2
getUsbStatus KEYWORD2
getAudioStatus KEYWORD2
getMicStatus KEYWORD2
#################################################### ####################################################
# Constants and enums (LITERAL1) # Constants and enums (LITERAL1)
#################################################### ####################################################