From 9dca53f9682fd838722e69f110dc65f59b9a38f2 Mon Sep 17 00:00:00 2001 From: Andrew Warrington Date: Sun, 3 Dec 2017 18:53:52 +0100 Subject: [PATCH] Send OpenAPS timestamp to watch rather than minAgo, for more accurate updates on watch face. --- .../NSClientInternal/data/NSDeviceStatus.java | 13 +++++++++++-- .../wearintegration/WatchUpdaterService.java | 10 ++-------- .../androidaps/watchfaces/BaseWatchFace.java | 19 ++++++++----------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java index 2bd61aa4a9..20e601bea3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java @@ -264,8 +264,8 @@ public class NSDeviceStatus { JSONObject enacted = openaps.has("enacted") ? openaps.getJSONObject("enacted") : new JSONObject(); long clock = 0L; - if (suggested.has("timestamp")) - clock = DateUtil.fromISODateString(suggested.getString("timestamp")).getTime(); + if (suggested.has("deliverAt")) + clock = DateUtil.fromISODateString(suggested.getString("deliverAt")).getTime(); // check if this is new data if (clock != 0 && clock > deviceStatusOpenAPSData.clockSuggested) { deviceStatusOpenAPSData.suggested = suggested; @@ -308,6 +308,15 @@ public class NSDeviceStatus { return Html.fromHtml(string.toString()); } + public static double getOpenApsTimestamp() { + + if (deviceStatusOpenAPSData.clockSuggested != 0) { + return deviceStatusOpenAPSData.clockSuggested; + } else { + return -1; + } + } + public Spanned getExtendedOpenApsStatus() { StringBuilder string = new StringBuilder(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index 9a7eed1fd7..c6caca20a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -552,13 +552,7 @@ public class WatchUpdaterService extends WearableListenerService implements String rigBattery = NSDeviceStatus.getInstance().getUploaderStatus().trim(); //OpenAPS status - String openApsString = String.valueOf(NSDeviceStatus.getInstance().getOpenApsStatus()); - String openApsStatus = ""; - if(openApsString != null) { - int index = openApsString.indexOf("m"); - if(index > 0) - openApsStatus = openApsString.substring(0, index); - } + Double openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH); //unique content @@ -570,7 +564,7 @@ public class WatchUpdaterService extends WearableListenerService implements dataMapRequest.getDataMap().putString("tempBasal", tempBasal); dataMapRequest.getDataMap().putString("battery", "" + phoneBattery); dataMapRequest.getDataMap().putString("rigBattery", rigBattery); - dataMapRequest.getDataMap().putString("openApsStatus", openApsStatus); + dataMapRequest.getDataMap().putDouble("openApsStatus", openApsStatus); dataMapRequest.getDataMap().putString("bgi", bgiString); dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false)); dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java index 17df5197d5..a442ed1c12 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -85,7 +85,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen public boolean detailedIOB = false; public boolean showBGI = false; - public String openApsStatus = "0"; + public Double openApsStatus; public String externalStatusString = "no status"; public String sSgv = "---"; public String sDirection = "--"; @@ -267,8 +267,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen sBgi = dataMap.getString("bgi"); showBGI = dataMap.getBoolean("showBgi"); externalStatusString = dataMap.getString("externalStatusString"); - openApsStatus = dataMap.getString("openApsStatus"); batteryLevel = dataMap.getInt("batteryLevel"); + openApsStatus = dataMap.getDouble("openApsStatus"); } setDataFields(); @@ -453,18 +453,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen if (mLoop != null) { if (sharedPrefs.getBoolean("showExternalStatus", true)) { mLoop.setVisibility(View.VISIBLE); - if (openApsStatus != null && openApsStatus != "") { - mLoop.setText(openApsStatus + "'"); - if (Integer.valueOf(openApsStatus) > 14) { + if (openApsStatus != null) { + int mins = (int) ((System.currentTimeMillis() - openApsStatus) / 1000 / 60); + mLoop.setText(mins + "'"); + if (mins > 14) { loopLevel = 0; - //if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { - mLoop.setBackgroundResource(R.drawable.loop_red_25); - //} + mLoop.setBackgroundResource(R.drawable.loop_red_25); } else { loopLevel = 1; - //if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { - mLoop.setBackgroundResource(R.drawable.loop_green_25); - //} + mLoop.setBackgroundResource(R.drawable.loop_green_25); } } else { mLoop.setText("-'");