2
0
mirror of synced 2025-02-23 23:08:14 +00:00

4 Commits

Author SHA1 Message Date
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
Burcu Dogan
c76d5c8830 exp/sensor: remove the manager type
The manager type is not required, because the APIs don't allow
more than one event sources as they used to. In this CL, I am
flattening out the underlying implementations by removing the
manager type.

Change-Id: I3b606ac160b9cecd85cb657e3df1d7d789604764
Reviewed-on: https://go-review.googlesource.com/14293
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 16:23:41 +00:00
Burcu Dogan
9ddeada810 exp/sensor: provide sensor events from the app event channel
We are also limiting the number of sensor managers to one.
The application provide sensor events to third-party packages
by consuming them in the main.

An application will be able to consume the sensor events similar
to the other events.

package main

func main() {
  app.Main(func(a app.App) {
    // enables the accelerometer
    sensor.Enable(a, sensor.Accelerometer, 100*time.Millisecond)

    var sz size.Event
    for e := range a.Events() {
      switch e := app.Filter(e).(type) {
      case sensor.Event:
        log.Println(e)
      }
    }
  })
}

Change-Id: Iaad1c59f8d2322c7620df62ed9b9283c91746fa8
Reviewed-on: https://go-review.googlesource.com/13983
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-01 04:44:55 +00:00
Burcu Dogan
b5583e233e exp/sensor: reorg package to create space for darwin/arm,arm64 impl
Change-Id: I41e4088a92fff2f411dd82102fc3c421d2679c21
Reviewed-on: https://go-review.googlesource.com/13582
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-12 22:18:05 +00:00