darwin_armx.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. //go:build darwin && (arm || arm64)
  5. // +build darwin
  6. // +build arm arm64
  7. #import <CoreMotion/CoreMotion.h>
  8. CMMotionManager* manager = nil;
  9. void GoIOS_createManager() {
  10. manager = [[CMMotionManager alloc] init];
  11. }
  12. void GoIOS_startAccelerometer(float interval) {
  13. manager.accelerometerUpdateInterval = interval;
  14. [manager startAccelerometerUpdates];
  15. }
  16. void GoIOS_stopAccelerometer() {
  17. [manager stopAccelerometerUpdates];
  18. }
  19. void GoIOS_readAccelerometer(int64_t* timestamp, float* v) {
  20. CMAccelerometerData* data = manager.accelerometerData;
  21. *timestamp = (int64_t)(data.timestamp * 1000 * 1000);
  22. v[0] = data.acceleration.x;
  23. v[1] = data.acceleration.y;
  24. v[2] = data.acceleration.z;
  25. }
  26. void GoIOS_startGyro(float interval) {
  27. manager.gyroUpdateInterval = interval;
  28. [manager startGyroUpdates];
  29. }
  30. void GoIOS_stopGyro() {
  31. [manager stopGyroUpdates];
  32. }
  33. void GoIOS_readGyro(int64_t* timestamp, float* v) {
  34. CMGyroData* data = manager.gyroData;
  35. *timestamp = (int64_t)(data.timestamp * 1000 * 1000);
  36. v[0] = data.rotationRate.x;
  37. v[1] = data.rotationRate.y;
  38. v[2] = data.rotationRate.z;
  39. }
  40. void GoIOS_startMagneto(float interval) {
  41. manager.magnetometerUpdateInterval = interval;
  42. [manager startMagnetometerUpdates];
  43. }
  44. void GoIOS_stopMagneto() {
  45. [manager stopMagnetometerUpdates];
  46. }
  47. void GoIOS_readMagneto(int64_t* timestamp, float* v) {
  48. CMMagnetometerData* data = manager.magnetometerData;
  49. *timestamp = (int64_t)(data.timestamp * 1000 * 1000);
  50. v[0] = data.magneticField.x;
  51. v[1] = data.magneticField.y;
  52. v[2] = data.magneticField.z;
  53. }
  54. void GoIOS_destroyManager() {
  55. [manager release];
  56. manager = nil;
  57. }