コード例 #1
0
ファイル: joystickconfig.cpp プロジェクト: COHRINT/cuTORCS
static void Idle2(void)
{
	int mask;
	int b, i;
	int index;

	for (index = 0; index < NUM_JOY; index++) {
		if (js[index]) {
			js[index]->read(&b, &ax[index * _JS_MAX_AXES]);
			
			/* Joystick buttons */
			for (i = 0, mask = 1; i < 32; i++, mask *= 2) {
			if (((b & mask) != 0) && ((rawb[index] & mask) == 0)) {
				/* Button fired */
				JoyCalAutomaton();
				if (CalState >= NB_STEPS) {
					glutIdleFunc(GfuiIdle);
				}
				glutPostRedisplay();
				rawb[index] = b;
				return;
			}
			}
			rawb[index] = b;
		}
	}
}
コード例 #2
0
static void
Idle2(void)
{
    int		mask;
    int		b, i;
    int		index;

    for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
	if (Joystick[index]) {
	    Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
	    
	    /* Joystick buttons */
	    for (i = 0, mask = 1; i < 32; i++, mask *= 2) {
		if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) {
		    /* Check whether to ignore */
		    if(Cmd[CalState + CmdOffset].butIgnore == i + 32 * index)
			break;

		    /* Button fired */
		    JoyCalAutomaton();
		    if (CalState >= NbCalSteps) {
			GfuiApp().eventLoop().setRecomputeCB(0);
		    }
		    GfuiApp().eventLoop().postRedisplay();
		    JoyButtons[index] = b;
		    return;
		}
	    }
	    JoyButtons[index] = b;
	}
    }

    /* Let CPU take breath (and fans stay at low and quite speed) */
    GfSleep(0.001);
}
コード例 #3
0
static void
Idle2(void)
{
   int		index;
#if SDL_JOYSTICK
   /* Check for activity on Joystick buttons */
   GfctrlJoyGetCurrentStates(&joyInfo);
   for (index = 0; index < GFCTRL_JOY_NUMBER * GFCTRL_JOY_MAX_BUTTONS; index++) {
      if (joyInfo.edgedn[index]) {
         /* Check whether to ignore */
         if(Cmd[CalState + CmdOffset].butIgnore == index)
            break;

         /* Button fired */
         JoyCalAutomaton();
         if (CalState >= NbCalSteps) {
            GfuiApp().eventLoop().setRecomputeCB(0);
         }
         GfuiApp().eventLoop().postRedisplay();
         return;
      }
#else
    int		mask;
    int		b, i;
    

    for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
	if (Joystick[index]) {
	    Joystick[index]->read(&b, &JoyAxis[index * GFCTRL_JOY_MAX_AXES]);
	    
	    /* Joystick buttons */
	    for (i = 0, mask = 1; i < 32; i++, mask *= 2) {
		if (((b & mask) != 0) && ((JoyButtons[index] & mask) == 0)) {
		    /* Check whether to ignore */
		    if(Cmd[CalState + CmdOffset].butIgnore == i + 32 * index)
			break;

		    /* Button fired */
		    JoyCalAutomaton();
		    if (CalState >= NbCalSteps) {
			GfuiApp().eventLoop().setRecomputeCB(0);
		    }
		    GfuiApp().eventLoop().postRedisplay();
		    JoyButtons[index] = b;
		    return;
		}
	    }
	    JoyButtons[index] = b;
	}
#endif
    }

    /* Let CPU take breath (and fans stay at low and quite speed) */
    GfSleep(0.001);
}


static void
onActivate(void * /* dummy */)
{
    int i;
    int step;
#if SDL_JOYSTICK
    //joyInfo = GfctrlJoyCreate();
    GfctrlJoyGetCurrentStates(&joyInfo);
#else
    int index;

    // Create and test joysticks ; only keep the up and running ones.
    for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
	Joystick[index] = new jsJoystick(index);
	if (Joystick[index]->notWorking()) {
	    /* don't configure the joystick */
	    delete Joystick[index];
	    Joystick[index] = 0;
	}
    }
#endif

    CalState = 0;
    GfuiLabelSetText(ScrHandle, InstId, Instructions[CalState]);
    GfuiApp().eventLoop().setRecomputeCB(Idle2);
    GfuiApp().eventLoop().postRedisplay();
#ifndef SDL_JOYSTICK
    for (index = 0; index < GFCTRL_JOY_NUMBER; index++) {
	if (Joystick[index]) {
	    Joystick[index]->read(&JoyButtons[index], &JoyAxis[index * GFCTRL_JOY_MAX_AXES]); /* initial value */
	}
    }
#endif

    for (i = 0; i < NbMaxCalAxis; i++) {
	if (i > 0) {
	    step = i + 2;
	} else {
	    step = i + 1;
	}
	if (Cmd[step + CmdOffset].ref.type == GFCTRL_TYPE_JOY_AXIS) {
	    GfuiLabelSetText(ScrHandle, LabAxisId[i], GfctrlGetNameByRef(GFCTRL_TYPE_JOY_AXIS, Cmd[step + CmdOffset].ref.index));
	} else {
	    GfuiLabelSetText(ScrHandle, LabAxisId[i], "---");
	}
	GfuiLabelSetText(ScrHandle, LabMinId[i], "");
 	GfuiLabelSetText(ScrHandle, LabMaxId[i], "");
    }

    GfuiEnable(ScrHandle, CancelBut, GFUI_ENABLE);
    if (DoneBut)
	GfuiEnable(ScrHandle, DoneBut, GFUI_DISABLE);
    else
	GfuiEnable(ScrHandle, NextBut, GFUI_DISABLE);
}