2
0
mirror of synced 2025-02-23 14:58:12 +00:00
mobile/exp/sensor/notmobile.go
Burcu Dogan 1b12574c99 exp/sensor: don't enable a sensor on a sender
The underlying implementation was not enabling the sensors on a
particular sender even though the Enable signature accepts different
instances of Sender to enable.

Consider the following program:

  type A struct{}
  func (a A) Send(ev interface{}) {}

  type B struct{}
  func (b B) Send(ev interface{}) {}

  sensor.Enable(A{}, sensor.Gyroscope, time.Millisecond)
  sensor.Enable(B{}, sensor.Accelerometer, time.Millisecond)

is going to compile but only A will be notified when there are new
gyroscope and accelerometer events.

In order to improve the misleading APIs, this CL introduces a
Notify function that users can register a Sender implementation to
listen the changes. If set nil, the sensor package will keep
reading the events but will won't notify.

  sensor.Notify(A{})
  sensor.Enable(sensor.Gyroscope, time.Millisecond)
  sensor.Enable(sensor.Accelerometer, time.Millisecond)

Change-Id: I25e43349e4ae682930baa2d32430f46f24b588b7
Reviewed-on: https://go-review.googlesource.com/15650
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-19 21:21:50 +00:00

25 lines
482 B
Go

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build linux,!android darwin,!arm,!arm64 windows
package sensor
import (
"errors"
"time"
)
func enable(t Type, delay time.Duration) error {
return errors.New("sensor: no sensors available")
}
func disable(t Type) error {
return errors.New("sensor: no sensors available")
}
func destroy() error {
return nil
}