I'm trying to code a very basic lightmeter application for use with my old 35mm cameras using my Galaxy S2 as the sensor.
I should point out first of all that there is a hidden/test mode available on this phone selected by entering star hash zero star hash, on the dialller keypad then selecting 'sensor'. This makes available the light sensor which shows a range of Lux values varying between 5 and over 2000 in steps of 5 as I vary the light level.
The very simple proof of concept code I have written will only show me three values, namely 10, 100 and 1000 over the same range of lighting condtions. My code is:
public class LightMeterActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mLightSensor;
private float mLux = 0.0f;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
}
@Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mLightSensor,
SensorManager.SENSOR_DELAY_FASTEST);
}
@Override
protected void onPause() {
mSensorManager.unregisterListener(this);
super.onPause();
}
@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_LIGHT) {
mLux = event.values[0];
String luxStr = String.valueOf(mLux);
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(luxStr);
Log.d("LUXTAG", "Lux value: " + event.values[0] );
}
}
}
Can anybody suggest why this might be?
I have seen the question Light sensor on Nexus One returns only two distinct values which didn't help at all. I can't understand how the built in test mode can see the full range and my code can't.