主導機 mbed用のプログラムです 改良しました

Dependencies:   mbed

Fork of F3RC_syudou_master by yuto kawamura

Committer:
yuto17320508
Date:
Mon Aug 21 04:51:26 2017 +0000
Revision:
16:b232fd9ee9c2
Parent:
15:c5258a4dee75
Child:
17:c5c41fcf316e
aaa

Who changed what in which revision?

UserRevisionLine numberNew 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"
hirokimineshita 0:736c76a75def 7
hirokimineshita 0:736c76a75def 8 int RSX,RSY,LSX,LSY,BSU,BSL;
hirokimineshita 9:e5437ba3e920 9 //これより下に関数外に書く要素を記入する
yuto17320508 16:b232fd9ee9c2 10 //spi通信用
yuto17320508 16:b232fd9ee9c2 11 SPI spi(p5,p6,p7);
yuto17320508 16:b232fd9ee9c2 12 DigitalOut cs(p8);
yuto17320508 16:b232fd9ee9c2 13
baba2357 11:86d717718dbf 14
yuto17320508 16:b232fd9ee9c2 15 void UserLoopSetting()
yuto17320508 16:b232fd9ee9c2 16 {
yuto17320508 16:b232fd9ee9c2 17 spi.format(16,3);
yuto17320508 16:b232fd9ee9c2 18 spi.frequency(1000000);
hirokimineshita 0:736c76a75def 19 }
hirokimineshita 0:736c76a75def 20
yuto17320508 16:b232fd9ee9c2 21 void UserLoop(char n,const u8* data)
yuto17320508 16:b232fd9ee9c2 22 {
hirokimineshita 0:736c76a75def 23 u16 ButtonState;
yuto17320508 16:b232fd9ee9c2 24 if(n==0) { //有線Ps3USB.cpp
hirokimineshita 0:736c76a75def 25 RSX = ((ps3report*)data)->RightStickX;
hirokimineshita 0:736c76a75def 26 RSY = ((ps3report*)data)->RightStickY;
hirokimineshita 0:736c76a75def 27 LSX = ((ps3report*)data)->LeftStickX;
hirokimineshita 0:736c76a75def 28 LSY = ((ps3report*)data)->LeftStickY;
hirokimineshita 0:736c76a75def 29 BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff);
hirokimineshita 0:736c76a75def 30 BSL = (u8)(((ps3report*)data)->ButtonState >> 8);
hirokimineshita 0:736c76a75def 31 //ボタンの処理
hirokimineshita 0:736c76a75def 32 ButtonState = ((ps3report*)data)->ButtonState;
yuto17320508 16:b232fd9ee9c2 33 } else {//無線TestShell.cpp
hirokimineshita 0:736c76a75def 34 RSX = ((ps3report*)(data + 1))->RightStickX;
hirokimineshita 0:736c76a75def 35 RSY = ((ps3report*)(data + 1))->RightStickY;
hirokimineshita 0:736c76a75def 36 LSX = ((ps3report*)(data + 1))->LeftStickX;
hirokimineshita 0:736c76a75def 37 LSY = ((ps3report*)(data + 1))->LeftStickY;
hirokimineshita 0:736c76a75def 38 BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff);
hirokimineshita 0:736c76a75def 39 BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8);
hirokimineshita 0:736c76a75def 40 //ボタンの処理
hirokimineshita 0:736c76a75def 41 ButtonState = ((ps3report*)(data + 1))->ButtonState;
hirokimineshita 0:736c76a75def 42 }
hirokimineshita 0:736c76a75def 43 //ここより下にプログラムを書く
yuto17320508 16:b232fd9ee9c2 44 //spi通信用プログラム
yuto17320508 16:b232fd9ee9c2 45
yuto17320508 16:b232fd9ee9c2 46 int a,b,c,d,e,f,g,h,i,j;
yuto17320508 16:b232fd9ee9c2 47 int send = 0;
yuto17320508 16:b232fd9ee9c2 48
yuto17320508 16:b232fd9ee9c2 49
yuto17320508 16:b232fd9ee9c2 50 while(1) {
yuto17320508 16:b232fd9ee9c2 51 if((ButtonState >> BUTTONTRIANGEL)&1 == 1) { //フォトトランジスタ1
yuto17320508 16:b232fd9ee9c2 52 a = 1;
yuto17320508 16:b232fd9ee9c2 53 } else {
yuto17320508 16:b232fd9ee9c2 54 a = 0;
yuto17320508 16:b232fd9ee9c2 55 }
yuto17320508 16:b232fd9ee9c2 56
yuto17320508 16:b232fd9ee9c2 57 if((ButtonState >> BUTTONCIRCLE)&1 == 1) {//フォトトランジスタ2
yuto17320508 16:b232fd9ee9c2 58 b = 2;
yuto17320508 16:b232fd9ee9c2 59 } else {
yuto17320508 16:b232fd9ee9c2 60 b = 0;
yuto17320508 16:b232fd9ee9c2 61 }
yuto17320508 16:b232fd9ee9c2 62
yuto17320508 16:b232fd9ee9c2 63 if((ButtonState >> BUTTONUP)&1 == 1) {//対応するボタンを書く(今回上ボタン
yuto17320508 16:b232fd9ee9c2 64 c = 4;
yuto17320508 16:b232fd9ee9c2 65 } else {
yuto17320508 16:b232fd9ee9c2 66 c = 0;
yuto17320508 16:b232fd9ee9c2 67 }
yuto17320508 16:b232fd9ee9c2 68
yuto17320508 16:b232fd9ee9c2 69 if((ButtonState >> BUTTONDOWN)&1 == 1) {//対応するボタンを書く(今回下ボタン
yuto17320508 16:b232fd9ee9c2 70 d = 8;
yuto17320508 16:b232fd9ee9c2 71 } else {
yuto17320508 16:b232fd9ee9c2 72 d = 0;
yuto17320508 16:b232fd9ee9c2 73 }
yuto17320508 16:b232fd9ee9c2 74
yuto17320508 16:b232fd9ee9c2 75 if((ButtonState >> BUTTONL1)&1 == 1) {//対応するボタンを書く(今回L1ボタン
yuto17320508 16:b232fd9ee9c2 76 e = 16;
yuto17320508 16:b232fd9ee9c2 77 } else {
yuto17320508 16:b232fd9ee9c2 78 e = 0;
abcdefgh 13:3d7a8cb91eeb 79 }
yuto17320508 16:b232fd9ee9c2 80
yuto17320508 16:b232fd9ee9c2 81 if((ButtonState >> BUTTONL2)&1 == 1) {//対応するボタンを書く(今回L2ボタン
yuto17320508 16:b232fd9ee9c2 82 f = 32;
yuto17320508 16:b232fd9ee9c2 83 } else {
yuto17320508 16:b232fd9ee9c2 84 f = 0;
yuto17320508 16:b232fd9ee9c2 85 }
yuto17320508 16:b232fd9ee9c2 86
yuto17320508 16:b232fd9ee9c2 87 if((ButtonState >> BUTTONTRIANGEL)&1 == 1) {//対応するボタンを書く(今回△ボタン
yuto17320508 16:b232fd9ee9c2 88 g = 64;
yuto17320508 16:b232fd9ee9c2 89 } else {
yuto17320508 16:b232fd9ee9c2 90 g = 0;
yuto17320508 16:b232fd9ee9c2 91 }
yuto17320508 16:b232fd9ee9c2 92
yuto17320508 16:b232fd9ee9c2 93 if((ButtonState >> BUTTONCROSS)&1 == 1) {//対応するボタンを書く(今回×ボタン
yuto17320508 16:b232fd9ee9c2 94 h = 128;
yuto17320508 16:b232fd9ee9c2 95 } else {
yuto17320508 16:b232fd9ee9c2 96 h = 0;
yuto17320508 16:b232fd9ee9c2 97 }
yuto17320508 16:b232fd9ee9c2 98
yuto17320508 16:b232fd9ee9c2 99 if((ButtonState >> BUTTONR1)&1 == 1) {//対応するボタンを書く(今回R1ボタン
yuto17320508 16:b232fd9ee9c2 100 i = 256;
yuto17320508 16:b232fd9ee9c2 101 } else {
yuto17320508 16:b232fd9ee9c2 102 i = 0;
yuto17320508 16:b232fd9ee9c2 103 }
yuto17320508 16:b232fd9ee9c2 104
yuto17320508 16:b232fd9ee9c2 105 if((ButtonState >> BUTTONR2)&1 == 1) {//対応するボタンを書く(今回R2ボタン
yuto17320508 16:b232fd9ee9c2 106 j = 512;
yuto17320508 16:b232fd9ee9c2 107 } else {
yuto17320508 16:b232fd9ee9c2 108 j = 0;
yuto17320508 16:b232fd9ee9c2 109 }
yuto17320508 16:b232fd9ee9c2 110
yuto17320508 16:b232fd9ee9c2 111
yuto17320508 16:b232fd9ee9c2 112
yuto17320508 16:b232fd9ee9c2 113 send = a+b+c+d+e+f+g+h+i+j;
yuto17320508 16:b232fd9ee9c2 114
yuto17320508 16:b232fd9ee9c2 115 cs = 0;
yuto17320508 16:b232fd9ee9c2 116 spi. write(send);
yuto17320508 16:b232fd9ee9c2 117 cs = 1;
yuto17320508 16:b232fd9ee9c2 118 printf("%d\r\n",send);
yuto17320508 16:b232fd9ee9c2 119
yuto17320508 16:b232fd9ee9c2 120 }
hirokimineshita 0:736c76a75def 121 }