|
|
@@ -1,4 +1,47 @@ |
|
|
|
package com.example.greenwatch; |
|
|
|
|
|
|
|
public class Beschleunigungssensor { |
|
|
|
import android.content.Context; |
|
|
|
import android.hardware.Sensor; |
|
|
|
import android.hardware.SensorEvent; |
|
|
|
import android.hardware.SensorEventListener; |
|
|
|
import android.hardware.SensorManager; |
|
|
|
import android.os.Bundle; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
public class Beschleunigungssensor extends AppCompatActivity implements SensorEventListener { |
|
|
|
|
|
|
|
private SensorManager bsmanager; |
|
|
|
private int sensorType = Sensor.TYPE_ACCELEROMETER; |
|
|
|
private Sensor Beschleunigungssensor; |
|
|
|
|
|
|
|
public Beschleunigungssensor() { |
|
|
|
bsmanager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); |
|
|
|
if(bsmanager.getSensorList(sensorType).size()==0) |
|
|
|
{ |
|
|
|
//logger.log("Es gibt den gewünschten Sensor |
|
|
|
//nicht"); |
|
|
|
Beschleunigungssensor = null; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Beschleunigungssensor = bsmanager.getSensorList(sensorType).get(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSensorChanged(SensorEvent event) { |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
sb.append("t=").append(event.timestamp) |
|
|
|
.append("\nx=").append(event.values[0]) |
|
|
|
.append("\ny=").append(event.values[1]) |
|
|
|
.append("\nz=").append(event.values[2]); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {} |
|
|
|
// if Abfrage ob values sich verändert haben |
|
|
|
} |