kopia lustrzana https://github.com/FreeSpacenav/spacenavd
				
				
				
			Merge branch 'bnev_dis_motion'
						commit
						6e458f1676
					
				|  | @ -75,6 +75,8 @@ | ||||||
| # available actions: | # available actions: | ||||||
| #    none, | #    none, | ||||||
| #    sensitivity-up, sensitivity-down, sensitivity-reset | #    sensitivity-up, sensitivity-down, sensitivity-reset | ||||||
|  | #    disable-rotation | ||||||
|  | #    disable-translation | ||||||
| # | # | ||||||
| #bnact16 = sensitivity-up | #bnact16 = sensitivity-up | ||||||
| #bnact17 = sensitivity-down | #bnact17 = sensitivity-down | ||||||
|  |  | ||||||
|  | @ -68,6 +68,8 @@ void default_cfg(struct cfg *cfg) | ||||||
| 		cfg->devname[i] = 0; | 		cfg->devname[i] = 0; | ||||||
| 		cfg->devid[i][0] = cfg->devid[i][1] = -1; | 		cfg->devid[i][0] = cfg->devid[i][1] = -1; | ||||||
| 	} | 	} | ||||||
|  | 	cfg->disable_translation = 0; | ||||||
|  | 	cfg->disable_rotation = 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #define EXPECT(cond) \ | #define EXPECT(cond) \ | ||||||
|  | @ -195,6 +197,14 @@ int read_cfg(const char *fname, struct cfg *cfg) | ||||||
| 			EXPECT(isfloat); | 			EXPECT(isfloat); | ||||||
| 			cfg->sens_rot[2] = fval; | 			cfg->sens_rot[2] = fval; | ||||||
| 
 | 
 | ||||||
