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 <crawshaw@golang.org>
This commit is contained in:
Burcu Dogan 2015-09-02 23:08:47 -07:00
parent 70b9ad3e00
commit 931e394f4f
1 changed files with 18 additions and 3 deletions

View File

@ -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 {