qtmobility/plugins/sensors/generic/main.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
    42 #include "genericorientationsensor.h"
    42 #include "genericorientationsensor.h"
       
    43 #include "genericrotationsensor.h"
    43 #include <qsensorplugin.h>
    44 #include <qsensorplugin.h>
    44 #include <qsensorbackend.h>
    45 #include <qsensorbackend.h>
    45 #include <qsensormanager.h>
    46 #include <qsensormanager.h>
    46 #include <QFile>
    47 #include <QFile>
    47 #include <QDebug>
    48 #include <QDebug>
    53 public:
    54 public:
    54     void registerSensors()
    55     void registerSensors()
    55     {
    56     {
    56         qDebug() << "loaded the Generic plugin";
    57         qDebug() << "loaded the Generic plugin";
    57         QSensorManager::registerBackend(QOrientationSensor::type, genericorientationsensor::id, this);
    58         QSensorManager::registerBackend(QOrientationSensor::type, genericorientationsensor::id, this);
       
    59         QSensorManager::registerBackend(QRotationSensor::type, genericrotationsensor::id, this);
    58     }
    60     }
    59 
    61 
    60     QSensorBackend *createBackend(QSensor *sensor)
    62     QSensorBackend *createBackend(QSensor *sensor)
    61     {
    63     {
    62         if (sensor->identifier() == genericorientationsensor::id) {
    64         if (sensor->identifier() == genericorientationsensor::id) {
    64             if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty())
    66             if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty())
    65                 return new genericorientationsensor(sensor);
    67                 return new genericorientationsensor(sensor);
    66             qDebug() << "can't make" << sensor->identifier() << "because no" << QAccelerometer::type << "sensors exist";
    68             qDebug() << "can't make" << sensor->identifier() << "because no" << QAccelerometer::type << "sensors exist";
    67         }
    69         }
    68 
    70 
       
    71         if (sensor->identifier() == genericrotationsensor::id) {
       
    72             // Can't make this unless we have an accelerometer
       
    73             if (!QSensor::defaultSensorForType(QAccelerometer::type).isEmpty())
       
    74                 return new genericrotationsensor(sensor);
       
    75             qDebug() << "can't make" << sensor->identifier() << "because no" << QAccelerometer::type << "sensors exist";
       
    76         }
       
    77 
    69         return 0;
    78         return 0;
    70     }
    79     }
    71 };
    80 };
    72 
    81 
    73 Q_EXPORT_PLUGIN2(libsensors_generic, genericSensorPlugin)
    82 Q_EXPORT_PLUGIN2(libsensors_generic, genericSensorPlugin)