Skip to content

Commit

Permalink
Readed key.c to compile. Implemented smart config switching for all
Browse files Browse the repository at this point in the history
devices based on ir state.
  • Loading branch information
zakkudo committed Jan 21, 2015
1 parent 0954968 commit 3c47ab8
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 515 deletions.
3 changes: 1 addition & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ AM_CFLAGS = $(XORG_CFLAGS) $(SYSDEP_CFLAGS) -Wno-redundant-decls -Wno-cast-qual
@DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version
@DRIVER_NAME@_drv_la_LIBADD = $(SYSDEP_LIBS)
@DRIVER_NAME@_drv_ladir = @inputdir@
#@DRIVER_NAME@_drv_la_SOURCES = src/@DRIVER_NAME@
@DRIVER_NAME@_drv_la_SOURCES = src/analog-stick-axis.c src/analog-stick.c src/nunchuk.c src/wiimote.c src/ir.c src/accelerometer.c src/motionplus.c
@DRIVER_NAME@_drv_la_SOURCES = src/key.c src/xwiimote.c src/analog-stick-axis.c src/analog-stick.c src/nunchuk.c src/wiimote.c src/ir.c src/accelerometer.c src/motionplus.c
8 changes: 8 additions & 0 deletions src/accelerometer.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ void handle_accelerometer(struct accelerometer *accelerometer,

xf86PostMotionEvent(info->dev, 1, 0, 2, x, y);
}


