Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/Makefile b/Makefile
- index 14ef09d..172eb5e 100644
- --- a/Makefile
- +++ b/Makefile
- @@ -1,9 +1,9 @@
- -# Disable -Werror if there are compile errors
- +# Disable -Werror if there are compile errors
- CFLAGS+=-Wall -Werror -g
- all: loadmap reserve_js joymap_blocker.so joymap_blocker.i386.so
- loadmap: loadmap.o dictionary.o mapparser.o programparser.o validkeys.o events.o vm.o devices.o config.o daemon.o file.o
- - $(CC) -g -o loadmap loadmap.o dictionary.o mapparser.o programparser.o validkeys.o events.o vm.o devices.o config.o daemon.o file.o
- + $(CC) -lm -g -o loadmap loadmap.o dictionary.o mapparser.o programparser.o validkeys.o events.o vm.o devices.o config.o daemon.o file.o
- reserve_js: reserve_js.o config.o daemon.o
- $(CC) -g -o reserve_js reserve_js.o config.o daemon.o
- diff --git a/devices.c b/devices.c
- index 527511c..4e59e8c 100644
- --- a/devices.c
- +++ b/devices.c
- @@ -46,6 +46,8 @@ struct joystick_device {
- int axes;
- int buttons;
- int fd;
- + int absmin[ABS_MAX + 1];
- + int absmax[ABS_MAX + 1];
- struct jscal cal;
- unsigned long absbits[ABS_UL];
- unsigned long keybits[KEY_UL];
- @@ -55,16 +57,16 @@ struct joystick_device {
- };
- static struct joystick_device devices[NUM_JOYSTICKS]={
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0},
- - {0,0,-1, {0,0,1000}, {0}, {0}, {0}, 0}
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0},
- + {0,0,-1, {0}, {0}, {0,0,1000}, {0}, {0}, {0}, 0}
- };
- static int mouse_fd;
- @@ -105,6 +107,16 @@ void set_joystick_has_axis(int js, int axis) {
- set_bit(devices[js].absbits, axis);
- }
- +void set_joystick_axis_min(int js, int axis, int value) {
- + if ((js<0)||(js>NUM_JOYSTICKS)) return;
- + devices[js].absmin[axis]=value;
- +}
- +
- +void set_joystick_axis_max(int js, int axis, int value) {
- + if ((js<0)||(js>NUM_JOYSTICKS)) return;
- + devices[js].absmax[axis]=value;
- +}
- +
- void set_joystick_ff_program(int js, struct program_force_remap *map) {
- int i;
- int effects;
- @@ -250,9 +262,9 @@ void register_devices(int add_code_device) {
- dev.ff_effects_max = devices[i].max_effects;
- for (j = 0; j < ABS_MAX + 1; j++) {
- - dev.absmax[j] = 32767;
- - dev.absmin[j] = -32767;
- - dev.absfuzz[i] = 0;
- + dev.absmin[j] = devices[i].absmin[j];
- + dev.absmax[j] = devices[i].absmax[j];
- + dev.absfuzz[j] = 0;
- dev.absflat[j] = 0;
- }
- safe_write(devices[i].fd, &dev, sizeof(dev));
- @@ -328,7 +340,7 @@ void register_devices(int add_code_device) {
- for (i = 0; i < ABS_MAX + 1; i++) {
- dev.absmax[i] = 32767;
- - dev.absmin[i] = -32767;
- + dev.absmin[i] = -32768;
- dev.absfuzz[i] = 256;
- dev.absflat[i] = 0;
- }
- diff --git a/events.c b/events.c
- index 4aa23a9..b815d12 100644
- --- a/events.c
- +++ b/events.c
- @@ -18,6 +18,7 @@
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- +#include <math.h>
- #include "config.h"
- #include "mapper.h"
- @@ -88,6 +89,12 @@ static uint16_t shift_button;
- struct mapping *devices[MAX_DEVICES];
- struct event_device event_devices[MAX_EVENTS] = {0};
- +int clamp_int(int value, int min, int max) {
- + if (value < min) value = min;
- + else if (value > max) value = max;
- + return value;
- +}
- +
- void set_event_input_calibrate(int set) {
- event_calibrate = set;
- }
- @@ -190,7 +197,7 @@ struct mapping *get_device_by_vendor(uint16_t vendor, uint16_t product, int inst
- mapper->map[1].button_press[j]=NULL;
- mapper->map[1].button_release[j]=NULL;
- }
- -
- +
- for (j=0; j<ABS_MAX+1; j++) {
- mapper->map[0].axes[j]=NULL;
- mapper->map[1].axes[j]=NULL;
- @@ -684,9 +691,8 @@ static void process_axis(struct mapping *mapper, int axis, int value) {
- value = axes_remap[axis]->max;
- }
- // sigh. use floating point because I am too lazy (right now) to work out an overflow free integer version
- - value = ((value - axes_remap[axis]->min) * 65536.0) / (axes_remap[axis]->max - axes_remap[axis]->min) - 32768;
- - if (value < -32767) value = -32767;
- - if (value > 32767) value = 32767;
- + value = round(((value - axes_remap[axis]->min) * 65534.0) / (axes_remap[axis]->max - axes_remap[axis]->min) - 32767);
- + value = clamp_int(value, -32767, 32767);
- }
- if ((value >= -axes_remap[axis]->deadzone) && (value <= axes_remap[axis]->deadzone)) {
- @@ -694,9 +700,10 @@ static void process_axis(struct mapping *mapper, int axis, int value) {
- } else if (axes_remap[axis]->deadzone) {
- // we don't want a sudden jump in values. rescale it.
- if (value < 0)
- - value = (value + axes_remap[axis]->deadzone) * 32767.0 / (32767 - axes_remap[axis]->deadzone);
- + value = round((value + axes_remap[axis]->deadzone) * 32767.0 / (32767 - axes_remap[axis]->deadzone));
- else
- - value = (value - axes_remap[axis]->deadzone) * 32767.0 / (32767 - axes_remap[axis]->deadzone);
- + value = round((value - axes_remap[axis]->deadzone) * 32767.0 / (32767 - axes_remap[axis]->deadzone));
- + value = clamp_int(value, -32767, 32767);
- }
- if (axes_remap[axis]->flags&FLAG_BINARY) {
- diff --git a/loadmap.c b/loadmap.c
- index d40d039..9d51eee 100644
- --- a/loadmap.c
- +++ b/loadmap.c
- @@ -65,6 +65,10 @@ int main(int argc, char *argv[]) {
- for (i=0; i<njoysticks; i++) {
- set_num_axes(i, joysticks[i].axes);
- set_num_buttons(i, joysticks[i].buttons);
- + for (j=0; j<joysticks[i].axes; j++) {
- + set_joystick_axis_min(i, j, axes[j].min);
- + set_joystick_axis_max(i, j, axes[j].max);
- + }
- printf("joystick%d axes=%d buttons=%d.\n", i, joysticks[i].axes, joysticks[i].buttons);
- }
- @@ -131,7 +135,7 @@ int main(int argc, char *argv[]) {
- device_poll_timer = DEVICE_POLL_TIMER;
- while (1) {
- start = clock_millis();
- - poll_joystick_loop(timeout);
- + poll_joystick_loop();
- poll_ff();
- stop = clock_millis();
- timeout -= stop - start;
- diff --git a/mapparser.c b/mapparser.c
- index 01bcb0d..0ca676a 100644
- --- a/mapparser.c
- +++ b/mapparser.c
- @@ -103,11 +103,11 @@ static int isnum(char *s) {
- return 1;
- }
- -int numeric(char *s) {
- +int numeric(char *s, int defaultvalue) {
- int r=0;
- int sign = 1;
- char msg[256];
- - if (s==NULL) return 0;
- + if (s==NULL) return defaultvalue;
- if (s[0] == '-') {
- sign = -1;
- s++;
- @@ -244,7 +244,7 @@ static void parse_sequence(uint16_t *sequence, char *s, int base, int type) {
- } else if ((base==DEVICE_MOUSE)&&(type==TYPE_BUTTON)) {
- base=BTN_MOUSE;
- } else base=0;
- - sequence[0]=numeric(s)+base;
- + sequence[0]=numeric(s, 0)+base;
- sequence[1]=SEQUENCE_DONE;
- } else {
- p=s;
- @@ -618,13 +618,13 @@ static void parse_shift() {
- if (has_required(dict, "src", NULL)) {
- map.program=PROGRAM_BUTTON_REMAP;
- if (id!=NULL)
- - map.joystick=numeric(id);
- + map.joystick=numeric(id, 0);
- else
- map.joystick=255;
- - map.vendor=numeric(vendor);
- - map.product=numeric(product);
- - map.instance=numeric(instance);
- - map.srcbutton=numeric(src)+BTN_JOYSTICK;
- + map.vendor=numeric(vendor, 0);
- + map.product=numeric(product, 0);
- + map.instance=numeric(instance, 0);
- + map.srcbutton=numeric(src, 0)+BTN_JOYSTICK;
- map.type=TYPE_SHIFT;
- map.flags=FLAG_NONE;
- buttons[nbuttons]=map;
- @@ -652,13 +652,13 @@ static void parse_script() {
- } else {
- if (has_required(dict, "device", NULL)) {
- if (id!=NULL)
- - script.id=numeric(id);
- + script.id=numeric(id, 0);
- else
- script.id=-1;
- - script.vendor=numeric(vendor);
- - script.product=numeric(product);
- - script.device=numeric(device);
- - script.instance=numeric(instance);
- + script.vendor=numeric(vendor, 0);
- + script.product=numeric(product, 0);
- + script.device=numeric(device, 0);
- + script.instance=numeric(instance, 0);
- scriptassign[nscript]=script;
- nscript++;
- }
- @@ -689,17 +689,17 @@ static void parse_button() {
- if (has_required(dict, "src", "target", NULL)) {
- map.program=PROGRAM_BUTTON_REMAP;
- if (id!=NULL)
- - map.joystick=numeric(id);
- + map.joystick=numeric(id, 0);
- else
- map.joystick=255;
- - map.vendor=numeric(vendor);
- - map.product=numeric(product);
- + map.vendor=numeric(vendor, 0);
- + map.product=numeric(product, 0);
- base=get_device(target);
- - map.device=base+(numeric(device)&0xF);
- + map.device=base+(numeric(device, 0)&0xF);
- map.type=get_type(target,dict);
- - map.instance=numeric(instance);
- + map.instance=numeric(instance, 0);
- if (base==DEVICE_JOYSTICK) {
- - num=numeric(device);
- + num=numeric(device, 0);
- if (num>8) {
- report("Maximum of 8 joysticks allowed");
- } else {
- @@ -707,19 +707,19 @@ static void parse_button() {
- njoysticks=num+1;
- }
- if (map.type==TYPE_AXIS) {
- - if (joysticks[num].axes<=numeric(axis))
- - joysticks[num].axes=numeric(axis)+1;
- - set_joystick_has_axis(num, numeric(axis));
- + if (joysticks[num].axes<=numeric(axis, 0))
- + joysticks[num].axes=numeric(axis, 0)+1;
- + set_joystick_has_axis(num, numeric(axis, 0));
- }
- if (map.type==TYPE_BUTTON) {
- - if (joysticks[num].buttons<=numeric(button))
- - joysticks[num].buttons=numeric(button)+1;
- - set_joystick_has_button(num, numeric(button));
- + if (joysticks[num].buttons<=numeric(button, 0))
- + joysticks[num].buttons=numeric(button, 0)+1;
- + set_joystick_has_button(num, numeric(button, 0));
- }
- }
- }
- - map.srcbutton=numeric(src)+BTN_JOYSTICK;
- - map.speed=numeric(speed);
- + map.srcbutton=numeric(src, 0)+BTN_JOYSTICK;
- + map.speed=numeric(speed, 0);
- if (map.speed==0)
- map.speed=8;
- map.flags=parse_flags(flags);
- @@ -775,19 +775,19 @@ static void parse_axis() {
- if (has_required(dict, "src", "target", NULL)) {
- amap.program=PROGRAM_AXIS_REMAP;
- if (id!=NULL)
- - amap.joystick=numeric(id);
- + amap.joystick=numeric(id, 0);
- else
- amap.joystick=255;
- - amap.vendor=numeric(vendor);
- - amap.product=numeric(product);
- - amap.srcaxis=numeric(src);
- + amap.vendor=numeric(vendor, 0);
- + amap.product=numeric(product, 0);
- + amap.srcaxis=numeric(src, 0);
- base=get_device(target);
- - amap.device=base+(numeric(device)&0xF);
- + amap.device=base+(numeric(device, 0)&0xF);
- amap.type=get_type(target,dict);
- amap.saved_value = 0;
- - amap.instance=numeric(instance);
- + amap.instance=numeric(instance, 0);
- if (base==DEVICE_JOYSTICK) {
- - num=numeric(device);
- + num=numeric(device, 0);
- if (num>8) {
- report("Maximum of 8 joysticks allowed");
- } else {
- @@ -795,17 +795,17 @@ static void parse_axis() {
- njoysticks=num+1;
- }
- if (amap.type==TYPE_AXIS) {
- - if (joysticks[num].axes<=numeric(axis))
- - joysticks[num].axes=numeric(axis)+1;
- - set_joystick_has_axis(num, numeric(axis));
- + if (joysticks[num].axes<=numeric(axis, 0))
- + joysticks[num].axes=numeric(axis, 0)+1;
- + set_joystick_has_axis(num, numeric(axis, 0));
- }
- if (amap.type==TYPE_BUTTON) {
- - if (joysticks[num].buttons<=numeric(plus))
- - joysticks[num].buttons=numeric(plus)+1;
- - if (joysticks[num].buttons<=numeric(minus))
- - joysticks[num].buttons=numeric(minus)+1;
- - set_joystick_has_button(num, numeric(plus));
- - set_joystick_has_button(num, numeric(minus));
- + if (joysticks[num].buttons<=numeric(plus, 0))
- + joysticks[num].buttons=numeric(plus, 0)+1;
- + if (joysticks[num].buttons<=numeric(minus, 0))
- + joysticks[num].buttons=numeric(minus, 0)+1;
- + set_joystick_has_button(num, numeric(plus, 0));
- + set_joystick_has_button(num, numeric(minus, 0));
- }
- }
- }
- @@ -816,12 +816,12 @@ static void parse_axis() {
- } else base=0;
- parse_sequence(amap.plus, plus, base, amap.type);
- parse_sequence(amap.minus, minus, base, amap.type);
- - amap.axis=numeric(axis);
- + amap.axis=numeric(axis, 0);
- amap.flags=parse_flags(flags);
- - amap.min=numeric(min);
- - amap.max=numeric(max);
- - amap.deadzone=numeric(deadzone);
- - amap.speed=numeric(speed);
- + amap.min=numeric(min, -32768);
- + amap.max=numeric(max, 32767);
- + amap.deadzone=numeric(deadzone, 0);
- + amap.speed=numeric(speed, 0);
- if (amap.speed==0)
- amap.speed=32767;
- axes[naxes]=amap;
- @@ -849,21 +849,21 @@ static void parse_force_feedback() {
- } else {
- ffmap.program=PROGRAM_FORCE_REMAP;
- if (id!=NULL)
- - ffmap.joystick=numeric(id);
- + ffmap.joystick=numeric(id, 0);
- else
- ffmap.joystick=255;
- - ffmap.vendor=numeric(vendor);
- - ffmap.product=numeric(product);
- - ffmap.device=DEVICE_JOYSTICK + (numeric(device)&0xF);
- - ffmap.instance=numeric(instance);
- + ffmap.vendor=numeric(vendor, 0);
- + ffmap.product=numeric(product, 0);
- + ffmap.device=DEVICE_JOYSTICK + (numeric(device, 0)&0xF);
- + ffmap.instance=numeric(instance, 0);
- ffmap.forces=parse_forces(force_flags);
- ffmap.allocated=NULL;
- - ffmap.max_effects=numeric(max);
- + ffmap.max_effects=numeric(max, 0);
- if (ffmap.max_effects == 0) {
- ffmap.max_effects = 1;
- }
- forces[nforces]=ffmap;
- - num=numeric(device);
- + num=numeric(device, 0);
- if (num>8) {
- report("Maximum of 8 joysticks allowed");
- } else {
- @@ -890,18 +890,18 @@ static void parse_joystick() {
- if (device==NULL) {
- reportline(t.line, t.pos, "Must have device");
- } else {
- - num=numeric(device);
- + num=numeric(device, 0);
- if ((num<0)||(num>7)) reportline(t.line, t.pos, "Joystick must be 0-7");
- //printf("joystick ");
- //show_dictionary(dict);
- //printf("\n");
- if (num>=njoysticks) njoysticks=num+1;
- if (axes!=NULL)
- - joysticks[num].axes=numeric(axes);
- + joysticks[num].axes=numeric(axes, 0);
- else
- joysticks[num].axes=0;
- if (buttons!=NULL)
- - joysticks[num].buttons=numeric(buttons);
- + joysticks[num].buttons=numeric(buttons, 0);
- else
- joysticks[num].buttons=0;
- }
- @@ -932,7 +932,7 @@ static void parse_joysticks() {
- printf("joysticks ");
- if (t.type!=VALUE) {
- reportline(t.line, t.pos, "Value expected");
- - } else num=numeric(t.value);
- + } else num=numeric(t.value, 0);
- t=readtoken();
- while ((t.type!=NL)&&(t.type!=EOF)) {
- reportline(t.line, t.pos, "No further token expected on this line");
- diff --git a/mapper.h b/mapper.h
- index 83f8220..60b9916 100644
- --- a/mapper.h
- +++ b/mapper.h
- @@ -19,6 +19,8 @@ void set_num_axes(int js, int axes);
- void set_num_buttons(int js, int buttons);
- void set_joystick_has_button(int js, int button);
- void set_joystick_has_axis(int js, int axis);
- +void set_joystick_axis_min(int js, int axis, int value);
- +void set_joystick_axis_max(int js, int axis, int value);
- void set_joystick_ff_program(int js, struct program_force_remap *map);
- void set_skip_unused();
- void set_nograb();
- diff --git a/parser.h b/parser.h
- index 9f1999f..3fa3d67 100644
- --- a/parser.h
- +++ b/parser.h
- @@ -23,9 +23,9 @@
- #define RELEASE 270
- #define PHALT 271
- #define PTHREAD 272
- -#define NL 273
- -#define INCLUDE 274
- -#define PSIGNAL 275
- +#define NL 273
- +#define INCLUDE 274
- +#define PSIGNAL 275
- #define PEQ 276
- #define PNE 277
- #define PLE 278
- @@ -80,7 +80,7 @@ struct token peektoken();
- void eattoken();
- struct token readtoken();
- void init_tokenizer();
- -int numeric(char *s);
- +int numeric(char *s, int defaultvalue);
- int parse_map(void);
- int has_program_instance(uint16_t vendor, uint16_t product, int instance);
- int max_program_instance(uint16_t vendor, uint16_t product);
- diff --git a/programparser.c b/programparser.c
- index ec81776..bdd95a0 100644
- --- a/programparser.c
- +++ b/programparser.c
- @@ -587,7 +587,7 @@ static void parse_unit() {
- emit2(PUSH, sym, 0);
- break;
- case VALUE:
- - emitc(PUSH, numeric(t.value));
- + emitc(PUSH, numeric(t.value, 0));
- break;
- case '-':
- parse_unit();
- @@ -767,7 +767,7 @@ static void parse_var(int global) {
- if (t.type!=VALUE) {
- reportline(t.line, t.pos, "Only constant array dimensions are allowed");
- size=1;
- - } else size=numeric(t.value);
- + } else size=numeric(t.value, 0);
- if (t.type!=']') {
- eattoken();
- t=peektoken();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement