DeveloperDeveloper
  • Standard Solutions
  • Cam Solutions
  • Native SDKs
  • App Gallery
  • Game Engine Plugins
Forum
Projects Library
Dev Discord
  • Standard Solutions
  • Cam Solutions
  • Native SDKs
  • App Gallery
  • Game Engine Plugins
Forum
Projects Library
Dev Discord
  • App Gallery (with Lovense Remote)
    • Get Started
    • Development
    • Deploy
  • Basic API
    • Life Cycle
  • Platform API
    • App Info
      • AppBaseInfo
    • Toy
      • Toy Info
      • Command
      • Feedback Mode
    • Device
      • Accelerometer
      • Screen Orientation
      • Shake
      • Vibrate
    • File System
      • Save Image
  • Open API
    • User Authorization
      • Client API
      • Server API
  • Error Code
  • getCurrentAccelerometer
  • startAccelerometerListener
  • stopAccelerometerListener
Got Stuck?
Forum for Lovense Developers
Support
Document Feedback

Accelerometer

getCurrentAccelerometer

  • Description

    Get the current accelerometer data.

  • Parameters

    AttributeTypeDefaultRequiredIntroduction
    successfunctionNoCallback function triggered when the API call successes
    failfunctionNoCallback function triggered when the API call fails

    Success callback function will receive an object with the following attributes:

    AttributeTypeIntroduction
    xstringx-axis acceleration
    ystringy-axis acceleration
    zstringz-axis acceleration
    timestampstringTimestamp 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

    AttributeTypeDefaultRequiredIntroduction
    intervalstringnormalNoListen the execution frequency of the accelerometer data callback function. Valid values are: game, ui, normal. When an invalid value is passed, normal is used
    successfunctionNoCallback function triggered when the accelerometer listener is successfully enabled
    failfunctionNoCallback function triggered when the API call fails

    The interval types are as follows:

    Valid ValueIntroduction
    gameApplicable for updating game callback frequency, around 20ms per update
    uiApplicable for updating UI callback frequency, around 60ms per update
    normalNormal callback frequency, around 200ms per update

    Success callback function will receive an object with the following attributes:

    AttributeTypeIntroduction
    xstringx-axis acceleration
    ystringy-axis acceleration
    zstringz-axis acceleration
    timestampstringTimestamp 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

    AttributeTypeDefaultRequiredIntroduction
    listenerIdstringNoAccelerometer 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()
    
Last Updated:
Next
Screen Orientation
Explore our Forum or Support to get more inspiration or solve your problems.
Discord Channel
It is an online real-time channel where you can communicate directly with our official administrators or many excellent developers.
Forum
It is a place for Lovense developers to communicate, where you can find solutions to problems or get inspired for your projects.
Support
Find documents and tutorials that may be helpful to you.