手動機アーム、mbed基盤のspiをおくるだけのプログラムです(9/4)
Dependencies: SPI_master_arm_shudouki mbed
Fork of SPI_master_arm_shudouki2 by
User.cpp@0:76d1c7f13415, 2017-08-21 (annotated)
- Committer:
- yoka06
- Date:
- Mon Aug 21 08:49:06 2017 +0000
- Revision:
- 0:76d1c7f13415
- Child:
- 1:5b008a48a49c
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yoka06 | 0:76d1c7f13415 | 1 | #include "Utils.h" |
yoka06 | 0:76d1c7f13415 | 2 | #include "USBHost.h" |
yoka06 | 0:76d1c7f13415 | 3 | #include "hci.h" |
yoka06 | 0:76d1c7f13415 | 4 | #include "ps3.h" |
yoka06 | 0:76d1c7f13415 | 5 | #include "User.h" |
yoka06 | 0:76d1c7f13415 | 6 | |
yoka06 | 0:76d1c7f13415 | 7 | #include "rc-servo.h" |
yoka06 | 0:76d1c7f13415 | 8 | #include "motor_1.h" |
yoka06 | 0:76d1c7f13415 | 9 | #include "motor_2.h" |
yoka06 | 0:76d1c7f13415 | 10 | |
yoka06 | 0:76d1c7f13415 | 11 | #include "mbed.h" |
yoka06 | 0:76d1c7f13415 | 12 | int RSX,RSY,LSX,LSY,BSU,BSL; |
yoka06 | 0:76d1c7f13415 | 13 | int a,b,c,d,e,f,g,h; |
yoka06 | 0:76d1c7f13415 | 14 | int send=0; |
yoka06 | 0:76d1c7f13415 | 15 | |
yoka06 | 0:76d1c7f13415 | 16 | |
yoka06 | 0:76d1c7f13415 | 17 | |
yoka06 | 0:76d1c7f13415 | 18 | //これより下に関数外に書く要素を記入する |
yoka06 | 0:76d1c7f13415 | 19 | PwmOut led1(LED1); |
yoka06 | 0:76d1c7f13415 | 20 | PwmOut led2(LED2); |
yoka06 | 0:76d1c7f13415 | 21 | DigitalOut led3(LED3); |
yoka06 | 0:76d1c7f13415 | 22 | DigitalOut led4(LED4); |
yoka06 | 0:76d1c7f13415 | 23 | |
yoka06 | 0:76d1c7f13415 | 24 | SPI spi(p5,p6,p7); |
yoka06 | 0:76d1c7f13415 | 25 | DigitalOut cs(p8); |
yoka06 | 0:76d1c7f13415 | 26 | |
yoka06 | 0:76d1c7f13415 | 27 | void UserLoopSetting() |
yoka06 | 0:76d1c7f13415 | 28 | { |
yoka06 | 0:76d1c7f13415 | 29 | //一度だけ行いたい初期設定をここに書く |
yoka06 | 0:76d1c7f13415 | 30 | led1.period_ms(20); |
yoka06 | 0:76d1c7f13415 | 31 | } |
yoka06 | 0:76d1c7f13415 | 32 | |
yoka06 | 0:76d1c7f13415 | 33 | void UserLoop(char n,const u8* data) |
yoka06 | 0:76d1c7f13415 | 34 | { |
yoka06 | 0:76d1c7f13415 | 35 | u16 ButtonState; |
yoka06 | 0:76d1c7f13415 | 36 | if(n==0) { //有線Ps3USB.cpp |
yoka06 | 0:76d1c7f13415 | 37 | RSX = ((ps3report*)data)->RightStickX; |
yoka06 | 0:76d1c7f13415 | 38 | RSY = ((ps3report*)data)->RightStickY; |
yoka06 | 0:76d1c7f13415 | 39 | LSX = ((ps3report*)data)->LeftStickX; |
yoka06 | 0:76d1c7f13415 | 40 | LSY = ((ps3report*)data)->LeftStickY; |
yoka06 | 0:76d1c7f13415 | 41 | BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); |
yoka06 | 0:76d1c7f13415 | 42 | BSL = (u8)(((ps3report*)data)->ButtonState >> 8); |
yoka06 | 0:76d1c7f13415 | 43 | //ボタンの処理 |
yoka06 | 0:76d1c7f13415 | 44 | ButtonState = ((ps3report*)data)->ButtonState; |
yoka06 | 0:76d1c7f13415 | 45 | } else {//無線TestShell.cpp |
yoka06 | 0:76d1c7f13415 | 46 | RSX = ((ps3report*)(data + 1))->RightStickX; |
yoka06 | 0:76d1c7f13415 | 47 | RSY = ((ps3report*)(data + 1))->RightStickY; |
yoka06 | 0:76d1c7f13415 | 48 | LSX = ((ps3report*)(data + 1))->LeftStickX; |
yoka06 | 0:76d1c7f13415 | 49 | LSY = ((ps3report*)(data + 1))->LeftStickY; |
yoka06 | 0:76d1c7f13415 | 50 | BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); |
yoka06 | 0:76d1c7f13415 | 51 | BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); |
yoka06 | 0:76d1c7f13415 | 52 | //ボタンの処理 |
yoka06 | 0:76d1c7f13415 | 53 | ButtonState = ((ps3report*)(data + 1))->ButtonState; |
yoka06 | 0:76d1c7f13415 | 54 | } |
yoka06 | 0:76d1c7f13415 | 55 | //ここより下にプログラムを書く |
yoka06 | 0:76d1c7f13415 | 56 | |
yoka06 | 0:76d1c7f13415 | 57 | spi.format(8,3); |
yoka06 | 0:76d1c7f13415 | 58 | spi.frequency(1000000); |
yoka06 | 0:76d1c7f13415 | 59 | |
yoka06 | 0:76d1c7f13415 | 60 | send =a+b+c+d+e+f+g+h; |
yoka06 | 0:76d1c7f13415 | 61 | |
yoka06 | 0:76d1c7f13415 | 62 | |
yoka06 | 0:76d1c7f13415 | 63 | // a= 0b1 |
yoka06 | 0:76d1c7f13415 | 64 | // b= 0b10 |
yoka06 | 0:76d1c7f13415 | 65 | // c= 0b100 |
yoka06 | 0:76d1c7f13415 | 66 | // d= 0b1000 |
yoka06 | 0:76d1c7f13415 | 67 | // e= 0b10000 |
yoka06 | 0:76d1c7f13415 | 68 | // f= 0b100000 |
yoka06 | 0:76d1c7f13415 | 69 | // g= 0b1000000 |
yoka06 | 0:76d1c7f13415 | 70 | // h= 0b10000000 |
yoka06 | 0:76d1c7f13415 | 71 | |
yoka06 | 0:76d1c7f13415 | 72 | while(1) { |
yoka06 | 0:76d1c7f13415 | 73 | |
yoka06 | 0:76d1c7f13415 | 74 | if((ButtonState >> BUTTONUP)&1 == 1) { // ▲で燃料用アーム展開 |
yoka06 | 0:76d1c7f13415 | 75 | a= 0b1; |
yoka06 | 0:76d1c7f13415 | 76 | } else { |
yoka06 | 0:76d1c7f13415 | 77 | a= 0; |
yoka06 | 0:76d1c7f13415 | 78 | } |
yoka06 | 0:76d1c7f13415 | 79 | |
yoka06 | 0:76d1c7f13415 | 80 | if((ButtonState >> BUTTONTRIANGEL)&1 == 1) { // △で燃料回収 |
yoka06 | 0:76d1c7f13415 | 81 | b= 0b10; |
yoka06 | 0:76d1c7f13415 | 82 | } else { |
yoka06 | 0:76d1c7f13415 | 83 | b= 0 ; |
yoka06 | 0:76d1c7f13415 | 84 | } |
yoka06 | 0:76d1c7f13415 | 85 | |
yoka06 | 0:76d1c7f13415 | 86 | if((ButtonState >> BUTTONLEFT)&1 == 1) { // ◀で燃料掃き出し |
yoka06 | 0:76d1c7f13415 | 87 | c= 0b100; |
yoka06 | 0:76d1c7f13415 | 88 | } else { |
yoka06 | 0:76d1c7f13415 | 89 | c= 0; |
yoka06 | 0:76d1c7f13415 | 90 | } |
yoka06 | 0:76d1c7f13415 | 91 | |
yoka06 | 0:76d1c7f13415 | 92 | if((ButtonState >> BUTTONCIRCLE)&1 == 1) { // 〇でタンク回収 |
yoka06 | 0:76d1c7f13415 | 93 | d= 0b1000; |
yoka06 | 0:76d1c7f13415 | 94 | } else { |
yoka06 | 0:76d1c7f13415 | 95 | d= 0; |
yoka06 | 0:76d1c7f13415 | 96 | } |
yoka06 | 0:76d1c7f13415 | 97 | |
yoka06 | 0:76d1c7f13415 | 98 | if((ButtonState >> BUTTONRIGHT)&1 == 1) { // ‣でタンク掃き出し |
yoka06 | 0:76d1c7f13415 | 99 | e= 0b10000; |
yoka06 | 0:76d1c7f13415 | 100 | } else { |
yoka06 | 0:76d1c7f13415 | 101 | e= 0; |
yoka06 | 0:76d1c7f13415 | 102 | } |
yoka06 | 0:76d1c7f13415 | 103 | |
yoka06 | 0:76d1c7f13415 | 104 | if((ButtonState >> BUTTONDOWN)&1 == 1) { // ▼で待機 |
yoka06 | 0:76d1c7f13415 | 105 | f= 0b100000; |
yoka06 | 0:76d1c7f13415 | 106 | } else { |
yoka06 | 0:76d1c7f13415 | 107 | f= 0; |
yoka06 | 0:76d1c7f13415 | 108 | } |
yoka06 | 0:76d1c7f13415 | 109 | |
yoka06 | 0:76d1c7f13415 | 110 | if((ButtonState >> BUTTONCROSS)&1 == 1) { // ×でサンプル受け取り |
yoka06 | 0:76d1c7f13415 | 111 | g= 0b1000000; |
yoka06 | 0:76d1c7f13415 | 112 | } else { |
yoka06 | 0:76d1c7f13415 | 113 | g= 0; |
yoka06 | 0:76d1c7f13415 | 114 | } |
yoka06 | 0:76d1c7f13415 | 115 | |
yoka06 | 0:76d1c7f13415 | 116 | if((ButtonState >> BUTTONSQUARE)&1 == 1) { // □でサンプル設置 |
yoka06 | 0:76d1c7f13415 | 117 | h= 0b10000000; |
yoka06 | 0:76d1c7f13415 | 118 | } else { |
yoka06 | 0:76d1c7f13415 | 119 | h= 0; |
yoka06 | 0:76d1c7f13415 | 120 | } |
yoka06 | 0:76d1c7f13415 | 121 | |
yoka06 | 0:76d1c7f13415 | 122 | cs= 0; |
yoka06 | 0:76d1c7f13415 | 123 | spi.write(send); |
yoka06 | 0:76d1c7f13415 | 124 | cs= 1; |
yoka06 | 0:76d1c7f13415 | 125 | printf("%d\r\n",send); |
yoka06 | 0:76d1c7f13415 | 126 | |
yoka06 | 0:76d1c7f13415 | 127 | } |
yoka06 | 0:76d1c7f13415 | 128 | } |