ps3 with sbdbt
Dependents: NHK2019manualver2 NHK2019manualver2_10_3
PS3.cpp@1:feb844c4721e, 2016-08-15 (annotated)
- Committer:
- sgrsn
- Date:
- Mon Aug 15 04:52:14 2016 +0000
- Revision:
- 1:feb844c4721e
- Parent:
- 0:87f83956cb4c
- Child:
- 2:fe29007fb56c
rorikon_seikou_class_mae
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 | 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 | 1:feb844c4721e | 20 | while(Serial::getc() != 128) |
sgrsn | 1:feb844c4721e | 21 | { |
sgrsn | 1:feb844c4721e | 22 | } |
sgrsn | 1:feb844c4721e | 23 | for(int i = 1;i < 8;i++) |
sgrsn | 1:feb844c4721e | 24 | { |
sgrsn | 1:feb844c4721e | 25 | *(PS3Data+i) = Serial::getc(); |
sgrsn | 1:feb844c4721e | 26 | } |
sgrsn | 0:87f83956cb4c | 27 | } |
sgrsn | 0:87f83956cb4c | 28 | } |
sgrsn | 0:87f83956cb4c | 29 | bool PS3::getButtonState(int button) |
sgrsn | 0:87f83956cb4c | 30 | { |
sgrsn | 0:87f83956cb4c | 31 | return (*(PS3Data+(button>>4)) >> (button & 0x0f)) & 1; |
sgrsn | 0:87f83956cb4c | 32 | } |
sgrsn | 0:87f83956cb4c | 33 | double PS3::getRightJoystickAngle() |
sgrsn | 0:87f83956cb4c | 34 | { |
sgrsn | 0:87f83956cb4c | 35 | return atan2(double(PS3Data[6]*-1+64), double(PS3Data[5]-64))*double(180/PI); |
sgrsn | 0:87f83956cb4c | 36 | } |
sgrsn | 0:87f83956cb4c | 37 | double PS3::getLeftJoystickAngle() |
sgrsn | 0:87f83956cb4c | 38 | { |
sgrsn | 0:87f83956cb4c | 39 | return atan2(double(PS3Data[4]*-1+64), double(PS3Data[3]-64))*double(180/PI); |
sgrsn | 0:87f83956cb4c | 40 | } |