Question

I'm stuck upon this problem writing code for an application in Java, that is connected with external device Uc which takes samples from multiple channels of ADC and sends them back to app for proccessing and graphing. My problem is, that I don't know how to sort and store data of samples corresponing to each sampled channel for later processing, since I can not graph all data coming let's say from 3 different channels at once. Any suggestions would greatly appreciated!

Was it helpful?

Solution

1) Create a global int variable(say int eventTimer) and create a timer that'll have its own thread which increases this eventTimer on each timer tick. Set the timer's period according to sampling rate.

2) create a map for each channel to store "reading time and read value" like:

Map<int, float> readingsFromChannel1 = new HashMap<int, float>();

and whenever you receive a new reading from that channel, append it into its map like:

float value; // the value that you just get from channel 1
readingsFromChannel1.put(eventTimer, value);

3) in your drawing function of the graph:

// drawing of channel1 data:
iterator it = readingsFromChannel1.iterator();
while(it.next())
{
  Map.Entry m =(Map.Entry)it.next();
  int key=(Integer)m.getKey();
  float value=(float)m.getValue();
  // I assume that you have a putpixel(x,y) method for drawing:
  putPixel(key - eventTimer, value);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top