Added phone battery level to logged data fixes #55
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user