Revision: 45576
http://sourceforge.net/p/vice-emu/code/45576
Author: compyx
Date: 2025-03-24 07:05:56 +0000 (Mon, 24 Mar 2025)
Log Message:
-----------
Joystick: make `joy_axis_event()` accept raw values
Drivers can pass their raw axis values to `joy_axis_event()`, interpretation of
the value is done in common code by applying calibration (thresholds) and then
determining direction of axis. Linux evdev has been updated. SDL, Win32 and BSD
will follow shortly.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
branches/compyx/joymap-001/vice/src/joyport/joystick.h
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-24 06:45:21 UTC (rev 45575)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-24 07:05:56 UTC (rev 45576)
@@ -157,24 +157,7 @@
#endif
axis = joystick_axis_from_code(joydev, event->code);
if (axis != NULL) {
- int32_t minimum = axis->minimum;
- int32_t maximum = axis->maximum;
- int32_t range = maximum - minimum;
- joystick_axis_value_t direction = JOY_AXIS_MIDDLE;
-
- /* ABS_HAT[0-3]XY axes return -1, 0 or 1: */
- if (minimum == -1 && maximum == 1) {
- if (event->value < 0) {
- direction = JOY_AXIS_NEGATIVE;
- } else if (event->value > 0) {
- direction = JOY_AXIS_POSITIVE;
- }
- } else if (event->value < (minimum + (range / 4))) {
- direction = JOY_AXIS_NEGATIVE;
- } else if (event->value > (maximum - (range / 4))) {
- direction = JOY_AXIS_POSITIVE;
- }
- joy_axis_event(joydev, axis, direction);
+ joy_axis_event(joydev, axis, event->value);
}
}
}
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-24 06:45:21 UTC (rev 45575)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-24 07:05:56 UTC (rev 45576)
@@ -2999,17 +2999,35 @@
void joy_axis_event(joystick_device_t *joydev,
joystick_axis_t *axis,
- joystick_axis_value_t value)
+ int32_t value)
{
- joystick_axis_value_t prev = axis->prev;
- int joyport = joydev->joyport;
+ joystick_axis_value_t direction = JOY_AXIS_MIDDLE;
+ joystick_axis_value_t prev = axis->prev;
+ int joyport = joydev->joyport;
- if (value == prev) {
+
+ /* digital axes don't require calibration: */
+ if (axis->digital) {
+ if (value < 0) {
+ direction = JOY_AXIS_NEGATIVE;
+ } else if (value > 0) {
+ direction = JOY_AXIS_POSITIVE;
+ }
+ } else {
+ /* here we apply calibration */
+ if (value <= axis->calibration.threshold.negative) {
+ direction = JOY_AXIS_NEGATIVE;
+ } else if (value >= axis->calibration.threshold.positive) {
+ direction = JOY_AXIS_POSITIVE;
+ }
+ }
+
+ if (direction == prev) {
return;
}
- DBG(("joy_axis_event: joy: %s axis: %d value: %d prev: %u\n",
- joydev->name, axis->index, value, prev));
+ DBG(("joy_axis_event: joy: %s axis: %d value: %d: direction: %d prev: %d\n",
+ joydev->name, axis->index, value, direction, prev));
/* release directions first if needed */
if (prev == JOY_AXIS_POSITIVE) {
@@ -3020,14 +3038,14 @@
}
/* press new direction if needed */
- if (value == JOY_AXIS_POSITIVE) {
+ if (direction == JOY_AXIS_POSITIVE) {
joy_perform_event(&axis->mapping.positive, joyport, 1);
}
- if (value == JOY_AXIS_NEGATIVE) {
+ if (direction == JOY_AXIS_NEGATIVE) {
joy_perform_event(&axis->mapping.negative, joyport, 1);
}
- axis->prev = value;
+ axis->prev = direction;
}
void joy_button_event(joystick_device_t *joydev,
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.h
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-24 06:45:21 UTC (rev 45575)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.h 2025-03-24 07:05:56 UTC (rev 45576)
@@ -179,7 +179,8 @@
*/
typedef struct joystick_calibration_s {
bool invert; /**< invert value */
- struct {
+ struct
+ {
int32_t negative; /**< axis threshold: V <= T: active input */
int32_t positive; /**< axis threshold: V >= T: active input */
} threshold;
@@ -379,15 +380,9 @@
void joystick_set_snes_mapping(int port);
-/* TODO: Pass raw value to joy_axis_event(), let the joystick code figure out
- * what the axis value should be, based on limits and calibration data
- * inside the axis object.
- * Same for buttons and hats: let the joystick code decide what to do,
- * not the driver.
- */
-void joy_axis_event (joystick_device_t *joydev, joystick_axis_t *axis, joystick_axis_value_t value);
-void joy_button_event(joystick_device_t *joydev, joystick_button_t *button, int32_t value);
-void joy_hat_event (joystick_device_t *joydev, joystick_hat_t *hat, int32_t value);
+void joy_axis_event (joystick_device_t *joydev, joystick_axis_t *axis, int32_t value);
+void joy_button_event(joystick_device_t *joydev, joystick_button_t *button, int32_t value);
+void joy_hat_event (joystick_device_t *joydev, joystick_hat_t *hat, int32_t value);
void joystick(void);
void joystick_close(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|