Data flow stops after a few number of points

Supporting 4.1 and up
J. Sousa
Fresh meat
Posts: 2
Joined: Tue Aug 18, 2015 10:14 am
Contact:

Data flow stops after a few number of points

Postby J. Sousa » Tue Aug 18, 2015 10:55 am

Hi there,

I'm developing an application for Android with the objective of creating a vibrations analyzer using an external accelerometer. I've been creating real time graphics, Fourier transforms and so on to produce a sound vibrations analyzer on android using Phidgets MEMS, specifically the 1041_0, on a mobile phone running android 4.0.

The thing is I can't collect more than 40 points reliably where i should be collecting 2048, for example. If I impose to gather only 30 points things go well but more than that the application loses momentum and stops gathering around 40 points. Bellow is the code in which it collect points:

Code: Select all

try {
            com.phidgets.usb.Manager.Initialize(getApplicationContext());
            spatial = new SpatialPhidget();
            spatial.addAttachListener(new AttachListener() {
                @Override
                public void attached(AttachEvent attachEvent) {
                    try {
                        spatial.setDataRate((int)DR);
                    } catch (PhidgetException e) {
                        e.printStackTrace();
                        System.out.println("ERRO second activity addAttachListener");
                    }
                }
            });
            spatial.addDetachListener(new DetachListener() {
                @Override
                public void detached(DetachEvent detachEvent) {
                    //qq coisa
                }
            });
            spatial.addSpatialDataListener(new SpatialDataListener() {
                public void data(SpatialDataEvent sde) {
                    runOnUiThread(new SpatialDataRunnable(
                            sde.getData()[0].getAcceleration()[0],
                            sde.getData()[0].getAcceleration()[1],
                            sde.getData()[0].getAcceleration()[2]));
                }
            });
            spatial.openAny();
        }catch (PhidgetException e) {
            e.printStackTrace();
        }


and then

Code: Select all

double ax, ay, az,data;
        public SpatialDataRunnable(double ax, double ay, double az) {
            this.ax = (double)Math.round(ax*1000)/1000;
            this.ay = (double)Math.round(ay*1000)/1000;
            this.az = (double)Math.round(az*1000)/1000;         
        }
        public void run() {
            [u]dataArray[dataIndex] = (float)data;
            dataIndex +=1;
            System.out.println("dataIndex: " +  dataIndex); [/u]         
        }


I've been trying many options but the this problem is persistent and is keeping the app. from being finalized

Thanks in Advance,
J. Sousa

User avatar
Patrick
Lead Developer
Posts: 3067
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Data flow stops after a few number of points

Postby Patrick » Tue Aug 18, 2015 1:36 pm

I suspect that your callback code runs too slowly. Try simply appending the data directly to a global queue (FIFO of 2048 elements) from the spatial data callback, and then in your main thread context, you can operate on this queue directly as needed (with synchronization).

-Patrick

J. Sousa
Fresh meat
Posts: 2
Joined: Tue Aug 18, 2015 10:14 am
Contact:

Re: Data flow stops after a few number of points

Postby J. Sousa » Thu Aug 20, 2015 8:49 am

Patrick wrote:I suspect that your callback code runs too slowly. Try simply appending the data directly to a global queue (FIFO of 2048 elements) from the spatial data callback, and then in your main thread context, you can operate on this queue directly as needed (with synchronization).

-Patrick


Hi there Patrick

Thank you for the quick reply.
However the same code running by itself ( same code as this activity, that runs upon click, but as the main now) runs perfectly.

I'm going to give your advice a try. Thanks again

J. Sousa


Return to “Android”

Who is online

Users browsing this forum: No registered users and 1 guest