MM640g bg source
This commit is contained in:
parent
9982004e9a
commit
e2c2f49f6f
7 changed files with 143 additions and 0 deletions
|
@ -63,6 +63,8 @@
|
|||
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
|
||||
<!-- Receiver from xDrip -->
|
||||
<action android:name="com.eveningoutpost.dexdrip.BgEstimate" />
|
||||
<!-- Receiver from 640g uploader -->
|
||||
<action android:name="com.eveningoutpost.dexdrip.NS_EMULATOR" />
|
||||
<!-- Auto start -->
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
|
|
|
@ -33,6 +33,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.SourceMM640g.SourceMM640gFragment;
|
||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
|
||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
|
||||
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
|
||||
|
@ -89,6 +90,7 @@ public class MainApp extends Application {
|
|||
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
|
||||
pluginsList.add(SourceXdripFragment.getPlugin());
|
||||
pluginsList.add(SourceNSClientFragment.getPlugin());
|
||||
pluginsList.add(SourceMM640gFragment.getPlugin());
|
||||
if (Config.SMSCOMMUNICATORENABLED)
|
||||
pluginsList.add(SmsCommunicatorFragment.getPlugin());
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
|
|||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||
|
@ -55,6 +56,7 @@ public class DataService extends IntentService {
|
|||
|
||||
boolean xDripEnabled = false;
|
||||
boolean nsClientEnabled = true;
|
||||
boolean mm640gEnabled = false;
|
||||
|
||||
public DataService() {
|
||||
super("DataService");
|
||||
|
@ -69,9 +71,15 @@ public class DataService extends IntentService {
|
|||
if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
|
||||
xDripEnabled = true;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
||||
xDripEnabled = false;
|
||||
nsClientEnabled = true;
|
||||
mm640gEnabled = false;
|
||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
||||
xDripEnabled = false;
|
||||
nsClientEnabled = false;
|
||||
mm640gEnabled = true;
|
||||
}
|
||||
|
||||
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfile().getClass().equals(NSProfilePlugin.class);
|
||||
|
@ -85,6 +93,10 @@ public class DataService extends IntentService {
|
|||
if (xDripEnabled) {
|
||||
handleNewDataFromXDrip(intent);
|
||||
}
|
||||
} else if (Intents.NS_EMULATOR.equals(action)) {
|
||||
if (mm640gEnabled) {
|
||||
handleNewDataFromMM640g(intent);
|
||||
}
|
||||
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
|
||||
// always handle SGV if NS-Client is the source
|
||||
if (nsClientEnabled) {
|
||||
|
@ -171,6 +183,58 @@ public class DataService extends IntentService {
|
|||
MainApp.bus().post(new EventNewBG());
|
||||
}
|
||||
|
||||
private void handleNewDataFromMM640g(Intent intent) {
|
||||
Bundle bundle = intent.getExtras();
|
||||
if (bundle == null) return;
|
||||
|
||||
final String collection = bundle.getString("collection");
|
||||
if (collection == null) return;
|
||||
|
||||
if (collection.equals("entries")) {
|
||||
final String data = bundle.getString("data");
|
||||
|
||||
if ((data != null) && (data.length() > 0)) {
|
||||
try {
|
||||
final JSONArray json_array = new JSONArray(data);
|
||||
for (int i = 0; i < json_array.length(); i++) {
|
||||
final JSONObject json_object = json_array.getJSONObject(i);
|
||||
final String type = json_object.getString("type");
|
||||
switch (type) {
|
||||
case "sgv":
|
||||
BgReading bgReading = new BgReading();
|
||||
|
||||
bgReading.value = json_object.getDouble("sgv");
|
||||
bgReading.direction = json_object.getString("direction");
|
||||
bgReading.timeIndex = json_object.getLong("date");
|
||||
bgReading.raw = json_object.getDouble("sgv");
|
||||
|
||||
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) {
|
||||
if (Config.logIncommingBG)
|
||||
log.debug("Ignoring old MM640g BG " + bgReading.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (Config.logIncommingBG)
|
||||
log.debug("MM640g BG " + bgReading.toString());
|
||||
|
||||
try {
|
||||
MainApp.getDbHelper().getDaoBgReadings().createIfNotExists(bgReading);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log.debug("Unknown entries type: " + type);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
log.error("Got JSON exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
MainApp.bus().post(new EventNewBG());
|
||||
}
|
||||
|
||||
private void handleNewDataFromNSClient(Intent intent) {
|
||||
Bundle bundles = intent.getExtras();
|
||||
if (bundles == null) return;
|
||||
|
|
|
@ -29,4 +29,6 @@ public interface Intents {
|
|||
String EXTRA_RAW = "com.eveningoutpost.dexdrip.Extras.Raw";
|
||||
|
||||
String ACTION_NEW_BG_ESTIMATE_NO_DATA = "com.eveningoutpost.dexdrip.BgEstimateNoData";
|
||||
|
||||
String NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package info.nightscout.androidaps.plugins.SourceMM640g;
|
||||
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
|
||||
public class SourceMM640gFragment extends Fragment implements FragmentBase {
|
||||
|
||||
private static SourceMM640gPlugin sourceMM640gPlugin = new SourceMM640gPlugin();
|
||||
|
||||
public static SourceMM640gPlugin getPlugin() {
|
||||
return sourceMM640gPlugin;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package info.nightscout.androidaps.plugins.SourceMM640g;
|
||||
|
||||
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.SourceNSClient.SourceNSClientFragment;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
|
||||
boolean fragmentEnabled = true;
|
||||
|
||||
@Override
|
||||
public String getFragmentClass() {
|
||||
return SourceMM640gFragment.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return PluginBase.BGSOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return MainApp.instance().getString(R.string.MM640g);
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -387,4 +387,5 @@
|
|||
<string name="actualbg">BG:</string>
|
||||
<string name="lastbg">Last BG:</string>
|
||||
<string name="mdi">MDI</string>
|
||||
<string name="MM640g">MM640g</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue