|
|
@@ -11,6 +11,26 @@ import android.widget.TextView; |
|
|
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Accelerometer inherits some methods from abstract Detector class (more info there) |
|
|
|
* |
|
|
|
* |
|
|
|
* USE FROM MAIN ACTIVITY: |
|
|
|
* |
|
|
|
* Accelerometer beschleunigungssensor = new Accelerometer(this); |
|
|
|
* onCreate: |
|
|
|
* //Accelerometer Setup |
|
|
|
* beschleunigungssensor = new Accelerometer(this, logger, textViewLog); //logger and textview only for debugging necessary |
|
|
|
* beschleunigungssensor.getSensor(); |
|
|
|
* |
|
|
|
* //Starting Detection: |
|
|
|
* beschleunigungssensor.startDetection(); |
|
|
|
* //Stopping Detection: also recommended at onPause to avoid unnecessary battery consumption |
|
|
|
* beschleunigungssensor.stopDetection(); |
|
|
|
* |
|
|
|
* */ |
|
|
|
|
|
|
|
public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
|
|
|
|
Logger logger; |
|
|
@@ -25,18 +45,18 @@ public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
float z; |
|
|
|
float betrag; //Betrag aller drei Achsen sqrt(x*x + y*y + z*z) |
|
|
|
private DetectionReport detectionReport; |
|
|
|
TextView textViewLog; |
|
|
|
TextView textView; |
|
|
|
|
|
|
|
//Queue for taking in values |
|
|
|
LinkedBlockingQueue<Float> linkedBlockingQueue = new LinkedBlockingQueue<>(); |
|
|
|
|
|
|
|
|
|
|
|
// In constructor pass Activity, Context and TextView from MainActivity in Accelerometer class |
|
|
|
public Accelerometer(Context context, Logger mainLogger, TextView textViewLog){ |
|
|
|
public Accelerometer(Context context, Logger mainLogger, TextView textView){ |
|
|
|
super(context); //von Detektor |
|
|
|
logger = mainLogger; |
|
|
|
this.context = context; |
|
|
|
this.textViewLog = textViewLog; |
|
|
|
this.textView = this.textView; |
|
|
|
//Logger logger = new Logger(this.getClass().getSimpleName(), textViewLog, ""); |
|
|
|
} |
|
|
|
|
|
|
@@ -52,22 +72,6 @@ public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// void start wird überflüssig mit void startDetection() |
|
|
|
//void start() { |
|
|
|
// // register the sensor before using // |
|
|
|
// sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); |
|
|
|
// logger.log("Accelerometer, registered"); |
|
|
|
//} |
|
|
|
|
|
|
|
// void stop wird überflüssig mit void stopDetection() |
|
|
|
//void stop() { |
|
|
|
// // unregister from the sensor to stop using it // |
|
|
|
// sensorManager.unregisterListener(this, accelerometer); |
|
|
|
// logger.log("Accelerometer unregistered!"); |
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSensorChanged(SensorEvent event) { |
|
|
|
try { |
|
|
@@ -78,6 +82,7 @@ public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
} |
|
|
|
|
|
|
|
StringBuffer stringBuffer = new StringBuffer(); |
|
|
|
|
|
|
|
public void checkAlarm (SensorEvent event) throws InterruptedException { |
|
|
|
x = event.values[0]; |
|
|
|
y = event.values[1]; |
|
|
@@ -89,8 +94,8 @@ public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
if (betrag > threshold) { |
|
|
|
alarm = true; |
|
|
|
detectionReport = new DetectionReport("Accelerometer1", "Bewegung", betrag); |
|
|
|
stringBuffer.append("\nDetectionReport = ").append(detectionReport).append("\nAlarm an").append(betrag).append(event.timestamp); |
|
|
|
linkedBlockingQueue.put(betrag); |
|
|
|
|
|
|
|
stringBuffer.append("\nDetectionReport = ").append(detectionReport).append("\nAlarm an"); |
|
|
|
logger.clearLog(); |
|
|
|
logger.log(stringBuffer.toString()); |
|
|
|
stringBuffer.delete(0, stringBuffer.length()); |