Skip to content

Commit

Permalink
ROTATION: Add ios code and rename variables to be consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
mgorges committed Apr 7, 2020
1 parent 7151ef1 commit d9d27a6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
16 changes: 16 additions & 0 deletions modules/rotation/IOS_launcherappdelegate_didfinishlaunching
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Gyroscope
if (motionmanager_needsinit) {
motionManager = [[CMMotionManager alloc] init];
motionmanager_needsinit = 0;
}

if ([motionManager isDeviceMotionAvailable]) {
[motionManager setDeviceMotionUpdateInterval: (1.0 / 50)];
[motionManager startDeviceMotionUpdatesToQueue: [NSOperationQueue mainQueue] withHandler: ^(CMDeviceMotion *motion, NSError *error) {
[[NSUserDefaults standardUserDefaults] setValue: [NSNumber numberWithDouble: motion.attitude.quaternion.x] forKey: @"quaternion_x"];
[[NSUserDefaults standardUserDefaults] setValue: [NSNumber numberWithDouble: motion.attitude.quaternion.y] forKey: @"quaternion_y"];
[[NSUserDefaults standardUserDefaults] setValue: [NSNumber numberWithDouble: motion.attitude.quaternion.z] forKey: @"quaternion_z"];
[[NSUserDefaults standardUserDefaults] setValue: [NSNumber numberWithDouble: motion.attitude.quaternion.w] forKey: @"quaternion_w"];
[[NSUserDefaults standardUserDefaults] synchronize];
}];
}
17 changes: 17 additions & 0 deletions modules/rotation/IOS_objc_additions
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// attitude quaternion
extern double ios_rot_getx() {
NSNumber* x = [[NSUserDefaults standardUserDefaults] valueForKey:@"quaternion_x"];
return [x doubleValue];
}
extern double ios_rot_gety() {
NSNumber* y = [[NSUserDefaults standardUserDefaults] valueForKey:@"quaternion_y"];
return [y doubleValue];
}
extern double ios_rot_getz() {
NSNumber* z = [[NSUserDefaults standardUserDefaults] valueForKey:@"quaternion_z"];
return [z doubleValue];
}
extern double ios_rot_getw() {
NSNumber* w = [[NSUserDefaults standardUserDefaults] valueForKey:@"quaternion_w"];
return [w doubleValue];
}
1 change: 1 addition & 0 deletions modules/rotation/IOS_xml_requireddevicecap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<string>gyroscope</string>
49 changes: 24 additions & 25 deletions modules/rotation/rotation.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#|
LambdaNative - a cross-platform Scheme framework
Copyright (c) 2009-2013, University of British Columbia
Copyright (c) 2009-2020, University of British Columbia
All rights reserved.

Redistribution and use in source and binary forms, with or
Expand Down Expand Up @@ -41,11 +41,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DArotE.
(c-declare #<<end-of-c-declare

#ifdef IOS
double ios_rot_getq1(void);
double ios_rot_getq2(void);
double ios_rot_getq3(void);
double ios_rot_getq4(void);
double ios_rot_getaccuracy(void);
double ios_rot_getx(void);
double ios_rot_gety(void);
double ios_rot_getz(void);
double ios_rot_getw(void);
#endif

#ifdef ANDROID
Expand All @@ -57,58 +56,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DArotE.
#endif


static double rot_q1(void) {
static double rotation_x(void) {
#ifdef IOS
return 0; //ios_rot_getq1();
return ios_rot_getx();
#elif ANDROID
return android_rot_getq1();
#else
return 0.;
#endif
}
static double rot_q2(void) {
static double rotation_y(void) {
#ifdef IOS
return 0; //ios_rot_getq2();
return ios_rot_gety();
#elif ANDROID
return android_rot_getq2();
#else
return 0.;
#endif
}
static double rot_q3(void) {
static double rotation_z(void) {
#ifdef IOS
return 0; //ios_rot_getq3();
return ios_rot_getz();
#elif ANDROID
return android_rot_getq3();
#else
return 0.;
#endif
}
static double rot_q4(void) {
}
static double rotation_w(void) {
#ifdef IOS
return 0; //ios_rot_getq4();
return ios_rot_getw();
#elif ANDROID
return android_rot_getq4();
#else
return 0.;
#endif
}
}
static double rot_accuracy(void) {
#ifdef IOS
return 0; //ios_rot_getaccuracy();
return -1;
#elif ANDROID
return android_rot_getaccuracy();
#else
return 0.;
#endif
}
return -1;
#endif
}
end-of-c-declare
)

(define rot-q1 (c-lambda () double "rot_q1")) ;;x*sin(θ/2)
(define rot-q2 (c-lambda () double "rot_q2")) ;;[1]: y*sin(θ/2)
(define rot-q3 (c-lambda () double "rot_q3")) ;;[2]: z*sin(θ/2)
(define rot-q4 (c-lambda () double "rot_q4")) ;;[3]: cos(θ/2)
(define rot-accuracy (c-lambda () double "rot_accuracy")) ;;[4]: estimated heading Accuracy (in radians) (-1 if unavailable)
(define rotation-x (c-lambda () double "rotation_x")) ;;x*sin(θ/2)
(define rotation-y (c-lambda () double "rotation_y")) ;;[1]: y*sin(θ/2)
(define rotation-z (c-lambda () double "rotation_z")) ;;[2]: z*sin(θ/2)
(define rotation-w (c-lambda () double "rotation_w")) ;;[3]: cos(θ/2)
(define rotation-accuracy (c-lambda () double "rot_accuracy")) ;;[4]: estimated heading Accuracy (in radians) (-1 if unavailable)

;; eof

0 comments on commit d9d27a6

Please sign in to comment.