主導機 mbed用のプログラムです

Dependencies:   mbed

Fork of F3RC_syudou_master by F3RC1班

Committer:
baba2357
Date:
Mon Feb 15 02:19:02 2016 +0000
Revision:
10:bf0c0cdb487d
Parent:
9:e5437ba3e920
Child:
11:86d717718dbf
; fuc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hirokimineshita 0:736c76a75def 1 #include "Utils.h"
hirokimineshita 0:736c76a75def 2 #include "USBHost.h"
hirokimineshita 0:736c76a75def 3 #include "hci.h"
hirokimineshita 0:736c76a75def 4 #include "ps3.h"
hirokimineshita 0:736c76a75def 5 #include "User.h"
hirokimineshita 0:736c76a75def 6
hirokimineshita 0:736c76a75def 7 #include "mbed.h"
hirokimineshita 0:736c76a75def 8
hirokimineshita 0:736c76a75def 9 int RSX,RSY,LSX,LSY,BSU,BSL;
hirokimineshita 9:e5437ba3e920 10 //これより下に関数外に書く要素を記入する
hirokimineshita 0:736c76a75def 11 PwmOut led1(LED1);
hirokimineshita 0:736c76a75def 12 PwmOut led2(LED2);
hirokimineshita 0:736c76a75def 13 DigitalOut led3(LED3);
hirokimineshita 0:736c76a75def 14 DigitalOut led4(LED4);
baba2357 10:bf0c0cdb487d 15 DigitalOut LDB(p21);
baba2357 10:bf0c0cdb487d 16 DigitalOut RDB(p22);
baba2357 10:bf0c0cdb487d 17 SPI m(p5, p6, p7);
baba2357 10:bf0c0cdb487d 18 DigitalOut cs(p8);
hirokimineshita 0:736c76a75def 19 void UserLoopSetting(){
hirokimineshita 0:736c76a75def 20 //一度だけ行いたい初期設定をここに書く
hirokimineshita 0:736c76a75def 21 led1.period_ms(20);
hirokimineshita 0:736c76a75def 22 }
hirokimineshita 0:736c76a75def 23
hirokimineshita 0:736c76a75def 24 void UserLoop(char n,const u8* data){
hirokimineshita 0:736c76a75def 25 u16 ButtonState;
hirokimineshita 0:736c76a75def 26 if(n==0){//有線Ps3USB.cpp
hirokimineshita 0:736c76a75def 27 RSX = ((ps3report*)data)->RightStickX;
hirokimineshita 0:736c76a75def 28 RSY = ((ps3report*)data)->RightStickY;
hirokimineshita 0:736c76a75def 29 LSX = ((ps3report*)data)->LeftStickX;
hirokimineshita 0:736c76a75def 30 LSY = ((ps3report*)data)->LeftStickY;
hirokimineshita 0:736c76a75def 31 BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff);
hirokimineshita 0:736c76a75def 32 BSL = (u8)(((ps3report*)data)->ButtonState >> 8);
hirokimineshita 0:736c76a75def 33 //ボタンの処理
hirokimineshita 0:736c76a75def 34 ButtonState = ((ps3report*)data)->ButtonState;
hirokimineshita 0:736c76a75def 35 }else {//無線TestShell.cpp
hirokimineshita 0:736c76a75def 36 RSX = ((ps3report*)(data + 1))->RightStickX;
hirokimineshita 0:736c76a75def 37 RSY = ((ps3report*)(data + 1))->RightStickY;
hirokimineshita 0:736c76a75def 38 LSX = ((ps3report*)(data + 1))->LeftStickX;
hirokimineshita 0:736c76a75def 39 LSY = ((ps3report*)(data + 1))->LeftStickY;
hirokimineshita 0:736c76a75def 40 BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff);
hirokimineshita 0:736c76a75def 41 BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8);
hirokimineshita 0:736c76a75def 42 //ボタンの処理
hirokimineshita 0:736c76a75def 43 ButtonState = ((ps3report*)(data + 1))->ButtonState;
hirokimineshita 0:736c76a75def 44 }
hirokimineshita 0:736c76a75def 45 //ここより下にプログラムを書く
hirokimineshita 0:736c76a75def 46 //データ取得例
baba2357 10:bf0c0cdb487d 47 int M=0;
baba2357 10:bf0c0cdb487d 48 m.format(16,3);
baba2357 10:bf0c0cdb487d 49 m.frequency(1000000);
baba2357 10:bf0c0cdb487d 50 cs=0;
hirokimineshita 0:736c76a75def 51 if((ButtonState >> BUTTONCIRCLE)&1) {
hirokimineshita 0:736c76a75def 52 //○が押されたとき
hirokimineshita 0:736c76a75def 53 }
baba2357 10:bf0c0cdb487d 54 if((ButtonState >> BUTTONL2)&1){
baba2357 10:bf0c0cdb487d 55 LDB=1;
baba2357 10:bf0c0cdb487d 56 }
baba2357 10:bf0c0cdb487d 57 else if((ButtonState >> BUTTONR2)&1){
baba2357 10:bf0c0cdb487d 58 RDB=1;
baba2357 10:bf0c0cdb487d 59 }
baba2357 10:bf0c0cdb487d 60 else if((ButtonState >> BUTTONDOWN)&1){
baba2357 10:bf0c0cdb487d 61 RDB=1;
baba2357 10:bf0c0cdb487d 62 LDB=1;
baba2357 10:bf0c0cdb487d 63 }
baba2357 10:bf0c0cdb487d 64 if((ButtonState >> BUTTONR1)&1){
baba2357 10:bf0c0cdb487d 65 M=+32768;
baba2357 10:bf0c0cdb487d 66 }
baba2357 10:bf0c0cdb487d 67 else if((ButtonState >> BUTTONL2)&1){
baba2357 10:bf0c0cdb487d 68 M=+16384;
baba2357 10:bf0c0cdb487d 69 }
baba2357 10:bf0c0cdb487d 70 if(LSX-128>=0){
baba2357 10:bf0c0cdb487d 71 M=+8192;
baba2357 10:bf0c0cdb487d 72 M=+(LSX-128)*64;
baba2357 10:bf0c0cdb487d 73 }
baba2357 10:bf0c0cdb487d 74 else if(LSX-128<0){
baba2357 10:bf0c0cdb487d 75 M=+(-1)*((LSX-128)*64);
baba2357 10:bf0c0cdb487d 76 }
baba2357 10:bf0c0cdb487d 77 if(LSY-128>=0){
baba2357 10:bf0c0cdb487d 78 M=+64;
baba2357 10:bf0c0cdb487d 79 M=+((LSY-128)/2);
baba2357 10:bf0c0cdb487d 80 }
baba2357 10:bf0c0cdb487d 81 else if(LSY-128<0){
baba2357 10:bf0c0cdb487d 82 M=+((-1)*(LSY-128));
baba2357 10:bf0c0cdb487d 83 }
baba2357 10:bf0c0cdb487d 84 m.write(M);
baba2357 10:bf0c0cdb487d 85
hirokimineshita 0:736c76a75def 86 led1=LSX/256.0f;
hirokimineshita 0:736c76a75def 87 led2=LSY/256.0f;
hirokimineshita 0:736c76a75def 88 led3=ButtonState & 0x0400; //L1の状態
hirokimineshita 0:736c76a75def 89 led4=ButtonState & 0x0800; //R1の状態
hirokimineshita 0:736c76a75def 90 //値の取得はps3.hを参照
baba2357 10:bf0c0cdb487d 91 cs=1;
hirokimineshita 0:736c76a75def 92 }