LTR329 Light Sensor

The Ltr329AmbientLight class is an extension of the AmbientLight class that interacts specifically with the LTR329 chip, the light sensor on the MetaWear R Pro and MetaDetector boards.

Sensor Configuration

Sensor configuration is handled with a ConfigEditor. The sensor has three parameters to set: gain, integration time, and measurement rate. Gain controls the range and resolution of the illuminance value, integration time is the measurement time for each cycle, and measurement rate is how frequently to update the illuminance data.

import com.mbientlab.metawear.module.Ltr329AmbientLight;
import com.mbientlab.metawear.module.Ltr329AmbientLight.*;

Ltr329AmbientLight ltr329Module= mwBoard.getModule(Ltr329AmbientLight.class);
// Set the gain to 4x
// Set integration time to 150ms
// Set measurement rate to 100ms
ltr329Module.configure().setGain(Gain.LTR329_GAIN_4X)
    .setIntegrationTime(IntegrationTime.LTR329_TIME_150MS)
    .setMeasurementRate(MeasurementRate.LTR329_RATE_100MS)
    .commit();

Data Sampling

To start sampling illuminance data, call the start method, and conversely, the stop method to terminate data sampling. Sensor data is reported in units of milli lux, and should be interpretted as a long due to Java 7 not supporting unsigned types.

import com.mbientlab.metawear.module.Ltr329AmbientLight;

final Ltr329AmbientLight ltr329Module= mwBoard.getModule(Ltr329AmbientLight.class);
ltr329Module.routeData().fromSensor().stream("light_sub").commit()
    .onComplete(new CompletionHandler<RouteManager>() {
        @Override
        public void success(RouteManager result) {
            result.subscribe("light_sub", new RouteManager.MessageHandler() {
                @Override
                public void process(Message msg) {
                    Log.i("MainActivity", String.format("%dmlx",
                            msg.getData(Long.class)));
                }
            });
            ltr329Module.start();
        }
    });