GLBasic forum

Main forum => GLBasic - en => Topic started by: ampos on 2010-Oct-07

Title: Compass in iPhone
Post by: ampos on 2010-Oct-07
Just an idea...

Can we get the iPhone compass value in "getjoyrz"?
Title: Re: Compass in iPhone
Post by: matchy on 2010-Oct-07
Quote from: ampos on 2010-Oct-07
Just an idea...

Can we get the iPhone compass value in "getjoyrz"?
:blink:
Great idea but not original and it's also in the iPad.
http://www.glbasic.com/forum/index.php?topic=4817.msg36591#msg36591
Why don't you have a go at creating a gyroscope wrapper? :zzz:
Title: Re: Compass in iPhone
Post by: ampos on 2010-Oct-07
No "C" knowledge?

Also, the compass could be interpreted as a RZ axis compared to a joy...
Title: Re: Compass in iPhone
Post by: matchy on 2010-Oct-07
Quote from: ampos on 2010-Oct-07
No "C" knowledge?
:rant:
Who else is going to do your homework? It's easy to learn how to create a wrapper. You don't need to know C or OBJC because there are many samples on the forum on how to implement one!
Title: Re: Compass in iPhone
Post by: ampos on 2010-Oct-07
I didnt know what a "wrapper" is...  :whistle:

If GLB has implemented iphone accelerometer as joy, there is no real reason not to implement it on GLB. If your attitude is this, we wouldnt have accelerometer at all, just a bunch of "wrappers" to read iphone acc.

Of course, if Kitty has time for it, or wants to implement it.

It was just an idea to implement in GLB. Currently I dont need compass on any of my projects  :booze:
Title: Re: Compass in iPhone
Post by: matchy on 2010-Oct-07
 :blink: Okay but did the link to the other thread help?
Title: Re: Compass in iPhone
Post by: ampos on 2010-Oct-07
Nop, the last post is like chinese to me.  :S
Title: Re: Compass in iPhone
Post by: ampos on 2010-Oct-07
Sorry, I mean that currently I dont need compass, thats why I will not learn (now) how to.

Thx anyway.
Title: Re: Compass in iPhone
Post by: Kitty Hello on 2010-Oct-11
I'll add the gyro to the GETJOYRX and such when I have my iPhone 4.
Title: Re: Compass in iPhone
Post by: AlienMenace on 2011-Apr-12
So, was this ever implemented?
Title: Re: Compass in iPhone
Post by: trucidare on 2011-Apr-12
Hm good question. Kitty?
Title: Re: Compass in iPhone
Post by: Kitty Hello on 2011-Apr-12
No, not yet. I'll put that on the todo as well...
Title: Re: Compass in iPhone
Post by: AlienMenace on 2011-Apr-13
Cool, that would be fun to play around with.

Thanks!
Title: Re: Compass in iPhone
Post by: Kitty Hello on 2011-Apr-15
The gyro information impacts the battery drain. I think it's better to release that addition as a library.


From the docs...
Code (glbasic) Select

    motionManager = [[CMMotionManager alloc] init];
    motionManager.gyroUpdateInterval = 1.0/60.0;
    if (motionManager.gyroAvailable) {
        opQ = [[NSOperationQueue currentQueue] retain];
        gyroHandler = ^ (CMGyroData *gyroData, NSError *error) {
            CMRotationRate rotate = gyroData.rotationRate;
            // handle rotation-rate data here......
        };
    } else {
        NSLog(@"No gyroscope on device.");
        toggleButton.enabled = NO;
        [motionManager release];
    }


Title: Re: Compass in iPhone
Post by: shawnus on 2011-Jun-10
Hi,

I'd really like to use the gyroscope via GLB, but dont understand what a library is. That code looks like C, does that go into xcode somewhere?

cheers, Shawnus
Title: Re: Compass in iPhone
Post by: Kitty Hello on 2011-Jun-20
put that in an external .mm file and include the proper headers. Then make a C function wrapper around it.

... can someone help here?
Title: Re: Compass in iPhone
Post by: matchy on 2011-Jun-20
 :whistle:

When I test on my iPad 1, there is no gyroscope on that device (but it does have a compass) so I haven't bothered to place parameters in the calls, but this prototype should work (output to NSLog only so the rotationRate will need to be move to gyro_read later).    :noggin:
gyro.h
Code (glbasic) Select

#import <CoreMotion/CoreMotion.h>
@interface gyro: NSObject {
CMMotionManager *motionManager;
NSOperation *opQ;
}
@end


gyro.mm
Code (glbasic) Select

#import "gyro.h"
@implementation gyro
#pragma mark -
#pragma mark Memory management
- (void)dealloc {
[motionManager dealloc];
[super dealloc];
}
#pragma mark -
#pragma mark GLB Gyro
- (void) _glb_gyro_init {
NSLog(@"Gyro init.");
motionManager = [[CMMotionManager alloc] init];
motionManager.gyroUpdateInterval = 1.0/60.0;
if (motionManager.gyroAvailable) {
NSLog(@"Gyroscope is on device.");
[motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
   withHandler: ^(CMGyroData *gyroData, NSError *error)
{
CMRotationRate rotate = gyroData.rotationRate;
NSLog(@"rotation rate = [%f %f %f]", rotate.x, rotate.y, rotate.z);
}];
} else {
NSLog(@"No gyroscope on device.");
[motionManager release];
}
}
- (void) _glb_gyro_read {
NSLog(@"Gyro read.");
}
extern "C" {
gyro *my_gyro;
void glb_gyro_init() {
my_gyro = [[gyro alloc] init];
[my_gyro _glb_gyro_init];
}
void glb_gyro_read() {
[my_gyro _glb_gyro_read];
}
}
@end


gyro.gbas
Code (glbasic) Select

// --------------------------------- //
// Project: Gyroscrope for iOS4 - prototype wrapper
// Start: Tuesday, June 21, 2011
// IDE Version: 9.104

// Wrapper install: In Xcode, drop the gyro.h & gyro.mm files in Classes folder and add CoreMotion.framework

TYPE _mouse
x
y
b1
b2
ENDTYPE

main_gyro()

FUNCTION main_gyro:
LOCAL mo AS _mouse

glb_gyro_init()
WHILE TRUE
MOUSESTATE mo.x, mo.y, mo.b1, mo.b2
IF mo.b1 = 1
glb_gyro_read() // test output in NSLog
PRINT "read: YES", 0, 20
ELSE
PRINT "read: NO", 0, 20
ENDIF
PRINT "Gyro", 0, 0
SHOWSCREEN
WEND
ENDFUNCTION

?IFDEF IPHONE
IMPORT "C" void glb_gyro_init()
IMPORT "C" void glb_gyro_read()
?ELSE
FUNCTION glb_gyro_init:
RETURN 0
ENDFUNCTION

FUNCTION glb_gyro_read:
RETURN 0
ENDFUNCTION
?ENDIF