MM640g base interface code

This commit is contained in:
Milos Kozak 2016-07-13 15:56:27 +02:00
parent 8681dc5122
commit b81cf8341b
8 changed files with 232 additions and 3 deletions

View file

@ -17,6 +17,8 @@ public class Config {
public static final boolean DANAR = true;
public static final boolean MM640G = true;
public static final boolean detailedLog = true;
public static final boolean logFunctionCalls = true;
public static final boolean logIncommingBG = true;

View file

@ -34,6 +34,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.DanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.LowSuspend.LowSuspendFragment;
import info.nightscout.androidaps.plugins.MM640g.MM640gFragment;
import info.nightscout.androidaps.plugins.NSProfileViewer.NSProfileViewerFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
@ -88,6 +89,7 @@ public class MainActivity extends AppCompatActivity {
// Register all tabs in app here
pluginsList.add(OverviewFragment.newInstance());
if (Config.DANAR) pluginsList.add(DanaRFragment.newInstance());
if (Config.MM640G) pluginsList.add(MM640gFragment.newInstance());
pluginsList.add(VirtualPumpFragment.newInstance());
if (Config.CAREPORTALENABLED) pluginsList.add(CareportalFragment.newInstance());
if (Config.LOOPENABLED) pluginsList.add(LoopFragment.newInstance());

View file

@ -85,6 +85,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
addPreferencesFromResource(R.xml.pref_nightscout);
if (Config.DANAR)
addPreferencesFromResource(R.xml.pref_danar);
if (Config.MM640G)
addPreferencesFromResource(R.xml.pref_mm640g);
if (Config.CAREPORTALENABLED)
addPreferencesFromResource(R.xml.pref_careportal);
initSummary(getPreferenceScreen());

View file

@ -150,7 +150,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
}
void setViews() {
bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.BGSOURCE), PluginBase.BGSOURCE);
bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(BgSourceInterface.class), PluginBase.BGSOURCE);
bgsourceListView.setAdapter(bgsourceDataAdapter);
setListViewHeightBasedOnChildren(bgsourceListView);
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PUMP), PluginBase.PUMP);
@ -455,9 +455,10 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
CheckBox cb = (CheckBox) v;
PluginBase plugin = (PluginBase) cb.getTag();
plugin.setFragmentEnabled(type, cb.isChecked());
if (cb.isChecked()) plugin.setFragmentVisible(type, true);
plugin.setFragmentVisible(type, cb.isChecked());
onEnabledCategoryChanged(plugin, type);
storeSettings();
MainApp.bus().post(new EventRefreshGui());
}
});
@ -569,12 +570,13 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
// this is new selected
} else {
p.setFragmentEnabled(type, false);
setViews();
p.setFragmentVisible(type, false);
}
}
} else { // enable first plugin in list
pluginsInCategory.get(0).setFragmentEnabled(type, true);
}
setViews();
}
}

View file

@ -0,0 +1,205 @@
package info.nightscout.androidaps.plugins.MM640g;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.squareup.otto.Subscribe;
import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.client.data.NSProfile;
public class MM640gFragment extends Fragment implements PluginBase, PumpInterface, BgSourceInterface {
boolean fragmentPumpEnabled = false;
boolean fragmentProfileEnabled = false;
boolean fragmentBgSourceEnabled = false;
boolean fragmentPumpVisible = true;
public MM640gFragment() {
registerBus();
}
public static MM640gFragment newInstance() {
MM640gFragment fragment = new MM640gFragment();
return fragment;
}
private void registerBus() {
try {
MainApp.bus().unregister(this);
} catch (RuntimeException x) {
// Ignore
}
MainApp.bus().register(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.mm640g_fragment, container, false);
return view;
}
/**
* Plugin base interface
*/
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.mm640g);
}
@Override
public boolean isEnabled(int type) {
if (type == PluginBase.PROFILE) return fragmentProfileEnabled;
else if (type == PluginBase.BGSOURCE) return fragmentBgSourceEnabled;
else if (type == PluginBase.PUMP) return fragmentPumpEnabled;
else if (type == PluginBase.CONSTRAINTS) return fragmentPumpEnabled;
return false;
}
@Override
public boolean isVisibleInTabs(int type) {
if (type == PluginBase.PROFILE || type == PluginBase.CONSTRAINTS) return false;
else if (type == PluginBase.PUMP) return fragmentPumpVisible;
return false;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
if (type == PluginBase.PROFILE) this.fragmentProfileEnabled = fragmentEnabled;
if (type == PluginBase.BGSOURCE) this.fragmentBgSourceEnabled = fragmentEnabled;
else if (type == PluginBase.PUMP) this.fragmentPumpEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PluginBase.PUMP)
this.fragmentPumpVisible = fragmentVisible;
}
/**
* Plugin communications
*/
@Subscribe
public void onStatusEvent(final EventPreferenceChange s) {
}
/**
* Pump Interface
*/
@Override
public boolean isTempBasalInProgress() {
return false;
}
@Override
public boolean isExtendedBoluslInProgress() {
return false;
}
@Override
public void setNewBasalProfile(NSProfile profile) {
}
@Override
public double getBaseBasalRate() {
return 0;
}
@Override
public double getTempBasalAbsoluteRate() {
return 0;
}
@Override
public double getTempBasalRemainingMinutes() {
return 0;
}
@Override
public TempBasal getTempBasal(Date time) {
return null;
}
@Override
public TempBasal getTempBasal() {
return null;
}
@Override
public TempBasal getExtendedBolus() {
return null;
}
@Override
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
return new PumpEnactResult();
}
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
return new PumpEnactResult();
}
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
return new PumpEnactResult();
}
@Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
return new PumpEnactResult();
}
@Override
public PumpEnactResult cancelTempBasal() {
return new PumpEnactResult();
}
@Override
public PumpEnactResult cancelExtendedBolus() {
return new PumpEnactResult();
}
@Override
public JSONObject getJSONStatus() {
return new JSONObject();
}
@Override
public String deviceID() {
return "MM640G"; // TODO: probably serial goes here
}
}

View file

@ -0,0 +1,7 @@
<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="info.nightscout.androidaps.plugins.MM640g.MM640gFragment">
</FrameLayout>

View file

@ -243,5 +243,6 @@
<string name="absolute">Absolute</string>
<string name="canceltemp">Cancel temp basal</string>
<string name="smscommunicator">Sms Communicator</string>
<string name="mm640g">MM 640g</string>
</resources>

View file

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