Reading sensor values directly without having to use/wait for onSensorChanged

by bmcc » Sun, 04 Oct 2009 22:44:18 GMT


Sponsored Links
 Gentlemen,

Up until now I have been using SensorEventListener.onSensorChanged
(SensorEvent evt) to obtain data values from the on board sensors (G1)
whenever a sensor event occurs (snippet below). However, what I really
want to be able to do is read the values of all the sensors (i.e.
Sensor.TYPE_ORIENTATION, Sensor.TYPE_ACCELEROMETER and
Sensor.TYPE_MAGNETIC_FIELD) together at the same instant in time, or
near enough as the system will allow.

I'm probably being thick but does anyone know whether there a way of
reading the sensor values directly without having to use/wait for
onSensorChanged() ?

Many thanks in advance,
B.

----------

Snippet - currently using onSensorChanged(SensorEvent evt):

SensorManager sman = (SensorManager) getSystemService
(Context.SENSOR_SERVICE);
                List<Sensor> accelerometer = sman.getSensorList
(Sensor.TYPE_ACCELEROMETER);
                Sensor myAccelerometer = accelelerometer.get(0);

                sman.registerListener(new SensorEventListener() {

                        public void onAccuracyChanged(Sensor arg0, int
arg1) {

                        }

                        public void onSensorChanged(SensorEvent evt) {

                                // read new sensor values
                                accelTextView.setText("X-accel: " +
evt.values[0] + "\n" + "Y-
accel: "
                                                + evt.values[1] + "\n"
+ "Z-accel: " + evt.values[2]);
                                accelTextView.invalidate();

                                // sleep for a bit
                               try {
                                        Thread.sleep(10);
                                } catch (Exception ex) {
                                        accelTextView.setText("Erk!");
                                }
                        }

                }, myAccelerometer, SensorManager.SENSOR_DELAY_UI);
--~--~---------~--~----~------------~-------~--~----~



Reading sensor values directly without having to use/wait for onSensorChanged

by bmcc » Sun, 04 Oct 2009 23:12:23 GMT


 Thanks for the swift reply Mark.

Hmmm that's a shame, i suppose I could listen for a sensorChanged
event on the accelerometer, then for each other sensor in turn - and
log the time delay between each event. Unsatisfactory as I'd really
like to get the data every nth of a second to do some signal
processing/filtering but that would rely on having a known
frequency... ho hum :(

BTW I was playing with Android Scripting Environment and there is a
python example called sensors.py:


import android
droid = android.Android()
droid.startSensing()
.
.
sensors = droid.readSensors()
print sensors

I wonder what's going on "under the hood" there...?

Thanks again,
B



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Reflection / backward compatibility question

Hi all. The examples at...

http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html

...show some good ideas of testing methods against incompatible
versions.

But the method I want to call is DisplayMetrics.densityDpi(); (since
level 4) which returns an int value. None of these examples return any
values, they're all void.

How would I do this?

Thanks.

-- 

2. Wrong Position when using Big Images

Hallo,

i just stumpled over this:

In want to place an Image on the Bottom of the Screen, so i used an
RelativeLayout placed an ImageView in it:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
 android:layout_width="wrap_content"
android:layout_height="wrap_content" >

 <ImageView android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true" android:src="@drawable/hand"
android:layout_gravity="bottom"/>
</RelativeLayout>

My Emulator ist API Version 8, with Screen Dimension 480x800. The
Image in the HDPI Folder was 652x652 in 240DPI. If i run it with this
Image (hand) i always get the Image Scaled but it shows up much more
over the Bottom as i would expect. The Image has NO transparent Border
that may would cause this.

When i scale the Image down to apx. width of the Screen (480x480) i
get a result i would expect.

Anybody can explain why Android Layout like this ?

PS: I did not put any other Images of that in the folders "mdpi" or
"ldpi" as alternatives !

best regards,
Jens




-- 

3. Ringtone playing just once.

4. Pinch Zoom on Image

5. Customizing a RelativeLayout

6. SQLite Implementation

7. HTC Evo Brand New feat HTC HD 2 and HTC touch Pro