BlueUSBをつかってみた

Dependencies:   FatFileSystem mbed

Fork of PS3_BlueUSB by Bart Janssens

Files at this revision

API Documentation at this revision

Comitter:
kikoaac
Date:
Wed Jun 17 09:48:19 2015 +0000
Parent:
0:99a111b75cb4
Commit message:
PS3?BlueTooth????????

Changed in this revision

AutoEvents.cpp Show annotated file Show diff for this revision Revisions of this file
FATFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Ps3USB.cpp Show annotated file Show diff for this revision Revisions of this file
TestShell.cpp Show annotated file Show diff for this revision Revisions of this file
hci.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/AutoEvents.cpp	Tue Apr 26 16:09:17 2011 +0000
+++ b/AutoEvents.cpp	Wed Jun 17 09:48:19 2015 +0000
@@ -258,7 +258,7 @@
 {
     printf("LoadDevice %d %02X:%02X:%02X\r\n",device,interfaceDesc->bInterfaceClass,interfaceDesc->bInterfaceSubClass,interfaceDesc->bInterfaceProtocol);
     char s[128];
-    u8 my_mac[6] = {0x00, 0x02, 0x72, 0xAD, 0xF3, 0x5B}; // mac address of my Bluetooth device
+    u8 my_mac[6] = {0x00,0x1b,0xdc,0x06,0xbf,0x40}; // mac address of my Bluetooth device
     
     u8 buf2[6];
     
@@ -308,4 +308,4 @@
             //StartAutoEvent(device,1,0);
             break;
     }
-}
\ No newline at end of file
+}
--- a/FATFileSystem.lib	Tue Apr 26 16:09:17 2011 +0000
+++ b/FATFileSystem.lib	Wed Jun 17 09:48:19 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_unsupported/code/fatfilesystem/
\ No newline at end of file
+http://mbed.org/users/mbed_unsupported/code/fatfilesystem/#333d6e93e58f
--- a/Ps3USB.cpp	Tue Apr 26 16:09:17 2011 +0000
+++ b/Ps3USB.cpp	Wed Jun 17 09:48:19 2015 +0000
@@ -116,7 +116,7 @@
         if (_count == 25) _count = 1;
         
         err = USBInterruptTransfer(_device,output_ep,ps3_data,sizeof(ps3_data),PS3EventCallback,this);
-        wait_ms(4);
+        wait_ms(0.1);
         
         return 0;
     
@@ -145,7 +145,7 @@
       
         //set Mac address    
         err = USBControlTransfer(_device, HOST_TO_DEVICE|REQUEST_TYPE_CLASS|RECIPIENT_INTERFACE, HID_REQUEST_SET_REPORT, 0x03f5, 0, buf, sizeof(buf), 0, 0 );
-        wait_ms(4);
+        wait_ms(0.1);
         printf("set Mac address to %02X:%02X:%02X:%02X:%02X:%02X , result = %d\r\n", buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], err);
 
         return 0;
@@ -158,7 +158,7 @@
         u8 buf[8];
         //get Mac address    
         err = USBControlTransfer(_device, DEVICE_TO_HOST|REQUEST_TYPE_CLASS|RECIPIENT_INTERFACE, HID_REQUEST_GET_REPORT, 0x03f5, 0, buf, sizeof(buf), 0, 0 );
-        wait_ms(4);
+        wait_ms(0.1);
         printf("Mac address is set to %02X:%02X:%02X:%02X:%02X:%02X , result = %d\r\n",buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], err);
 
         
@@ -175,7 +175,7 @@
         memcpy(buf, ledrumble, 48);
         
         err = USBControlTransfer(_device, HOST_TO_DEVICE|REQUEST_TYPE_CLASS|RECIPIENT_INTERFACE, HID_REQUEST_SET_REPORT, 0x0201,0, buf, sizeof(buf), 0, 0 );
-        wait_ms(4);
+        wait_ms(0.1);
       
         return 0;
     }
@@ -193,7 +193,7 @@
         buf[4] = power_left;
          
         err = USBControlTransfer(_device, HOST_TO_DEVICE|REQUEST_TYPE_CLASS|RECIPIENT_INTERFACE, HID_REQUEST_SET_REPORT, 0x0201,0, buf, sizeof(buf), 0, 0 );
-        wait_ms(4);
+        wait_ms(0.1);
         
         return 0;
     }
@@ -208,7 +208,7 @@
         
         ParsePs3Result(data, sizeof(ps3report),t->_count);
         USBInterruptTransfer(device, endpoint , data, len, PS3EventCallback, userData);
-        wait_ms(4);
+        wait_ms(0.1);
 
     }
     
@@ -241,3 +241,5 @@
     }
 
     
