0

I'm working on an Android project where the subject is to develop an android application to gather data from an external sensor (phidgets) and then generate a graphic representation using graphview or similar. The question i would like to expose is how to save the real time data to the DataPoint[] structure. I've tried with while and for methods using number of points or time.

 DataPoint[] data_ax = new DataPoint[number of points];
 data_ax[i] = new DataPoint(i,onDataEvent.getData()[0].getAcceleration()[0]);

or with a for cycle

DataPoint[] data_ax = new DataPoint[number of points];
for (int i = 0;i<30;i++){
   data_ax[i] = new DataPoint(i,onDataEvent.getData()[0].getAcceleration()[0]);
}

while cycle

long t= System.currentTimeMillis();
long end = t+15000;//15*1000 seconds
while(System.currentTimeMillis() < end) {
    String[] data_az = new String[];
    int x=0;
    data_az[x]= onDataEvent.getData()[0].getAcceleration()[0]);
    x=x+1;
}

I can't seem to find the correct way to do it. Thank you for your answers.

T.Gounelle
  • 5,953
  • 1
  • 22
  • 32
bobyzano
  • 1
  • 1
  • When do you want to store 1 `DataPoint`? is it for each event `onDataEvent`? right now, I would say that the _for cycle_ (as you call it) will store 30 times the same thing, and the _while cycle_ just cannot compile. – T.Gounelle Apr 21 '15 at 09:52
  • @AbbéRésina I would like to "store" the different values of onDataEvent(from a phidget sensor), as they change, within a specific number of points/values (acceleration on z axes per example), and then pass them to DataPoint to finally be able to create a line graph – bobyzano Apr 21 '15 at 14:00
  • I'm not a phidget expert, but as a matter of logic/design, I would define a global array with a fixed size (as you did), and a counter that shall be incremented and where you apply a [modulo](http://en.wiktionary.org/wiki/modulo) with array size, in order to cycle through the array, when adding a new _data point_. This rotating array can be defined in a specific class. – T.Gounelle Apr 21 '15 at 15:50

0 Answers0