int main(void) { uchar i = 1; uchar hidCurrentMode = 255; char remainingData=0; uchar offset=0; HardwareInit(); usbInit(); // Set up descriptor hidMode = HIDM_1P; ReadController(1); SetHIDMode(); for(;;){ /* main event loop */ usbPoll(); if(usbInterruptIsReady()){ /* called after every poll of the interrupt endpoint */ ReadController(i); RemapButtons(&(reportBuffer.b1), &(reportBuffer.b2)); RemapButtons(&(reportBufferWheel.b1), &(reportBufferWheel.b2)); remainingData=reportBufferLength; offset=0; // handle report with more than 8 byte length (for NegCon and future expansion) do { if (remainingData<=8) { usbSetInterrupt(reportBufferAddress+offset, remainingData); remainingData=0; } else { usbSetInterrupt(reportBufferAddress+offset, 8); offset+=8; remainingData-=8; do { usbPoll(); } while (!usbInterruptIsReady()); } } while (remainingData>0); i++; if (i > hidNumReports) i = 1; if (hidCurrentMode != hidMode) { SetHIDMode(); hidCurrentMode = hidMode; } } } return 0; }
int main(void) { uchar i = 1; uchar hidCurrentMode = 255; char remainingData=0; uchar offset=0; HardwareInit(); usbInit(); // Set up descriptor hidMode = HIDM_1P; ReadController(1); SetHIDMode(); // uchar j = 1; //for speed test only for(;;){ /* main event loop */ usbPoll(); if(usbInterruptIsReady()){ /* called after every poll of the interrupt endpoint */ ReadController(i); switch (hidCurrentMode) { case HIDM_1P: RemapController(&(reportBuffer.x), &(reportBuffer.y), &(reportBuffer.rx), &(reportBuffer.ry), &(reportBuffer.b1), &(reportBuffer.b2)); break; case HIDM_2P: RemapController(&(reportBuffer.x), &(reportBuffer.y), &(reportBuffer.rx), &(reportBuffer.ry), &(reportBuffer.b1), &(reportBuffer.b2)); break; case HIDM_NEGCON: RemapController(&(reportBufferNegCon.x), &(reportBufferNegCon.y), &(reportBufferNegCon.rx), &(reportBufferNegCon.ry), &(reportBufferNegCon.b1), &(reportBufferNegCon.b2)); break; } remainingData=reportBufferLength; offset=0; // For speed test, uncommnent the next three lines and the line "uchar j=0" above // reportBuffer.x=(j%4)*10; //for speed test only // reportBufferNegCon.x=(j%4)*10; //for speed test only // j++; //for speed test only // handle report with more than 8 byte length (for NegCon and future expansion) do { if (remainingData<=8) { usbSetInterrupt(reportBufferAddress+offset, remainingData); remainingData=0; } else { usbSetInterrupt(reportBufferAddress+offset, 8); offset+=8; remainingData-=8; do { usbPoll(); } while (!usbInterruptIsReady()); } } while (remainingData>0); i++; if (i > hidNumReports) i = 1; if (hidCurrentMode != hidMode) { SetHIDMode(); hidCurrentMode = hidMode; } } } return 0; }