|
|
@@ -3,6 +3,8 @@ package com.example.greenwatch; |
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
import android.content.Context; |
|
|
|
import android.content.SharedPreferences; |
|
|
|
import android.hardware.Sensor; |
|
|
|
import android.hardware.SensorEvent; |
|
|
|
import android.hardware.SensorEventListener; |
|
|
@@ -18,14 +20,19 @@ public class Beschleunigungssensor extends AppCompatActivity implements SensorEv |
|
|
|
|
|
|
|
private SensorManager bsmanager; |
|
|
|
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 float x_value = 0, y_value, z_value, Vorbesetzung = 0, gesamt_runde =0; |
|
|
|
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; |
|
|
|
private boolean toggle = true, ts_setzen = true, start_messen; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
@@ -116,6 +123,8 @@ public class Beschleunigungssensor extends AppCompatActivity implements SensorEv |
|
|
|
} |
|
|
|
} |
|
|
|
//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 |
|
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {} |
|
|
|
|
|
|
@@ -129,13 +138,51 @@ public class Beschleunigungssensor extends AppCompatActivity implements SensorEv |
|
|
|
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(); |
|
|
|
} |
|
|
|
} |