Just an idea...
Can we get the iPhone compass value in "getjoyrz"?
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:
No "C" knowledge?
Also, the compass could be interpreted as a RZ axis compared to a joy...
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!
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:
:blink: Okay but did the link to the other thread help?
Nop, the last post is like chinese to me. :S
Sorry, I mean that currently I dont need compass, thats why I will not learn (now) how to.
Thx anyway.
I'll add the gyro to the GETJOYRX and such when I have my iPhone 4.
So, was this ever implemented?
Hm good question. Kitty?
No, not yet. I'll put that on the todo as well...
Cool, that would be fun to play around with.
Thanks!
The gyro information impacts the battery drain. I think it's better to release that addition as a library.
From the docs...
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];
}
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
put that in an external .mm file and include the proper headers. Then make a C function wrapper around it.
... can someone help here?
: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
#import <CoreMotion/CoreMotion.h>
@interface gyro: NSObject {
CMMotionManager *motionManager;
NSOperation *opQ;
}
@end
gyro.mm
#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
// --------------------------------- //
// 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