Exemple #1
0
/**
 * Updates the state of the digital data vector.
 *
 * @note Digital is on when key is held down.
 *       When key is release, digital goes to off state.
 */
void SimDigital::updateData()
{
    //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimDigital::updateData()\n"<< vprDEBUG_FLUSH;
    std::vector<DigitalData>  digital_data_sample(mSimKeys.size());   // The digital data that makes up the sample

    // -- Update digital data --- //
    for (unsigned int i = 0; i < mSimKeys.size(); i++)
    {
        // Set the time for the digital data to the KeyboardMouse timestamp
        digital_data_sample[i].setTime(mKeyboardMouse->getTimeStamp());
        if(checkKeyPair(mSimKeys[i]))             // If keys pressed
        {
            digital_data_sample[i] = 1;
        }
        else
        {
            digital_data_sample[i] = 0;
        }
    }

    // Add a sample
    addDigitalSample(digital_data_sample);

    swapDigitalBuffers();
}
Exemple #2
0
void SimAnalog::updateData()
{
   //vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)<<"*** SimAnalog::updateData()\n"<< vprDEBUG_FLUSH;

   // -- Update analog data --- //
   for (unsigned int i = 0; i < mSimKeysUp.size(); ++i)
   {
      int upPressed   = checkKeyPair(mSimKeysUp[i]);
      int downPressed = checkKeyPair(mSimKeysDown[i]);

      mAnaData[i].setTime();
      mAnaData[i].setValue(mAnaData[i].getValue() + upPressed   * mAnaStep);
      mAnaData[i].setValue(mAnaData[i].getValue() - downPressed * mAnaStep);

      if (mAutoReturn == true && upPressed == 0 && downPressed == 0)
      {
         if (mAnaData[i].getValue() >= mInitialValue + mAnaStep)
         {
            mAnaData[i].setValue(mAnaData[i].getValue() - mAnaStep);
         }
         else if (mAnaData[i].getValue() <= mInitialValue - mAnaStep )
         {
            mAnaData[i].setValue(mAnaData[i].getValue() + mAnaStep);
         }
         else
         {
            mAnaData[i].setValue(mInitialValue);
         }
      }

      // Clamp to the min/max range
      mAnaData[i].setValue(gmtl::Math::clamp(mAnaData[i].getValue(),
                                              getMin(), getMax()));
   }

   // Locks and then swaps the indices.
   addAnalogSample(mAnaData);
   swapAnalogBuffers();
}