mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge pull request #10 from TKJElectronics/master
Added better example and changed delay once again
This commit is contained in:
commit
31a1357954
2 changed files with 109 additions and 142 deletions
10
PS3BT.cpp
10
PS3BT.cpp
|
@ -682,7 +682,7 @@ void PS3BT::HCI_task()
|
|||
switch (hci_state){
|
||||
case HCI_INIT_STATE:
|
||||
hci_counter++;
|
||||
if (hci_counter > 100) // wait until we have looped 100 times to clear any old events
|
||||
if (hci_counter > 1000) // wait until we have looped 1000 times to clear any old events
|
||||
{
|
||||
hci_reset();
|
||||
hci_state = HCI_RESET_STATE;
|
||||
|
@ -700,7 +700,7 @@ void PS3BT::HCI_task()
|
|||
hci_state = HCI_BDADDR_STATE;
|
||||
hci_read_bdaddr();
|
||||
}
|
||||
else if (hci_counter > 100)
|
||||
else if (hci_counter > 1000)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nNo response to HCI Reset"));
|
||||
|
@ -1072,7 +1072,7 @@ void PS3BT::L2CAP_task()
|
|||
delay(1000);//There has to be a delay before data can be read
|
||||
setLedOn(LED1);
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nDualshock 3 Controller Enabled"));
|
||||
Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"));
|
||||
#endif
|
||||
PS3BTConnected = true;
|
||||
}
|
||||
|
@ -1086,7 +1086,7 @@ void PS3BT::L2CAP_task()
|
|||
delay(1000);//There has to be a delay before data can be read
|
||||
setLedOn(LED1);//This just turns LED constantly on, on the Navigation controller
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nNavigation Controller Enabled"));
|
||||
Notify(PSTR("\r\nNavigation Controller Enabled\r\n"));
|
||||
#endif
|
||||
PS3NavigationBTConnected = true;
|
||||
}
|
||||
|
@ -1095,7 +1095,7 @@ void PS3BT::L2CAP_task()
|
|||
delay(1000);//There has to be a delay before data can be read
|
||||
moveSetBulb(Red);
|
||||
#ifdef DEBUG
|
||||
Notify(PSTR("\r\nMotion Controller Enabled"));
|
||||
Notify(PSTR("\r\nMotion Controller Enabled\r\n"));
|
||||
#endif
|
||||
PS3MoveBTConnected = true;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Example sketch for the PS3 Bluetooth library - developed by Kristian Lauszus
|
||||
For more information visit my blog: http://blog.tkjelectronics.dk/ or
|
||||
send me an e-mail: kristianl@tkjelectronics.com
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <PS3BT.h>
|
||||
USB Usb;
|
||||
|
@ -14,199 +14,166 @@ void setup()
|
|||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
if (Usb.Init() == -1)
|
||||
{
|
||||
Notify(PSTR("\r\nOSC did not start"));
|
||||
if (Usb.Init() == -1) {
|
||||
Serial.print(F("\r\nOSC did not start"));
|
||||
while(1); //halt
|
||||
}
|
||||
Notify(PSTR("\r\nPS3 Bluetooth Library Started"));
|
||||
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
Usb.Task();
|
||||
|
||||
if(BT.PS3BTConnected || BT.PS3NavigationBTConnected)
|
||||
{
|
||||
if(BT.getAnalogHat(LeftHatX) > 137 || BT.getAnalogHat(LeftHatX) < 117)
|
||||
{
|
||||
Notify(PSTR("\r\nLeftHatX: "));
|
||||
if(BT.PS3BTConnected || BT.PS3NavigationBTConnected) {
|
||||
if(BT.getAnalogHat(LeftHatX) > 137 || BT.getAnalogHat(LeftHatX) < 117 || BT.getAnalogHat(LeftHatY) > 137 || BT.getAnalogHat(LeftHatY) < 117 || BT.getAnalogHat(RightHatX) > 137 || BT.getAnalogHat(RightHatX) < 117 || BT.getAnalogHat(RightHatY) > 137 || BT.getAnalogHat(RightHatY) < 117) {
|
||||
if(BT.getAnalogHat(LeftHatX) > 137 || BT.getAnalogHat(LeftHatX) < 117) {
|
||||
Serial.print(F("LeftHatX: "));
|
||||
Serial.print(BT.getAnalogHat(LeftHatX), DEC);
|
||||
}
|
||||
if(BT.getAnalogHat(LeftHatY) > 137 || BT.getAnalogHat(LeftHatY) < 117)
|
||||
{
|
||||
Notify(PSTR("\r\nLeftHatY: "));
|
||||
Serial.print("\t");
|
||||
} if(BT.getAnalogHat(LeftHatY) > 137 || BT.getAnalogHat(LeftHatY) < 117) {
|
||||
Serial.print(F("LeftHatY: "));
|
||||
Serial.print(BT.getAnalogHat(LeftHatY), DEC);
|
||||
}
|
||||
if(BT.getAnalogHat(RightHatX) > 137 || BT.getAnalogHat(RightHatX) < 117)
|
||||
{
|
||||
Notify(PSTR("\r\nRightHatX: "));
|
||||
Serial.print("\t");
|
||||
} if(BT.getAnalogHat(RightHatX) > 137 || BT.getAnalogHat(RightHatX) < 117) {
|
||||
Serial.print(F("RightHatX: "));
|
||||
Serial.print(BT.getAnalogHat(RightHatX), DEC);
|
||||
}
|
||||
if(BT.getAnalogHat(RightHatY) > 137 || BT.getAnalogHat(RightHatY) < 117)
|
||||
{
|
||||
Notify(PSTR("\r\nRightHatY: "));
|
||||
Serial.print("\t");
|
||||
} if(BT.getAnalogHat(RightHatY) > 137 || BT.getAnalogHat(RightHatY) < 117) {
|
||||
Serial.print(F("RightHatY: "));
|
||||
Serial.print(BT.getAnalogHat(RightHatY), DEC);
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
//Analog button values can be read from almost all buttons
|
||||
if(BT.getAnalogButton(L2_ANALOG) > 0)
|
||||
{
|
||||
Notify(PSTR("\r\nL2: "));
|
||||
if(BT.getAnalogButton(L2_ANALOG) > 0 || BT.getAnalogButton(R2_ANALOG) > 0) {
|
||||
if(BT.getAnalogButton(L2_ANALOG) > 0) {
|
||||
Serial.print(F("L2: "));
|
||||
Serial.print(BT.getAnalogButton(L2_ANALOG), DEC);
|
||||
}
|
||||
if(BT.getAnalogButton(R2_ANALOG) > 0)
|
||||
{
|
||||
Notify(PSTR("\r\nR2: "));
|
||||
Serial.print("\t");
|
||||
} if(BT.getAnalogButton(R2_ANALOG) > 0) {
|
||||
Serial.print(F("R2: "));
|
||||
Serial.print(BT.getAnalogButton(R2_ANALOG), DEC);
|
||||
}
|
||||
Serial.println("");
|
||||
}
|
||||
|
||||
if(BT.ButtonPressed)
|
||||
{
|
||||
Notify(PSTR("\r\nPS3 Controller"));
|
||||
Serial.print(F("PS3 Controller"));
|
||||
|
||||
if(BT.getButton(PS))
|
||||
{
|
||||
Notify(PSTR(" - PS"));
|
||||
if(BT.getButton(PS)) {
|
||||
Serial.print(F(" - PS"));
|
||||
BT.disconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if(BT.getButton(TRIANGLE))
|
||||
Notify(PSTR(" - Traingle"));
|
||||
Serial.print(F(" - Traingle"));
|
||||
if(BT.getButton(CIRCLE))
|
||||
Notify(PSTR(" - Circle"));
|
||||
Serial.print(F(" - Circle"));
|
||||
if(BT.getButton(CROSS))
|
||||
Notify(PSTR(" - Cross"));
|
||||
Serial.print(F(" - Cross"));
|
||||
if(BT.getButton(SQUARE))
|
||||
Notify(PSTR(" - Square"));
|
||||
Serial.print(F(" - Square"));
|
||||
|
||||
if(BT.getButton(UP))
|
||||
{
|
||||
Notify(PSTR(" - Up"));
|
||||
if(BT.getButton(UP)) {
|
||||
Serial.print(F(" - Up"));
|
||||
BT.setAllOff();
|
||||
BT.setLedOn(LED4);
|
||||
}
|
||||
if(BT.getButton(RIGHT))
|
||||
{
|
||||
Notify(PSTR(" - Right"));
|
||||
} if(BT.getButton(RIGHT)) {
|
||||
Serial.print(F(" - Right"));
|
||||
BT.setAllOff();
|
||||
BT.setLedOn(LED1);
|
||||
}
|
||||
if(BT.getButton(DOWN))
|
||||
{
|
||||
Notify(PSTR(" - Down"));
|
||||
} if(BT.getButton(DOWN)) {
|
||||
Serial.print(F(" - Down"));
|
||||
BT.setAllOff();
|
||||
BT.setLedOn(LED2);
|
||||
}
|
||||
if(BT.getButton(LEFT))
|
||||
{
|
||||
Notify(PSTR(" - Left"));
|
||||
} if(BT.getButton(LEFT)) {
|
||||
Serial.print(F(" - Left"));
|
||||
BT.setAllOff();
|
||||
BT.setLedOn(LED3);
|
||||
}
|
||||
|
||||
if(BT.getButton(L1))
|
||||
Notify(PSTR(" - L1"));
|
||||
Serial.print(F(" - L1"));
|
||||
//if(BT.getButton(L2))
|
||||
//Notify(PSTR(" - L2"));
|
||||
//Serial.print(F(" - L2"));
|
||||
if(BT.getButton(L3))
|
||||
Notify(PSTR(" - L3"));
|
||||
Serial.print(F(" - L3"));
|
||||
if(BT.getButton(R1))
|
||||
Notify(PSTR(" - R1"));
|
||||
Serial.print(F(" - R1"));
|
||||
//if(BT.getButton(R2))
|
||||
//Notify(PSTR(" - R2"));
|
||||
//Serial.print(F(" - R2"));
|
||||
if(BT.getButton(R3))
|
||||
Notify(PSTR(" - R3"));
|
||||
Serial.print(F(" - R3"));
|
||||
|
||||
if(BT.getButton(SELECT))
|
||||
{
|
||||
Notify(PSTR(" - Select - "));
|
||||
if(BT.getButton(SELECT)) {
|
||||
Serial.print(F(" - Select - "));
|
||||
Serial.print(BT.getStatusString());
|
||||
}
|
||||
if(BT.getButton(START))
|
||||
Notify(PSTR(" - Start"));
|
||||
} if(BT.getButton(START))
|
||||
Serial.print(F(" - Start"));
|
||||
|
||||
Serial.println("");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(BT.PS3MoveBTConnected)
|
||||
{
|
||||
if(BT.getAnalogButton(T_MOVE_ANALOG) > 0)
|
||||
{
|
||||
Notify(PSTR("\r\nT: "));
|
||||
Serial.print(BT.getAnalogButton(T_MOVE_ANALOG), DEC);
|
||||
}
|
||||
if(BT.ButtonPressed)
|
||||
{
|
||||
Notify(PSTR("\r\nPS3 Move Controller"));
|
||||
if(BT.getAnalogButton(T_MOVE_ANALOG) > 0) {
|
||||
Serial.print(F("T: "));
|
||||
Serial.println(BT.getAnalogButton(T_MOVE_ANALOG), DEC);
|
||||
} if(BT.ButtonPressed) {
|
||||
Serial.print(F("PS3 Move Controller"));
|
||||
|
||||
if(BT.getButton(PS_MOVE))
|
||||
{
|
||||
Notify(PSTR(" - PS"));
|
||||
if(BT.getButton(PS_MOVE)) {
|
||||
Serial.print(F(" - PS"));
|
||||
BT.disconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(BT.getButton(SELECT_MOVE))
|
||||
{
|
||||
Notify(PSTR(" - Select"));
|
||||
} else {
|
||||
if(BT.getButton(SELECT_MOVE)) {
|
||||
Serial.print(F(" - Select"));
|
||||
printTemperature = false;
|
||||
}
|
||||
if(BT.getButton(START_MOVE))
|
||||
{
|
||||
Notify(PSTR(" - Start"));
|
||||
} if(BT.getButton(START_MOVE)) {
|
||||
Serial.print(F(" - Start"));
|
||||
printTemperature = true;
|
||||
}
|
||||
if(BT.getButton(TRIANGLE_MOVE))
|
||||
{
|
||||
Notify(PSTR(" - Triangle"));
|
||||
} if(BT.getButton(TRIANGLE_MOVE)) {
|
||||
Serial.print(F(" - Triangle"));
|
||||
BT.moveSetBulb(Red);
|
||||
}
|
||||
if(BT.getButton(CIRCLE_MOVE))
|
||||
{
|
||||
Notify(PSTR(" - Circle"));
|
||||
} if(BT.getButton(CIRCLE_MOVE)) {
|
||||
Serial.print(F(" - Circle"));
|
||||
BT.moveSetBulb(Green);
|
||||
}
|
||||
if(BT.getButton(SQUARE_MOVE))
|
||||
{
|
||||
Notify(PSTR(" - Square"));
|
||||
} if(BT.getButton(SQUARE_MOVE)) {
|
||||
Serial.print(F(" - Square"));
|
||||
BT.moveSetBulb(Blue);
|
||||
}
|
||||
if(BT.getButton(CROSS_MOVE))
|
||||
{
|
||||
Notify(PSTR(" - Cross"));
|
||||
} if(BT.getButton(CROSS_MOVE)) {
|
||||
Serial.print(F(" - Cross"));
|
||||
BT.moveSetBulb(Yellow);
|
||||
}
|
||||
if(BT.getButton(MOVE_MOVE))
|
||||
{
|
||||
} if(BT.getButton(MOVE_MOVE)) {
|
||||
BT.moveSetBulb(Off);
|
||||
Notify(PSTR(" - Move"));
|
||||
Notify(PSTR(" - "));
|
||||
Serial.print(F(" - Move"));
|
||||
Serial.print(F(" - "));
|
||||
Serial.print(BT.getStatusString());
|
||||
}
|
||||
//if(BT.getButton(T_MOVE))
|
||||
//Notify(PSTR(" - T"));
|
||||
//if(BT.getButton(T))
|
||||
//Serial.print(F(" - T"));
|
||||
|
||||
Serial.println("");
|
||||
}
|
||||
}
|
||||
if(printTemperature)
|
||||
{
|
||||
if(printTemperature) {
|
||||
String templow;
|
||||
String temphigh;
|
||||
String input = String(BT.getSensor(tempMove), DEC);
|
||||
|
||||
if (input.length() > 3)
|
||||
{
|
||||
if (input.length() > 3) {
|
||||
temphigh = input.substring(0, 2);
|
||||
templow = input.substring(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
temphigh = input.substring(0, 1);
|
||||
templow = input.substring(1);
|
||||
}
|
||||
Notify(PSTR("\r\nTemperature: "));
|
||||
Serial.print(F("Temperature: "));
|
||||
Serial.print(temphigh);
|
||||
Notify(PSTR("."));
|
||||
Serial.print(templow);
|
||||
Serial.print(F("."));
|
||||
Serial.println(templow);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue