void invoking(void)
{
	waitButton(&xPos, &yPos);
	if(isInRange(xPos, yPos, APP1_X, APP1_Y)){
		side_to_side();
	}
	else if(isInRange(xPos, yPos, APP2_X, APP2_Y)){
		starts_swinging();
	}
	else if(isInRange(xPos, yPos, APP3_X, APP3_Y)){
		inverted_pendulum();
	}
		else if(isInRange(xPos, yPos, APP4_X, APP4_Y)){
		circular_motion();
	}
}
Ejemplo n.º 2
0
void CalDialog::calibrate()
{
  text->setText(i18n("Please wait a moment to calculate the precision"));
  setResult(-1);
  show();

  // calibrate precision (which min,max delivers the joystick in its center position)
  // get values through the normal idle procedure
  QTimer ti;
  ti.setSingleShot(true); // single shot
  ti.start(2000);         // in 2 seconds

  // normally I'd like to hide the 'Next' button in this step,
  // but it does not work - which means: in the steps after the first,
  // the 'Next' button does not have the focus (to be the default button)

  do
  {
    qApp->processEvents(QEventLoop::AllEvents, 2000);
  }
  while ( ti.isActive() && (result() != QDialog::Rejected) );

  joydev->calcPrecision();

  int i, lastVal;
  int min[2], center[2], max[2];
  QString hint;

  for (i = 0; i < joydev->numAxes(); i++)
  {
    if ( i == 0 )
      hint = i18n("(usually X)");
    else if ( i == 1 )
      hint = i18n("(usually Y)");
    else
      hint = "";

    // minimum position
    text->setText(i18n("<qt>Calibration is about to check the value range your device delivers.<br /><br />"
                       "Please move <b>axis %1 %2</b> on your device to the <b>minimum</b> position.<br /><br />"
                       "Press any button on the device or click on the 'Next' button "
                       "to continue with the next step.</qt>", i+1, hint));
    waitButton(i, true, lastVal);
    joydev->resetMinMax(i, lastVal);
    if ( result() != -2 ) waitButton(i, false, lastVal);

    min[0] = joydev->axisMin(i);
    min[1] = joydev->axisMax(i);

    if ( result() == QDialog::Rejected ) return;  // user canceled the dialog

    // center position
    text->setText(i18n("<qt>Calibration is about to check the value range your device delivers.<br /><br />"
                       "Please move <b>axis %1 %2</b> on your device to the <b>center</b> position.<br /><br />"
                       "Press any button on the device or click on the 'Next' button "
                       "to continue with the next step.</qt>", i+1, hint));
    waitButton(i, true, lastVal);
    joydev->resetMinMax(i, lastVal);
    if ( result() != -2 ) waitButton(i, false, lastVal);

    center[0] = joydev->axisMin(i);
    center[1] = joydev->axisMax(i);

    if ( result() == QDialog::Rejected ) return;  // user canceled the dialog

    // maximum position
    text->setText(i18n("<qt>Calibration is about to check the value range your device delivers.<br /><br />"
                       "Please move <b>axis %1 %2</b> on your device to the <b>maximum</b> position.<br /><br />"
                       "Press any button on the device or click on the 'Next' button "
                       "to continue with the next step.</qt>", i+1, hint));
    waitButton(i, true, lastVal);
    joydev->resetMinMax(i, lastVal);
    if ( result() != -2 ) waitButton(i, false, lastVal);

    max[0] = joydev->axisMin(i);
    max[1] = joydev->axisMax(i);

    if ( result() == QDialog::Rejected ) return;  // user canceled the dialog

    joydev->calcCorrection(i, min, center, max);
  }

  JoyDevice::ErrorCode ret = joydev->applyCalibration();

  if ( ret != JoyDevice::SUCCESS )
  {
    KMessageBox::error(this, joydev->errText(ret), i18n("Communication Error"));
    reject();
  }

  KMessageBox::information(this, i18n("You have successfully calibrated your device"), i18n("Calibration Success"));
  accept();
}