Skip to content

Commit

Permalink
removed the global disable-translation/disable-rotation options, and
Browse files Browse the repository at this point in the history
moved the state variables out of the cfg structure.
  • Loading branch information
jtsiomb committed Feb 10, 2022
1 parent 6e458f1 commit 946a087
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
16 changes: 1 addition & 15 deletions src/cfgfile.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
spacenavd - a free software replacement driver for 6dof space-mice.
Copyright (C) 2007-2019 John Tsiombikas <nuclear@member.fsf.org>
Copyright (C) 2007-2022 John Tsiombikas <nuclear@member.fsf.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -68,8 +68,6 @@ void default_cfg(struct cfg *cfg)
cfg->devname[i] = 0;
cfg->devid[i][0] = cfg->devid[i][1] = -1;
}
cfg->disable_translation = 0;
cfg->disable_rotation = 0;
}

#define EXPECT(cond) \
Expand Down Expand Up @@ -197,14 +195,6 @@ int read_cfg(const char *fname, struct cfg *cfg)
EXPECT(isfloat);
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) {
if(strchr(val_str, 'x')) {
cfg->invert[RX] = !def_axinv[RX];
Expand Down Expand Up @@ -390,10 +380,6 @@ int write_cfg(const char *fname, struct cfg *cfg)
}
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");

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]) {
Expand Down
4 changes: 1 addition & 3 deletions src/cfgfile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
spacenavd - a free software replacement driver for 6dof space-mice.
Copyright (C) 2007-2019 John Tsiombikas <nuclear@member.fsf.org>
Copyright (C) 2007-2022 John Tsiombikas <nuclear@member.fsf.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -45,8 +45,6 @@ enum {

struct cfg {
float sensitivity, sens_trans[3], sens_rot[3];
int disable_rotation;
int disable_translation;
int dead_threshold[MAX_AXES];
int invert[MAX_AXES];
int map_axis[MAX_AXES];
Expand Down
25 changes: 14 additions & 11 deletions src/event.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
spacenavd - a free software replacement driver for 6dof space-mice.
Copyright (C) 2007-2013 John Tsiombikas <nuclear@member.fsf.org>
Copyright (C) 2007-2022 John Tsiombikas <nuclear@member.fsf.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -56,6 +56,9 @@ static unsigned int msec_dif(struct timeval tv1, struct timeval tv2);

static struct dev_event *dev_ev_list = NULL;

static int disable_translation, disable_rotation;


static struct dev_event *add_dev_event(struct device *dev)
{
struct dev_event *dev_ev, *iter;
Expand Down Expand Up @@ -143,8 +146,8 @@ void process_input(struct device *dev, struct dev_input *inp)
}
sign = cfg.invert[inp->idx] ? -1 : 1;

sens_rot = cfg.disable_rotation ? 0 : cfg.sens_rot[inp->idx - 3];
sens_trans = cfg.disable_translation ? 0 : cfg.sens_trans[inp->idx];
sens_rot = disable_rotation ? 0 : cfg.sens_rot[inp->idx - 3];
sens_trans = disable_translation ? 0 : cfg.sens_trans[inp->idx];

inp->val = (int)((float)inp->val * cfg.sensitivity * (inp->idx < 3 ? sens_trans : sens_rot));

Expand Down Expand Up @@ -224,6 +227,8 @@ void process_input(struct device *dev, struct dev_input *inp)

static void handle_button_action(int act, int pressed)
{
if(pressed) return; /* perform all actions on release */

switch(act) {
case BNACT_SENS_INC:
cfg.sensitivity *= 1.1f;
Expand All @@ -235,17 +240,15 @@ static void handle_button_action(int act, int pressed)
cfg.sensitivity = 1.0f;
break;
case BNACT_DISABLE_ROTATION:
if(pressed == BTN_RELEASE) {
cfg.disable_rotation = !cfg.disable_rotation;
if (cfg.disable_rotation)
cfg.disable_translation = 0;
disable_rotation = !disable_rotation;
if(disable_rotation) {
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;
disable_translation = !disable_translation;
if(disable_translation) {
disable_rotation = 0;
}
break;
}
Expand Down

0 comments on commit 946a087

Please sign in to comment.