Browse Source

Improved Microfon and Accelerometer detection in Project

Benutzeroberflaeche_Permission
Christian Tinz 1 year ago
parent
commit
cb425cce56

+ 3
- 0
app/src/main/java/com/example/greenwatch/AudiodetectionActivity.java View File

@@ -106,6 +106,9 @@ public class AudiodetectionActivity extends AppCompatActivity {
@Override
protected void onPause() {
super.onPause();
if (isFinishing()){
mMicrofonViewModel.recalibrationMicrofonSensor();
}
mMicrofonViewModel.stopMicrofonSensor();
}
}

+ 11
- 3
app/src/main/java/com/example/greenwatch/AudiodetectionAndAccelerometerActivity.java View File

@@ -92,14 +92,19 @@ public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity im
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if (mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedTrue", Toast.LENGTH_LONG).show();
if (mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && !mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected()) {
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
}
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected()) {
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Microfon", (int) mAudiodetectionAndAccelerometerViewModel.getAmplitudeInDB());
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && !mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Audio", (int) mAudiodetectionAndAccelerometerViewModel.getAmplitudeInDB());
}
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "2AudioAndAccelerometer", 10);
}
}
else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedFalse", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0);
}

@@ -153,6 +158,9 @@ public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity im
@Override
protected void onPause() {
super.onPause();
if (isFinishing()){
mAudiodetectionAndAccelerometerViewModel.recalibrationMicrofonSensor();
}
mAudiodetectionAndAccelerometerViewModel.stopMicrofonSensor();
if (accelerometerSensor != null) {
accelerometerManager.unregisterListener(this, accelerometerSensor);

+ 2
- 3
app/src/main/java/com/example/greenwatch/sensors/MicrofonSensor.java View File

@@ -19,7 +19,7 @@ import com.example.greenwatch.sensors.MicrofonHelperClasses.Verarbeitungsergebni
private boolean microfonAlarmDetected = false;
private boolean kalibrierung_do = true;
private float threshold = 40;
private float sensitivity = 5;
private float sensitivity = 10;

private float amplitudeInDB = 0;

@@ -52,9 +52,8 @@ import com.example.greenwatch.sensors.MicrofonHelperClasses.Verarbeitungsergebni
microfonAlarmDetected = false;
kalibrierung_do = true;
threshold = 40;
sensitivity = 5;
sensitivity = 10;
amplitudeInDB = 0;
start();
}

public float getAmplitudeInDB() {

+ 2
- 2
app/src/main/java/com/example/greenwatch/viewmodels/AudiodetectionAndAccelerometerViewModel.java View File

@@ -120,12 +120,12 @@ public class AudiodetectionAndAccelerometerViewModel extends ViewModel implement
public void onChanged(Boolean aBoolean) {
setAccelerometerAlarmDetected(mAccelerometerAlarmDetected.getValue());
setMicrofonAlarmDetected(mMicrofonAlarmDetected.getValue());
if (microfonAlarmDetected || accelerometerAlarmDetected && !microfondetectionAndAccelerometerAlarmDetected) {
if (microfonAlarmDetected || accelerometerAlarmDetected) {
microfondetectionAndAccelerometerAlarmDetected = true;
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();

}
else if (!microfonAlarmDetected && !accelerometerAlarmDetected && microfondetectionAndAccelerometerAlarmDetected) {
else if (!microfonAlarmDetected && !accelerometerAlarmDetected) {
microfondetectionAndAccelerometerAlarmDetected = false;
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();
}

Loading…
Cancel
Save