From e8edf9eb542f7c4a08e2262cd64d749acef9f23c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Mar 2017 19:11:39 +0100 Subject: [PATCH] Glimp support --- .../info/nightscout/androidaps/MainApp.java | 2 + .../androidaps/Services/DataService.java | 38 ++++++++++++ .../androidaps/Services/Intents.java | 2 + .../SourceGlimp/SourceGlimpFragment.java | 16 +++++ .../SourceGlimp/SourceGlimpPlugin.java | 62 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 121 insertions(+) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index ec478584a2..67057f1e9d 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -38,6 +38,7 @@ import info.nightscout.androidaps.plugins.Overview.OverviewFragment; import info.nightscout.androidaps.plugins.SafetyFragment.SafetyFragment; import info.nightscout.androidaps.plugins.SimpleProfile.SimpleProfileFragment; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorFragment; +import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpFragment; import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment; @@ -104,6 +105,7 @@ public class MainApp extends Application { pluginsList.add(SourceXdripFragment.getPlugin()); pluginsList.add(SourceNSClientFragment.getPlugin()); pluginsList.add(SourceMM640gFragment.getPlugin()); + pluginsList.add(SourceGlimpFragment.getPlugin()); if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorFragment.getPlugin()); if (Config.WEAR) pluginsList.add(WearFragment.getPlugin(this)); 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 b27a1a85b4..f45e59f4c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -44,6 +44,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS; +import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; @@ -59,6 +60,7 @@ public class DataService extends IntentService { boolean xDripEnabled = false; boolean nsClientEnabled = true; boolean mm640gEnabled = false; + boolean glimpEnabled = false; public DataService() { super("DataService"); @@ -74,14 +76,22 @@ public class DataService extends IntentService { xDripEnabled = true; nsClientEnabled = false; mm640gEnabled = false; + glimpEnabled = false; } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) { xDripEnabled = false; nsClientEnabled = true; mm640gEnabled = false; + glimpEnabled = false; } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) { xDripEnabled = false; nsClientEnabled = false; mm640gEnabled = true; + glimpEnabled = false; + } else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) { + xDripEnabled = false; + nsClientEnabled = false; + mm640gEnabled = false; + glimpEnabled = true; } boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class); @@ -99,6 +109,10 @@ public class DataService extends IntentService { if (mm640gEnabled) { handleNewDataFromMM640g(intent); } + } else if (Intents.GLIMP_BG.equals(action)) { + if (glimpEnabled) { + handleNewDataFromGlimp(intent); + } } else if (Intents.ACTION_NEW_SGV.equals(action)) { // always handle SGV if NS-Client is the source if (nsClientEnabled) { @@ -185,6 +199,30 @@ public class DataService extends IntentService { MainApp.bus().post(new EventNewBG()); } + private void handleNewDataFromGlimp(Intent intent) { + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + BgReading bgReading = new BgReading(); + + bgReading.value = bundle.getDouble("mySGV"); + bgReading.direction = bundle.getString("myTrend"); + bgReading.battery_level = bundle.getInt("myBatLvl"); + bgReading.timeIndex = bundle.getLong("myTimestamp"); + bgReading.raw = 0; + + if (Config.logIncommingBG) + log.debug(bundle.toString()); + log.debug("GLIMP BG " + bgReading.toString()); + + try { + MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading); + } catch (SQLException e) { + e.printStackTrace(); + } + MainApp.bus().post(new EventNewBG()); + } + private void handleNewDataFromMM640g(Intent intent) { Bundle bundle = intent.getExtras(); if (bundle == null) return; diff --git a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java index 4787838d4f..1b7b0875e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java @@ -35,4 +35,6 @@ public interface Intents { String NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR"; String ACTION_REMOTE_CALIBRATION = "com.eveningoutpost.dexdrip.NewCalibration"; + + String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java new file mode 100644 index 0000000000..85a4ee9646 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpFragment.java @@ -0,0 +1,16 @@ +package info.nightscout.androidaps.plugins.SourceGlimp; + + +import android.support.v4.app.Fragment; + +import info.nightscout.androidaps.interfaces.FragmentBase; + +public class SourceGlimpFragment extends Fragment implements FragmentBase { + + private static SourceGlimpPlugin sourceGlimpPlugin = new SourceGlimpPlugin(); + + public static SourceGlimpPlugin getPlugin() { + return sourceGlimpPlugin; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java new file mode 100644 index 0000000000..7a5965e3df --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java @@ -0,0 +1,62 @@ +package info.nightscout.androidaps.plugins.SourceGlimp; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.BgSourceInterface; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment; + +/** + * Created by mike on 05.08.2016. + */ +public class SourceGlimpPlugin implements PluginBase, BgSourceInterface { + boolean fragmentEnabled = false; + + @Override + public String getFragmentClass() { + return SourceGlimpFragment.class.getName(); + } + + @Override + public int getType() { + return PluginBase.BGSOURCE; + } + + @Override + public String getName() { + return MainApp.instance().getString(R.string.Glimp); + } + + @Override + public String getNameShort() { + // use long name as fallback (no tabs) + return getName(); + } + + @Override + public boolean isEnabled(int type) { + return type == BGSOURCE && fragmentEnabled; + } + + @Override + public boolean isVisibleInTabs(int type) { + return false; + } + + @Override + public boolean canBeHidden(int type) { + return true; + } + + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled; + } + + @Override + public void setFragmentVisible(int type, boolean fragmentVisible) { + + } + + +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 45688577f3..5c28094f14 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -553,4 +553,5 @@ adult Please select patient age to setup safety limits I_understand + Glimp