From 931e394f4fce5c2bb00b2b6340a06fdfd2956209 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Wed, 2 Sep 2015 23:08:47 -0700 Subject: [PATCH] exp/sensor: don't allow delays smaller than 10ms on ios "You can set the reporting interval to be as small as 10 milliseconds (ms), which corresponds to a 100 Hz update rate, but most app operate sufficiently with a larger interval." from https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html Larger delay values makes the library poll more frequently than needed. Change-Id: Ie3057813209746bff00b8ef534c9ae239396366e Reviewed-on: https://go-review.googlesource.com/14252 Reviewed-by: David Crawshaw --- exp/sensor/darwin_armx.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/exp/sensor/darwin_armx.go b/exp/sensor/darwin_armx.go index c5299a5..ac93737 100644 --- a/exp/sensor/darwin_armx.go +++ b/exp/sensor/darwin_armx.go @@ -41,13 +41,28 @@ func (m *manager) initialize() { C.GoIOS_createManager() } +// minDelay is the minimum delay allowed. +// +// From Event Handling Guide for iOS: +// +// "You can set the reporting interval to be as small as 10 +// milliseconds (ms), which corresponds to a 100 Hz update rate, +// but most app operate sufficiently with a larger interval." +// +// There is no need to poll more frequently than once every 10ms. +// +// https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html + +const minDelay = 10 * time.Millisecond + func (m *manager) enable(s Sender, t Type, delay time.Duration) error { - // TODO(jbd): If delay is smaller than 10 milliseconds, set it to - // 10 milliseconds. It is highest frequency iOS SDK suppports and - // we don't want to have time.Tick durations smaller than this value. channels.Lock() defer channels.Unlock() + if delay < minDelay { + delay = minDelay + } + switch t { case Accelerometer: if channels.acceleroDone != nil {