0

I'm trying to get my game working on Android. I've ported it with the free version of Apportable and it works quite well, but I haven't been able to implement the gyroscope feature.

CMMotionManager gets initialized but the motion updates never start (or at least handleDeviceMotion: never gets called). The motion manager's isAccelerometerActive property is always NO, but isAccelerometerAvailable is YES.

Using [NSOperationQueue mainQueue] doesn't help either.

This is how I initialize the motion manager:

self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.gyroUpdateInterval = .2;

[self.motionManager startDeviceMotionUpdatesToQueue:[[NSOperationQueue alloc] init]
                                                withHandler:^(CMDeviceMotion *motion, NSError *error) {
                                                    dispatch_async(dispatch_get_main_queue(), ^{
                                                        [self handleDeviceMotion:motion];
                                                    });
                                                }];

It produces the following message to logcat:

E/Sensors (  507): HAL:ERR open file /sys/bus/iio/devices/iio:device0/dmp_event_int_on to write with error 2
E/Sensors (  507): HAL:ERR can't disable DMP event interrupt

I have no idea what this means... I'm testing the app on Asus Nexus 7.

Is there something special I need to do to use CoreMotion with Apportable?

Edit: Here's a simple test project I created to demonstrate the issue.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
  • The logcat has likely nothing to do with the CoreMotion problem. Are you able to simplify the CoreMotion initialization? – Paul Beusterien Feb 01 '14 at 00:16
  • @PaulBeusterien I'm not sure what you mean by _simplifying_ but I added some info about the problem. –  Feb 01 '14 at 09:19

2 Answers2

1

CoreMotion should work with apportable. Here is a simplified initialization and usage paradigm that I've tested on a Nexus 7 (2012).

self.motionManager = [[CMMotionManager alloc] init];
[self.motionManager startDeviceMotionUpdates];

self.motionTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 
    target:self 
    selector:@selector(handleDeviceMotion) 
    userInfo:nil 
    repeats:YES];

Instead of using startDeviceMotionUpdatesToQueue: withHandler: to process the motion events, try explicitly accessing the deviceMotion property in a handleDeviceMotion method which will be called by the repeating timer.

-(void) handleDeviceMotion {
    CMDeviceMotion *motion = [self.motionManager deviceMotion];
    // use motion data accordingly
}    

And don't forget to stop updates when you're done!

[self.motionManager stopDeviceMotionUpdates];
hifigi
  • 256
  • 1
  • 1
  • Sorry it took so long to get back to this. Just tested it on 3 Android devices and it's not working on any of them. I'm wondering if I should include CoreMotion in the "deps" section of Apportable configuration or not? Does it get included automatically if I add it to the linked frameworks in Xcode? –  Feb 13 '14 at 15:31
  • if you're using the SDK, it should get automatically picked up. it's unlikely it'd compile if it wasn't. what devices are you using, and can you create a reduced test case that demonstrates the issue you're having? – mike_haney Feb 21 '14 at 11:06
  • 1
    @iosdev Speaking of the Apportable configuration, you must make sure you have "accelerometer" listed in the FEATURES array in the configuration file. If it isn't listed you don't get access to the physical motion hardware itself. – hifigi Feb 21 '14 at 17:27
  • @mike_haney I'm testing the app on about 10 devices, including both tablets and phones (Samsung Galaxy S2 and Asus Nexus 7, for example). [Here's](https://www.dropbox.com/s/0imnlbwksjrg5rb/CoreMotionTest.zip) the full test project I created. –  Feb 22 '14 at 20:43
  • @hifigi I have it in there, and as UIAccelerometer is working, that should not be the problem... I guess. But I'm sure it's something simple, I just haven't noticed it yet :) –  Feb 22 '14 at 20:46
  • Hi! Sorry it's taken me so long, I've been quite busy here. I've finally gotten around to taking a look at your test project, and I'm confident I've discovered the problem: - (double)yaw { return 0.0; // TODO: FIXME } - (double)pitch { return 0.0; // TODO: FIXME } - (double)roll { return 0.0; // TODO: FIXME } I am going to look into implementing these, and I'll update later. – mike_haney Apr 02 '14 at 21:05
  • The problem here is because some Android devices do not support gyroscope and only accelerometer. Accelerometer has been deprecated on iOS and instead let us use Core Motion. I think we will just wait for an updated SDK where Core Motion will support Android devices without Gyroscope. – East Bay Ray May 05 '14 at 10:01
0

For this sort of device motion in particular, we had a fairly layered series of issues that I've (hopefully) resolved with the next SDK update. I've implemented yaw, pitch, and roll, and they seem to give relatively sane values. If you're still having issues, email sdk(@)apportable.com (delete the parens obviously) and mention me.

mike_haney
  • 545
  • 1
  • 8
  • 18