Got Stuck?
Forum for Lovense Developers
Support
Document Feedback
Accelerometer
getCurrentAccelerometer
Description
Get the current accelerometer data.
Parameters
Attribute Type Default Required Introduction success function No Callback function triggered when the API call successes fail function No Callback function triggered when the API call fails Success callback function will receive an object with the following attributes:
Attribute Type Introduction x string x-axis acceleration y string y-axis acceleration z string z-axis acceleration timestamp string Timestamp when the data was obtained Example
const deviceManager = appGallery.getDeviceManager(); // Get the current accelerometer data deviceManager.getCurrentAccelerometer({ success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, });
startAccelerometerListener
Description
Start accelerometer listener.
Parameters
Attribute Type Default Required Introduction interval string normal No Listen the execution frequency of the accelerometer data callback function. Valid values are: game, ui, normal. When an invalid value is passed, normal is used success function No Callback function triggered when the accelerometer listener is successfully enabled fail function No Callback function triggered when the API call fails The interval types are as follows:
Valid Value Introduction game Applicable for updating game callback frequency, around 20ms per update ui Applicable for updating UI callback frequency, around 60ms per update normal Normal callback frequency, around 200ms per update Success callback function will receive an object with the following attributes:
Attribute Type Introduction x string x-axis acceleration y string y-axis acceleration z string z-axis acceleration timestamp string Timestamp when the data was obtained Return
Accelerometer listener ID
Example
const deviceManager = appGallery.getDeviceManager() // Start accelerometer listener const listenerId = deviceManager.startAccelerometerListener({ interval: "ui", success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, })
stopAccelerometerListener
Description
Stop specified or all accelerometer listeners.
Parameters
Attribute Type Default Required Introduction listenerId string No Accelerometer listener ID. If listenerId or object parameter is not passed, all accelerometer listeners will be stopped Example
const deviceManager = appGallery.getDeviceManager() // Method 1 : // Start accelerometer listener and record the corresponding listenerId const listenerId = deviceManager.startAccelerometerListener({ interval: "game", success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, }) // Stop the accelerometer listener with the corresponding listenerId deviceManager.stopAccelerometerListener({ listenerId: listenerId, }) // Method 2 : // Start accelerometer listener, default as normal deviceManager.startAccelerometerListener({ success(res) { console.log(res) }, fail(err) { console.error(err.code) console.error(err.msg) }, }) // Stop all accelerometer listeners deviceManager.stopAccelerometerListener()