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