From 7a5550c7cb2fc0619c560e9cba754cd2a8907a00 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Mon, 22 Jan 2001 12:27:55 +0000 Subject: [PATCH] joystick support --- input/linux/include/joy.h | 8 +++--- input/linux/joystick.c | 27 ++++++++++--------- main/kconfig.c | 56 ++++++++++++++++++++++----------------- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/input/linux/include/joy.h b/input/linux/include/joy.h index feb93457a..b4d731a77 100644 --- a/input/linux/include/joy.h +++ b/input/linux/include/joy.h @@ -29,15 +29,15 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define JOY_2_Y_AXIS 8 #define JOY_ALL_AXIS (1+2+4+8) -#define JOY_SLOW_READINGS 1 -#define JOY_POLLED_READINGS 2 -#define JOY_BIOS_READINGS 4 +#define JOY_SLOW_READINGS 1 +#define JOY_POLLED_READINGS 2 +#define JOY_BIOS_READINGS 4 #define JOY_FRIENDLY_READINGS 8 #define MAX_AXES 32 #define MAX_BUTTONS 64 -#define JOY_NUM_AXES 4 +#define JOY_NUM_AXES 5 typedef struct joystick_device { int device_number; diff --git a/input/linux/joystick.c b/input/linux/joystick.c index 6c9a1ee08..ab23e6af7 100644 --- a/input/linux/joystick.c +++ b/input/linux/joystick.c @@ -1,7 +1,7 @@ #include #include #include -//#include "joystick.h" +#include "joystick.h" #include #include #include @@ -49,7 +49,7 @@ int j_Get_joydev_button_number (int all_button_number) { int j_Update_state () { -/* int num_processed = 0, i; + int num_processed = 0, i; struct js_event current_event; struct JS_DATA_TYPE joy_data; @@ -89,8 +89,7 @@ int j_Update_state () { } } - return num_processed;*/ - return 0; + return num_processed; } @@ -166,7 +165,7 @@ ubyte joystick_read_raw_axis (ubyte mask, int *axes) { j_Update_state(); - for (i = 0; i <= j_num_axes; i++) { + for (i = 0; i < j_num_axes; i++) { axes[i] = j_axis[i].value; } @@ -185,7 +184,7 @@ int joy_init () { if (!joy_installed) { -// printf ("Initializing joystick... "); + printf ("Initializing joystick... "); j_joystick[0].buffer = open ("/dev/js0", O_NONBLOCK); j_joystick[1].buffer = open ("/dev/js1", O_NONBLOCK); @@ -193,21 +192,23 @@ int joy_init () { j_joystick[3].buffer = open ("/dev/js3", O_NONBLOCK); if (j_joystick[0].buffer >= 0 || j_joystick[1].buffer >= 0 || j_joystick[2].buffer >= 0 || j_joystick[3].buffer >= 0) { -// printf ("found: "); + printf ("found: "); for (i = 0; i < 4; i++) { if (j_joystick[i].buffer >= 0) { - /* ioctl (j_joystick[i].buffer, JSIOCGAXES, &j_joystick[i].num_axes); ioctl (j_joystick[i].buffer, JSIOCGBUTTONS, &j_joystick[i].num_buttons); ioctl (j_joystick[i].buffer, JSIOCGVERSION, &j_joystick[i].version); -*/ if (!j_joystick[i].version) { j_joystick[i].num_axes = 2; j_joystick[i].num_buttons = 2; -// printf ("js%d (v0.x) " , i); + printf ("js%d (v0.x) " , i); } else { -// printf ("js%d (v%d.%d.%d) ", i, (j_joystick[i].version & 0xff0000) >> 16, (j_joystick[i].version & 0xff00) >> 8, j_joystick[i].version & 0xff); + printf ("js%d (v%d.%d.%d) ", + i, + (j_joystick[i].version & 0xff0000) >> 16, + (j_joystick[i].version & 0xff00) >> 8, + j_joystick[i].version & 0xff); } for (j = j_num_axes; j < (j_num_axes + j_joystick[i].num_axes); j++) { @@ -236,11 +237,11 @@ int joy_init () { } } } else { -// printf ("no joysticks found\n"); + printf ("no joysticks found\n"); return 0; } -// printf ("\n"); + printf ("\n"); if (j_num_axes > MAX_AXES) j_num_axes = MAX_AXES; diff --git a/main/kconfig.c b/main/kconfig.c index 94ea571ac..ea7164268 100644 --- a/main/kconfig.c +++ b/main/kconfig.c @@ -13,7 +13,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifdef RCS -static char rcsid[] = "$Id: kconfig.c,v 1.2 2001-01-20 13:49:15 bradleyb Exp $"; +static char rcsid[] = "$Id: kconfig.c,v 1.3 2001-01-22 12:27:55 bradleyb Exp $"; #endif #include @@ -115,7 +115,8 @@ int invert_text[2] = { TNUM_N, TNUM_Y }; TNUM_TRIG, TNUM_LEFT, TNUM_RIGHT, -1, TNUM_UP, TNUM_DOWN, TNUM_LEFT, TNUM_RIGHT }; - int joyaxis_text[4] = { TNUM_X1, TNUM_Y1, TNUM_X2, TNUM_Y2 }; + int joyaxis_text[7] = { TNUM_X1, TNUM_Y1, TNUM_Z1, TNUM_UN, TNUM_P1,TNUM_R1,TNUM_YA1 }; +// int joyaxis_text[4] = { TNUM_X1, TNUM_Y1, TNUM_X2, TNUM_Y2 }; #endif int mouseaxis_text[2] = { TNUM_L_R, TNUM_F_B }; @@ -966,7 +967,9 @@ WIN(DDGRUNLOCK(dd_grd_curcanv)); kc_drawitem( &items[i], 0 ); } } else { - #ifdef MACINTOSH // hack for firebire and mousestick default controls since I made them the same control type -- dumb dumb dumb + #ifdef MACINTOSH + // hack for firebire and mousestick default controls since I made + // them the same control type -- dumb dumb dumb if (joy_have_firebird()) for (i=0; i200 ) { #endif code = i; + printf("Axis Movement detected: Axis %i\n", i); } //old_axis[i] = axis[i]; } for (i=0; i joy_null_value) - raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value); + raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value); else if (raw_joy_axis[i] < -joy_null_value) - raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value); + raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value); else - raw_joy_axis[i] = 0; + raw_joy_axis[i] = 0; joy_axis[i] = (raw_joy_axis[i]*FrameTime)/128; } +#ifndef __ENV_LINUX__ } else { joy_axis[i] = 0; } +#endif } use_joystick=1; } else { @@ -2732,7 +2740,7 @@ void controls_read_all() joy_axis[i] = 0; use_joystick=0; } -#else +#else // MACINTOSH //--------- Read Joystick ----------- if ((Config_control_type>0) && (Config_control_type<5) ) { channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis ); @@ -3307,8 +3315,8 @@ void controls_read_all() //read_head_tracker(); // Read external controls - if (kc_use_external_control || CybermouseActive) - kconfig_read_external_controls(); + // if (kc_use_external_control || CybermouseActive) + // kconfig_read_external_controls(); #endif //----------- Clamp values between -FrameTime and FrameTime