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

@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
if (isFinishing()){
mMicrofonViewModel.recalibrationMicrofonSensor();
}
mMicrofonViewModel.stopMicrofonSensor(); mMicrofonViewModel.stopMicrofonSensor();
} }
} }

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

@Override @Override
public void onChanged(Boolean aBoolean) { public void onChanged(Boolean aBoolean) {
if (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); 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 { else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedFalse", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0); mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0);
} }


@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
if (isFinishing()){
mAudiodetectionAndAccelerometerViewModel.recalibrationMicrofonSensor();
}
mAudiodetectionAndAccelerometerViewModel.stopMicrofonSensor(); mAudiodetectionAndAccelerometerViewModel.stopMicrofonSensor();
if (accelerometerSensor != null) { if (accelerometerSensor != null) {
accelerometerManager.unregisterListener(this, accelerometerSensor); accelerometerManager.unregisterListener(this, accelerometerSensor);

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

private boolean microfonAlarmDetected = false; private boolean microfonAlarmDetected = false;
private boolean kalibrierung_do = true; private boolean kalibrierung_do = true;
private float threshold = 40; private float threshold = 40;
private float sensitivity = 5;
private float sensitivity = 10;


private float amplitudeInDB = 0; private float amplitudeInDB = 0;


microfonAlarmDetected = false; microfonAlarmDetected = false;
kalibrierung_do = true; kalibrierung_do = true;
threshold = 40; threshold = 40;
sensitivity = 5;
sensitivity = 10;
amplitudeInDB = 0; amplitudeInDB = 0;
start();
} }


public float getAmplitudeInDB() { public float getAmplitudeInDB() {

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

public void onChanged(Boolean aBoolean) { public void onChanged(Boolean aBoolean) {
setAccelerometerAlarmDetected(mAccelerometerAlarmDetected.getValue()); setAccelerometerAlarmDetected(mAccelerometerAlarmDetected.getValue());
setMicrofonAlarmDetected(mMicrofonAlarmDetected.getValue()); setMicrofonAlarmDetected(mMicrofonAlarmDetected.getValue());
if (microfonAlarmDetected || accelerometerAlarmDetected && !microfondetectionAndAccelerometerAlarmDetected) {
if (microfonAlarmDetected || accelerometerAlarmDetected) {
microfondetectionAndAccelerometerAlarmDetected = true; microfondetectionAndAccelerometerAlarmDetected = true;
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected(); setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();


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

Loading…
Cancel
Save