From 0013050860cdf7fbae6d9b5111512501fbfaadad Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 7 Dec 2017 12:32:14 +0100 Subject: [PATCH 1/9] remove wear-overview notifications as replaced by system notifications --- .../plugins/Overview/notifications/NotificationStore.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java index ce18c32734..1ce92249f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/NotificationStore.java @@ -69,11 +69,6 @@ public class NotificationStore { } } - WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class); - if (wearPlugin != null && wearPlugin.isEnabled()) { - wearPlugin.overviewNotification(n.id, "OverviewNotification:\n" + n.text); - } - Collections.sort(store, new NotificationComparator()); } From e14272c083127739e760d0414ca3eb40cca0dcb6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 12 Dec 2017 18:18:41 +0100 Subject: [PATCH 2/9] Rv2,RS: always load last 45 min --- .../androidaps/plugins/PumpDanaRS/services/DanaRSService.java | 2 +- .../plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index f927c107f1..a30e237672 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -185,7 +185,7 @@ public class DanaRSService extends Service { while (!msg.done && bleComm.isConnected()) { SystemClock.sleep(100); } - lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded; + lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded - 45 * 60 * 1000L; // always load last 45 min log.debug("Events loaded"); return new PumpEnactResult().success(true); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 2020e6d14d..4e5b85177a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -527,7 +527,7 @@ public class DanaRv2ExecutionService extends Service { waitMsec(100); } waitMsec(200); - lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded; + lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - 45 * 60 * 1000L; //always load last 45 min; return new PumpEnactResult().success(true); } From f6721f628cadb51bc7ce50a605daa4c71c90ae82 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 12 Dec 2017 22:30:42 +0100 Subject: [PATCH 3/9] Apply bolus constraint before applying. --- .../info/nightscout/androidaps/queue/CommandQueue.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index eea2635ae7..af768e4888 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -153,6 +153,10 @@ public class CommandQueue { // remove all unfinished boluses removeAll(Command.CommandType.BOLUS); + // apply constraints + detailedBolusInfo.insulin = MainApp.getConfigBuilder().applyBolusConstraints(detailedBolusInfo.insulin); + detailedBolusInfo.carbs = MainApp.getConfigBuilder().applyCarbsConstraints((int) detailedBolusInfo.carbs); + // add new command to queue add(new CommandBolus(detailedBolusInfo, callback)); @@ -162,12 +166,8 @@ public class CommandQueue { MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin)); // Bring up bolus progress dialog - detailedBolusInfo.insulin = MainApp.getConfigBuilder().applyBolusConstraints(detailedBolusInfo.insulin); - detailedBolusInfo.carbs = MainApp.getConfigBuilder().applyCarbsConstraints((int) detailedBolusInfo.carbs); - - BolusProgressDialog bolusProgressDialog = null; if (detailedBolusInfo.context != null) { - bolusProgressDialog = new BolusProgressDialog(); + BolusProgressDialog bolusProgressDialog = new BolusProgressDialog(); bolusProgressDialog.setInsulin(detailedBolusInfo.insulin); bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress"); } else { From 0151dbd496a040ac85519a632218e9e59ece8e30 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 13 Dec 2017 22:14:02 +0100 Subject: [PATCH 4/9] fake Esel --- app/src/main/java/info/nightscout/androidaps/MainApp.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index a0ba2a6843..71778d723a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -71,6 +71,7 @@ import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; +import info.nightscout.androidaps.plugins.XDripFakeEsel.XDripFakeEselPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; @@ -160,6 +161,7 @@ public class MainApp extends Application { pluginsList.add(WearPlugin.initPlugin(this)); pluginsList.add(StatuslinePlugin.initPlugin(this)); + pluginsList.add(XDripFakeEselPlugin.initPlugin(this)); pluginsList.add(new PersistentNotificationPlugin(this)); pluginsList.add(NSClientInternalPlugin.getPlugin()); From 9602bde6a16e955b3ea592b84e6afb3a57c434c1 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 13 Dec 2017 22:39:44 +0100 Subject: [PATCH 5/9] fake Esel new file --- .../XDripFakeEsel/XDripFakeEselPlugin.java | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java new file mode 100644 index 0000000000..6c79fa8ebb --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java @@ -0,0 +1,190 @@ +package info.nightscout.androidaps.plugins.XDripFakeEsel; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.ResolveInfo; +import android.os.Bundle; + +import com.squareup.otto.Subscribe; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Locale; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.db.DatabaseHelper; +import info.nightscout.androidaps.events.EventNewBG; +import info.nightscout.androidaps.interfaces.PluginBase; + +/** + * Created by adrian on 13/12/17. + */ + +public class XDripFakeEselPlugin implements PluginBase { + + private static Logger log = LoggerFactory.getLogger(XDripFakeEselPlugin.class); + + public static final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; + private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); + + private boolean fragmentEnabled = false; + + private final Context ctx; + + private static XDripFakeEselPlugin thisPlugin; + + public static XDripFakeEselPlugin getPlugin() { + return thisPlugin; + } + + public static XDripFakeEselPlugin initPlugin(Context ctx) { + + if (thisPlugin == null) { + thisPlugin = new XDripFakeEselPlugin(ctx); + } + + return thisPlugin; + } + + private XDripFakeEselPlugin(Context ctx) { + this.ctx = ctx; + MainApp.bus().register(this); + } + + @Override + public int getType() { + return PluginBase.GENERAL; + } + + @Override + public String getFragmentClass() { + return null; + } + + @Override + public String getName() { + return "Fake ESEL for xDrip"; + } + + @Override + public String getNameShort() { + String name = "FakeESEL"; + if (!name.trim().isEmpty()) { + //only if translation exists + return name; + } + // use long name as fallback + return getName(); + } + + @Override + public boolean isEnabled(int type) { + return type == GENERAL && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return false; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public boolean hasFragment() { + return false; + } + + @Override + public boolean showInList(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == GENERAL) { + this.fragmentEnabled = fragmentEnabled; + } + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + // do nothing, no gui + } + + @Override + public int getPreferencesId() { + return -1; + } + + + private void sendBG() { + if (!fragmentEnabled) { + return; + } + try { + + final JSONArray entriesBody = new JSONArray(); + addLastSgvEntry(entriesBody); + + sendBundle("add", "entries", entriesBody, XDRIP_PLUS_NS_EMULATOR); + } catch (Exception e) { + log.debug(e.getMessage()); + } + } + + @Subscribe + public void onStatusEvent(final EventNewBG ev) { + sendBG(); + } + + private static void sendBundle(String action, String collection, Object json, String intentIdAction) { + final Bundle bundle = new Bundle(); + bundle.putString("action", action); + bundle.putString("collection", collection); + bundle.putString("data", json.toString()); + final Intent intent = new Intent(intentIdAction); + intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + MainApp.instance().sendBroadcast(intent); + List receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0); + if (receivers.size() < 1) { + log.debug("No xDrip receivers found. "); + } else { + log.debug(receivers.size() + " xDrip receivers"); + } + } + + private static void addLastSgvEntry(JSONArray entriesArray) throws Exception { + JSONObject json = new JSONObject(); + BgReading bgReading = DatabaseHelper.lastBg(); + if(bgReading==null){ + log.debug("bgReading==null"); + } + + json.put("sgv", bgReading.value); + if (bgReading.direction == null){ + json.put("direction", "NONE"); + } else { + json.put("direction", bgReading.direction); + } + json.put("device", "ESEL"); + json.put("type", "sgv"); + json.put("date", bgReading.date); + json.put("dateString", format.format(bgReading.date)); + + entriesArray.put(json); + } + + public boolean isEnabled() { + return fragmentEnabled; + } + +} From 5f60e7cf2b476863b6829f4483c2814543f1ce52 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 14 Dec 2017 21:49:11 +0100 Subject: [PATCH 6/9] G5 upload to xdrip --- .../info/nightscout/androidaps/MainApp.java | 10 +- .../androidaps/Services/DataService.java | 3 + .../nightscout/androidaps/data/Profile.java | 6 +- .../XDripFakeEsel/XDripFakeEselPlugin.java | 190 ------------------ .../java/info/nightscout/utils/NSUpload.java | 48 ++++- app/src/main/res/values/strings.xml | 3 + app/src/main/res/xml/pref_dexcomg5.xml | 6 + 7 files changed, 64 insertions(+), 202 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 71778d723a..7eac441726 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps; import android.app.Application; -import android.content.Intent; import android.content.IntentFilter; import android.content.res.Resources; import android.os.SystemClock; @@ -25,7 +24,6 @@ import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Actions.ActionsFragment; import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; @@ -51,13 +49,9 @@ import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; @@ -71,7 +65,6 @@ import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; -import info.nightscout.androidaps.plugins.XDripFakeEsel.XDripFakeEselPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; @@ -161,7 +154,6 @@ public class MainApp extends Application { pluginsList.add(WearPlugin.initPlugin(this)); pluginsList.add(StatuslinePlugin.initPlugin(this)); - pluginsList.add(XDripFakeEselPlugin.initPlugin(this)); pluginsList.add(new PersistentNotificationPlugin(this)); pluginsList.add(NSClientInternalPlugin.getPlugin()); @@ -175,7 +167,7 @@ public class MainApp extends Application { else Answers.getInstance().logCustom(new CustomEvent("AppStart")); - new Thread(new Runnable() { + new Thread(new Runnable() { @Override public void run() { SystemClock.sleep(5000); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index 540df96fe8..c8d8dbe808 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -228,6 +228,9 @@ public class DataService extends IntentService { if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { NSUpload.uploadBg(bgReading); } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } } } catch (JSONException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 5b2db2c912..ea662e434d 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -159,12 +159,16 @@ public class Profile { LongSparseArray sparse = new LongSparseArray<>(); for (Integer index = 0; index < array.length(); index++) { try { - JSONObject o = array.getJSONObject(index); + final JSONObject o = array.getJSONObject(index); long tas = getShitfTimeSecs((int) o.getLong("timeAsSeconds")); Double value = o.getDouble("value") * multiplier; sparse.put(tas, value); } catch (JSONException e) { log.error("Unhandled exception", e); + try { + log.error(array.getJSONObject(index).toString()); + } catch (JSONException e1) { + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java deleted file mode 100644 index 6c79fa8ebb..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripFakeEsel/XDripFakeEselPlugin.java +++ /dev/null @@ -1,190 +0,0 @@ -package info.nightscout.androidaps.plugins.XDripFakeEsel; - -import android.content.Context; -import android.content.Intent; -import android.content.pm.ResolveInfo; -import android.os.Bundle; - -import com.squareup.otto.Subscribe; - -import org.json.JSONArray; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Locale; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.db.BgReading; -import info.nightscout.androidaps.db.DatabaseHelper; -import info.nightscout.androidaps.events.EventNewBG; -import info.nightscout.androidaps.interfaces.PluginBase; - -/** - * Created by adrian on 13/12/17. - */ - -public class XDripFakeEselPlugin implements PluginBase { - - private static Logger log = LoggerFactory.getLogger(XDripFakeEselPlugin.class); - - public static final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; - private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); - - private boolean fragmentEnabled = false; - - private final Context ctx; - - private static XDripFakeEselPlugin thisPlugin; - - public static XDripFakeEselPlugin getPlugin() { - return thisPlugin; - } - - public static XDripFakeEselPlugin initPlugin(Context ctx) { - - if (thisPlugin == null) { - thisPlugin = new XDripFakeEselPlugin(ctx); - } - - return thisPlugin; - } - - private XDripFakeEselPlugin(Context ctx) { - this.ctx = ctx; - MainApp.bus().register(this); - } - - @Override - public int getType() { - return PluginBase.GENERAL; - } - - @Override - public String getFragmentClass() { - return null; - } - - @Override - public String getName() { - return "Fake ESEL for xDrip"; - } - - @Override - public String getNameShort() { - String name = "FakeESEL"; - if (!name.trim().isEmpty()) { - //only if translation exists - return name; - } - // use long name as fallback - return getName(); - } - - @Override - public boolean isEnabled(int type) { - return type == GENERAL && fragmentEnabled; - } - - @Override - public boolean isVisibleInTabs(int type) { - return false; - } - - @Override - public boolean canBeHidden(int type) { - return true; - } - - @Override - public boolean hasFragment() { - return false; - } - - @Override - public boolean showInList(int type) { - return true; - } - - @Override - public void setFragmentEnabled(int type, boolean fragmentEnabled) { - if (type == GENERAL) { - this.fragmentEnabled = fragmentEnabled; - } - } - - @Override - public void setFragmentVisible(int type, boolean fragmentVisible) { - // do nothing, no gui - } - - @Override - public int getPreferencesId() { - return -1; - } - - - private void sendBG() { - if (!fragmentEnabled) { - return; - } - try { - - final JSONArray entriesBody = new JSONArray(); - addLastSgvEntry(entriesBody); - - sendBundle("add", "entries", entriesBody, XDRIP_PLUS_NS_EMULATOR); - } catch (Exception e) { - log.debug(e.getMessage()); - } - } - - @Subscribe - public void onStatusEvent(final EventNewBG ev) { - sendBG(); - } - - private static void sendBundle(String action, String collection, Object json, String intentIdAction) { - final Bundle bundle = new Bundle(); - bundle.putString("action", action); - bundle.putString("collection", collection); - bundle.putString("data", json.toString()); - final Intent intent = new Intent(intentIdAction); - intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - MainApp.instance().sendBroadcast(intent); - List receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0); - if (receivers.size() < 1) { - log.debug("No xDrip receivers found. "); - } else { - log.debug(receivers.size() + " xDrip receivers"); - } - } - - private static void addLastSgvEntry(JSONArray entriesArray) throws Exception { - JSONObject json = new JSONObject(); - BgReading bgReading = DatabaseHelper.lastBg(); - if(bgReading==null){ - log.debug("bgReading==null"); - } - - json.put("sgv", bgReading.value); - if (bgReading.direction == null){ - json.put("direction", "NONE"); - } else { - json.put("direction", bgReading.direction); - } - json.put("device", "ESEL"); - json.put("type", "sgv"); - json.put("date", bgReading.date); - json.put("dateString", format.format(bgReading.date)); - - entriesArray.put(json); - } - - public boolean isEnabled() { - return fragmentEnabled; - } - -} diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index d6e8254cd6..f115358703 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -3,33 +3,37 @@ package info.nightscout.utils; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; +import java.util.Locale; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.DeviceStatus; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger; -import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA; import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA; @@ -449,4 +453,44 @@ public class NSUpload { } + public static void sendToXdrip(BgReading bgReading) { + final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); + + try { + final JSONArray entriesBody = new JSONArray(); + JSONObject json = new JSONObject(); + json.put("sgv", bgReading.value); + if (bgReading.direction == null) { + json.put("direction", "NONE"); + } else { + json.put("direction", bgReading.direction); + } + json.put("device", "G5"); + json.put("type", "sgv"); + json.put("date", bgReading.date); + json.put("dateString", format.format(bgReading.date)); + entriesBody.put(json); + + final Bundle bundle = new Bundle(); + bundle.putString("action", "add"); + bundle.putString("collection", "entries"); + bundle.putString("data", entriesBody.toString()); + final Intent intent = new Intent(XDRIP_PLUS_NS_EMULATOR); + intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + MainApp.instance().sendBroadcast(intent); + List receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0); + if (receivers.size() < 1) { + log.debug("No xDrip receivers found. "); + } else { + log.debug(receivers.size() + " xDrip receivers"); + } + + + } catch (JSONException e) { + e.printStackTrace(); + } + + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 282299fdd0..7286003410 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -785,5 +785,8 @@ Show detailed delta Show delta with one more decimal place Unsupported pump firmware + Send BG data to xDrip+ + dexcomg5_xdripupload + In xDrip+ select 640g/Eversense data source diff --git a/app/src/main/res/xml/pref_dexcomg5.xml b/app/src/main/res/xml/pref_dexcomg5.xml index 75631b3b85..03c49bf624 100644 --- a/app/src/main/res/xml/pref_dexcomg5.xml +++ b/app/src/main/res/xml/pref_dexcomg5.xml @@ -9,6 +9,12 @@ android:key="@string/key_dexcomg5_nsupload" android:title="@string/dexcomg5_nsupload_title" /> + + \ No newline at end of file From 559dbdf0b1c7b0fef1a7c5d5284338e76912ac39 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 18 Dec 2017 20:26:35 +0100 Subject: [PATCH 7/9] Undo over-eager optimization. Makes setting actual 90/110% TBRs impossiblee and will result in ComboPlugin starting TBRs with 100% (and failing because duration is not readable or 0). (cherry picked from commit 5a4e7d4) --- .../java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java index 63ac25a2f8..975eb0f50d 100644 --- a/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java +++ b/ruffyscripter/src/main/java/de/jotomo/ruffyscripter/commands/SetTbrCommand.java @@ -124,9 +124,8 @@ public class SetTbrCommand extends BaseCommand { scripter.waitForScreenUpdate(); state = scripter.readPumpStateInternal(); } - // if we waited above and a cancellation (fake or hard) was requested, - // we already completed the request - if (!state.tbrActive && percentage >= 90 && percentage <= 110) { + // if we waited above and a cancellation was requested, we already completed the request + if (!state.tbrActive && percentage == 100) { result.success = true; return true; } From 28961da25352f876fd16f0df5658480e3e3cebc9 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 19 Dec 2017 00:00:00 +0100 Subject: [PATCH 8/9] Declare profile switches being supported by the Combo. --- .../nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 9f737d39d0..c38d7d7827 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -80,7 +80,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf pumpDescription.tempMaxDuration = 24 * 60; - pumpDescription.isSetBasalProfileCapable = false; + pumpDescription.isSetBasalProfileCapable = true; pumpDescription.basalStep = 0.01d; pumpDescription.basalMinimumRate = 0.0d; From 28ce67ae424183f3b0eb457b35ddcd5e5b45f458 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 19 Dec 2017 00:04:15 +0100 Subject: [PATCH 9/9] Typo fixes. --- README-Combo.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README-Combo.md b/README-Combo.md index ffaba95efa..b4c42f30aa 100644 --- a/README-Combo.md +++ b/README-Combo.md @@ -9,10 +9,10 @@ Hardware requirements: - A Roche Accu-Chek Combo (any firmware, they all work) - A Smartpix or Realtyme device together with the 360 Configuration Software to configure the pump. - Roche sends these out Smartpix devices and the configuration software + Roche sends out Smartpix devices and the configuration software free of charge to their customers upon request. - A compatible phone: An Android phone with a phone running LineageOS 14.1 (formerly CyanogenMod) -- To build AndroidAPS with Combo support you need the lastet Android Studio 3 version +- To build AndroidAPS with Combo support you need the latest Android Studio 3 version Limitations: - Extended bolus and multiwave bolus are not supported. @@ -24,10 +24,11 @@ Limitations: changes have to be performed manually. - There's a bug in the pump's firmware that's triggered when "too much" communication happens with the pump. Specifically, this issue occurs when going from just issuing commands to the pump - to reading the pumps data and history. For that reason, a minimal amount of data is read from + to reading the pump's data and history. For that reason, a minimal amount of data is read from the pump. The bug might still rarely occur and causes the pump to not accept any connection - unless a button is physically pressed on the pump. + unless a button is physically pressed on the pump (make sure the 'pump unreachable' alert is enabled + so you'll get an alarm if the bug occurs. Therefore, the pump's reservoir level is not read and the pump status information uploaded to Nightscout shows fake numbers of 150 (above low threshold - which can be configured via the configuration tool), 8 (below low threshold, triggers NS alarm since < 10) and 0 if the reservoir is empty. @@ -48,20 +49,20 @@ Setup: - Set maximum TBR to 500% - Disable end of TBR alert - Set TBR duration step-size to 15 min - - Set low cartridge alarm to your licking + - Set low cartridge alarm to your liking - Enable keylock (can also be set on the pump directly, see usage section on reasoning) -- Get Android Studio 3 -- Get ruffy from https://github.com/jotomo/ruffy (branch `combo-scripter-v2`) -- Pair the pump, if it doesn't work, switch to the `pairing` branch, pair, +- Get Android Studio 3 https://developer.android.com/studio/index.html +- Clone ruffy from https://github.com/jotomo/ruffy (branch `combo-scripter-v2`) +- Pair the pump, if it doesn't work after multiple attempts, switch to the `pairing` branch, pair, then switch back the original branch. If the pump is already paired and can be controlled via ruffy, installing the above version is sufficient. If AAPS is already installed, switch to the MDI plugin to avoid the Combo plugin from interfering with ruffy during the pairing process. Note that the pairing processing is somewhat fragile and may need a few attempts; quickly acknowledge prompts and when starting over, remove the pump device - from the bluetooth settings beforehand -- Get AndroidAPS from https://github.com/jotomo/AndroidAPS (Branch `combo-scripter-v2`) -- Before enabling the Combo plugin in AAPS make sure you're profile is set up + from the bluetooth settings beforehand. +- Clone AndroidAPS from https://github.com/jotomo/AndroidAPS (Branch `combo-scripter-v2`) +- Before enabling the Combo plugin in AAPS make sure your profile is set up correctly and your basal profile is up to date as AAPS will sync the basal profile to the pump.