Skip to content

Sensors

Iristick smart glasses feature additional sensors: accelerometer, gyroscope, and magnetometer. The Iristick.G1 also features a fusion algorithm to provide the absolute orientation of the glasses with respect to the earth surface and the magnetic North. Such algorithm is not yet available on the Iristick.G2 and Iristick.H1.

Example code

The Sensors Readout Example provided in the SDK package provides a minimal example on how to use the Sensors API. It reads out the values of all sensors and show them on the main phone display.

In order to get data from one of these sensors, you have to implement and register a SensorEventListener. A listener is registered with a given rate at which you want to receive data. The desired rate is expressed as an interval in microseconds. The actual rate may be faster or slower.

@Override
public void onHeadsetConnected(@NonNull Headset headset) {
    /* Listen to the accelerometer with a desired refresh rate of twice
     * per second. */
    Sensor gravitySensor = headset.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    gravitySensor.registerListener(new SensorEventListener() {
        @Override
        public void onSensorChanged(@NonNull SensorEvent event) {
            /* Do something with data in event.values. */
        }
    }, 500000);
}

When you no longer need the sensor data, you can unregister your listener with a call to unregisterListener(). Alternatively, you can unregister a listener from all sensors with unregisterSensorListener().