qtmobility/plugins/sensors/maemo6/maemo6orientationsensor.cpp
changeset 11 06b8e2af4411
parent 8 71781823f776
child 14 6fbed849b4f4
equal deleted inserted replaced
8:71781823f776 11:06b8e2af4411
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the Qt Mobility Components.
     7 ** This file is part of the Qt Mobility Components.
     8 **
     8 **
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "maemo6orientationsensor.h"
    42 #include "maemo6orientationsensor.h"
    43 
    43 
    44 #include "sensord/filters/posedata.h"
    44 #include <posedata.h>
    45 
    45 
    46 const char *maemo6orientationsensor::id("maemo6.orientationsensor");
    46 const char *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)
    53 
    53 
    54     if (!m_initDone) {
    54     if (!m_initDone) {
    55         initSensor<OrientationSensorChannelInterface>("orientationsensor");
    55         initSensor<OrientationSensorChannelInterface>("orientationsensor");
    56 
    56 
    57         if (m_sensorInterface)
    57         if (m_sensorInterface)
    58             QObject::connect(static_cast<OrientationSensorChannelInterface*>(m_sensorInterface), SIGNAL(orientationChanged(const int&)), this, SLOT(slotOrientationChanged(const int&)));
    58             QObject::connect(static_cast<OrientationSensorChannelInterface*>(m_sensorInterface), SIGNAL(orientationChanged(const Unsigned&)), this, SLOT(slotOrientationChanged(const Unsigned&)));
    59         else
    59         else
    60             qWarning() << "Unable to initialize orientation sensor.";
    60             qWarning() << "Unable to initialize orientation sensor.";
    61 
    61 
    62         // metadata
    62         // metadata
    63         addDataRate(142, 142); // 142Hz
    63         addDataRate(142, 142); // 142Hz
    64         sensor->setDataRate(142);
    64         sensor->setDataRate(142);
    65         addOutputRange(0, 6, 1);
    65         addOutputRange(0, 6, 1);
    66         setDescription(QLatin1String("Orientation of the device screen"));
    66         setDescription(QLatin1String("Measures orientation of the device screen as 6 pre-defined levels"));
    67 
    67 
    68         m_initDone = true;
    68         m_initDone = true;
    69     }
    69     }
    70 }
    70 }
    71 
    71 
    72 void maemo6orientationsensor::slotOrientationChanged(const int& data)
    72 void maemo6orientationsensor::slotOrientationChanged(const Unsigned& data)
    73 {
    73 {
    74     QOrientationReading::Orientation o;
    74     QOrientationReading::Orientation o;
    75     switch (data) {
    75     switch (data.x()) {
    76         case PoseData::BottomDown: o = QOrientationReading::TopUp;     break;
    76         case PoseData::BottomDown: o = QOrientationReading::TopUp;     break;
    77         case PoseData::BottomUp:   o = QOrientationReading::TopDown;   break;
    77         case PoseData::BottomUp:   o = QOrientationReading::TopDown;   break;
    78         case PoseData::LeftUp:     o = QOrientationReading::LeftUp;    break;
    78         case PoseData::LeftUp:     o = QOrientationReading::LeftUp;    break;
    79         case PoseData::RightUp:    o = QOrientationReading::RightUp;   break;
    79         case PoseData::RightUp:    o = QOrientationReading::RightUp;   break;
    80         case PoseData::FaceUp:     o = QOrientationReading::FaceUp;    break;
    80         case PoseData::FaceUp:     o = QOrientationReading::FaceUp;    break;
    81         case PoseData::FaceDown:   o = QOrientationReading::FaceDown;  break;
    81         case PoseData::FaceDown:   o = QOrientationReading::FaceDown;  break;
    82         default:                   o = QOrientationReading::Undefined;
    82         default:                   o = QOrientationReading::Undefined;
    83     }
    83     }
    84     m_reading.setOrientation(o);
    84     m_reading.setOrientation(o);
    85     //m_reading.setTimestamp(data.timestamp());
    85     m_reading.setTimestamp(data.UnsignedData().timestamp_);
    86     m_reading.setTimestamp(createTimestamp()); //TODO: use correct timestamp
       
    87     newReadingAvailable();
    86     newReadingAvailable();
    88 }
    87 }