76 | | case 0: |
77 | | if (data == 0xaa) state++; |
78 | | break; |
79 | | case 1: |
80 | | if (data == 0x00) state++; |
81 | | else { |
82 | | counter = 0; |
83 | | state = 0; |
| 76 | case 0: |
| 77 | if (data == 0xaa) { |
| 78 | state++; |
| 79 | } |
| 80 | break; |
| 81 | case 1: |
| 82 | if (data == 0x00) { |
| 83 | state++; |
| 84 | } |
| 85 | else { |
| 86 | counter = 0; |
| 87 | state = 0; |
| 88 | } |
| 89 | break; |
| 90 | case 2: |
| 91 | buffer[counter++] = data; |
| 92 | if (counter >= 13) { |
| 93 | int sum = 0; |
| 94 | for (int i = 0; i < 11; i++) sum += buffer[i]; |
| 95 | if ((sum & 0xff) == buffer[12]) { |
| 96 | lcd.clear(); |
| 97 | disp5(0, 0, "A:", (buffer[2] << 8) | buffer[1]); // angle |
| 98 | disp5(0, 1, "X:", (buffer[6] << 8) | buffer[5]); // accX |
| 99 | disp5(9, 1, "Y:", (buffer[8] << 8) | buffer[7]); // accY |
| 100 | disp5(9, 0, "Z:", (buffer[10] << 8) | buffer[9]); // accZ |
| 101 | delay(100); |
| 102 | Serial.flush(); |
85 | | break; |
86 | | case 2: |
87 | | buffer[counter++] = data; |
88 | | if (counter >= 13) { |
89 | | int sum = 0; |
90 | | for (int i = 0;i < 11;i++) sum += buffer[i]; |
91 | | if ((sum & 0xff) == buffer[12]) { |
92 | | lcd.clear(); |
93 | | disp5(0, 0, "A:", (buffer[2] << 8) | buffer[1]); // angle |
94 | | disp5(0, 1, "X:", (buffer[6] << 8) | buffer[5]); // accX |
95 | | disp5(9, 1, "Y:", (buffer[8] << 8) | buffer[7]); // accY |
96 | | disp5(9, 0, "Z:", (buffer[10] << 8) | buffer[9]); // accZ |
97 | | delay(100); |
98 | | Serial.flush(); |
99 | | } |
100 | | state = 0; |
101 | | counter = 0; |
102 | | } |
103 | | break; |
| 104 | state = 0; |
| 105 | counter = 0; |
| 106 | } |
| 107 | break; |