NagaokaRoboticsClub_mbedTeam
/
2022A_FEPRX_TokiPS4
FEP RX program TokiPS4
main.cpp@0:c2cc8f4e2ba0, 2022-10-08 (annotated)
- Committer:
- watarushimoda
- Date:
- Sat Oct 08 10:20:18 2022 +0000
- Revision:
- 0:c2cc8f4e2ba0
FEP RX program TokiPS4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
watarushimoda | 0:c2cc8f4e2ba0 | 1 | //PS4コントローラーにしわき拡張版 |
watarushimoda | 0:c2cc8f4e2ba0 | 2 | #include "FEP_RX22.h" |
watarushimoda | 0:c2cc8f4e2ba0 | 3 | #include "pinconfig.h" |
watarushimoda | 0:c2cc8f4e2ba0 | 4 | #include <cmath> |
watarushimoda | 0:c2cc8f4e2ba0 | 5 | |
watarushimoda | 0:c2cc8f4e2ba0 | 6 | FEP_RX22 mycon(fepTX, fepRX, fepad); |
watarushimoda | 0:c2cc8f4e2ba0 | 7 | Serial pc(pcTX, pcRX, 115200); |
watarushimoda | 0:c2cc8f4e2ba0 | 8 | |
watarushimoda | 0:c2cc8f4e2ba0 | 9 | int main() |
watarushimoda | 0:c2cc8f4e2ba0 | 10 | { |
watarushimoda | 0:c2cc8f4e2ba0 | 11 | mycon.StartReceive(); |
watarushimoda | 0:c2cc8f4e2ba0 | 12 | uint8_t b[16]; |
watarushimoda | 0:c2cc8f4e2ba0 | 13 | int16_t stick[4]; |
watarushimoda | 0:c2cc8f4e2ba0 | 14 | int16_t trigger[4]; |
watarushimoda | 0:c2cc8f4e2ba0 | 15 | int16_t volume[3]; |
watarushimoda | 0:c2cc8f4e2ba0 | 16 | uint8_t toggle[4]; |
watarushimoda | 0:c2cc8f4e2ba0 | 17 | uint8_t timeout; |
watarushimoda | 0:c2cc8f4e2ba0 | 18 | uint8_t data[128]; |
watarushimoda | 0:c2cc8f4e2ba0 | 19 | int pw; |
watarushimoda | 0:c2cc8f4e2ba0 | 20 | while(1) { |
watarushimoda | 0:c2cc8f4e2ba0 | 21 | |
watarushimoda | 0:c2cc8f4e2ba0 | 22 | #if ControllerMode |
watarushimoda | 0:c2cc8f4e2ba0 | 23 | for (int i=0; i<16; i++) b[i] = mycon.getButton(i); |
watarushimoda | 0:c2cc8f4e2ba0 | 24 | for (int i=0; i<4; i++) stick[i] = mycon.getStick(i); |
watarushimoda | 0:c2cc8f4e2ba0 | 25 | for (int i=0; i<2; i++) trigger[i] = mycon.getTrigger(i); |
watarushimoda | 0:c2cc8f4e2ba0 | 26 | |
watarushimoda | 0:c2cc8f4e2ba0 | 27 | for (int i=0; i<16; i++) pc.printf("%d ", b[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 28 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 29 | for (int i=0; i<4; i++) pc.printf("%3d ", stick[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 30 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 31 | for (int i=0; i<2; i++) pc.printf("%3d ", trigger[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 32 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 33 | #else |
watarushimoda | 0:c2cc8f4e2ba0 | 34 | mycon.getData(data); |
watarushimoda | 0:c2cc8f4e2ba0 | 35 | for (int i=0, tmp=1; i<8; i++) { |
watarushimoda | 0:c2cc8f4e2ba0 | 36 | pw = pow((float)2,i); |
watarushimoda | 0:c2cc8f4e2ba0 | 37 | b[i] = (int)((data[0] & tmp)/pw); |
watarushimoda | 0:c2cc8f4e2ba0 | 38 | pc.printf("%d ", b[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 39 | tmp *= 2; |
watarushimoda | 0:c2cc8f4e2ba0 | 40 | } |
watarushimoda | 0:c2cc8f4e2ba0 | 41 | for (int i=8, tmp=1, j=0; i<16; i++, j++) { |
watarushimoda | 0:c2cc8f4e2ba0 | 42 | pw = pow((float)2,j); |
watarushimoda | 0:c2cc8f4e2ba0 | 43 | b[i] = (int)((data[1] & tmp)/pw); |
watarushimoda | 0:c2cc8f4e2ba0 | 44 | pc.printf("%d ", b[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 45 | tmp *= 2; |
watarushimoda | 0:c2cc8f4e2ba0 | 46 | } |
watarushimoda | 0:c2cc8f4e2ba0 | 47 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 48 | |
watarushimoda | 0:c2cc8f4e2ba0 | 49 | for (int i=0; i<4; i++) { |
watarushimoda | 0:c2cc8f4e2ba0 | 50 | stick[i] = data[i+2]; |
watarushimoda | 0:c2cc8f4e2ba0 | 51 | pc.printf("%3d ", stick[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 52 | } |
watarushimoda | 0:c2cc8f4e2ba0 | 53 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 54 | |
watarushimoda | 0:c2cc8f4e2ba0 | 55 | for (int i=0; i<2; i++) { |
watarushimoda | 0:c2cc8f4e2ba0 | 56 | trigger[i] = data[i+6]; |
watarushimoda | 0:c2cc8f4e2ba0 | 57 | pc.printf("%3d ", trigger[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 58 | } |
watarushimoda | 0:c2cc8f4e2ba0 | 59 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 60 | |
watarushimoda | 0:c2cc8f4e2ba0 | 61 | for (int i=0; i<3; i++) { |
watarushimoda | 0:c2cc8f4e2ba0 | 62 | volume[i] = data[i+9]; |
watarushimoda | 0:c2cc8f4e2ba0 | 63 | pc.printf("%3d ", volume[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 64 | } |
watarushimoda | 0:c2cc8f4e2ba0 | 65 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 66 | |
watarushimoda | 0:c2cc8f4e2ba0 | 67 | for (int i=0; i<4; i++) { |
watarushimoda | 0:c2cc8f4e2ba0 | 68 | toggle[i] = data[i+12]; |
watarushimoda | 0:c2cc8f4e2ba0 | 69 | pc.printf("%3d ", toggle[i]); |
watarushimoda | 0:c2cc8f4e2ba0 | 70 | } |
watarushimoda | 0:c2cc8f4e2ba0 | 71 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 72 | |
watarushimoda | 0:c2cc8f4e2ba0 | 73 | timeout = data[8]; |
watarushimoda | 0:c2cc8f4e2ba0 | 74 | pc.printf("%3d ", timeout); |
watarushimoda | 0:c2cc8f4e2ba0 | 75 | pc.printf(" | "); |
watarushimoda | 0:c2cc8f4e2ba0 | 76 | |
watarushimoda | 0:c2cc8f4e2ba0 | 77 | #endif |
watarushimoda | 0:c2cc8f4e2ba0 | 78 | if (mycon.getStatus()) pc.printf("received\r\n"); |
watarushimoda | 0:c2cc8f4e2ba0 | 79 | else pc.printf("anything error...\r\n"); |
watarushimoda | 0:c2cc8f4e2ba0 | 80 | |
watarushimoda | 0:c2cc8f4e2ba0 | 81 | } |
watarushimoda | 0:c2cc8f4e2ba0 | 82 | } |