test
Dependencies: mbed KondoServoLibrary Encoder
User.cpp@18:f7c587f0f8b8, 2019-11-01 (annotated)
- Committer:
- o2132613
- Date:
- Fri Nov 01 01:39:57 2019 +0000
- Revision:
- 18:f7c587f0f8b8
- Parent:
- 17:348c660ea6f6
- Child:
- 19:510b87211851
this was the version use in F3rc(maybe;
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" |
o2132613 | 18:f7c587f0f8b8 | 6 | #define speed 0.2 |
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 | //これより下に関数外に書く要素を記入する |
o2132613 | 18:f7c587f0f8b8 | 11 | DigitalOut air(p24); |
o2132613 | 18:f7c587f0f8b8 | 12 | PwmOut motorRB(p22); |
o2132613 | 18:f7c587f0f8b8 | 13 | PwmOut motorRF(p21); |
o2132613 | 18:f7c587f0f8b8 | 14 | PwmOut motorLB(p25); |
o2132613 | 18:f7c587f0f8b8 | 15 | PwmOut motorLF(p26); |
o2132613 | 17:348c660ea6f6 | 16 | SPI spi(p5,p6,p7); |
o2132613 | 17:348c660ea6f6 | 17 | DigitalOut cs(p8); |
o2132613 | 17:348c660ea6f6 | 18 | int send; |
o2132613 | 17:348c660ea6f6 | 19 | |
baba2357 | 11:86d717718dbf | 20 | |
o2132613 | 17:348c660ea6f6 | 21 | void UserLoopSetting() |
o2132613 | 17:348c660ea6f6 | 22 | { |
o2132613 | 17:348c660ea6f6 | 23 | spi.format(8,3); |
o2132613 | 17:348c660ea6f6 | 24 | spi.frequency(1000000); |
o2132613 | 18:f7c587f0f8b8 | 25 | motorRF.period_ms(1); |
o2132613 | 18:f7c587f0f8b8 | 26 | motorRB.period_ms(1); |
o2132613 | 18:f7c587f0f8b8 | 27 | motorLF.period_ms(1); |
o2132613 | 18:f7c587f0f8b8 | 28 | motorLB.period_ms(1); |
hirokimineshita | 0:736c76a75def | 29 | } |
o2132613 | 17:348c660ea6f6 | 30 | void UserLoop(char n,const u8* data) |
o2132613 | 17:348c660ea6f6 | 31 | { |
hirokimineshita | 0:736c76a75def | 32 | u16 ButtonState; |
o2132613 | 17:348c660ea6f6 | 33 | if(n==0) { //有線Ps3USB.cpp |
hirokimineshita | 0:736c76a75def | 34 | RSX = ((ps3report*)data)->RightStickX; |
hirokimineshita | 0:736c76a75def | 35 | RSY = ((ps3report*)data)->RightStickY; |
hirokimineshita | 0:736c76a75def | 36 | LSX = ((ps3report*)data)->LeftStickX; |
hirokimineshita | 0:736c76a75def | 37 | LSY = ((ps3report*)data)->LeftStickY; |
hirokimineshita | 0:736c76a75def | 38 | BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 39 | BSL = (u8)(((ps3report*)data)->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 40 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 41 | ButtonState = ((ps3report*)data)->ButtonState; |
o2132613 | 17:348c660ea6f6 | 42 | } else {//無線TestShell.cpp |
hirokimineshita | 0:736c76a75def | 43 | RSX = ((ps3report*)(data + 1))->RightStickX; |
hirokimineshita | 0:736c76a75def | 44 | RSY = ((ps3report*)(data + 1))->RightStickY; |
hirokimineshita | 0:736c76a75def | 45 | LSX = ((ps3report*)(data + 1))->LeftStickX; |
hirokimineshita | 0:736c76a75def | 46 | LSY = ((ps3report*)(data + 1))->LeftStickY; |
hirokimineshita | 0:736c76a75def | 47 | BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 48 | BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 49 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 50 | ButtonState = ((ps3report*)(data + 1))->ButtonState; |
hirokimineshita | 0:736c76a75def | 51 | } |
hirokimineshita | 0:736c76a75def | 52 | //ここより下にプログラムを書く |
o2132613 | 17:348c660ea6f6 | 53 | //spi通信用プログラム |
o2132613 | 17:348c660ea6f6 | 54 | send = 0; |
o2132613 | 18:f7c587f0f8b8 | 55 | if((ButtonState >> BUTTONUP)&1 == 1) |
o2132613 | 17:348c660ea6f6 | 56 | {//対応するボタンを書く(今回上ボタン |
o2132613 | 18:f7c587f0f8b8 | 57 | motorRF = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 58 | motorRB = 0; |
o2132613 | 18:f7c587f0f8b8 | 59 | motorLF = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 60 | motorLB = 0; |
o2132613 | 18:f7c587f0f8b8 | 61 | send = 0; |
o2132613 | 17:348c660ea6f6 | 62 | }else if((ButtonState >> BUTTONDOWN)&1 == 1) |
o2132613 | 17:348c660ea6f6 | 63 | {//対応するボタンを書く(今回下ボタン |
o2132613 | 18:f7c587f0f8b8 | 64 | motorRF = 0; |
o2132613 | 18:f7c587f0f8b8 | 65 | motorRB = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 66 | motorLF = 0; |
o2132613 | 18:f7c587f0f8b8 | 67 | motorLB = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 68 | send = 0; |
o2132613 | 17:348c660ea6f6 | 69 | }else if((ButtonState >> BUTTONL1)&1 == 1) |
o2132613 | 17:348c660ea6f6 | 70 | {//対応するボタンを書く(今回L1ボタン |
o2132613 | 18:f7c587f0f8b8 | 71 | motorRF = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 72 | motorRB = 0; |
o2132613 | 18:f7c587f0f8b8 | 73 | motorLF = 0; |
o2132613 | 18:f7c587f0f8b8 | 74 | motorLB = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 75 | send = 0; |
o2132613 | 17:348c660ea6f6 | 76 | }else if((ButtonState >> BUTTONR1)&1 == 1) |
o2132613 | 17:348c660ea6f6 | 77 | {//対応するボタンを書く(今回R1ボタン |
o2132613 | 18:f7c587f0f8b8 | 78 | send = 0; |
o2132613 | 18:f7c587f0f8b8 | 79 | motorRF = 0; |
o2132613 | 18:f7c587f0f8b8 | 80 | motorRB = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 81 | motorLF = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 82 | motorLB = 0; |
o2132613 | 18:f7c587f0f8b8 | 83 | }else if((ButtonState >> BUTTONRIGHT)&1 == 1)//Right |
o2132613 | 18:f7c587f0f8b8 | 84 | { |
o2132613 | 18:f7c587f0f8b8 | 85 | send = 4; |
o2132613 | 18:f7c587f0f8b8 | 86 | motorRF = 0; |
o2132613 | 18:f7c587f0f8b8 | 87 | motorRB = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 88 | motorLF = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 89 | motorLB = 0; |
o2132613 | 18:f7c587f0f8b8 | 90 | }else if((ButtonState >> BUTTONLEFT)&1 == 1)//Left |
o2132613 | 18:f7c587f0f8b8 | 91 | { |
o2132613 | 18:f7c587f0f8b8 | 92 | send = 3; |
o2132613 | 18:f7c587f0f8b8 | 93 | motorRF = 0.2; |
o2132613 | 18:f7c587f0f8b8 | 94 | motorRB = 0; |
o2132613 | 18:f7c587f0f8b8 | 95 | motorLF = 0; |
o2132613 | 18:f7c587f0f8b8 | 96 | motorLB = 0.2; |
abcdefgh | 13:3d7a8cb91eeb | 97 | }else{ |
o2132613 | 17:348c660ea6f6 | 98 | send = 0; |
o2132613 | 18:f7c587f0f8b8 | 99 | motorRF = 0; |
o2132613 | 18:f7c587f0f8b8 | 100 | motorRB = 0; |
o2132613 | 18:f7c587f0f8b8 | 101 | motorLF = 0; |
o2132613 | 18:f7c587f0f8b8 | 102 | motorLB = 0; |
o2132613 | 17:348c660ea6f6 | 103 | } |
o2132613 | 18:f7c587f0f8b8 | 104 | if((ButtonState >> BUTTONCIRCLE)&1 == 1) {//対応するボタンを書く(今回Oボタン |
o2132613 | 18:f7c587f0f8b8 | 105 | air=1; |
o2132613 | 18:f7c587f0f8b8 | 106 | } else if((ButtonState >> BUTTONCROSS)&1 == 1) {//対応するボタンを書く(今回×ボタン |
o2132613 | 18:f7c587f0f8b8 | 107 | air=0; |
o2132613 | 17:348c660ea6f6 | 108 | } |
o2132613 | 18:f7c587f0f8b8 | 109 | if((ButtonState >> BUTTONR2&1) == 1 )//R2 down |
o2132613 | 18:f7c587f0f8b8 | 110 | { |
o2132613 | 18:f7c587f0f8b8 | 111 | send = 1; |
o2132613 | 18:f7c587f0f8b8 | 112 | }else if((ButtonState >> BUTTONL2)&1 == 1)//L2 up |
o2132613 | 18:f7c587f0f8b8 | 113 | { |
o2132613 | 18:f7c587f0f8b8 | 114 | send = 2; |
o2132613 | 17:348c660ea6f6 | 115 | } |
o2132613 | 17:348c660ea6f6 | 116 | spi. write(send); |
hirokimineshita | 0:736c76a75def | 117 | } |