Change-Id: I24fbde8ec50be43000b9fcf3e7801f1ad25238cb Reviewed-on: https://go-review.googlesource.com/c/mobile/+/374498 Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com> Trust: Hajime Hoshi <hajimehoshi@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
72 lines
1.8 KiB
Objective-C
72 lines
1.8 KiB
Objective-C
// 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.
|
|
|
|
//go:build darwin && (arm || arm64)
|
|
// +build darwin
|
|
// +build arm arm64
|
|
|
|
#import <CoreMotion/CoreMotion.h>
|
|
|
|
CMMotionManager* manager = nil;
|
|
|
|
void GoIOS_createManager() {
|
|
manager = [[CMMotionManager alloc] init];
|
|
}
|
|
|
|
void GoIOS_startAccelerometer(float interval) {
|
|
manager.accelerometerUpdateInterval = interval;
|
|
[manager startAccelerometerUpdates];
|
|
}
|
|
|
|
void GoIOS_stopAccelerometer() {
|
|
[manager stopAccelerometerUpdates];
|
|
}
|
|
|
|
void GoIOS_readAccelerometer(int64_t* timestamp, float* v) {
|
|
CMAccelerometerData* data = manager.accelerometerData;
|
|
*timestamp = (int64_t)(data.timestamp * 1000 * 1000);
|
|
v[0] = data.acceleration.x;
|
|
v[1] = data.acceleration.y;
|
|
v[2] = data.acceleration.z;
|
|
}
|
|
|
|
void GoIOS_startGyro(float interval) {
|
|
manager.gyroUpdateInterval = interval;
|
|
[manager startGyroUpdates];
|
|
}
|
|
|
|
void GoIOS_stopGyro() {
|
|
[manager stopGyroUpdates];
|
|
}
|
|
|
|
void GoIOS_readGyro(int64_t* timestamp, float* v) {
|
|
CMGyroData* data = manager.gyroData;
|
|
*timestamp = (int64_t)(data.timestamp * 1000 * 1000);
|
|
v[0] = data.rotationRate.x;
|
|
v[1] = data.rotationRate.y;
|
|
v[2] = data.rotationRate.z;
|
|
}
|
|
|
|
void GoIOS_startMagneto(float interval) {
|
|
manager.magnetometerUpdateInterval = interval;
|
|
[manager startMagnetometerUpdates];
|
|
}
|
|
|
|
void GoIOS_stopMagneto() {
|
|
[manager stopMagnetometerUpdates];
|
|
}
|
|
|
|
void GoIOS_readMagneto(int64_t* timestamp, float* v) {
|
|
CMMagnetometerData* data = manager.magnetometerData;
|
|
*timestamp = (int64_t)(data.timestamp * 1000 * 1000);
|
|
v[0] = data.magneticField.x;
|
|
v[1] = data.magneticField.y;
|
|
v[2] = data.magneticField.z;
|
|
}
|
|
|
|
void GoIOS_destroyManager() {
|
|
[manager release];
|
|
manager = nil;
|
|
}
|