qtmobility/plugins/sensors/maemo6/maemo6compass.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "maemo6compass.h"
    42 #include "maemo6compass.h"
    43 
    43 
    44 const char *maemo6compass::id("maemo6.compass");
    44 char const * const maemo6compass::id("maemo6.compass");
    45 bool maemo6compass::m_initDone = false;
    45 bool maemo6compass::m_initDone = false;
    46 
    46 
    47 maemo6compass::maemo6compass(QSensor *sensor)
    47 maemo6compass::maemo6compass(QSensor *sensor)
    48     : maemo6sensorbase(sensor)
    48     : maemo6sensorbase(sensor)
    49 {
    49 {
       
    50     const QString sensorName = "compasssensor";
       
    51     initSensor<CompassSensorChannelInterface>(sensorName, m_initDone);
       
    52 
       
    53     if (m_sensorInterface){
       
    54         if (!(QObject::connect(m_sensorInterface, SIGNAL(dataAvailable(const Compass&)),
       
    55                                this, SLOT(slotDataAvailable(const Compass&)))))
       
    56             qWarning() << "Unable to connect "<< sensorName;
       
    57     }
       
    58     else
       
    59         qWarning() << "Unable to initialize "<<sensorName;
       
    60 
    50     setReading<QCompassReading>(&m_reading);
    61     setReading<QCompassReading>(&m_reading);
    51 
    62     // metadata
    52     if (!m_initDone) {
    63     addDataRate(1, 130); // 43 Hz
    53         initSensor<CompassSensorChannelInterface>("compasssensor");
    64     addOutputRange(0, 359, 1);
    54 
    65     setDescription(QLatin1String("Measures compass north in degrees"));
    55         if (m_sensorInterface) {
       
    56             QObject::connect(static_cast<CompassSensorChannelInterface*>(m_sensorInterface), SIGNAL(dataAvailable(const Compass&)), this, SLOT(dataAvailable(const Compass&)));
       
    57         } else {
       
    58             qWarning() << "Unable to initialize compass sensor.";            
       
    59         }
       
    60 
       
    61         // metadata TODO accuracy
       
    62         addDataRate(43, 43); // 43Hz
       
    63         sensor->setDataRate(43);
       
    64         addOutputRange(0, 359, 1);
       
    65         setDescription(QLatin1String("Measures compass north in degrees"));
       
    66  
       
    67         m_initDone = true;
       
    68     }
       
    69 }
    66 }
    70 
    67 
    71 void maemo6compass::dataAvailable(const Compass& data)
    68 void maemo6compass::slotDataAvailable(const Compass& data)
    72 {
    69 {
    73     // The scale for level is [0,3], where 3 is the best
    70     // The scale for level is [0,3], where 3 is the best
    74     // Qt: Measured as a value from 0 to 1 with higher values being better.
    71     // Qt: Measured as a value from 0 to 1 with higher values being better.
    75     m_reading.setCalibrationLevel(((float) data.level()) / 3.0);
    72     m_reading.setCalibrationLevel(((float) data.level()) / 3.0);
    76 
    73