Accelerometer / Gyro

Any chance we’ll see support for the accelerometer and gyro in Xojo iOS?
Or could this be done with declares?

There’s a good tutorial with Xcode example here. Too bad I don’t speak ObjC.

[quote=153930:@Vincent Verweij]Any chance we’ll see support for the accelerometer and gyro in Xojo iOS?
Or could this be done with declares?

There’s a good tutorial with Xcode example here. Too bad I don’t speak ObjC.

[/quote]

Thank you for sharing that link.

At first glance, it looks possible to create declares to do the same thing.

From my feeble ability to decipher OC, Looks as the code is built around the UIAcceleration class https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAcceleration_Class/#//apple_ref/occ/instp/UIAcceleration/x

From what I read on the iOS Library reference, here are the properties to get :

Accessing the Acceleration Values
x
y
z
timestamp

Probably rather easy for a declare wizard.

UIAcceleration is deprecated since iOS5

you have to use CMMotionManager

I put together a couple of classes to wrap Core Motion two weeks ago or so. Here they are.

Does it works for you?
NSClassFromString(“CMMotionManager”) return nil

It is only available on a physical device.

Ah, ok
I will try on device.

Thanks Jason, awesome. But how do I call the acceleration and rotation parameters?
I would like to make something like this

Create a CMMotionManager object. Set the deviceMotionUpdateInterval. Then call the startDeviceMotionUpdates function. From there you poll the CMMotionManager deviceMotion property, and read the acceleration/rotation from the properties of the CMDeviceMotion object. When you are done, call the stopDeviceMotionUpdates function.

Thank you Jason.

I have no immediate need for this but will certainly experiment with it.

I just saw a couple days ago an interesting use Nokia/Microsoft came up with a new feature yet beta where a phone will automatically turn on the speaker when the phone is rested on a table, or end the communication when the same phone is placed face down on it. It is not a revolution, but it is certainly a much more original idea than counting steps…

I’m struggling with this, Jason. I’ve followed the steps, but it doesn’t work (tested on device).

In the View1 / Open event, I added this code:

[quote] Dim MotionManager as new CMMotionManager MotionManager.deviceMotionUpdateInterval = 0.1 MotionManager.startDeviceMotionUpdates [/quote]

I added a Timer, 3 global doubles and 3 labels.
In the Timer / Action event, I added this code:

[quote] [code] Dim DeviceMotion as new CMDeviceMotion

Xacceleration = DeviceMotion.acceleration.x
Yacceleration = DeviceMotion.acceleration.y
Zacceleration = DeviceMotion.acceleration.z

Label1.Text = Xacceleration.ToText
Label2.Text = Yacceleration.ToText
Label3.Text = Zacceleration.ToText[/code][/quote]

The readout is 0.0000 on all labels, nothing changes when I move the device. Any idea?