mirror of https://github.com/nirenjan/libx52.git
Add HATX and HATY axis values
parent
2c40785c2b
commit
a0b7769dab
|
@ -10,12 +10,16 @@
|
|||
#include "io_common.h"
|
||||
#include "usb-ids.h"
|
||||
|
||||
static const int32_t axis_min[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1
|
||||
};
|
||||
|
||||
static const int32_t x52_axis_max[] = {
|
||||
2047, 2047, 1023, 255, 255, 255, 255, 15, 15
|
||||
2047, 2047, 1023, 255, 255, 255, 255, 15, 15, 1, 1
|
||||
};
|
||||
|
||||
static const int32_t x52pro_axis_max[] = {
|
||||
1023, 1023, 1023, 255, 255, 255, 255, 15, 15
|
||||
1023, 1023, 1023, 255, 255, 255, 255, 15, 15, 1, 1
|
||||
};
|
||||
|
||||
void _x52io_set_axis_range(libx52io_context *ctx)
|
||||
|
@ -23,10 +27,12 @@ void _x52io_set_axis_range(libx52io_context *ctx)
|
|||
switch (ctx->pid) {
|
||||
case X52_PROD_X52_1:
|
||||
case X52_PROD_X52_2:
|
||||
memcpy(ctx->axis_min, axis_min, sizeof(ctx->axis_min));
|
||||
memcpy(ctx->axis_max, x52_axis_max, sizeof(ctx->axis_max));
|
||||
break;
|
||||
|
||||
case X52_PROD_X52PRO:
|
||||
memcpy(ctx->axis_min, axis_min, sizeof(ctx->axis_min));
|
||||
memcpy(ctx->axis_max, x52pro_axis_max, sizeof(ctx->axis_max));
|
||||
break;
|
||||
|
||||
|
@ -52,11 +58,7 @@ int libx52io_get_axis_range(libx52io_context *ctx,
|
|||
return LIBX52IO_ERROR_NO_DEVICE;
|
||||
}
|
||||
|
||||
/*
|
||||
* All axis ranges start at 0, only the max value changes between
|
||||
* X52 and X52Pro
|
||||
*/
|
||||
*min = 0;
|
||||
*min = ctx->axis_min[axis];
|
||||
*max = ctx->axis_max[axis];
|
||||
|
||||
return LIBX52IO_SUCCESS;
|
||||
|
|
|
@ -19,6 +19,7 @@ typedef int (*x52_parse_report)(unsigned char *data, int length, libx52io_report
|
|||
struct libx52io_context {
|
||||
hid_device *handle;
|
||||
|
||||
int32_t axis_min[LIBX52IO_AXIS_MAX];
|
||||
int32_t axis_max[LIBX52IO_AXIS_MAX];
|
||||
|
||||
int16_t pid;
|
||||
|
|
|
@ -109,6 +109,12 @@ typedef enum {
|
|||
/** Thumbstick Y */
|
||||
LIBX52IO_AXIS_THUMBY,
|
||||
|
||||
/** Hat X */
|
||||
LIBX52IO_AXIS_HATX,
|
||||
|
||||
/** Hat Y */
|
||||
LIBX52IO_AXIS_HATY,
|
||||
|
||||
LIBX52IO_AXIS_MAX
|
||||
} libx52io_axis;
|
||||
|
||||
|
|
|
@ -58,29 +58,33 @@ static int group_teardown(void **state)
|
|||
|
||||
/* List of test cases - list the axis and the corresponding maximum for that axis */
|
||||
#define TEST_CASES \
|
||||
TEST_X52(X, 2047) \
|
||||
TEST_X52(Y, 2047) \
|
||||
TEST_X52(RZ, 1023) \
|
||||
TEST_X52(Z, 255) \
|
||||
TEST_X52(RX, 255) \
|
||||
TEST_X52(RY, 255) \
|
||||
TEST_X52(SLIDER, 255) \
|
||||
TEST_X52(THUMBX, 15) \
|
||||
TEST_X52(THUMBY, 15) \
|
||||
TEST_PRO(X, 1023) \
|
||||
TEST_PRO(Y, 1023) \
|
||||
TEST_PRO(RZ, 1023) \
|
||||
TEST_PRO(Z, 255) \
|
||||
TEST_PRO(RX, 255) \
|
||||
TEST_PRO(RY, 255) \
|
||||
TEST_PRO(SLIDER, 255) \
|
||||
TEST_PRO(THUMBX, 15) \
|
||||
TEST_PRO(THUMBY, 15)
|
||||
TEST_X52(X, 0, 2047) \
|
||||
TEST_X52(Y, 0, 2047) \
|
||||
TEST_X52(RZ, 0, 1023) \
|
||||
TEST_X52(Z, 0, 255) \
|
||||
TEST_X52(RX, 0, 255) \
|
||||
TEST_X52(RY, 0, 255) \
|
||||
TEST_X52(SLIDER, 0, 255) \
|
||||
TEST_X52(THUMBX, 0, 15) \
|
||||
TEST_X52(THUMBY, 0, 15) \
|
||||
TEST_X52(HATX, -1, 1) \
|
||||
TEST_X52(HATY, -1, 1) \
|
||||
TEST_PRO(X, 0, 1023) \
|
||||
TEST_PRO(Y, 0, 1023) \
|
||||
TEST_PRO(RZ, 0, 1023) \
|
||||
TEST_PRO(Z, 0, 255) \
|
||||
TEST_PRO(RX, 0, 255) \
|
||||
TEST_PRO(RY, 0, 255) \
|
||||
TEST_PRO(SLIDER, 0, 255) \
|
||||
TEST_PRO(THUMBX, 0, 15) \
|
||||
TEST_PRO(THUMBY, 0, 15) \
|
||||
TEST_PRO(HATX, -1, 1) \
|
||||
TEST_PRO(HATY, -1, 1)
|
||||
|
||||
#define TEST_X52(axis, max) TEST(_1, axis, max) TEST(_2, axis, max)
|
||||
#define TEST_PRO(axis, max) TEST(PRO, axis, max)
|
||||
#define TEST_X52(axis, min, max) TEST(_1, axis, min, max) TEST(_2, axis, min, max)
|
||||
#define TEST_PRO(axis, min, max) TEST(PRO, axis, min, max)
|
||||
|
||||
#define TEST(prodid, axis, maxval) \
|
||||
#define TEST(prodid, axis, minval, maxval) \
|
||||
static void axis ## _ ## prodid (void **state) \
|
||||
{ \
|
||||
libx52io_context *ctx = *state; \
|
||||
|
@ -90,7 +94,7 @@ static int group_teardown(void **state)
|
|||
_x52io_set_axis_range(ctx); \
|
||||
rc = libx52io_get_axis_range(ctx, LIBX52IO_AXIS_ ## axis, &min, &max); \
|
||||
assert_int_equal(rc, LIBX52IO_SUCCESS); \
|
||||
assert_int_equal(min, 0); \
|
||||
assert_int_equal(min, minval); \
|
||||
assert_int_equal(max, maxval); \
|
||||
}
|
||||
|
||||
|
@ -123,7 +127,7 @@ static void test_error_case(void **state)
|
|||
assert_int_equal(rc, LIBX52IO_ERROR_NO_DEVICE);
|
||||
}
|
||||
|
||||
#define TEST(prodid, axis, maxval) cmocka_unit_test_setup_teardown(axis ## _ ## prodid, test_setup, test_teardown),
|
||||
#define TEST(prodid, axis, minval, maxval) cmocka_unit_test_setup_teardown(axis ## _ ## prodid, test_setup, test_teardown),
|
||||
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(test_error_case, test_setup, test_teardown),
|
||||
|
|
Loading…
Reference in New Issue