Added reportViolation()

This commit is contained in:
Leon Market 2023-06-20 20:59:18 +02:00
parent 8a5d720685
commit d33ab299ab
3 changed files with 5 additions and 2 deletions

View File

@ -47,6 +47,7 @@ public class Accelerometer extends Detector implements SensorEventListener {
private DetectionReport detectionReport; private DetectionReport detectionReport;
TextView textView; TextView textView;
//Queue for taking in values //Queue for taking in values
LinkedBlockingQueue<Float> linkedBlockingQueue = new LinkedBlockingQueue<>(); LinkedBlockingQueue<Float> linkedBlockingQueue = new LinkedBlockingQueue<>();
@ -94,6 +95,7 @@ public class Accelerometer extends Detector implements SensorEventListener {
if (betrag > threshold) { if (betrag > threshold) {
alarm = true; alarm = true;
detectionReport = new DetectionReport("Accelerometer1", "Bewegung", betrag); detectionReport = new DetectionReport("Accelerometer1", "Bewegung", betrag);
reportViolation("Accelo1", "Bewegung", betrag);
stringBuffer.append("\nDetectionReport = ").append(detectionReport).append("\nAlarm an"); stringBuffer.append("\nDetectionReport = ").append(detectionReport).append("\nAlarm an");
logger.clearLog(); logger.clearLog();
@ -124,6 +126,7 @@ public class Accelerometer extends Detector implements SensorEventListener {
@Override @Override
public void startDetection() { public void startDetection() {
// entspricht void start() // entspricht void start()
getSensor();
if (accelerometer != null) { if (accelerometer != null) {
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME); sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
logger.log("Sensor registriert"); logger.log("Sensor registriert");

View File

@ -21,7 +21,7 @@ abstract public class Detector {
/** Triggers onDetectionListener - call this to trigger violation/alarm */ /** Triggers onDetectionListener - call this to trigger violation/alarm */
private void reportViolation(String detectorID, String detectionType, float amplitude) { public void reportViolation(String detectorID, String detectionType, float amplitude) {
if (listener != null) { if (listener != null) {
DetectionReport detectionReport = new DetectionReport(detectorID, detectionType, amplitude); DetectionReport detectionReport = new DetectionReport(detectorID, detectionType, amplitude);
listener.onDetection(detectionReport); listener.onDetection(detectionReport);

View File

@ -41,7 +41,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//Accelerometer Setup //Accelerometer Setup
beschleunigungssensor = new Accelerometer(this, logger, textViewLog); //logger and textview only for debugging necessary beschleunigungssensor = new Accelerometer(this, logger, textViewLog); //logger and textview only for debugging necessary
beschleunigungssensor.getSensor(); //beschleunigungssensor.getSensor();
logger.log("onCreate"); logger.log("onCreate");
} }