ps3 with sbdbt

Dependents:   omuni

Committer:
sgrsn
Date:
Tue May 10 08:18:54 2016 +0000
Revision:
0:87f83956cb4c
Child:
1:feb844c4721e
ps3 with sbdbt

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 0:87f83956cb4c 13 baud(2400);
sgrsn 0:87f83956cb4c 14 attach(this, &PS3::getdata, Serial::RxIrq);
sgrsn 0:87f83956cb4c 15 }
sgrsn 0:87f83956cb4c 16 void PS3::getdata()
sgrsn 0:87f83956cb4c 17 {
sgrsn 0:87f83956cb4c 18 if(Serial::readable())
sgrsn 0:87f83956cb4c 19 {
sgrsn 0:87f83956cb4c 20 for(int i = 0;i < 8;i++)
sgrsn 0:87f83956cb4c 21 *(PS3Data+i) = Serial::getc();
sgrsn 0:87f83956cb4c 22 }
sgrsn 0:87f83956cb4c 23 }
sgrsn 0:87f83956cb4c 24 bool PS3::getButtonState(int button)
sgrsn 0:87f83956cb4c 25 {
sgrsn 0:87f83956cb4c 26 return (*(PS3Data+(button>>4)) >> (button & 0x0f)) & 1;
sgrsn 0:87f83956cb4c 27 }
sgrsn 0:87f83956cb4c 28 double PS3::getRightJoystickAngle()
sgrsn 0:87f83956cb4c 29 {
sgrsn 0:87f83956cb4c 30 return atan2(double(PS3Data[6]*-1+64), double(PS3Data[5]-64))*double(180/PI);
sgrsn 0:87f83956cb4c 31 }
sgrsn 0:87f83956cb4c 32 double PS3::getLeftJoystickAngle()
sgrsn 0:87f83956cb4c 33 {
sgrsn 0:87f83956cb4c 34 return atan2(double(PS3Data[4]*-1+64), double(PS3Data[3]-64))*double(180/PI);
sgrsn 0:87f83956cb4c 35 }