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_circlewarA by
User.cpp@19:71f64ff1b86f, 2016-03-30 (annotated)
- Committer:
- baba2357
- Date:
- Wed Mar 30 05:09:54 2016 +0000
- Revision:
- 19:71f64ff1b86f
- Parent:
- 13:0d6ad1fb03b5
- Child:
- 20:18ae99ad72f7
A?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
baba2357 | 11:8288386dc376 | 1 | |
hirokimineshita | 0:736c76a75def | 2 | #include "Utils.h" |
hirokimineshita | 0:736c76a75def | 3 | #include "USBHost.h" |
hirokimineshita | 0:736c76a75def | 4 | #include "hci.h" |
hirokimineshita | 0:736c76a75def | 5 | #include "ps3.h" |
hirokimineshita | 0:736c76a75def | 6 | #include "User.h" |
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 | 13:0d6ad1fb03b5 | 15 | DigitalOut hand(p21); |
baba2357 | 10:bf0c0cdb487d | 16 | SPI m(p5, p6, p7); |
baba2357 | 10:bf0c0cdb487d | 17 | DigitalOut cs(p8); |
baba2357 | 13:0d6ad1fb03b5 | 18 | void UserLoopSetting() |
baba2357 | 13:0d6ad1fb03b5 | 19 | { |
hirokimineshita | 0:736c76a75def | 20 | //一度だけ行いたい初期設定をここに書く |
hirokimineshita | 0:736c76a75def | 21 | led1.period_ms(20); |
hirokimineshita | 0:736c76a75def | 22 | } |
hirokimineshita | 0:736c76a75def | 23 | |
baba2357 | 13:0d6ad1fb03b5 | 24 | void UserLoop(char n,const u8* data) |
baba2357 | 13:0d6ad1fb03b5 | 25 | { |
hirokimineshita | 0:736c76a75def | 26 | u16 ButtonState; |
baba2357 | 13:0d6ad1fb03b5 | 27 | if(n==0) { //有線Ps3USB.cpp |
hirokimineshita | 0:736c76a75def | 28 | RSX = ((ps3report*)data)->RightStickX; |
hirokimineshita | 0:736c76a75def | 29 | RSY = ((ps3report*)data)->RightStickY; |
hirokimineshita | 0:736c76a75def | 30 | LSX = ((ps3report*)data)->LeftStickX; |
hirokimineshita | 0:736c76a75def | 31 | LSY = ((ps3report*)data)->LeftStickY; |
hirokimineshita | 0:736c76a75def | 32 | BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 33 | BSL = (u8)(((ps3report*)data)->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 34 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 35 | ButtonState = ((ps3report*)data)->ButtonState; |
baba2357 | 13:0d6ad1fb03b5 | 36 | } else {//無線TestShell.cpp |
hirokimineshita | 0:736c76a75def | 37 | RSX = ((ps3report*)(data + 1))->RightStickX; |
hirokimineshita | 0:736c76a75def | 38 | RSY = ((ps3report*)(data + 1))->RightStickY; |
hirokimineshita | 0:736c76a75def | 39 | LSX = ((ps3report*)(data + 1))->LeftStickX; |
hirokimineshita | 0:736c76a75def | 40 | LSY = ((ps3report*)(data + 1))->LeftStickY; |
hirokimineshita | 0:736c76a75def | 41 | BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 42 | BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 43 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 44 | ButtonState = ((ps3report*)(data + 1))->ButtonState; |
hirokimineshita | 0:736c76a75def | 45 | } |
hirokimineshita | 0:736c76a75def | 46 | //ここより下にプログラムを書く |
hirokimineshita | 0:736c76a75def | 47 | //データ取得例 |
baba2357 | 10:bf0c0cdb487d | 48 | int M=0; |
baba2357 | 13:0d6ad1fb03b5 | 49 | bool H=0; |
baba2357 | 10:bf0c0cdb487d | 50 | m.format(16,3); |
baba2357 | 10:bf0c0cdb487d | 51 | m.frequency(1000000); |
baba2357 | 10:bf0c0cdb487d | 52 | cs=0; |
hirokimineshita | 0:736c76a75def | 53 | if((ButtonState >> BUTTONCIRCLE)&1) { |
hirokimineshita | 0:736c76a75def | 54 | //○が押されたとき |
baba2357 | 13:0d6ad1fb03b5 | 55 | H=!H; |
baba2357 | 13:0d6ad1fb03b5 | 56 | hand=H; |
hirokimineshita | 0:736c76a75def | 57 | } |
baba2357 | 13:0d6ad1fb03b5 | 58 | //以下の整数MをSPIで送る |
baba2357 | 13:0d6ad1fb03b5 | 59 | //整数Mを16桁の二進数とする。 |
baba2357 | 13:0d6ad1fb03b5 | 60 | //桁数| 16 | 15 | 14 |13|12|11|10|9|8| 7 |6|5|4|3|2|1| |
baba2357 | 13:0d6ad1fb03b5 | 61 | //指示|右旋回 |左旋回 |Xの+or-| 出力0~63 |Yの+orー| 出力0~63 | |
baba2357 | 13:0d6ad1fb03b5 | 62 | if((ButtonState >> BUTTONR1)&1) { |
baba2357 | 13:0d6ad1fb03b5 | 63 | M=1; |
baba2357 | 13:0d6ad1fb03b5 | 64 | M=M<<15; |
baba2357 | 19:71f64ff1b86f | 65 | } else if((ButtonState >> BUTTONL1)&1) { |
baba2357 | 13:0d6ad1fb03b5 | 66 | M=1; |
baba2357 | 13:0d6ad1fb03b5 | 67 | M=M<<14; |
baba2357 | 13:0d6ad1fb03b5 | 68 | } else { |
baba2357 | 19:71f64ff1b86f | 69 | if(LSX-127>0) { |
baba2357 | 13:0d6ad1fb03b5 | 70 | M=1; |
baba2357 | 13:0d6ad1fb03b5 | 71 | M=M<<6; |
baba2357 | 19:71f64ff1b86f | 72 | M+=(LSX-127)/2; |
baba2357 | 13:0d6ad1fb03b5 | 73 | M=M<<7; |
baba2357 | 19:71f64ff1b86f | 74 | } else if(LSX-127<0) { |
baba2357 | 13:0d6ad1fb03b5 | 75 | M+=(-1)*((LSX-128)/2); |
baba2357 | 13:0d6ad1fb03b5 | 76 | if(M==64) M=63; |
baba2357 | 13:0d6ad1fb03b5 | 77 | M=M<<7; |
baba2357 | 10:bf0c0cdb487d | 78 | } |
baba2357 | 19:71f64ff1b86f | 79 | if(LSY-127>0) { |
baba2357 | 13:0d6ad1fb03b5 | 80 | M+=1<<6; |
baba2357 | 13:0d6ad1fb03b5 | 81 | M+=(LSY-128)/2; |
baba2357 | 19:71f64ff1b86f | 82 | } else if(LSY-127<0) { |
baba2357 | 13:0d6ad1fb03b5 | 83 | M+=((-1)*(LSY-128)/2); |
baba2357 | 13:0d6ad1fb03b5 | 84 | if(M==64) M=63; |
baba2357 | 13:0d6ad1fb03b5 | 85 | } else M=0; |
baba2357 | 13:0d6ad1fb03b5 | 86 | } |
baba2357 | 13:0d6ad1fb03b5 | 87 | m.write(0xffff); |
baba2357 | 13:0d6ad1fb03b5 | 88 | // m.write(M); |
baba2357 | 13:0d6ad1fb03b5 | 89 | printf("0x%x\r\n",M); |
baba2357 | 13:0d6ad1fb03b5 | 90 | |
hirokimineshita | 0:736c76a75def | 91 | led1=LSX/256.0f; |
hirokimineshita | 0:736c76a75def | 92 | led2=LSY/256.0f; |
hirokimineshita | 0:736c76a75def | 93 | led3=ButtonState & 0x0400; //L1の状態 |
hirokimineshita | 0:736c76a75def | 94 | led4=ButtonState & 0x0800; //R1の状態 |
hirokimineshita | 0:736c76a75def | 95 | //値の取得はps3.hを参照 |
baba2357 | 13:0d6ad1fb03b5 | 96 | cs=1; |
hirokimineshita | 0:736c76a75def | 97 | } |