Browse Source

Removed calibration code and added method checkAlarm

lm
Leon Market 1 year ago
parent
commit
402b73e4bd

+ 1
- 89
app/src/main/java/com/example/ueberwachungssystem/Beschleunigungssensor.java View File

} }
} }
} }
int i = 0;
boolean stopp_mal = false;


@Override @Override
public void onSensorChanged(SensorEvent event) public void onSensorChanged(SensorEvent event)
{ {
checkAlarm(event); checkAlarm(event);

//Alter Code, erstmal wild mit if statement ausgeschlossen
if (stopp_mal) {
if (i<numberOfValues) {
calibrationMatrix[0][i] = event.values[0];
calibrationMatrix[1][i] = event.values[1];
calibrationMatrix[2][i] = event.values[2];
i++;
}

double sumX = 0;
double sumY = 0;
double sumZ = 0;
for (int j = 0; j<numberOfValues;j++){
sumX += calibrationMatrix[0][j];
sumY += calibrationMatrix[1][j];
sumZ += calibrationMatrix[2][j];
}

double averageX = sumX/numberOfValues;
double averageY = sumY/numberOfValues;
double averageZ = sumZ/numberOfValues;

String sb2 = "t=" + event.timestamp +
"\nx=" + event.values[0] + // Wert liegend: x = 0.04
"\ny=" + event.values[1] + // Wert liegend: y = 0.44
"\nz=" + event.values[2] + // Wert liegend: z = 9.90 = Erdbeschleunigung
"\nlin_x=" + linear_acceleration[0] +
"\nlin_x=" + linear_acceleration[1] +
"\nlin_x=" + linear_acceleration[2] +
"\naverageX=" + averageX +
"\naverageY=" + averageY +
"\naverageZ=" + averageZ +
"\ni=" + i;

double schwelle = 5.0;

if (alarm = false) {
if (averageX + schwelle < event.values[0]) {
alarm = true;
}
}
if (alarm = false) {
if (averageY + schwelle < event.values[1]) {
alarm = true;
}
}
if (alarm = false) {
if (averageZ + schwelle < event.values[2]) {
alarm = true;
}
}
if (alarm = true) {
if (averageX + schwelle > event.values[0]) {
alarm = false;
}
if (averageY + schwelle > event.values[1]) {
alarm = false;
}
if (averageZ + schwelle > event.values[2]) {
alarm = false;
}
}


logger.clearLog();
logger.log(sb2);
}

} }


@Override @Override
public void onAccuracyChanged(Sensor sensor, int accuracy) public void onAccuracyChanged(Sensor sensor, int accuracy)
{ {
} }
}

//Sample code for deque usage. Might be not useful.
class MovingAverage {
int size, windowSum = 0, count = 0;
Deque queue = new ArrayDeque<Integer>();
public MovingAverage(int size) {
this.size = size;
}
public double next(int val) {
++count;
// calculate the new sum by shifting the window
queue.add(val);
int tail = count > size ? (int)queue.poll() : 0;
windowSum = windowSum - tail + val;
return windowSum * 1.0 / Math.min(size, count);
}
}
}

Loading…
Cancel
Save