Example #1
0
void MainUI::updateAccelerometer()
{
#if defined(MOBILE_DEVICE) && !defined(MAEMO)
        // TODO: Toggle it depending on whether it is enabled
        QAccelerometerReading *reading = acc->reading();
        if (reading) {
            input_state.acc.x = reading->x();
            input_state.acc.y = reading->y();
            input_state.acc.z = reading->z();
            AxisInput axis;
            axis.deviceId = DEVICE_ID_ACCELEROMETER;
            axis.flags = 0;

            axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X;
            axis.value = input_state.acc.x;
            NativeAxis(axis);

            axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y;
            axis.value = input_state.acc.y;
            NativeAxis(axis);

            axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z;
            axis.value = input_state.acc.z;
            NativeAxis(axis);
        }
#endif
}
Example #2
0
void Accelerometer::updateSensor()
{
    QAccelerometerReading *reading = m_accelerometer->reading ();
    m_x = reading->x();
    m_y = reading->y();
    m_z = reading->z();
}
Example #3
0
void reading_perf::reading_speed_direct()
{
    QAccelerometer sensor;
    QVERIFY(sensor.connectToBackend());
    QAccelerometerReading *reading = sensor.reading();
    qreal x;
    QBENCHMARK { x = reading->x(); }
}
void AsemanSensors::grv_reading()
{
    if( !p->gravity->reading() )
        return;

    QAccelerometerReading *rd = p->gravity->reading();
    p->pg_vector.x = rd->x();
    p->pg_vector.y = rd->y();
    p->pg_vector.z = rd->z();
    refresh();
}
void AsemanSensors::acc_reading()
{
    if( !p->accelerometer->reading() )
        return;

    QAccelerometerReading *rd = p->accelerometer->reading();
    p->pa_vector.x = rd->x();
    p->pa_vector.y = rd->y();
    p->pa_vector.z = rd->z();
    refresh();
}
Example #6
0
void DeviceMotion::updateSensor() {
    QAccelerometerReading *accelerometer = _accelerometerSource->reading();

    QVariantMap obj;
    obj.insert("x", accelerometer->x());
    obj.insert("y", accelerometer->y());
    obj.insert("z", accelerometer->z());
    // accelerometer->timestamp() is not sutiable.
    // Timestamps values are microseconds since _a_ fixed point(depend on backend).
    obj.insert("timestamp", QDateTime::currentDateTime().toMSecsSinceEpoch());

    if (_scId)
        this->cb(_scId, obj);
}
Example #7
0
    HRESULT readingChanged(IAccelerometer *, IAccelerometerReadingChangedEventArgs *args)
    {
        ComPtr<IAccelerometerReading> value;
        HRESULT hr = args->get_Reading(&value);
        if (FAILED(hr)) {
            qCWarning(lcWinRtSensors) << "Failed to get accelerometer reading" << qt_error_string(hr);
            return hr;
        }

        DOUBLE x;
        hr = value->get_AccelerationX(&x);
        if (FAILED(hr))
            qCWarning(lcWinRtSensors) << "Failed to get acceleration X" << qt_error_string(hr);

        DOUBLE y;
        hr = value->get_AccelerationY(&y);
        if (FAILED(hr))
            qCWarning(lcWinRtSensors) << "Failed to get acceleration Y" << qt_error_string(hr);

        DOUBLE z;
        hr = value->get_AccelerationZ(&z);
        if (FAILED(hr))
            qCWarning(lcWinRtSensors) << "Failed to get acceleration Z" << qt_error_string(hr);

        DateTime dateTime;
        hr = value->get_Timestamp(&dateTime);
        if (FAILED(hr))
            qCWarning(lcWinRtSensors) << "Failed to get acceleration timestamp" << qt_error_string(hr);

        // The reading is in G force, so convert to m/s/s
        reading.setX(x * GRAVITY_EARTH_MS2);
        reading.setY(y * GRAVITY_EARTH_MS2);
        reading.setZ(z * GRAVITY_EARTH_MS2);
        reading.setTimestamp(dateTimeToMsSinceEpoch(dateTime));
        q->newReadingAvailable();

        return S_OK;
    }
Example #8
0
void SpeedSensor2::poll_sensor() {

  // do not delete reading.  It's owned by the sensor.
  QAccelerometerReading* reading = sensor->reading ();
  qreal x = 0.0f;
  qreal y = 0.0f;
  qreal z = 0.0f;

  if (reading) {
    x = reading->x();
    y = reading->y();
    z = reading->z();

    qreal mag = (sqrt ((x * x) + (y * y) + (z * z))) - gravity;

    // circular queue of magnitudes of past s seconds
    mags[insert_index] = mag;
    insert_index++;

    if (insert_index >= MAGS_COUNT) {
      insert_index = 0;


      qreal min = 1000.;
      qreal max = -1000.;
      qreal sum = 0.;
    
      for (int i = 0; i < MAGS_COUNT; i++) {
	//qDebug () << "i " << i << " " << mags[i];

	if (mags[i] > max) {
	  max = mags[i];
	}
	if (mags[i] < min) {
	  min = mags[i];
	}
	sum += mags[i];

      }

      if (max - min < 1.) {
	qreal avg = sum / MAGS_COUNT;
	qreal new_gravity = gravity + avg;
	/*
	qDebug () << "gravity old " << gravity 
		  << " new " << new_gravity
		  << " avg " << avg;
	*/
	if (startup) {
	  gravity = new_gravity;
	} else {
	  gravity = 0.9*gravity + (0.1 * new_gravity);
	}
      }
      startup = false;
    }

    if (startup) {
      qDebug () << "not enough sensor values";
      return;
    }

    int high_count = 0;
    int low_count = 0;
    int idle_count = 0;

    qreal min = 1000.;
    qreal max = -1000.;

    for (int i = 0; i < MAGS_COUNT; i++) {
      //qDebug () << "i " << i << " " << mags[i];

      if (mags[i] > max) {
	max = mags[i];
      }
      if (mags[i] < min) {
	min = mags[i];
      }


      if (mags[i] > HIGH_LOW_MAG_THRESHOLD) {
	high_count++;
      } else if (mags[i] < -HIGH_LOW_MAG_THRESHOLD) {
	low_count++;
      } else if (mags[i] < IDLE_MAG_THRESHOLD && mags[i] > -IDLE_MAG_THRESHOLD) {
	idle_count++;
      }
    }

    float high_fraq = high_count / (float) MAGS_COUNT;
    float low_fraq = low_count / (float) MAGS_COUNT;
    float idle_fraq = idle_count / (float) MAGS_COUNT;

    MovementState current_state = NOT_IDLE;

    /*
    qDebug () << "high " << high_fraq
	      << " low " << low_fraq
	      << " idle " << idle_fraq
	      << " state " << state;
    */

    if (idle_fraq > 0.25 || (max - min < 1.)) {
      current_state = IDLE;
    } else if (high_fraq > 0.10 && low_fraq > 0.10 && idle_fraq < 0.10) {
      current_state = WALKING;
    }

    if (state != current_state) {
      switch (current_state) {
      case IDLE:
	qDebug () << "speed state change IDLE";
	break;
      case NOT_IDLE:
	qDebug () << "speed state change NOT_IDLE";
	break;
      case WALKING:
	qDebug () << "speed state change WALKING";
	break;
      }

      state = current_state;
    }

  }
}