Several minor changes

This commit is contained in:
Kristian Lauszus 2012-08-04 19:46:32 +02:00
parent 234685359b
commit a093e777d3
7 changed files with 33 additions and 89 deletions

49
BTD.cpp
View file

@ -108,8 +108,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
// Assign new address to the device // Assign new address to the device
rcode = pUsb->setAddr( 0, 0, bAddress ); rcode = pUsb->setAddr( 0, 0, bAddress );
if (rcode) if (rcode) {
{
p->lowspeed = false; p->lowspeed = false;
addrPool.FreeAddress(bAddress); addrPool.FreeAddress(bAddress);
bAddress = 0; bAddress = 0;
@ -140,44 +139,18 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct; PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct;
if(VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) { if(VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) {
/* The application will work in reduced host mode, so we can save program and data /* We only need the Control endpoint, so we don't have to initialize the other endpoints of device */
memory space. After verifying the PID and VID we will use known values for the
configuration values for device, interface, endpoints and HID for the PS3 Controllers */
/* Initialize data structures for endpoints of device */
epInfo[ PS3_OUTPUT_PIPE ].epAddr = 0x02; // PS3 output endpoint
epInfo[ PS3_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT;
epInfo[ PS3_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
epInfo[ PS3_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
epInfo[ PS3_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0;
epInfo[ PS3_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
epInfo[ PS3_INPUT_PIPE ].epAddr = 0x01; // PS3 report endpoint
epInfo[ PS3_INPUT_PIPE ].epAttribs = EP_INTERRUPT;
epInfo[ PS3_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
epInfo[ PS3_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE;
epInfo[ PS3_INPUT_PIPE ].bmSndToggle = bmSNDTOG0;
epInfo[ PS3_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0;
rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
if( rcode )
goto FailSetDevTblEntry;
delay(200);//Give time for address change
rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1);
if( rcode ) if( rcode )
goto FailSetConf; goto FailSetConf;
if(PID == PS3_PID || PID == PS3NAVIGATION_PID) { if(PID == PS3_PID || PID == PS3NAVIGATION_PID) {
if(PID == PS3_PID) {
#ifdef DEBUG #ifdef DEBUG
if(PID == PS3_PID)
Notify(PSTR("\r\nDualshock 3 Controller Connected")); Notify(PSTR("\r\nDualshock 3 Controller Connected"));
#endif else // must be a navigation controller
} else { // must be a navigation controller
#ifdef DEBUG
Notify(PSTR("\r\nNavigation Controller Connected")); Notify(PSTR("\r\nNavigation Controller Connected"));
#endif #endif
}
/* Set internal bluetooth address */ /* Set internal bluetooth address */
setBdaddr(my_bdaddr); setBdaddr(my_bdaddr);
} }
@ -241,7 +214,7 @@ FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\nsetDevTblEn")); Notify(PSTR("\r\nsetDevTblEn"));
#endif #endif
goto Fail; goto Fail;
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG
Notify(PSTR("\r\ngetConf")); Notify(PSTR("\r\ngetConf"));
@ -807,11 +780,11 @@ void BTD::hci_disconnect(uint16_t handle) { // This is called by the different s
/************************************************************/ /************************************************************/
void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) { void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t channelLow, uint8_t channelHigh) {
uint8_t buf[256]; uint8_t buf[256];
buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag buf[0] = (uint8_t)(handle & 0xff); // HCI handle with PB,BC flag
buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20); buf[1] = (uint8_t)(((handle >> 8) & 0x0f) | 0x20);
buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length buf[2] = (uint8_t)((4 + nbytes) & 0xff); // HCI ACL total data length
buf[3] = (uint8_t)((4 + nbytes) >> 8); buf[3] = (uint8_t)((4 + nbytes) >> 8);
buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length buf[4] = (uint8_t)(nbytes & 0xff); // L2CAP header: Length
buf[5] = (uint8_t)(nbytes >> 8); buf[5] = (uint8_t)(nbytes >> 8);
buf[6] = channelLow; buf[6] = channelLow;
buf[7] = channelHigh; buf[7] = channelHigh;
@ -920,8 +893,7 @@ void BTD::l2cap_information_response(uint16_t handle, uint8_t rxid, uint8_t info
} }
/* PS3 Commands - only set Bluetooth address is implemented */ /* PS3 Commands - only set Bluetooth address is implemented */
void BTD::setBdaddr(uint8_t* BDADDR) void BTD::setBdaddr(uint8_t* BDADDR) {
{
/* Set the internal bluetooth address */ /* Set the internal bluetooth address */
uint8_t buf[8]; uint8_t buf[8];
buf[0] = 0x01; buf[0] = 0x01;
@ -942,8 +914,7 @@ void BTD::setBdaddr(uint8_t* BDADDR)
#endif #endif
return; return;
} }
void BTD::setMoveBdaddr(uint8_t* BDADDR) void BTD::setMoveBdaddr(uint8_t* BDADDR) {
{
/* Set the internal bluetooth address */ /* Set the internal bluetooth address */
uint8_t buf[11]; uint8_t buf[11];
buf[0] = 0x05; buf[0] = 0x05;

17
BTD.h
View file

@ -18,17 +18,6 @@
#ifndef _btd_h_ #ifndef _btd_h_
#define _btd_h_ #define _btd_h_
#define PS3_CONTROL_PIPE 0
#define PS3_OUTPUT_PIPE 1
#define PS3_INPUT_PIPE 2
#define PS3_CONTROL_PIPE 0
#define PS3_OUTPUT_PIPE 1
#define PS3_INPUT_PIPE 2
#define EP_INTERRUPT 0x03
#define EP_MAXPKTSIZE 64 // max size for data via USB
#include "Usb.h" #include "Usb.h"
#include "confdescparser.h" #include "confdescparser.h"
@ -127,7 +116,7 @@ class BluetoothService { // All services should include this class
public: public:
virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services
virtual void Poll(); // Used to run the different state machines virtual void Poll(); // Used to run the different state machines
virtual void Release(); // Used to disconnect both the L2CAP Channel and the HCI Connection virtual void Release(); // Used to reset the services
virtual void disconnect(); // Used to disconnect both the L2CAP Channel and the HCI Connection virtual void disconnect(); // Used to disconnect both the L2CAP Channel and the HCI Connection
}; };
@ -150,7 +139,7 @@ public:
for (uint8_t i=0; i<BTD_NUMDEVICES; i++) for (uint8_t i=0; i<BTD_NUMDEVICES; i++)
if (btService[i]) if (btService[i])
btService[i]->disconnect(); // Disconnect both the L2CAP Channel and the HCI Connection btService[i]->disconnect(); // Disconnect both the L2CAP Channel and the HCI Connection
}; };
/* Register bluetooth dongle members/services */ /* Register bluetooth dongle members/services */
uint8_t registerServiceClass(BluetoothService *pService) { uint8_t registerServiceClass(BluetoothService *pService) {
@ -220,7 +209,7 @@ private:
BluetoothService* btService[BTD_NUMDEVICES]; BluetoothService* btService[BTD_NUMDEVICES];
bool bPollEnable; bool bPollEnable;
uint8_t pollInterval; uint8_t pollInterval;
/* 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

View file

@ -60,8 +60,7 @@ pBtd(p) // pointer to USB class instance - mandatory
Release(); Release();
} }
bool PS3BT::getButton(Button b) bool PS3BT::getButton(Button b) {
{
if (l2capinpointer == NULL) if (l2capinpointer == NULL)
return false; return false;
if(PS3MoveConnected) { if(PS3MoveConnected) {
@ -76,20 +75,17 @@ bool PS3BT::getButton(Button b)
return false; return false;
} }
} }
uint8_t PS3BT::getAnalogButton(AnalogButton a) uint8_t PS3BT::getAnalogButton(AnalogButton a) {
{
if (l2capinpointer == NULL) if (l2capinpointer == NULL)
return 0; return 0;
return (uint8_t)(l2capinpointer[(uint16_t)a]); return (uint8_t)(l2capinpointer[(uint16_t)a]);
} }
uint8_t PS3BT::getAnalogHat(AnalogHat a) uint8_t PS3BT::getAnalogHat(AnalogHat a) {
{
if (l2capinpointer == NULL) if (l2capinpointer == NULL)
return 0; return 0;
return (uint8_t)(l2capinpointer[(uint16_t)a]); return (uint8_t)(l2capinpointer[(uint16_t)a]);
} }
int16_t PS3BT::getSensor(Sensor a) int16_t PS3BT::getSensor(Sensor a) {
{
if (l2capinpointer == NULL) if (l2capinpointer == NULL)
return 0; return 0;
if (a == aX || a == aY || a == aZ || a == gZ) if (a == aX || a == aY || a == aZ || a == gZ)
@ -157,18 +153,15 @@ String PS3BT::getTemperature() {
return output; return output;
} }
} }
bool PS3BT::getStatus(Status c) bool PS3BT::getStatus(Status c) {
{
if (l2capinpointer == NULL) if (l2capinpointer == NULL)
return false; return false;
if (l2capinpointer[(uint16_t)c >> 8] == ((uint8_t)c & 0xff)) if (l2capinpointer[(uint16_t)c >> 8] == ((uint8_t)c & 0xff))
return true; return true;
return false; return false;
} }
String PS3BT::getStatusString() String PS3BT::getStatusString() {
{ if (PS3Connected || PS3NavigationConnected) {
if (PS3Connected || PS3NavigationConnected)
{
char statusOutput[100]; char statusOutput[100];
strcpy(statusOutput,"ConnectionStatus: "); strcpy(statusOutput,"ConnectionStatus: ");
@ -199,8 +192,7 @@ String PS3BT::getStatusString()
return statusOutput; return statusOutput;
} }
else if(PS3MoveConnected) else if(PS3MoveConnected) {
{
char statusOutput[50]; char statusOutput[50];
strcpy(statusOutput,"PowerRating: "); strcpy(statusOutput,"PowerRating: ");
@ -371,8 +363,7 @@ void PS3BT::ACLData(uint8_t* l2capinbuf) {
//Serial.print("\r\nL2CAP Interrupt"); //Serial.print("\r\nL2CAP Interrupt");
if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) { if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) {
/* Read Report */ /* Read Report */
if(l2capinbuf[8] == 0xA1) // HID_THDR_DATA_INPUT if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT
{
if(PS3Connected || PS3NavigationConnected) if(PS3Connected || PS3NavigationConnected)
ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16)); ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16));
else if(PS3MoveConnected) else if(PS3MoveConnected)
@ -381,8 +372,7 @@ void PS3BT::ACLData(uint8_t* l2capinbuf) {
//Notify(PSTR("\r\nButtonState"); //Notify(PSTR("\r\nButtonState");
//PrintHex<uint32_t>(ButtonState); //PrintHex<uint32_t>(ButtonState);
if(ButtonState != OldButtonState) if(ButtonState != OldButtonState) {
{
buttonChanged = true; buttonChanged = true;
if(ButtonState != 0x00) { if(ButtonState != 0x00) {
buttonPressed = true; buttonPressed = true;
@ -391,16 +381,13 @@ void PS3BT::ACLData(uint8_t* l2capinbuf) {
buttonPressed = false; buttonPressed = false;
buttonReleased = true; buttonReleased = true;
} }
} }
else {
else
{
buttonChanged = false; buttonChanged = false;
buttonPressed = false; buttonPressed = false;
buttonReleased = false; buttonReleased = false;
} }
OldButtonState = ButtonState;
OldButtonState = ButtonState;
} }
#ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers #ifdef PRINTREPORT // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers
if(l2capinbuf[8] == 0xA1) { //HID_THDR_DATA_INPUT if(l2capinbuf[8] == 0xA1) { //HID_THDR_DATA_INPUT
@ -532,10 +519,8 @@ void PS3BT::Poll() {
break; break;
case L2CAP_EV_DONE: case L2CAP_EV_DONE:
if (PS3MoveConnected)//The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on if (PS3MoveConnected) { //The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on
{ if (millis() - timerBulbRumble > 4000) { //Send at least every 4th second
if (millis() - timerBulbRumble > 4000)//Send at least every 4th second
{
HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);//The Bulb and rumble values, has to be written again and again, for it to stay turned on HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE);//The Bulb and rumble values, has to be written again and again, for it to stay turned on
timerBulbRumble = millis(); timerBulbRumble = millis();
} }

View file

@ -220,7 +220,7 @@ public:
// BluetoothService implementation // BluetoothService implementation
virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services
virtual void Poll(); // Used to run the state maschine virtual void Poll(); // Used to run the state maschine
virtual void Release(); virtual void Release(); // Use this to reset the service
virtual void disconnect(); // Use this void to disconnect any of the controllers virtual void disconnect(); // Use this void to disconnect any of the controllers
/* PS3 Controller Commands */ /* PS3 Controller Commands */

View file

@ -66,8 +66,7 @@ void SPP::Release() {
SDPConnected = false; SDPConnected = false;
l2cap_sdp_state = L2CAP_SDP_WAIT; l2cap_sdp_state = L2CAP_SDP_WAIT;
l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT; l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT;
l2cap_event_flag = 0; l2cap_event_flag = 0;
} }
void SPP::disconnect(){ void SPP::disconnect(){
connected = false; connected = false;

2
SPP.h
View file

@ -100,7 +100,7 @@ public:
// BluetoothService implementation // BluetoothService implementation
virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services virtual void ACLData(uint8_t* ACLData); // Used to pass acldata to the services
virtual void Poll(); // Used to run SDP_task() and RFCOMM_task() virtual void Poll(); // Used to run SDP_task() and RFCOMM_task()
virtual void Release(); virtual void Release(); // Use this to reset the service
virtual void disconnect(); // Used this void to disconnect the virtual serial port virtual void disconnect(); // Used this void to disconnect the virtual serial port
bool connected;// Variable used to indicate if the connection is established bool connected;// Variable used to indicate if the connection is established

View file

@ -41,7 +41,7 @@ buttonChanged KEYWORD2
buttonPressed KEYWORD2 buttonPressed KEYWORD2
buttonReleased KEYWORD2 buttonReleased KEYWORD2
isWatingForConnection KEYWORD2 watingForConnection KEYWORD2
#################################################### ####################################################
# Constants and enums (LITERAL1) # Constants and enums (LITERAL1)