Data Bufferingv1

parent c845551b
//buffering arrays to store data from sensors
ArrayList<Double> phArray = new ArrayList<Double>();
ArrayList<Double> tdsArray = new ArrayList<Double>();
ArrayList<Double> distanceArray = new ArrayList<Double>();
ArrayList<Double> turbidityArray = new ArrayList<Double>();
switch(value){
case "tds":
// imageView.setBackgroundColor(getResources().getColor(R.color.colorOff));
double tdsVal = Double.parseDouble(arrOfStr[1]);
tdsArray.add(tdsVal);
textViewInfo.setText("TDS : " + arrOfStr[1]);
break;
case "distance":
// imageView.setBackgroundColor(getResources().getColor(R.color.colorOff));
double disVal = Double.parseDouble(arrOfStr[1]);
distanceArray.add(disVal); //add to distance buffer
textViewInfo.setText("Distance : " + arrOfStr[1]);
break;
case "ph":
// imageView.setBackgroundColor(getResources().getColor(R.color.colorOff));
double phVal = Double.parseDouble(arrOfStr[1]);
phArray.add(phVal);
textViewInfo.setText("PH : " + arrOfStr[1]);
break;
case "turbidity":
// imageView.setBackgroundColor(getResources().getColor(R.color.colorOff));
double turbVal = Double.parseDouble(arrOfStr[1]);
turbidityArray.add(turbVal);
textViewInfo.setText("Turbidity : " + arrOfStr[1]);
break;
}
private Double getAvg(ArrayList<Double> valArray) {//calculate average value from buffers
double avg=0;
double total = 0;
for(int i = 0; i < valArray.size(); i++){
total += valArray.get(i);
}
avg = total/(valArray.size());
return avg;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment