In my application I am reading an external value (int) from an EEG headset.
I thought that the value was read once a second but from my logcat report it seems that it is being read more than that.
This is disrupting my intentions as I want to calculate the average of the values. I am trying to do so using an increment operator called count.
Note that the values being read from the headset can only be from 1-100, so the output for average has to be incorrect as it is 168.
What am I doing wrong?
Current code:
Where value is being recorded:
case TGDevice.MSG_MEDITATION:
//BELOW CODE RELATES TO SAVING AN AVERAGE VALUE
meditationValues.add(msg.arg1);
count++;
for(int i = 0; i < meditationValues.size(); i++){
totalofMedLevels += meditationValues.get(i);
Log.d("Total", "Total : " + totalofMedLevels);
Log.d("Count ", "Count: " + count);
}
Calculating average:
public void getAverageValue(){
//stop device so that the values can be recorded
device.stop();
averageMedLevel=totalofMedLevels/count;
Log.d("Average level:", "Average: " + averageMedLevel);
}
Logcat Output:
For total:
07-14 14:16:44.312: D/Total(30422): Total : 301
07-14 14:16:45.313: D/Total(30422): Total : 301
07-14 14:16:45.313: D/Total(30422): Total : 301
07-14 14:16:45.313: D/Total(30422): Total : 301
07-14 14:16:45.323: D/Total(30422): Total : 301
07-14 14:16:45.323: D/Total(30422): Total : 301
07-14 14:16:45.323: D/Total(30422): Total : 301
07-14 14:16:45.323: D/Total(30422): Total : 342
07-14 14:16:45.323: D/Total(30422): Total : 406
07-14 14:16:45.323: D/Total(30422): Total : 456
07-14 14:16:45.323: D/Total(30422): Total : 496
07-14 14:16:46.314: D/Total(30422): Total : 496
07-14 14:16:46.314: D/Total(30422): Total : 496
07-14 14:16:46.314: D/Total(30422): Total : 496
07-14 14:16:46.314: D/Total(30422): Total : 496
07-14 14:16:46.314: D/Total(30422): Total : 496
07-14 14:16:46.314: D/Total(30422): Total : 496
07-14 14:16:46.324: D/Total(30422): Total : 537
07-14 14:16:46.324: D/Total(30422): Total : 601
07-14 14:16:46.324: D/Total(30422): Total : 651
07-14 14:16:46.324: D/Total(30422): Total : 691
07-14 14:16:46.324: D/Total(30422): Total : 725
07-14 14:16:47.285: D/Total(30422): Total : 725
07-14 14:16:47.285: D/Total(30422): Total : 725
07-14 14:16:47.285: D/Total(30422): Total : 725
07-14 14:16:47.285: D/Total(30422): Total : 725
07-14 14:16:47.285: D/Total(30422): Total : 725
For count:
07-14 14:16:47.285: D/Count(30422): Count: 12
07-14 14:16:47.285: D/Count(30422): Count: 12
07-14 14:16:47.285: D/Count(30422): Count: 12
07-14 14:16:47.285: D/Count(30422): Count: 12
07-14 14:16:47.285: D/Count(30422): Count: 12
07-14 14:16:47.295: D/Count(30422): Count: 12
07-14 14:16:47.295: D/Count(30422): Count: 12
07-14 14:16:47.295: D/Count(30422): Count: 12
07-14 14:16:47.295: D/Count(30422): Count: 12
07-14 14:16:47.295: D/Count(30422): Count: 12
07-14 14:16:47.295: D/Count(30422): Count: 12
07-14 14:16:48.286: D/Count(30422): Count: 13
07-14 14:16:48.286: D/Count(30422): Count: 13
07-14 14:16:48.286: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
07-14 14:16:48.296: D/Count(30422): Count: 13
For average:
07-14 14:16:53.281: D/Average level:(30422): Average: 168
EDIT (TRYING TO ONLY SAVE A VALUE IF IT IS ABOVE 0):
if((msg.arg1)!=0){
meditationValues.add(msg.arg1);
}
for(int i = 0; i < meditationValues.size(); i++){
//totalofMedLevels += meditationValues.get(i);
totalofMedLevels+=msg.arg1;
count++;
Log.d("Total", "Total : " + totalofMedLevels);
Log.d("Count ", "Count: " + count);
}