I'am trying to read gyroscope values from HAL using the below apk. The apk is successfully enables the gyroscope sensor and reads and process events from kernel ,no crash in the adb-log but i'am not able to read any data even in the log or on the screen. For Accelerometer and magnetic field I got proper data.(on kitkat board) I would like to know why the data is missing.Why can't I read any x value if it is able go in reading events successfully?
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public class MySensorActivity extends Activity implements SensorEventListener {
private TextView tv;
private SensorManager mSensorManager;
private Sensor mLightSensor,mGyroSensor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv= (TextView)findViewById(R.id.txt2);
// Get an instance of the sensor service
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
mGyroSensor=mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
PackageManager PM= this.getPackageManager();
boolean gyro = PM.hasSystemFeature(PackageManager.FEATURE_SENSOR_GYROSCOPE);
boolean light = PM.hasSystemFeature(PackageManager.FEATURE_SENSOR_LIGHT);
if(gyro){
if(light){
Toast.makeText(getApplicationContext(),"Both light and gyroscope sensors are present", Toast.LENGTH_LONG).show();
}
else
Toast.makeText(getApplicationContext(),"Only gyroscope sensor is present", Toast.LENGTH_LONG).show();
}
}
@Override
public final void onAccuracyChanged(Sensor sensor, int accuracy) {
// Do something if sensor accuracy changes.
}
@Override
public final void onSensorChanged(SensorEvent event) {
//float lux = event.values[0];
float angularXSpeed = event.values[0];
tv.setText("Angular X speed level is: " + "" +angularXSpeed);
}
@Override
protected void onResume() {
// Register a listener for the sensor.
super.onResume();
mSensorManager.registerListener(this, mGyroSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause() {
// important to unregister the sensor when the activity pauses.
super.onPause();
mSensorManager.unregisterListener(this);
}
}