qtmobility/plugins/sensors/maemo6/maemo6tapsensor.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "maemo6tapsensor.h"
    42 #include "maemo6tapsensor.h"
    43 
    43 
    44 #include <tapdata.h>
    44 char const * const maemo6tapsensor::id("maemo6.tapsensor");
    45 
       
    46 const char *maemo6tapsensor::id("maemo6.tapsensor");
       
    47 bool maemo6tapsensor::m_initDone = false;
    45 bool maemo6tapsensor::m_initDone = false;
    48 
    46 
    49 maemo6tapsensor::maemo6tapsensor(QSensor *sensor)
    47 maemo6tapsensor::maemo6tapsensor(QSensor *sensor)
    50     : maemo6sensorbase(sensor), m_sensor(sensor)
    48     : maemo6sensorbase(sensor)
    51 {
    49 {
       
    50     const QString sensorName = "tapsensor";
       
    51     initSensor<TapSensorChannelInterface>(sensorName, m_initDone);
       
    52 
       
    53     if (m_sensorInterface){
       
    54         if (!(QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Tap&)),
       
    55                                this, SLOT(slotDataAvailable(const Tap&)))))
       
    56             qWarning() << "Unable to connect "<< sensorName;
       
    57     }
       
    58     else
       
    59         qWarning() << "Unable to initialize "<<sensorName;
       
    60 
    52     setReading<QTapReading>(&m_reading);
    61     setReading<QTapReading>(&m_reading);
       
    62     // metadata
       
    63     addDataRate(130, 130);
       
    64     addDataRate(1, 130); // TODO: this is for testing only
       
    65     addOutputRange(0, 9, 1);
       
    66     setDescription(QLatin1String("Measures either single or double taps and gives tap direction"));
    53 
    67 
    54     if (!m_initDone) {
    68 }
    55         qDBusRegisterMetaType<Tap>();
       
    56         initSensor<TapSensorChannelInterface>("tapsensor");
       
    57 
    69 
    58         if (m_sensorInterface)
       
    59             QObject::connect(static_cast<TapSensorChannelInterface*>(m_sensorInterface), SIGNAL(dataAvailable(const Tap&)), this, SLOT(slotDataAvailable(const Tap&)));
       
    60         else
       
    61             qWarning() << "Unable to initialize tap sensor.";
       
    62 
    70 
    63         // metadata
    71 void maemo6tapsensor::start(){
    64         addDataRate(100, 100); // 100Hz
    72     maemo6sensorbase::start();
    65         sensor->setDataRate(100);
    73     QVariant v = sensor()->property("returnDoubleTapEvents");
    66         addOutputRange(0, 9, 1);
    74     m_isDoubleTapSensor =  v.isValid() && v.toBool()? true: false;
    67         setDescription(QLatin1String("Measures single and double taps and gives tap direction"));
    75     // Set tap type (single/double)
       
    76     m_reading.setDoubleTap(m_isDoubleTapSensor);
       
    77 }
    68 
    78 
    69         m_initDone = true;
       
    70     }
       
    71 }
       
    72 
    79 
    73 void maemo6tapsensor::slotDataAvailable(const Tap& data)
    80 void maemo6tapsensor::slotDataAvailable(const Tap& data)
    74 {
    81 {
    75     // Set tap type (single/double)
    82 
    76     bool doubleTap;
    83     if (data.type() == TapData::DoubleTap){
    77     switch (data.type()) {
    84         if (!m_isDoubleTapSensor) return;
    78         case TapData::DoubleTap: doubleTap = true; break;
       
    79         case TapData::SingleTap: doubleTap = false; break;
       
    80         default:                 doubleTap = false;
       
    81     }
    85     }
    82     QVariant v = m_sensor->property("returnDoubleTapEvents");
    86     else if (m_isDoubleTapSensor) return;
    83     if (v.isValid() && v.toBool() == false)
       
    84         m_reading.setDoubleTap(false);
       
    85     else
       
    86         m_reading.setDoubleTap(doubleTap);
       
    87 
    87 
    88     // Set tap direction
    88     // Set tap direction
    89     QTapReading::TapDirection o;
    89     QTapReading::TapDirection o;
    90     switch (data.direction()) {
    90     switch (data.direction()) {
    91         case TapData::X:         o = QTapReading::X;         break;
    91         case TapData::X:         o = QTapReading::X;         break;
    98         case TapData::FaceBack:  o = QTapReading::Y_Pos;     break;
    98         case TapData::FaceBack:  o = QTapReading::Y_Pos;     break;
    99         case TapData::BackFace:  o = QTapReading::Y_Neg;     break;
    99         case TapData::BackFace:  o = QTapReading::Y_Neg;     break;
   100         default:                 o = QTapReading::Undefined;
   100         default:                 o = QTapReading::Undefined;
   101     }
   101     }
   102     m_reading.setTapDirection(o);
   102     m_reading.setTapDirection(o);
   103 
       
   104     m_reading.setTimestamp(data.tapData().timestamp_);
   103     m_reading.setTimestamp(data.tapData().timestamp_);
   105     newReadingAvailable();
   104     newReadingAvailable();
   106 }
   105 }