qtmobility/plugins/sensors/maemo6/maemo6orientationsensor.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    41 
    41 
    42 #include "maemo6orientationsensor.h"
    42 #include "maemo6orientationsensor.h"
    43 
    43 
    44 #include <posedata.h>
    44 #include <posedata.h>
    45 
    45 
    46 const char *maemo6orientationsensor::id("maemo6.orientationsensor");
    46 char const * const maemo6orientationsensor::id("maemo6.orientationsensor");
    47 bool maemo6orientationsensor::m_initDone = false;
    47 bool maemo6orientationsensor::m_initDone = false;
    48 
    48 
    49 maemo6orientationsensor::maemo6orientationsensor(QSensor *sensor)
    49 maemo6orientationsensor::maemo6orientationsensor(QSensor *sensor)
    50     : maemo6sensorbase(sensor)
    50     : maemo6sensorbase(sensor)
    51 {
    51 {
       
    52     const QString sensorName = "orientationsensor";
       
    53     initSensor<OrientationSensorChannelInterface>(sensorName, m_initDone);
       
    54 
       
    55     if (m_sensorInterface){
       
    56         if (!(QObject::connect(m_sensorInterface, SIGNAL(orientationChanged(const Unsigned&)),
       
    57                                this, SLOT(slotDataAvailable(const Unsigned&)))))
       
    58             qWarning() << "Unable to connect "<< sensorName;
       
    59     }
       
    60     else
       
    61         qWarning() << "Unable to initialize "<<sensorName;
       
    62 
    52     setReading<QOrientationReading>(&m_reading);
    63     setReading<QOrientationReading>(&m_reading);
    53 
    64     // metadata
    54     if (!m_initDone) {
    65     addDataRate(130, 130);
    55         initSensor<OrientationSensorChannelInterface>("orientationsensor");
    66     addDataRate(1, 130); // TODO: this is for testing only
    56 
    67     addOutputRange(0, 6, 1);
    57         if (m_sensorInterface)
    68     setDescription(QLatin1String("Measures orientation of the device screen as 6 pre-defined positions"));
    58             QObject::connect(static_cast<OrientationSensorChannelInterface*>(m_sensorInterface), SIGNAL(orientationChanged(const Unsigned&)), this, SLOT(slotOrientationChanged(const Unsigned&)));
       
    59         else
       
    60             qWarning() << "Unable to initialize orientation sensor.";
       
    61 
       
    62         // metadata
       
    63         addDataRate(142, 142); // 142Hz
       
    64         sensor->setDataRate(142);
       
    65         addOutputRange(0, 6, 1);
       
    66         setDescription(QLatin1String("Measures orientation of the device screen as 6 pre-defined levels"));
       
    67 
       
    68         m_initDone = true;
       
    69     }
       
    70 }
    69 }
    71 
    70 
    72 void maemo6orientationsensor::slotOrientationChanged(const Unsigned& data)
    71 void maemo6orientationsensor::slotDataAvailable(const Unsigned& data)
    73 {
    72 {
    74     QOrientationReading::Orientation o;
    73     QOrientationReading::Orientation o;
    75     switch (data.x()) {
    74     switch (data.x()) {
    76         case PoseData::BottomDown: o = QOrientationReading::TopUp;     break;
    75         case PoseData::BottomDown: o = QOrientationReading::TopUp;     break;
    77         case PoseData::BottomUp:   o = QOrientationReading::TopDown;   break;
    76         case PoseData::BottomUp:   o = QOrientationReading::TopDown;   break;