1.1 --- a/src/joystick/bsd/SDL_sysjoystick.c Sun Mar 10 03:38:32 2002 +0000
1.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c Sun Mar 10 03:49:25 2002 +0000
1.3 @@ -52,11 +52,6 @@
1.4 #define MAX_JOY_JOYS 2
1.5 #define MAX_JOYS (MAX_UHID_JOYS + MAX_JOY_JOYS)
1.6
1.7 -#define SDLAXIS_UINT8(v) \
1.8 - ((v == 127) ? 0 : \
1.9 - (v == 255) ? 32767 : \
1.10 - -32767)
1.11 -
1.12 struct report {
1.13 struct usb_ctl_report *buf; /* Buffer */
1.14 size_t size; /* Buffer size */
1.15 @@ -77,9 +72,20 @@
1.16 { UHID_OUTPUT_REPORT, hid_output, "output" },
1.17 { UHID_FEATURE_REPORT, hid_feature, "feature" }
1.18 };
1.19 -#define REPORT_INPUT 0
1.20 -#define REPORT_OUTPUT 1
1.21 -#define REPORT_FEATURE 2
1.22 +
1.23 +enum {
1.24 + REPORT_INPUT = 0,
1.25 + REPORT_OUTPUT = 1,
1.26 + REPORT_FEATURE = 2
1.27 +};
1.28 +
1.29 +enum {
1.30 + JOYAXE_X,
1.31 + JOYAXE_Y,
1.32 + JOYAXE_Z,
1.33 + JOYAXE_SLIDER,
1.34 + JOYAXE_WHEEL
1.35 +};
1.36
1.37 struct joystick_hwdata {
1.38 int fd;
1.39 @@ -90,8 +96,10 @@
1.40 } type;
1.41 struct report_desc *repdesc;
1.42 struct report inreport;
1.43 - int axismin[3];
1.44 - int axismax[3];
1.45 +#if 0
1.46 + int axismin[];
1.47 + int axismax[];
1.48 +#endif
1.49 };
1.50
1.51 static char *joynames[MAX_JOYS];
1.52 @@ -181,7 +189,8 @@
1.53 goto usberr;
1.54 }
1.55 if (rep->size <= 0) {
1.56 - SDL_SetError("Input report descriptor has invalid length");
1.57 + SDL_SetError("%s: Input report descriptor has invalid length",
1.58 + hw->path);
1.59 goto usberr;
1.60 }
1.61
1.62 @@ -222,10 +231,14 @@
1.63 case HUG_X:
1.64 case HUG_Y:
1.65 case HUG_Z:
1.66 + case HUG_SLIDER:
1.67 + case HUG_WHEEL:
1.68 +#if 0
1.69 hw->axismin[joy->naxes] =
1.70 hitem.logical_minimum;
1.71 hw->axismax[joy->naxes] =
1.72 hitem.logical_maximum;
1.73 +#endif
1.74 joy->naxes++;
1.75 break;
1.76 }
1.77 @@ -257,8 +270,9 @@
1.78 {
1.79 static struct hid_item hitem;
1.80 static struct hid_data *hdata;
1.81 - static int nbutton, naxe, v, max, min;
1.82 static struct report *rep;
1.83 + int nbutton, naxe;
1.84 + Sint32 v;
1.85
1.86 rep = &joy->hwdata->inreport;
1.87 if (read(joy->hwdata->fd, rep->buf->data, rep->size) != rep->size) {
1.88 @@ -271,7 +285,7 @@
1.89 return;
1.90 }
1.91
1.92 - for (nbutton = 0, naxe = 0; hid_get_item(hdata, &hitem) > 0;) {
1.93 + for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
1.94 switch (hitem.kind) {
1.95 case hid_input:
1.96 switch (HID_PAGE(hitem.usage)) {
1.97 @@ -280,31 +294,43 @@
1.98 case HUP_GENERIC_DESKTOP:
1.99 switch (HID_USAGE(hitem.usage)) {
1.100 case HUG_X:
1.101 + naxe = JOYAXE_X;
1.102 + goto scaleaxe;
1.103 case HUG_Y:
1.104 + naxe = JOYAXE_Y;
1.105 + goto scaleaxe;
1.106 case HUG_Z:
1.107 - v = hid_get_data(rep->buf->data,
1.108 - &hitem);
1.109 -
1.110 - /*
1.111 - * XXX revisit later. need to test
1.112 - * with more devices.
1.113 - */
1.114 - if (joy->hwdata->axismin[naxe] == 0 &&
1.115 - joy->hwdata->axismax[naxe] == 255) {
1.116 - v = SDLAXIS_UINT8(v);
1.117 + naxe = JOYAXE_Z;
1.118 + goto scaleaxe;
1.119 + case HUG_SLIDER:
1.120 + naxe = JOYAXE_SLIDER;
1.121 + goto scaleaxe;
1.122 + case HUG_WHEEL:
1.123 + naxe = JOYAXE_WHEEL;
1.124 + goto scaleaxe;
1.125 + }
1.126 +scaleaxe:
1.127 + v = (Sint32)hid_get_data(rep->buf->data, &hitem);
1.128 + if (v != 127) {
1.129 + if (v < 127) {
1.130 + v = -(256 - v);
1.131 + v <<= 7;
1.132 + v++;
1.133 + } else {
1.134 + v++;
1.135 + v <<= 7;
1.136 + v--;
1.137 }
1.138 -
1.139 - if (v != joy->axes[naxe]) {
1.140 - SDL_PrivateJoystickAxis(joy,
1.141 - naxe, (Sint32)v);
1.142 - }
1.143 - naxe++;
1.144 - break;
1.145 + } else {
1.146 + v = 0;
1.147 + }
1.148 + if (v != joy->axes[naxe]) {
1.149 + SDL_PrivateJoystickAxis(joy, naxe, v);
1.150 }
1.151 break;
1.152 case HUP_BUTTON:
1.153 - /* XXX assume a 0..1 range */
1.154 - v = hid_get_data(rep->buf->data, &hitem);
1.155 + v = (Sint32)hid_get_data(rep->buf->data,
1.156 + &hitem);
1.157 if (joy->buttons[nbutton] != v) {
1.158 SDL_PrivateJoystickButton(joy,
1.159 nbutton, v);