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.
PS3.cpp
- Committer:
- sgrsn
- Date:
- 2016-05-10
- Revision:
- 0:87f83956cb4c
- Child:
- 1:feb844c4721e
File content as of revision 0:87f83956cb4c:
#include "PS3.h"
PS3::PS3(PinName TX, PinName RX) : Serial(TX, RX)
{
PS3Data[0] = 128;
PS3Data[1] = 0;
PS3Data[2] = 0;
PS3Data[3] = 64;
PS3Data[4] = 64;
PS3Data[5] = 64;
PS3Data[6] = 64;
PS3Data[7] = 0;
baud(2400);
attach(this, &PS3::getdata, Serial::RxIrq);
}
void PS3::getdata()
{
if(Serial::readable())
{
for(int i = 0;i < 8;i++)
*(PS3Data+i) = Serial::getc();
}
}
bool PS3::getButtonState(int button)
{
return (*(PS3Data+(button>>4)) >> (button & 0x0f)) & 1;
}
double PS3::getRightJoystickAngle()
{
return atan2(double(PS3Data[6]*-1+64), double(PS3Data[5]-64))*double(180/PI);
}
double PS3::getLeftJoystickAngle()
{
return atan2(double(PS3Data[4]*-1+64), double(PS3Data[3]-64))*double(180/PI);
}