示例#1
0
func (m *manager) runAccelerometer(s Sender, d time.Duration, done chan struct{}) {
	var timestamp C.int64_t
	var ev [3]C.float
	var lastTimestamp int64
	for {
		select {
		case <-done:
			return
		default:
			C.GoIOS_readAccelerometer((*C.int64_t)(unsafe.Pointer(&timestamp)), (*C.float)(unsafe.Pointer(&ev[0])))
			t := int64(timestamp)
			if t > lastTimestamp {
				// TODO(jbd): Do we need to convert the values to another unit?
				// How does iOS units compare to the Android units.
				s.Send(Event{
					Sensor:    Accelerometer,
					Timestamp: t,
					Data:      []float64{float64(ev[0]), float64(ev[1]), float64(ev[2])},
				})
				lastTimestamp = t
				time.Sleep(d / 2)
			}
		}
	}
}
示例#2
0
func (m *manager) startAccelometer(app sender, d time.Duration) {
	go func() {
		ev := make([]C.float, 4)
		var lastTimestamp int64
		for {
			select {
			case <-doneA:
				return
			default:
				C.GoIOS_readAccelerometer(m.m, (*C.float)(unsafe.Pointer(&ev[0])))
				t := int64(ev[0] * 1000 * 1000)
				if t > lastTimestamp {
					// TODO(jbd): Do we need to convert the values to another unit?
					// How does iOS units compate to the Android units.
					app.Send(Event{
						Sensor:    Accelerometer,
						Timestamp: t,
						Data:      []float64{float64(ev[1]), float64(ev[2]), float64(ev[3])},
					})
					lastTimestamp = t
					<-time.Tick(d)
				} else {
					<-time.Tick(d / 2)
				}
			}
		}
	}()
}
示例#3
0
func pollSensor(s Sender, t Type, d time.Duration, done chan struct{}) {
	var lastTimestamp int64

	var timestamp C.int64_t
	var ev [3]C.float

	for {
		select {
		case <-done:
			return
		default:
			tp := (*C.int64_t)(unsafe.Pointer(&timestamp))
			vp := (*C.float)(unsafe.Pointer(&ev[0]))

			switch t {
			case Accelerometer:
				C.GoIOS_readAccelerometer(tp, vp)
			case Gyroscope:
				C.GoIOS_readGyro(tp, vp)
			case Magnetometer:
				C.GoIOS_readMagneto(tp, vp)
			}
			ts := int64(timestamp)
			if ts > lastTimestamp {
				// TODO(jbd): Do we need to convert the values to another unit?
				// How does iOS units compare to the Android units.
				s.Send(Event{
					Sensor:    t,
					Timestamp: ts,
					Data:      []float64{float64(ev[0]), float64(ev[1]), float64(ev[2])},
				})
				lastTimestamp = ts
				time.Sleep(d / 2)
			}
		}
	}
}