Example #1
0
int joystickb_svgalib_stick_axe_analog_get(unsigned joystick, unsigned stick, unsigned axe)
{
	int r;
	log_debug(("joystickb:svgalib: joystickb_svgalib_stick_axe_analog_get()\n"));

	r = joystick_getaxis(joystick, axe);

	r = joystickb_adjust_analog(r, -128, 127);

	return r;
}
Example #2
0
int joystickb_sdl_stick_axe_analog_get(unsigned joystick, unsigned stick, unsigned axe)
{
	int r;
	log_debug(("joystickb:sdl: joystickb_sdl_stick_axe_analog_get()\n"));

	r = SDL_JoystickGetAxis(sdl_state.map[joystick], axe);

	r = joystickb_adjust_analog(r, -32768, 32768);

	return r;
}
Example #3
0
unsigned joystickb_svgalib_stick_axe_digital_get(unsigned joystick, unsigned stick, unsigned axe, unsigned d)
{
	int r;
	log_debug(("joystickb:svgalib: joystickb_svgalib_stick_axe_digital_get()\n"));

	r = joystick_getaxis(joystick, axe);

	r = joystickb_adjust_analog(r, -128, 127);

	if (d)
		return r < -JOYSTICK_DRIVER_BASE/8; /* -1/8 of the partial range */
	else
		return r > JOYSTICK_DRIVER_BASE/8; /* +1/8 of the partial range */
}
Example #4
0
static void joystickb_raw_axe_set(struct joystick_axe_context* axe, int value)
{
	axe->value = value;

	axe->value_adj = joystickb_adjust_analog(value, -32767, 32767);
}
Example #5
0
static void raw_event(RAWINPUT* r)
{
	unsigned i;
	RAWMOUSE* m;
	struct raw_context* c;

	if (r->header.dwType != RIM_TYPEMOUSE) {
		log_std(("WARNING:joystickb:lgrawinput: not a mouse device\n"));
		return;
	}

	/* search the device */
	for (i = 0; i < raw_state.mac; ++i)
		if (r->header.hDevice == raw_state.map[i].context.h)
			break;

	if (i == raw_state.mac) {
		log_std(("WARNING:joystickb:lgrawinput: input device not found\n"));
		return;
	}

	m = &r->data.mouse;
	c = &raw_state.map[i].context;

	log_debug(("joystickb:lgrawinput: device:%d -> usFlags:%d,usButtonFlags:%d,ulRawButtons:%d,lLastX:%d,lLastY:%d,ulExtraInformation:%d\n", i, (unsigned)m->usFlags, (unsigned)m->usButtonFlags, (unsigned)m->ulRawButtons, (unsigned)m->lLastX, (unsigned)m->lLastY, (unsigned)m->ulExtraInformation));

	if (m->usFlags & MOUSE_MOVE_ABSOLUTE) {
		/* absolute */
		c->x = m->lLastX;
		c->y = m->lLastY;
	} else {
		log_std(("WARNING:joystickb:lgrawinput: device:%d relative move\n", i));
	}

	if (m->usButtonFlags & RI_MOUSE_BUTTON_1_DOWN)
		c->button |= 0x1;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_1_UP)
		c->button &= ~0x1;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_2_DOWN)
		c->button |= 0x2;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_2_UP)
		c->button &= ~0x2;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_3_DOWN)
		c->button |= 0x4;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_3_UP)
		c->button &= ~0x4;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_4_DOWN)
		c->button |= 0x8;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_4_UP)
		c->button &= ~0x8;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_5_DOWN)
		c->button |= 0x10;
	if (m->usButtonFlags & RI_MOUSE_BUTTON_5_UP)
		c->button &= ~0x10;

	/* update autocalibration */
	if (c->lx == 0 && c->hx == 0) {
		c->lx = c->x;
		c->hx = c->x;
	} else {
		if (c->x < c->lx)
			c->lx = c->x;
		if (c->x > c->hx)
			c->hx = c->x;
	}
	if (c->ly == 0 && c->hy == 0) {
		c->ly = c->y;
		c->hy = c->y;
	} else {
		if (c->y < c->ly)
			c->ly = c->y;
		if (c->y > c->hy)
			c->hy = c->y;
	}

	if (raw_option.calibration == CALIBRATION_AUTO) {
		c->x_adj = joystickb_adjust_analog(c->x, c->lx, c->hx);
		c->y_adj = joystickb_adjust_analog(c->y, c->ly, c->hy);
	} else if (raw_option.calibration == CALIBRATION_NONE) {
		c->x_adj = joystickb_adjust_analog(c->x, 0, 65536);
		c->y_adj = joystickb_adjust_analog(c->y, 0, 65536);
	} else {
		c->x_adj = 0;
		c->y_adj = 0;
	}

	log_debug(("joystickb:lgrawinput: id:%d,x:%d[%d:%d>%d],y:%d[%d:%d>%d],button:%d\n", i, c->x, c->lx, c->hx, c->x_adj, c->y, c->ly, c->hy, c->y_adj, c->button));
}
void joystickb_lgallegro_poll(void)
{
	unsigned j, s, a;

	log_debug(("joystickb:lgallegro: joystickb_lgallegro_poll()\n"));

	target_clock_t now = target_clock();

	if (lgallegro_option.filter == FILTER_AUTO
		|| lgallegro_option.filter == FILTER_TIME
	) {
		/* don't poll too frequently */
		if (now - lgallegro_state.last > TARGET_CLOCKS_PER_SEC / 30) {
			log_debug(("joystickb:lgallegro: effective poll\n"));
			lgallegro_state.last = now;
			poll_joystick();
		} else {
			log_debug(("joystickb:lgallegro: skipped poll\n"));
		}
	} else {
		lgallegro_state.last = now;
		poll_joystick();
	}

	for(j=0;j<joystickb_lgallegro_count_get();++j) {
		for(s=0;s<joystickb_lgallegro_stick_count_get(j);++s) {
			for(a=0;a<joystickb_lgallegro_stick_axe_count_get(j,s);++a) {
				struct joystick_axe_context* c = &lgallegro_state.map[j].axe_map[s][a];

				int r = joy[j].stick[s].axis[a].pos;

				if (lgallegro_option.filter == FILTER_VALUE) {
					int limit = 127;
					if (r <= -limit || r >= limit) {
						/* skip */
						continue;
					}
				}

				/* store the new values */
				c->v = r;
				c->d1 = joy[j].stick[s].axis[a].d1;
				c->d2 = joy[j].stick[s].axis[a].d2;

				/* update autocalibration */
				if (c->l == 0 && c->h == 0) {
					c->l = c->v;
					c->h = c->v;
				} else {
					if (c->v < c->l)
						c->l = c->v;
					if (c->v > c->h)
						c->h = c->v;
				}

				if (lgallegro_option.calibration == CALIBRATION_AUTO) {
					c->a = joystickb_adjust_analog(c->v, c->l, c->h);
				} else if (lgallegro_option.calibration == CALIBRATION_NONE) {
					c->a = joystickb_adjust_analog(c->v, -128, 128);
				} else {
					c->a = 0;
				}

				log_debug(("joystickb:lgallegro: id:%d,%d,%d,v:%d[%d:%d>%d]\n", j, s, a, c->v, c->l, c->h, c->a));
			}
		}
	}
}
Example #7
0
static void joystickb_event_axe_set(struct joystick_axe_context* axe, int value)
{
/*
   The min_value is the minimum value that this particular axis can return, while
   the max_value is the maximum value that it can return. The fuzz element is the
   range of values that can be considered the same (due to mechanical sensor
   tolerances, or some other reason), and is zero for most devices. The flat is the
   range of values about the mid-point in the axes that are indicate a zero
   response (typically, this is the "dead zone" around the null position of a
   joystick).
*/
	int min = axe->min;
	int max = axe->max;
	int fuzz = axe->fuzz;
	int flat = axe->flat;

	axe->value = value;

	if (min >= max) {
		/* adjustment not possible */
		axe->value_adj = 0;
		return;
	}

	if (fuzz) {
		/* detect edge values with some error */

		int fuzz_min = min + fuzz;
		int fuzz_max = max - fuzz;

		if (value < fuzz_min) {
			axe->value_adj = -JOYSTICK_DRIVER_BASE;
			return;
		}

		if (value > fuzz_max) {
			axe->value_adj = JOYSTICK_DRIVER_BASE;
			return;
		}
	}

	if (flat) {
		/* remove the dead zone */

		int middle = (max + min) / 2;
		int flat_min = middle - flat;
		int flat_max = middle + flat;

		if (flat_min <= value && value <= flat_max) {
			/* center position */
			axe->value_adj = 0;
			return;
		}

		if (min + 2 * flat >= max) {
			/* adjustment not possible */
			axe->value_adj = 0;
			return;
		}

		min += flat;
		max -= flat;

		if (value < middle) {
			value += flat;
		} else {
			value -= flat;
		}
	}

	axe->value_adj = joystickb_adjust_analog(value, min, max);
}