yuto kawamura
/
F3RC_syudou_master
主導機 mbed用のプログラムです
Fork of F3RC_syudou_master by
User.cpp
- Committer:
- baba2357
- Date:
- 2016-02-15
- Revision:
- 10:bf0c0cdb487d
- Parent:
- 9:e5437ba3e920
- Child:
- 11:86d717718dbf
File content as of revision 10:bf0c0cdb487d:
#include "Utils.h" #include "USBHost.h" #include "hci.h" #include "ps3.h" #include "User.h" #include "mbed.h" int RSX,RSY,LSX,LSY,BSU,BSL; //これより下に関数外に書く要素を記入する PwmOut led1(LED1); PwmOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); DigitalOut LDB(p21); DigitalOut RDB(p22); SPI m(p5, p6, p7); DigitalOut cs(p8); void UserLoopSetting(){ //一度だけ行いたい初期設定をここに書く led1.period_ms(20); } void UserLoop(char n,const u8* data){ u16 ButtonState; if(n==0){//有線Ps3USB.cpp RSX = ((ps3report*)data)->RightStickX; RSY = ((ps3report*)data)->RightStickY; LSX = ((ps3report*)data)->LeftStickX; LSY = ((ps3report*)data)->LeftStickY; BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); BSL = (u8)(((ps3report*)data)->ButtonState >> 8); //ボタンの処理 ButtonState = ((ps3report*)data)->ButtonState; }else {//無線TestShell.cpp RSX = ((ps3report*)(data + 1))->RightStickX; RSY = ((ps3report*)(data + 1))->RightStickY; LSX = ((ps3report*)(data + 1))->LeftStickX; LSY = ((ps3report*)(data + 1))->LeftStickY; BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); //ボタンの処理 ButtonState = ((ps3report*)(data + 1))->ButtonState; } //ここより下にプログラムを書く //データ取得例 int M=0; m.format(16,3); m.frequency(1000000); cs=0; if((ButtonState >> BUTTONCIRCLE)&1) { //○が押されたとき } if((ButtonState >> BUTTONL2)&1){ LDB=1; } else if((ButtonState >> BUTTONR2)&1){ RDB=1; } else if((ButtonState >> BUTTONDOWN)&1){ RDB=1; LDB=1; } if((ButtonState >> BUTTONR1)&1){ M=+32768; } else if((ButtonState >> BUTTONL2)&1){ M=+16384; } if(LSX-128>=0){ M=+8192; M=+(LSX-128)*64; } else if(LSX-128<0){ M=+(-1)*((LSX-128)*64); } if(LSY-128>=0){ M=+64; M=+((LSY-128)/2); } else if(LSY-128<0){ M=+((-1)*(LSY-128)); } m.write(M); led1=LSX/256.0f; led2=LSY/256.0f; led3=ButtonState & 0x0400; //L1の状態 led4=ButtonState & 0x0800; //R1の状態 //値の取得はps3.hを参照 cs=1; }