void configure_accelerometer(struct accelerometer_config *config,
char const *name,
InputInfoPtr info)
{
/*TODO*/
}
1 change: 1 addition & 0 deletions src/accelerometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct accelerometer_config {


void handle_accelerometer(struct accelerometer *accelerometer, struct accelerometer_config *config, struct xwii_event *ev, InputInfoPtr info);
void configure_accelerometer(struct accelerometer_config *config, char const *name, InputInfoPtr info);

#endif

39 changes: 21 additions & 18 deletions src/analog-stick-axis.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,21 @@ static void print_analog_stick_config (struct analog_stick_axis_config *config,
}

void configure_analog_stick_axis(struct analog_stick_axis_config *config,
char const *name,
char const *value,
char const *option_key,
InputInfoPtr info)
{
char const *c = value;
char const *c;
char v[40];
int i;
double d;
char key_name[100];
char const *value;

value = xf86FindOptionValue(info->options, option_key);
if (!value)
return;

if (name) {
i = 0;
while (name[i] != '\0' && i < sizeof(config->name) - 1) {
config->name[i] = name[i];
i++;
}
config->name[i] = '\0';
}
c = value;

while (*c != '\0') {
/* Skip any possible whitespace */
Expand All @@ -102,25 +96,25 @@ void configure_analog_stick_axis(struct analog_stick_axis_config *config,
} else if (strcmp(v, "none") == 0) {
config->mode = ANALOG_STICK_AXIS_MODE_NONE;
} else {
xf86Msg(X_WARNING, "%s: error parsing mode. value: %s\n", config->name, v);
xf86Msg(X_WARNING, "%s: error parsing mode. value: %s\n", option_key, v);
}
} else if (sscanf(c, "keylow=%40s", v)) {
snprintf(key_name, sizeof(key_name), "%s low", config->name);
configure_key(&config->low, key_name, v, info);
snprintf(key_name, sizeof(key_name), "%s low", option_key);
configure_key_by_value(&config->low, key_name, v, info);
} else if (sscanf(c, "keyhigh=%40s", v)) {
snprintf(key_name, sizeof(key_name), "%s high", config->name);
configure_key(&config->high, key_name, v, info);
snprintf(key_name, sizeof(key_name), "%s high", option_key);
configure_key_by_value(&config->high, key_name, v, info);
} else if (sscanf(c, "deadzone=%i", &i)) {
if (i > 1 && i < 100) {
config->deadzone = i;
} else {
xf86Msg(X_WARNING, "%s: error parsing deadzone. value: %d\n", config->name, i);
xf86Msg(X_WARNING, "%s: error parsing deadzone. value: %d\n", option_key, i);
}
} else if (sscanf(c, "amplify=%lf", &d)) {
if (d >= 0.0 && d < 10.0) {
config->amplify = d;
} else {
xf86Msg(X_WARNING, "%s: error parsing amplify. value: %f\n", config->name, d);
xf86Msg(X_WARNING, "%s: error parsing amplify. value: %f\n", option_key, d);
}
}

Expand Down Expand Up @@ -195,5 +189,14 @@ void handle_analog_stick_axis(struct analog_stick_axis *axis,
xf86PostMotionEvent(info->dev, 0, first_valuator, 2 - first_valuator, axis->delta);
}

/* Give easy access to the state */
if (axis->low.state) {
axis->state = axis->low.state;
} else if (axis->high.state) {
axis->state = axis->high.state;
} else {
axis->state = 0;
}

axis->previous_value = value;
}
3 changes: 2 additions & 1 deletion src/analog-stick-axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct analog_stick_axis {
double subpixel; /*for ANALOG_STICK_MOTION_TYPE_RELATIVE*/
struct key high;
struct key low;
unsigned int state;
};

struct analog_stick_axis_config {
Expand All @@ -31,7 +32,7 @@ struct analog_stick_axis_config {
double amplify;
};

void configure_analog_stick_axis(struct analog_stick_axis_config *config, char const *name, char const *value, InputInfoPtr info);
void configure_analog_stick_axis(struct analog_stick_axis_config *config, char const *option_key, InputInfoPtr info);
void handle_analog_stick_axis(struct analog_stick_axis *axis, struct analog_stick_axis_config *config, int32_t value, int state, InputInfoPtr info, int first_valuator);

#endif
196 changes: 13 additions & 183 deletions src/analog-stick.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,186 +75,10 @@ static int analog_stick_map_y_to_circle(int x, int y) {
return analog_stick_map_x_to_circle(y, x);
}


/*
static struct analog_stick_func map_analog_stick_nunchuk_default[KEYSET_NUM] = {
[KEYSET_NORMAL] = {
.x = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_D,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_A,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
.y = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_W,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_S,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
},
[KEYSET_IR] = {
.x = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_D,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_A,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
.y = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_W,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_S,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
},
};
static struct analog_stick_func map_analog_stick_left_default[KEYSET_NUM] = {
[KEYSET_NORMAL] = {
.x = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_D,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_A,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
.y = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_W,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_S,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
},
[KEYSET_IR] = {
.x = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_D,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_A,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
.y = {
.mode = ANALOG_STICK_MODE_NONE,
.map_high = {
.type = FUNC_KEY,
.u.key = KEY_W,
},
.map_low = {
.type = FUNC_KEY,
.u.key = KEY_S,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
},
};
static struct analog_stick_func map_analog_stick_right_default[KEYSET_NUM] = {
[KEYSET_NORMAL] = {
.x = {
.mode = ANALOG_STICK_MODE_RELATIVE,
.map_high = {
.type = FUNC_IGNORE,
},
.map_low = {
.type = FUNC_IGNORE,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
.y = {
.mode = ANALOG_STICK_MODE_RELATIVE,
.map_high = {
.type = FUNC_IGNORE,
},
.map_low = {
.type = FUNC_IGNORE,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
},
[KEYSET_IR] = {
.x = {
.mode = ANALOG_STICK_MODE_RELATIVE,
.map_high = {
.type = FUNC_IGNORE,
},
.map_low = {
.type = FUNC_IGNORE,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
.y = {
.mode = ANALOG_STICK_MODE_RELATIVE,
.map_high = {
.type = FUNC_IGNORE,
},
.map_low = {
.type = FUNC_IGNORE,
},
.amplify = ANALOG_STICK_AMPLIFY_DEFAULT,
.deadzone = ANALOG_STICK_DEADZONE_DEFAULT,
},
},
};
*/


void configure_analog_stick(struct analog_stick_config *config,
char const *name,
InputInfoPtr info)
{
const char *value;
char axis_name[100];
int i;

Expand All @@ -268,18 +92,15 @@ void configure_analog_stick(struct analog_stick_config *config,
if (!name)
return;

if (snprintf(axis_name, 100, "%sX", name) < 100) {
value = xf86FindOptionValue(info->options, axis_name);
configure_analog_stick_axis (&config->x, name, value, info);
if (snprintf(axis_name, 100, "%sAnalogStickAxisX", name) < 100) {
configure_analog_stick_axis (&config->x, axis_name, info);
}

if (snprintf(axis_name, 100, "%sY", name) < 100) {
value = xf86FindOptionValue(info->options, axis_name);
configure_analog_stick_axis (&config->y, name, value, info);
if (snprintf(axis_name, 100, "%sAnalogStickAxisY", name) < 100) {
configure_analog_stick_axis (&config->y, axis_name, info);
}
}


void handle_analog_stick(struct analog_stick *stick,
struct analog_stick_config *config,
struct xwii_event *ev,
Expand Down Expand Up @@ -313,4 +134,13 @@ void handle_analog_stick(struct analog_stick *stick,

handle_analog_stick_axis(&stick->x, &config->x, mapped_x, state, info, 0);
handle_analog_stick_axis(&stick->y, &config->y, mapped_y, state, info, 1);

/* Give easy access to the state */
if (stick->x.state) {
stick->state = stick->x.state;
} else if (stick->y.state) {
stick->state = stick->y.state;
} else {
stick->state = 0;
}
}
1 change: 1 addition & 0 deletions src/analog-stick.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum analog_stick_shape {
struct analog_stick {
struct analog_stick_axis x;
struct analog_stick_axis y;
unsigned int state;
};

struct analog_stick_config {
Expand Down
Loading

0 comments on commit 3c47ab8

Please sign in to comment.