+
+
--- a/TestShell.cpp	Tue Apr 26 16:09:17 2011 +0000
+++ b/TestShell.cpp	Wed Jun 17 09:48:19 2015 +0000
@@ -35,6 +35,10 @@
 #include "ps3.h"
 
 #include "mbed.h"
+DigitalOut LEDa(LED1);
+PwmOut     LEDb(LED2);
+PwmOut     LEDc(LED3);
+Serial Dev(p13,p14);
 
 
 void printf(const BD_ADDR* addr)
@@ -60,6 +64,8 @@
         _aclBuffer = aclBuffer;
         USBInterruptTransfer(_device,0x81,_hciBuffer,MAX_HCL_SIZE,HciCallback,this);
         USBBulkTransfer(_device,0x82,_aclBuffer,MAX_ACL_SIZE,AclCallback,this);
+        //Dev.baud(115200);
+       
     }
 
     static void HciCallback(int device, int endpoint, int status, u8* data, int len, void* userData)
@@ -92,7 +98,7 @@
 
 #define WII_REMOTE 0x042500
 #define PS3_REMOTE 0x080500
-
+char DATA[30];
 class HIDBluetooth
 {
     int _control;   // Sockets for control (out) and interrupt (in)
@@ -105,7 +111,7 @@
     int _count;
     
 public:
-    HIDBluetooth() : _control(0),_interrupt(0),_devClass(0), _ready(1) {};
+    HIDBluetooth() : _control(0),_interrupt(0),_devClass(0), _ready(1) {Dev.baud(921600);};
     
 
     bool InUse()
@@ -159,9 +165,96 @@
              }
              if (t->_devClass == PS3_REMOTE)
              {   
+
+                u16 ButtonState =  ((ps3report*)(data + 1))->ButtonState;
+                u8 x = (ButtonState&0xff00)>>8, x1 = ButtonState & 0xff ; 
+                DATA[0] = x ; 
+                DATA[1] = x1;
+                DATA[2] = ((ps3report*)(data+1))->LeftStickX;
+                DATA[3] = ((ps3report*)(data+1))->LeftStickY;
+                DATA[4] = ((ps3report*)(data+1))->RightStickX;
+                DATA[5] = ((ps3report*)(data+1))->RightStickY;
+                DATA[6] = ((ps3report*)(data+1))->PressureUp;
+                DATA[7] = ((ps3report*)(data+1))->PressureRight;
+                DATA[8] = ((ps3report*)(data+1))->PressureDown;
+                DATA[9] = ((ps3report*)(data+1))->PressureLeft; 
+                DATA[10] = ((ps3report*)(data+1))->PressureL2;
+                DATA[11] = ((ps3report*)(data+1))->PressureR2;
+                DATA[12] = ((ps3report*)(data+1))->PressureL1;
+                DATA[13] = ((ps3report*)(data+1))->PressureR1;
+                DATA[14] = ((ps3report*)(data+1))->PressureTriangle; 
+                DATA[15] = ((ps3report*)(data+1))->PressureCircle;
+                DATA[16] = ((ps3report*)(data+1))->PressureCross;
+                DATA[17] = ((ps3report*)(data+1))->PressureSquare;
+                DATA[18] = ((ps3report*)(data+1))->PSButtonState;
+                DATA[19] = (((ps3report*)(data+1))->AccelX&0xff00)>>8; 
+                DATA[20] = ((ps3report*)(data+1))->AccelX & 0xff;                                     
+                DATA[21] = (((ps3report*)(data+1))->AccelY&0xff00)>>8;
+                DATA[22] = ((ps3report*)(data+1))->AccelY & 0xff;     
+                DATA[23] = (((ps3report*)(data+1))->AccelZ&0xff00)>>8;
+                DATA[24] = ((ps3report*)(data+1))->AccelZ & 0xff;
+                DATA[25] = (((ps3report*)(data+1))->GyroZ&0xff00)>>8;
+                DATA[26] = ((ps3report*)(data+1))->GyroZ & 0xff;
+                DATA[27] = ((ps3report*)(data+1))->Charge;     
+                DATA[28] = ((ps3report*)(data+1))->Power;
+                DATA[29] = ((ps3report*)(data+1))->Connection;                                 
+                //Dev.putc(0xff);
+                //wait(0.003);
+                for(int i = 0;i<6;i++)
+                {
+                    //if(i%2 == 1)
+                    wait(0.0003);
+                    Dev.putc(DATA[i]);
+                    printf(": %3d " , DATA[i]);
+                }
+                wait(0.001);
+                printf("\n");
+                char flag=0;
+                char Cis = ((ps3report*)(data+1))->RightStickY;
+                float cis = LEDb = (float)(Cis)/255;               
+                char Cross = ((ps3report*)(data+1))->RightStickX;
+                float cross = LEDc = (float)(Cross)/255;      
+                //printf("Cis , %f  , %f\n", cis,cross);  
+                /*if (Cis >= 180) flag=1;
+                else if (Cis <= 80) flag=2;
+                else if (Cross >= 180) flag=11;
+                else if (Cross <= 80) flag=12;
+                else if (((ps3report*)(data+1))->LeftStickX >= 180) flag=21;
+                else if (((ps3report*)(data+1))->LeftStickX <= 80) flag=22;
+                else if (((ps3report*)(data+1))->LeftStickY >= 180) flag=23;
+                else if (((ps3report*)(data+1))->LeftStickY <= 80) flag=24;
+                else if (x & 0x01) flag=3;
+                else if (x & 0x02) flag=4;
+                else if (x & 0x04) flag=5;
+                else if (x & 0x08) flag=6;
+                else if (x & 16) flag=7;
+                else if (x & 32) flag=8;
+                else if (x & 64) flag=9;
+                else if (x & 128) flag=10;
+                else if (x1 & 0x01) flag=13;
+                else if (x1 & 0x02) flag=14;
+                else if (x1 & 0x04) flag=15;
+                else if (x1 & 0x08) flag=16;
+                else if (x1 & 16) flag=17;
+                else if (x1 & 32) flag=18;
+                else if (x1 & 64) flag=19;
+                else if (x1 & 128) flag=20;          
+                Dev.putc(flag);*/
+                if(ButtonState & 0x0002) {  //L3
+                  //L3が押された時の処理
+                  LEDa=1;
+                } else {
+                  LEDa=0;
+                  //L3が離された時の処理
+                }
+                if(ButtonState & 0x0004) {  //R3
+                  //R3が押された時の処理
+                } else {
+                  //R3が離された時の処理
+                }
                 t->_count ++;
                 if (t->_count == 25) t->_count = 1;
-                ParsePs3Result((data + 1), sizeof(ps3report),t->_count);
+                //ParsePs3Result((data + 1), sizeof(ps3report),t->_count);
              }
              else {
                   printf("Not yet implemented \r\n");
@@ -308,7 +401,7 @@
 
         if (_control != -1)
         Socket_Send(_control,buf,37);
-        wait_ms(4);
+        wait_ms(0.1);
     }
     
     void Ps3Hid_Rumble(u8 duration_right, u8 power_right, u8 duration_left, u8 power_left  )
@@ -324,7 +417,7 @@
 
         if (_control != -1)
         Socket_Send(_control,buf,37);
-        wait_ms(4);
+        wait_ms(0.1);
     }
     
     int CheckHID()
--- a/hci.cpp	Tue Apr 26 16:09:17 2011 +0000
+++ b/hci.cpp	Wed Jun 17 09:48:19 2015 +0000
@@ -106,21 +106,26 @@
 int HCI::WriteScanEnable()
 {
    
-    u8 buf[2];
-    buf[0] = 0x03;
-    buf[1] = 0x01;    
-    
+//    u8 buf[2];
+//    buf[0] = 0x03;
+//    buf[1] = 0x01;    
+    u8 buf[1];
+    buf[0] = 0x03;    
     SendCmd(HCI_OP_WRITE_SCAN_ENABLE,buf,sizeof(buf));
     return 0;
 }
 
 int HCI::AcceptConnection(const BD_ADDR* addr)
 {
-    u8 buf[6+4];
+//    u8 buf[6+4];
+//    memset(buf,0,sizeof(buf));
+//    memcpy(buf,addr,6);
+//    buf[7] = 0;      
+    u8 buf[6+1];
     memset(buf,0,sizeof(buf));
     memcpy(buf,addr,6);
-    buf[7] = 0;      
-    
+    buf[6]=0;
+        
     SendCmd(HCI_OP_ACCEPT_CONN_REQ,buf,sizeof(buf));
     return 0;
 }
--- a/main.cpp	Tue Apr 26 16:09:17 2011 +0000
+++ b/main.cpp	Wed Jun 17 09:48:19 2015 +0000
@@ -21,10 +21,13 @@
 */
 
 #include "mbed.h"
+//#include "rtos.h"
+
 #include "USBHost.h"
 #include "Utils.h"
 #include "FATFileSystem.h"
 
+
 int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
 int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
 int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
@@ -110,12 +113,15 @@
     pc.putc(c); // echo
     return c;
 }
+   
+void TestShell();
 
-void TestShell();
 
 int main()
 {
-    pc.baud(9600);
+
+    pc.baud(230400);
     printf("BlueUSB\nNow get a bunch of usb or bluetooth things and plug them in\r\n");
     TestShell();
+
 }