예제 #1
0
void loop() {
	int8_t r = 0;
	uint8_t offset = 0;
	while (1) {
		// if we received data, do something with it
		r = usb_gamepad_read();
		if (r > 0) {
			offset = 0;
			while (offset < r) {
				uint8_t cmd = receiveBuffer[offset];
				uint8_t val = receiveBuffer[offset + 1];
				switch (cmd) {
					case 0x01:
					// 1 - drive board command
					PORTA = val;
					break;
					case 0x02:
					// 2 - lamp data
					PORTB = val;
					break;
				}
				offset+=3;
			}
		}

		// read data
		getControllerData();
		
		// finally, we send the data out via the USB port
		usb_gamepad_send();
	}
		
}
예제 #2
0
bool TFarmStuff::testConnectionToController() {
  QString hostName;
  QString ipAddr;
  int port;

  getControllerData(hostName, ipAddr, port);
  return doTestConnection(hostName, ipAddr, port);
}
int main(int argc, _TCHAR* argv[])
{
	struct ControllerStruct
	{
		unsigned long eventCount; //event counter, increases with every controller event,
					  //but for some reason not by one.
		unsigned short up:1, down:1, left:1, right:1, start:1, back:1, l3:1, r3:1,
                       lButton:1, rButton:1, guideButton:1, unknown:1, aButton:1,
                       bButton:1, xButton:1, yButton:1; // button state bitfield
		unsigned char lTrigger;  //Left Trigger
		unsigned char rTrigger;  //Right Trigger
		short lJoyY;  //Left Joystick Y
		short lJoyx;  //Left Joystick X
		short rJoyY;  //Right Joystick Y 
		short rJoyX;  //Right Joystick X
	};
	//First create an HINSTANCE of the xinput1_3.dll.  Probably should use system variables to find it
	//but whatever.
	HINSTANCE hGetProcIDDLL = LoadLibrary("C:/Windows/System32/xinput1_3.dll");  //In Visual Studio replace this
	//HINSTANCE hGetProcIDDLL = LoadLibrary(L"C:/Windows/System32/xinput1_3.dll");  //With this

	//Get the address of ordinal 100.
	FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), (LPCSTR)100);

	//typedef the function. It takes an int and a pointer to a ControllerStruct and returns an error code
	//as an int.  it's 0 for no error and 1167 for "controller not present".  presumably there are others
	//but I never saw them.  It won't cause a crash on error, it just won't update the data.
	typedef int(__stdcall * pICFUNC)(int, ControllerStruct &);

	//Assign it to getControllerData for easier use
	pICFUNC getControllerData;
	getControllerData = pICFUNC(lpfnGetProcessID);
	
	//Create in an instance of the ControllerStruct
	ControllerStruct buttons;
	while(1) //Infinite polling loop
	{

		getControllerData(0, buttons);  //call the function with the controller number(zero based) and
						//the pointer to the ControllerStruct.
		ClearScreen();  //clear the screen
		std::cout << buttons.guideButton;  //simply access the variable like normal.  Easy peasy.
		Sleep(50);  //pause briefly so as not to spam the console
	}
	//in a real program you should release the dll by calling FreeLibrary(hGetProcIDDLL) to prevent memory
	//leaks, but since there's no way of cleanly exiting this program, I'm not sure where to put it
	
	return 0;
}