qtmobility/plugins/sensors/generic/genericorientationsensor.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    46 
    46 
    47 genericorientationsensor::genericorientationsensor(QSensor *sensor)
    47 genericorientationsensor::genericorientationsensor(QSensor *sensor)
    48     : QSensorBackend(sensor)
    48     : QSensorBackend(sensor)
    49 {
    49 {
    50     accelerometer = new QAccelerometer(this);
    50     accelerometer = new QAccelerometer(this);
    51     accelerometer->setUpdatePolicy(QSensor::FrequentUpdates);
       
    52     accelerometer->addFilter(this);
    51     accelerometer->addFilter(this);
       
    52     accelerometer->connectToBackend();
    53 
    53 
    54     setSupportedUpdatePolicies(QSensor::OnChangeUpdates);
       
    55     setReading<QOrientationReading>(&m_reading);
    54     setReading<QOrientationReading>(&m_reading);
       
    55     setDataRates(accelerometer);
    56 }
    56 }
    57 
    57 
    58 void genericorientationsensor::start()
    58 void genericorientationsensor::start()
    59 {
    59 {
       
    60     accelerometer->setDataRate(sensor()->dataRate());
    60     accelerometer->start();
    61     accelerometer->start();
       
    62     if (!accelerometer->isActive())
       
    63         sensorStopped();
       
    64     if (accelerometer->isBusy())
       
    65         sensorBusy();
    61 }
    66 }
    62 
    67 
    63 void genericorientationsensor::stop()
    68 void genericorientationsensor::stop()
    64 {
    69 {
    65     accelerometer->stop();
    70     accelerometer->stop();
    66 }
    71 }
    67 
    72 
    68 void genericorientationsensor::poll()
       
    69 {
       
    70     accelerometer->poll();
       
    71 }
       
    72 
       
    73 bool genericorientationsensor::filter(QAccelerometerReading *reading)
    73 bool genericorientationsensor::filter(QAccelerometerReading *reading)
    74 {
    74 {
    75     QOrientationReading::Orientation o = m_reading.orientation();
    75     QOrientationReading::Orientation o = m_reading.orientation();
    76 
    76 
    77     if (reading->x() < -7.35) {
    77     if (reading->y() > 7.35)
       
    78         o = QOrientationReading::TopUp;
       
    79     else if (reading->y() < -7.35)
       
    80         o = QOrientationReading::TopDown;
       
    81     else if (reading->x() > 7.35)
       
    82         o = QOrientationReading::RightUp;
       
    83     else if (reading->x() < -7.35)
    78         o = QOrientationReading::LeftUp;
    84         o = QOrientationReading::LeftUp;
    79     } else if (reading->y() < -7.35) {
    85     else if (reading->z() > 7.35)
    80         o = QOrientationReading::BottomUp;
       
    81     } else if (reading->x() > 7.35) {
       
    82         o = QOrientationReading::RightUp;
       
    83     } else if (reading->y() > 7.35) {
       
    84         o = QOrientationReading::BottomDown;
       
    85     } else if (reading->z() > 7.35) {
       
    86         o = QOrientationReading::FaceUp;
    86         o = QOrientationReading::FaceUp;
    87     } else if (reading->z() < -7.35) {
    87     else if (reading->z() < -7.35)
    88         o = QOrientationReading::FaceDown;
    88         o = QOrientationReading::FaceDown;
    89     }
       
    90 
    89 
    91     if (o != m_reading.orientation()) {
    90     if (o != m_reading.orientation()) {
    92         m_reading.setTimestamp(reading->timestamp());
    91         m_reading.setTimestamp(reading->timestamp());
    93         m_reading.setOrientation(o);
    92         m_reading.setOrientation(o);
    94         newReadingAvailable();
    93         newReadingAvailable();