diff --git a/CHANGELOG.md b/CHANGELOG.md index b22c02d..908c73a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ OpenSeizureDetector Android App - Change Log ============================================ + V3.6.0 - Sep 2020 + - Added a phone sensor datasource, primarily for people to use for testing without needing a watch. V3.5.0 - Aug 2020 - Added broadcast to request phone call dial alert (handled by separate app OpenSeizureDetector Dialler). - Added UUID string to SMS alerts so they can be detected by a custom SMS receiver on the carer's phone. diff --git a/app/release/app-release-3.5.0.apk b/app/release/app-release-3.6.0.apk similarity index 61% rename from app/release/app-release-3.5.0.apk rename to app/release/app-release-3.6.0.apk index c528bdd..7a5f8d8 100644 Binary files a/app/release/app-release-3.5.0.apk and b/app/release/app-release-3.6.0.apk differ diff --git a/app/release/app-release.apk b/app/release/app-release.apk index 0d39784..7a5f8d8 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 6b00b99..35459c3 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -11,8 +11,8 @@ "type": "SINGLE", "filters": [], "properties": [], - "versionCode": 72, - "versionName": "3.5.0a", + "versionCode": 73, + "versionName": "3.6.0", "enabled": true, "outputFile": "app-release.apk" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 00484cb..52c0f90 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="73" + android:versionName="3.6.0"> diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java index 634f5bb..b96d672 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourceBLE.java @@ -176,7 +176,9 @@ public class SdDataSourceBLE extends SdDataSource { return; } // Un-register for BLE Notifications. - setCharacteristicNotification(mOsdChar, false); + if (mOsdChar != null) { + setCharacteristicNotification(mOsdChar, false); + } mBluetoothGatt.disconnect(); if (mBluetoothGatt == null) { @@ -314,6 +316,7 @@ public class SdDataSourceBLE extends SdDataSource { mSdData.watchAppRunning = true; for (i = 0; i < rawData.length; i++) { mSdData.rawData[i] = rawData[i]; + //Log.v(TAG,"onDataReceived() i="+i+", "+rawData[i]); } mSdData.mNsamp = rawData.length; //mNSamp = accelVals.length(); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePhone.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePhone.java new file mode 100644 index 0000000..625a7c1 --- /dev/null +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSourcePhone.java @@ -0,0 +1,175 @@ +/* + Android_Pebble_sd - Android alarm client for openseizuredetector.. + + See http://openseizuredetector.org for more information. + + Copyright Graham Jones, 2015, 2016 + + This file is part of pebble_sd. + + Android_Pebble_sd is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Android_Pebble_sd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Android_pebble_sd. If not, see . + +*/ +package uk.org.openseizuredetector; + +import android.content.Context; +import android.content.Intent; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.os.Binder; +import android.os.Handler; +import android.os.IBinder; +import android.os.PowerManager; +import android.preference.PreferenceManager; +import android.util.Log; + +import static java.lang.Math.sqrt; + + +/** + * A data source that uses the accelerometer built into the phone to provide seizure detector data for testing purposes. + * Note that this is unlikely to be useable as a viable seizure detector because the phone must be firmly attached to the part of the body that + * will shake during a seizure. + */ +public class SdDataSourcePhone extends SdDataSource implements SensorEventListener { + private String TAG = "SdDataSourcePhone"; + + + private final static int NSAMP = 250; + private SensorManager mSensorManager; + private Sensor mSensor; + private int mMode = 0; // 0=check data rate, 1=running + private SensorEvent mStartEvent = null; + private long mStartTs = 0; + public double mSampleFreq = 0; + + + private PowerManager.WakeLock mWakeLock; + + + public SdDataSourcePhone(Context context, Handler handler, + SdDataReceiver sdDataReceiver) { + super(context, handler, sdDataReceiver); + mName = "Phone"; + // Set default settings from XML files (mContext is set by super(). + PreferenceManager.setDefaultValues(mContext, + R.xml.network_passive_datasource_prefs, true); + } + + + /** + * Start the datasource updating - initialises from sharedpreferences first to + * make sure any changes to preferences are taken into account. + */ + public void start() { + Log.i(TAG, "start()"); + mUtil.writeToSysLogFile("SdDataSourcePhone.start()"); + mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); + mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); + mSensorManager.registerListener(this, mSensor , SensorManager.SENSOR_DELAY_GAME); + super.start(); + } + + /** + * Stop the datasource from updating + */ + public void stop() { + Log.i(TAG, "stop()"); + mUtil.writeToSysLogFile("SdDataSourcePhone.stop()"); + mSensorManager.unregisterListener(this); + + super.stop(); + } + + + + + + @Override + public void onSensorChanged(SensorEvent event) { + if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { + // we initially start in mMode=0, which calculates the sample frequency returned by the sensor, then enters mMode=1, which is normal operation. + if (mMode == 0) { + if (mStartEvent==null) { + Log.v(TAG,"onSensorChanged(): mMode=0 - checking Sample Rate - mNSamp = "+mSdData.mNsamp); + Log.v(TAG,"onSensorChanged(): saving initial event data"); + mStartEvent = event; + mStartTs = event.timestamp; + mSdData.mNsamp = 0; + } else { + mSdData.mNsamp ++; + } + if (mSdData.mNsamp>=250) { + Log.v(TAG,"onSensorChanged(): Collected Data = final TimeStamp="+event.timestamp+", initial TimeStamp="+mStartTs); + double dT = 1e-9*(event.timestamp - mStartTs); + mSdData.mSampleFreq = (int)(mSdData.mNsamp/dT); + mSdData.haveSettings = true; + Log.v(TAG,"onSensorChanged(): Collected data for "+dT+" sec - calculated sample rate as "+ mSampleFreq +" Hz"); + mMode = 1; + mSdData.mNsamp = 0; + mStartTs = event.timestamp; + } + } else if (mMode==1) { + // mMode=1 is normal operation - collect NSAMP accelerometer data samples, then analyse them by calling doAnalysis(). + float x = event.values[0]; + float y = event.values[1]; + float z = event.values[2]; + //Log.v(TAG,"Accelerometer Data Received: x="+x+", y="+y+", z="+z); + mSdData.rawData[mSdData.mNsamp] = sqrt(x*x + y*y + z*z); + mSdData.mNsamp++; + if (mSdData.mNsamp==NSAMP) { + // Calculate the sample frequency for this sample, but do not change mSampleFreq, which is used for + // analysis - this is because sometimes you get a very long delay (e.g. when disconnecting debugger), + // which gives a very low frequency which can make us run off the end of arrays in doAnalysis(). + // FIXME - we should do some sort of check and disregard samples with long delays in them. + double dT = 1e-9*(event.timestamp - mStartTs); + int sampleFreq = (int)(mSdData.mNsamp/dT); + Log.v(TAG,"onSensorChanged(): Collected "+NSAMP+" data points in "+dT+" sec (="+sampleFreq+" Hz) - analysing..."); + // DownSample from the 50Hz received frequency to 25Hz and convert to mg. + // FIXME - we should really do this properly rather than assume we are really receiving data at 50Hz. + for (int i=0; iNSAMP) { + Log.v(TAG,"onSensorChanged(): Received data during analysis - ignoring sample"); + } + + } else { + Log.v(TAG,"onSensorChanged(): ERROR - Mode "+mMode+" unrecognised"); + } + } + + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) { + Log.v(TAG,"onAccuracyChanged()"); + } + + + + +} + + + + + diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 5c24fb6..7e9127e 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -250,6 +250,11 @@ public class SdServer extends Service implements SdDataReceiver { mUtil.writeToSysLogFile("SdServer.onStartCommand() - creating SdDataSourceBLE"); mSdDataSource = new SdDataSourceBLE(this.getApplicationContext(), mHandler, this); break; + case "Phone": + Log.v(TAG, "Selecting Phone Sensor DataSource"); + mUtil.writeToSysLogFile("SdServer.onStartCommand() - creating SdDataSourcePhone"); + mSdDataSource = new SdDataSourcePhone(this.getApplicationContext(), mHandler, this); + break; default: Log.e(TAG, "Datasource " + mSdDataSourceName + " not recognised - Defaulting to Pebble"); mUtil.writeToSysLogFile("SdServer.onStartCommand() - Datasource " + mSdDataSourceName + " not recognised - exiting"); diff --git a/app/src/main/res/values/datasource_list.xml b/app/src/main/res/values/datasource_list.xml index c8a5d21..f095243 100644 --- a/app/src/main/res/values/datasource_list.xml +++ b/app/src/main/res/values/datasource_list.xml @@ -1,16 +1,18 @@ - "Pebble Watch" "Garmin Watch" - "Network" "Bluetooth Device" + "Pebble Watch" + "Phone Sensor (for testing)" + "Network (for Wifi Alerts)" - "Pebble" "Garmin" - "Network" "BLE" + "Pebble" + "Phone" + "Network" \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8d13d90..7906070 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,6 +2,7 @@ OpenSeizureDetector + \n V3.6 - Added phone sensor data source for testing without a watchs \n V3.5 - Added support for Phone Call Alerts, using separate OpenSeizureDetector Dialler App \n - Added Unique Identifier (UUID) to SMS alerts so they can be detected as OpenSeizureDetector SMS messages on client phone. \n V3.4.0 - Aug 2020 @@ -143,6 +144,6 @@ STOP SCAN Unknown Device - Select BLE Device - Select Bluetooth Low Energy (BLE) Device to provide seizure (acceleration and heart rate) data). + Select BLE Device (for Buetooth Data Source Only) + Select Bluetooth Low Energy (BLE) Device to provide seizure (acceleration and heart rate) data) when using the Bluetooth Device data source. diff --git a/app/src/main/res/xml/general_prefs.xml b/app/src/main/res/xml/general_prefs.xml index 9e1408a..4191d7b 100644 --- a/app/src/main/res/xml/general_prefs.xml +++ b/app/src/main/res/xml/general_prefs.xml @@ -3,7 +3,7 @@