I am trying to encode a very basic indicator light application for use with my old 35mm cameras using Galaxy S2 as a sensor.
First of all, I have to indicate that this phone has a hidden / test mode, selected by entering a star hash symbol with a zero star , on the dialller keyboard, then selecting the “sensor”. This makes the light sensor available, which displays a range of Lux values varying from 5 to 2000 in increments of 5 when the light level changes.
The simplest proof of concept code that I wrote will show only three values, namely 10, 100 and 1000 in the same light range. 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 anyone guess why this might be?
I saw the question The light sensor on the Nexus One returns only two different values, which did not help at all. I can’t understand how the built-in test mode can see the full range, but my code cannot.
Nickt
source share