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.
Dependents: NHK2019robokon_10_26 NHK2019robokon_10_30 NHK2019robokon_11_18 NHK2019robokon_11_19 ... more
PS3.cpp
00001 #include "PS3.h" 00002 00003 PS3::PS3(PinName TX, PinName RX) : Serial(TX, RX) 00004 { 00005 PS3Data[0] = 128; 00006 PS3Data[1] = 0; 00007 PS3Data[2] = 0; 00008 PS3Data[3] = 64; 00009 PS3Data[4] = 64; 00010 PS3Data[5] = 64; 00011 PS3Data[6] = 64; 00012 PS3Data[7] = 0; 00013 addflag = 0; 00014 baud(115200); 00015 Serial::attach(this, &PS3::getdata, Serial::RxIrq); 00016 } 00017 void PS3::getdata() 00018 { 00019 if(Serial::readable()) 00020 { 00021 while(Serial::getc() != 128) 00022 { 00023 } 00024 for(int i = 1;i < 8;i++) 00025 { 00026 *(PS3Data+i) = Serial::getc(); 00027 } 00028 } 00029 if(addflag) 00030 (*fpFunc)(); 00031 } 00032 void PS3::myattach() 00033 { 00034 Serial::attach(this, &PS3::getdata, Serial::RxIrq); 00035 } 00036 00037 void PS3::addattach(void (*Func)()) 00038 { 00039 fpFunc = Func; 00040 addflag = 1; 00041 } 00042 00043 void PS3::nothingFunc() 00044 { 00045 } 00046 00047 bool PS3::getButtonState(int button) 00048 { 00049 return (*(PS3Data+(button>>4)) >> (button & 0x0f)) & 1; 00050 } 00051 bool PS3::getSELECTState() 00052 { 00053 return getButtonState(migi) & getButtonState(hidari); 00054 } 00055 bool PS3::getSTARTState() 00056 { 00057 return getButtonState(ue) & getButtonState(sita); 00058 } 00059 int PS3::getRightJoystickXaxis() 00060 { 00061 return (int)PS3Data[5]-64; 00062 } 00063 int PS3::getRightJoystickYaxis() 00064 { 00065 return (int)PS3Data[6]*-1+64; 00066 } 00067 int PS3::getLeftJoystickXaxis() 00068 { 00069 return (int)PS3Data[3]-64; 00070 } 00071 int PS3::getLeftJoystickYaxis() 00072 { 00073 return (int)PS3Data[4]*-1+64; 00074 } 00075 double PS3::getRightJoystickAngle() 00076 { 00077 return atan2(double(PS3Data[6]*-1+64), double(PS3Data[5]-64))*double(180/PI); 00078 } 00079 double PS3::getLeftJoystickAngle() 00080 { 00081 return atan2(double(PS3Data[4]*-1+64), double(PS3Data[3]-64))*double(180/PI); 00082 } 00083 void PS3::printdata() 00084 { 00085 Serial pc(USBTX, USBRX); 00086 for(int i = 0; i < 8; i++) 00087 { 00088 pc.printf("%4d", PS3Data[i]); 00089 } 00090 } 00091 00092 00093
Generated on Sat Aug 20 2022 22:47:43 by
1.7.2