forked from organicmaps/organicmaps
[android] Filter compass values before emit into Framework via nv-queue. Added threshold for the location and angle to the location::State.
This commit is contained in:
parent
a7c0b78fa6
commit
99168e583c
9 changed files with 47 additions and 22 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "../core/jni_helper.hpp"
|
||||
#include "../core/render_context.hpp"
|
||||
|
||||
#include "../platform/Platform.hpp"
|
||||
|
||||
#include "../../../../../map/framework.hpp"
|
||||
|
@ -12,22 +13,23 @@
|
|||
|
||||
#include "../../../../../gui/controller.hpp"
|
||||
|
||||
#include "../../../../../graphics/opengl/framebuffer.hpp"
|
||||
#include "../../../../../graphics/opengl/opengl.hpp"
|
||||
|
||||
#include "../../../../../indexer/drawing_rules.hpp"
|
||||
|
||||
#include "../../../../../coding/file_container.hpp"
|
||||
#include "../../../../../coding/file_name_utils.hpp"
|
||||
|
||||
#include "../../../../../graphics/opengl/framebuffer.hpp"
|
||||
#include "../../../../../graphics/opengl/opengl.hpp"
|
||||
#include "../../../../../geometry/angles.hpp"
|
||||
|
||||
#include "../../../../../platform/platform.hpp"
|
||||
#include "../../../../../platform/location.hpp"
|
||||
#include "../../../../../platform/preferred_languages.hpp"
|
||||
|
||||
#include "../../../../../base/math.hpp"
|
||||
#include "../../../../../base/logging.hpp"
|
||||
|
||||
#include "../../../../../platform/preferred_languages.hpp"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -47,6 +49,7 @@ namespace android
|
|||
: m_mask(0),
|
||||
m_isCleanSingleClick(false),
|
||||
m_doLoadState(true),
|
||||
m_lastCompass(0.0),
|
||||
m_wasLongClick(false)
|
||||
{
|
||||
ASSERT_EQUAL ( g_framework, 0, () );
|
||||
|
@ -67,12 +70,20 @@ namespace android
|
|||
|
||||
void Framework::OnLocationUpdated(location::GpsInfo const & info)
|
||||
{
|
||||
Platform::RunOnGuiThreadImpl(bind(&::Framework::OnLocationUpdate, ref(m_work), info));
|
||||
Platform::RunOnGuiThreadImpl(bind(&::Framework::OnLocationUpdate, ref(m_work), info), false);
|
||||
}
|
||||
|
||||
void Framework::OnCompassUpdated(location::CompassInfo const & info)
|
||||
{
|
||||
Platform::RunOnGuiThreadImpl(bind(&::Framework::OnCompassUpdate, ref(m_work), info));
|
||||
static double const COMPASS_THRASHOLD = my::DegToRad(1.0);
|
||||
|
||||
/// @todo Do not emit compass bearing too often while we are passing it through nv-queue.
|
||||
/// Need to make more experiments in future.
|
||||
if (fabs(ang::GetShortestDistance(m_lastCompass, info.m_bearing)) >= COMPASS_THRASHOLD)
|
||||
{
|
||||
m_lastCompass = info.m_bearing;
|
||||
Platform::RunOnGuiThreadImpl(bind(&::Framework::OnCompassUpdate, ref(m_work), info), false);
|
||||
}
|
||||
}
|
||||
|
||||
void Framework::UpdateCompassSensor(int ind, float * arr)
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace android
|
|||
//@}
|
||||
|
||||
math::LowPassVector<float, 3> m_sensors[2];
|
||||
double m_lastCompass;
|
||||
|
||||
unique_ptr<ScheduledTask> m_scheduledTask;
|
||||
bool m_wasLongClick;
|
||||
|
|
|
@ -57,7 +57,7 @@ string Platform::UniqueClientId() const
|
|||
|
||||
void Platform::RunOnGuiThread(TFunctor const & fn)
|
||||
{
|
||||
android::Platform::RunOnGuiThreadImpl(fn);
|
||||
android::Platform::RunOnGuiThreadImpl(fn, true);
|
||||
}
|
||||
|
||||
namespace android
|
||||
|
@ -137,9 +137,9 @@ namespace android
|
|||
return platform;
|
||||
}
|
||||
|
||||
void Platform::RunOnGuiThreadImpl(TFunctor const & fn)
|
||||
void Platform::RunOnGuiThreadImpl(TFunctor const & fn, bool blocking)
|
||||
{
|
||||
postMWMEvent(new TFunctor(fn));
|
||||
postMWMEvent(new TFunctor(fn), blocking);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace android
|
|||
|
||||
bool HasAvailableSpaceForWriting(uint64_t size) const;
|
||||
|
||||
static void RunOnGuiThreadImpl(TFunctor const & fn);
|
||||
static void RunOnGuiThreadImpl(TFunctor const & fn, bool blocking);
|
||||
|
||||
static Platform & Instance();
|
||||
};
|
||||
|
|
|
@ -799,19 +799,22 @@ static jboolean postUserEvent(JNIEnv* env, jobject thiz,
|
|||
return NVEventInsertBlocking(&ev);
|
||||
}
|
||||
else
|
||||
{
|
||||
NVEventInsert(&ev);
|
||||
return true;
|
||||
}
|
||||
{
|
||||
NVEventInsert(&ev);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void postMWMEvent(void * pFn)
|
||||
void postMWMEvent(void * pFn, bool blocking)
|
||||
{
|
||||
NVEvent ev;
|
||||
ev.m_type = NV_EVENT_MWM;
|
||||
ev.m_data.m_mwm.m_pFn = pFn;
|
||||
|
||||
NVEventInsertBlocking(&ev);
|
||||
if (blocking)
|
||||
(void) NVEventInsertBlocking(&ev);
|
||||
else
|
||||
NVEventInsert(&ev);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -544,6 +544,6 @@ NVEventPlatformAppHandle NVEventGetPlatformAppHandle();
|
|||
|
||||
void InitNVEvent(JavaVM * jvm);
|
||||
|
||||
void postMWMEvent(void * pFn);
|
||||
void postMWMEvent(void * pFn, bool blocking);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -195,7 +195,7 @@ public enum LocationService implements
|
|||
{
|
||||
if (mSensorManager != null)
|
||||
{
|
||||
final int COMPASS_REFRESH_MKS = SensorManager.SENSOR_DELAY_NORMAL;
|
||||
final int COMPASS_REFRESH_MKS = SensorManager.SENSOR_DELAY_UI;
|
||||
|
||||
if (mAccelerometer != null)
|
||||
mSensorManager.registerListener(this, mAccelerometer, COMPASS_REFRESH_MKS);
|
||||
|
|
|
@ -29,6 +29,9 @@ namespace
|
|||
{
|
||||
|
||||
static const int POSITION_Y_OFFSET = 120;
|
||||
static const double POSITION_TOLERANCE = 1.0E-6; // much less than coordinates coding error
|
||||
static const double ANGLE_TOLERANCE = my::DegToRad(3.0);
|
||||
|
||||
|
||||
uint16_t IncludeModeBit(uint16_t mode, uint16_t bit)
|
||||
{
|
||||
|
@ -72,6 +75,11 @@ public:
|
|||
{
|
||||
ASSERT(m_angleAnim != nullptr, ());
|
||||
ASSERT(m_posAnim != nullptr, ());
|
||||
|
||||
if (dstPos.EqualDxDy(m_posAnim->GetCurrentValue(), POSITION_TOLERANCE) &&
|
||||
fabs(ang::GetShortestDistance(m_angleAnim->GetCurrentValue(), dstAngle)) < ANGLE_TOLERANCE)
|
||||
return;
|
||||
|
||||
double const posSpeed = m_fw->GetNavigator().ComputeMoveSpeed(m_posAnim->GetCurrentValue(), dstPos);
|
||||
double const angleSpeed = 1.5;//m_fw->GetAnimator().GetRotationSpeed();
|
||||
|
||||
|
@ -799,7 +807,10 @@ void State::AnimateFollow()
|
|||
return;
|
||||
|
||||
if (!FollowCompass())
|
||||
m_framework->SetViewportCenterAnimated(Position());
|
||||
{
|
||||
if (!m_position.EqualDxDy(m_framework->GetViewportCenter(), POSITION_TOLERANCE))
|
||||
m_framework->SetViewportCenterAnimated(m_position);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
namespace routing
|
||||
{
|
||||
|
||||
static double const TIME_THRESHOLD_SECONDS = 60.0*1.0;
|
||||
|
||||
double GetDistanceOnEarth(m2::PointD const & p1, m2::PointD const & p2)
|
||||
{
|
||||
return ms::DistanceOnEarth(MercatorBounds::YToLat(p1.y),
|
||||
|
@ -70,9 +68,10 @@ void Route::MoveIterator(m2::PointD const & currPos, location::GpsInfo const & i
|
|||
{
|
||||
/// @todo Need to distinguish GPS and WiFi locations.
|
||||
/// They may have different time metrics in case of incorrect system time on a device.
|
||||
static double const LOCATION_TIME_THRESHOLD = 60.0*1.0;
|
||||
|
||||
double const deltaT = info.m_timestamp - m_currentTime;
|
||||
if (deltaT > 0.0 && deltaT < TIME_THRESHOLD_SECONDS)
|
||||
if (deltaT > 0.0 && deltaT < LOCATION_TIME_THRESHOLD)
|
||||
predictDistance = info.m_speed * deltaT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue