示例#1
0
func enable(s Sender, t Type, delay time.Duration) error {
	channels.Lock()
	defer channels.Unlock()

	if channels.done[t] != nil {
		return fmt.Errorf("sensor: cannot enable; %v sensor is already enabled", t)
	}
	channels.done[t] = make(chan struct{})

	if delay < minDelay {
		delay = minDelay
	}
	interval := C.float(float64(delay) / float64(time.Second))

	switch t {
	case Accelerometer:
		C.GoIOS_startAccelerometer(interval)
	case Gyroscope:
		C.GoIOS_startGyro(interval)
	case Magnetometer:
		C.GoIOS_startMagneto(interval)
	}
	go pollSensor(s, t, delay, channels.done[t])
	return nil
}
示例#2
0
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.
	mu.Lock()
	mu.Unlock()

	switch t {
	case Accelerometer:
		if doneA != nil {
			return fmt.Errorf("sensor: cannot enable; %v sensor is already enabled", t)
		}
		// TODO(jbd): Check if acceloremeter is available.
		C.GoIOS_startAccelerometer(m.m)
		m.startAccelometer(s, delay)
		doneA = make(chan struct{})
	case Gyroscope:
	case Magnetometer:
	default:
		return fmt.Errorf("sensor: unknown sensor type: %v", t)
	}
	return nil
}
示例#3
0
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()

	switch t {
	case Accelerometer:
		if channels.acceleroDone != nil {
			return fmt.Errorf("sensor: cannot enable; %v sensor is already enabled", t)
		}
		// TODO(jbd): Check if accelerometer is available.
		interval := float64(delay) / float64(time.Second)
		C.GoIOS_startAccelerometer(C.float(interval))
		channels.acceleroDone = make(chan struct{})
		go m.runAccelerometer(s, delay, channels.acceleroDone)
	case Gyroscope:
	case Magnetometer:
	default:
		return fmt.Errorf("sensor: unknown sensor type: %v", t)
	}
	return nil
}