combo plugin skeleton

This commit is contained in:
Milos Kozak 2017-05-24 18:24:23 +02:00 committed by Johannes Mockenhaupt
parent 26ebceb4d9
commit 253c2a34e5
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
9 changed files with 375 additions and 0 deletions

View file

@ -15,6 +15,7 @@ public class Config {
public static final boolean NSCLIENT = BuildConfig.NSCLIENTOLNY;
public static final boolean COMBO = true && BuildConfig.PUMPDRIVERS;
public static final boolean DANAR = true && BuildConfig.PUMPDRIVERS;
public static final boolean DANARv2 = true && BuildConfig.PUMPDRIVERS;

View file

@ -40,6 +40,7 @@ import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPe
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment;
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfileFragment;
import info.nightscout.androidaps.plugins.PumpCombo.ComboFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanFragment;
@ -106,6 +107,7 @@ public class MainApp extends Application {
if (Config.DANAR) pluginsList.add(DanaRFragment.getPlugin());
if (Config.DANAR) pluginsList.add(DanaRKoreanFragment.getPlugin());
if (Config.DANARv2) pluginsList.add(DanaRv2Fragment.getPlugin());
if (Config.COMBO) pluginsList.add(ComboFragment.getPlugin());
pluginsList.add(CareportalFragment.getPlugin());
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance());

View file

@ -14,6 +14,7 @@ import android.preference.PreferenceManager;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
@ -135,6 +136,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
addPreferencesFromResource(R.xml.pref_danarprofile);
}
}
if (Config.COMBO) {
ComboPlugin comboPlugin = (ComboPlugin) MainApp.getSpecificPlugin(ComboPlugin.class);
if (comboPlugin.isEnabled(PluginBase.PUMP)) {
addPreferencesFromResource(R.xml.pref_combo);
}
}
VirtualPumpPlugin virtualPumpPlugin = (VirtualPumpPlugin) MainApp.getSpecificPlugin(VirtualPumpPlugin.class);
if (virtualPumpPlugin != null && virtualPumpPlugin.isEnabled(PluginBase.PUMP)) {
addPreferencesFromResource(R.xml.pref_virtualpump);

View file

@ -0,0 +1,74 @@
package info.nightscout.androidaps.plugins.PumpCombo;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
public class ComboFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(ComboFragment.class);
private static ComboPlugin comboPlugin = new ComboPlugin();
public static ComboPlugin getPlugin() {
return comboPlugin;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.combopump_fragment, container, false);
updateGUI();
return view;
}
@Override
public void onPause() {
super.onPause();
MainApp.bus().unregister(this);
}
@Override
public void onResume() {
super.onResume();
MainApp.bus().register(this);
}
@Subscribe
public void onStatusEvent(final EventComboPumpUpdateGUI ev) {
updateGUI();
}
public void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// your rendering code here
}
});
}
}

View file

