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@21:34b11624c5a0, 2016-04-03 (annotated)
- Committer:
- baba2357
- Date:
- Sun Apr 03 18:21:41 2016 +0000
- Revision:
- 21:34b11624c5a0
- Parent:
- 20:18ae99ad72f7
????????
Who changed what in which revision?
| User | Revision | Line number | New 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 | #include "mbed.h" |
| baba2357 | 21:34b11624c5a0 | 7 | int a=0; |
| baba2357 | 21:34b11624c5a0 | 8 | int RSX,RSY,LSX,LSY,BSU,BSL,H=0,h=0; |
| baba2357 | 21:34b11624c5a0 | 9 | bool circleState=0; |
| 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 | SPI m(p5, p6, p7); |
| baba2357 | 10:bf0c0cdb487d | 16 | DigitalOut cs(p8); |
| baba2357 | 13:0d6ad1fb03b5 | 17 | void UserLoopSetting() |
| baba2357 | 13:0d6ad1fb03b5 | 18 | { |
| hirokimineshita | 0:736c76a75def | 19 | //一度だけ行いたい初期設定をここに書く |
| hirokimineshita | 0:736c76a75def | 20 | led1.period_ms(20); |
| hirokimineshita | 0:736c76a75def | 21 | } |
| hirokimineshita | 0:736c76a75def | 22 | |
| baba2357 | 13:0d6ad1fb03b5 | 23 | void UserLoop(char n,const u8* data) |
| baba2357 | 13:0d6ad1fb03b5 | 24 | { |
| hirokimineshita | 0:736c76a75def | 25 | u16 ButtonState; |
| baba2357 | 13:0d6ad1fb03b5 | 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; |
| baba2357 | 13:0d6ad1fb03b5 | 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 | 21:34b11624c5a0 | 47 | int M=0,move=0,updown=0; |
| baba2357 | 21:34b11624c5a0 | 48 | |
| baba2357 | 10:bf0c0cdb487d | 49 | m.format(16,3); |
| baba2357 | 10:bf0c0cdb487d | 50 | m.frequency(1000000); |
| baba2357 | 10:bf0c0cdb487d | 51 | cs=0; |
| baba2357 | 21:34b11624c5a0 | 52 | |
| baba2357 | 13:0d6ad1fb03b5 | 53 | //以下の整数MをSPIで送る |
| baba2357 | 13:0d6ad1fb03b5 | 54 | //整数Mを16桁の二進数とする。 |
| baba2357 | 21:34b11624c5a0 | 55 | //桁数| 16 | 15 | 14 |13|12|11|10| 9 | 8 | 7 | 6 | 5 |4|3|2|1| |
| baba2357 | 21:34b11624c5a0 | 56 | //指示|右旋回 |左旋回 |Xの+or-| 出力0~15 |アームonoff|上下onoff| 上下+- |空白|Yの+orー|出力0~15| |
| baba2357 | 13:0d6ad1fb03b5 | 57 | if((ButtonState >> BUTTONR1)&1) { |
| baba2357 | 21:34b11624c5a0 | 58 | M=1<<15; |
| baba2357 | 19:71f64ff1b86f | 59 | } else if((ButtonState >> BUTTONL1)&1) { |
| baba2357 | 21:34b11624c5a0 | 60 | M=1<<14; |
| baba2357 | 13:0d6ad1fb03b5 | 61 | } else { |
| baba2357 | 20:18ae99ad72f7 | 62 | if(LSX-129>0) { |
| baba2357 | 13:0d6ad1fb03b5 | 63 | M=1; |
| baba2357 | 21:34b11624c5a0 | 64 | M=M<<4; |
| baba2357 | 21:34b11624c5a0 | 65 | M+=(LSX-128)/8; |
| baba2357 | 21:34b11624c5a0 | 66 | M=M<<9; |
| baba2357 | 19:71f64ff1b86f | 67 | } else if(LSX-127<0) { |
| baba2357 | 21:34b11624c5a0 | 68 | if(((LSX-128)/8)==-16) M+=15; |
| baba2357 | 21:34b11624c5a0 | 69 | else M+=(-1)*((LSX-128)/8); |
| baba2357 | 21:34b11624c5a0 | 70 | M=M<<9; |
| baba2357 | 10:bf0c0cdb487d | 71 | } |
| baba2357 | 21:34b11624c5a0 | 72 | if((ButtonState >> BUTTONTRIANGEL)&1) { |
| baba2357 | 21:34b11624c5a0 | 73 | //○が押されたとき |
| baba2357 | 21:34b11624c5a0 | 74 | circleState=1; |
| baba2357 | 21:34b11624c5a0 | 75 | a=0; |
| baba2357 | 21:34b11624c5a0 | 76 | } else { |
| baba2357 | 21:34b11624c5a0 | 77 | //a=0; |
| baba2357 | 21:34b11624c5a0 | 78 | if(circleState == 1) { |
| baba2357 | 21:34b11624c5a0 | 79 | if(H == 0) { |
| baba2357 | 21:34b11624c5a0 | 80 | H = 1; |
| baba2357 | 21:34b11624c5a0 | 81 | } else { |
| baba2357 | 21:34b11624c5a0 | 82 | H = 0; |
| baba2357 | 21:34b11624c5a0 | 83 | } |
| baba2357 | 21:34b11624c5a0 | 84 | circleState = 0; |
| baba2357 | 21:34b11624c5a0 | 85 | }else circleState = 0; |
| baba2357 | 21:34b11624c5a0 | 86 | //a++; |
| baba2357 | 21:34b11624c5a0 | 87 | } |
| baba2357 | 21:34b11624c5a0 | 88 | h=H<<8; |
| baba2357 | 21:34b11624c5a0 | 89 | if((ButtonState >> BUTTONUP)&1) { |
| baba2357 | 21:34b11624c5a0 | 90 | move=1<<7; |
| baba2357 | 21:34b11624c5a0 | 91 | updown=1<<6; |
| baba2357 | 21:34b11624c5a0 | 92 | } else if((ButtonState >> BUTTONDOWN)&1) { |
| baba2357 | 21:34b11624c5a0 | 93 | move=1<<7; |
| baba2357 | 13:0d6ad1fb03b5 | 94 | } |
| baba2357 | 21:34b11624c5a0 | 95 | if(LSY-129>0) { |
| baba2357 | 21:34b11624c5a0 | 96 | M+=0x10; |
| baba2357 | 21:34b11624c5a0 | 97 | M+=(LSY-128)/8; |
| baba2357 | 21:34b11624c5a0 | 98 | } else if(LSY-127<0) { |
| baba2357 | 21:34b11624c5a0 | 99 | if(((LSY-128)/8)==-16) M+=15; |
| baba2357 | 21:34b11624c5a0 | 100 | else M+=(-1)*((LSY-128)/8); |
| baba2357 | 21:34b11624c5a0 | 101 | } else { |
| baba2357 | 21:34b11624c5a0 | 102 | M=0; |
| baba2357 | 21:34b11624c5a0 | 103 | } |
| baba2357 | 21:34b11624c5a0 | 104 | } |
| baba2357 | 21:34b11624c5a0 | 105 | M+=h; |
| baba2357 | 21:34b11624c5a0 | 106 | M+=move; |
| baba2357 | 21:34b11624c5a0 | 107 | M+=updown; |
| baba2357 | 21:34b11624c5a0 | 108 | |
| baba2357 | 20:18ae99ad72f7 | 109 | // m.write(0xffff); |
| baba2357 | 20:18ae99ad72f7 | 110 | m.write(M); |
| baba2357 | 20:18ae99ad72f7 | 111 | // printf("%d,%d\n\r",M&0x40,0x40); |
| baba2357 | 13:0d6ad1fb03b5 | 112 | |
| hirokimineshita | 0:736c76a75def | 113 | led1=LSX/256.0f; |
| hirokimineshita | 0:736c76a75def | 114 | led2=LSY/256.0f; |
| hirokimineshita | 0:736c76a75def | 115 | led3=ButtonState & 0x0400; //L1の状態 |
| hirokimineshita | 0:736c76a75def | 116 | led4=ButtonState & 0x0800; //R1の状態 |
| baba2357 | 21:34b11624c5a0 | 117 | //値の取得はps3.hを参照 |
| baba2357 | 13:0d6ad1fb03b5 | 118 | cs=1; |
| baba2357 | 21:34b11624c5a0 | 119 | printf("M:%d\t,h:%d\t,updown:%d\t,move:%d\t,a=%d\t\n",M,H,updown,move,a); |
| baba2357 | 21:34b11624c5a0 | 120 | } |
