Beispiel #1
0
unsigned int
MainWindow::handleDataEvent(unsigned char *pData, unsigned int deviceID, unsigned int error)
{
	unsigned int result;
	char dataStr[256];

	sprintf(dataStr, "%02x %02x %02x %02x -- %02x %02x %02x %02x -- %02x %02x %02x %02x", 
		pData[0], pData[1], pData[2], pData[3], pData[4], pData[5], pData[6], pData[7], pData[8], pData[9], pData[10], pData[11]);

	// Append it to the end of the output box. This is done using a signal
	// which is connected to the output box because this function is
	// called from a different thread than the GUI is on.
	emit append(dataStr);

	// The output buffer
	unsigned char buffer[80];
	memset(buffer, 0, sizeof(buffer));

	//for Keyboard Reflect,
	if ((pData[3]&1) && keyboard==true) {
		//Sends keyboard commands as a native keyboard
		//Before pressing 1st key activate a Notepad or other text capturing application to see the results: Abcd
		
		buffer[0]=0;
		buffer[1]=201;
		buffer[2]=2; //modifiers Bit 1=Left Ctrl, bit 2=Left Shift, bit 3=Left Alt, bit 4=Left Gui, bit 5=Right Ctrl, bit 6=Right Shift, bit 7=Right Alt, bit 8=Right Gui.
		buffer[3]=0; //always 0
		buffer[4]=0x04; //1st hid code a, down
		buffer[5]=0; //2nd hid code
		buffer[6]=0; //3rd hid code
		buffer[7]=0; //4th hid code
		buffer[8]=0; //5th hid code
		buffer[9]=0; //6th hid code
		result = WriteData(handle, buffer);
		if (result != 0) {
			emit messageBox("Write Error", "Unable to write to Device.");
		}

		buffer[0]=0;
		buffer[1]=201;
		buffer[2]=0; //modifiers Bit 1=Left Ctrl, bit 2=Left Shift, bit 3=Left Alt, bit 4=Left Gui, bit 5=Right Ctrl, bit 6=Right Shift, bit 7=Right Alt, bit 8=Right Gui.
		buffer[3]=0; //always 0
		buffer[4]=0; //1st hid code a up
		buffer[5]=0x05; //2nd hid code b down
		buffer[6]=0x06; //3rd hid code c down
		buffer[7]=0x07; //4th hid code d down
		buffer[8]=0; //5th hid code
		buffer[9]=0; //6th hid code
		result = WriteData(handle, buffer);
		if (result != 0) {
			emit messageBox("Write Error", "Unable to write to Device.");
		}

		buffer[0]=0;
		buffer[1]=201;
		buffer[2]=0; //modifiers Bit 1=Left Ctrl, bit 2=Left Shift, bit 3=Left Alt, bit 4=Left Gui, bit 5=Right Ctrl, bit 6=Right Shift, bit 7=Right Alt, bit 8=Right Gui.
		buffer[3]=0; //always 0
		buffer[4]=0; //1st hid code 
		buffer[5]=0; //2nd hid code b up
		buffer[6]=0; //3rd hid code c up
		buffer[7]=0; //4th hid code d up
		buffer[8]=0; //5th hid code
		buffer[9]=0; //6th hid code
		result = WriteData(handle, buffer);
		if (result != 0) {
			emit messageBox("Write Error", "Unable to write to Device.");
		}
		keyboard=false;
	}
	
	//for Mouse Reflect, must be in PID #1 to function
	if (mouseon) {
		bool progsw = pData[3] & 1;
		if (progsw && !lastprogsw) //key down
		{
			memset(buffer, 0, sizeof(buffer));
			buffer[0]=0;
			buffer[1]=203;
			//play with these values to get various mouse functions; clicks, motion, scroll
			buffer[2]=1; //buttons 1=left, 2=right, 4=center, 8=XButton1 (browser back on my mouse), 16=XButton2
			buffer[3]=0; //X 128=0 no motion, 1-127 is right, 255-129=left, finest inc (1 and 255) to coarsest (127 and 129)
			buffer[4]=0; //Y 128=0 no motion, 1-127 is down, 255-129=up, finest inc (1 and 255) to coarsest (127 and 129)
			buffer[5]=0; //wheel X
			buffer[6]=0; //wheel Y 128=0 no motion, 1-127 is up, 255-129=down, finest inc (1 and 255) to coarsest (127 and 129)
			result = WriteData(handle, buffer);
			if (result != 0) {
				emit messageBox("Write Error", "Unable to write to Device.");
			}
		}
		else if (!progsw && lastprogsw==true) //key up
		{
			//send ups
			buffer[0]=0;
			buffer[1]=203;
			//play with these values to get various mouse functions; clicks, motion, scroll
			buffer[2]=0; //buttons 1=left, 2=right, 4=center, 8=XButton1 (browser back on my mouse), 16=XButton2
			buffer[3]=0; //X 128=0 no motion, 1-127 is right, 255-129=left, finest inc (1 and 255) to coarsest (127 and 129)
			buffer[4]=0; //Y 128=0 no motion, 1-127 is down, 255-129=up, finest inc (1 and 255) to coarsest (127 and 129)
			buffer[5]=0; //wheel X
			buffer[6]=0; //wheel Y 128=0 no motion, 1-127 is up, 255-129=down, finest inc (1 and 255) to coarsest (127 and 129)
			result = WriteData(handle, buffer);
			if (result != 0) {
				emit messageBox("Write Error", "Unable to write to Device.");
			}
		}
		lastprogsw=progsw;
	}

	if (joystick) {
		// Open up the game controller control panel to test these features,
		// after clicking this button go and make active the control panel
		// properties and change will occur available for PID #2 only.
		// In this example, the first 4 buttons on the device will
		// correspond to the first 4 buttons of the joystick.
		unsigned char buttons = ((pData[3] & 0x1) << 0) |
		                        ((pData[4] & 0x1) << 1) |
		                        ((pData[5] & 0x1) << 2) |
		                        ((pData[6] & 0x1) << 3);
		
		printf("Buttons %02hhx\n", buttons);

		unsigned int result;
		unsigned char buffer[80];
		memset(buffer, 0, sizeof(buffer));
		
		buffer[0]=0;
		buffer[1]=202;
		buffer[2]=128;  // X, 0 to 127 from center to right, 255 to 128 from center to left
		buffer[3]=128;  // Y, 0 to 127 from center down, 255 to 128 from center up
		buffer[4]=128;  // Z rot, 0 to 127 from center down, 255 to 128 from center up
		buffer[5]=128;  // Z, 0 to 127 from center down, 255 to 128 from center up
		buffer[6]=128;  // Slider, 0 to 127 from center down, 255 to 128 from center up
		
		buffer[7]=buttons;  // Game buttons as bitmap, bit 1= game button 1, bit 2=game button 2, etc., all buttons on
		buffer[8]=0;  // Game buttons as bitmap, bit 1= game button 1, bit 2=game button 2, etc., all buttons on
		buffer[9]=0;  // Game buttons as bitmap, bit 1= game button 1, bit 2=game button 2, etc., all buttons on
		buffer[10]=0; // Game buttons as bitmap, bit 1= game button 1, bit 2=game button 2, etc., all buttons on
		
		buffer[11]=0;

		buffer[12]=1; // Hat, 0 to 7 clockwise, 8=no hat

		result = WriteData(handle, buffer);

		if (result != 0) {
			QMessageBox::critical(this, "Write Error", "Unable to write to Device.");
		}
	}
	
	// Error handling
	if (error == PIE_HID_READ_INVALID_HANDLE)
	{
		CleanupInterface(handle);
		output_box->append("Device Disconnected");
	}

	return true;
}
Beispiel #2
0
DWORD WINAPI Execute(LPDWORD data)
{
	int i, linenumber;
	char line[256], buf[256], logbuf[100], *prog;
	BOOL error = FALSE;

	obj = NULL;
	light = NULL;

	ULONG arg[MAXARGS];

	InitInterface();

	for (i = 0; i < MAXARGS; i++)
		arg[i] = NULL;

	prog = ((THREAD_DATA *)data)->szProg;
	pDisplay = ((THREAD_DATA *)data)->pDisplay;
	strcpy(szIncludePath, "");
	strcpy(szPicturePath, "");

	linenumber = 0;
	nIncludeDepth = 0;

	while ((*prog || nIncludeDepth > 0) && !error)
	{ 
		GetLine(&prog, line, &linenumber);
		// read command first
		if (!Scan(line, buf, arg))
		{
			i = 0;
			// find command in list	
  			while (commands[i].name && stricmp(buf, commands[i].name))
  		 		i++;
				
			// call corresponding function with "arg" as argument
			if (commands[i].func)
				error = commands[i].func(arg);
			else
				error = ERROR_UNKNOWNCOM;
				
			for (i = 0; i < MAXARGS; i++)
			{
				if (arg[i])
					delete (ULONG *)arg[i];
				arg[i] = NULL;
			}

			if (error)
			{
				if (nIncludeDepth)
				{
					sprintf(logbuf, "In include file: \"%s\"", Includefile[nIncludeDepth].name);
					pDisplay->Log(logbuf);
					linenumber = Includefile[nIncludeDepth].linenumber;
				}
				sprintf(logbuf, "Error executing command in line %i", linenumber);
				pDisplay->Log(logbuf);
				pDisplay->Log(line);
				GetError(logbuf, error);
				pDisplay->Log(logbuf);
			}
		}
	}
	if (error)
	{
		pDisplay->Log("Error occurred");
		pDisplay->Log("Cancel execution");
		// close open include files
		while (nIncludeDepth > 0)
		{
			if (Includefile[nIncludeDepth].hFile)
				fclose(Includefile[nIncludeDepth].hFile);
			nIncludeDepth--;
		}
	}
	else
	{
		if (pDisplay->CheckCancel())
			pDisplay->Log("Execution canceled");
		else
			pDisplay->Log("Execution successful");
	}


	CleanupInterface();
	/*rsiCleanup(rc);
	rsiExit();*/

	return TRUE;
}