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