mirror of https://github.com/nirenjan/libx52.git
Add axis API implementation
parent
329274e6c9
commit
aebd5e14f9
|
@ -13,7 +13,7 @@ lib_LTLIBRARIES = libx52io.la
|
||||||
libx52io_v_CUR=0
|
libx52io_v_CUR=0
|
||||||
libx52io_v_AGE=0
|
libx52io_v_AGE=0
|
||||||
libx52io_v_REV=0
|
libx52io_v_REV=0
|
||||||
libx52io_la_SOURCES = io_core.c
|
libx52io_la_SOURCES = io_core.c io_axis.c
|
||||||
libx52io_la_CFLAGS = @HIDAPI_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -I $(top_srcdir) $(WARN_CFLAGS)
|
libx52io_la_CFLAGS = @HIDAPI_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -I $(top_srcdir) $(WARN_CFLAGS)
|
||||||
libx52io_la_LDFLAGS = \
|
libx52io_la_LDFLAGS = \
|
||||||
-export-symbols-regex '^libx52io_' \
|
-export-symbols-regex '^libx52io_' \
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Saitek X52 IO driver - axis ranges
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012-2020 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include "io_common.h"
|
||||||
|
|
||||||
|
static const int32_t x52_axis_max[] = {
|
||||||
|
2047, 2047, 1023, 255, 255, 255, 255, 15, 15
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int32_t x52pro_axis_max[] = {
|
||||||
|
1023, 1023, 1023, 255, 255, 255, 255, 15, 15
|
||||||
|
};
|
||||||
|
|
||||||
|
void _x52io_set_axis_range(libx52io_context *ctx)
|
||||||
|
{
|
||||||
|
switch (ctx->pid) {
|
||||||
|
case 0x0255:
|
||||||
|
case 0x075c:
|
||||||
|
memcpy(ctx->axis_max, x52_axis_max, sizeof(ctx->axis_max));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x0762:
|
||||||
|
memcpy(ctx->axis_max, x52pro_axis_max, sizeof(ctx->axis_max));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int libx52io_get_axis_range(libx52io_context *ctx,
|
||||||
|
libx52io_axis axis,
|
||||||
|
int32_t *min,
|
||||||
|
int32_t *max)
|
||||||
|
{
|
||||||
|
if (ctx == NULL || min == NULL || max == NULL) {
|
||||||
|
return LIBX52IO_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (axis < 0 || axis >= LIBX52IO_AXIS_MAX) {
|
||||||
|
return LIBX52IO_ERROR_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->handle == NULL) {
|
||||||
|
return LIBX52IO_ERROR_NO_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* All axis ranges start at 0, only the max value changes between
|
||||||
|
* X52 and X52Pro
|
||||||
|
*/
|
||||||
|
*min = 0;
|
||||||
|
*max = ctx->axis_max[axis];
|
||||||
|
|
||||||
|
return LIBX52IO_SUCCESS;
|
||||||
|
}
|
|
@ -19,7 +19,6 @@ typedef int (*x52_parse_report)(unsigned char *data, int length);
|
||||||
struct libx52io_context {
|
struct libx52io_context {
|
||||||
hid_device *handle;
|
hid_device *handle;
|
||||||
|
|
||||||
int32_t axis_min[LIBX52IO_AXIS_MAX];
|
|
||||||
int32_t axis_max[LIBX52IO_AXIS_MAX];
|
int32_t axis_max[LIBX52IO_AXIS_MAX];
|
||||||
|
|
||||||
int16_t pid;
|
int16_t pid;
|
||||||
|
|
|
@ -84,7 +84,7 @@ int libx52io_open(libx52io_context *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->pid = cur_dev->product_id;
|
ctx->pid = cur_dev->product_id;
|
||||||
/* _x52io_set_axis_range(ctx); */
|
_x52io_set_axis_range(ctx);
|
||||||
/* _x52io_set_report_parser(ctx); */
|
/* _x52io_set_report_parser(ctx); */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue