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
User.cpp@19:812c3572622a, 2021-05-07 (annotated)
- Committer:
- shunsuke0427
- Date:
- Fri May 07 08:31:36 2021 +0000
- Revision:
- 19:812c3572622a
- Parent:
- 18:065d88f01f2b
to be published
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shunsuke0427 | 19:812c3572622a | 1 | //PS3コンの値をSPIで送信 |
shunsuke0427 | 19:812c3572622a | 2 | //最初に255を送る→L,RスティックのX,Yの値を送る |
shunsuke0427 | 19:812c3572622a | 3 | |
hirokimineshita | 0:736c76a75def | 4 | #include "Utils.h" |
shunsuke0427 | 19:812c3572622a | 5 | |
hirokimineshita | 0:736c76a75def | 6 | #include "USBHost.h" |
hirokimineshita | 0:736c76a75def | 7 | #include "hci.h" |
hirokimineshita | 0:736c76a75def | 8 | #include "ps3.h" |
hirokimineshita | 0:736c76a75def | 9 | #include "User.h" |
hirokimineshita | 0:736c76a75def | 10 | |
hirokimineshita | 0:736c76a75def | 11 | #include "mbed.h" |
hirokimineshita | 0:736c76a75def | 12 | |
shunsuke0427 | 19:812c3572622a | 13 | #define waitTime 0.1 |
shunsuke0427 | 19:812c3572622a | 14 | |
shunsuke0427 | 19:812c3572622a | 15 | //#define serial |
shunsuke0427 | 19:812c3572622a | 16 | |
shunsuke0427 | 19:812c3572622a | 17 | |
hirokimineshita | 0:736c76a75def | 18 | int RSX,RSY,LSX,LSY,BSU,BSL; |
hirokimineshita | 9:e5437ba3e920 | 19 | //これより下に関数外に書く要素を記入する |
shunsuke0427 | 19:812c3572622a | 20 | |
shunsuke0427 | 19:812c3572622a | 21 | #ifdef serial |
shunsuke0427 | 19:812c3572622a | 22 | //Serial pc(USBTX, USBRX); |
shunsuke0427 | 19:812c3572622a | 23 | #endif |
shunsuke0427 | 19:812c3572622a | 24 | |
shunsuke0427 | 19:812c3572622a | 25 | DigitalOut cs(p8); |
shunsuke0427 | 19:812c3572622a | 26 | |
shunsuke0427 | 19:812c3572622a | 27 | //PwmOut pin(p9); |
shunsuke0427 | 19:812c3572622a | 28 | SPI mySPI(p5, p6, p7); |
shunsuke0427 | 19:812c3572622a | 29 | |
shunsuke0427 | 19:812c3572622a | 30 | //SPIHalfDuplex mySPI(p5, p6, p7); |
stream3715 | 18:065d88f01f2b | 31 | PwmOut led1(LED1); |
stream3715 | 18:065d88f01f2b | 32 | PwmOut led2(LED2); |
shunsuke0427 | 19:812c3572622a | 33 | PwmOut led3(LED3); |
shunsuke0427 | 19:812c3572622a | 34 | PwmOut led4(LED4); |
shunsuke0427 | 19:812c3572622a | 35 | //DigitalOut myled(LED1); |
baba2357 | 11:86d717718dbf | 36 | |
shunsuke0427 | 19:812c3572622a | 37 | |
shunsuke0427 | 19:812c3572622a | 38 | void UserLoopSetting() |
shunsuke0427 | 19:812c3572622a | 39 | { |
shunsuke0427 | 19:812c3572622a | 40 | // pc.printf("UserLoopSetting()\r\n"); |
stream3715 | 18:065d88f01f2b | 41 | //一度だけ行いたい初期設定をここに書く |
stream3715 | 18:065d88f01f2b | 42 | led1.period_ms(20); |
shunsuke0427 | 19:812c3572622a | 43 | |
shunsuke0427 | 19:812c3572622a | 44 | mySPI.format(8,3); |
shunsuke0427 | 19:812c3572622a | 45 | mySPI.frequency(1000000); |
shunsuke0427 | 19:812c3572622a | 46 | |
shunsuke0427 | 19:812c3572622a | 47 | //mySPI.format(8,3); |
shunsuke0427 | 19:812c3572622a | 48 | //mySPI.frequency(1000000); |
shunsuke0427 | 19:812c3572622a | 49 | |
shunsuke0427 | 19:812c3572622a | 50 | //mySPI.reply(0X00); |
shunsuke0427 | 19:812c3572622a | 51 | |
shunsuke0427 | 19:812c3572622a | 52 | //uint8_t reg[] = {0,1}; |
shunsuke0427 | 19:812c3572622a | 53 | |
shunsuke0427 | 19:812c3572622a | 54 | //printf("Setting...\n"); |
hirokimineshita | 0:736c76a75def | 55 | } |
stream3715 | 18:065d88f01f2b | 56 | |
shunsuke0427 | 19:812c3572622a | 57 | void UserLoop(char n,const u8* data) |
shunsuke0427 | 19:812c3572622a | 58 | { |
hirokimineshita | 0:736c76a75def | 59 | u16 ButtonState; |
shunsuke0427 | 19:812c3572622a | 60 | if(n==0) { //有線Ps3USB.cpp |
hirokimineshita | 0:736c76a75def | 61 | RSX = ((ps3report*)data)->RightStickX; |
hirokimineshita | 0:736c76a75def | 62 | RSY = ((ps3report*)data)->RightStickY; |
hirokimineshita | 0:736c76a75def | 63 | LSX = ((ps3report*)data)->LeftStickX; |
hirokimineshita | 0:736c76a75def | 64 | LSY = ((ps3report*)data)->LeftStickY; |
hirokimineshita | 0:736c76a75def | 65 | BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 66 | BSL = (u8)(((ps3report*)data)->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 67 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 68 | ButtonState = ((ps3report*)data)->ButtonState; |
shunsuke0427 | 19:812c3572622a | 69 | } else {//無線TestShell.cpp |
hirokimineshita | 0:736c76a75def | 70 | RSX = ((ps3report*)(data + 1))->RightStickX; |
hirokimineshita | 0:736c76a75def | 71 | RSY = ((ps3report*)(data + 1))->RightStickY; |
hirokimineshita | 0:736c76a75def | 72 | LSX = ((ps3report*)(data + 1))->LeftStickX; |
hirokimineshita | 0:736c76a75def | 73 | LSY = ((ps3report*)(data + 1))->LeftStickY; |
hirokimineshita | 0:736c76a75def | 74 | BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); |
hirokimineshita | 0:736c76a75def | 75 | BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); |
hirokimineshita | 0:736c76a75def | 76 | //ボタンの処理 |
hirokimineshita | 0:736c76a75def | 77 | ButtonState = ((ps3report*)(data + 1))->ButtonState; |
hirokimineshita | 0:736c76a75def | 78 | } |
hirokimineshita | 0:736c76a75def | 79 | //ここより下にプログラムを書く |
shunsuke0427 | 19:812c3572622a | 80 | |
shunsuke0427 | 19:812c3572622a | 81 | led3=LSX/256.0f; |
shunsuke0427 | 19:812c3572622a | 82 | led4=LSY/256.0f; |
shunsuke0427 | 19:812c3572622a | 83 | led1=RSX/256.0f; |
shunsuke0427 | 19:812c3572622a | 84 | led2=RSY/256.0f; |
shunsuke0427 | 19:812c3572622a | 85 | |
shunsuke0427 | 19:812c3572622a | 86 | #ifdef serial |
shunsuke0427 | 19:812c3572622a | 87 | printf("LSX:%d LSY:%d RSX:%d RSY:%d\r\n", LSX, LSY, RSX, RSY); |
shunsuke0427 | 19:812c3572622a | 88 | #endif |
shunsuke0427 | 19:812c3572622a | 89 | //led3=ButtonState & 0x0400; //L1の状態 |
shunsuke0427 | 19:812c3572622a | 90 | //led4=ButtonState & 0x0200; //R1の状態 |
shunsuke0427 | 19:812c3572622a | 91 | |
shunsuke0427 | 19:812c3572622a | 92 | /* |
shunsuke0427 | 19:812c3572622a | 93 | 0x0200 : L2 |
shunsuke0427 | 19:812c3572622a | 94 | 0x0400 : L1 |
shunsuke0427 | 19:812c3572622a | 95 | 0x0800 : L1 |
shunsuke0427 | 19:812c3572622a | 96 | */ |
shunsuke0427 | 19:812c3572622a | 97 | |
shunsuke0427 | 19:812c3572622a | 98 | |
shunsuke0427 | 19:812c3572622a | 99 | //値の取得はps3.hを参照 |
stream3715 | 18:065d88f01f2b | 100 | |
shunsuke0427 | 19:812c3572622a | 101 | |
shunsuke0427 | 19:812c3572622a | 102 | /*uint8_t first; |
shunsuke0427 | 19:812c3572622a | 103 | uint8_t second; |
shunsuke0427 | 19:812c3572622a | 104 | first = (uint8_t) ButtonState & 0XFF; |
shunsuke0427 | 19:812c3572622a | 105 | second = (uint8_t) (ButtonState>>8) & 0XFF;*/ |
shunsuke0427 | 19:812c3572622a | 106 | cs = 0; |
shunsuke0427 | 19:812c3572622a | 107 | mySPI.write(255); |
shunsuke0427 | 19:812c3572622a | 108 | mySPI.write(LSX*255/256); |
shunsuke0427 | 19:812c3572622a | 109 | mySPI.write(LSY*255/256); |
shunsuke0427 | 19:812c3572622a | 110 | mySPI.write(RSX*255/256); |
shunsuke0427 | 19:812c3572622a | 111 | mySPI.write(RSY*255/256); |
shunsuke0427 | 19:812c3572622a | 112 | //myled = 1; |
shunsuke0427 | 19:812c3572622a | 113 | cs = 1; |
shunsuke0427 | 19:812c3572622a | 114 | wait(waitTime); |
shunsuke0427 | 19:812c3572622a | 115 | //myled = 0; |
hirokimineshita | 0:736c76a75def | 116 | } |