|  | 		} else if(strcmp(key_str, "disable-rotation") == 0) { | ||||||
|  | 			EXPECT(isint); | ||||||
|  | 			cfg->disable_rotation = ival; | ||||||
|  | 
 | ||||||
|  | 		} else if(strcmp(key_str, "disable-translation") == 0) { | ||||||
|  | 			EXPECT(isint); | ||||||
|  | 			cfg->disable_translation = ival; | ||||||
|  | 
 | ||||||
| 		} else if(strcmp(key_str, "invert-rot") == 0) { | 		} else if(strcmp(key_str, "invert-rot") == 0) { | ||||||
| 			if(strchr(val_str, 'x')) { | 			if(strchr(val_str, 'x')) { | ||||||
| 				cfg->invert[RX] = !def_axinv[RX]; | 				cfg->invert[RX] = !def_axinv[RX]; | ||||||
|  | @ -380,6 +390,10 @@ int write_cfg(const char *fname, struct cfg *cfg) | ||||||
| 	} | 	} | ||||||
| 	fputc('\n', fp); | 	fputc('\n', fp); | ||||||
| 
 | 
 | ||||||
|  | 	fprintf(fp, "disable-rotation = %d\n", cfg->disable_rotation); | ||||||
|  | 	fprintf(fp, "disable-translation = %d\n", cfg->disable_translation); | ||||||
|  | 	fputc('\n', fp); | ||||||
|  | 
 | ||||||
| 	fprintf(fp, "# dead zone; any motion less than this number, is discarded as noise.\n"); | 	fprintf(fp, "# dead zone; any motion less than this number, is discarded as noise.\n"); | ||||||
| 
 | 
 | ||||||
| 	if(cfg->dead_threshold[0] == cfg->dead_threshold[1] && cfg->dead_threshold[1] == cfg->dead_threshold[2] && cfg->dead_threshold[2] == cfg->dead_threshold[3] && cfg->dead_threshold[3] == cfg->dead_threshold[4] && cfg->dead_threshold[4] == cfg->dead_threshold[5]) { | 	if(cfg->dead_threshold[0] == cfg->dead_threshold[1] && cfg->dead_threshold[1] == cfg->dead_threshold[2] && cfg->dead_threshold[2] == cfg->dead_threshold[3] && cfg->dead_threshold[3] == cfg->dead_threshold[4] && cfg->dead_threshold[4] == cfg->dead_threshold[5]) { | ||||||
|  | @ -495,6 +509,8 @@ static struct { | ||||||
| 	{"sensitivity-up", BNACT_SENS_INC}, | 	{"sensitivity-up", BNACT_SENS_INC}, | ||||||
| 	{"sensitivity-down", BNACT_SENS_DEC}, | 	{"sensitivity-down", BNACT_SENS_DEC}, | ||||||
| 	{"sensitivity-reset", BNACT_SENS_RESET}, | 	{"sensitivity-reset", BNACT_SENS_RESET}, | ||||||
|  | 	{"disable-rotation", BNACT_DISABLE_ROTATION}, | ||||||
|  | 	{"disable-translation", BNACT_DISABLE_TRANSLATION}, | ||||||
| 	{0, 0} | 	{0, 0} | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -37,12 +37,16 @@ enum { | ||||||
| 	BNACT_SENS_RESET, | 	BNACT_SENS_RESET, | ||||||
| 	BNACT_SENS_INC, | 	BNACT_SENS_INC, | ||||||
| 	BNACT_SENS_DEC, | 	BNACT_SENS_DEC, | ||||||
|  | 	BNACT_DISABLE_ROTATION, | ||||||
|  | 	BNACT_DISABLE_TRANSLATION, | ||||||
| 
 | 
 | ||||||
| 	MAX_BNACT | 	MAX_BNACT | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| struct cfg { | struct cfg { | ||||||
| 	float sensitivity, sens_trans[3], sens_rot[3]; | 	float sensitivity, sens_trans[3], sens_rot[3]; | ||||||
|  | 	int disable_rotation; | ||||||
|  | 	int disable_translation; | ||||||
| 	int dead_threshold[MAX_AXES]; | 	int dead_threshold[MAX_AXES]; | ||||||
| 	int invert[MAX_AXES]; | 	int invert[MAX_AXES]; | ||||||
| 	int map_axis[MAX_AXES]; | 	int map_axis[MAX_AXES]; | ||||||
|  |  | ||||||
							
								
								
									
										31
									
								
								src/event.c
								
								
								
								
							
							
						
						
									
										31
									
								
								src/event.c
								
								
								
								
							|  | @ -34,6 +34,11 @@ enum { | ||||||
| 	MOT_RX, MOT_RY, MOT_RZ | 	MOT_RX, MOT_RY, MOT_RZ | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | enum { | ||||||
|  | 	BTN_RELEASE = 0, | ||||||
|  | 	BTN_PRESS = 1 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| struct dev_event { | struct dev_event { | ||||||
| 	spnav_event event; | 	spnav_event event; | ||||||
| 	struct timeval timeval; | 	struct timeval timeval; | ||||||
|  | @ -44,7 +49,7 @@ struct dev_event { | ||||||
| 
 | 
 | ||||||
| static struct dev_event *add_dev_event(struct device *dev); | static struct dev_event *add_dev_event(struct device *dev); | ||||||
| static struct dev_event *device_event_in_use(struct device *dev); | static struct dev_event *device_event_in_use(struct device *dev); | ||||||
| static void handle_button_action(int act); | static void handle_button_action(int act, int val); | ||||||
| static void dispatch_event(struct dev_event *dev); | static void dispatch_event(struct dev_event *dev); | ||||||
| static void send_event(spnav_event *ev, struct client *c); | static void send_event(spnav_event *ev, struct client *c); | ||||||
| static unsigned int msec_dif(struct timeval tv1, struct timeval tv2); | static unsigned int msec_dif(struct timeval tv1, struct timeval tv2); | ||||||
|  | @ -127,6 +132,7 @@ void process_input(struct device *dev, struct dev_input *inp) | ||||||
| { | { | ||||||
| 	int sign; | 	int sign; | ||||||
| 	struct dev_event *dev_ev; | 	struct dev_event *dev_ev; | ||||||
|  | 	float sens_rot, sens_trans; | ||||||
| 
 | 
 | ||||||
| 	switch(inp->type) { | 	switch(inp->type) { | ||||||
| 	case INP_MOTION: | 	case INP_MOTION: | ||||||
|  | @ -137,7 +143,10 @@ void process_input(struct device *dev, struct dev_input *inp) | ||||||
| 		} | 		} | ||||||
| 		sign = cfg.invert[inp->idx] ? -1 : 1; | 		sign = cfg.invert[inp->idx] ? -1 : 1; | ||||||
| 
 | 
 | ||||||
| 		inp->val = (int)((float)inp->val * cfg.sensitivity * (inp->idx < 3 ? cfg.sens_trans[inp->idx] : cfg.sens_rot[inp->idx - 3])); | 		sens_rot = cfg.disable_rotation ? 0 : cfg.sens_rot[inp->idx - 3]; | ||||||
|  | 		sens_trans = cfg.disable_translation ? 0 : cfg.sens_trans[inp->idx]; | ||||||
|  | 
 | ||||||
|  | 		inp->val = (int)((float)inp->val * cfg.sensitivity * (inp->idx < 3 ? sens_trans : sens_rot)); | ||||||
| 
 | 
 | ||||||
| 		dev_ev = device_event_in_use(dev); | 		dev_ev = device_event_in_use(dev); | ||||||
| 		if(verbose && dev_ev == NULL) | 		if(verbose && dev_ev == NULL) | ||||||
|  | @ -155,7 +164,7 @@ void process_input(struct device *dev, struct dev_input *inp) | ||||||
| 	case INP_BUTTON: | 	case INP_BUTTON: | ||||||
| 		/* check to see if the button has been bound to an action */ | 		/* check to see if the button has been bound to an action */ | ||||||
| 		if(cfg.bnact[inp->idx] > 0) { | 		if(cfg.bnact[inp->idx] > 0) { | ||||||
| 			handle_button_action(cfg.bnact[inp->idx]); | 			handle_button_action(cfg.bnact[inp->idx], inp->val); | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | @ -213,7 +222,7 @@ void process_input(struct device *dev, struct dev_input *inp) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void handle_button_action(int act) | static void handle_button_action(int act, int pressed) | ||||||
| { | { | ||||||
| 	switch(act) { | 	switch(act) { | ||||||
| 	case BNACT_SENS_INC: | 	case BNACT_SENS_INC: | ||||||
|  | @ -225,6 +234,20 @@ static void handle_button_action(int act) | ||||||
| 	case BNACT_SENS_RESET: | 	case BNACT_SENS_RESET: | ||||||
| 		cfg.sensitivity = 1.0f; | 		cfg.sensitivity = 1.0f; | ||||||
| 		break; | 		break; | ||||||
|  | 	case BNACT_DISABLE_ROTATION: | ||||||
|  | 		if(pressed == BTN_RELEASE) { | ||||||
|  | 			cfg.disable_rotation = !cfg.disable_rotation; | ||||||
|  | 			if (cfg.disable_rotation) | ||||||
|  | 				cfg.disable_translation = 0; | ||||||
|  | 		} | ||||||
|  | 		break; | ||||||
|  | 	case BNACT_DISABLE_TRANSLATION: | ||||||
|  | 		if(pressed == BTN_RELEASE) { | ||||||
|  | 			cfg.disable_translation = !cfg.disable_translation; | ||||||
|  | 			if (cfg.disable_translation) | ||||||
|  | 				cfg.disable_rotation = 0; | ||||||
|  | 		} | ||||||
|  | 		break; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 John Tsiombikas
						John Tsiombikas