std::string DirectInJoystickDriverImpl::joystick_name(int id) const { MMRESULT mr; JOYCAPS jc; mr = joyGetDevCaps(id, &jc, sizeof(jc)); if (mr != JOYERR_NOERROR) { return ""; } else return jc.szPname; }
//////////////////////////////////////////////////////////// /// Initialize the instance and bind it to a physical joystick //////////////////////////////////////////////////////////// void Joystick::Initialize(unsigned int Index) { // Reset state myIndex = JOYSTICKID1; myNbButtons = 0; myIsConnected = false; myHasContinuousPOV = false; for (int i = 0; i < Joy::AxisCount; ++i) myAxes[i] = false; // Get the Index-th connected joystick MMRESULT Error; JOYINFOEX JoyInfo; JoyInfo.dwSize = sizeof(JoyInfo); JoyInfo.dwFlags = JOY_RETURNALL; for (unsigned int NbFound = 0; (Error = joyGetPosEx(myIndex, &JoyInfo)) != JOYERR_PARMS; myIndex++) { // Check if the current joystick is connected if (Error == JOYERR_NOERROR) { // Check if it's the required index if (NbFound == Index) { // Ok : store its parameters and return myIsConnected = true; JOYCAPS Caps; joyGetDevCaps(myIndex, &Caps, sizeof(Caps)); myNbButtons = Caps.wNumButtons; if (myNbButtons > Joy::ButtonCount) myNbButtons = Joy::ButtonCount; myAxes[Joy::AxisX] = true; myAxes[Joy::AxisY] = true; myAxes[Joy::AxisZ] = (Caps.wCaps & JOYCAPS_HASZ) != 0; myAxes[Joy::AxisR] = (Caps.wCaps & JOYCAPS_HASR) != 0; myAxes[Joy::AxisU] = (Caps.wCaps & JOYCAPS_HASU) != 0; myAxes[Joy::AxisV] = (Caps.wCaps & JOYCAPS_HASV) != 0; myAxes[Joy::AxisPOV] = (Caps.wCaps & JOYCAPS_HASPOV) != 0; myHasContinuousPOV = (Caps.wCaps & JOYCAPS_POVCTS) != 0; return; } // Go to the next valid joystick ++NbFound; } } }
Joystick::Joystick() { ZeroMemory( &JoyCaps, sizeof(JOYCAPS) ); joyGetDevCaps( 0, &JoyCaps, sizeof( JoyCaps ) ); unsigned int dwSize = sizeof(JoyInfo); ZeroMemory(&JoyInfo, sizeof(JOYINFO)); JoyInfo.dwSize = dwSize; JoyInfo.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNR | JOY_RETURNZ | JOY_RETURNBUTTONS; // Calculates the center of the joysticks. centerX = JoyCaps.wXmax / 2; centerY = JoyCaps.wYmax / 2; centerZ = JoyCaps.wZmax / 2; centerR = JoyCaps.wRmax / 2; }
void EMU::initialize_input() { // initialize status memset(key_status, 0, sizeof(key_status)); memset(joy_status, 0, sizeof(joy_status)); memset(mouse_status, 0, sizeof(mouse_status)); // initialize joysticks joy_num = joyGetNumDevs(); for(int i = 0; i < joy_num && i < 2; i++) { JOYCAPS joycaps; if(joyGetDevCaps(i, &joycaps, sizeof(joycaps)) == JOYERR_NOERROR) { joy_mask[i] = (1 << joycaps.wNumButtons) - 1; } else { joy_mask[i] = 0x0f; // 4buttons } } // mouse emulation is disenabled mouse_enabled = false; // initialize keycode convert table FILEIO* fio = new FILEIO(); if(fio->Fopen(bios_path(_T("keycode.cfg")), FILEIO_READ_BINARY)) { fio->Fread(keycode_conv, sizeof(keycode_conv), 1); fio->Fclose(); } else { for(int i = 0; i < 256; i++) { keycode_conv[i] = i; } } delete fio; #ifdef USE_SHIFT_NUMPAD_KEY // initialize shift+numpad conversion memset(key_converted, 0, sizeof(key_converted)); key_shift_pressed = key_shift_released = false; #endif #ifdef USE_AUTO_KEY // initialize autokey autokey_buffer = new FIFO(65536); autokey_buffer->clear(); autokey_phase = autokey_shift = 0; #endif lost_focus = false; }
bool JoystickImpl::open(unsigned int index) { // No explicit "open" action is required m_index = JOYSTICKID1 + index; // Store the joystick capabilities bool success = joyGetDevCaps(m_index, &m_caps, sizeof(m_caps)) == JOYERR_NOERROR; if (success) { m_identification.name = getDeviceName(m_index, m_caps); m_identification.productId = m_caps.wPid; m_identification.vendorId = m_caps.wMid; } return success; }
void TryJoystick(UINT id) { JOYINFOEX jinfo_ex; jinfo_ex.dwSize = sizeof(jinfo_ex); jinfo_ex.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV; if (joyGetPosEx(id, &jinfo_ex) != JOYERR_NOERROR) { return; } JOYCAPS jcaps; if (joyGetDevCaps(id, &jcaps, sizeof(jcaps)) != JOYERR_NOERROR) { return; } Joystick j; j.id = id; j.minX = jcaps.wXmin; j.maxX = jcaps.wXmax; j.minY = jcaps.wYmin; j.maxY = jcaps.wYmax; j.minZ = jcaps.wZmin; j.maxZ = jcaps.wZmax; j.minR = jcaps.wRmin; j.maxR = jcaps.wRmax; j.minU = jcaps.wUmin; j.maxU = jcaps.wUmax; j.minV = jcaps.wVmin; j.maxV = jcaps.wVmax; j.axes[0] = 0; j.axes[1] = 0; j.axes[2] = 0; j.axes[3] = 0; j.axes[4] = 0; j.axes[5] = 0; j.buttons = 0; j.numButtons = jcaps.wNumButtons; j.numAxes = jcaps.wNumAxes; Joysticks.push_back(j); }
DirectInJoystickImpl(DirectInJoystickDriverImpl* driver, int handle) : m_driver(driver), m_handle(handle) { MMRESULT mr; JOYCAPS jc; mr = joyGetDevCaps(handle, &jc, sizeof(jc)); if (mr != JOYERR_NOERROR) { throw std::runtime_error("Could not get caps for joystick"); } m_num_axes = jc.wNumAxes; m_num_buttons = jc.wNumButtons; m_state.axes = std::vector<int>(m_num_axes, 0); m_state.buttons = std::vector<bool>(m_num_buttons, false); }
Joystick::Capabilities JoystickImpl::getCapabilities(Uint8 id) { Joystick::Capabilities caps; JOYCAPS infoCaps; BULL_ZERO_MEMORY(caps); if(joyGetDevCaps(id, &infoCaps, sizeof(JOYCAPS)) == JOYERR_NOERROR) { caps.name = infoCaps.szPname; caps.axes[JoystickAxis_X].exists = true; caps.axes[JoystickAxis_Y].exists = true; caps.axes[JoystickAxis_Z].exists = infoCaps.wCaps & JOYCAPS_HASZ; caps.axes[JoystickAxis_R].exists = infoCaps.wCaps & JOYCAPS_HASR; caps.axes[JoystickAxis_U].exists = infoCaps.wCaps & JOYCAPS_HASU; caps.axes[JoystickAxis_V].exists = infoCaps.wCaps & JOYCAPS_HASV; caps.axes[JoystickAxis_PovX].exists = infoCaps.wCaps & JOYCAPS_HASPOV; caps.axes[JoystickAxis_PovY].exists = infoCaps.wCaps & JOYCAPS_HASPOV; caps.axes[JoystickAxis_X].min = infoCaps.wXmin; caps.axes[JoystickAxis_Y].min = infoCaps.wYmin; caps.axes[JoystickAxis_Z].min = infoCaps.wZmin; caps.axes[JoystickAxis_R].min = infoCaps.wRmin; caps.axes[JoystickAxis_U].min = infoCaps.wUmin; caps.axes[JoystickAxis_V].min = infoCaps.wVmin; caps.axes[JoystickAxis_PovX].min = 90; caps.axes[JoystickAxis_PovY].min = 90; caps.axes[JoystickAxis_X].max = infoCaps.wXmax; caps.axes[JoystickAxis_Y].max = infoCaps.wYmax; caps.axes[JoystickAxis_Z].max = infoCaps.wZmax; caps.axes[JoystickAxis_R].max = infoCaps.wRmax; caps.axes[JoystickAxis_U].max = infoCaps.wUmax; caps.axes[JoystickAxis_V].max = infoCaps.wVmax; caps.axes[JoystickAxis_PovX].max = 9000; caps.axes[JoystickAxis_PovY].max = 9000; caps.countButtons = infoCaps.wNumButtons; caps.countAxes = infoCaps.wNumAxes; } return caps; }
void JoystickManager::resetManager() { clearJoysticks(); const unsigned int maxSticks = 15; debugLog << "JoystickManager::resetManager" << std::endl; for ( unsigned int i =0; i < maxSticks; ++i ) { // Only use the 4 axis joysticks JOYCAPS jc; MMRESULT result = joyGetDevCaps(i, &jc, sizeof(jc)); if ((JOYERR_NOERROR == result) && (jc.wNumAxes >= 4)) { joysticks_.push_back(new Joystick(i)); debugLog << "\tfound joystick " << i << std::endl; } } }
bool Joystick::InitJoystick() { if(init) return true; // Make sure joystick driver is present UINT uiNumJoysticks; if ((uiNumJoysticks = joyGetNumDevs()) == 0) return false; // Make sure the joystick is attached JOYINFO jiInfo; unsigned i; for(i = m_uiJoystickID; i < uiNumJoysticks; i++){ MMRESULT mr = joyGetPos(i, &jiInfo); if (mr == JOYERR_NOERROR){ m_uiJoystickID = i; break; } } if(i == uiNumJoysticks){ return false; } // Calculate the trip values JOYCAPS jcCaps; joyGetDevCaps(m_uiJoystickID, &jcCaps, sizeof(JOYCAPS)); DWORD dwXCenter = ((DWORD)jcCaps.wXmin + jcCaps.wXmax) / 2; DWORD dwYCenter = ((DWORD)jcCaps.wYmin + jcCaps.wYmax) / 2; DWORD dwZCenter = ((DWORD)jcCaps.wZmin + jcCaps.wZmax) / 2; DWORD dwRCenter = ((DWORD)jcCaps.wRmin + jcCaps.wRmax) / 2; m_rcJoystickTrip.left = (jcCaps.wXmin + (WORD)dwXCenter) / 2; m_rcJoystickTrip.right = (jcCaps.wXmax + (WORD)dwXCenter) / 2; m_rcJoystickTrip.top = (jcCaps.wYmin + (WORD)dwYCenter) / 2; m_rcJoystickTrip.bottom = (jcCaps.wYmax + (WORD)dwYCenter) / 2; m_rcJoystickTrip2.left = (jcCaps.wZmin + (WORD)dwZCenter) / 2; m_rcJoystickTrip2.right = (jcCaps.wZmax + (WORD)dwZCenter) / 2; m_rcJoystickTrip2.top = (jcCaps.wRmin + (WORD)dwRCenter) / 2; m_rcJoystickTrip2.bottom = (jcCaps.wRmax + (WORD)dwRCenter) / 2; init = true; return true; }
void InitJoy(void) /* * See if there's a joystick */ { ZeroMemory (&joyInfoEx, sizeof(joyInfoEx)); joyInfoEx.dwSize = sizeof(joyInfoEx); joy_available = (JOYERR_NOERROR == joyGetPosEx (JOYSTICKID1, &joyInfoEx)); /* Get joystick min-max values */ joyGetDevCaps (JOYSTICKID1, &joyCaps, sizeof(joyCaps)); joy_xmin = (double) joyCaps.wXmin; joy_xmax = (double) joyCaps.wXmax; joy_ymin = (double) joyCaps.wYmin; joy_ymax = (double) joyCaps.wYmax; joy_rmin = (double) joyCaps.wRmin; joy_rmax = (double) joyCaps.wRmax; joy_zmin = (double) joyCaps.wZmin; joy_zmax = (double) joyCaps.wZmax; }
/* Function to scan the system for joysticks. * This function should set SDL_numjoysticks to the number of available * joysticks. Joystick 0 should be the system default joystick. * It should return 0, or -1 on an unrecoverable fatal error. */ int SDL_SYS_JoystickInit(void) { int i; int maxdevs; int numdevs; JOYINFOEX joyinfo; JOYCAPS joycaps; MMRESULT result; numdevs = 0; maxdevs = joyGetNumDevs(); if ( maxdevs > MAX_JOYSTICKS ) { maxdevs = MAX_JOYSTICKS; } for ( i = 0; i < MAX_JOYSTICKS; i++ ) { SYS_JoystickID[i] = JOYSTICKID1 + i; } for ( i = 0; (i < maxdevs); ++i ) { /* added 8/31/2001 By Vitaliy Mikitchenko */ joyinfo.dwSize = sizeof(joyinfo); joyinfo.dwFlags = JOY_RETURNALL; /* end addition */ result = joyGetPosEx(SYS_JoystickID[i], &joyinfo); if ( result == JOYERR_NOERROR ) { result = joyGetDevCaps(SYS_JoystickID[i], &joycaps, sizeof(joycaps)); if ( result == JOYERR_NOERROR ) { SYS_JoystickID[numdevs] = SYS_JoystickID[i]; SYS_Joystick[numdevs] = joycaps; numdevs++; } } } return(numdevs); }
wxString wxJoystick::GetProductName() const { wxString str; #ifndef __WINE__ JOYCAPS joyCaps; if (joyGetDevCaps(m_joystick, &joyCaps, sizeof(joyCaps)) != JOYERR_NOERROR) return wxEmptyString; wxRegKey key1(wxString::Format(wxT("HKEY_LOCAL_MACHINE\\%s\\%s\\%s"), REGSTR_PATH_JOYCONFIG, joyCaps.szRegKey, REGSTR_KEY_JOYCURR)); key1.QueryValue(wxString::Format(wxT("Joystick%d%s"), m_joystick + 1, REGSTR_VAL_JOYOEMNAME), str); wxRegKey key2(wxString::Format(wxT("HKEY_LOCAL_MACHINE\\%s\\%s"), REGSTR_PATH_JOYOEM, str.c_str())); key2.QueryValue(REGSTR_VAL_JOYOEMNAME, str); #endif return str; }
//////////////////////////////////////////////////////////// /// Update the current joystick and return its new state //////////////////////////////////////////////////////////// JoystickState Joystick::UpdateState() { JoystickState State; if (myIsConnected) { // Get the joystick caps (for range conversions) JOYCAPS Caps; if (joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) == JOYERR_NOERROR) { // Get the current joystick state JOYINFOEX Pos; Pos.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR | JOY_RETURNU | JOY_RETURNV | JOY_RETURNBUTTONS; Pos.dwFlags |= myHasContinuousPOV ? JOY_RETURNPOVCTS : JOY_RETURNPOV; Pos.dwSize = sizeof(JOYINFOEX); if (joyGetPosEx(myIndex, &Pos) == JOYERR_NOERROR) { // Axes State.Axis[Joy::AxisX] = (Pos.dwXpos - (Caps.wXmax + Caps.wXmin) / 2.f) * 200.f / (Caps.wXmax - Caps.wXmin); State.Axis[Joy::AxisY] = (Pos.dwYpos - (Caps.wYmax + Caps.wYmin) / 2.f) * 200.f / (Caps.wYmax - Caps.wYmin); State.Axis[Joy::AxisZ] = (Pos.dwZpos - (Caps.wZmax + Caps.wZmin) / 2.f) * 200.f / (Caps.wZmax - Caps.wZmin); State.Axis[Joy::AxisR] = (Pos.dwRpos - (Caps.wRmax + Caps.wRmin) / 2.f) * 200.f / (Caps.wRmax - Caps.wRmin); State.Axis[Joy::AxisU] = (Pos.dwUpos - (Caps.wUmax + Caps.wUmin) / 2.f) * 200.f / (Caps.wUmax - Caps.wUmin); State.Axis[Joy::AxisV] = (Pos.dwVpos - (Caps.wVmax + Caps.wVmin) / 2.f) * 200.f / (Caps.wVmax - Caps.wVmin); // POV if (Pos.dwPOV != 0xFFFF) State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f; else State.Axis[Joy::AxisPOV] = -1.f; // Buttons for (unsigned int i = 0; i < GetButtonsCount(); ++i) State.Buttons[i] = (Pos.dwButtons & (1 << i)) != 0; } } } return State; }
double joystick_axis(int id, int axisnum) { JOYINFOEX joyinfo; JOYCAPS joycaps; joyGetDevCaps(JOYSTICKID1 + id, &joycaps, sizeof(joycaps)); switch (axisnum) { case 1: joyinfo.dwFlags = JOY_RETURNX | JOY_RETURNCENTERED; joyGetPosEx(JOYSTICKID1 + id, &joyinfo); return (joyinfo.dwXpos - (joycaps.wXmax + joycaps.wXmin) / 2.f) / ((joycaps.wXmax - joycaps.wXmin)/ 2.f); break; case 2: joyinfo.dwFlags = JOY_RETURNY | JOY_RETURNCENTERED; joyGetPosEx(JOYSTICKID1 + id, &joyinfo); return (joyinfo.dwYpos - (joycaps.wYmax + joycaps.wYmin) / 2.f) / ((joycaps.wYmax - joycaps.wYmin)/ 2.f); break; case 3: joyinfo.dwFlags = JOY_RETURNZ | JOY_RETURNCENTERED; joyGetPosEx(JOYSTICKID1 + id, &joyinfo); return (joyinfo.dwZpos - (joycaps.wZmax + joycaps.wZmin) / 2.f) / ((joycaps.wZmax - joycaps.wZmin)/ 2.f); break; case 4: joyinfo.dwFlags = JOY_RETURNR | JOY_RETURNCENTERED; joyGetPosEx(JOYSTICKID1 + id, &joyinfo); return (joyinfo.dwRpos - (joycaps.wRmax + joycaps.wRmin) / 2.f) / ((joycaps.wRmax - joycaps.wRmin)/ 2.f); break; case 5: joyinfo.dwFlags = JOY_RETURNU | JOY_RETURNCENTERED; joyGetPosEx(JOYSTICKID1 + id, &joyinfo); return (joyinfo.dwUpos - (joycaps.wUmax + joycaps.wUmin) / 2.f) / ((joycaps.wUmax - joycaps.wUmin)/ 2.f); break; case 6: joyinfo.dwFlags = JOY_RETURNV | JOY_RETURNCENTERED; joyGetPosEx(JOYSTICKID1 + id, &joyinfo); return (joyinfo.dwVpos - (joycaps.wVmax + joycaps.wVmin) / 2.f) / ((joycaps.wVmax - joycaps.wVmin)/ 2.f); break; default: return 0; } }
void PXL_joystick_init() { JOYINFOEX joy_info; JOYCAPS joy_caps; uint32 num_devices = joyGetNumDevs(); uint32 device_id; for (size_t n = 0; n < num_devices; ++n) { if (joyGetPosEx(n, &joy_info) == JOYERR_NOERROR) { device_id = n; joyGetDevCaps(device_id, &joy_caps, sizeof(joy_caps)); PXL_Joystick* joystick = new PXL_Joystick(); joystick->name = get_joystick_name(device_id, joy_caps); joystick->device_id = device_id; joystick->num_buttons = joy_caps.wNumButtons; joystick->num_axes = joy_caps.wNumAxes; joysticks.push_back(joystick); } } }
/* Function to scan the system for joysticks. * This function should set SDL_numjoysticks to the number of available * joysticks. Joystick 0 should be the system default joystick. * It should return 0, or -1 on an unrecoverable fatal error. */ int SDL_SYS_JoystickInit(void) { int i; int maxdevs; int numdevs; JOYINFOEX joyinfo; JOYCAPS joycaps; MMRESULT result; /* Reset the joystick ID & name mapping tables */ for (i = 0; i < MAX_JOYSTICKS; ++i) { SYS_JoystickID[i] = 0; SYS_JoystickName[i] = NULL; } /* Loop over all potential joystick devices */ numdevs = 0; maxdevs = joyGetNumDevs(); for (i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i) { joyinfo.dwSize = sizeof(joyinfo); joyinfo.dwFlags = JOY_RETURNALL; result = joyGetPosEx(i, &joyinfo); if (result == JOYERR_NOERROR) { result = joyGetDevCaps(i, &joycaps, sizeof(joycaps)); if (result == JOYERR_NOERROR) { SYS_JoystickID[numdevs] = i; SYS_Joystick[numdevs] = joycaps; SYS_JoystickName[numdevs] = GetJoystickName(i, joycaps.szRegKey); numdevs++; } } } return (numdevs); }
VOID IK1_AnimRender( VOID ) { INT i; if (!IK1_IsInit) return; if ((i = joyGetNumDevs()) > 1) { JOYCAPS jc; if (joyGetDevCaps(JOYSTICKID1, &jc, sizeof(jc)) == JOYERR_NOERROR) { JOYINFOEX ji; ji.dwSize = sizeof(ji); ji.dwFlags = JOY_RETURNALL; if (joyGetPosEx(JOYSTICKID1, &ji) == JOYERR_NOERROR) { /* кнопки */ memcpy(IK1_Anim.JButOld, IK1_Anim.JBut, 32); for (i = 0; i < 32; i++) IK1_Anim.JBut[i] = (ji.dwButtons >> i) & 1; /* оси переводим в диапазон -1..1 */ IK1_Anim.Jx = 2.0 * (ji.dwXpos - jc.wXmin) / (jc.wXmax - jc.wXmin) - 1; IK1_Anim.Jy = 2.0 * (ji.dwYpos - jc.wYmin) / (jc.wYmax - jc.wYmin) - 1; IK1_Anim.Jz = 2.0 * (ji.dwZpos - jc.wZmin) / (jc.wZmax - jc.wZmin) - 1; IK1_Anim.Jr = 2.0 * (ji.dwRpos - jc.wRmin) / (jc.wRmax - jc.wRmin) - 1; if (ji.dwPOV == 0xFFFF) IK1_Anim.Jpov = 0; else IK1_Anim.Jpov = ji.dwPOV / 4500 + 1; }
glzInputData::glzInputData() { LMdown = false; MMdown = false; RMdown = false; Mpos_x = 0; Mpos_y = 0; Mweel = 0; Mactive = false; pulsar1 = false; pulsar2 = false; pulsar4 = false; pulsar8 = false; pulsar16 = false; pulsartimer = 0.0f; pulsarcounter = 0; JoyPresent = false; JOYINFOEX joyInfoEx; joyInfoEx.dwSize = sizeof(joyInfoEx); joyGetDevCaps(JOYSTICKID1, &joyCaps, sizeof(joyCaps)); JoyPresent = (joyGetPosEx(JOYSTICKID1, &joyInfoEx) == JOYERR_NOERROR); }
/* =============== IN_StartupJoystick =============== */ void IN_StartupJoystick (void) { int numdevs; JOYCAPS jc; MMRESULT mmr; cvar_t *cv; // assume no joystick joy_avail = false; // abort startup if user requests no joystick cv = Cvar_Get ("in_initjoy", "1", CVAR_NOSET); if ( !cv->value ) return; // verify joystick driver is present if ((numdevs = joyGetNumDevs ()) == 0) { // Com_Printf ("\njoystick not found -- driver not present\n\n"); return; } // cycle through the joystick ids for the first valid one for (joy_id=0 ; joy_id<numdevs ; joy_id++) { memset (&ji, 0, sizeof(ji)); ji.dwSize = sizeof(ji); ji.dwFlags = JOY_RETURNCENTERED; if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR) break; } // abort startup if we didn't find a valid joystick if (mmr != JOYERR_NOERROR) { Com_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr); return; } // get the capabilities of the selected joystick // abort startup if command fails memset (&jc, 0, sizeof(jc)); if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR) { Com_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr); return; } // save the joystick's number of buttons and POV status joy_numbuttons = jc.wNumButtons; joy_haspov = jc.wCaps & JOYCAPS_HASPOV; // old button and POV states default to no buttons pressed joy_oldbuttonstate = joy_oldpovstate = 0; // mark the joystick as available and advanced initialization not completed // this is needed as cvars are not available during initialization joy_avail = true; joy_advancedinit = false; Com_Printf ("\njoystick detected\n\n"); }
static int __glutProcessDeviceEvents(XEvent * event) { #if !defined(_WIN32) GLUTwindow *window; /* XXX Ugly code fan out. */ /* Can't use switch/case since X Input event types are dynamic. */ if (__glutDeviceMotionNotify && event->type == __glutDeviceMotionNotify) { XDeviceMotionEvent *devmot = (XDeviceMotionEvent *) event; window = __glutGetWindow(devmot->window); if (window) { if (__glutTablet && devmot->deviceid == __glutTablet->device_id && window->tabletMotion) { tabletPosChange(window, devmot->first_axis, devmot->axes_count, devmot->axis_data); } else if (__glutDials && devmot->deviceid == __glutDials->device_id && window->dials) { int i, first = devmot->first_axis, count = devmot->axes_count; for (i = first; i < first + count; i++) window->dials(i + 1, normalizeDialAngle(i, devmot->axis_data[i - first])); } else if (__glutSpaceball && devmot->deviceid == __glutSpaceball->device_id) { /* XXX Assume that space ball motion events come in as all the first 6 axes. Assume first 3 axes are XYZ translations; second 3 axes are XYZ rotations. */ if (devmot->first_axis == 0 && devmot->axes_count == 6) { if (window->spaceMotion) window->spaceMotion( normalizeSpaceballDelta(0, devmot->axis_data[0]), normalizeSpaceballDelta(1, devmot->axis_data[1]), normalizeSpaceballDelta(2, devmot->axis_data[2])); if (window->spaceRotate) window->spaceRotate( normalizeSpaceballAngle(3, devmot->axis_data[3]), normalizeSpaceballAngle(4, devmot->axis_data[4]), normalizeSpaceballAngle(5, devmot->axis_data[5])); } } return 1; } } else if (__glutDeviceButtonPress && event->type == __glutDeviceButtonPress) { XDeviceButtonEvent *devbtn = (XDeviceButtonEvent *) event; window = __glutGetWindow(devbtn->window); if (window) { if (__glutTablet && devbtn->deviceid == __glutTablet->device_id && window->tabletButton && devbtn->first_axis == 0 && devbtn->axes_count == 2) { tabletPosChange(window, devbtn->first_axis, devbtn->axes_count, devbtn->axis_data); window->tabletButton(devbtn->button, GLUT_DOWN, window->tabletPos[0], window->tabletPos[1]); } else if (__glutDials && devbtn->deviceid == __glutDials->device_id && window->buttonBox) { window->buttonBox(devbtn->button, GLUT_DOWN); } else if (__glutSpaceball && devbtn->deviceid == __glutSpaceball->device_id && window->spaceButton) { window->spaceButton(devbtn->button, GLUT_DOWN); } return 1; } } else if (__glutDeviceButtonRelease && event->type == __glutDeviceButtonRelease) { XDeviceButtonEvent *devbtn = (XDeviceButtonEvent *) event; window = __glutGetWindow(devbtn->window); if (window) { if (__glutTablet && devbtn->deviceid == __glutTablet->device_id && window->tabletButton && devbtn->first_axis == 0 && devbtn->axes_count == 2) { tabletPosChange(window, devbtn->first_axis, devbtn->axes_count, devbtn->axis_data); window->tabletButton(devbtn->button, GLUT_UP, window->tabletPos[0], window->tabletPos[1]); } else if (__glutDials && devbtn->deviceid == __glutDials->device_id && window->buttonBox) { window->buttonBox(devbtn->button, GLUT_UP); } else if (__glutSpaceball && devbtn->deviceid == __glutSpaceball->device_id && window->spaceButton) { window->spaceButton(devbtn->button, GLUT_UP); } return 1; } } #else { JOYINFOEX info; JOYCAPS joyCaps; memset(&info, 0, sizeof(JOYINFOEX)); info.dwSize = sizeof(JOYINFOEX); info.dwFlags = JOY_RETURNALL; if (joyGetPosEx(JOYSTICKID1,&info) != JOYERR_NOERROR) { __glutHasJoystick = 1; joyGetDevCaps(JOYSTICKID1, &joyCaps, sizeof(joyCaps)); __glutNumJoystickButtons = joyCaps.wNumButtons; __glutNumJoystickAxes = joyCaps.wNumAxes; } else { __glutHasJoystick = 0; __glutNumJoystickButtons = 0; __glutNumJoystickAxes = 0; } } #endif /* !_WIN32 */ return 0; }
/* * Happy happy happy joy joy joy (happy new year toudi :D) */ static void fghJoystickOpen( SFG_Joystick* joy ) { #ifdef WIN32 JOYCAPS jsCaps; int i; joy->js.dwFlags = JOY_RETURNALL; joy->js.dwSize = sizeof( joy->js ); memset( &jsCaps, 0, sizeof( jsCaps ) ); joy->error = ( joyGetDevCaps( joy->js_id, &jsCaps, sizeof( jsCaps ) ) != JOYERR_NOERROR ); joy->num_axes = ( jsCaps.wNumAxes < _JS_MAX_AXES ) ? jsCaps.wNumAxes : _JS_MAX_AXES; /* * WARNING - Fall through case clauses!! */ switch( joy->num_axes ) { case 6: joy->min[ 5 ] = (float) jsCaps.wVmin; joy->max[ 5 ] = (float) jsCaps.wVmax; case 5: joy->min[ 4 ] = (float) jsCaps.wUmin; joy->max[ 4 ] = (float) jsCaps.wUmax; case 4: joy->min[ 3 ] = (float) jsCaps.wRmin; joy->max[ 3 ] = (float) jsCaps.wRmax; case 3: joy->min[ 2 ] = (float) jsCaps.wZmin; joy->max[ 2 ] = (float) jsCaps.wZmax; case 2: joy->min[ 1 ] = (float) jsCaps.wYmin; joy->max[ 1 ] = (float) jsCaps.wYmax; case 1: joy->min[ 0 ] = (float) jsCaps.wXmin; joy->max[ 0 ] = (float) jsCaps.wXmax; break; /* * I guess we have no axes at all */ default: joy->error = GL_TRUE; break; } /* * Guess all the rest judging on the axes extremals */ for( i=0 ; i<joy->num_axes ; i++ ) { joy->center [ i ] = (joy->max[i] + joy->min[i]) * 0.5f; joy->dead_band[ i ] = 0.0f; joy->saturate [ i ] = 1.0f; } #else # ifdef __FreeBSD__ int buttons[ _JS_MAX_AXES ]; float axes[ _JS_MAX_AXES ]; int noargs, in_no_axes; char joyfname[ 1024 ]; FILE* joyfile; # else # ifndef JS_NEW int counter; # endif # endif int i; /* * Default for older Linux systems. */ joy->num_axes = 2; joy->num_buttons = 32; # ifdef JS_NEW for( i=0 ; i<_JS_MAX_AXES ; i++ ) joy->tmp_axes[ i ] = 0.0f ; joy->tmp_buttons = 0 ; # endif joy->fd = open( joy->fname, O_RDONLY ); joy->error = (joy->fd < 0); if( joy->error ) return; /* * XXX All BSDs should share this? */ # ifdef __FreeBSD__ fghJoystickRawRead(joy, buttons, axes ); joy->error = axes[ 0 ] < -1000000000.0f; if( joy->error ) return; sprintf( joyfname, "%s/.joy%drc", getenv( "HOME" ), joy->id ); joyfile = fopen( joyfname, "r" ); joy->error =( joyfile == NULL ); if( joy->error ) return; noargs = fscanf( joyfile, "%d%f%f%f%f%f%f", &in_no_axes, &joy->min[ 0 ], &joy->center[ 0 ], &joy->max[ 0 ], &joy->min[ 1 ], &joy->center[ 1 ], &joy->max[ 1 ] ); joy->error =( noargs != 7 ) || ( in_no_axes != _JS_MAX_AXES ); fclose( joyfile ); if( joy->error ) return; for( i = 0; i < _JS_MAX_AXES; i++ ) { joy->dead_band[ i ] = 0.0f; joy->saturate [ i ] = 1.0f; } # else /* * Set the correct number of axes for the linux driver */ # ifdef JS_NEW ioctl( joy->fd, JSIOCGAXES , &joy->num_axes ); ioctl( joy->fd, JSIOCGBUTTONS, &joy->num_buttons ); fcntl( joy->fd, F_SETFL, O_NONBLOCK ); # endif /* * The Linux driver seems to return 512 for all axes * when no stick is present - but there is a chance * that could happen by accident - so it's gotta happen * on both axes for at least 100 attempts. * * PWO: shouldn't be that done somehow wiser on the kernel level? */ # ifndef JS_NEW counter = 0; do { fghJoystickRawRead( joy, NULL, joy->center ); counter++; } while( !joy->error && counter < 100 && joy->center[ 0 ] == 512.0f && joy->center[ 1 ] == 512.0f ); if( counter >= 100 ) joy->error = GL_TRUE; # endif for( i = 0; i < _JS_MAX_AXES; i++ ) { # ifdef JS_NEW joy->max [ i ] = 32767.0f; joy->center[ i ] = 0.0f; joy->min [ i ] = -32767.0f; # else joy->max[ i ] = joy->center[ i ] * 2.0f; joy->min[ i ] = 0.0f; # endif joy->dead_band[ i ] = 0.0f ; joy->saturate [ i ] = 1.0f ; } # endif #endif }
int joystick_buttons(int id) { JOYCAPS joycaps; joyGetDevCaps(JOYSTICKID1 + id, &joycaps, sizeof(joycaps)); return joycaps.wNumButtons; }
/* joystick_win32_init: * Initialises the Win32 joystick driver. */ static int joystick_win32_init(void) { JOYCAPS caps; JOYINFOEX js; int n_joyat, n_joy, n_axis; win32_joy_num = joyGetNumDevs(); if (win32_joy_num > MAX_JOYSTICKS) _TRACE(PREFIX_W "The system supports more than %d joysticks\n", MAX_JOYSTICKS); /* retrieve joystick infos */ n_joy = 0; for (n_joyat = 0; n_joyat < win32_joy_num; n_joyat++) { if (n_joy == MAX_JOYSTICKS) break; if (joyGetDevCaps(n_joyat, &caps, sizeof(caps)) == JOYERR_NOERROR) { /* is the joystick physically attached? */ js.dwSize = sizeof(js); js.dwFlags = JOY_RETURNALL; if (joyGetPosEx(n_joyat, &js) == JOYERR_UNPLUGGED) continue; memset(&win32_joystick[n_joy], 0, sizeof(struct WIN32_JOYSTICK_INFO)); /* set global properties */ win32_joystick[n_joy].device = n_joyat; win32_joystick[n_joy].caps = caps.wCaps; win32_joystick[n_joy].num_buttons = MIN(caps.wNumButtons, MAX_JOYSTICK_BUTTONS); win32_joystick[n_joy].num_axes = MIN(caps.wNumAxes, WINDOWS_MAX_AXES); /* fill in ranges of axes */ win32_joystick[n_joy].axis_min[0] = caps.wXmin; win32_joystick[n_joy].axis_max[0] = caps.wXmax; win32_joystick[n_joy].axis_min[1] = caps.wYmin; win32_joystick[n_joy].axis_max[1] = caps.wYmax; n_axis = 2; if (caps.wCaps & JOYCAPS_HASZ) { win32_joystick[n_joy].axis_min[2] = caps.wZmin; win32_joystick[n_joy].axis_max[2] = caps.wZmax; n_axis++; } if (caps.wCaps & JOYCAPS_HASR) { win32_joystick[n_joy].axis_min[n_axis] = caps.wRmin; win32_joystick[n_joy].axis_max[n_axis] = caps.wRmax; n_axis++; } if (caps.wCaps & JOYCAPS_HASU) { win32_joystick[n_joy].axis_min[n_axis] = caps.wUmin; win32_joystick[n_joy].axis_max[n_axis] = caps.wUmax; n_axis++; } if (caps.wCaps & JOYCAPS_HASV) { win32_joystick[n_joy].axis_min[n_axis] = caps.wVmin; win32_joystick[n_joy].axis_max[n_axis] = caps.wVmax; n_axis++; } /* register this joystick */ if (win_add_joystick((WINDOWS_JOYSTICK_INFO *)&win32_joystick[n_joy]) != 0) break; n_joy++; } } win32_joy_num = n_joy; return (win32_joy_num == 0); }
string joystick_name(int id) { JOYCAPS joycaps; joyGetDevCaps(JOYSTICKID1 + id, &joycaps, sizeof(joycaps)); return joycaps.szPname; }
/* Функция построения кадра анимации. * АРГУМЕНТЫ: Нет. * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ VOID VG4_AnimRender( VOID ) { INT i; LARGE_INTEGER li; POINT pt; /*** Обновление ввода ***/ /* Клавиатура */ GetKeyboardState(VG4_Anim.Keys); for (i = 0; i < 256; i++) VG4_Anim.Keys[i] >>= 7; for (i = 0; i < 256; i++) VG4_Anim.KeysClick[i] = VG4_Anim.Keys[i] && !VG4_Anim.KeysOld[i]; memcpy(VG4_Anim.KeysOld, VG4_Anim.Keys, 256); /* Мышь */ /* колесо */ VG4_Anim.MsWheel = VG4_MouseGlobalWheel; VG4_MouseGlobalWheel = 0; /* абсолютная позиция */ pt.x = VG4_MouseGlobalX; pt.y = VG4_MouseGlobalY; ScreenToClient(VG4_Anim.hWnd, &pt); VG4_Anim.MsX = pt.x; VG4_Anim.MsY = pt.y; /* относительное перемещение */ VG4_Anim.MsDeltaX = VG4_MouseGlobalX - VG4_MouseXOld; VG4_Anim.MsDeltaY = VG4_MouseGlobalY - VG4_MouseYOld; VG4_MouseXOld = VG4_MouseGlobalX; VG4_MouseYOld = VG4_MouseGlobalY; /* Джойстик */ if ((i = joyGetNumDevs()) > 0) { JOYCAPS jc; /* получение общей информации о джостике */ if (joyGetDevCaps(JOYSTICKID1, &jc, sizeof(jc)) == JOYERR_NOERROR) { JOYINFOEX ji; /* получение текущего состояния */ ji.dwSize = sizeof(JOYCAPS); ji.dwFlags = JOY_RETURNALL; if (joyGetPosEx(JOYSTICKID1, &ji) == JOYERR_NOERROR) { /* Кнопки */ memcpy(VG4_Anim.JButsOld, VG4_Anim.JButs, sizeof(VG4_Anim.JButs)); for (i = 0; i < 32; i++) VG4_Anim.JButs[i] = (ji.dwButtons >> i) & 1; for (i = 0; i < 32; i++) VG4_Anim.JButsClick[i] = VG4_Anim.JButs[i] && !VG4_Anim.JButsOld[i]; /* Оси */ VG4_Anim.JX = VG4_GET_AXIS_VALUE(X); VG4_Anim.JY = VG4_GET_AXIS_VALUE(Y); if (jc.wCaps & JOYCAPS_HASZ) VG4_Anim.JZ = VG4_GET_AXIS_VALUE(Z); if (jc.wCaps & JOYCAPS_HASR) VG4_Anim.JR = VG4_GET_AXIS_VALUE(R); if (jc.wCaps & JOYCAPS_HASU) VG4_Anim.JU = 2.0 * (ji.dwUpos - jc.wUmin) / (jc.wUmax - jc.wUmin - 1) - 1; /* Point-Of-View */ if (jc.wCaps & JOYCAPS_HASPOV) { if (ji.dwPOV == 0xFFFF) VG4_Anim.JPOV = 0; else VG4_Anim.JPOV = ji.dwPOV / 4500 + 1; } }
bool joystick_has_pov(int id) { JOYCAPS joycaps; joyGetDevCaps(JOYSTICKID1 + id, &joycaps, sizeof(joycaps)); return (joycaps.wCaps & JOYCAPS_HASPOV); }
VOID IK3_AnimRender( VOID ) { int i; POINT pt; LARGE_INTEGER t; IK3_FrameCounter++; QueryPerformanceCounter(&t); IK3_Anim.GlobalTime =(DBL)(t.QuadPart - IK3_StartTime) / IK3_TimePerSec; IK3_Anim.GlobalDeltaTime =(DBL)(t.QuadPart - IK3_OldTime) / IK3_TimePerSec; if (IK3_Anim.IsPause) { IK3_Anim.DeltaTime = 0; IK3_PauseTime += t.QuadPart - IK3_OldTime; } else { IK3_Anim.DeltaTime = IK3_Anim.GlobalDeltaTime; IK3_Anim.Time = (DBL)(t.QuadPart - IK3_PauseTime - IK3_OldTime) / IK3_TimePerSec; } if (t.QuadPart - IK3_OldTimeFPS > IK3_TimePerSec); { CHAR str[100]; IK3_Anim.FPS = IK3_FrameCounter * IK3_TimePerSec / (DBL)(t.QuadPart - IK3_OldTimeFPS); IK3_OldTimeFPS = t.QuadPart; sprintf(str, "FPS: %.5f", IK3_Anim.FPS); SetWindowText(IK3_Anim.hWnd, str); IK3_FrameCounter = 0; } GetKeyboardState(IK3_Anim.Keys); for (i = 0; i < 256; i++) { IK3_Anim.Keys[i] >>= 7; if (!IK3_Anim.OldKeys[i] && IK3_Anim.Keys[i]) IK3_Anim.KeysClick[i] = TRUE; else IK3_Anim.KeysClick[i] = FALSE; } memcpy(IK3_Anim.OldKeys, IK3_Anim.Keys, 256); GetCursorPos(&pt); ScreenToClient(IK3_Anim.hWnd, &pt); IK3_Anim.Mdx = pt.x - IK3_Anim.Mx; IK3_Anim.Mdy = pt.y - IK3_Anim.My; IK3_Anim.Mdx = pt.x; IK3_Anim.Mdy = pt.y; /* Joystick */ if (joyGetNumDevs() > 0) { JOYCAPS jc; /* Get joystick info */ if (joyGetDevCaps(JOYSTICKID1, &jc, sizeof(jc)) == JOYERR_NOERROR) { JOYINFOEX ji; ji.dwSize = sizeof(JOYINFOEX); ji.dwFlags = JOY_RETURNALL; if (joyGetPosEx(JOYSTICKID1, &ji) == JOYERR_NOERROR) { /* Buttons */ for (i = 0; i < 32; i++) IK3_Anim.JBut[i] = (ji.dwButtons >> i) & 1; /* Axes */ IK3_Anim.JX = IK3_GET_JOYSTIC_AXIS(X); IK3_Anim.JY = IK3_GET_JOYSTIC_AXIS(Y); IK3_Anim.JZ = IK3_GET_JOYSTIC_AXIS(Z); IK3_Anim.JR = IK3_GET_JOYSTIC_AXIS(R); /* Point of view */ IK3_Anim.JPov = ji.dwPOV == 0xFFFF ? 0 : ji.dwPOV / 4500 + 1; } }
/* Функция построения кадра. * АРГУМЕНТЫ: Нет. * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ VOID VG4_AnimRender( VOID ) { INT i; LARGE_INTEGER li; POINT pt; if (!VG4_IsInit) return; /*** Опрос таймера ***/ /* обновляем информацию: */ QueryPerformanceCounter(&li); /* глобальное время */ VG4_Anim.GlobalTime = (DBL)(li.QuadPart - VG4_TimeStart) / VG4_TimeFreq; VG4_Anim.GlobalDeltaTime = (DBL)(li.QuadPart - VG4_TimeOld) / VG4_TimeFreq; /* локальное время */ if (VG4_Anim.IsPause) VG4_Anim.DeltaTime = 0, VG4_TimePause += li.QuadPart - VG4_TimeOld; else VG4_Anim.DeltaTime = VG4_Anim.GlobalDeltaTime; VG4_Anim.Time = (DBL)(li.QuadPart - VG4_TimeStart - VG4_TimePause - VG4_TimeShift) / VG4_TimeFreq; /* вычисляем производительность */ if (li.QuadPart - VG4_TimeFPS > VG4_TimeFreq * 3.0) { VG4_Anim.FPS = VG4_FrameCounter / ((DBL)(li.QuadPart - VG4_TimeFPS) / VG4_TimeFreq); VG4_TimeFPS = li.QuadPart; VG4_FrameCounter = 0; } /* обновляем время "старого" кадра */ VG4_TimeOld = li.QuadPart; /*** Опрос устройств ввода ***/ /* клавиатура */ /* копируем старое состояние */ memcpy(VG4_Anim.KeysOld, VG4_Anim.Keys, 256); /* Считываем новое */ GetKeyboardState(VG4_Anim.Keys); /* конвертироем в Да,Нет */ for (i = 0; i < 256; i++) VG4_Anim.Keys[i] >>= 7; /* мышь */ GetCursorPos(&pt); ScreenToClient(VG4_Anim.hWnd, &pt); VG4_Anim.MouseX = pt.x; VG4_Anim.MouseY = pt.y; VG4_Anim.MouseBut[0] = VG4_Anim.Keys[VK_LBUTTON]; VG4_Anim.MouseBut[1] = VG4_Anim.Keys[VK_RBUTTON]; VG4_Anim.MouseBut[2] = VG4_Anim.Keys[VK_MBUTTON]; VG4_Anim.MouseDeltaX = pt.x - VG4_MousePosOld.x; VG4_Anim.MouseDeltaY = pt.y - VG4_MousePosOld.y; VG4_Anim.MouseWheel = VG4_MouseWheel; VG4_MouseWheel = 0; VG4_MousePosOld = pt; /* джойстик */ if ((i = joyGetNumDevs()) > 1) { JOYCAPS jc; if (joyGetDevCaps(JOYSTICKID1, &jc, sizeof(jc)) == JOYERR_NOERROR) { JOYINFOEX ji; ji.dwSize = sizeof(ji); ji.dwFlags = JOY_RETURNALL; if (joyGetPosEx(JOYSTICKID1, &ji) == JOYERR_NOERROR) { /* кнопки */ memcpy(VG4_Anim.JButOld, VG4_Anim.JBut, 32); for (i = 0; i < 32; i++) VG4_Anim.JBut[i] = (ji.dwButtons >> i) & 1; /* оси переводим в диапазон -1..1 */ VG4_Anim.Jx = 2.0 * (ji.dwXpos - jc.wXmin) / (jc.wXmax - jc.wXmin) - 1; VG4_Anim.Jy = 2.0 * (ji.dwYpos - jc.wYmin) / (jc.wYmax - jc.wYmin) - 1; VG4_Anim.Jz = 2.0 * (ji.dwZpos - jc.wZmin) / (jc.wZmax - jc.wZmin) - 1; VG4_Anim.Jr = 2.0 * (ji.dwRpos - jc.wRmin) / (jc.wRmax - jc.wRmin) - 1; if (ji.dwPOV == 0xFFFF) VG4_Anim.JPov = 0; else VG4_Anim.JPov = ji.dwPOV / 4500 + 1; }
AREXPORT bool ArJoyHandler::init(void) { myPhysMax = 1; myLastZ = 0; // first see if we can talk to the first joystick if (joyGetDevCaps(JOYSTICKID1,&myJoyCaps,sizeof(myJoyCaps)) == JOYERR_NOERROR && joyGetPos(JOYSTICKID1,&myJoyInfo) != JOYERR_UNPLUGGED) { myJoyID = JOYSTICKID1; // So far, it seems that the x range is the same as that of y and // z, so only one is used myPhysMax = myJoyCaps.wXmax - myJoyCaps.wXmin; /* ArLog::log(ArLog::Normal, "caps 0x%x numAxes %d maxAxes %d %s", myJoyCaps.wCaps, myJoyCaps.wNumAxes, myJoyCaps.wMaxAxes, myJoyCaps.szPname); ArLog::log(ArLog::Normal, "xMin %d xMax %d yMin %d yMax %d zMin %d zMax %d rMin %d rMax %d uMin %d uMax %d", myJoyCaps.wXmin, myJoyCaps.wXmax, myJoyCaps.wYmin, myJoyCaps.wYmax, myJoyCaps.wRmin, myJoyCaps.wRmax, myJoyCaps.wZmin, myJoyCaps.wZmax, myJoyCaps.wUmin, myJoyCaps.wUmax); */ myInitialized = true; startCal(); endCal(); return true; } // we couldn't talk to the first one so try the second one else if (joyGetDevCaps(JOYSTICKID2,&myJoyCaps,sizeof(myJoyCaps)) == JOYERR_NOERROR && joyGetPos(JOYSTICKID2,&myJoyInfo) != JOYERR_UNPLUGGED) { myJoyID = JOYSTICKID2; // So far, it seems that the x range is the same as that of y and // z, so only one is used myPhysMax = myJoyCaps.wXmax - myJoyCaps.wXmin; /* ArLog::log(ArLog::Normal, "2 caps 0x%x numAxes %d maxAxes %d %s", myJoyCaps.wCaps, myJoyCaps.wNumAxes, myJoyCaps.wMaxAxes, myJoyCaps.szPname); ArLog::log(ArLog::Normal, "2 xMin %d xMax %d yMin %d yMax %d zMin %d zMax %d rMin %d rMax %d uMin %d uMax %d", myJoyCaps.wXmin, myJoyCaps.wXmax, myJoyCaps.wYmin, myJoyCaps.wYmax, myJoyCaps.wRmin, myJoyCaps.wRmax, myJoyCaps.wZmin, myJoyCaps.wZmax, myJoyCaps.wUmin, myJoyCaps.wUmax); */ myInitialized = true; startCal(); endCal(); return true; } // we couldn't talk to either one else { myInitialized = false; return false; } // Just to prevent any possible divide-by-zeros... if (myPhysMax == 0) { myPhysMax = 1; } getData(); }