qtmobility/examples/sensors/accel/main.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    49 class AccelerometerFilter : public QAccelerometerFilter
    49 class AccelerometerFilter : public QAccelerometerFilter
    50 {
    50 {
    51 public:
    51 public:
    52     bool filter(QAccelerometerReading *reading)
    52     bool filter(QAccelerometerReading *reading)
    53     {
    53     {
    54 #if 0
       
    55         QAccelerometerReading *lastReading = accelerometer->reading();
       
    56         qDebug() << "acceleration: "
       
    57                  << QString().sprintf("%0.2f (%0.2f) %0.2f (%0.2f) %0.2f (%0.2f)",
       
    58                          reading->x(),
       
    59                          lastReading->x() - reading->x(),
       
    60                          reading->y(),
       
    61                          lastReading->y() - reading->y(),
       
    62                          reading->z(),
       
    63                          lastReading->z() - reading->z());
       
    64         return true; // so the last reading is available!
       
    65 #else
       
    66         qDebug() << "acceleration: "
    54         qDebug() << "acceleration: "
    67                  << QString().sprintf("%0.2f %0.2f %0.2f",
    55                  << QString().sprintf("%0.2f %0.2f %0.2f",
    68                          reading->x(),
    56                          reading->x(),
    69                          reading->y(),
    57                          reading->y(),
    70                          reading->z());
    58                          reading->z());
    71         return false; // don't store the reading in the sensor
    59         return false; // don't store the reading in the sensor
    72 #endif
       
    73     }
    60     }
    74 };
    61 };
    75 
    62 
    76 int main(int argc, char **argv)
    63 int main(int argc, char **argv)
    77 {
    64 {
    78     QCoreApplication app(argc, argv);
    65     QCoreApplication app(argc, argv);
    79 
    66 
    80     QAccelerometer sensor;
    67     QAccelerometer sensor;
    81     accelerometer = &sensor;
    68     accelerometer = &sensor;
    82     if (!sensor.connect()) {
    69     AccelerometerFilter filter;
    83         qWarning("No Accelerometer available!");
    70     sensor.addFilter(&filter);
       
    71     sensor.start();
       
    72 
       
    73     if (!sensor.isActive()) {
       
    74         qWarning("Accelerometer didn't start!");
    84         return 1;
    75         return 1;
    85     }
    76     }
    86     AccelerometerFilter filter;
       
    87     sensor.setSignalEnabled(false);
       
    88     sensor.addFilter(&filter);
       
    89     //sensor.setUpdatePolicy(QSensor::InfrequentUpdates);
       
    90     sensor.setUpdateInterval(100); // as fast as the sensor can go!
       
    91     sensor.start();
       
    92 
    77 
    93     return app.exec();
    78     return app.exec();
    94 }
    79 }
    95 
    80