コード例 #1
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();

    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;
}
コード例 #2
0
void __fastcall TransformRemap(REMAP *remap, XINPUT_STATE* pState)
{
	GAMEPAD gamepad;

	gamepad.buttons = RemapButtons(remap, &pState->Gamepad);

	gamepad.triggerL = RemapGetValue(&remap[Gamepad::LEFT_TRIGGER], &pState->Gamepad);
	gamepad.triggerR = RemapGetValue(&remap[Gamepad::RIGHT_TRIGGER], &pState->Gamepad);

	gamepad.analogLX = RemapGetValue(&remap[Gamepad::THUMB_LX_P], &pState->Gamepad) - 
		               RemapGetValue(&remap[Gamepad::THUMB_LX_M], &pState->Gamepad);
	gamepad.analogLY = RemapGetValue(&remap[Gamepad::THUMB_LY_P], &pState->Gamepad) - 
		               RemapGetValue(&remap[Gamepad::THUMB_LY_M], &pState->Gamepad);
	gamepad.analogRX = RemapGetValue(&remap[Gamepad::THUMB_RX_P], &pState->Gamepad) - 
		               RemapGetValue(&remap[Gamepad::THUMB_RX_M], &pState->Gamepad);
	gamepad.analogRY = RemapGetValue(&remap[Gamepad::THUMB_RY_P], &pState->Gamepad) - 
		               RemapGetValue(&remap[Gamepad::THUMB_RY_M], &pState->Gamepad);

	pState->Gamepad.wButtons = gamepad.buttons;

	pState->Gamepad.bLeftTrigger = gamepad.triggerL;
	pState->Gamepad.bRightTrigger = gamepad.triggerR;

	pState->Gamepad.sThumbLX = gamepad.analogLX;
	pState->Gamepad.sThumbLY = gamepad.analogLY;
	pState->Gamepad.sThumbRX = gamepad.analogRX;
	pState->Gamepad.sThumbRY = gamepad.analogRY;
}