Debian Codegraph @

exp/sensor/darwin_armx.m

raw
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build darwin && (arm || arm64)
6 // +build darwin
7 // +build arm arm64
8
9 #import <CoreMotion/CoreMotion.h>
10
11 CMMotionManager* manager = nil;
12
13 void GoIOS_createManager() {
14 manager = [[CMMotionManager alloc] init];
15 }
16
17 void GoIOS_startAccelerometer(float interval) {
18 manager.accelerometerUpdateInterval = interval;
19 [manager startAccelerometerUpdates];
20 }
21
22 void GoIOS_stopAccelerometer() {
23 [manager stopAccelerometerUpdates];
24 }
25
26 void GoIOS_readAccelerometer(int64_t* timestamp, float* v) {
27 CMAccelerometerData* data = manager.accelerometerData;
28 *timestamp = (int64_t)(data.timestamp * 1000 * 1000);
29 v[0] = data.acceleration.x;
30 v[1] = data.acceleration.y;
31 v[2] = data.acceleration.z;
32 }
33
34 void GoIOS_startGyro(float interval) {
35 manager.gyroUpdateInterval = interval;
36 [manager startGyroUpdates];
37 }
38
39 void GoIOS_stopGyro() {
40 [manager stopGyroUpdates];
41 }
42
43 void GoIOS_readGyro(int64_t* timestamp, float* v) {
44 CMGyroData* data = manager.gyroData;
45 *timestamp = (int64_t)(data.timestamp * 1000 * 1000);
46 v[0] = data.rotationRate.x;
47 v[1] = data.rotationRate.y;
48 v[2] = data.rotationRate.z;
49 }
50
51 void GoIOS_startMagneto(float interval) {
52 manager.magnetometerUpdateInterval = interval;
53 [manager startMagnetometerUpdates];
54 }
55
56 void GoIOS_stopMagneto() {
57 [manager stopMagnetometerUpdates];
58 }
59
60 void GoIOS_readMagneto(int64_t* timestamp, float* v) {
61 CMMagnetometerData* data = manager.magnetometerData;
62 *timestamp = (int64_t)(data.timestamp * 1000 * 1000);
63 v[0] = data.magneticField.x;
64 v[1] = data.magneticField.y;
65 v[2] = data.magneticField.z;
66 }
67
68 void GoIOS_destroyManager() {
69 [manager release];
70 manager = nil;
71 }