Send OpenAPS timestamp to watch rather than minAgo, for more accurate updates on watch face.

This commit is contained in:
Andrew Warrington 2017-12-03 18:53:52 +01:00
parent cefe93d0a0
commit 9dca53f968
3 changed files with 21 additions and 21 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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("-'");