Android Application Programming: Populating a Two-Dimensional Array in a Stream

I am trying to calibrate an accelerometer, but I cannot get 6 sample values ​​at 6 different acceleration readings needed for calibration. Preliminary W is a double array [6] [3] designed to populate these sample values. This is 6 by 3 because every acceleration read has components x, y and z.

I plan to try them by pressing a button on 6 different acceleration readings. This button makes the "calibrate" true.

Of course, I will first do a β€œcalibration” of true to start this chain.

For some incomprehensible reason, the preliminary W [i] = currentAcc seems to populate from 0 to i with the same value, not just i. I made sure that currentAcc is different every time I click the calibrate button.

What is wrong with my code?

public synchronized void run() {
    Log.d(TAG, "+ in Calibrator thread +");

    int i = -1;
    while (calibrating) {
        if (calibrate) {
            i = i + 1;
            calibrate = false;
            preliminaryW[i] = currentAcc;
            if (i == 5) {
                calibrating = false;
            }
        }
    }
}
+4
source share
1 answer

I am not very familiar with the internal operations of the accelerometer, and it is difficult to decide why it does not work without seeing more code. For example, can you be sure that there is only one instance of Thread, or are you creating multiple instances?

Why should it be in stream?

, , , wait/notify, Thread. ( http://docs.oracle.com/javase/tutorial/essential/concurrency/guardmeth.html)

, , , . , executeCalibration() :

class Calibrator{
    int count = 0;
    double[][] preliminaryW = new double[6][3];

    public void performCalibration(double[] currentAcc){
        preliminaryW[count] = currentAcc;
        count++;
    }
}

"" "" "", , , .

!

0

All Articles