This lesson is part of the Perspective Components and Bindings course. You can browse the rest of the lessons below.

LESSON LIST

Autoplay Off

LESSON

Accelerometer Data Received

Description

Learn how to handle and use accelerometer data from a mobile device using the Ignition Perspective App.

Video recorded using: Ignition 8.0

Transcript

(open in window)

[00:00] When using the Ignition Perspective App you have the ability to grab data from the mobile device's various systems such as the accelerometer. While the accelerometer on your phone is typically always on, you have to enable Ignition to pull in that data. To do this you can use an Accelerometer action. I have a button here with an onClick event which has an accelerometer action configured on it. Now there are three modes to the accelerometer action. Continuous mode and Off mode go hand in hand. When you run an accelerometer action at continuous mode it will pull in accelerometer data at the sample rate and will continue to do so until a similar accelerometer action in Off mode stops it. Batch works a little bit differently in that it runs at the sample rate pulling in accelerometer data every however often you specify and it will only last for the duration that you set up here in the action.

[01:16] So in this example my action is going to sample accelerometer data every 100 milliseconds and it's going to do that for 200 milliseconds so I'm going to get two different readings. Now where this data is made available depends on the mode that the action is in. For batch mode, the accelerometer data is actually passed into a Session Event script, I'm gonna go up into my Project menu, select the Session Events option and go down to the Accelerometer Data Received event. Here in the script we can parse out the data object to get at the list of accelerometer data. In continuous mode the accelerometer data will continuously be captured at the sample rate by session properties that are set up to capture them.

[02:08] You will notice in the session props we have a device property and then an accelerometer property which contains X, Y and Z properties as well as a timestamp. If we go back to my view and I take a look at my button we can see that it's in Continuous mode which means the data is going to continuously feed into those session props. This is why on my view I have three different Label components. Each Label has an Expression Binding on its text property that is looking at one of the appropriate accelerometer properties X Y or Z. I have an emulated mobile device where we can test this out. You'll notice that my Y value starts out with 9.81. And that's because my accelerometer is being pulled down in that direction by the force of gravity.

[03:04] If I go into my menu here I can actually change what rotation my device is at. Now I still haven't clicked my button yet so you'll notice that if I move my device to the side my accelerometer data has changed but it doesn't update on the Perspective application. This is because I haven't told Perspective to start grabbing that data just yet. Once I click on my button to start grabbing accelerometer data. It's going to pull in those new records into my X and Y values. You'll notice that these values change as I move my device around.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.