|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
|
|
import android.content.SharedPreferences; |
|
|
import android.hardware.Sensor; |
|
|
import android.hardware.Sensor; |
|
|
import android.hardware.SensorEvent; |
|
|
import android.hardware.SensorEvent; |
|
|
import android.hardware.SensorEventListener; |
|
|
import android.hardware.SensorEventListener; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SensorManager bsmanager; |
|
|
private SensorManager bsmanager; |
|
|
private ArrayList<Float> Gesamt_be; |
|
|
private ArrayList<Float> Gesamt_be; |
|
|
private int sensorType = Sensor.TYPE_GYROSCOPE, zaehler_runde =0, listen_groesse = 500, kalibrieren; |
|
|
|
|
|
|
|
|
private int sensorType = Sensor.TYPE_GYROSCOPE, zaehler_runde =0, listen_groesse = 500, kalibrieren, Offset_shared = 0, shared_merk, mittelwertsumme_shared; |
|
|
private Sensor sens, sensor_l; |
|
|
private Sensor sens, sensor_l; |
|
|
private float x_value = 0, y_value, z_value, Vorbesetzung = 0, gesamt_runde =0; |
|
|
private float x_value = 0, y_value, z_value, Vorbesetzung = 0, gesamt_runde =0; |
|
|
private double Schwellwert = 0.15, mittelwertsumme = 0.0, Offset = 0.1; |
|
|
private double Schwellwert = 0.15, mittelwertsumme = 0.0, Offset = 0.1; |
|
|
String Daten, Warnung, Zeitstempel; |
|
|
|
|
|
|
|
|
String Daten, Warnung, Zeitstempel, Array_shared; |
|
|
|
|
|
private final static String KEY_kalibirieren = "KEY_KALIBRIEREN_"+Beschleunigungssensor.class.getSimpleName(); |
|
|
|
|
|
private final static String KEY_Gesamt_be = "KEY_GESAMT_BE_"+Beschleunigungssensor.class.getSimpleName(); |
|
|
|
|
|
private final static String KEY_Offset = "KEY_OFFSET_"+Beschleunigungssensor.class.getSimpleName(); |
|
|
|
|
|
private final static String KEY_Mittelwertsumme = "KEY_MITTELWERTSUMME_"+Beschleunigungssensor.class.getSimpleName(); |
|
|
TextView Daten_Bsensor, Warnung_Bsensor, test; |
|
|
TextView Daten_Bsensor, Warnung_Bsensor, test; |
|
|
private boolean toggle = true, ts_setzen = true, start_messen; |
|
|
private boolean toggle = true, ts_setzen = true, start_messen; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
super.onCreate(savedInstanceState); |
|
|
super.onCreate(savedInstanceState); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//mittelwertsumme ist kein int in diesem programm |
|
|
//mittelwertsumme ist kein int in diesem programm |
|
|
|
|
|
//shared prefenrences: bei Kippen speichern -> nochmal neu klalibrieren? -> eig ja, weil neuer Standort |
|
|
|
|
|
//Vorbelegung nicht nochmal neu vornehmen -> aus onCreate Funktion raus -> hilfsvariablen auch in shared preferences speichern |
|
|
@Override |
|
|
@Override |
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {} |
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Daten = "Das anmelden hat nicht geklappt"; |
|
|
Daten = "Das anmelden hat nicht geklappt"; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE); |
|
|
|
|
|
//mittelwertsumme_shared = p.getInt(KEY_Mittelwertsumme, 0); |
|
|
|
|
|
//kalibrieren = p.getInt(KEY_kalibirieren, 0); |
|
|
|
|
|
//Offset_shared = p.getInt(KEY_Offset, 0 ); |
|
|
|
|
|
//Array_shared = p.getString(KEY_Gesamt_be, ""); |
|
|
|
|
|
|
|
|
|
|
|
//mittelwertsumme = (double) mittelwertsumme_shared; |
|
|
|
|
|
//mittelwertsumme /= 1000000.0; |
|
|
|
|
|
|
|
|
|
|
|
//Offset = (double) Offset_shared; |
|
|
|
|
|
//Offset /= 1000000.0; |
|
|
|
|
|
|
|
|
|
|
|
//String zw[] = Array_shared.split(";", listen_groesse); |
|
|
|
|
|
|
|
|
|
|
|
//if(shared_merk == 2){ |
|
|
|
|
|
//for (int i=0; i<listen_groesse; i++){ |
|
|
|
|
|
//float wert = Float.valueOf(zw[i]); |
|
|
|
|
|
//Gesamt_be.add(i, wert); |
|
|
|
|
|
//}} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void onPause() { |
|
|
|
|
|
super.onPause(); |
|
|
|
|
|
if (sens != null) { |
|
|
|
|
|
bsmanager.unregisterListener(this, sens); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void onPause () { |
|
|
|
|
|
super.onPause(); |
|
|
|
|
|
if (sens != null) { |
|
|
|
|
|
bsmanager.unregisterListener(this, sens); |
|
|
|
|
|
} |
|
|
|
|
|
//shared_merk = 2; |
|
|
|
|
|
// Offset_shared = (int) (Offset * 1000000.0); |
|
|
|
|
|
//mittelwertsumme_shared = (int) (mittelwertsumme * 1000000.0); |
|
|
|
|
|
|
|
|
|
|
|
//StringBuilder ar = new StringBuilder(); |
|
|
|
|
|
//for (int z=0; z < listen_groesse; z++){ |
|
|
|
|
|
//ar.append(Gesamt_be.get(z)).append(";"); |
|
|
|
|
|
//} |
|
|
|
|
|
//Array_shared = ar.toString(); |
|
|
|
|
|
|
|
|
|
|
|
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE); |
|
|
|
|
|
//SharedPreferences.Editor editor = p.edit(); |
|
|
|
|
|
//editor.putInt(KEY_Mittelwertsumme, mittelwertsumme_shared); |
|
|
|
|
|
//editor.putInt(KEY_kalibirieren, kalibrieren); |
|
|
|
|
|
//editor.putInt(KEY_Offset, Offset_shared); |
|
|
|
|
|
//editor.putString(KEY_Gesamt_be, Array_shared); |
|
|
|
|
|
//editor.commit(); |
|
|
|
|
|
} |
|
|
|
|
|
} |