diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java index ab42708..31cb6fe 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java @@ -701,7 +701,9 @@ public class MainActivity extends AppCompatActivity { tv.setTextColor(warnTextColour); } tv = (TextView) findViewById(R.id.battTv); - tv.setText(getString(R.string.WatchBatteryEquals) + String.valueOf(mConnection.mSdServer.mSdData.batteryPc) + "%"); + tv.setText(getString(R.string.WatchBatteryEquals) + + String.valueOf(mConnection.mSdServer.mSdData.batteryPc) + "% / " + +String.valueOf(mConnection.mSdServer.mSdData.phoneBatteryPc)+"%"); if (mConnection.mSdServer.mSdData.batteryPc <= 10) { tv.setBackgroundColor(alarmColour); tv.setTextColor(alarmTextColour); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdData.java b/app/src/main/java/uk/org/openseizuredetector/SdData.java index cc850c5..74ab37e 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdData.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdData.java @@ -64,7 +64,8 @@ public class SdData implements Parcelable { public long alarmTime; public long alarmThresh; public long alarmRatioThresh; - public long batteryPc; + public long batteryPc; // watch battery + public int phoneBatteryPc; /* Heart Rate Alarm Settings */ public boolean mHRAlarmActive = false; @@ -269,6 +270,7 @@ public class SdData implements Parcelable { jsonObj.put("dataTime", "00-00-00 00:00:00"); } jsonObj.put("batteryPc", batteryPc); + jsonObj.put("phoneBatteryPc", phoneBatteryPc); jsonObj.put("alarmState", alarmState); jsonObj.put("alarmPhrase", alarmPhrase); jsonObj.put("sdMode", mSdMode); @@ -330,6 +332,7 @@ public class SdData implements Parcelable { jsonObj.put("specPower", specPower); jsonObj.put("roiPower", roiPower); jsonObj.put("batteryPc", batteryPc); + jsonObj.put("phoneBatteryPc", phoneBatteryPc); jsonObj.put("watchConnected", watchConnected); jsonObj.put("watchAppRunning", watchAppRunning); jsonObj.put("haveSettings", haveSettings); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java index dbeec10..2aed61f 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java @@ -26,8 +26,10 @@ package uk.org.openseizuredetector; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.net.Uri; +import android.os.BatteryManager; import android.os.Handler; import android.preference.PreferenceManager; import android.text.format.Time; @@ -359,6 +361,7 @@ public abstract class SdDataSource { mSamplePeriod = (short) dataObject.getInt("analysisPeriod"); mSampleFreq = (short) dataObject.getInt("sampleFreq"); mSdData.batteryPc = (short) dataObject.getInt("battery"); + Log.v(TAG, "updateFromJSON - mSamplePeriod=" + mSamplePeriod + " mSampleFreq=" + mSampleFreq); mUtil.writeToSysLogFile("SDDataSource.updateFromJSON - Settings Received"); mUtil.writeToSysLogFile(" * mSamplePeriod=" + mSamplePeriod + " mSampleFreq=" + mSampleFreq); @@ -404,6 +407,19 @@ public abstract class SdDataSource { return (retVal); } + private int getPhoneBatteryLevel() { + /* Returns the current phone battery level in percent */ + // Check phone battery level + int batPc; + IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent batteryStatus = mContext.registerReceiver(null, ifilter); + int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); + int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); + batPc = (int) (level * 100 / (float) scale); + Log.v(TAG, "SdDataSource.getPhoneBatteryLevel - Phone Bat = " + level + ", scale=" + scale + ", phoneBatteryPc=" + batPc); + return batPc; + } + /** * Calculate the magnitude of entry i in the fft array fft * @@ -426,6 +442,8 @@ public abstract class SdDataSource { int nMax = 0; int nFreqCutoff = 0; double[] fft = null; + // Update phone battery level - it is done here so it is called for all data sources. + mSdData.phoneBatteryPc = getPhoneBatteryLevel(); try { // FIXME - Use specified sampleFreq, not this hard coded one mSampleFreq = 25; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3797d8f..efb9fc3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,7 +55,7 @@ HR Alarm OFF Watch App OK Watch App NOT Running - Watch Battery = + Batteries = Power = Spectrum Ratio = threshold