ps3 with sbdbt

Dependents:   NHK2019manualver2 NHK2019manualver2_10_3

Committer:
sgrsn
Date:
Mon Sep 26 10:28:39 2016 +0000
Revision:
2:fe29007fb56c
Parent:
1:feb844c4721e
Child:
3:5640aae53391
be able to add function in serial attach

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sgrsn 0:87f83956cb4c 1 #include "PS3.h"
sgrsn 0:87f83956cb4c 2
sgrsn 0:87f83956cb4c 3 PS3::PS3(PinName TX, PinName RX) : Serial(TX, RX)
sgrsn 0:87f83956cb4c 4 {
sgrsn 0:87f83956cb4c 5 PS3Data[0] = 128;
sgrsn 0:87f83956cb4c 6 PS3Data[1] = 0;
sgrsn 0:87f83956cb4c 7 PS3Data[2] = 0;
sgrsn 0:87f83956cb4c 8 PS3Data[3] = 64;
sgrsn 0:87f83956cb4c 9 PS3Data[4] = 64;
sgrsn 0:87f83956cb4c 10 PS3Data[5] = 64;
sgrsn 0:87f83956cb4c 11 PS3Data[6] = 64;
sgrsn 0:87f83956cb4c 12 PS3Data[7] = 0;
sgrsn 2:fe29007fb56c 13 addflag = 0;
sgrsn 0:87f83956cb4c 14 baud(2400);
sgrsn 2:fe29007fb56c 15 Serial::attach(this, &PS3::getdata, Serial::RxIrq);
sgrsn 0:87f83956cb4c 16 }
sgrsn 0:87f83956cb4c 17 void PS3::getdata()
sgrsn 0:87f83956cb4c 18 {
sgrsn 0:87f83956cb4c 19 if(Serial::readable())
sgrsn 0:87f83956cb4c 20 {
sgrsn 1:feb844c4721e 21 while(Serial::getc() != 128)
sgrsn 1:feb844c4721e 22 {
sgrsn 1:feb844c4721e 23 }
sgrsn 1:feb844c4721e 24 for(int i = 1;i < 8;i++)
sgrsn 1:feb844c4721e 25 {
sgrsn 1:feb844c4721e 26 *(PS3Data+i) = Serial::getc();
sgrsn 1:feb844c4721e 27 }
sgrsn 0:87f83956cb4c 28 }
sgrsn 2:fe29007fb56c 29 if(addflag)
sgrsn 2:fe29007fb56c 30 (*fpFunc)();
sgrsn 0:87f83956cb4c 31 }
sgrsn 2:fe29007fb56c 32 void PS3::myattach()
sgrsn 2:fe29007fb56c 33 {
sgrsn 2:fe29007fb56c 34 Serial::attach(this, &PS3::getdata, Serial::RxIrq);
sgrsn 2:fe29007fb56c 35 }
sgrsn 2:fe29007fb56c 36
sgrsn 2:fe29007fb56c 37 void PS3::addattach(void (*Func)())
sgrsn 2:fe29007fb56c 38 {
sgrsn 2:fe29007fb56c 39 fpFunc = Func;
sgrsn 2:fe29007fb56c 40 addflag = 1;
sgrsn 2:fe29007fb56c 41 }
sgrsn 2:fe29007fb56c 42
sgrsn 2:fe29007fb56c 43 void PS3::nothingFunc()
sgrsn 2:fe29007fb56c 44 {
sgrsn 2:fe29007fb56c 45 }
sgrsn 2:fe29007fb56c 46
sgrsn 0:87f83956cb4c 47 bool PS3::getButtonState(int button)
sgrsn 0:87f83956cb4c 48 {
sgrsn 0:87f83956cb4c 49 return (*(PS3Data+(button>>4)) >> (button & 0x0f)) & 1;
sgrsn 0:87f83956cb4c 50 }
sgrsn 2:fe29007fb56c 51 int PS3::getRightJoystickXaxis()
sgrsn 2:fe29007fb56c 52 {
sgrsn 2:fe29007fb56c 53 return (int)PS3Data[5]-64;
sgrsn 2:fe29007fb56c 54 }
sgrsn 2:fe29007fb56c 55 int PS3::getRightJoystickYaxis()
sgrsn 2:fe29007fb56c 56 {
sgrsn 2:fe29007fb56c 57 return (int)PS3Data[6]*-1+64;
sgrsn 2:fe29007fb56c 58 }
sgrsn 2:fe29007fb56c 59 int PS3::getLeftJoystickXaxis()
sgrsn 2:fe29007fb56c 60 {
sgrsn 2:fe29007fb56c 61 return (int)PS3Data[3]-64;
sgrsn 2:fe29007fb56c 62 }
sgrsn 2:fe29007fb56c 63 int PS3::getLeftJoystickYaxis()
sgrsn 2:fe29007fb56c 64 {
sgrsn 2:fe29007fb56c 65 return (int)PS3Data[4]*-1+64;
sgrsn 2:fe29007fb56c 66 }
sgrsn 0:87f83956cb4c 67 double PS3::getRightJoystickAngle()
sgrsn 0:87f83956cb4c 68 {
sgrsn 0:87f83956cb4c 69 return atan2(double(PS3Data[6]*-1+64), double(PS3Data[5]-64))*double(180/PI);
sgrsn 0:87f83956cb4c 70 }
sgrsn 0:87f83956cb4c 71 double PS3::getLeftJoystickAngle()
sgrsn 0:87f83956cb4c 72 {
sgrsn 0:87f83956cb4c 73 return atan2(double(PS3Data[4]*-1+64), double(PS3Data[3]-64))*double(180/PI);
sgrsn 0:87f83956cb4c 74 }
sgrsn 2:fe29007fb56c 75