ps3 with sbdbt
PS3.cpp@4:12efe7905809, 2019-12-25 (annotated)
- Committer:
- shina
- Date:
- Wed Dec 25 06:17:06 2019 +0000
- Revision:
- 4:12efe7905809
- Parent:
- 3:5640aae53391
aaaaa;
Who changed what in which revision?
User | Revision | Line number | New 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; |
shina | 4:12efe7905809 | 14 | baud(115200); |
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 | 3:5640aae53391 | 51 | bool PS3::getSELECTState() |
sgrsn | 3:5640aae53391 | 52 | { |
sgrsn | 3:5640aae53391 | 53 | return getButtonState(migi) & getButtonState(hidari); |
sgrsn | 3:5640aae53391 | 54 | } |
sgrsn | 3:5640aae53391 | 55 | bool PS3::getSTARTState() |
sgrsn | 3:5640aae53391 | 56 | { |
sgrsn | 3:5640aae53391 | 57 | return getButtonState(ue) & getButtonState(sita); |
sgrsn | 3:5640aae53391 | 58 | } |
sgrsn | 2:fe29007fb56c | 59 | int PS3::getRightJoystickXaxis() |
sgrsn | 2:fe29007fb56c | 60 | { |
sgrsn | 2:fe29007fb56c | 61 | return (int)PS3Data[5]-64; |
sgrsn | 2:fe29007fb56c | 62 | } |
sgrsn | 2:fe29007fb56c | 63 | int PS3::getRightJoystickYaxis() |
sgrsn | 2:fe29007fb56c | 64 | { |
sgrsn | 2:fe29007fb56c | 65 | return (int)PS3Data[6]*-1+64; |
sgrsn | 2:fe29007fb56c | 66 | } |
sgrsn | 2:fe29007fb56c | 67 | int PS3::getLeftJoystickXaxis() |
sgrsn | 2:fe29007fb56c | 68 | { |
sgrsn | 2:fe29007fb56c | 69 | return (int)PS3Data[3]-64; |
sgrsn | 2:fe29007fb56c | 70 | } |
sgrsn | 2:fe29007fb56c | 71 | int PS3::getLeftJoystickYaxis() |
sgrsn | 2:fe29007fb56c | 72 | { |
sgrsn | 2:fe29007fb56c | 73 | return (int)PS3Data[4]*-1+64; |
sgrsn | 2:fe29007fb56c | 74 | } |
sgrsn | 0:87f83956cb4c | 75 | double PS3::getRightJoystickAngle() |
sgrsn | 0:87f83956cb4c | 76 | { |
sgrsn | 0:87f83956cb4c | 77 | return atan2(double(PS3Data[6]*-1+64), double(PS3Data[5]-64))*double(180/PI); |
sgrsn | 0:87f83956cb4c | 78 | } |
sgrsn | 0:87f83956cb4c | 79 | double PS3::getLeftJoystickAngle() |
sgrsn | 0:87f83956cb4c | 80 | { |
sgrsn | 0:87f83956cb4c | 81 | return atan2(double(PS3Data[4]*-1+64), double(PS3Data[3]-64))*double(180/PI); |
sgrsn | 0:87f83956cb4c | 82 | } |
sgrsn | 3:5640aae53391 | 83 | void PS3::printdata() |
sgrsn | 3:5640aae53391 | 84 | { |
sgrsn | 3:5640aae53391 | 85 | Serial pc(USBTX, USBRX); |
sgrsn | 3:5640aae53391 | 86 | for(int i = 0; i < 8; i++) |
sgrsn | 3:5640aae53391 | 87 | { |
sgrsn | 3:5640aae53391 | 88 | pc.printf("%4d", PS3Data[i]); |
sgrsn | 3:5640aae53391 | 89 | } |
sgrsn | 3:5640aae53391 | 90 | } |
sgrsn | 2:fe29007fb56c | 91 | |
sgrsn | 3:5640aae53391 | 92 | |
sgrsn | 3:5640aae53391 | 93 |