Пример #1
0
LRESULT CALLBACK edit_action_dlg(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
	print_msg(message,lParam,wParam);
	switch(message)
	{
	case WM_SHOWWINDOW:
		break;
	case WM_INITDIALOG:
		SendMessage(GetDlgItem(hwnd,IDC_ACTION_NAME),EM_SETLIMITTEXT,200,0);
		{
		TCITEMA tc;
		HWND hctrl;
		hctrl=GetDlgItem(hwnd,IDC_TAB1);
		tc.mask=TCIF_TEXT;
		tc.pszText="Simple";
		TabCtrl_InsertItem(hctrl,0,&tc);
		tc.mask=TCIF_TEXT;
		tc.pszText="Script";
		TabCtrl_InsertItem(hctrl,1,&tc);
		switch_tab_controls(0,0);
		switch_tab_controls(hwnd,TabCtrl_GetCurSel(GetDlgItem(hwnd,IDC_TAB1)));
		}
		check_action_name(hwnd);
		break;
	case WM_NOTIFY:
		if(LOWORD(wParam)==IDC_TAB1){
			NMHDR *hdr;
			hdr=(NMHDR*)lParam;
			if(hdr->code==TCN_SELCHANGE){
				switch_tab_controls(hwnd,TabCtrl_GetCurSel(GetDlgItem(hwnd,IDC_TAB1)));
			}
		}
		break;
	case WM_COMMAND:
		//printf("wParam %08X lParam %08X msg %08X x=%i y=%i\n",wParam,lParam,message,LOWORD(lParam),HIWORD(lParam));
		switch(LOWORD(wParam))
		{
		case IDOK:
			save_button_keys(current_config,current_button,pressed_keys,sizeof(pressed_keys));
			DestroyWindow(hwnd);
			SetFocus(hwnd_parent);
			break;
		case IDC_APPLY:
			save_button_keys(current_config,current_button,pressed_keys,sizeof(pressed_keys));
			break;
		case IDC_ACTION_NAME:
			check_action_name(hwnd);
			break;
		case IDC_CLEAR_NAME:
			SetDlgItemText(hwnd,IDC_ACTION_NAME,"");
			break;
		case WM_DESTROY:
			hdlg=0;
			DestroyWindow(hwnd);
			SetFocus(hwnd_parent);
			break;
		default:
			switch(get_control_id((HWND)lParam)){
			case ID_RECORD:
				memset(pressed_keys,0,sizeof(pressed_keys));
				SendMessage(get_control_handle(ID_RECORDED),WM_SETTEXT,0,(LPARAM)"waiting...");
				record_mode=TRUE;
				EnableWindow(get_control_handle(ID_RECORD),FALSE);
				SetFocus(get_control_handle(ID_RECORD));
				//SetFocus(hwnd);
				//SetCapture(hwnd_parent);
				SetCapture(get_control_handle(ID_STOP));
				SetCursor(LoadCursor(NULL,IDC_CROSS));
				break;
			case ID_STOP:
				EnableWindow(get_control_handle(ID_RECORD),TRUE);
				ReleaseCapture();
				SetCursor(LoadCursor(NULL,IDC_ARROW));
				record_mode=FALSE;
				{
				char str[255];
				memset(str,0,sizeof(str));
				GetDlgItemText(hwnd,IDC_ACTION_NAME,str,sizeof(str));
				if(strlen(str)==0){
					memset(str,0,sizeof(str));
					SendMessage(get_control_handle(ID_RECORDED),WM_GETTEXT,sizeof(str),(LPARAM)str);
					if(strstr(str,"nothing")!=0){
						memset(pressed_keys,0,sizeof(pressed_keys));
					}
					else{
						sanatize_string(str,strlen(str));
						SetDlgItemText(hwnd,IDC_ACTION_NAME,str);
					}
				}
				}
				break;
			}
			break;
		}
		break;
	case WM_SETCURSOR:
		break;
	case WM_NCMOUSEMOVE:
	case WM_MOUSEFIRST:
		break;
	case WM_CLOSE:
		hdlg=0;
		DestroyWindow(hwnd);
		SetFocus(hwnd_parent);
		break;
	}
	return 0;
}
Пример #2
0
int
main (int argc, char **argv)
{
	CHandle handle = 0;
	CResult res = C_SUCCESS;

	// Parse the command line
	if(cmdline_parser(argc, argv, &args_info) != 0)
		exit(1);
	
	// Display help if no arguments were specified
	if(argc == 1) {
		cmdline_parser_print_help();
		exit(0);
	}

	res = c_init();
	if(res) goto done;
	
	// Open the device
	if (!args_info.list_given && (!args_info.import_given || args_info.device_given)) {
		handle = c_open_device(args_info.device_arg);
		if(!handle) {
			print_error("Unable to open device", -1);
			res = C_INVALID_DEVICE;
			goto done;
		}
	}

	// List devices
	if(args_info.list_given) {
		res = list_devices();
		goto done;
	}
	// Import dynamic controls from XML file
	else if(args_info.import_given) {
		res = add_control_mappings(handle, args_info.import_arg);
		goto done;
	}
	// Import dynamic controls from XML files at default location
	if(args_info.addctrl_given) {
		// list all xml files at default data/vid dir
		int nf=0;
		char vid[5];
		char pid[5];
		short pid_set = 0;
		if(fnmatch("[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]", args_info.addctrl_arg, 0))
		{
			if(fnmatch("[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]", args_info.addctrl_arg, 0))
			{
				printf("%s invalid: set at least a valid vid value, :pid is optional\n", args_info.addctrl_arg);
				goto done;
			}
			else
			{
				/*extract vid and reset pid*/
				int c = 0;
				for (c = 0; c < 4; c++)
				{
					vid[c] = args_info.addctrl_arg[c];
					pid[c] = 0;
				}
				vid[4] = '\0';
				pid[4] = '\0';
			}
		}
		else 
		{
			/*extract vid and pid*/
			int c = 0;
			for (c = 0; c < 4; c++)
			{
				vid[c] = args_info.addctrl_arg[c];
				pid[c] = args_info.addctrl_arg[c+5];
			}
			vid[4] = '\0';
			pid[4] = '\0';
			pid_set = 1; /*flag pid.xml check*/
			//printf("vid:%s pid:%s\n", vid, pid);
		}
		
		/* get xml file list from DATA_DIR/vid/ */ 
		char **xml_files = get_filename (DATA_DIR, vid);
 
		/*check for pid.xml*/
		char fname[9];
		strcpy(fname, pid);
		strcat(fname,".xml");
		if(pid_set)
		{
			pid_set = 0; /*reset*/
			nf=0;
			while (xml_files[nf] != NULL)
			{
				if ( strcasecmp(fname, xml_files[nf]) == 0)
					pid_set = 1; /*file exists so flag it*/
				nf++;
			}
		}
		
		/*parse xml files*/
		nf = 0;
		while (xml_files[nf] != NULL)
		{
			/* if pid was set and pid.xml exists parse it*/
			if(pid_set)
			{
				if ((strcasecmp(fname, xml_files[nf]) == 0))
				{
					printf ( "Parsing: %s \n", xml_files[nf]);
					res = add_control_mappings(handle, xml_files[nf]);
				}
			}
			else /* parse all xml files inside vid dir */
			{
				printf ( "Parsing: %s \n", xml_files[nf]);
				res = add_control_mappings(handle, xml_files[nf]);
			}
			free(xml_files[nf]);
			xml_files[nf]=NULL;
			nf++;
		}
		free(xml_files);
		goto done;
	}

	// List frame formats
	if(args_info.formats_given) {
		printf("Listing available frame formats for device %s:\n", args_info.device_arg);
		res = list_frame_formats(handle);
	}
	// List controls
	else if(args_info.clist_given) {
		printf("Listing available controls for device %s:\n", args_info.device_arg);
		res = list_controls(handle);
	}
	// Retrieve control value
	else if(args_info.get_given) {
		CControlValue value;
		
		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.get_arg);
		if(!controlId) {
			res = 1;
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Retrieve the control value
		res = c_get_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to retrieve control value", res);
			goto done;
		}
		printf("%d\n", value.value);
	}
	// Retrieve raw control value
	else if(args_info.get_raw_given) {
		//scan input
		uint16_t unit_id;
		unsigned char selector;
		sscanf(args_info.get_raw_arg, "%hu:%hhu", &unit_id, &selector);
		CControlValue value;
		value.type = CC_TYPE_RAW;
		// the entity is only used for the generating a control name
		//TODO: pass the guid through cmdline (optional)
		unsigned char entity[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
		res = c_read_xu_control(handle, entity, unit_id, selector, &value);
		if(res) {
			print_handle_error(handle, "Unable to retrieve control value", res);
			goto done;
		}
		
		//print the raw value
		uint8_t * val = value.raw.data;
		int i=0;
		printf("query current value of: (LE)0x");
		for(i=0; i<value.raw.size; i++)	{
			printf("%.2x", val[i]);
		}
		printf("  (BE)0x");
		for(i=value.raw.size-1; i >=0; i--) {
			printf("%.2x", val[i]);
		}
		printf("\n");
		//free the raw value alocation
		if(value.raw.data) free(value.raw.data);
	}
	else if(args_info.set_given) {
		CControlValue value;

		// Parse the control value
		if(args_info.inputs_num < 1) {
			res = 3;
			print_error("No control value specified", -1);
			goto done;
		}
		if(parse_control_value(args_info.inputs[0], &value)) {
			res = 2;
			print_error("Invalid control value specified", -1);
			goto done;
		}

		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.set_arg);
		if(!controlId) {
			res = 1;
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Set the new control value
		res = c_set_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to set new control value", res);
			goto done;
		}
	}
	// Set the raw control value
	else if(args_info.set_raw_given) {
		CControlValue value;
		
		// Parse the control value
		if(args_info.inputs_num < 1) {
			res = 3;
			print_error("No raw control value specified", -1);
			goto done;
		}
		uint16_t unit_id;
		unsigned char selector;

		sscanf(args_info.set_raw_arg, "%hu:%hhu", &unit_id, &selector);
		
		parse_raw_control_value (args_info.inputs[0], &value);
		
		// the entity is only used for the generating a control name
		//TODO: pass the guid through cmdline (optional)
		unsigned char entity[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
		res = c_write_xu_control(handle, entity, unit_id, selector, &value);
		if(res) {
			print_handle_error(handle, "Unable to set the control value", res);
			goto done;
		}
		
		//print the raw value le and be format
		uint8_t * val = value.raw.data;
		int i=0;
		printf("set value of          : (LE)0x");
		for(i=0; i<value.raw.size; i++)	{
			printf("%.2x", val[i]);
		}
		printf("  (BE)0x");
		for(i=value.raw.size-1; i >=0; i--) {
			printf("%.2x", val[i]);
		}
		printf("\n");
		//free the raw value alocation
		if(value.raw.data) free(value.raw.data);
	}
	else if(args_info.save_ctrl_given) {
		res = save_controls( handle, args_info.save_ctrl_arg);
	}
	else if(args_info.load_ctrl_given) {
		res = load_controls( handle, args_info.load_ctrl_arg);
	}

	// Clean up
done:
	if(handle) c_close_device(handle);
	c_cleanup();
	cmdline_parser_free(&args_info);

	return res;
}
Пример #3
0
Файл: main.c Проект: BotBot/ASV
int
main (int argc, char **argv)
{
	CHandle handle = 0;
	CResult res = C_SUCCESS;

	// Parse the command line
	if(cmdline_parser(argc, argv, &args_info) != 0)
		exit(1);
	
	// Display help if no arguments were specified
	if(argc == 1) {
		cmdline_parser_print_help();
		exit(0);
	}

	res = c_init();
	if(res) goto done;

	// List devices
	if(args_info.list_given) {
		res = list_devices();
		goto done;
	}
	// Import dynamic controls from XML file
	else if(args_info.import_given) {
		res = add_control_mappings(args_info.import_arg);
		goto done;
	}

	// Open the device
	handle = c_open_device(args_info.device_arg);
	if(!handle) {
		print_error("Unable to open device", -1);
		res = C_INVALID_DEVICE;
		goto done;
	}

	// List frame formats
	if(args_info.formats_given) {
		printf("Listing available frame formats for device %s:\n", args_info.device_arg);
		res = list_frame_formats(handle);
	}
	// List controls
	else if(args_info.clist_given) {
		printf("Listing available controls for device %s:\n", args_info.device_arg);
		res = list_controls(handle);
	}
	// Retrieve control value
	else if(args_info.get_given) {
		CControlValue value;
		
		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.get_arg);
		if(!controlId) {
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Retrieve the control value
		res = c_get_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to retrieve control value", res);
			goto done;
		}
		printf("%d\n", value.value);
	}
	else if(args_info.set_given) {
		CControlValue value;

		// Parse the control value
		if(args_info.inputs_num < 1) {
			print_error("No control value specified", -1);
			goto done;
		}
		if(parse_control_value(args_info.inputs[0], &value)) {
			print_error("Invalid control value specified", -1);
			goto done;
		}

		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.set_arg);
		if(!controlId) {
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Set the new control value
		res = c_set_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to set new control value", res);
			goto done;
		}
	}

	// Clean up
done:
	if(handle) c_close_device(handle);
	c_cleanup();
	cmdline_parser_free(&args_info);

	return res;
}