API: Detect Accelerometer Motion

Trigger actions based on a change in the tilt or angle of the iPad indicating motion of the device.

Requirements

Kiosk Pro Plus and Enterprise

  • Integration of our JavaScript API into your webpage
    • Sample code to run within the app and download for integration into your own project is available here.
    • Best practices for working with the JavaScript API are available here.
  • App Settings
    • Content > JavaScript API > Access JavaScript API = By Import
    • Device Access > Accelerometer Motion > Motion Detection Reset Period - must be configured, will affect the length of the motion session


Triggers via API Functions

Start Listening for Accelerometer Motion

This function triggers the app to start listening for changes in one of three possible tilts (roll, yaw, pitch) of the tablet.

Format
kp_AccelerometerAPI_startListenToEvents(callback);
		
Parameters
  • callback - [optional, string] the name of the callback to be triggered after the function has been executed
Callback format
callback(isListening, previouslyListening);
		
Callback return values
  • isListening - [boolean integer] representing whether the app is currently listening for motion:
    • 1 = the app is listening and ready to trigger automatic callbacks based on device motion
    • 0 = the app is not listening
  • previouslyListening - [boolean integer] representing whether the app was listening for motion prior to this call:
    • 1 = the app was listening previously
    • 0 = the app was not listening previously


Stop Listening for Accelerometer Motion

This function triggers the app to stop listening for changes in one of three possible tilts (roll, yaw, pitch) of the tablet.

Format
kp_AccelerometerAPI_stopListenToEvents(callback);
		
Parameters
  • callback - [optional, string] the name of the callback to be triggered after the function has been executed
Callback format
callback(isListening, previouslyListening);
		
Callback return values
  • isListening - [boolean integer] representing whether the app is currently listening for changes in one of three possible tilts (roll, yaw, pitch):
    • 1 = the app is listening and ready to trigger automatic callbacks based on device motion
    • 0 = the app is not listening
  • previouslyListening - [boolean integer] representing whether the app was listening for motion prior to this call:
    • 1 = the app was listening previously
    • 0 = the app was not listening previously


Check Current State

This function checks whether the app is currently listening for motion and whether a motion detection session is currently active.

Format
kp_AccelerometerAPI_getState(callback);
		
Parameters
  • callback - [optional, string] the name of the callback to be triggered after the function has been executed
Callback format
callback(isListening, sessionInProgress, secondsToSessionReset);
		
Callback return values
  • isListening - [boolean integer] representing whether the app is currently listening for changes in one of three possible tilts (roll, yaw, pitch):
    • 1 = the app is listening and ready to trigger automatic callbacks based on device motion
    • 0 = the app is not listening
  • sessionInProgress - [boolean integer] representing whether there is currently an active motion detection session:
    • 1 = motion detection session is currently ongoing
    • 0 = no motion detection session is currently ongoing
  • secondsToSessionReset - [string] the number of seconds before the current motion detection session ends (unless new motion is detected)


Notifications via API Callbacks

New Motion Detected

Triggers when new motion is detected. A motion detection session is started and will end if no continued motion is detected.

Format
kp_AccelerometerAPI_didDetectStartMotion();
		


Continued Motion Detection

Triggers when a motion detection session is currently in progress and motion is detected.

Format
kp_AccelerometerAPI_didDetectContinueMotion();
		


Motion Stopped

Triggers when a motion detection session is active and motion is not detected for the period defined by the Motion Detection Reset Period setting.

Format
kp_AccelerometerAPI_didDetectStopMotion();
		


Sample Code

  • This sample code relies on the JavaScript APIs built into Kiosk Pro and will not run successfully in other browsers or within our in-app help interface.
  • To run sample code, set the app's homepage to kioskgroup.com/accelerometer-api
  • To download a .zip of sample code, click here.

Change Log

  • Added in version 10.1

Still stuck? How can we help? How can we help?