ps3 with sbdbt
Diff: PS3.cpp
- Revision:
- 2:fe29007fb56c
- Parent:
- 1:feb844c4721e
- Child:
- 3:5640aae53391
--- a/PS3.cpp Mon Aug 15 04:52:14 2016 +0000 +++ b/PS3.cpp Mon Sep 26 10:28:39 2016 +0000 @@ -10,8 +10,9 @@ PS3Data[5] = 64; PS3Data[6] = 64; PS3Data[7] = 0; + addflag = 0; baud(2400); - attach(this, &PS3::getdata, Serial::RxIrq); + Serial::attach(this, &PS3::getdata, Serial::RxIrq); } void PS3::getdata() { @@ -25,11 +26,44 @@ *(PS3Data+i) = Serial::getc(); } } + if(addflag) + (*fpFunc)(); } +void PS3::myattach() +{ + Serial::attach(this, &PS3::getdata, Serial::RxIrq); +} + +void PS3::addattach(void (*Func)()) +{ + fpFunc = Func; + addflag = 1; +} + +void PS3::nothingFunc() +{ +} + bool PS3::getButtonState(int button) { return (*(PS3Data+(button>>4)) >> (button & 0x0f)) & 1; } +int PS3::getRightJoystickXaxis() +{ + return (int)PS3Data[5]-64; +} +int PS3::getRightJoystickYaxis() +{ + return (int)PS3Data[6]*-1+64; +} +int PS3::getLeftJoystickXaxis() +{ + return (int)PS3Data[3]-64; +} +int PS3::getLeftJoystickYaxis() +{ + return (int)PS3Data[4]*-1+64; +} double PS3::getRightJoystickAngle() { return atan2(double(PS3Data[6]*-1+64), double(PS3Data[5]-64))*double(180/PI); @@ -38,3 +72,4 @@ { return atan2(double(PS3Data[4]*-1+64), double(PS3Data[3]-64))*double(180/PI); } +