diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayAbstract.java b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayAbstract.java index 09b859fed1..30e6ba4910 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayAbstract.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayAbstract.java @@ -36,6 +36,8 @@ public abstract class PebbleDisplayAbstract implements PebbleDisplayInterface { protected static final int BG_DELTA_KEY = 4; protected static final int UPLOADER_BATTERY_KEY = 5; protected static final int NAME_KEY = 6; + protected static final int TBR_KEY = 7; + protected static final int IOB_KEY = 8; protected static final int NUM_VALUES =(60/5)*24; diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayStandard.java b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayStandard.java index 6fd33cafdf..d0dcac684d 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayStandard.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/pebble/PebbleDisplayStandard.java @@ -1,10 +1,13 @@ package com.eveningoutpost.dexdrip.UtilityModels.pebble; import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Handler; import com.eveningoutpost.dexdrip.BestGlucose; import com.eveningoutpost.dexdrip.Models.BgReading; import com.eveningoutpost.dexdrip.Models.JoH; +import com.eveningoutpost.dexdrip.Models.UserError; import com.eveningoutpost.dexdrip.Models.UserError.Log; import com.getpebble.android.kit.PebbleKit; import com.getpebble.android.kit.util.PebbleDictionary; @@ -23,10 +26,18 @@ public class PebbleDisplayStandard extends PebbleDisplayAbstract { private static double last_time_seen = 0; + private String StatusLine=""; + @Override public void startDeviceCommand() { - sendData(); + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + public void run() { + sendData(); // Actions to do after 30 seconds + } + }, 20000); + } @@ -36,7 +47,14 @@ public void receiveData(int transactionId, PebbleDictionary data) { PebbleWatchSync.lastTransactionId = transactionId; Log.d(TAG, "Received Query. data: " + data.size() + ". sending ACK and data"); PebbleKit.sendAckToPebble(this.context, transactionId); - sendData(); + + //Handler handler = new Handler(); + //handler.postDelayed(new Runnable() { + // public void run() { + sendData(); // Actions to do after 30 seconds + // } + //}, 30000); + } else { Log.d(TAG, "receiveData: lastTransactionId is " + String.valueOf(PebbleWatchSync.lastTransactionId) + ", sending NACK"); PebbleKit.sendNackToPebble(this.context, transactionId); @@ -50,20 +68,27 @@ private PebbleDictionary buildDictionary() { Date now = new Date(); int offsetFromUTC = tz.getOffset(now.getTime()); + SharedPreferences loopstatus = context.getSharedPreferences("loopstatus", 0); + StatusLine = loopstatus.getString("loopstatus", null); + final String bgDelta = getBgDelta(); final String bgReadingS = getBgReading(); final String slopeOrdinal = getSlopeOrdinal(); + final String insulinOnBoard = getIOB(); + final String tempBasalRate = getTBR(); //boolean no_signal; if (use_best_glucose) { Log.v(TAG, "buildDictionary: slopeOrdinal-" + slopeOrdinal + " bgReading-" + bgReadingS + // " now-" + (int) now.getTime() / 1000 + " bgTime-" + (int) (dg.timestamp / 1000) + // - " phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta()); + " phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta() + // + " IOB-" + getIOB() + " TBR-" + getTBR()); // no_signal = (dg.mssince > Home.stale_data_millis()); } else { Log.v(TAG, "buildDictionary: slopeOrdinal-" + slopeOrdinal + " bgReading-" + bgReadingS + // " now-" + (int) now.getTime() / 1000 + " bgTime-" + (int) (this.bgReading.timestamp / 1000) + // - " phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta()); + " phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta() + // + " IOB-" + getIOB() + " TBR-" + getTBR()); // no_signal = ((new Date().getTime()) - Home.stale_data_millis() - this.bgReading.timestamp > 0); } @@ -81,6 +106,9 @@ private PebbleDictionary buildDictionary() { addBatteryStatusToDictionary(dictionary); + dictionary.addString(IOB_KEY, insulinOnBoard); + dictionary.addString(TBR_KEY, tempBasalRate); + return dictionary; } @@ -131,6 +159,41 @@ private void watchdog() { } } + public String getIOB() { + String check = StatusLine.replaceAll("[^%]", ""); + if ( (StatusLine != null) && (check.length() > 0) ) { + UserError.Log.v("LOOP-STATUS-PEBBLE ", StatusLine); + return StatusLine.substring( (StatusLine.lastIndexOf('%')+2), (StatusLine.lastIndexOf('%')+6)); + + } + else if ( (StatusLine != null) && (check.length() == 0) ) { + UserError.Log.v("LOOP-STATUS-PEBBLE ", StatusLine); + return StatusLine.substring(0, 4); + + } + else return "???"; + + } + + + public String getTBR() { + String check = StatusLine.replaceAll("[^%]", ""); + if ( (StatusLine != null) && (check.length() > 0) ) { + int index1 = 0, index2 = 4; + UserError.Log.v("LOOP-STATUS-PEBBLE ", StatusLine); + if ( (StatusLine.lastIndexOf('%') == 3) ) index2 = 4; + else if ( (StatusLine.lastIndexOf('%') == 2) ) index2 = 3; + else if ( (StatusLine.lastIndexOf('%') == 1) ) index2 = 2; + return StatusLine.substring(index1, index2); + + } + else if ( (StatusLine != null) && (check.length() == 0) ) + return "100%"; + else + return "???"; + } + + } diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java index 87d1cf0f59..c173c707fd 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/wearintegration/ExternalStatusService.java @@ -3,6 +3,7 @@ import android.app.IntentService; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.PowerManager; import android.preference.PreferenceManager; import android.support.v4.content.WakefulBroadcastReceiver; @@ -18,6 +19,7 @@ public class ExternalStatusService extends IntentService{ public static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline"; public static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE"; public static final int MAX_LEN = 40; + public static final String LOOP_STATUS = "loopstatus"; private final static String TAG = ExternalStatusService.class.getSimpleName(); public ExternalStatusService() { @@ -44,6 +46,11 @@ protected void onHandleIntent(Intent intent) { statusline = statusline.substring(0, MAX_LEN); } + SharedPreferences loopstatus = getSharedPreferences("loopstatus", 0); + SharedPreferences.Editor editor = loopstatus.edit(); + editor.putString ("loopstatus", statusline); + editor.commit(); + // send to wear if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("wear_sync", false)) { startWatchUpdaterService(this, WatchUpdaterService.ACTION_SEND_STATUS, TAG, "externalStatusString", "" + statusline); @@ -61,4 +68,4 @@ protected void onHandleIntent(Intent intent) { WakefulBroadcastReceiver.completeWakefulIntent(intent); } } -} \ No newline at end of file +}