@ -0,0 +1,252 @@
package info.nightscout.androidaps.plugins.PumpCombo;
import android.content.Context;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
import info.nightscout.androidaps.plugins.PumpMDI.MDIFragment;
import info.nightscout.androidaps.plugins.TreatmentsFromHistory.TreatmentsFromHistoryPlugin;
import info.nightscout.utils.DateUtil;
/**
* Created by mike on 05.08.2016.
*/
public class ComboPlugin implements PluginBase, PumpInterface {
private static Logger log = LoggerFactory.getLogger(ComboPlugin.class);
boolean fragmentEnabled = false;
boolean fragmentVisible = false;
PumpDescription pumpDescription = new PumpDescription();
public ComboPlugin() {
pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.5d;
pumpDescription.isExtendedBolusCapable = false;
pumpDescription.extendedBolusStep = 0d;
pumpDescription.isTempBasalCapable = false;
pumpDescription.lowTempBasalStyle = PumpDescription.NONE;
pumpDescription.highTempBasalStyle = PumpDescription.NONE;
pumpDescription.maxHighTempPercent = 0;
pumpDescription.maxHighTempAbsolute = 0;
pumpDescription.lowTempPercentStep = 0;
pumpDescription.lowTempAbsoluteStep = 0;
pumpDescription.lowTempPercentDuration = 0;
pumpDescription.lowTempAbsoluteDuration = 0;
pumpDescription.highTempPercentStep = 0;
pumpDescription.highTempAbsoluteStep = 0d;
pumpDescription.highTempPercentDuration = 0;
pumpDescription.highTempAbsoluteDuration = 0;
pumpDescription.isSetBasalProfileCapable = false;
pumpDescription.basalStep = 0d;
pumpDescription.basalMinimumRate = 0d;
pumpDescription.isRefillingCapable = false;
}
@Override
public String getFragmentClass() {
return ComboFragment.class.getName();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.combopump);
}
@Override
public String getNameShort() {
// use long name as fallback (not visible in tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == PUMP && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PUMP && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
if (type == PUMP) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PUMP) this.fragmentVisible = fragmentVisible;
}
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override
public String treatmentPlugin() {
return TreatmentsFromHistoryPlugin.class.getName();
}
@Override
public boolean isInitialized() {
return true;
}
@Override
public boolean isSuspended() {
return false;
}
@Override
public boolean isBusy() {
return false;
}
@Override
public int setNewBasalProfile(NSProfile profile) {
return FAILED;
}
@Override
public boolean isThisProfileSet(NSProfile profile) {
return false;
}
@Override
public Date lastDataTime() {
return new Date();
}
@Override
public void refreshDataFromPump(String reason) {
// this is called regulary from keepalive
}
@Override
public double getBaseBasalRate() {
return 0d;
}
@Override
public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) {
PumpEnactResult result = new PumpEnactResult();
return result;
}
@Override
public void stopBolusDelivering() {
}
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
PumpEnactResult result = new PumpEnactResult();
return result;
}
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
PumpEnactResult result = new PumpEnactResult();
return result;
}
@Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
PumpEnactResult result = new PumpEnactResult();
return result;
}
@Override
public PumpEnactResult cancelTempBasal() {
PumpEnactResult result = new PumpEnactResult();
return result;
}
@Override
public PumpEnactResult cancelExtendedBolus() {
PumpEnactResult result = new PumpEnactResult();
return result;
}
@Override
public JSONObject getJSONStatus() {
JSONObject pump = new JSONObject();
JSONObject status = new JSONObject();
JSONObject extended = new JSONObject();
try {
status.put("status", "normal");
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
try {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getActiveProfile().getProfile().getActiveProfile());
} catch (Exception e) {
}
status.put("timestamp", DateUtil.toISOString(new Date()));
// more info here .... look at dana plugin
pump.put("status", status);
pump.put("extended", extended);
pump.put("clock", DateUtil.toISOString(new Date()));
} catch (JSONException e) {
}
return pump;
}
@Override
public String deviceID() {
// Serial number here
return "Combo";
}
@Override
public PumpDescription getPumpDescription() {
return pumpDescription;
}
@Override
public String shortStatus(boolean veryShort) {
return deviceID();
}
}
// If you want update fragment call
// MainApp.bus().post(new EventComboPumpUpdateGUI());
// fragment should fetch data from plugin and display status, buttons etc ...

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.plugins.PumpCombo.events;
/**
* Created by mike on 24.05.2017.
*/
public class EventComboPumpUpdateGUI {
}

View file

@ -0,0 +1,20 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".plugins.PumpCombo.ComboFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</FrameLayout>

View file

@ -685,4 +685,6 @@
<string name="cpp_valuesnotstored">Values not stored!</string>
<string name="wear_overviewnotifications">Overview Notifications</string>
<string name="wear_overviewnotifications_summary">Pass the Overview Notifications through as wear confirmation messages.</string>
<string name="combopump">Accu-Chek Combo</string>
<string name="combopump_settings">Accu-Chek Combo settings</string>
</resources>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="combopump"
android:title="@string/combopump_settings">
</PreferenceCategory>
</PreferenceScreen>