Commit 2886366b authored by Artem Fedoskin's avatar Artem Fedoskin

Fix issue with rotation when in automatic mode in KStars Lite. Added low-pass...

Fix issue with rotation when in automatic mode in KStars Lite. Added low-pass filter to reduce hittering of screen in auto mode.
parent 4e417ff1
......@@ -93,6 +93,9 @@ public class DeviceOrientation extends QtActivity implements RotationUpdateDeleg
public void onRotationUpdate(float[] newMatrix) {
// remap matrix values according to display rotation, as in
// SensorManager documentation.
final Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
mDisplayRotation = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) ? display.getRotation() : display.getOrientation();
switch (mDisplayRotation) {
case Surface.ROTATION_0:
case Surface.ROTATION_180:
......@@ -111,7 +114,6 @@ public class DeviceOrientation extends QtActivity implements RotationUpdateDeleg
Azimuth = m_orientation[0];
Pitch = m_orientation[1];
Roll = m_orientation[2];
// System.out.println(m_orientation[0] + " " + m_orientation[1] + " " + m_orientation[2]);
}
// Other Activity life-cycle methods
......
......@@ -20,6 +20,12 @@ import android.hardware.SensorManager;
public class RotationVectorListener implements SensorEventListener {
private float[] mRotationM = new float[16];
private RotationUpdateDelegate mRotationUpdateDelegate;
private final float mFilterFactor = 1.0f;
private final float mFilterFactorInv = 1.0f - mFilterFactor;
private boolean firstSensor = true;
private float[] mVectorVals = new float[] { 0f, 0f, 0f };
public RotationVectorListener(RotationUpdateDelegate rotationUpdateDelegate) {
mRotationUpdateDelegate = rotationUpdateDelegate;
......@@ -28,6 +34,8 @@ public class RotationVectorListener implements SensorEventListener {
@SuppressLint("NewApi")
@Override
public void onSensorChanged(SensorEvent event) {
// smooth(event.values, mVectorVals, mVectorVals);
SensorManager.getRotationMatrixFromVector(mRotationM, event.values);
mRotationUpdateDelegate.onRotationUpdate(mRotationM);
}
......@@ -35,4 +43,10 @@ public class RotationVectorListener implements SensorEventListener {
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
private void smooth(float[] inv, float prevv[], float outv[]) {
outv[0] = prevv[0] + mFilterFactor * (inv[0] - prevv[0]);
outv[1] = prevv[1] + mFilterFactor * (inv[1] - prevv[1]);
outv[2] = prevv[2] + mFilterFactor * (inv[2] - prevv[2]);
}
}
......@@ -36,6 +36,7 @@
#include "auxiliary/kspaths.h"
#include <QPointer>
#include <QProcessEnvironment>
namespace KSUtils
{
......
......@@ -4,10 +4,11 @@
#include <QAndroidJniObject>
#include <QtAndroidExtras>
#include <QtAndroid>
#define ALPHA_LOW_PASS 0.1
#endif
DeviceOrientation::DeviceOrientation(QObject * parent)
: QObject(parent)
: QObject(parent), m_Azimuth(0), m_Altitude(0), m_Roll(0)
{
}
......@@ -32,8 +33,10 @@ void DeviceOrientation::getOrientation()
{
#if defined (Q_OS_ANDROID)
QAndroidJniObject activity = QtAndroid::androidActivity();
m_Azimuth = activity.callMethod<float>("getAzimuth");
m_Altitude = activity.callMethod<float>("getPitch");
m_Roll = activity.callMethod<float>("getRoll");
m_Azimuth = m_Azimuth + ALPHA_LOW_PASS * (activity.callMethod<float>("getAzimuth") - m_Azimuth);
m_Altitude = m_Altitude + ALPHA_LOW_PASS * (activity.callMethod<float>("getPitch") - m_Altitude);
float newRoll = activity.callMethod<float>("getRoll");
m_Roll = abs(newRoll - m_Roll) > 10 ? newRoll : m_Roll + ALPHA_LOW_PASS * (newRoll - m_Roll);
#endif
}
......@@ -156,7 +156,6 @@ SkyMapLite::SkyMapLite()
connect(&automaticModeTimer, SIGNAL(timeout()), this, SLOT(updateAutomaticMode()));
setAutomaticMode(false);
#endif
// setRotation(30);
}
QSGNode * SkyMapLite::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment