Example #1
0
void QFeedbackSimulator::setActuatorProperty(const QFeedbackActuator &actuator, ActuatorProperty prop, const QVariant &value)
{
    if (!mActuatorData.contains(actuator.id()))
        return;
    ActuatorData &data = mActuatorData[actuator.id()];

    switch (prop)
    {
    case Enabled:
        data.enabled = value.toBool();
        mConnection->setActuatorEnabled(actuator.id(), data.enabled);
        break;
    default:
        break;
    }
}
Example #2
0
QVariant QFeedbackSimulator::actuatorProperty(const QFeedbackActuator &actuator, ActuatorProperty prop)
{
    if (!mActuatorData.contains(actuator.id()))
        return QVariant();
    const ActuatorData &data = mActuatorData.value(actuator.id());

    switch (prop)
    {
    case Name:
        return data.name;
    case State:
        return data.state;
    case Enabled:
        return data.enabled;
    default:
        break;
    }

    return QVariant();
}
Example #3
0
QVariant QFeedbackImmersion::actuatorProperty(const QFeedbackActuator &actuator, ActuatorProperty prop)
{
    switch (prop)
    {
    case Name:
        {
            char szDeviceName[VIBE_MAX_DEVICE_NAME_LENGTH] = { 0 };
            if (VIBE_FAILED(ImmVibeGetDeviceCapabilityString(actuator.id(), VIBE_DEVCAPTYPE_DEVICE_NAME,
                VIBE_MAX_CAPABILITY_STRING_LENGTH, szDeviceName)))
                return QString();

            return QString::fromLocal8Bit(szDeviceName);
        }

    case State:
        {
            QFeedbackActuator::State ret = QFeedbackActuator::Unknown;
            VibeInt32 s = 0;
            if (actuator.isValid() && VIBE_SUCCEEDED(ImmVibeGetDeviceState(actuator.id(), &s))) {
                if (s == VIBE_DEVICESTATE_ATTACHED)
                    ret = QFeedbackActuator::Ready;
                else if (s == VIBE_DEVICESTATE_BUSY)
                    ret = QFeedbackActuator:: Busy;
            }

            return ret;
        }
    case Enabled:
        {
            VibeBool disabled = true;
            if (VIBE_FAILED(ImmVibeGetDevicePropertyBool(handleForActuator(actuator), VIBE_DEVPROPTYPE_DISABLE_EFFECTS, &disabled)))
                return false;
            return !disabled;
        }
    default:
        return QVariant();
    }
}
Example #4
0
void tst_QFeedbackPlugin::testPlugin()
{
    QFeedbackHapticsEffect testEffect;
    // first get the actuators.  we want to use the test plugin actuator.
    QFeedbackActuator* testActuator;
    QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators();
    QCOMPARE(actuators.count(), 2);

    QCOMPARE(actuators.at(0)->name(), QString("test plugin"));
    QCOMPARE(actuators.at(0)->id(), 0);
    QCOMPARE(actuators.at(1)->name(), QString("5555"));
    QCOMPARE(actuators.at(1)->id(), 1);

    // make sure we found the test actuator...
    testActuator = actuators.at(0);

    QCOMPARE(testActuator->name(), QString("test plugin"));
    QCOMPARE(testActuator->id(), 0); // test
    QVERIFY(testActuator->isCapabilitySupported(QFeedbackActuator::Period));
    testActuator->setEnabled(true);
    QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false.
    testActuator->setEnabled(false);
    QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false.
    testActuator->setEnabled(true);
    QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false.
    QCOMPARE(testActuator->state(), QFeedbackActuator::Unknown); // and it always returns state = unknown.
    // XXX TODO: ensure that a "working" plugin returns real values..

    // then, ensure that the test effect uses this actuator.
    testEffect.setActuator(testActuator);

    // it will do nothing, so stick some values in and play it.
    testEffect.setAttackIntensity(0.0);
    testEffect.setAttackTime(250);
    testEffect.setIntensity(1.0);
    testEffect.setDuration(100);
    testEffect.setFadeTime(250);
    testEffect.setFadeIntensity(0.0);
    testEffect.start();
    QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Running);
    testEffect.pause();
    QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Paused);
    testEffect.start();
    QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Running);
    testEffect.stop();
    QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Stopped);
}
QTM_BEGIN_NAMESPACE

/*!
    \class QFeedbackActuator
    \brief The QFeedbackActuator class describes actuators for tactile feedback.
    \inmodule QtFeedback
    \since 1.1

    An actuator knows how to play a \l{QFeedbackEffect}{tactile
    effect}. The class gives access to a specified actuator.

    An actuator can be used to play \l{QFeedbackHapticsEffect}s using
    \l{QFeedbackHapticsEffect::}{setActuator()}. Usually, you will not
    have to set an actuator directly on a QFeedbackHapticsEffect.
    QFeedbackHapticsEffect and QFeedbackFileEffect uses an appropriate
    actuator by default. However, you can query which actuators
    are available with actuators().

    \code
     QFeedbackActuator actuator; // default system actuator
     QList<QFeedbackActuator> actuators = QFeedbackActuator::actuators();
     foreach (const QFeedbackActuator& temp, actuators) {
         if (temp.name() == "ExampleActuatorName") {
             actuator = temp;
         }
     }
    \endcode

    The QFeedbackActuator class gives access to information about the
    actuator it represents. You can query if the actuator \l{isEnabled()}{is enabled}
    and if it \l{isValid()}{is valid }. Whether an actuator is ready to play an
    effect can be queried by checking the actuator's state(). The
    \l{QFeedbackActuator::}{State} enum describes the states and
    actuator can have. You can also get a human readable name for the actuator with the
    name() function.

    \sa QFeedbackHapticsEffect QFeedbackFileEffect QFeedbackEffect
*/

/*!
    \enum QFeedbackActuator::Capability

    \value Envelope Capability defining the wave type with attack/fade times and levels.
    \value Period   Capability defining that the device can play periodic effects.
*/

/*!
    \enum QFeedbackActuator::State

    \value Busy    The actuator is busy.
    \value Ready   The actuator is ready to play an effect.
    \value Unknown The actuator is in an unknown state.
*/


/*!
    Constructs a QFeedbackActuator, passing \a parent to the QObject constructor.

    The object will represent the default actuator on the system.
    If there are no actuators attached to the system, isValid() will return false.

    \sa isValid()
*/
QFeedbackActuator::QFeedbackActuator(QObject *parent) : QObject(parent), m_id(-1)
{
    QList<QFeedbackActuator*> list = actuators();
    if  (!list.isEmpty()) {
        QFeedbackActuator* defaultActuator = list.first();
        m_id = defaultActuator->id();
    }
}
Example #6
0
VibeInt32 QFeedbackImmersion::handleForActuator(const QFeedbackActuator &actuator)
{
    return handleForActuator(actuator.id());
}