16 while (fSerial != NULL && fSerial->available())
19 fUARTRxBuff[fRXPos] = fSerial->read();
21 if (fRXPos == 0 && fUARTRxBuff[fRXPos] == 0xFE)
25 else if (fRXPos == 1 && fCmdType == 1)
27 fCmdLength = fUARTRxBuff[fRXPos];
29 else if (fRXPos == 2 && fCmdType == 1)
31 fCmdLength += (fUARTRxBuff[fRXPos] << 8);
34 else if (fCmdType == 0 && fUARTRxBuff[fRXPos] ==
'\n')
37 for (uint8_t i = 0; i < fRXPos; i ++ )
46 if ((fRXPos > 0 && fRXPos == fCmdLength + 11 && fCmdType) || (fRXPos > 1024))
48 filterCommand(fCmdLength, fUARTRxBuff);
62 return (fBTReceived) ? fBTAddress : NULL;
68 MSG_TYPE_CONNECTED = 0x01,
69 MSG_TYPE_DISCONNECTED = 0x02,
70 MSG_TYPE_ERROR = 0x03,
71 MSG_TYPE_DEVICE_POLL = 0x04,
72 MSG_TYPE_DEVICE_STRING = 0x05,
73 MSG_TYPE_DEVICE_INFO = 0x06,
74 MSG_TYPE_HID_INFO = 0x07,
75 MSG_TYPE_STARTUP = 0x08,
76 MSG_TYPE_BTADDRESS = 0x09
79 void filterCommand(
int buffLength,
unsigned char *msgbuffer)
81 static const char* deviceType[] = {
"UNKNOWN",
"POINTER",
"MOUSE",
"RESERVED",
"JOYSTICK",
"GAMEPAD",
"KEYBOARD",
"KEYPAD",
"MULTI_AXIS",
"SYSTEM"};
83 int cmdLength = buffLength;
84 unsigned char msgType = msgbuffer[3];
85 unsigned char devType = msgbuffer[4];
86 unsigned char device = msgbuffer[5];
87 unsigned char endpoint = msgbuffer[6];
88 unsigned char idVendorL = msgbuffer[7];
89 unsigned char idVendorH = msgbuffer[8];
90 unsigned char idProductL = msgbuffer[9];
91 unsigned char idProductH = msgbuffer[10];
94 case MSG_TYPE_CONNECTED:
98 case MSG_TYPE_DISCONNECTED:
108 case MSG_TYPE_DEVICE_POLL:
116 for (
int j = 0; j < 4; j++)
123 for (
int j = 0; j < cmdLength; j++)
131 case MSG_TYPE_DEVICE_STRING:
135 for (
int j = 0; j < cmdLength; j++)
139 case MSG_TYPE_DEVICE_INFO:
143 for (
int j = 0; j < cmdLength; j++)
151 case MSG_TYPE_HID_INFO:
155 for (
int j = 0; j < cmdLength; j++)
163 case MSG_TYPE_STARTUP:
166 case MSG_TYPE_BTADDRESS:
168 for (
int j = 0; j < cmdLength; j++)
171 if (j <
sizeof(fBTAddress))
172 fBTAddress[j] = msgbuffer[j + 11];
183 uint8_t fUARTRxBuff[1024];
185 unsigned fCmdLength = 0;
186 uint8_t fCmdType = 0;
187 uint8_t fBTAddress[6];
188 bool fBTReceived =
false;