kopia lustrzana https://github.com/FreeSpacenav/spacenavd
- added proper build-dependency tracking in the makefile
- added separate sensitivities for each axis git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/spacenavd@124 ef983eb1-d774-4af8-acfd-baaf7b16a646pull/1/head
rodzic
c901bfa6df
commit
135772a7a5
|
@ -1,6 +1,7 @@
|
|||
src = $(wildcard src/*.c) $(wildcard src/serial/*.c)
|
||||
hdr = $(wildcard src/*.h) $(wildcard src/serial/*.h)
|
||||
obj = $(src:.c=.o)
|
||||
dep = $(obj:.o=.d)
|
||||
bin = spacenavd
|
||||
ctl = spnavd_ctl
|
||||
|
||||
|
@ -12,12 +13,17 @@ LDFLAGS = -L/usr/local/lib $(xlib)
|
|||
$(bin): $(obj)
|
||||
$(CC) -o $@ $(obj) $(LDFLAGS)
|
||||
|
||||
-include $(dep)
|
||||
|
||||
tags: $(src) $(hdr)
|
||||
ctags $(src) $(hdr)
|
||||
|
||||
%.o: $(srcdir)/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.d: $(srcdir)/%.c
|
||||
@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(obj) $(bin)
|
||||
|
|
|
@ -33,7 +33,11 @@ void default_cfg(struct cfg *cfg)
|
|||
{
|
||||
int i;
|
||||
|
||||
cfg->sensitivity = cfg->sens_trans = cfg->sens_rot = 1.0;
|
||||
cfg->sensitivity = 1.0;
|
||||
for(i=0; i<3; i++) {
|
||||
cfg->sens_trans[i] = cfg->sens_rot[i] = 1.0;
|
||||
}
|
||||
|
||||
cfg->dead_threshold = 2;
|
||||
cfg->led = 1;
|
||||
|
||||
|
@ -47,6 +51,14 @@ void default_cfg(struct cfg *cfg)
|
|||
}
|
||||
}
|
||||
|
||||
#define EXPECT(cond) \
|
||||
do { \
|
||||
if(!(cond)) { \
|
||||
fprintf(stderr, "%s: invalid value for %s\n", __func__, key_str); \
|
||||
continue; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
int read_cfg(const char *fname, struct cfg *cfg)
|
||||
{
|
||||
FILE *fp;
|
||||
|
@ -87,32 +99,44 @@ int read_cfg(const char *fname, struct cfg *cfg)
|
|||
isnum = isdigit(val_str[0]);
|
||||
|
||||
if(strcmp(key_str, "dead-zone") == 0) {
|
||||
if(!isnum) {
|
||||
fprintf(stderr, "invalid configuration value for %s, expected a number.\n", key_str);
|
||||
continue;
|
||||
}
|
||||
EXPECT(isnum);
|
||||
cfg->dead_threshold = atoi(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity") == 0) {
|
||||
if(!isnum) {
|
||||
fprintf(stderr, "invalid configuration value for %s, expected a number.\n", key_str);
|
||||
continue;
|
||||
}
|
||||
EXPECT(isnum);
|
||||
cfg->sensitivity = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-translation") == 0) {
|
||||
if(!isnum) {
|
||||
fprintf(stderr, "invalid configuration value for %s, expected a number.\n", key_str);
|
||||
continue;
|
||||
}
|
||||
cfg->sens_trans = atof(val_str);
|
||||
EXPECT(isnum);
|
||||
cfg->sens_trans[0] = cfg->sens_trans[1] = cfg->sens_trans[2] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-translation-x") == 0) {
|
||||
EXPECT(isnum);
|
||||
cfg->sens_trans[0] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-translation-y") == 0) {
|
||||
EXPECT(isnum);
|
||||
cfg->sens_trans[1] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-translation-z") == 0) {
|
||||
EXPECT(isnum);
|
||||
cfg->sens_trans[2] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-rotation") == 0) {
|
||||
if(!isnum) {
|
||||
fprintf(stderr, "invalid configuration value for %s, expected a number.\n", key_str);
|
||||
continue;
|
||||
}
|
||||
cfg->sens_rot = atof(val_str);
|
||||
EXPECT(isnum);
|
||||
cfg->sens_rot[0] = cfg->sens_rot[1] = cfg->sens_rot[2] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-rotation-x") == 0) {
|
||||
EXPECT(isnum);
|
||||
cfg->sens_rot[0] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-rotation-y") == 0) {
|
||||
EXPECT(isnum);
|
||||
cfg->sens_rot[1] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "sensitivity-rotation-z") == 0) {
|
||||
EXPECT(isnum);
|
||||
cfg->sens_rot[2] = atof(val_str);
|
||||
|
||||
} else if(strcmp(key_str, "invert-rot") == 0) {
|
||||
if(strchr(val_str, 'x')) {
|
||||
|
@ -208,8 +232,23 @@ int write_cfg(const char *fname, struct cfg *cfg)
|
|||
fprintf(fp, "sensitivity = %.3f\n\n", cfg->sensitivity);
|
||||
|
||||
fprintf(fp, "# separate sensitivity for rotation and translation.\n");
|
||||
fprintf(fp, "sensitivity-translation = %.3f\n", cfg->sens_trans);
|
||||
fprintf(fp, "sensitivity-rotation = %.3f\n\n", cfg->sens_rot);
|
||||
|
||||
if(cfg->sens_trans[0] == cfg->sens_trans[1] && cfg->sens_trans[1] == cfg->sens_trans[2]) {
|
||||
fprintf(fp, "sensitivity-translation = %.3f\n", cfg->sens_trans[0]);
|
||||
} else {
|
||||
fprintf(fp, "sensitivity-translation-x = %.3f\n", cfg->sens_trans[0]);
|
||||
fprintf(fp, "sensitivity-translation-y = %.3f\n", cfg->sens_trans[1]);
|
||||
fprintf(fp, "sensitivity-translation-z = %.3f\n", cfg->sens_trans[2]);
|
||||
}
|
||||
|
||||
if(cfg->sens_rot[0] == cfg->sens_rot[1] && cfg->sens_rot[1] == cfg->sens_rot[2]) {
|
||||
fprintf(fp, "sensitivity-rotation = %.3f\n", cfg->sens_rot[0]);
|
||||
} else {
|
||||
fprintf(fp, "sensitivity-rotation-x = %.3f\n", cfg->sens_rot[0]);
|
||||
fprintf(fp, "sensitivity-rotation-y = %.3f\n", cfg->sens_rot[1]);
|
||||
fprintf(fp, "sensitivity-rotation-z = %.3f\n", cfg->sens_rot[2]);
|
||||
}
|
||||
fputc('\n', fp);
|
||||
|
||||
fprintf(fp, "# dead zone; any motion less than this number, is discarded as noise.\n");
|
||||
fprintf(fp, "dead-zone = %d\n\n", cfg->dead_threshold);
|
||||
|
|
|
@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#define MAX_BUTTONS 64
|
||||
|
||||
struct cfg {
|
||||
float sensitivity, sens_trans, sens_rot;
|
||||
float sensitivity, sens_trans[3], sens_rot[3];
|
||||
int dead_threshold;
|
||||
int invert[6];
|
||||
int map_axis[6];
|
||||
|
|
|
@ -55,7 +55,7 @@ void process_input(struct dev_input *inp)
|
|||
inp->idx = cfg.map_axis[inp->idx];
|
||||
sign = cfg.invert[inp->idx] ? -1 : 1;
|
||||
|
||||
inp->val = (int)((float)inp->val * cfg.sensitivity * (inp->idx < 3 ? cfg.sens_trans : cfg.sens_rot));
|
||||
inp->val = (int)((float)inp->val * cfg.sensitivity * (inp->idx < 3 ? cfg.sens_trans[inp->idx] : cfg.sens_rot[inp->idx - 3]));
|
||||
|
||||
ev.type = EVENT_MOTION;
|
||||
ev.motion.data = (int*)&ev.motion.x;
|
||||
|
|
Ładowanie…
Reference in New Issue