Sony SmartEyeglass read Accelerometer

67 Views Asked by At

I am trying to get a float array of the accelerometer values of the SmartEyeglass. I want to have a float-Array in my ControlExtension that is automatically updated if the accelerometer changes.

The official documentation hasn't been a lot of help. What do I have to do?

So far I realized I need to include this attribute:

eprivate final AccessorySensorEventListener listener =
        new AccessorySensorEventListener() {
    // Respond to change by updating the screen to
    // display the current sensor data
    @Override
    public void onSensorEvent(final AccessorySensorEvent sensorEvent) {
        Log.d(Constants.LOG_TAG, "Listener: OnSensorEvent");
        float[] data = sensorEvent.getSensorValues();
        doStuff(data);
    }
};

But this just won't doStuff(data) and I have no idea what will be inside of the data-Array.

1

There are 1 best solutions below

0
On BEST ANSWER

Adding this to the constructor resolves the problem:

// Create a sensor manager object
AccessorySensorManager manager =
        new AccessorySensorManager(context, hostAppPackageName);

AccessorySensor acc = manager.getSensor(Registration.SensorTypeValue.ACCELEROMETER);
try {
    acc.registerFixedRateListener(listener, Sensor.SensorRates.SENSOR_DELAY_FASTEST);
} catch (AccessorySensorException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}