forked from organicmaps/organicmaps
[android] Add average sensor calculation routine for compass.
This commit is contained in:
parent
29285304b3
commit
f63169987d
4 changed files with 68 additions and 3 deletions
|
@ -42,6 +42,10 @@ namespace android
|
|||
|
||||
m_videoTimer = new VideoTimer(bind(&Framework::CallRepaint, this));
|
||||
|
||||
size_t const measurementsCount = 5;
|
||||
m_sensors[0].SetCount(measurementsCount);
|
||||
m_sensors[1].SetCount(measurementsCount);
|
||||
|
||||
// @TODO refactor storage
|
||||
m_work.Storage().ReInitCountries(false);
|
||||
}
|
||||
|
@ -81,6 +85,13 @@ namespace android
|
|||
m_work.OnCompassUpdate(info);
|
||||
}
|
||||
|
||||
void Framework::UpdateCompassSensor(int ind, float * arr)
|
||||
{
|
||||
//LOG ( LINFO, ("Sensors before, C++: ", arr[0], arr[1], arr[2]) );
|
||||
m_sensors[ind].Next(arr);
|
||||
//LOG ( LINFO, ("Sensors after, C++: ", arr[0], arr[1], arr[2]) );
|
||||
}
|
||||
|
||||
void Framework::DeleteRenderPolicy()
|
||||
{
|
||||
m_work.SaveState();
|
||||
|
|
|
@ -6,9 +6,14 @@
|
|||
#include "../../../../../map/drawer_yg.hpp"
|
||||
#include "../../../../../map/window_handle.hpp"
|
||||
#include "../../../../../map/feature_vec_model.hpp"
|
||||
|
||||
#include "../../../../../geometry/avg_vector.hpp"
|
||||
|
||||
#include "../../../../../base/timer.hpp"
|
||||
|
||||
#include "../../../nv_event/nv_event.hpp"
|
||||
|
||||
|
||||
namespace android
|
||||
{
|
||||
class Framework
|
||||
|
@ -43,6 +48,8 @@ namespace android
|
|||
double m_lastX1;
|
||||
double m_lastY1;
|
||||
|
||||
math::AvgVector<float, 3> m_sensors[2];
|
||||
|
||||
public:
|
||||
|
||||
Framework();
|
||||
|
@ -55,6 +62,7 @@ namespace android
|
|||
void OnLocationStatusChanged(int/* == location::TLocationStatus*/ newStatus);
|
||||
void OnLocationUpdated(uint64_t time, double lat, double lon, float accuracy);
|
||||
void OnCompassUpdated(uint64_t time, double magneticNorth, double trueNorth, float accuracy);
|
||||
void UpdateCompassSensor(int ind, float * arr);
|
||||
|
||||
void Invalidate();
|
||||
|
||||
|
|
|
@ -64,6 +64,25 @@ extern "C"
|
|||
g_framework->OnCompassUpdated(time, magneticNorth, trueNorth, accuracy);
|
||||
}
|
||||
|
||||
JNIEXPORT jfloatArray JNICALL
|
||||
Java_com_mapswithme_maps_location_LocationService_nativeUpdateCompassSensor(
|
||||
JNIEnv * env, jobject thiz, jint ind, jfloatArray arr)
|
||||
{
|
||||
int const count = 3;
|
||||
|
||||
// get Java array
|
||||
jfloat buffer[3];
|
||||
env->GetFloatArrayRegion(arr, 0, count, buffer);
|
||||
|
||||
// get the result
|
||||
g_framework->UpdateCompassSensor(ind, buffer);
|
||||
|
||||
// pass result back to Java
|
||||
jfloatArray ret = (jfloatArray)env->NewFloatArray(count);
|
||||
env->SetFloatArrayRegion(ret, 0, count, buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_hasMeasurementSystem(JNIEnv * env, jobject thiz)
|
||||
{
|
||||
|
|
|
@ -291,6 +291,28 @@ public class LocationService implements LocationListener, SensorEventListener, W
|
|||
}
|
||||
}
|
||||
|
||||
private native float[] nativeUpdateCompassSensor(int ind, float[] arr);
|
||||
private float[] UpdateCompassSensor(int ind, float[] arr)
|
||||
{
|
||||
/*
|
||||
Log.d(TAG, "Sensor before, Java: " +
|
||||
String.valueOf(arr[0]) + ", " +
|
||||
String.valueOf(arr[1]) + ", " +
|
||||
String.valueOf(arr[2]));
|
||||
*/
|
||||
|
||||
float[] ret = nativeUpdateCompassSensor(ind, arr);
|
||||
|
||||
/*
|
||||
Log.d(TAG, "Sensor after, Java: " +
|
||||
String.valueOf(ret[0]) + ", " +
|
||||
String.valueOf(ret[1]) + ", " +
|
||||
String.valueOf(ret[2]));
|
||||
*/
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private float[] m_gravity = null;
|
||||
private float[] m_geomagnetic = null;
|
||||
|
||||
|
@ -298,12 +320,17 @@ public class LocationService implements LocationListener, SensorEventListener, W
|
|||
public void onSensorChanged(SensorEvent event)
|
||||
{
|
||||
// Get the magnetic north (orientation contains azimut, pitch and roll).
|
||||
float orientation[] = null;
|
||||
float[] orientation = null;
|
||||
|
||||
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
|
||||
m_gravity = event.values;
|
||||
{
|
||||
m_gravity = UpdateCompassSensor(0, event.values);
|
||||
}
|
||||
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
|
||||
m_geomagnetic = event.values;
|
||||
{
|
||||
m_geomagnetic = UpdateCompassSensor(1, event.values);
|
||||
}
|
||||
|
||||
if (m_gravity != null && m_geomagnetic != null)
|
||||
{
|
||||
float R[] = new float[9];
|
||||
|
|
Loading…
Add table
Reference in a new issue