Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of PS3_BlueUSB_user_ver_circlewar by
User.cpp
00001 00002 #include "Utils.h" 00003 #include "USBHost.h" 00004 #include "hci.h" 00005 #include "ps3.h" 00006 #include "User.h" 00007 #include "mbed.h" 00008 00009 int RSX,RSY,LSX,LSY,BSU,BSL; 00010 //これより下に関数外に書く要素を記入する 00011 PwmOut led1(LED1); 00012 PwmOut led2(LED2); 00013 DigitalOut led3(LED3); 00014 DigitalOut led4(LED4); 00015 DigitalOut hand(p21); 00016 SPI m(p5, p6, p7); 00017 DigitalOut cs(p8); 00018 void UserLoopSetting() 00019 { 00020 //一度だけ行いたい初期設定をここに書く 00021 led1.period_ms(20); 00022 } 00023 00024 void UserLoop(char n,const u8* data) 00025 { 00026 u16 ButtonState; 00027 if(n==0) { //有線Ps3USB.cpp 00028 RSX = ((ps3report*)data)->RightStickX; 00029 RSY = ((ps3report*)data)->RightStickY; 00030 LSX = ((ps3report*)data)->LeftStickX; 00031 LSY = ((ps3report*)data)->LeftStickY; 00032 BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); 00033 BSL = (u8)(((ps3report*)data)->ButtonState >> 8); 00034 //ボタンの処理 00035 ButtonState = ((ps3report*)data)->ButtonState; 00036 } else {//無線TestShell.cpp 00037 RSX = ((ps3report*)(data + 1))->RightStickX; 00038 RSY = ((ps3report*)(data + 1))->RightStickY; 00039 LSX = ((ps3report*)(data + 1))->LeftStickX; 00040 LSY = ((ps3report*)(data + 1))->LeftStickY; 00041 BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); 00042 BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); 00043 //ボタンの処理 00044 ButtonState = ((ps3report*)(data + 1))->ButtonState; 00045 } 00046 //ここより下にプログラムを書く 00047 //データ取得例 00048 int M=0; 00049 bool H=0; 00050 m.format(16,3); 00051 m.frequency(1000000); 00052 cs=0; 00053 if((ButtonState >> BUTTONCIRCLE)&1) { 00054 //○が押されたとき 00055 H=!H; 00056 hand=H; 00057 } 00058 //以下の整数MをSPIで送る 00059 //整数Mを16桁の二進数とする。 00060 //桁数| 16 | 15 | 14 |13|12|11|10|9|8| 7 |6|5|4|3|2|1| 00061 //指示|右旋回 |左旋回 |Xの+or-| 出力0~63 |Yの+orー| 出力0~63 | 00062 if((ButtonState >> BUTTONR1)&1) { 00063 M=1; 00064 M=M<<15; 00065 } else if((ButtonState >> BUTTONL1)&1) { 00066 M=1; 00067 M=M<<14; 00068 } else { 00069 if(LSX-127>0) { 00070 M=1; 00071 M=M<<6; 00072 M+=(LSX-127)/2; 00073 M=M<<7; 00074 } else if(LSX-127<0) { 00075 M+=(-1)*((LSX-128)/2); 00076 if(M==64) M=63; 00077 M=M<<7; 00078 } 00079 if(LSY-127>0) { 00080 M+=1<<6; 00081 M+=(LSY-128)/2; 00082 } else if(LSY-127<0) { 00083 M+=((-1)*(LSY-128)/2); 00084 if(M==64) M=63; 00085 } else M=0; 00086 } 00087 m.write(0xffff); 00088 // m.write(M); 00089 printf("0x%x\r\n",M); 00090 00091 led1=LSX/256.0f; 00092 led2=LSY/256.0f; 00093 led3=ButtonState & 0x0400; //L1の状態 00094 led4=ButtonState & 0x0800; //R1の状態 00095 //値の取得はps3.hを参照 00096 cs=1; 00097 }
Generated on Wed Jul 13 2022 20:21:37 by
