mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge branch 'master' of github.com:felis/USB_Host_Shield_2.0
This commit is contained in:
commit
c16a160243
5 changed files with 837 additions and 711 deletions
100
PS3BT.h
100
PS3BT.h
|
@ -25,10 +25,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Usb.h"
|
#include "Usb.h"
|
||||||
|
#include "confdescparser.h"
|
||||||
/*The application will work in reduced host mode, so we can save program and data
|
|
||||||
memory space. After verifying the PID and VID we will use known values for the
|
|
||||||
configuration values for device, interface, endpoints and HID */
|
|
||||||
|
|
||||||
/* CSR Bluetooth data taken from descriptors */
|
/* CSR Bluetooth data taken from descriptors */
|
||||||
#define INT_MAXPKTSIZE 16 // max size for HCI data
|
#define INT_MAXPKTSIZE 16 // max size for HCI data
|
||||||
|
@ -39,35 +36,26 @@
|
||||||
|
|
||||||
/* Endpoint types */
|
/* Endpoint types */
|
||||||
#define EP_INTERRUPT 0x03
|
#define EP_INTERRUPT 0x03
|
||||||
#define EP_BULK 0x02
|
|
||||||
|
|
||||||
#define CSR_CONTROL_PIPE 0 // names we give to the 4 pipes
|
/* Names we give to the 3 ps3 pipes - this is only used for setting the bluetooth address into the ps3 controllers */
|
||||||
#define CSR_EVENT_PIPE 1
|
#define PS3_CONTROL_PIPE 0
|
||||||
#define CSR_DATAIN_PIPE 2
|
|
||||||
#define CSR_DATAOUT_PIPE 3
|
|
||||||
|
|
||||||
#define PS3_CONTROL_PIPE 0 // names we give to the 3 pipes
|
|
||||||
#define PS3_OUTPUT_PIPE 1
|
#define PS3_OUTPUT_PIPE 1
|
||||||
#define PS3_INPUT_PIPE 2
|
#define PS3_INPUT_PIPE 2
|
||||||
|
|
||||||
//PID and VID of the different devices
|
//PID and VID of the different devices
|
||||||
#define CSR_VID 0x0A12 //Cambridge Silicon Radio Ltd.
|
#define PS3_VID 0x054C // Sony Corporation
|
||||||
#define CSR_PID 0x0001 //Bluetooth HCI Device
|
#define PS3_PID 0x0268 // PS3 Controller DualShock 3
|
||||||
#define PS3_VID 0x054C //Sony Corporation
|
#define PS3NAVIGATION_PID 0x042F // Navigation controller
|
||||||
#define PS3_PID 0x0268 //PS3 Controller DualShock 3
|
#define PS3MOVE_PID 0x03D5 // Motion controller
|
||||||
#define PS3NAVIGATION_VID 0x054C //Sony Corporation
|
|
||||||
#define PS3NAVIGATION_PID 0x042F //Navigation controller
|
|
||||||
#define PS3MOVE_VID 0x054C //Sony Corporation
|
|
||||||
#define PS3MOVE_PID 0x03D5 //Motion controller
|
|
||||||
|
|
||||||
#define HIDMOVEBUFFERSIZE 50 // size of the buffer for the Playstation Motion Controller
|
#define HID_BUFFERSIZE 50 // size of the buffer for the Playstation Motion Controller
|
||||||
#define OUTPUT_REPORT_BUFFER_SIZE 48 //Size of the output report buffer for the controllers
|
#define OUTPUT_REPORT_BUFFER_SIZE 48 //Size of the output report buffer for the controllers
|
||||||
|
|
||||||
// used in control endpoint header for HCI Commands
|
// used in control endpoint header for HCI Commands
|
||||||
#define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
|
#define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE
|
||||||
|
|
||||||
// used in control endpoint header for HID Commands
|
// used in control endpoint header for HID Commands
|
||||||
#define bmREQ_HIDOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
|
#define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
|
||||||
#define HID_REQUEST_SET_REPORT 0x09
|
#define HID_REQUEST_SET_REPORT 0x09
|
||||||
|
|
||||||
/* Bluetooth HCI states for hci_task() */
|
/* Bluetooth HCI states for hci_task() */
|
||||||
|
@ -84,19 +72,15 @@
|
||||||
|
|
||||||
/* HCI event flags*/
|
/* HCI event flags*/
|
||||||
#define HCI_FLAG_CMD_COMPLETE 0x01
|
#define HCI_FLAG_CMD_COMPLETE 0x01
|
||||||
#define HCI_FLAG_CMD_STATUS 0x02
|
#define HCI_FLAG_CONN_COMPLETE 0x02
|
||||||
#define HCI_FLAG_CONN_COMPLETE 0x04
|
#define HCI_FLAG_DISCONN_COMPLETE 0x04
|
||||||
#define HCI_FLAG_DISCONN_COMPLETE 0x08
|
#define HCI_FLAG_REMOTE_NAME_COMPLETE 0x08
|
||||||
#define HCI_FLAG_CONNECT_OK 0x10
|
#define HCI_FLAG_INCOMING_REQUEST 0x10
|
||||||
#define HCI_FLAG_REMOTE_NAME_COMPLETE 0x20
|
|
||||||
#define HCI_FLAG_INCOMING_REQUEST 0x40
|
|
||||||
|
|
||||||
/*Macros for HCI event flag tests */
|
/*Macros for HCI event flag tests */
|
||||||
#define hci_cmd_complete (hci_event_flag & HCI_FLAG_CMD_COMPLETE)
|
#define hci_cmd_complete (hci_event_flag & HCI_FLAG_CMD_COMPLETE)
|
||||||
#define hci_cmd_status (hci_event_flag & HCI_FLAG_CMD_STATUS)
|
|
||||||
#define hci_connect_complete (hci_event_flag & HCI_FLAG_CONN_COMPLETE)
|
#define hci_connect_complete (hci_event_flag & HCI_FLAG_CONN_COMPLETE)
|
||||||
#define hci_disconnect_complete (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE)
|
#define hci_disconnect_complete (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE)
|
||||||
#define hci_connect_ok (hci_event_flag & HCI_FLAG_CONNECT_OK)
|
|
||||||
#define hci_remote_name_complete (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE)
|
#define hci_remote_name_complete (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE)
|
||||||
#define hci_incoming_connect_request (hci_event_flag & HCI_FLAG_INCOMING_REQUEST)
|
#define hci_incoming_connect_request (hci_event_flag & HCI_FLAG_INCOMING_REQUEST)
|
||||||
|
|
||||||
|
@ -111,6 +95,11 @@
|
||||||
#define EV_REMOTE_NAME_COMPLETE 0x07
|
#define EV_REMOTE_NAME_COMPLETE 0x07
|
||||||
#define EV_INCOMING_CONNECT 0x04
|
#define EV_INCOMING_CONNECT 0x04
|
||||||
#define EV_ROLE_CHANGED 0x12
|
#define EV_ROLE_CHANGED 0x12
|
||||||
|
#define EV_PAGE_SCAN_REP_MODE 0x20
|
||||||
|
#define EV_DATA_BUFFER_OVERFLOW 0x1A
|
||||||
|
#define EV_LOOPBACK_COMMAND 0x19
|
||||||
|
#define EV_CHANGE_CONNECTION_LINK 0x09
|
||||||
|
#define EV_AUTHENTICATION_COMPLETE 0x06
|
||||||
|
|
||||||
/* Bluetooth L2CAP states for L2CAP_task() */
|
/* Bluetooth L2CAP states for L2CAP_task() */
|
||||||
#define L2CAP_EV_WAIT 0
|
#define L2CAP_EV_WAIT 0
|
||||||
|
@ -121,9 +110,10 @@
|
||||||
#define L2CAP_EV_INTERRUPT_REQUEST 5
|
#define L2CAP_EV_INTERRUPT_REQUEST 5
|
||||||
#define L2CAP_EV_INTERRUPT_SUCCESS 6
|
#define L2CAP_EV_INTERRUPT_SUCCESS 6
|
||||||
#define L2CAP_EV_HID_ENABLE_SIXAXIS 7
|
#define L2CAP_EV_HID_ENABLE_SIXAXIS 7
|
||||||
#define L2CAP_EV_L2CAP_DONE 8
|
#define L2CAP_EV_HID_PS3_LED 8
|
||||||
#define L2CAP_EV_INTERRUPT_DISCONNECT 9
|
#define L2CAP_EV_L2CAP_DONE 9
|
||||||
#define L2CAP_EV_CONTROL_DISCONNECT 10
|
#define L2CAP_EV_INTERRUPT_DISCONNECT 10
|
||||||
|
#define L2CAP_EV_CONTROL_DISCONNECT 11
|
||||||
|
|
||||||
/* L2CAP event flags */
|
/* L2CAP event flags */
|
||||||
#define L2CAP_EV_CONTROL_CONNECTION_REQUEST 0x01
|
#define L2CAP_EV_CONTROL_CONNECTION_REQUEST 0x01
|
||||||
|
@ -162,7 +152,9 @@
|
||||||
#define PENDING 0x01
|
#define PENDING 0x01
|
||||||
#define SUCCESSFUL 0x00
|
#define SUCCESSFUL 0x00
|
||||||
|
|
||||||
#define bConfigurationValue 0x01 // Used to set configuration
|
// Used to determine if it is a Bluetooth dongle
|
||||||
|
#define WI_SUBCLASS_RF 0x01
|
||||||
|
#define WI_PROTOCOL_BT 0x01
|
||||||
|
|
||||||
#define PS3_MAX_ENDPOINTS 4
|
#define PS3_MAX_ENDPOINTS 4
|
||||||
|
|
||||||
|
@ -321,9 +313,10 @@ enum Rumble
|
||||||
RumbleLow = 0x20,
|
RumbleLow = 0x20,
|
||||||
};
|
};
|
||||||
|
|
||||||
class PS3BT : public USBDeviceConfig
|
class PS3BT : public USBDeviceConfig, public UsbConfigXtracter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
PS3BT(USB *pUsb, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0);
|
||||||
PS3BT(USB *pUsb);
|
PS3BT(USB *pUsb);
|
||||||
|
|
||||||
// USBDeviceConfig implementation
|
// USBDeviceConfig implementation
|
||||||
|
@ -331,6 +324,12 @@ public:
|
||||||
virtual uint8_t Release();
|
virtual uint8_t Release();
|
||||||
virtual uint8_t Poll();
|
virtual uint8_t Poll();
|
||||||
virtual uint8_t GetAddress() { return bAddress; };
|
virtual uint8_t GetAddress() { return bAddress; };
|
||||||
|
virtual bool isReady() { return bPollEnable; };
|
||||||
|
|
||||||
|
// UsbConfigXtracter implementation
|
||||||
|
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
|
||||||
|
|
||||||
|
bool isWatingForConnection() { return watingForConnection; }; // Use this to indicate when it is ready for a incoming connection
|
||||||
|
|
||||||
void setBdaddr(uint8_t* BDADDR);
|
void setBdaddr(uint8_t* BDADDR);
|
||||||
void setMoveBdaddr(uint8_t* BDADDR);
|
void setMoveBdaddr(uint8_t* BDADDR);
|
||||||
|
@ -339,8 +338,8 @@ public:
|
||||||
bool getButton(Button b);
|
bool getButton(Button b);
|
||||||
uint8_t getAnalogButton(AnalogButton a);
|
uint8_t getAnalogButton(AnalogButton a);
|
||||||
uint8_t getAnalogHat(AnalogHat a);
|
uint8_t getAnalogHat(AnalogHat a);
|
||||||
uint32_t getSensor(Sensor a);
|
int32_t getSensor(Sensor a);
|
||||||
double getAngle(Angle a, boolean resolution);
|
double getAngle(Angle a);
|
||||||
bool getStatus(Status c);
|
bool getStatus(Status c);
|
||||||
String getStatusString();
|
String getStatusString();
|
||||||
void disconnect(); // use this void to disconnect any of the controllers
|
void disconnect(); // use this void to disconnect any of the controllers
|
||||||
|
@ -360,32 +359,49 @@ public:
|
||||||
bool PS3BTConnected;// Variable used to indicate if the normal playstation controller is successfully connected
|
bool PS3BTConnected;// Variable used to indicate if the normal playstation controller is successfully connected
|
||||||
bool PS3MoveBTConnected;// Variable used to indicate if the move controller is successfully connected
|
bool PS3MoveBTConnected;// Variable used to indicate if the move controller is successfully connected
|
||||||
bool PS3NavigationBTConnected;// Variable used to indicate if the navigation controller is successfully connected
|
bool PS3NavigationBTConnected;// Variable used to indicate if the navigation controller is successfully connected
|
||||||
bool ButtonChanged;//Indicate if a button has been changed
|
bool buttonChanged;//Indicate if a button has been changed
|
||||||
bool ButtonPressed;//Indicate if a button has been pressed
|
bool buttonPressed;//Indicate if a button has been pressed
|
||||||
|
bool buttonReleased;//Indicate if a button has been pressed
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* mandatory members */
|
/* mandatory members */
|
||||||
USB *pUsb;
|
USB *pUsb;
|
||||||
uint8_t bAddress;
|
uint8_t bAddress; // device address
|
||||||
EpInfo epInfo[PS3_MAX_ENDPOINTS]; //endpoint info structure
|
EpInfo epInfo[PS3_MAX_ENDPOINTS]; //endpoint info structure
|
||||||
|
|
||||||
|
uint8_t bConfNum; // configuration number
|
||||||
|
uint8_t bNumEP; // total number of endpoints in the configuration
|
||||||
|
uint32_t qNextPollTime; // next poll time
|
||||||
|
|
||||||
|
#define BTD_CONTROL_PIPE 0 // Bluetooth dongles control endpoint
|
||||||
|
static const uint8_t BTD_EVENT_PIPE; // HCI event endpoint index
|
||||||
|
static const uint8_t BTD_DATAIN_PIPE; // ACL In endpoint index
|
||||||
|
static const uint8_t BTD_DATAOUT_PIPE; // ACL Out endpoint index
|
||||||
|
|
||||||
|
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool bPollEnable;
|
bool bPollEnable;
|
||||||
|
uint8_t pollInterval;
|
||||||
|
bool watingForConnection;
|
||||||
|
|
||||||
/*variables filled from HCI event management */
|
/*variables filled from HCI event management */
|
||||||
int16_t hci_handle;
|
int16_t hci_handle;
|
||||||
uint8_t disc_bdaddr[6]; // maximum of three discovered devices
|
uint8_t disc_bdaddr[6]; // the bluetooth address is always 6 bytes
|
||||||
uint8_t remote_name[30]; // first 30 chars of remote name
|
uint8_t remote_name[30]; // first 30 chars of remote name
|
||||||
|
|
||||||
/* variables used by high level HCI task */
|
/* variables used by high level HCI task */
|
||||||
uint8_t hci_state; //current state of bluetooth hci connection
|
uint8_t hci_state; //current state of bluetooth hci connection
|
||||||
uint16_t hci_counter; // counter used for bluetooth hci reset loops
|
uint16_t hci_counter; // counter used for bluetooth hci reset loops
|
||||||
|
uint8_t hci_num_reset_loops; // this value indicate how many times it should read before trying to reset
|
||||||
uint16_t hci_event_flag;// hci flags of received bluetooth events
|
uint16_t hci_event_flag;// hci flags of received bluetooth events
|
||||||
|
|
||||||
/* variables used by high level L2CAP task */
|
/* variables used by high level L2CAP task */
|
||||||
uint8_t l2cap_state;
|
uint8_t l2cap_state;
|
||||||
uint16_t l2cap_event_flag;// l2cap flags of received bluetooth events
|
uint16_t l2cap_event_flag;// l2cap flags of received bluetooth events
|
||||||
|
|
||||||
|
unsigned long timer;
|
||||||
|
|
||||||
uint32_t ButtonState;
|
uint32_t ButtonState;
|
||||||
uint32_t OldButtonState;
|
uint32_t OldButtonState;
|
||||||
uint32_t timerHID;// timer used see if there has to be a delay before a new HID command
|
uint32_t timerHID;// timer used see if there has to be a delay before a new HID command
|
||||||
|
@ -397,8 +413,8 @@ private:
|
||||||
uint8_t hcibuf[BULK_MAXPKTSIZE];//General purpose buffer for hci data
|
uint8_t hcibuf[BULK_MAXPKTSIZE];//General purpose buffer for hci data
|
||||||
uint8_t l2capinbuf[BULK_MAXPKTSIZE];//General purpose buffer for l2cap in data
|
uint8_t l2capinbuf[BULK_MAXPKTSIZE];//General purpose buffer for l2cap in data
|
||||||
uint8_t l2capoutbuf[BULK_MAXPKTSIZE];//General purpose buffer for l2cap out data
|
uint8_t l2capoutbuf[BULK_MAXPKTSIZE];//General purpose buffer for l2cap out data
|
||||||
uint8_t HIDBuffer[BULK_MAXPKTSIZE];// Used to store HID commands
|
uint8_t HIDBuffer[HID_BUFFERSIZE];// Used to store HID commands
|
||||||
uint8_t HIDMoveBuffer[HIDMOVEBUFFERSIZE];// Used to store HID commands for the Move controller
|
uint8_t HIDMoveBuffer[HID_BUFFERSIZE];// Used to store HID commands for the Move controller
|
||||||
|
|
||||||
/* L2CAP Channels */
|
/* L2CAP Channels */
|
||||||
uint8_t control_scid[2];// L2CAP source CID for HID_Control
|
uint8_t control_scid[2];// L2CAP source CID for HID_Control
|
||||||
|
|
|
@ -6,9 +6,12 @@
|
||||||
|
|
||||||
#include <PS3BT.h>
|
#include <PS3BT.h>
|
||||||
USB Usb;
|
USB Usb;
|
||||||
PS3BT BT(&Usb);
|
/* You can create the instance of the class in two ways */
|
||||||
|
PS3BT BT(&Usb); // This will just create the instance
|
||||||
|
//PS3BT BT(&Usb,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch
|
||||||
|
|
||||||
boolean printTemperature;
|
boolean printTemperature;
|
||||||
|
boolean printAngle;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
@ -28,19 +31,19 @@ void loop()
|
||||||
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 || 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: "));
|
Serial.print(F("LeftHatX: "));
|
||||||
Serial.print(BT.getAnalogHat(LeftHatX), DEC);
|
Serial.print(BT.getAnalogHat(LeftHatX));
|
||||||
Serial.print("\t");
|
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(F("LeftHatY: "));
|
||||||
Serial.print(BT.getAnalogHat(LeftHatY), DEC);
|
Serial.print(BT.getAnalogHat(LeftHatY));
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
} if(BT.getAnalogHat(RightHatX) > 137 || BT.getAnalogHat(RightHatX) < 117) {
|
} if(BT.getAnalogHat(RightHatX) > 137 || BT.getAnalogHat(RightHatX) < 117) {
|
||||||
Serial.print(F("RightHatX: "));
|
Serial.print(F("RightHatX: "));
|
||||||
Serial.print(BT.getAnalogHat(RightHatX), DEC);
|
Serial.print(BT.getAnalogHat(RightHatX));
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
} if(BT.getAnalogHat(RightHatY) > 137 || BT.getAnalogHat(RightHatY) < 117) {
|
} if(BT.getAnalogHat(RightHatY) > 137 || BT.getAnalogHat(RightHatY) < 117) {
|
||||||
Serial.print(F("RightHatY: "));
|
Serial.print(F("RightHatY: "));
|
||||||
Serial.print(BT.getAnalogHat(RightHatY), DEC);
|
Serial.print(BT.getAnalogHat(RightHatY));
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
}
|
}
|
||||||
|
@ -49,16 +52,16 @@ void loop()
|
||||||
if(BT.getAnalogButton(L2_ANALOG) > 0 || BT.getAnalogButton(R2_ANALOG) > 0) {
|
if(BT.getAnalogButton(L2_ANALOG) > 0 || BT.getAnalogButton(R2_ANALOG) > 0) {
|
||||||
if(BT.getAnalogButton(L2_ANALOG) > 0) {
|
if(BT.getAnalogButton(L2_ANALOG) > 0) {
|
||||||
Serial.print(F("L2: "));
|
Serial.print(F("L2: "));
|
||||||
Serial.print(BT.getAnalogButton(L2_ANALOG), DEC);
|
Serial.print(BT.getAnalogButton(L2_ANALOG));
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
} if(BT.getAnalogButton(R2_ANALOG) > 0) {
|
} if(BT.getAnalogButton(R2_ANALOG) > 0) {
|
||||||
Serial.print(F("R2: "));
|
Serial.print(F("R2: "));
|
||||||
Serial.print(BT.getAnalogButton(R2_ANALOG), DEC);
|
Serial.print(BT.getAnalogButton(R2_ANALOG));
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(BT.ButtonPressed)
|
if(BT.buttonPressed)
|
||||||
{
|
{
|
||||||
Serial.print(F("PS3 Controller"));
|
Serial.print(F("PS3 Controller"));
|
||||||
|
|
||||||
|
@ -109,19 +112,28 @@ void loop()
|
||||||
if(BT.getButton(SELECT)) {
|
if(BT.getButton(SELECT)) {
|
||||||
Serial.print(F(" - Select - "));
|
Serial.print(F(" - Select - "));
|
||||||
Serial.print(BT.getStatusString());
|
Serial.print(BT.getStatusString());
|
||||||
} if(BT.getButton(START))
|
} if(BT.getButton(START)) {
|
||||||
Serial.print(F(" - Start"));
|
Serial.print(F(" - Start"));
|
||||||
|
printAngle = !printAngle;
|
||||||
|
while(BT.getButton(START))
|
||||||
|
Usb.Task();
|
||||||
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(printAngle) {
|
||||||
|
Serial.print(F("Pitch: "));
|
||||||
|
Serial.print(BT.getAngle(Pitch));
|
||||||
|
Serial.print(F("\tRoll: "));
|
||||||
|
Serial.println(BT.getAngle(Roll));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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: "));
|
Serial.print(F("T: "));
|
||||||
Serial.println(BT.getAnalogButton(T_MOVE_ANALOG), DEC);
|
Serial.println(BT.getAnalogButton(T_MOVE_ANALOG));
|
||||||
} if(BT.ButtonPressed) {
|
} if(BT.buttonPressed) {
|
||||||
Serial.print(F("PS3 Move Controller"));
|
Serial.print(F("PS3 Move Controller"));
|
||||||
|
|
||||||
if(BT.getButton(PS_MOVE)) {
|
if(BT.getButton(PS_MOVE)) {
|
||||||
|
@ -130,10 +142,14 @@ void loop()
|
||||||
} else {
|
} else {
|
||||||
if(BT.getButton(SELECT_MOVE)) {
|
if(BT.getButton(SELECT_MOVE)) {
|
||||||
Serial.print(F(" - Select"));
|
Serial.print(F(" - Select"));
|
||||||
printTemperature = false;
|
printTemperature = !printTemperature;
|
||||||
|
while(BT.getButton(SELECT_MOVE))
|
||||||
|
Usb.Task();
|
||||||
} if(BT.getButton(START_MOVE)) {
|
} if(BT.getButton(START_MOVE)) {
|
||||||
Serial.print(F(" - Start"));
|
Serial.print(F(" - Start"));
|
||||||
printTemperature = true;
|
printAngle = !printAngle;
|
||||||
|
while(BT.getButton(START_MOVE))
|
||||||
|
Usb.Task();
|
||||||
} if(BT.getButton(TRIANGLE_MOVE)) {
|
} if(BT.getButton(TRIANGLE_MOVE)) {
|
||||||
Serial.print(F(" - Triangle"));
|
Serial.print(F(" - Triangle"));
|
||||||
BT.moveSetBulb(Red);
|
BT.moveSetBulb(Red);
|
||||||
|
@ -158,10 +174,16 @@ void loop()
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(printTemperature) {
|
if(printAngle) {
|
||||||
|
Serial.print(F("Pitch: "));
|
||||||
|
Serial.print(BT.getAngle(Pitch));
|
||||||
|
Serial.print(F("\tRoll: "));
|
||||||
|
Serial.println(BT.getAngle(Roll));
|
||||||
|
}
|
||||||
|
else if(printTemperature) {
|
||||||
String templow;
|
String templow;
|
||||||
String temphigh;
|
String temphigh;
|
||||||
String input = String(BT.getSensor(tempMove), DEC);
|
String input = String(BT.getSensor(tempMove));
|
||||||
|
|
||||||
if (input.length() > 3) {
|
if (input.length() > 3) {
|
||||||
temphigh = input.substring(0, 2);
|
temphigh = input.substring(0, 2);
|
||||||
|
|
|
@ -12,7 +12,7 @@ ADK adk(&Usb,"TKJElectronics", // Manufacturer Name
|
||||||
"http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.apk", // URL (web page to visit if no installed apps support the accessory)
|
"http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.apk", // URL (web page to visit if no installed apps support the accessory)
|
||||||
"123456789"); // Serial Number (optional)
|
"123456789"); // Serial Number (optional)
|
||||||
|
|
||||||
#define LED_RED 13 // Pin 13 is occupied by the SCK pin on a normal Arduino (Uno, Duemilanove etc.), so use a different pin
|
#define LED 13 // Pin 13 is occupied by the SCK pin on a normal Arduino (Uno, Duemilanove etc.), so use a different pin
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ void setup()
|
||||||
Serial.print("\r\nOSCOKIRQ failed to assert");
|
Serial.print("\r\nOSCOKIRQ failed to assert");
|
||||||
while(1); //halt
|
while(1); //halt
|
||||||
}
|
}
|
||||||
pinMode(LED_RED, OUTPUT);
|
pinMode(LED, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
@ -37,10 +37,9 @@ void loop()
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
Serial.print(F("\r\nData Packet: "));
|
Serial.print(F("\r\nData Packet: "));
|
||||||
Serial.print(msg[0]);
|
Serial.print(msg[0]);
|
||||||
digitalWrite(LED_RED,msg[0] ? HIGH : LOW);
|
digitalWrite(LED,msg[0] ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
digitalWrite(LED_RED, LOW);
|
digitalWrite(LED, LOW);
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,11 @@ moveSetRumble KEYWORD2
|
||||||
PS3BTConnected KEYWORD2
|
PS3BTConnected KEYWORD2
|
||||||
PS3MoveBTConnected KEYWORD2
|
PS3MoveBTConnected KEYWORD2
|
||||||
PS3NavigationBTConnected KEYWORD2
|
PS3NavigationBTConnected KEYWORD2
|
||||||
ButtonChanged KEYWORD2
|
buttonChanged KEYWORD2
|
||||||
ButtonPressed KEYWORD2
|
buttonPressed KEYWORD2
|
||||||
|
buttonReleased KEYWORD2
|
||||||
|
|
||||||
|
isWatingForConnection KEYWORD2
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
# Constants and enums (LITERAL1)
|
# Constants and enums (LITERAL1)
|
||||||
|
|
Loading…
Reference in a new issue