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
User.cpp
- Committer:
- shunsuke0427
- Date:
- 2021-05-07
- Revision:
- 19:812c3572622a
- Parent:
- 18:065d88f01f2b
File content as of revision 19:812c3572622a:
//PS3コンの値をSPIで送信 //最初に255を送る→L,RスティックのX,Yの値を送る #include "Utils.h" #include "USBHost.h" #include "hci.h" #include "ps3.h" #include "User.h" #include "mbed.h" #define waitTime 0.1 //#define serial int RSX,RSY,LSX,LSY,BSU,BSL; //これより下に関数外に書く要素を記入する #ifdef serial //Serial pc(USBTX, USBRX); #endif DigitalOut cs(p8); //PwmOut pin(p9); SPI mySPI(p5, p6, p7); //SPIHalfDuplex mySPI(p5, p6, p7); PwmOut led1(LED1); PwmOut led2(LED2); PwmOut led3(LED3); PwmOut led4(LED4); //DigitalOut myled(LED1); void UserLoopSetting() { // pc.printf("UserLoopSetting()\r\n"); //一度だけ行いたい初期設定をここに書く led1.period_ms(20); mySPI.format(8,3); mySPI.frequency(1000000); //mySPI.format(8,3); //mySPI.frequency(1000000); //mySPI.reply(0X00); //uint8_t reg[] = {0,1}; //printf("Setting...\n"); } 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; } //ここより下にプログラムを書く led3=LSX/256.0f; led4=LSY/256.0f; led1=RSX/256.0f; led2=RSY/256.0f; #ifdef serial printf("LSX:%d LSY:%d RSX:%d RSY:%d\r\n", LSX, LSY, RSX, RSY); #endif //led3=ButtonState & 0x0400; //L1の状態 //led4=ButtonState & 0x0200; //R1の状態 /* 0x0200 : L2 0x0400 : L1 0x0800 : L1 */ //値の取得はps3.hを参照 /*uint8_t first; uint8_t second; first = (uint8_t) ButtonState & 0XFF; second = (uint8_t) (ButtonState>>8) & 0XFF;*/ cs = 0; mySPI.write(255); mySPI.write(LSX*255/256); mySPI.write(LSY*255/256); mySPI.write(RSX*255/256); mySPI.write(RSY*255/256); //myled = 1; cs = 1; wait(waitTime); //myled = 0; }