void Accelerometer::updateSensor() { QAccelerometerReading *reading = m_accelerometer->reading (); m_x = reading->x(); m_y = reading->y(); m_z = reading->z(); }
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 }
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(); }
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); }
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; } } }