diff -r 06b8e2af4411 -r 6fbed849b4f4 qtmobility/plugins/sensors/maemo6/maemo6tapsensor.cpp --- a/qtmobility/plugins/sensors/maemo6/maemo6tapsensor.cpp Fri Jun 11 14:26:25 2010 +0300 +++ b/qtmobility/plugins/sensors/maemo6/maemo6tapsensor.cpp Wed Jun 23 19:08:38 2010 +0300 @@ -41,49 +41,49 @@ #include "maemo6tapsensor.h" -#include - -const char *maemo6tapsensor::id("maemo6.tapsensor"); +char const * const maemo6tapsensor::id("maemo6.tapsensor"); bool maemo6tapsensor::m_initDone = false; maemo6tapsensor::maemo6tapsensor(QSensor *sensor) - : maemo6sensorbase(sensor), m_sensor(sensor) + : maemo6sensorbase(sensor) { - setReading(&m_reading); + const QString sensorName = "tapsensor"; + initSensor(sensorName, m_initDone); - if (!m_initDone) { - qDBusRegisterMetaType(); - initSensor("tapsensor"); + if (m_sensorInterface){ + if (!(QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Tap&)), + this, SLOT(slotDataAvailable(const Tap&))))) + qWarning() << "Unable to connect "<< sensorName; + } + else + qWarning() << "Unable to initialize "<(m_sensorInterface), SIGNAL(dataAvailable(const Tap&)), this, SLOT(slotDataAvailable(const Tap&))); - else - qWarning() << "Unable to initialize tap sensor."; + setReading(&m_reading); + // metadata + addDataRate(130, 130); + addDataRate(1, 130); // TODO: this is for testing only + addOutputRange(0, 9, 1); + setDescription(QLatin1String("Measures either single or double taps and gives tap direction")); + +} - // metadata - addDataRate(100, 100); // 100Hz - sensor->setDataRate(100); - addOutputRange(0, 9, 1); - setDescription(QLatin1String("Measures single and double taps and gives tap direction")); - m_initDone = true; - } +void maemo6tapsensor::start(){ + maemo6sensorbase::start(); + QVariant v = sensor()->property("returnDoubleTapEvents"); + m_isDoubleTapSensor = v.isValid() && v.toBool()? true: false; + // Set tap type (single/double) + m_reading.setDoubleTap(m_isDoubleTapSensor); } + void maemo6tapsensor::slotDataAvailable(const Tap& data) { - // Set tap type (single/double) - bool doubleTap; - switch (data.type()) { - case TapData::DoubleTap: doubleTap = true; break; - case TapData::SingleTap: doubleTap = false; break; - default: doubleTap = false; + + if (data.type() == TapData::DoubleTap){ + if (!m_isDoubleTapSensor) return; } - QVariant v = m_sensor->property("returnDoubleTapEvents"); - if (v.isValid() && v.toBool() == false) - m_reading.setDoubleTap(false); - else - m_reading.setDoubleTap(doubleTap); + else if (m_isDoubleTapSensor) return; // Set tap direction QTapReading::TapDirection o; @@ -100,7 +100,6 @@ default: o = QTapReading::Undefined; } m_reading.setTapDirection(o); - m_reading.setTimestamp(data.tapData().timestamp_); newReadingAvailable(); }