Skip to content

Commit

Permalink
Merge branch 'bnev_dis_motion'
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsiomb committed Feb 10, 2022
2 parents eb0287f + 4f7989d commit 6e458f1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/example-spnavrc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
# available actions:
# none,
# sensitivity-up, sensitivity-down, sensitivity-reset
# disable-rotation
# disable-translation
#
#bnact16 = sensitivity-up
#bnact17 = sensitivity-down
Expand Down
16 changes: 16 additions & 0 deletions src/cfgfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ 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 @@ -195,6 +197,14 @@ 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 @@ -380,6 +390,10 @@ 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 Expand Up @@ -495,6 +509,8 @@ static struct {
{"sensitivity-up", BNACT_SENS_INC},
{"sensitivity-down", BNACT_SENS_DEC},
{"sensitivity-reset", BNACT_SENS_RESET},
{"disable-rotation", BNACT_DISABLE_ROTATION},
{"disable-translation", BNACT_DISABLE_TRANSLATION},
{0, 0}
};

Expand Down
4 changes: 4 additions & 0 deletions src/cfgfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ enum {
BNACT_SENS_RESET,
BNACT_SENS_INC,
BNACT_SENS_DEC,
BNACT_DISABLE_ROTATION,
BNACT_DISABLE_TRANSLATION,

MAX_BNACT
};

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
31 changes: 27 additions & 4 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ enum {
MOT_RX, MOT_RY, MOT_RZ
};

enum {
BTN_RELEASE = 0,
BTN_PRESS = 1
};

struct dev_event {
spnav_event event;
struct timeval timeval;
Expand All @@ -44,7 +49,7 @@ struct dev_event {

static struct dev_event *add_dev_event(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 send_event(spnav_event *ev, struct client *c);
static unsigned int msec_dif(struct timeval tv1, struct timeval tv2);
Expand Down Expand Up @@ -127,6 +132,7 @@ void process_input(struct device *dev, struct dev_input *inp)
{
int sign;
struct dev_event *dev_ev;
float sens_rot, sens_trans;

switch(inp->type) {
case INP_MOTION:
Expand All @@ -137,7 +143,10 @@ void process_input(struct device *dev, struct dev_input *inp)
}
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);
if(verbose && dev_ev == NULL)
Expand All @@ -155,7 +164,7 @@ void process_input(struct device *dev, struct dev_input *inp)
case INP_BUTTON:
/* check to see if the button has been bound to an action */
if(cfg.bnact[inp->idx] > 0) {
handle_button_action(cfg.bnact[inp->idx]);
handle_button_action(cfg.bnact[inp->idx], inp->val);
break;
}

Expand Down Expand Up @@ -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) {
case BNACT_SENS_INC:
Expand All @@ -225,6 +234,20 @@ static void handle_button_action(int act)
case BNACT_SENS_RESET:
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;
}
break;
case BNACT_DISABLE_TRANSLATION:
if(pressed == BTN_RELEASE) {
cfg.disable_translation = !cfg.disable_translation;
if (cfg.disable_translation)
cfg.disable_rotation = 0;
}
break;
}
}

Expand Down

0 comments on commit 6e458f1

Please sign in to comment.