From afa5faf834389ba56d155f64e479642a7a2b61ed Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 18 Nov 2016 03:21:38 +0100 Subject: [PATCH] wear basal live --- .../wearintegration/WatchUpdaterService.java | 58 ++++++++++++++----- .../info/nightscout/androidaps/BIGChart.java | 1 - .../nightscout/androidaps/BasalWatchData.java | 1 - .../nightscout/androidaps/BgGraphBuilder.java | 2 +- 4 files changed, 44 insertions(+), 18 deletions(-) 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 3328e58406..ee4701a20a 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 @@ -247,40 +247,69 @@ public class WatchUpdaterService extends WearableListenerService implements private void sendBasals() { if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); } - long startTime = System.currentTimeMillis() - (long)(60000 * 60 * 5.5); + + long now = System.currentTimeMillis(); + long startTimeWindow = now - (long)(60000 * 60 * 5.5); ArrayList basals = new ArrayList<>(); + NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); + + + long beginBasalSegmentTime = startTimeWindow; + long endBasalSegmentTime = startTimeWindow; + double beginValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(beginBasalSegmentTime))); + double endValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(endBasalSegmentTime))); + + + for(;endBasalSegmentTime temps = new ArrayList<>(); - from = (long)(startTime + (1/8d)*(now - startTime)); + from = (long)(startTimeWindow + (1/8d)*(now - startTimeWindow)); double fromBasal = 0.5; - to = (long)(startTime + (2/8d)*(now - startTime)); + to = (long)(startTimeWindow + (2/8d)*(now - startTimeWindow)); double toBasal = 0.5; amount = 3; temps.add(tempDatamap(from, fromBasal, to, toBasal, amount)); - from = (long)(startTime + (6/8d)*(now - startTime)); + from = (long)(startTimeWindow + (6/8d)*(now - startTimeWindow)); fromBasal = 0.8; - to = (long)(startTime + (7/8d)*(now - startTime)); + to = (long)(startTimeWindow + (7/8d)*(now - startTimeWindow)); toBasal = 0.8; amount = 0; temps.add(tempDatamap(from, fromBasal, to, toBasal, amount)); @@ -305,12 +334,11 @@ public class WatchUpdaterService extends WearableListenerService implements return dm; } - private DataMap basalMap(long startTime, long endTime, double amount, double afterwards) { + private DataMap basalMap(long startTime, long endTime, double amount) { DataMap dm = new DataMap(); dm.putLong("starttime", startTime); dm.putLong("endtime", endTime); dm.putDouble("amount", amount); - dm.putDouble("afterwards", afterwards); return dm; } diff --git a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java index bcf78f1af2..2eb6718553 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java @@ -311,7 +311,6 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre bwd.startTime = basal.getLong("starttime"); bwd.endTime = basal.getLong("endtime"); bwd.amount = basal.getDouble("amount"); - //bwd.afterwards; basalWatchDataList.add(bwd); } } diff --git a/wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java b/wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java index 1d85a73fd7..46b913aa7e 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java +++ b/wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java @@ -8,5 +8,4 @@ public class BasalWatchData { public long startTime; public long endTime; public double amount; - public double afterwards; } diff --git a/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java b/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java index 22773b2af6..9f5448c2c3 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java +++ b/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java @@ -124,7 +124,7 @@ public class BgGraphBuilder { double factor = (maxChart-minChart)/maxTemp; // in case basal is the highest, don't paint it totally at the top. - factor = Math.min(factor, ((maxChart-minChart)/maxTemp)*(2/3d)); + factor = Math.min(factor, ((maxChart-minChart)/maxBasal)*(2/3d)); for (TempWatchData twd: tempWatchDataList) { if(twd.endTime > start_time) { lines.add(tempValuesLine(twd, (float) minChart, factor));