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