Skip to content

Commit 15974fc

Browse files
committed
Merge branch 'master' of github.com:felis/USB_Host_Shield_2.0 into xxxajk
2 parents d56ed57 + 67cb06e commit 15974fc

File tree

22 files changed

+133
-390
lines changed

22 files changed

+133
-390
lines changed

BTD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void BTD::HCI_task() {
720720
if(pairWithWii)
721721
Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
722722
else
723-
Notify(PSTR("\r\nBTHID hid(&Btd);"), 0x80);
723+
Notify(PSTR("\r\nBTHID bthid(&Btd);"), 0x80);
724724

725725
Notify(PSTR("\r\nAnd then press any button on the "), 0x80);
726726
if(pairWithWii)

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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ It enables me to see the Bluetooth communication between my Mac and any device.
122122
123123
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.
124124
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.
126126
127127
Before you can use the PS4 controller via Bluetooth you will need to pair with it.
128128
129-
Simply create the PS4BT instance like so: ```PS4BT PS4(&Btd, PAIR);``` and then hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in paring mode.
129+
Simply create the PS4BT instance like so: ```PS4BT PS4(&Btd, PAIR);``` and then hold down the Share button and then hold down the PS without releasing the Share button. The PS4 controller will then start to blink rapidly indicating that it is in paring mode.
130130
131131
It should then automatically pair the dongle with your controller. This only have to be done once.
132132
@@ -138,9 +138,11 @@ Also check out this excellent Wiki by Frank Zhao about the PS4 controller: <http
138138
139139
These libraries consist of the [PS3BT](PS3BT.cpp) and [PS3USB](PS3USB.cpp). These libraries allows you to use a Dualshock 3, Navigation or a Motion controller with the USB Host Shield both via Bluetooth and USB.
140140
141-
In order to use your Playstation controller via Bluetooth you have to set the Bluetooth address of the dongle internally to your PS3 Controller. This can be achieved by plugging the controller in via USB and letting the library set it automatically.
141+
In order to use your Playstation controller via Bluetooth you have to set the Bluetooth address of the dongle internally to your PS3 Controller. This can be achieved by first plugging in the Bluetooth dongle and wait a few seconds. Now plug in the controller via USB and wait until the LEDs start to flash. The library has now written the Bluetooth address of the dongle to the PS3 controller.
142142
143-
__Note:__ To obtain the address you have to plug in the Bluetooth dongle before connecting the controller, or alternatively you could set it in code like so: [PS3BT.ino#L20](examples/Bluetooth/PS3BT/PS3BT.ino#L20).
143+
Finally simply plug in the Bluetooth dongle again and press PS on the PS3 controller. After a few seconds it should be connected to the dongle and ready to use.
144+
145+
__Note:__ You will have to plug in the Bluetooth dongle before connecting the controller, as the library needs to read the address of the dongle. Alternatively you could set it in code like so: [PS3BT.ino#L20](examples/Bluetooth/PS3BT/PS3BT.ino#L20).
144146
145147
For more information about the PS3 protocol see the official wiki: <https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information>.
146148

XBOXRECV.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ void XBOXRECV::setLedRaw(uint8_t value, uint8_t controller) {
514514

515515
void XBOXRECV::setLedOn(LEDEnum led, uint8_t controller) {
516516
if(led == OFF)
517-
setLedRaw(0);
517+
setLedRaw(0, controller);
518518
else if(led != ALL) // All LEDs can't be on a the same time
519-
setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]) + 4);
519+
setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]) + 4, controller);
520520
}
521521

522522
void XBOXRECV::setLedBlink(LEDEnum led, uint8_t controller) {

examples/Bluetooth/PS4BT/PS4BT.ino

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PS4BT PS4(&Btd, PAIR);
2525
//PS4BT PS4(&Btd);
2626

2727
boolean printAngle, printTouch;
28+
uint8_t oldL2Value, oldR2Value;
2829

2930
void setup() {
3031
Serial.begin(115200);
@@ -56,28 +57,46 @@ void loop() {
5657
Serial.print(F("\tR2: "));
5758
Serial.print(PS4.getAnalogButton(R2));
5859
}
60+
if (PS4.getAnalogButton(L2) != oldL2Value || PS4.getAnalogButton(R2) != oldR2Value) // Only write value if it's different
61+
PS4.setRumbleOn(PS4.getAnalogButton(L2), PS4.getAnalogButton(R2));
62+
oldL2Value = PS4.getAnalogButton(L2);
63+
oldR2Value = PS4.getAnalogButton(R2);
64+
5965
if (PS4.getButtonClick(PS)) {
6066
Serial.print(F("\r\nPS"));
6167
PS4.disconnect();
6268
}
6369
else {
64-
if (PS4.getButtonClick(TRIANGLE))
70+
if (PS4.getButtonClick(TRIANGLE)) {
6571
Serial.print(F("\r\nTraingle"));
66-
if (PS4.getButtonClick(CIRCLE))
72+
PS4.setRumbleOn(RumbleLow);
73+
}
74+
if (PS4.getButtonClick(CIRCLE)) {
6775
Serial.print(F("\r\nCircle"));
68-
if (PS4.getButtonClick(CROSS))
76+
PS4.setRumbleOn(RumbleHigh);
77+
}
78+
if (PS4.getButtonClick(CROSS)) {
6979
Serial.print(F("\r\nCross"));
70-
if (PS4.getButtonClick(SQUARE))
80+
PS4.setLedFlash(10, 10); // Set it to blink rapidly
81+
}
82+
if (PS4.getButtonClick(SQUARE)) {
7183
Serial.print(F("\r\nSquare"));
84+
PS4.setLedFlash(0, 0); // Turn off blinking
85+
}
7286

73-
if (PS4.getButtonClick(UP))
87+
if (PS4.getButtonClick(UP)) {
7488
Serial.print(F("\r\nUp"));
75-
if (PS4.getButtonClick(RIGHT))
89+
PS4.setLed(Red);
90+
} if (PS4.getButtonClick(RIGHT)) {
7691
Serial.print(F("\r\nRight"));
77-
if (PS4.getButtonClick(DOWN))
92+
PS4.setLed(Blue);
93+
} if (PS4.getButtonClick(DOWN)) {
7894
Serial.print(F("\r\nDown"));
79-
if (PS4.getButtonClick(LEFT))
95+
PS4.setLed(Yellow);
96+
} if (PS4.getButtonClick(LEFT)) {
8097
Serial.print(F("\r\nLeft"));
98+
PS4.setLed(Green);
99+
}
81100

82101
if (PS4.getButtonClick(L1))
83102
Serial.print(F("\r\nL1"));

examples/Bluetooth/SPP/SPP.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ USB Usb;
1616

1717
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
1818
/* You can create the instance of the class in two ways */
19-
SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "1234"
20-
//SPP SerialBT(&Btd, "Lauszus's Arduino","0000"); // You can also set the name and pin like so
19+
SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
20+
//SPP SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so
2121

2222
boolean firstMessage = true;
2323

examples/HID/USBHIDBootKbdAndMouse/Makefile

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/HID/USBHIDBootKbdAndMouse/nbproject/Package-Default.bash

Lines changed: 0 additions & 75 deletions
This file was deleted.

examples/HID/USBHIDBootKbdAndMouse/nbproject/configurations.xml

Lines changed: 0 additions & 38 deletions
This file was deleted.

examples/HID/USBHIDBootKbdAndMouse/nbproject/project.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)