|
|
@@ -14,32 +14,27 @@ import androidx.appcompat.app.AppCompatActivity; |
|
|
|
public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
|
|
|
|
Logger logger; |
|
|
|
|
|
|
|
private volatile boolean running = false; |
|
|
|
public SensorManager sensorManager; |
|
|
|
private static final int sensorType = Sensor.TYPE_LINEAR_ACCELERATION; |
|
|
|
private Sensor accelerometer; |
|
|
|
private Context context; |
|
|
|
|
|
|
|
private String threadName = "Accelerometer Thread"; |
|
|
|
boolean alarm = false; |
|
|
|
//Preallocate memory for the data of each axis of the acceleration sensor |
|
|
|
float x; |
|
|
|
float y; |
|
|
|
float z; |
|
|
|
float betrag; //Betrag aller drei Achsen sqrt(x*x + y*y + z*z) |
|
|
|
private TextView textViewWorkerThread; |
|
|
|
private AppCompatActivity activity; |
|
|
|
private DetectionReport detectionReport; |
|
|
|
TextView textViewLog; |
|
|
|
|
|
|
|
|
|
|
|
// In constructor pass Activity, Context and TextView from MainActivity in Accelerometer class |
|
|
|
public Accelerometer(Context context, Logger mainLogger, TextView textViewWorkerThread){ |
|
|
|
public Accelerometer(Context context, Logger mainLogger, TextView textViewLog){ |
|
|
|
super(context); //von Detektor |
|
|
|
logger = mainLogger; |
|
|
|
this.context = context; |
|
|
|
this.textViewWorkerThread = textViewWorkerThread; |
|
|
|
Logger logger = new Logger(this.getClass().getSimpleName(), textViewWorkerThread, ""); |
|
|
|
this.textViewLog = textViewLog; |
|
|
|
//Logger logger = new Logger(this.getClass().getSimpleName(), textViewLog, ""); |
|
|
|
} |
|
|
|
|
|
|
|
public void getSensor(){ |
|
|
@@ -57,7 +52,7 @@ public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
|
|
|
|
void start() { |
|
|
|
// register the sensor before using // |
|
|
|
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME); |
|
|
|
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); |
|
|
|
logger.log("Accelerometer, start!"); |
|
|
|
} |
|
|
|
|
|
|
@@ -81,8 +76,6 @@ public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
z = event.values[2]; |
|
|
|
betrag = (float) sqrt(x*x + y*y + z*z); |
|
|
|
double schwelle = 1.5; |
|
|
|
//stringBuffer.append("\nBetrag =" + betrag); |
|
|
|
//logger.log("Betrag" + betrag); |
|
|
|
|
|
|
|
if (!alarm) { |
|
|
|
if (betrag > schwelle) { |
|
|
@@ -111,7 +104,7 @@ public class Accelerometer extends Detector implements SensorEventListener { |
|
|
|
logger.log("Betragswert immer noch über Schwellwert: " + betrag + "; Alarm bleibt an."); |
|
|
|
logger.log("Betragswert immer noch über Schwellwert: " + betrag + "; Alarm bleibt an."); |
|
|
|
} |
|
|
|
logger.clearLog(); |
|
|
|
//logger.clearLog(); |
|
|
|
logger.log(stringBuffer.toString()); |
|
|
|
stringBuffer.delete(0, stringBuffer.length()); |
|
|
|
} |