int joy_init () { int i, j; if (joy_installed) return 0; joy_flush (); if (!joy_installed) { //printf ("Initializing joystick... "); j_joystick[0].buffer = open ("/dev/js0", O_NONBLOCK); j_joystick[1].buffer = open ("/dev/js1", O_NONBLOCK); j_joystick[2].buffer = open ("/dev/js2", O_NONBLOCK); 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: "); 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); } 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); } for (j = j_num_axes; j < (j_num_axes + j_joystick[i].num_axes); j++) { j_axis[j].joydev = i; if (j_joystick[i].version) { j_axis[j].center_val = 0; j_axis[j].max_val = 32767; j_axis[j].min_val = -32767; } } for (j = j_num_buttons; j < (j_num_buttons + j_joystick[i].num_buttons); j++) { j_button[j].joydev = i; } j_num_axes += j_joystick[i].num_axes; j_num_buttons += j_joystick[i].num_buttons; } else { j_joystick[i].num_buttons = 0; j_joystick[i].num_axes = 0; } for (j = 0; j < i; j++) { j_axes_in_sticks[i] += j_joystick[j].num_axes; j_buttons_in_sticks[i] += j_joystick[j].num_buttons; } }
void joy_delay() { StopTime(); timer_delay(.25); //delay(250); // changed by allender because 1) more portable // 2) was totally broken on PC joy_flush(); StartTime(); }
void joy_delay() { stop_time(); // timer_delay(.25); delay(250); // changed by allender because 1) more portable // 2) was totally broken on PC joy_flush(); start_time(); }
int joy_init(int joyid) //HH: added joyid parameter { int i; int temp_axis[JOY_NUM_AXES]; //changed - orulz JOYCAPS pjc; if (FindArg( "-nojoystick" )) return 0; atexit(joy_close); //HH: we are a bit lazy :). Errors are ignored, so we are even double-lazy :) joy_flush(); memset(&joystick, 0, sizeof(joystick)); for (i=0; i<MAX_BUTTONS; i++) joystick.buttons[i].last_state = 0; if ( !joy_installed ) { joy_present = 0; joy_installed = 1; joystick.max_timer = 65536; joystick.read_count = 0; joystick.last_value = 0; } joystick.present_mask = JOY_ALL_AXIS; // Assume they're all present joystick.present_mask = joystick_read_raw_axis( JOY_ALL_AXIS, temp_axis ); if ( joystick.present_mask & 3 ) joy_present = 1; else joy_present = 0; //HH: Main Win32 joystick initialization, incl. reading cal. stuff if (joyGetDevCaps(joyid, &pjc, sizeof(pjc))!=JOYERR_NOERROR) { return 0; } if (joySetThreshold(joyid, pjc.wXmax/256)!=JOYERR_NOERROR) { return 0; } joystick.max_timer = pjc.wPeriodMax; joystick.axis_min[0] = pjc.wXmin; joystick.axis_min[1] = pjc.wYmin; //orulz: // joystick.axis_min[2] = pjc.wZmin; // //HH: joystick.axis_min[3] = pov-stuff // joystick.axis_min[4] = pjc.wRmin; // joystick.axis_min[5] = pjc.wUmin; // joystick.axis_min[6] = pjc.wVmin; joystick.axis_min[2] = pjc.wRmin; joystick.axis_min[3] = pjc.wZmin; joystick.axis_min[4] = pjc.wUmin; joystick.axis_min[5] = pjc.wVmin; joystick.axis_max[0] = pjc.wXmax; joystick.axis_max[1] = pjc.wYmax; //orulz: // joystick.axis_max[2] = pjc.wZmax; // //HH: joystick.axis_max[3] = pov-stuff // joystick.axis_max[4] = pjc.wRmax; // joystick.axis_max[5] = pjc.wUmax; // joystick.axis_max[6] = pjc.wVmax; joystick.axis_max[2] = pjc.wRmax; joystick.axis_max[3] = pjc.wZmax; joystick.axis_max[4] = pjc.wUmax; joystick.axis_max[5] = pjc.wVmax; joystick.axis_center[0] = hh_average(pjc.wXmax,pjc.wXmin); joystick.axis_center[1] = hh_average(pjc.wYmax,pjc.wYmin); //orulz: // joystick.axis_center[2] = hh_average(pjc.wZmax,pjc.wZmin); // joystick.axis_center[3] = JOY_POVCENTERED; // joystick.axis_center[4] = hh_average(pjc.wRmax,pjc.wRmin); // joystick.axis_center[5] = hh_average(pjc.wUmax,pjc.wUmin); // joystick.axis_center[6] = hh_average(pjc.wVmax,pjc.wVmin); joystick.axis_center[2] = hh_average(pjc.wRmax,pjc.wRmin); joystick.axis_center[3] = hh_average(pjc.wZmax,pjc.wZmin); joystick.axis_center[4] = hh_average(pjc.wUmax,pjc.wUmin); joystick.axis_center[5] = hh_average(pjc.wVmax,pjc.wVmin); joystick.present_mask = JOY_1_X_AXIS | JOY_1_Y_AXIS; if (pjc.wCaps & JOYCAPS_HASZ) joystick.present_mask |= JOY_1_Z_AXIS; // if (pjc.wCaps & JOYCAPS_HASPOV) joystick.present_mask |= JOY_1_POV; if (pjc.wCaps & JOYCAPS_HASR) joystick.present_mask |= JOY_1_R_AXIS; if (pjc.wCaps & JOYCAPS_HASU) joystick.present_mask |= JOY_1_U_AXIS; if (pjc.wCaps & JOYCAPS_HASV) joystick.present_mask |= JOY_1_V_AXIS; return joy_present; }
/* joy_init Reset joystick information and request joystick notification from Windows... Calibration shouldn't be a problem since Windows 95 takes care of that. Also attaches a window to the joystick. */ int joy_init(int joy, int spjoy) { int i; //int num_devs; atexit(joy_close); // Reset Joystick information. joy_flush(); memset(&joystick, 0, sizeof(joystick)); for (i=0; i<MAX_BUTTONS; i++) joystick.buttons[i].last_state = 0; if ( !joy_installed ) { joy_present = 0; joy_installed = 1; joystick.max_timer = 65536; joystick.read_count = 0; joystick.last_value = 0; } if (spjoy) { // Special joystick interface initialize. int port; SpecialDevice = 0; joy_present = 0; // if (FindArg("-CyberImpact")) // SpecialDevice = TACTILE_CYBERNET; if (i = FindArg("-Iforce")) { SpecialDevice = TACTILE_IMMERSION; if (atoi(Args[i+1]) != 0) port = atoi(Args[i+1]); } if (SpecialDevice) mprintf((0, "Using Special Joystick!\n")); switch(SpecialDevice) { #ifdef WIN_TACTILE_ON case TACTILE_CYBERNET: TactileStick = TACTILE_CYBERNET; if (!Tactile_open(0)) joy_present = 0; else joy_present = 1; break; case TACTILE_IMMERSION: TactileStick = TACTILE_IMMERSION; if (!Tactile_open(port)) joy_present = 0; else joy_present = 1; break; #endif } if (!joy_present) SpecialDevice = 0; } else joy_present = (char)joyGetNumDevs(); return joy_present; }
int joy_init() { int i, n; if (Joy_inited) return 0; if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) { mprintf(("Could not initialize joystick\n")); return 0; } // enable event processing of the joystick if ( (SDL_JoystickEventState(SDL_ENABLE)) != SDL_ENABLE ) { mprintf(("ERROR: Unable to initialize joystick event processing!\n")); SDL_QuitSubSystem(SDL_INIT_JOYSTICK); return 0; } n = SDL_NumJoysticks(); if (n < 1) { mprintf(("No joysticks found\n")); SDL_QuitSubSystem(SDL_INIT_JOYSTICK); return 0; } joy_get_caps(n); Cur_joystick = os_config_read_uint(NULL, "CurrentJoystick", JOYSTICKID1); sdljoy = SDL_JoystickOpen(Cur_joystick); if (sdljoy == NULL) { mprintf(("Unable to init joystick %d\n", Cur_joystick)); SDL_QuitSubSystem(SDL_INIT_JOYSTICK); return 0; } joy_flush(); joy_num_sticks = n; joy_num_buttons = SDL_JoystickNumButtons(sdljoy); joy_num_axes = SDL_JoystickNumAxes(sdljoy); joy_num_hats = SDL_JoystickNumHats(sdljoy); mprintf(( "\nJoystick INITTED!\n\n" )); mprintf(( "Using '%s' as the primary joystick:\n", SDL_JoystickName(SDL_JoystickOpen(Cur_joystick)) )); mprintf(( " Number of axes: %i\n", joy_num_axes )); mprintf(( " Number of buttons: %i\n", joy_num_buttons )); mprintf(( " Number of hats: %i\n", joy_num_hats )); mprintf(( " Number of trackballs: %i\n\n", SDL_JoystickNumBalls(sdljoy) )); // Fake a calibration if (joy_num_sticks > 0) { for (i=0; i<JOY_NUM_AXES; i++) { joystick.axis_center[i] = 32768; joystick.axis_min[i] = 0; joystick.axis_max[i] = 65536; } } // we poll for axis type motion so be sure to ignore that during normal event state polling SDL_EventState( SDL_JOYAXISMOTION, SDL_IGNORE ); SDL_EventState( SDL_JOYBALLMOTION, SDL_IGNORE ); // we do want to make sure that hat/button presses go through event polling though // (should be on by default already, just here as a reminder) SDL_EventState( SDL_JOYBUTTONDOWN, SDL_ENABLE ); SDL_EventState( SDL_JOYBUTTONUP, SDL_ENABLE ); SDL_EventState( SDL_JOYHATMOTION, SDL_ENABLE ); Joy_inited = 1; return joy_num_sticks; }