Merge branch 'dev' into smb, fix compile, add queue features
This commit is contained in:
commit
622ac15c50
136 changed files with 3204 additions and 1921 deletions
|
@ -45,7 +45,7 @@ android {
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
versionCode 1500
|
versionCode 1500
|
||||||
version "1.54-smb"
|
version "1.56-smb"
|
||||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||||
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "true"
|
buildConfigField "boolean", "CLOSEDLOOP", "true"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
}
|
}
|
||||||
openloop {
|
openloop {
|
||||||
dimension "standard"
|
dimension "standard"
|
||||||
|
@ -87,6 +88,7 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
}
|
}
|
||||||
pumpcontrol {
|
pumpcontrol {
|
||||||
dimension "standard"
|
dimension "standard"
|
||||||
|
@ -99,6 +101,7 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
buildConfigField "boolean", "PUMPDRIVERS", "true"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
}
|
}
|
||||||
nsclient {
|
nsclient {
|
||||||
dimension "standard"
|
dimension "standard"
|
||||||
|
@ -111,6 +114,20 @@ android {
|
||||||
buildConfigField "boolean", "PUMPDRIVERS", "false"
|
buildConfigField "boolean", "PUMPDRIVERS", "false"
|
||||||
buildConfigField "boolean", "NSCLIENTOLNY", "true"
|
buildConfigField "boolean", "NSCLIENTOLNY", "true"
|
||||||
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "false"
|
||||||
|
}
|
||||||
|
g5uploader {
|
||||||
|
dimension "standard"
|
||||||
|
resValue "string", "app_name", "NSClient"
|
||||||
|
versionName version + "-nsclient"
|
||||||
|
manifestPlaceholders = [
|
||||||
|
appIcon: "@mipmap/yellowowl"
|
||||||
|
]
|
||||||
|
buildConfigField "boolean", "APS", "false"
|
||||||
|
buildConfigField "boolean", "PUMPDRIVERS", "false"
|
||||||
|
buildConfigField "boolean", "NSCLIENTOLNY", "false"
|
||||||
|
buildConfigField "boolean", "CLOSEDLOOP", "false"
|
||||||
|
buildConfigField "boolean", "G5UPLOADER", "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +178,7 @@ dependencies {
|
||||||
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
|
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
|
||||||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
|
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
|
||||||
compile(name: 'android-edittext-validator-v1.3.4-mod', ext: 'aar')
|
compile(name: 'android-edittext-validator-v1.3.4-mod', ext: 'aar')
|
||||||
compile ('com.google.android:flexbox:0.3.0') {
|
compile('com.google.android:flexbox:0.3.0') {
|
||||||
exclude group: 'com.android.support'
|
exclude group: 'com.android.support'
|
||||||
}
|
}
|
||||||
compile('io.socket:socket.io-client:0.8.3') {
|
compile('io.socket:socket.io-client:0.8.3') {
|
||||||
|
|
|
@ -42,6 +42,9 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity"
|
android:name=".plugins.Overview.Dialogs.BolusProgressHelperActivity"
|
||||||
android:theme="@style/Theme.AppCompat.Translucent" />
|
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||||
|
<activity
|
||||||
|
android:name=".plugins.Overview.Dialogs.ErrorHelperActivity"
|
||||||
|
android:theme="@style/Theme.AppCompat.Translucent" />
|
||||||
<activity android:name=".AgreementActivity" />
|
<activity android:name=".AgreementActivity" />
|
||||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRHistoryActivity" />
|
<activity android:name=".plugins.PumpDanaR.activities.DanaRHistoryActivity" />
|
||||||
<activity android:name=".plugins.PumpDanaR.activities.DanaRStatsActivity" />
|
<activity android:name=".plugins.PumpDanaR.activities.DanaRStatsActivity" />
|
||||||
|
@ -72,6 +75,8 @@
|
||||||
<action android:name="com.eveningoutpost.dexdrip.NS_EMULATOR" />
|
<action android:name="com.eveningoutpost.dexdrip.NS_EMULATOR" />
|
||||||
<!-- Receiver from glimp -->
|
<!-- Receiver from glimp -->
|
||||||
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
|
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
|
||||||
|
<!-- Receiver from DexcomG5 -->
|
||||||
|
<action android:name="com.dexcom.cgm.DATA" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
<!-- Receiver keepalive, scheduled every 30 min -->
|
<!-- Receiver keepalive, scheduled every 30 min -->
|
||||||
|
@ -140,6 +145,9 @@
|
||||||
android:name=".Services.AlarmSoundService"
|
android:name=".Services.AlarmSoundService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true" />
|
android:exported="true" />
|
||||||
|
<service
|
||||||
|
android:name=".plugins.Overview.notifications.DismissNotificationService"
|
||||||
|
android:exported="false"></service>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="io.fabric.ApiKey"
|
android:name="io.fabric.ApiKey"
|
||||||
|
|
|
@ -10,16 +10,17 @@ public class Config {
|
||||||
public static final boolean APS = BuildConfig.APS;
|
public static final boolean APS = BuildConfig.APS;
|
||||||
// PLUGINS
|
// PLUGINS
|
||||||
public static final boolean NSCLIENT = BuildConfig.NSCLIENTOLNY;
|
public static final boolean NSCLIENT = BuildConfig.NSCLIENTOLNY;
|
||||||
|
public static final boolean G5UPLOADER = BuildConfig.G5UPLOADER;
|
||||||
|
|
||||||
public static final boolean DANAR = true && BuildConfig.PUMPDRIVERS;
|
public static final boolean DANAR = BuildConfig.PUMPDRIVERS;
|
||||||
|
|
||||||
public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean ACTION = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean VIRTUALPUMP = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean MDI = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean MDI = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean OTHERPROFILES = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean OTHERPROFILES = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
public static final boolean SAFETY = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean SAFETY = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
|
|
||||||
public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY;
|
public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER;
|
||||||
|
|
||||||
|
|
||||||
public static final boolean displayDeviationSlope = true;
|
public static final boolean displayDeviationSlope = true;
|
||||||
|
|
|
@ -58,4 +58,7 @@ public class Constants {
|
||||||
|
|
||||||
//Autosens
|
//Autosens
|
||||||
public static final double DEVIATION_TO_BE_EQUAL = 2.0;
|
public static final double DEVIATION_TO_BE_EQUAL = 2.0;
|
||||||
|
|
||||||
|
// Pump
|
||||||
|
public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 60 - 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,7 +369,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
case R.id.nav_about:
|
case R.id.nav_about:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
|
||||||
builder.setTitle(getString(R.string.app_name) + " " + BuildConfig.VERSION);
|
builder.setTitle(getString(R.string.app_name) + " " + BuildConfig.VERSION);
|
||||||
if (Config.NSCLIENT)
|
if (Config.NSCLIENT|| Config.G5UPLOADER)
|
||||||
builder.setIcon(R.mipmap.yellowowl);
|
builder.setIcon(R.mipmap.yellowowl);
|
||||||
else
|
else
|
||||||
builder.setIcon(R.mipmap.blueowl);
|
builder.setIcon(R.mipmap.blueowl);
|
||||||
|
|
|
@ -65,6 +65,7 @@ import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
||||||
|
@ -146,13 +147,16 @@ public class MainApp extends Application {
|
||||||
pluginsList.add(TreatmentsPlugin.getPlugin());
|
pluginsList.add(TreatmentsPlugin.getPlugin());
|
||||||
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
||||||
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||||
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
if (!Config.G5UPLOADER)
|
||||||
if (!Config.NSCLIENT)
|
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
||||||
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
||||||
if (!Config.NSCLIENT)
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
||||||
|
if (!Config.NSCLIENT)
|
||||||
|
pluginsList.add(SourceDexcomG5Plugin.getPlugin());
|
||||||
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
||||||
pluginsList.add(FoodPlugin.getPlugin());
|
pluginsList.add(FoodPlugin.getPlugin());
|
||||||
|
|
||||||
|
@ -171,17 +175,14 @@ public class MainApp extends Application {
|
||||||
else
|
else
|
||||||
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
Answers.getInstance().logCustom(new CustomEvent("AppStart"));
|
||||||
|
|
||||||
Thread t = new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SystemClock.sleep(5000);
|
SystemClock.sleep(5000);
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().readStatus("Initialization", null);
|
||||||
if (pump != null)
|
|
||||||
pump.refreshDataFromPump("Initialization");
|
|
||||||
startKeepAliveService();
|
startKeepAliveService();
|
||||||
}
|
}
|
||||||
}, "pump-initialization");
|
}).start();
|
||||||
t.start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps;
|
package info.nightscout.androidaps;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
|
@ -24,7 +23,6 @@ import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
|
@ -34,6 +32,7 @@ import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
||||||
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin;
|
||||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
||||||
import info.nightscout.utils.LocaleHelper;
|
import info.nightscout.utils.LocaleHelper;
|
||||||
|
@ -47,7 +46,9 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
myPreferenceFragment = new MyPreferenceFragment();
|
myPreferenceFragment = new MyPreferenceFragment();
|
||||||
myPreferenceFragment.setCaller(getIntent());
|
Bundle args = new Bundle();
|
||||||
|
args.putInt("id", getIntent().getIntExtra("id", -1));
|
||||||
|
myPreferenceFragment.setArguments(args);
|
||||||
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +72,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updatePrefSummary(Preference pref) {
|
private static void updatePrefSummary(Preference pref) {
|
||||||
if (pref instanceof ListPreference || pref instanceof BluetoothDevicePreference) {
|
if (pref instanceof ListPreference) {
|
||||||
ListPreference listPref = (ListPreference) pref;
|
ListPreference listPref = (ListPreference) pref;
|
||||||
pref.setSummary(listPref.getEntry());
|
pref.setSummary(listPref.getEntry());
|
||||||
}
|
}
|
||||||
|
@ -84,14 +85,10 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) {
|
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) {
|
||||||
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
|
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
|
||||||
pref.setSummary(editTextPref.getText());
|
pref.setSummary(editTextPref.getText());
|
||||||
} else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().toString().trim())) {
|
} else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().trim())) {
|
||||||
pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary));
|
pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pref instanceof MultiSelectListPreference) {
|
|
||||||
EditTextPreference editTextPref = (EditTextPreference) pref;
|
|
||||||
pref.setSummary(editTextPref.getText());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initSummary(Preference p) {
|
public static void initSummary(Preference p) {
|
||||||
|
@ -106,10 +103,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MyPreferenceFragment extends PreferenceFragment {
|
public static class MyPreferenceFragment extends PreferenceFragment {
|
||||||
Intent caller;
|
private Integer id;
|
||||||
|
|
||||||
public void setCaller(Intent i) {
|
@Override
|
||||||
caller = i;
|
public void setArguments(Bundle args) {
|
||||||
|
super.setArguments(args);
|
||||||
|
id = args.getInt("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) {
|
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) {
|
||||||
|
@ -121,20 +120,24 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Integer id = caller.getIntExtra("id", -1);
|
if (savedInstanceState != null && savedInstanceState.containsKey("id")) {
|
||||||
|
id = savedInstanceState.getInt("id");
|
||||||
|
}
|
||||||
|
|
||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
addPreferencesFromResource(id);
|
addPreferencesFromResource(id);
|
||||||
|
addPreferencesFromResource(R.xml.pref_advanced);
|
||||||
} else {
|
} else {
|
||||||
if (!Config.NSCLIENT) {
|
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||||
addPreferencesFromResource(R.xml.pref_password);
|
addPreferencesFromResource(R.xml.pref_password);
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.pref_age);
|
addPreferencesFromResource(R.xml.pref_age);
|
||||||
addPreferencesFromResource(R.xml.pref_language);
|
addPreferencesFromResource(R.xml.pref_language);
|
||||||
|
|
||||||
if (!Config.NSCLIENT) {
|
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||||
addPreferencesFromResource(R.xml.pref_quickwizard);
|
addPreferencesFromResource(R.xml.pref_quickwizard);
|
||||||
}
|
}
|
||||||
|
addPreferencesFromResourceIfEnabled(SourceDexcomG5Plugin.getPlugin(), PluginBase.BGSOURCE);
|
||||||
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL);
|
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS);
|
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS);
|
||||||
if (Config.APS) {
|
if (Config.APS) {
|
||||||
|
@ -148,7 +151,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY);
|
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY);
|
||||||
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY);
|
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY);
|
||||||
|
|
||||||
if (!Config.NSCLIENT) {
|
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||||
addPreferencesFromResource(R.xml.pref_profile);
|
addPreferencesFromResource(R.xml.pref_profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,14 +169,16 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginBase.PUMP);
|
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||||
|
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginBase.PUMP);
|
||||||
|
}
|
||||||
|
|
||||||
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginBase.INSULIN);
|
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginBase.INSULIN);
|
||||||
|
|
||||||
addPreferencesFromResourceIfEnabled(NSClientInternalPlugin.getPlugin(), PluginBase.GENERAL);
|
addPreferencesFromResourceIfEnabled(NSClientInternalPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL);
|
addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL);
|
||||||
|
|
||||||
if (!Config.NSCLIENT) {
|
if (!Config.NSCLIENT && !Config.G5UPLOADER) {
|
||||||
addPreferencesFromResource(R.xml.pref_others);
|
addPreferencesFromResource(R.xml.pref_others);
|
||||||
}
|
}
|
||||||
addPreferencesFromResource(R.xml.pref_advanced);
|
addPreferencesFromResource(R.xml.pref_advanced);
|
||||||
|
@ -185,6 +190,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
initSummary(getPreferenceScreen());
|
initSummary(getPreferenceScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putInt("id", id);
|
||||||
|
}
|
||||||
|
|
||||||
public Preference getPreference(String key) {
|
public Preference getPreference(String key) {
|
||||||
return findPreference(key);
|
return findPreference(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,14 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||||
|
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
||||||
|
@ -38,6 +39,7 @@ import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||||
import info.nightscout.androidaps.receivers.DataReceiver;
|
import info.nightscout.androidaps.receivers.DataReceiver;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
||||||
import info.nightscout.utils.BundleLogger;
|
import info.nightscout.utils.BundleLogger;
|
||||||
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +50,7 @@ public class DataService extends IntentService {
|
||||||
boolean nsClientEnabled = true;
|
boolean nsClientEnabled = true;
|
||||||
boolean mm640gEnabled = false;
|
boolean mm640gEnabled = false;
|
||||||
boolean glimpEnabled = false;
|
boolean glimpEnabled = false;
|
||||||
|
boolean dexcomG5Enabled = false;
|
||||||
|
|
||||||
public DataService() {
|
public DataService() {
|
||||||
super("DataService");
|
super("DataService");
|
||||||
|
@ -64,21 +67,31 @@ public class DataService extends IntentService {
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = true;
|
nsClientEnabled = true;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = true;
|
mm640gEnabled = true;
|
||||||
glimpEnabled = false;
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) {
|
||||||
xDripEnabled = false;
|
xDripEnabled = false;
|
||||||
nsClientEnabled = false;
|
nsClientEnabled = false;
|
||||||
mm640gEnabled = false;
|
mm640gEnabled = false;
|
||||||
glimpEnabled = true;
|
glimpEnabled = true;
|
||||||
|
dexcomG5Enabled = false;
|
||||||
|
} else if (ConfigBuilderPlugin.getActiveBgSource().getClass().equals(SourceDexcomG5Plugin.class)) {
|
||||||
|
xDripEnabled = false;
|
||||||
|
nsClientEnabled = false;
|
||||||
|
mm640gEnabled = false;
|
||||||
|
glimpEnabled = false;
|
||||||
|
dexcomG5Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
|
boolean isNSProfile = ConfigBuilderPlugin.getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
|
||||||
|
@ -99,6 +112,10 @@ public class DataService extends IntentService {
|
||||||
if (glimpEnabled) {
|
if (glimpEnabled) {
|
||||||
handleNewDataFromGlimp(intent);
|
handleNewDataFromGlimp(intent);
|
||||||
}
|
}
|
||||||
|
} else if (Intents.DEXCOMG5_BG.equals(action)) {
|
||||||
|
if (dexcomG5Enabled) {
|
||||||
|
handleNewDataFromDexcomG5(intent);
|
||||||
|
}
|
||||||
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
|
} else if (Intents.ACTION_NEW_SGV.equals(action)) {
|
||||||
// always handle SGV if NS-Client is the source
|
// always handle SGV if NS-Client is the source
|
||||||
if (nsClientEnabled) {
|
if (nsClientEnabled) {
|
||||||
|
@ -187,6 +204,37 @@ public class DataService extends IntentService {
|
||||||
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
|
MainApp.getDbHelper().createIfNotExists(bgReading, "GLIMP");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleNewDataFromDexcomG5(Intent intent) {
|
||||||
|
// onHandleIntent Bundle{ data => [{"m_time":1511939180,"m_trend":"NotComputable","m_value":335}]; android.support.content.wakelockid => 95; }Bundle
|
||||||
|
|
||||||
|
Bundle bundle = intent.getExtras();
|
||||||
|
if (bundle == null) return;
|
||||||
|
|
||||||
|
BgReading bgReading = new BgReading();
|
||||||
|
|
||||||
|
String data = bundle.getString("data");
|
||||||
|
log.debug("Received Dexcom Data", data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(data);
|
||||||
|
log.debug("Received Dexcom Data size:" + jsonArray.length());
|
||||||
|
for(int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
JSONObject json = jsonArray.getJSONObject(i);
|
||||||
|
bgReading.value = json.getInt("m_value");
|
||||||
|
bgReading.direction = json.getString("m_trend");
|
||||||
|
bgReading.date = json.getLong("m_time") * 1000L;
|
||||||
|
bgReading.raw = 0;
|
||||||
|
boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "DexcomG5");
|
||||||
|
if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
|
||||||
|
NSUpload.uploadBg(bgReading);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleNewDataFromMM640g(Intent intent) {
|
private void handleNewDataFromMM640g(Intent intent) {
|
||||||
Bundle bundle = intent.getExtras();
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundle == null) return;
|
if (bundle == null) return;
|
||||||
|
|
|
@ -45,4 +45,6 @@ public interface Intents {
|
||||||
String ACTION_REMOTE_CALIBRATION = "com.eveningoutpost.dexdrip.NewCalibration";
|
String ACTION_REMOTE_CALIBRATION = "com.eveningoutpost.dexdrip.NewCalibration";
|
||||||
|
|
||||||
String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED";
|
String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED";
|
||||||
|
|
||||||
|
String DEXCOMG5_BG = "com.dexcom.cgm.DATA";
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,15 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.SafeParse;
|
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
|
||||||
public class Profile {
|
public class Profile {
|
||||||
|
@ -30,21 +28,21 @@ public class Profile {
|
||||||
|
|
||||||
private JSONObject json;
|
private JSONObject json;
|
||||||
private String units = null;
|
private String units = null;
|
||||||
double dia = Constants.defaultDIA;
|
private double dia = Constants.defaultDIA;
|
||||||
TimeZone timeZone = TimeZone.getDefault();
|
private TimeZone timeZone = TimeZone.getDefault();
|
||||||
JSONArray isf;
|
private JSONArray isf;
|
||||||
private LongSparseArray<Double> isf_v = null; // oldest at index 0
|
private LongSparseArray<Double> isf_v = null; // oldest at index 0
|
||||||
JSONArray ic;
|
private JSONArray ic;
|
||||||
private LongSparseArray<Double> ic_v = null; // oldest at index 0
|
private LongSparseArray<Double> ic_v = null; // oldest at index 0
|
||||||
JSONArray basal;
|
private JSONArray basal;
|
||||||
private LongSparseArray<Double> basal_v = null; // oldest at index 0
|
private LongSparseArray<Double> basal_v = null; // oldest at index 0
|
||||||
JSONArray targetLow;
|
private JSONArray targetLow;
|
||||||
private LongSparseArray<Double> targetLow_v = null; // oldest at index 0
|
private LongSparseArray<Double> targetLow_v = null; // oldest at index 0
|
||||||
JSONArray targetHigh;
|
private JSONArray targetHigh;
|
||||||
private LongSparseArray<Double> targetHigh_v = null; // oldest at index 0
|
private LongSparseArray<Double> targetHigh_v = null; // oldest at index 0
|
||||||
|
|
||||||
int percentage = 100;
|
private int percentage = 100;
|
||||||
int timeshift = 0;
|
private int timeshift = 0;
|
||||||
|
|
||||||
public Profile(JSONObject json, String units) {
|
public Profile(JSONObject json, String units) {
|
||||||
this(json, 100, 0);
|
this(json, 100, 0);
|
||||||
|
@ -206,7 +204,7 @@ public class Profile {
|
||||||
return shiftedTime;
|
return shiftedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getMultiplier(LongSparseArray<Double> array) {
|
private double getMultiplier(LongSparseArray<Double> array) {
|
||||||
double multiplier = 1d;
|
double multiplier = 1d;
|
||||||
|
|
||||||
if (array == isf_v)
|
if (array == isf_v)
|
||||||
|
@ -220,7 +218,7 @@ public class Profile {
|
||||||
return multiplier;
|
return multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getMultiplier(JSONArray array) {
|
private double getMultiplier(JSONArray array) {
|
||||||
double multiplier = 1d;
|
double multiplier = 1d;
|
||||||
|
|
||||||
if (array == isf)
|
if (array == isf)
|
||||||
|
|
|
@ -32,6 +32,56 @@ public class PumpEnactResult extends Object {
|
||||||
|
|
||||||
public boolean queued = false;
|
public boolean queued = false;
|
||||||
|
|
||||||
|
public PumpEnactResult success(boolean success) {
|
||||||
|
this.success = success;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult enacted(boolean enacted) {
|
||||||
|
this.enacted = enacted;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult comment(String comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult duration(Integer duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult absolute(Double absolute) {
|
||||||
|
this.absolute = absolute;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult isPercent(boolean isPercent) {
|
||||||
|
this.isPercent = isPercent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult isTempCancel(boolean isTempCancel) {
|
||||||
|
this.isTempCancel = isTempCancel;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult bolusDelivered(Double bolusDelivered) {
|
||||||
|
this.bolusDelivered = bolusDelivered;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult carbsDelivered(Double carbsDelivered) {
|
||||||
|
this.carbsDelivered = carbsDelivered;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult queued(boolean queued) {
|
||||||
|
this.queued = queued;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public String log() {
|
public String log() {
|
||||||
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
|
return "Success: " + success + " Enacted: " + enacted + " Comment: " + comment + " Duration: " + duration + " Absolute: " + absolute + " Percent: " + percent + " IsPercent: " + isPercent + " Queued: " + queued;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,9 @@ public class BgReading implements DataPointWithLabelInterface {
|
||||||
direction.compareTo("NOT COMPUTABLE") == 0 ||
|
direction.compareTo("NOT COMPUTABLE") == 0 ||
|
||||||
direction.compareTo("OUT_OF_RANGE") == 0 ||
|
direction.compareTo("OUT_OF_RANGE") == 0 ||
|
||||||
direction.compareTo("OUT OF RANGE") == 0 ||
|
direction.compareTo("OUT OF RANGE") == 0 ||
|
||||||
direction.compareTo("NONE") == 0) {
|
direction.compareTo("NONE") == 0 ||
|
||||||
|
direction.compareTo("NotComputable") == 0
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -343,7 +343,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
// ------------------- BgReading handling -----------------------
|
// ------------------- BgReading handling -----------------------
|
||||||
|
|
||||||
public void createIfNotExists(BgReading bgReading, String from) {
|
public boolean createIfNotExists(BgReading bgReading, String from) {
|
||||||
try {
|
try {
|
||||||
bgReading.date = roundDateToSec(bgReading.date);
|
bgReading.date = roundDateToSec(bgReading.date);
|
||||||
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
|
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
|
||||||
|
@ -351,18 +351,20 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
getDaoBgReadings().create(bgReading);
|
getDaoBgReadings().create(bgReading);
|
||||||
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
||||||
scheduleBgChange();
|
scheduleBgChange();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
if (!old.isEqual(bgReading)) {
|
if (!old.isEqual(bgReading)) {
|
||||||
|
log.debug("BG: Similiar found: " + old.toString());
|
||||||
old.copyFrom(bgReading);
|
old.copyFrom(bgReading);
|
||||||
getDaoBgReadings().update(old);
|
getDaoBgReadings().update(old);
|
||||||
log.debug("BG: Updating record from: " + from + " " + old.toString());
|
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
|
||||||
scheduleBgChange();
|
scheduleBgChange();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleBgChange() {
|
private static void scheduleBgChange() {
|
||||||
|
|
|
@ -72,7 +72,10 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
||||||
name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U ";
|
name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U ";
|
||||||
}
|
}
|
||||||
if (isCPP) {
|
if (isCPP) {
|
||||||
name += "(" + percentage + "%," + timeshift + "h)";
|
name += "(" + percentage + "%";
|
||||||
|
if (timeshift != 0)
|
||||||
|
name += "," + timeshift + "h";
|
||||||
|
name += ")";
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package info.nightscout.androidaps.interfaces;
|
package info.nightscout.androidaps.interfaces;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 12.06.2017.
|
* Created by mike on 12.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface DanaRInterface {
|
public interface DanaRInterface {
|
||||||
boolean loadHistory(byte type);
|
PumpEnactResult loadHistory(byte type); // for history browser
|
||||||
|
PumpEnactResult loadEvents(); // events history to build treatments from
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,20 @@ public interface PumpInterface {
|
||||||
boolean isInitialized();
|
boolean isInitialized();
|
||||||
boolean isSuspended();
|
boolean isSuspended();
|
||||||
boolean isBusy();
|
boolean isBusy();
|
||||||
|
boolean isConnected();
|
||||||
|
boolean isConnecting();
|
||||||
|
|
||||||
|
void connect(String reason);
|
||||||
|
void disconnect(String reason);
|
||||||
|
void stopConnecting();
|
||||||
|
|
||||||
|
void getPumpStatus();
|
||||||
|
|
||||||
// Upload to pump new basal profile
|
// Upload to pump new basal profile
|
||||||
int SUCCESS = 0;
|
PumpEnactResult setNewBasalProfile(Profile profile);
|
||||||
int FAILED = 1;
|
|
||||||
int NOT_NEEDED = 2;
|
|
||||||
int setNewBasalProfile(Profile profile);
|
|
||||||
boolean isThisProfileSet(Profile profile);
|
boolean isThisProfileSet(Profile profile);
|
||||||
|
|
||||||
Date lastDataTime();
|
Date lastDataTime();
|
||||||
void refreshDataFromPump(String reason);
|
|
||||||
|
|
||||||
double getBaseBasalRate(); // base basal rate, not temp basal
|
double getBaseBasalRate(); // base basal rate, not temp basal
|
||||||
|
|
||||||
|
@ -36,7 +40,7 @@ public interface PumpInterface {
|
||||||
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
|
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
|
||||||
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
|
//some pumps might set a very short temp close to 100% as cancelling a temp can be noisy
|
||||||
//when the cancel request is requested by the user (forced), the pump should always do a real cancel
|
//when the cancel request is requested by the user (forced), the pump should always do a real cancel
|
||||||
PumpEnactResult cancelTempBasal(boolean force);
|
PumpEnactResult cancelTempBasal(boolean enforceNew);
|
||||||
PumpEnactResult cancelExtendedBolus();
|
PumpEnactResult cancelExtendedBolus();
|
||||||
|
|
||||||
// Status to be passed to NS
|
// Status to be passed to NS
|
||||||
|
|
|
@ -3,8 +3,6 @@ package info.nightscout.androidaps.plugins.Actions;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -34,6 +32,7 @@ import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
|
@ -54,16 +53,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
Button tempBasalCancel;
|
Button tempBasalCancel;
|
||||||
Button fill;
|
Button fill;
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
public ActionsFragment() {
|
public ActionsFragment() {
|
||||||
super();
|
super();
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(ActionsFragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,14 +126,15 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
fill.setVisibility(View.GONE);
|
fill.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1;
|
boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1;
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !allowProfileSwitch)
|
if (!pump.getPumpDescription().isSetBasalProfileCapable || !pump.isInitialized() || pump.isSuspended() || !allowProfileSwitch)
|
||||||
profileSwitch.setVisibility(View.GONE);
|
profileSwitch.setVisibility(View.GONE);
|
||||||
else
|
else
|
||||||
profileSwitch.setVisibility(View.VISIBLE);
|
profileSwitch.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
if (!pump.getPumpDescription().isExtendedBolusCapable || !pump.isInitialized() || pump.isSuspended() || pump.isFakingTempsByExtendedBoluses()) {
|
||||||
extendedBolus.setVisibility(View.GONE);
|
extendedBolus.setVisibility(View.GONE);
|
||||||
extendedBolusCancel.setVisibility(View.GONE);
|
extendedBolusCancel.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,7 +150,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) {
|
if (!pump.getPumpDescription().isTempBasalCapable || !pump.isInitialized() || pump.isSuspended()) {
|
||||||
tempBasal.setVisibility(View.GONE);
|
tempBasal.setVisibility(View.GONE);
|
||||||
tempBasalCancel.setVisibility(View.GONE);
|
tempBasalCancel.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -166,14 +158,14 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
tempBasal.setVisibility(View.GONE);
|
tempBasal.setVisibility(View.GONE);
|
||||||
tempBasalCancel.setVisibility(View.VISIBLE);
|
tempBasalCancel.setVisibility(View.VISIBLE);
|
||||||
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
tempBasalCancel.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort());
|
tempBasalCancel.setText(MainApp.instance().getString(R.string.cancel) + " " + activeTemp.toStringShort());
|
||||||
} else {
|
} else {
|
||||||
tempBasal.setVisibility(View.VISIBLE);
|
tempBasal.setVisibility(View.VISIBLE);
|
||||||
tempBasalCancel.setVisibility(View.GONE);
|
tempBasalCancel.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended())
|
if (!pump.getPumpDescription().isRefillingCapable || !pump.isInitialized() || pump.isSuspended())
|
||||||
fill.setVisibility(View.GONE);
|
fill.setVisibility(View.GONE);
|
||||||
else
|
else
|
||||||
fill.setVisibility(View.VISIBLE);
|
fill.setVisibility(View.VISIBLE);
|
||||||
|
@ -190,7 +182,6 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getFragmentManager();
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.actions_profileswitch:
|
case R.id.actions_profileswitch:
|
||||||
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
||||||
|
@ -212,24 +203,14 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
|
||||||
break;
|
break;
|
||||||
case R.id.actions_extendedbolus_cancel:
|
case R.id.actions_extendedbolus_cancel:
|
||||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelExtended(null);
|
||||||
@Override
|
Answers.getInstance().logCustom(new CustomEvent("CancelExtended"));
|
||||||
public void run() {
|
|
||||||
pump.cancelExtendedBolus();
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("CancelExtended"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.actions_canceltempbasal:
|
case R.id.actions_canceltempbasal:
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, null);
|
||||||
@Override
|
Answers.getInstance().logCustom(new CustomEvent("CancelTemp"));
|
||||||
public void run() {
|
|
||||||
pump.cancelTempBasal(true);
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("CancelTemp"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R.id.actions_settempbasal:
|
case R.id.actions_settempbasal:
|
||||||
|
|
|
@ -2,9 +2,8 @@ package info.nightscout.androidaps.plugins.Actions.dialogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -27,11 +26,10 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -48,13 +46,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
|
|
||||||
NumberPicker editInsulin;
|
NumberPicker editInsulin;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public FillDialog() {
|
public FillDialog() {
|
||||||
mHandlerThread = new HandlerThread(FillDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +61,7 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||||
|
|
||||||
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
||||||
double bolusstep = MainApp.getConfigBuilder().getPumpDescription().bolusStep;
|
double bolusstep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep;
|
||||||
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
|
editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false);
|
||||||
|
|
||||||
|
@ -158,28 +150,21 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
builder.setPositiveButton(getString(R.string.primefill), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.primefill), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
if (finalInsulinAfterConstraints > 0) {
|
if (finalInsulinAfterConstraints > 0) {
|
||||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
mHandler.post(new Runnable() {
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
|
detailedBolusInfo.context = context;
|
||||||
|
detailedBolusInfo.source = Source.USER;
|
||||||
|
detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history)
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
|
||||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
|
||||||
detailedBolusInfo.context = context;
|
|
||||||
detailedBolusInfo.source = Source.USER;
|
|
||||||
detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history)
|
|
||||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
try {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
i.putExtra("status", result.comment);
|
||||||
builder.setMessage(result.comment);
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
builder.show();
|
MainApp.instance().startActivity(i);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,15 +2,13 @@ package info.nightscout.androidaps.plugins.Actions.dialogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
|
||||||
|
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
|
@ -23,10 +21,9 @@ import java.text.DecimalFormat;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
@ -36,13 +33,7 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
||||||
NumberPicker editInsulin;
|
NumberPicker editInsulin;
|
||||||
NumberPicker editDuration;
|
NumberPicker editDuration;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public NewExtendedBolusDialog() {
|
public NewExtendedBolusDialog() {
|
||||||
mHandlerThread = new HandlerThread(NewExtendedBolusDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,8 +47,8 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
||||||
editInsulin = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_insulin);
|
editInsulin = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_insulin);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, 0.1d, new DecimalFormat("0.00"), false);
|
editInsulin.setParams(0d, 0d, maxInsulin, 0.1d, new DecimalFormat("0.00"), false);
|
||||||
|
|
||||||
double extendedDurationStep = MainApp.getConfigBuilder().getPumpDescription().extendedBolusDurationStep;
|
double extendedDurationStep = ConfigBuilderPlugin.getActivePump().getPumpDescription().extendedBolusDurationStep;
|
||||||
double extendedMaxDuration = MainApp.getConfigBuilder().getPumpDescription().extendedBolusMaxDuration;
|
double extendedMaxDuration = ConfigBuilderPlugin.getActivePump().getPumpDescription().extendedBolusMaxDuration;
|
||||||
editDuration = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_duration);
|
editDuration = (NumberPicker) view.findViewById(R.id.overview_newextendedbolus_duration);
|
||||||
editDuration.setParams(extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, new DecimalFormat("0"), false);
|
editDuration.setParams(extendedDurationStep, extendedDurationStep, extendedMaxDuration, extendedDurationStep, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
|
@ -99,23 +90,16 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
||||||
builder.setMessage(confirmMessage);
|
builder.setMessage(confirmMessage);
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().extendedBolus(finalInsulin, finalDurationInMinutes, new Callback() {
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
try {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
builder.setTitle(context.getString(R.string.treatmentdeliveryerror));
|
i.putExtra("status", result.comment);
|
||||||
builder.setMessage(result.comment);
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
builder.setPositiveButton(context.getString(R.string.ok), null);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
builder.show();
|
MainApp.instance().startActivity(i);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.Actions.dialogs;
|
package info.nightscout.androidaps.plugins.Actions.dialogs;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -26,9 +24,10 @@ import java.text.DecimalFormat;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
@ -47,13 +46,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
||||||
NumberPicker basalAbsolute;
|
NumberPicker basalAbsolute;
|
||||||
NumberPicker duration;
|
NumberPicker duration;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public NewTempBasalDialog() {
|
public NewTempBasalDialog() {
|
||||||
mHandlerThread = new HandlerThread(NewTempBasalDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,7 +63,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
||||||
absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute_radio);
|
absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute_radio);
|
||||||
typeSelectorLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout);
|
typeSelectorLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout);
|
||||||
|
|
||||||
PumpDescription pumpDescription = MainApp.getConfigBuilder().getPumpDescription();
|
PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
|
||||||
|
|
||||||
basalPercent = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalpercentinput);
|
basalPercent = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalpercentinput);
|
||||||
double maxTempPercent = pumpDescription.maxTempPercent;
|
double maxTempPercent = pumpDescription.maxTempPercent;
|
||||||
|
@ -143,37 +136,29 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
||||||
final Double finalBasal = absolute;
|
final Double finalBasal = absolute;
|
||||||
final int finalDurationInMinutes = durationInMinutes;
|
final int finalDurationInMinutes = durationInMinutes;
|
||||||
|
|
||||||
final Context context = getContext();
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||||
builder.setMessage(confirmMessage);
|
builder.setMessage(confirmMessage);
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
Callback callback = new Callback() {
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result;
|
|
||||||
if (setAsPercent) {
|
|
||||||
result = pump.setTempBasalPercent(finalBasalPercent, finalDurationInMinutes);
|
|
||||||
} else {
|
|
||||||
result = pump.setTempBasalAbsolute(finalBasal, finalDurationInMinutes, true);
|
|
||||||
}
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
if (context instanceof Activity) {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
Activity activity = (Activity) context;
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
if (activity.isFinishing()) {
|
i.putExtra("status", result.comment);
|
||||||
return;
|
i.putExtra("title", MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
}
|
MainApp.instance().startActivity(i);
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
|
||||||
builder.setMessage(result.comment);
|
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
|
||||||
builder.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
if (setAsPercent) {
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, callback);
|
||||||
|
} else {
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(finalBasal, finalDurationInMinutes, true, callback);
|
||||||
|
}
|
||||||
Answers.getInstance().logCustom(new CustomEvent("TempBasal"));
|
Answers.getInstance().logCustom(new CustomEvent("TempBasal"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.crashlytics.android.Crashlytics;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
|
@ -104,7 +105,7 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
butonsLayout.setVisibility(View.VISIBLE);
|
butonsLayout.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BuildConfig.NSCLIENTOLNY)
|
if (Config.NSCLIENT || Config.G5UPLOADER)
|
||||||
statsLayout.setVisibility(View.GONE); // visible on overview
|
statsLayout.setVisibility(View.GONE); // visible on overview
|
||||||
|
|
||||||
updateGUI();
|
updateGUI();
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class CareportalPlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showInList(int type) {
|
public boolean showInList(int type) {
|
||||||
return !Config.NSCLIENT;
|
return !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,9 +3,8 @@ package info.nightscout.androidaps.plugins.Careportal.Dialogs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -51,9 +50,10 @@ import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
|
@ -105,10 +105,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
|
|
||||||
Date eventTime;
|
Date eventTime;
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
|
|
||||||
public void setOptions(OptionsToShow options, int event) {
|
public void setOptions(OptionsToShow options, int event) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.event = MainApp.sResources.getString(event);
|
this.event = MainApp.sResources.getString(event);
|
||||||
|
@ -116,11 +112,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
|
|
||||||
public NewNSTreatmentDialog() {
|
public NewNSTreatmentDialog() {
|
||||||
super();
|
super();
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(NewNSTreatmentDialog.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,7 +129,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
if (options==null) return null;
|
if (options == null) return null;
|
||||||
getDialog().setTitle(getString(options.eventName));
|
getDialog().setTitle(getString(options.eventName));
|
||||||
setStyle(DialogFragment.STYLE_NORMAL, getTheme());
|
setStyle(DialogFragment.STYLE_NORMAL, getTheme());
|
||||||
View view = inflater.inflate(R.layout.careportal_newnstreatment_dialog, container, false);
|
View view = inflater.inflate(R.layout.careportal_newnstreatment_dialog, container, false);
|
||||||
|
@ -203,27 +194,30 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
double defaultDuration = 0;
|
double defaultDuration = 0;
|
||||||
double defaultTarget = 0;
|
double defaultTarget = 0;
|
||||||
if(profile!=null){
|
if (profile != null) {
|
||||||
defaultTarget = bg.doubleValue();
|
defaultTarget = bg.doubleValue();
|
||||||
}
|
}
|
||||||
boolean erase = false;
|
boolean erase = false;
|
||||||
|
|
||||||
if(MainApp.sResources.getString(R.string.eatingsoon).equals(reasonList.get(position))){
|
if (MainApp.sResources.getString(R.string.eatingsoon).equals(reasonList.get(position))) {
|
||||||
defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d);
|
defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d);
|
||||||
defaultTarget = SP.getDouble(R.string.key_eatingsoon_target, 0d);;
|
defaultTarget = SP.getDouble(R.string.key_eatingsoon_target, 0d);
|
||||||
} else if (MainApp.sResources.getString(R.string.activity).equals(reasonList.get(position))){
|
;
|
||||||
defaultDuration = SP.getDouble(R.string.key_activity_duration, 0d);;
|
} else if (MainApp.sResources.getString(R.string.activity).equals(reasonList.get(position))) {
|
||||||
defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);;
|
defaultDuration = SP.getDouble(R.string.key_activity_duration, 0d);
|
||||||
|
;
|
||||||
|
defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);
|
||||||
|
;
|
||||||
} else {
|
} else {
|
||||||
defaultDuration = 0;
|
defaultDuration = 0;
|
||||||
erase = true;
|
erase = true;
|
||||||
}
|
}
|
||||||
if(defaultTarget != 0 || erase){
|
if (defaultTarget != 0 || erase) {
|
||||||
editTemptarget.setValue(defaultTarget);
|
editTemptarget.setValue(defaultTarget);
|
||||||
}
|
}
|
||||||
if(defaultDuration != 0){
|
if (defaultDuration != 0) {
|
||||||
editDuration.setValue(defaultDuration);
|
editDuration.setValue(defaultDuration);
|
||||||
} else if (erase){
|
} else if (erase) {
|
||||||
editDuration.setValue(0d);
|
editDuration.setValue(0d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,7 +231,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
// bg
|
// bg
|
||||||
bgUnitsView.setText(units);
|
bgUnitsView.setText(units);
|
||||||
|
|
||||||
TextWatcher bgTextWatcher = new TextWatcher() {
|
TextWatcher bgTextWatcher = new TextWatcher() {
|
||||||
|
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
}
|
}
|
||||||
|
@ -337,15 +331,15 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false);
|
editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false);
|
||||||
|
|
||||||
ProfileSwitch ps = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
ProfileSwitch ps = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
if(ps!=null && ps.isCPP){
|
if (ps != null && ps.isCPP) {
|
||||||
final int percentage = ps.percentage;
|
final int percentage = ps.percentage;
|
||||||
final int timeshift = ps.timeshift;
|
final int timeshift = ps.timeshift;
|
||||||
reuseButton.setText(reuseButton.getText() + " " + percentage + "% " + timeshift +"h");
|
reuseButton.setText(reuseButton.getText() + " " + percentage + "% " + timeshift + "h");
|
||||||
reuseButton.setOnClickListener(new View.OnClickListener() {
|
reuseButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
editPercentage.setValue((double)percentage);
|
editPercentage.setValue((double) percentage);
|
||||||
editTimeshift.setValue((double)timeshift);
|
editTimeshift.setValue((double) timeshift);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -363,7 +357,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_timeshift_layout), options.profile);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_timeshift_layout), options.profile);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps!=null && ps.isCPP);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP);
|
||||||
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
|
showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
@ -674,31 +668,22 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
} else if (options.executeTempTarget) {
|
} else if (options.executeTempTarget) {
|
||||||
try {
|
try {
|
||||||
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) {
|
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) {
|
||||||
sHandler.post(new Runnable() {
|
TempTarget tempTarget = new TempTarget();
|
||||||
@Override
|
tempTarget.date = eventTime.getTime();
|
||||||
public void run() {
|
tempTarget.durationInMinutes = data.getInt("duration");
|
||||||
try {
|
tempTarget.reason = data.getString("reason");
|
||||||
TempTarget tempTarget = new TempTarget();
|
tempTarget.source = Source.USER;
|
||||||
tempTarget.date = eventTime.getTime();
|
if (tempTarget.durationInMinutes != 0) {
|
||||||
tempTarget.durationInMinutes = data.getInt("duration");
|
tempTarget.low = Profile.toMgdl(data.getDouble("targetBottom"), profile.getUnits());
|
||||||
tempTarget.reason = data.getString("reason");
|
tempTarget.high = Profile.toMgdl(data.getDouble("targetTop"), profile.getUnits());
|
||||||
tempTarget.source = Source.USER;
|
} else {
|
||||||
if (tempTarget.durationInMinutes != 0) {
|
tempTarget.low = 0;
|
||||||
tempTarget.low = Profile.toMgdl(data.getDouble("targetBottom"), profile.getUnits());
|
tempTarget.high = 0;
|
||||||
tempTarget.high = Profile.toMgdl(data.getDouble("targetTop"), profile.getUnits());
|
}
|
||||||
} else {
|
log.debug("Creating new TempTarget db record: " + tempTarget.toString());
|
||||||
tempTarget.low = 0;
|
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
||||||
tempTarget.high = 0;
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
}
|
Answers.getInstance().logCustom(new CustomEvent("TempTarget"));
|
||||||
log.debug("Creating new TempTarget db record: " + tempTarget.toString());
|
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("TempTarget"));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -714,64 +699,68 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
|
public static void doProfileSwitch(final ProfileStore profileStore, final String profileName, final int duration, final int percentage, final int timeshift) {
|
||||||
sHandler.post(new Runnable() {
|
ProfileSwitch profileSwitch = new ProfileSwitch();
|
||||||
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
|
profileSwitch.source = Source.USER;
|
||||||
|
profileSwitch.profileName = profileName;
|
||||||
|
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
||||||
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
||||||
|
profileSwitch.durationInMinutes = duration;
|
||||||
|
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
||||||
|
profileSwitch.timeshift = timeshift;
|
||||||
|
profileSwitch.percentage = percentage;
|
||||||
|
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||||
|
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ProfileSwitch profileSwitch = new ProfileSwitch();
|
if (!result.success) {
|
||||||
profileSwitch.date = System.currentTimeMillis();
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
profileSwitch.source = Source.USER;
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
profileSwitch.profileName = profileName;
|
i.putExtra("status", result.comment);
|
||||||
profileSwitch.profileJson = profileStore.getSpecificProfile(profileName).getData().toString();
|
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
|
||||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
profileSwitch.durationInMinutes = duration;
|
MainApp.instance().startActivity(i);
|
||||||
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
|
||||||
profileSwitch.timeshift = timeshift;
|
|
||||||
profileSwitch.percentage = percentage;
|
|
||||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
if (pump != null) {
|
|
||||||
pump.setNewBasalProfile(profileSwitch.getProfileObject());
|
|
||||||
MainApp.bus().post(new EventNewBasalProfile());
|
|
||||||
} else {
|
|
||||||
log.error("No active pump selected");
|
|
||||||
}
|
}
|
||||||
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
MainApp.bus().post(new EventNewBasalProfile());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
|
public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) {
|
||||||
sHandler.post(new Runnable() {
|
ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
@Override
|
if (profileSwitch != null) {
|
||||||
public void run() {
|
profileSwitch = new ProfileSwitch();
|
||||||
ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
profileSwitch.date = System.currentTimeMillis();
|
||||||
if (profileSwitch != null) {
|
profileSwitch.source = Source.USER;
|
||||||
profileSwitch = new ProfileSwitch();
|
profileSwitch.profileName = MainApp.getConfigBuilder().getProfileName(System.currentTimeMillis(), false);
|
||||||
profileSwitch.date = System.currentTimeMillis();
|
profileSwitch.profileJson = MainApp.getConfigBuilder().getProfile().getData().toString();
|
||||||
profileSwitch.source = Source.USER;
|
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
||||||
profileSwitch.profileName = MainApp.getConfigBuilder().getProfileName(System.currentTimeMillis(), false);
|
profileSwitch.durationInMinutes = duration;
|
||||||
profileSwitch.profileJson = MainApp.getConfigBuilder().getProfile().getData().toString();
|
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
||||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
profileSwitch.timeshift = timeshift;
|
||||||
profileSwitch.durationInMinutes = duration;
|
profileSwitch.percentage = percentage;
|
||||||
profileSwitch.isCPP = percentage != 100 || timeshift != 0;
|
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
||||||
profileSwitch.timeshift = timeshift;
|
|
||||||
profileSwitch.percentage = percentage;
|
|
||||||
MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch);
|
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().setProfile(profileSwitch.getProfileObject(), new Callback() {
|
||||||
if (pump != null) {
|
@Override
|
||||||
pump.setNewBasalProfile(profileSwitch.getProfileObject());
|
public void run() {
|
||||||
MainApp.bus().post(new EventNewBasalProfile());
|
if (!result.success) {
|
||||||
} else {
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
log.error("No active pump selected");
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
|
i.putExtra("status", result.comment);
|
||||||
|
i.putExtra("title", MainApp.sResources.getString(R.string.failedupdatebasalprofile));
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
MainApp.bus().post(new EventNewBasalProfile());
|
||||||
} else {
|
|
||||||
log.error("No profile switch existing");
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
Answers.getInstance().logCustom(new CustomEvent("ProfileSwitch"));
|
||||||
|
} else {
|
||||||
|
log.error("No profile switch existing");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,6 +270,23 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
holder.name.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
final PluginBase plugin = (PluginBase) v.getTag();
|
||||||
|
PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Intent i = new Intent(getContext(), PreferencesActivity.class);
|
||||||
|
i.putExtra("id", plugin.getPreferencesId());
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
holder = (PluginViewHolder) view.getTag();
|
holder = (PluginViewHolder) view.getTag();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.ConfigBuilder;
|
package info.nightscout.androidaps.plugins.ConfigBuilder;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -14,7 +10,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
|
@ -34,33 +29,29 @@ import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventBolusRequested;
|
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperActivity;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
import info.nightscout.androidaps.queue.CommandQueue;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class ConfigBuilderPlugin implements PluginBase, PumpInterface, ConstraintsInterface, TreatmentsInterface {
|
public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, TreatmentsInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
|
||||||
|
|
||||||
private static BgSourceInterface activeBgSource;
|
private static BgSourceInterface activeBgSource;
|
||||||
|
@ -79,12 +70,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
private static ArrayList<PluginBase> pluginList;
|
private static ArrayList<PluginBase> pluginList;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
private static CommandQueue commandQueue = new CommandQueue();
|
||||||
|
|
||||||
public ConfigBuilderPlugin() {
|
public ConfigBuilderPlugin() {
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "ConfigBuilderPlugin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -199,6 +188,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
verifySelectionInCategories();
|
verifySelectionInCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CommandQueue getCommandQueue() {
|
||||||
|
return commandQueue;
|
||||||
|
}
|
||||||
|
|
||||||
public static BgSourceInterface getActiveBgSource() {
|
public static BgSourceInterface getActiveBgSource() {
|
||||||
return activeBgSource;
|
return activeBgSource;
|
||||||
}
|
}
|
||||||
|
@ -359,243 +352,33 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Pump interface
|
|
||||||
*
|
|
||||||
* Config builder return itself as a pump and check constraints before it passes command to pump driver
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isInitialized() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isInitialized();
|
|
||||||
else return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSuspended() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isSuspended();
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isBusy() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isBusy();
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setNewBasalProfile(Profile profile) {
|
|
||||||
// Compare with pump limits
|
|
||||||
Profile.BasalValue[] basalValues = profile.getBasalValues();
|
|
||||||
|
|
||||||
for (int index = 0; index < basalValues.length; index++) {
|
|
||||||
if (basalValues[index].value < getPumpDescription().basalMinimumRate) {
|
|
||||||
Notification notification = new Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, MainApp.sResources.getString(R.string.basalvaluebelowminimum), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
return FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.BASAL_VALUE_BELOW_MINIMUM));
|
|
||||||
|
|
||||||
if (isThisProfileSet(profile)) {
|
|
||||||
log.debug("Correct profile already set");
|
|
||||||
return NOT_NEEDED;
|
|
||||||
} else if (activePump != null) {
|
|
||||||
return activePump.setNewBasalProfile(profile);
|
|
||||||
} else
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.isThisProfileSet(profile);
|
|
||||||
else return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Date lastDataTime() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.lastDataTime();
|
|
||||||
else return new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (activePump != null)
|
|
||||||
activePump.refreshDataFromPump(reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getBaseBasalRate() {
|
|
||||||
if (activePump != null)
|
|
||||||
return activePump.getBaseBasalRate();
|
|
||||||
else
|
|
||||||
return 0d;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
|
||||||
mWakeLock.acquire();
|
|
||||||
PumpEnactResult result;
|
|
||||||
detailedBolusInfo.insulin = applyBolusConstraints(detailedBolusInfo.insulin);
|
|
||||||
detailedBolusInfo.carbs = applyCarbsConstraints((int) detailedBolusInfo.carbs);
|
|
||||||
|
|
||||||
BolusProgressDialog bolusProgressDialog = null;
|
|
||||||
if (detailedBolusInfo.context != null) {
|
|
||||||
bolusProgressDialog = new BolusProgressDialog();
|
|
||||||
bolusProgressDialog.setInsulin(detailedBolusInfo.insulin);
|
|
||||||
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
|
||||||
} else if (detailedBolusInfo.isSMB) {
|
|
||||||
// do not show bolus progress dialog
|
|
||||||
} else {
|
|
||||||
Intent i = new Intent();
|
|
||||||
i.putExtra("insulin", detailedBolusInfo.insulin);
|
|
||||||
i.setClass(MainApp.instance(), BolusProgressHelperActivity.class);
|
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
MainApp.instance().startActivity(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
|
|
||||||
|
|
||||||
result = activePump.deliverTreatment(detailedBolusInfo);
|
|
||||||
|
|
||||||
BolusProgressDialog.bolusEnded = true;
|
|
||||||
MainApp.bus().post(new EventDismissBolusprogressIfRunning(result));
|
|
||||||
|
|
||||||
mWakeLock.release();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopBolusDelivering() {
|
|
||||||
activePump.stopBolusDelivering();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* apply constraints, set temp based on absolute valus and expecting absolute result
|
|
||||||
*
|
|
||||||
* @param absoluteRate
|
|
||||||
* @param durationInMinutes
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean force) {
|
|
||||||
Double rateAfterConstraints = applyBasalConstraints(absoluteRate);
|
|
||||||
PumpEnactResult result = activePump.setTempBasalAbsolute(rateAfterConstraints, durationInMinutes, force);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("setTempBasalAbsolute rate: " + rateAfterConstraints + " durationInMinutes: " + durationInMinutes + " success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
|
||||||
return setTempBasalAbsolute(absoluteRate, durationInMinutes, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* apply constraints, set temp based on percent and expecting result in percent
|
|
||||||
*
|
|
||||||
* @param percent 0 ... 100 ...
|
|
||||||
* @param durationInMinutes
|
|
||||||
* @return result
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
|
||||||
Integer percentAfterConstraints = applyBasalConstraints(percent);
|
|
||||||
PumpEnactResult result = activePump.setTempBasalPercent(percentAfterConstraints, durationInMinutes);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("setTempBasalPercent percent: " + percentAfterConstraints + " durationInMinutes: " + durationInMinutes + " success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
|
||||||
Double rateAfterConstraints = applyBolusConstraints(insulin);
|
|
||||||
PumpEnactResult result = activePump.setExtendedBolus(rateAfterConstraints, durationInMinutes);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("setExtendedBolus rate: " + rateAfterConstraints + " durationInMinutes: " + durationInMinutes + " success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult cancelTempBasal(boolean force) {
|
|
||||||
PumpEnactResult result = activePump.cancelTempBasal(force);
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("cancelTempBasal success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PumpEnactResult cancelExtendedBolus() {
|
|
||||||
PumpEnactResult result = activePump.cancelExtendedBolus();
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("cancelExtendedBolus success: " + result.success + " enacted: " + result.enacted);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* expect absolute request and allow both absolute and percent response based on pump capabilities
|
* expect absolute request and allow both absolute and percent response based on pump capabilities
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* @return
|
* @return
|
||||||
|
* true if command is going to be executed
|
||||||
|
* false if error
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public PumpEnactResult applyAPSRequest(APSResult request) {
|
public boolean applyAPSRequest(APSResult request, Callback callback) {
|
||||||
|
PumpInterface pump = getActivePump();
|
||||||
request.rate = applyBasalConstraints(request.rate);
|
request.rate = applyBasalConstraints(request.rate);
|
||||||
PumpEnactResult result;
|
|
||||||
|
|
||||||
if (!isInitialized()) {
|
if (!pump.isInitialized()) {
|
||||||
result = new PumpEnactResult();
|
|
||||||
result.comment = MainApp.sResources.getString(R.string.pumpNotInitialized);
|
|
||||||
result.enacted = false;
|
|
||||||
result.success = false;
|
|
||||||
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
|
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpNotInitialized));
|
||||||
return result;
|
if (callback != null) {
|
||||||
}
|
callback.result(new PumpEnactResult().comment(MainApp.sResources.getString(R.string.pumpNotInitialized)).enacted(false).success(false)).run();
|
||||||
|
|
||||||
if (isSuspended()) {
|
|
||||||
result = new PumpEnactResult();
|
|
||||||
result.comment = MainApp.sResources.getString(R.string.pumpsuspended);
|
|
||||||
result.enacted = false;
|
|
||||||
result.success = false;
|
|
||||||
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpsuspended));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("applyAPSRequest: " + request.toString());
|
|
||||||
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - getBaseBasalRate()) < 0.05) {
|
|
||||||
if (isTempBasalInProgress()) {
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("applyAPSRequest: cancelTempBasal()");
|
|
||||||
result = cancelTempBasal(false);
|
|
||||||
} else {
|
|
||||||
result = new PumpEnactResult();
|
|
||||||
result.absolute = request.rate;
|
|
||||||
result.duration = 0;
|
|
||||||
result.enacted = false;
|
|
||||||
result.comment = "Basal set correctly";
|
|
||||||
result.success = true;
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("applyAPSRequest: Basal set correctly");
|
|
||||||
}
|
}
|
||||||
} else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < getPumpDescription().basalStep) {
|
return false;
|
||||||
result = new PumpEnactResult();
|
}
|
||||||
result.absolute = getTempBasalAbsoluteRateHistory();
|
|
||||||
result.duration = getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes();
|
if (pump.isSuspended()) {
|
||||||
result.enacted = false;
|
log.debug("applyAPSRequest: " + MainApp.sResources.getString(R.string.pumpsuspended));
|
||||||
result.comment = "Temp basal set correctly";
|
if (callback != null) {
|
||||||
result.success = true;
|
callback.result(new PumpEnactResult().comment(MainApp.sResources.getString(R.string.pumpsuspended)).enacted(false).success(false)).run();
|
||||||
if (Config.logCongigBuilderActions)
|
}
|
||||||
log.debug("applyAPSRequest: Temp basal set correctly");
|
return false;
|
||||||
} else {
|
|
||||||
if (Config.logCongigBuilderActions)
|
|
||||||
log.debug("applyAPSRequest: setTempBasalAbsolute()");
|
|
||||||
result = setTempBasalAbsolute(request.rate, request.duration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.smb != 0) {
|
if (request.smb != 0) {
|
||||||
|
@ -608,31 +391,44 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
detailedBolusInfo.insulin = request.smb;
|
detailedBolusInfo.insulin = request.smb;
|
||||||
detailedBolusInfo.isSMB = true;
|
detailedBolusInfo.isSMB = true;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.source = Source.USER;
|
||||||
PumpEnactResult smbResult = deliverTreatment(detailedBolusInfo);
|
getCommandQueue().bolus(detailedBolusInfo, callback);
|
||||||
if (smbResult.success)
|
|
||||||
return result;
|
|
||||||
else
|
|
||||||
return smbResult;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
if (Config.logCongigBuilderActions)
|
||||||
|
log.debug("applyAPSRequest: " + request.toString());
|
||||||
@Nullable
|
if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) {
|
||||||
@Override
|
if (isTempBasalInProgress()) {
|
||||||
public JSONObject getJSONStatus() {
|
if (Config.logCongigBuilderActions)
|
||||||
if (activePump != null)
|
log.debug("applyAPSRequest: cancelTempBasal()");
|
||||||
return activePump.getJSONStatus();
|
getCommandQueue().cancelTempBasal(false, callback);
|
||||||
else return null;
|
return true;
|
||||||
}
|
} else {
|
||||||
|
if (Config.logCongigBuilderActions)
|
||||||
@Override
|
log.debug("applyAPSRequest: Basal set correctly");
|
||||||
public String deviceID() {
|
if (callback != null) {
|
||||||
if (activePump != null)
|
callback.result(new PumpEnactResult().absolute(request.rate).duration(0).enacted(false).success(true).comment("Basal set correctly")).run();
|
||||||
return activePump.deviceID();
|
}
|
||||||
else return "No Pump active!";
|
return false;
|
||||||
|
}
|
||||||
|
} else if (isTempBasalInProgress()
|
||||||
|
&& getTempBasalRemainingMinutesFromHistory() > 5
|
||||||
|
&& Math.abs(request.rate - getTempBasalAbsoluteRateHistory()) < pump.getPumpDescription().basalStep) {
|
||||||
|
if (Config.logCongigBuilderActions)
|
||||||
|
log.debug("applyAPSRequest: Temp basal set correctly");
|
||||||
|
if (callback != null) {
|
||||||
|
callback.result(new PumpEnactResult().absolute(getTempBasalAbsoluteRateHistory()).duration(getTempBasalFromHistory(System.currentTimeMillis()).getPlannedRemainingMinutes()).enacted(false).success(true).comment("Temp basal set correctly")).run();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (Config.logCongigBuilderActions)
|
||||||
|
log.debug("applyAPSRequest: setTempBasalAbsolute()");
|
||||||
|
getCommandQueue().tempBasalAbsolute(request.rate, request.duration, false, callback);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public PumpDescription getPumpDescription() {
|
public PumpDescription getPumpDescription() {
|
||||||
if (activePump != null)
|
if (activePump != null)
|
||||||
|
@ -647,20 +443,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return emptyDescription;
|
return emptyDescription;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
@Override
|
|
||||||
public String shortStatus(boolean veryShort) {
|
|
||||||
if (activePump != null) {
|
|
||||||
return activePump.shortStatus(veryShort);
|
|
||||||
} else {
|
|
||||||
return "No Pump active!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isFakingTempsByExtendedBoluses() {
|
|
||||||
return activePump.isFakingTempsByExtendedBoluses();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraints interface
|
* Constraints interface
|
||||||
|
|
|
@ -16,7 +16,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
@Override
|
@Override
|
||||||
public String getNameShort() {
|
public String getNameShort() {
|
||||||
String name = MainApp.sResources.getString(R.string.objectives_shortname);
|
String name = MainApp.sResources.getString(R.string.objectives_shortname);
|
||||||
if (!name.trim().isEmpty()){
|
if (!name.trim().isEmpty()) {
|
||||||
//only if translation exists
|
//only if translation exists
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == CONSTRAINTS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
return type == CONSTRAINTS && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == CONSTRAINTS && fragmentVisible && !BuildConfig.NSCLIENTOLNY;
|
return type == CONSTRAINTS && fragmentVisible && !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,9 +10,10 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.HardLimits;
|
import info.nightscout.utils.HardLimits;
|
||||||
import info.nightscout.utils.Round;
|
import info.nightscout.utils.Round;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -93,7 +94,7 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLoopEnabled() {
|
public boolean isLoopEnabled() {
|
||||||
return MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
return ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package info.nightscout.androidaps.plugins.Insulin;
|
package info.nightscout.androidaps.plugins.Insulin;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Iob;
|
import info.nightscout.androidaps.data.Iob;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +60,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getUserDefinedDia() {
|
public double getUserDefinedDia() {
|
||||||
return MainApp.getConfigBuilder().getProfile() != null ? MainApp.getConfigBuilder().getProfile().getDia() : Constants.defaultDIA;
|
return MainApp.getConfigBuilder().getProfile() != null ? MainApp.getConfigBuilder().getProfile().getDia() : MIN_DIA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,6 +17,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
|
||||||
|
@ -39,13 +40,13 @@ public class APSResult {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
if (changeRequested) {
|
if (changeRequested) {
|
||||||
if (rate == 0 && duration == 0)
|
if (rate == 0 && duration == 0)
|
||||||
return MainApp.sResources.getString(R.string.canceltemp);
|
return MainApp.sResources.getString(R.string.canceltemp);
|
||||||
else
|
else
|
||||||
return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
return MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
||||||
"(" + DecimalFormatter.to2Decimal(rate / configBuilder.getBaseBasalRate() * 100) + "%)\n" +
|
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100) + "%)\n" +
|
||||||
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(duration) + " min\n" +
|
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(duration) + " min\n" +
|
||||||
(smb != 0 ? ("SMB: " + DecimalFormatter.to2Decimal(smb) + " U\n") : "") +
|
(smb != 0 ? ("SMB: " + DecimalFormatter.to2Decimal(smb) + " U\n") : "") +
|
||||||
MainApp.sResources.getString(R.string.reason) + ": " + reason;
|
MainApp.sResources.getString(R.string.reason) + ": " + reason;
|
||||||
|
@ -54,13 +55,13 @@ public class APSResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Spanned toSpanned() {
|
public Spanned toSpanned() {
|
||||||
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
if (changeRequested) {
|
if (changeRequested) {
|
||||||
String ret = "";
|
String ret = "";
|
||||||
if (rate == 0 && duration == 0) ret = MainApp.sResources.getString(R.string.canceltemp);
|
if (rate == 0 && duration == 0) ret = MainApp.sResources.getString(R.string.canceltemp);
|
||||||
else
|
else
|
||||||
ret = "<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
ret = "<b>" + MainApp.sResources.getString(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
|
||||||
"(" + DecimalFormatter.to2Decimal(rate / configBuilder.getBaseBasalRate() * 100) + "%)<br>" +
|
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100) + "%) <br>" +
|
||||||
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" +
|
"<b>" + MainApp.sResources.getString(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>" +
|
||||||
(smb != 0 ? ("<b>" + "SMB" + "</b>: " + DecimalFormatter.to2Decimal(smb) + " U<br>") : "") +
|
(smb != 0 ? ("<b>" + "SMB" + "</b>: " + DecimalFormatter.to2Decimal(smb) + " U<br>") : "") +
|
||||||
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason.replace("<", "<").replace(">", ">");
|
"<b>" + MainApp.sResources.getString(R.string.reason) + "</b>: " + reason.replace("<", "<").replace(">", ">");
|
||||||
|
|
|
@ -6,15 +6,12 @@ import android.app.PendingIntent;
|
||||||
import android.app.TaskStackBuilder;
|
import android.app.TaskStackBuilder;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v7.app.NotificationCompat;
|
import android.support.v7.app.NotificationCompat;
|
||||||
|
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -31,14 +28,14 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
|
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
|
@ -55,14 +52,12 @@ public class LoopPlugin implements PluginBase {
|
||||||
return loopPlugin;
|
return loopPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private boolean fragmentEnabled = false;
|
private boolean fragmentEnabled = false;
|
||||||
private boolean fragmentVisible = false;
|
private boolean fragmentVisible = false;
|
||||||
|
|
||||||
private long loopSuspendedTill = 0L; // end of manual loop suspend
|
private long loopSuspendedTill = 0L; // end of manual loop suspend
|
||||||
private boolean isSuperBolus = false;
|
private boolean isSuperBolus = false;
|
||||||
|
private boolean isDisconnected = false;
|
||||||
|
|
||||||
public class LastRun {
|
public class LastRun {
|
||||||
public APSResult request = null;
|
public APSResult request = null;
|
||||||
|
@ -77,14 +72,10 @@ public class LoopPlugin implements PluginBase {
|
||||||
static public LastRun lastRun = null;
|
static public LastRun lastRun = null;
|
||||||
|
|
||||||
public LoopPlugin() {
|
public LoopPlugin() {
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(LoopPlugin.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L);
|
loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L);
|
||||||
isSuperBolus = SP.getBoolean("isSuperBolus", false);
|
isSuperBolus = SP.getBoolean("isSuperBolus", false);
|
||||||
|
isDisconnected = SP.getBoolean("isDisconnected", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,7 +96,7 @@ public class LoopPlugin implements PluginBase {
|
||||||
@Override
|
@Override
|
||||||
public String getNameShort() {
|
public String getNameShort() {
|
||||||
String name = MainApp.sResources.getString(R.string.loop_shortname);
|
String name = MainApp.sResources.getString(R.string.loop_shortname);
|
||||||
if (!name.trim().isEmpty()){
|
if (!name.trim().isEmpty()) {
|
||||||
//only if translation exists
|
//only if translation exists
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -115,12 +106,14 @@ public class LoopPlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == LOOP && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == LOOP && fragmentEnabled && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == LOOP && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == LOOP && fragmentVisible && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,13 +163,28 @@ public class LoopPlugin implements PluginBase {
|
||||||
public void suspendTo(long endTime) {
|
public void suspendTo(long endTime) {
|
||||||
loopSuspendedTill = endTime;
|
loopSuspendedTill = endTime;
|
||||||
isSuperBolus = false;
|
isSuperBolus = false;
|
||||||
|
isDisconnected = false;
|
||||||
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
||||||
|
SP.putBoolean("isSuperBolus", isSuperBolus);
|
||||||
|
SP.putBoolean("isDisconnected", isDisconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void superBolusTo(long endTime) {
|
public void superBolusTo(long endTime) {
|
||||||
loopSuspendedTill = endTime;
|
loopSuspendedTill = endTime;
|
||||||
isSuperBolus = true;
|
isSuperBolus = true;
|
||||||
|
isDisconnected = false;
|
||||||
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
||||||
|
SP.putBoolean("isSuperBolus", isSuperBolus);
|
||||||
|
SP.putBoolean("isDisconnected", isDisconnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnectTo(long endTime) {
|
||||||
|
loopSuspendedTill = endTime;
|
||||||
|
isSuperBolus = false;
|
||||||
|
isDisconnected = true;
|
||||||
|
SP.putLong("loopSuspendedTill", loopSuspendedTill);
|
||||||
|
SP.putBoolean("isSuperBolus", isSuperBolus);
|
||||||
|
SP.putBoolean("isDisconnected", isDisconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int minutesToEndOfSuspend() {
|
public int minutesToEndOfSuspend() {
|
||||||
|
@ -208,7 +216,7 @@ public class LoopPlugin implements PluginBase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuperBolus() {
|
public boolean isSuperBolus() {
|
||||||
if (loopSuspendedTill == 0)
|
if (loopSuspendedTill == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -222,6 +230,19 @@ public class LoopPlugin implements PluginBase {
|
||||||
return isSuperBolus;
|
return isSuperBolus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDisconnected() {
|
||||||
|
if (loopSuspendedTill == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (loopSuspendedTill <= now) { // time exceeded
|
||||||
|
suspendTo(0L);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return isDisconnected;
|
||||||
|
}
|
||||||
|
|
||||||
public void invoke(String initiator, boolean allowNotification) {
|
public void invoke(String initiator, boolean allowNotification) {
|
||||||
try {
|
try {
|
||||||
if (Config.logFunctionCalls)
|
if (Config.logFunctionCalls)
|
||||||
|
@ -232,10 +253,10 @@ public class LoopPlugin implements PluginBase {
|
||||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopdisabled)));
|
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.loopdisabled)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ConfigBuilderPlugin configBuilder = MainApp.getConfigBuilder();
|
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
APSResult result = null;
|
APSResult result = null;
|
||||||
|
|
||||||
if (configBuilder == null || !isEnabled(PluginBase.LOOP))
|
if (!isEnabled(PluginBase.LOOP))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isSuspended()) {
|
if (isSuspended()) {
|
||||||
|
@ -244,22 +265,22 @@ public class LoopPlugin implements PluginBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configBuilder.isSuspended()) {
|
if (pump.isSuspended()) {
|
||||||
log.debug(MainApp.sResources.getString(R.string.pumpsuspended));
|
log.debug(MainApp.sResources.getString(R.string.pumpsuspended));
|
||||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.pumpsuspended)));
|
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.pumpsuspended)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configBuilder.getProfile() == null) {
|
if (MainApp.getConfigBuilder().getProfile() == null) {
|
||||||
log.debug(MainApp.sResources.getString(R.string.noprofileselected));
|
log.debug(MainApp.sResources.getString(R.string.noprofileselected));
|
||||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected)));
|
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.sResources.getString(R.string.noprofileselected)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if pump info is loaded
|
// Check if pump info is loaded
|
||||||
if (configBuilder.getBaseBasalRate() < 0.01d) return;
|
if (pump.getBaseBasalRate() < 0.01d) return;
|
||||||
|
|
||||||
APSInterface usedAPS = configBuilder.getActiveAPS();
|
APSInterface usedAPS = MainApp.getConfigBuilder().getActiveAPS();
|
||||||
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) {
|
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) {
|
||||||
usedAPS.invoke(initiator);
|
usedAPS.invoke(initiator);
|
||||||
result = usedAPS.getLastAPSResult();
|
result = usedAPS.getLastAPSResult();
|
||||||
|
@ -283,20 +304,19 @@ public class LoopPlugin implements PluginBase {
|
||||||
lastRun.source = ((PluginBase) usedAPS).getName();
|
lastRun.source = ((PluginBase) usedAPS).getName();
|
||||||
lastRun.setByPump = null;
|
lastRun.setByPump = null;
|
||||||
|
|
||||||
if (constraintsInterface.isClosedModeEnabled()) {
|
if (constraintsInterface.isClosedModeEnabled()) {
|
||||||
if (result.changeRequested) {
|
if (result.changeRequested) {
|
||||||
final PumpEnactResult waiting = new PumpEnactResult();
|
final PumpEnactResult waiting = new PumpEnactResult();
|
||||||
final PumpEnactResult previousResult = lastRun.setByPump;
|
final PumpEnactResult previousResult = lastRun.setByPump;
|
||||||
waiting.queued = true;
|
waiting.queued = true;
|
||||||
lastRun.setByPump = waiting;
|
lastRun.setByPump = waiting;
|
||||||
MainApp.bus().post(new EventLoopUpdateGui());
|
MainApp.bus().post(new EventLoopUpdateGui());
|
||||||
sHandler.post(new Runnable() {
|
MainApp.getConfigBuilder().applyAPSRequest(resultAfterConstraints, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final PumpEnactResult applyResult = configBuilder.applyAPSRequest(resultAfterConstraints);
|
|
||||||
Answers.getInstance().logCustom(new CustomEvent("APSRequest"));
|
Answers.getInstance().logCustom(new CustomEvent("APSRequest"));
|
||||||
if (applyResult.enacted || applyResult.success) {
|
if (result.enacted || result.success) {
|
||||||
lastRun.setByPump = applyResult;
|
lastRun.setByPump = result;
|
||||||
lastRun.lastEnact = lastRun.lastAPSRun;
|
lastRun.lastEnact = lastRun.lastAPSRun;
|
||||||
} else {
|
} else {
|
||||||
lastRun.setByPump = previousResult;
|
lastRun.setByPump = previousResult;
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class NSClientInternalPlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showInList(int type) {
|
public boolean showInList(int type) {
|
||||||
return !Config.NSCLIENT;
|
return !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -336,7 +336,9 @@ public class NSDeviceStatus {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
long clock = 0L;
|
long clock = 0L;
|
||||||
if (object.has("created_at"))
|
if (object.has("mills"))
|
||||||
|
clock = object.getLong("mills");
|
||||||
|
else if (object.has("created_at"))
|
||||||
clock = DateUtil.fromISODateString(object.getString("created_at")).getTime();
|
clock = DateUtil.fromISODateString(object.getString("created_at")).getTime();
|
||||||
String device = getDevice();
|
String device = getDevice();
|
||||||
Integer battery = null;
|
Integer battery = null;
|
||||||
|
|
|
@ -58,7 +58,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
|
@ -25,11 +24,10 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
@ -186,7 +184,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
double minBg,
|
double minBg,
|
||||||
double maxBg,
|
double maxBg,
|
||||||
double targetBg,
|
double targetBg,
|
||||||
PumpInterface pump,
|
double basalrate,
|
||||||
IobTotal[] iobArray,
|
IobTotal[] iobArray,
|
||||||
GlucoseStatus glucoseStatus,
|
GlucoseStatus glucoseStatus,
|
||||||
MealData mealData,
|
MealData mealData,
|
||||||
|
@ -210,7 +208,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
mProfile.put("max_daily_safety_multiplier", SP.getInt("openapsama_max_daily_safety_multiplier", 3));
|
mProfile.put("max_daily_safety_multiplier", SP.getInt("openapsama_max_daily_safety_multiplier", 3));
|
||||||
mProfile.put("current_basal_safety_multiplier", SP.getInt("openapsama_current_basal_safety_multiplier", 4));
|
mProfile.put("current_basal_safety_multiplier", SP.getInt("openapsama_current_basal_safety_multiplier", 4));
|
||||||
mProfile.put("skip_neutral_temps", true);
|
mProfile.put("skip_neutral_temps", true);
|
||||||
mProfile.put("current_basal", pump.getBaseBasalRate());
|
mProfile.put("current_basal", basalrate);
|
||||||
mProfile.put("temptargetSet", tempTargetSet);
|
mProfile.put("temptargetSet", tempTargetSet);
|
||||||
mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
||||||
mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
||||||
|
|
|
@ -14,15 +14,15 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -75,12 +75,14 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == APS && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentEnabled && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == APS && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentVisible && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -137,7 +139,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
public void invoke(String initiator) {
|
public void invoke(String initiator) {
|
||||||
log.debug("invoke from " + initiator);
|
log.debug("invoke from " + initiator);
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = null;
|
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -147,7 +149,6 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
||||||
|
@ -215,7 +216,8 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900))
|
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
||||||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
if (!checkOnlyHardLimits(ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), "current_basal", 0.01, 5))
|
||||||
|
return;
|
||||||
|
|
||||||
startPart = new Date();
|
startPart = new Date();
|
||||||
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
||||||
|
@ -229,7 +231,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
start = new Date();
|
start = new Date();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
|
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
||||||
lastAutosensResult.ratio, //autosensDataRatio
|
lastAutosensResult.ratio, //autosensDataRatio
|
||||||
isTempTarget,
|
isTempTarget,
|
||||||
SafeParse.stringToDouble(SP.getString("openapsama_min_5m_carbimpact", "3.0"))//min_5m_carbimpact
|
SafeParse.stringToDouble(SP.getString("openapsama_min_5m_carbimpact", "3.0"))//min_5m_carbimpact
|
||||||
|
@ -248,7 +250,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
||||||
determineBasalResultAMA.changeRequested = false;
|
determineBasalResultAMA.changeRequested = false;
|
||||||
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - MainApp.getConfigBuilder().getBaseBasalRate()) < 0.1)
|
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultAMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||||
determineBasalResultAMA.changeRequested = false;
|
determineBasalResultAMA.changeRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,8 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
public class DetermineBasalAdapterMAJS {
|
public class DetermineBasalAdapterMAJS {
|
||||||
|
@ -155,7 +154,7 @@ public class DetermineBasalAdapterMAJS {
|
||||||
double minBg,
|
double minBg,
|
||||||
double maxBg,
|
double maxBg,
|
||||||
double targetBg,
|
double targetBg,
|
||||||
PumpInterface pump,
|
double basalRate,
|
||||||
IobTotal iobData,
|
IobTotal iobData,
|
||||||
GlucoseStatus glucoseStatus,
|
GlucoseStatus glucoseStatus,
|
||||||
MealData mealData) throws JSONException {
|
MealData mealData) throws JSONException {
|
||||||
|
@ -174,7 +173,7 @@ public class DetermineBasalAdapterMAJS {
|
||||||
mProfile.put("carb_ratio", profile.getIc());
|
mProfile.put("carb_ratio", profile.getIc());
|
||||||
mProfile.put("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
mProfile.put("sens", Profile.toMgdl(profile.getIsf().doubleValue(), units));
|
||||||
|
|
||||||
mProfile.put("current_basal", pump.getBaseBasalRate());
|
mProfile.put("current_basal", basalRate);
|
||||||
|
|
||||||
if (units.equals(Constants.MMOL)) {
|
if (units.equals(Constants.MMOL)) {
|
||||||
mProfile.put("out_units", "mmol/L");
|
mProfile.put("out_units", "mmol/L");
|
||||||
|
|
|
@ -14,13 +14,13 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -63,7 +63,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
@Override
|
@Override
|
||||||
public String getNameShort() {
|
public String getNameShort() {
|
||||||
String name = MainApp.sResources.getString(R.string.oaps_shortname);
|
String name = MainApp.sResources.getString(R.string.oaps_shortname);
|
||||||
if (!name.trim().isEmpty()){
|
if (!name.trim().isEmpty()) {
|
||||||
//only if translation exists
|
//only if translation exists
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -73,12 +73,14 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == APS && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentEnabled && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == APS && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
|
return type == APS && fragmentVisible && pumpCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,7 +147,6 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
||||||
|
@ -213,11 +214,12 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900))
|
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", 2, 900))
|
||||||
return;
|
return;
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
||||||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
if (!checkOnlyHardLimits(ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), "current_basal", 0.01, 5))
|
||||||
|
return;
|
||||||
|
|
||||||
start = new Date();
|
start = new Date();
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobTotal, glucoseStatus, mealData);
|
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -232,7 +234,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
||||||
determineBasalResultMA.changeRequested = false;
|
determineBasalResultMA.changeRequested = false;
|
||||||
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - MainApp.getConfigBuilder().getBaseBasalRate()) < 0.1)
|
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultMA.rate - ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) < 0.1)
|
||||||
determineBasalResultMA.changeRequested = false;
|
determineBasalResultMA.changeRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
double minBg,
|
double minBg,
|
||||||
double maxBg,
|
double maxBg,
|
||||||
double targetBg,
|
double targetBg,
|
||||||
PumpInterface pump,
|
double basalrate,
|
||||||
IobTotal[] iobArray,
|
IobTotal[] iobArray,
|
||||||
GlucoseStatus glucoseStatus,
|
GlucoseStatus glucoseStatus,
|
||||||
MealData mealData,
|
MealData mealData,
|
||||||
|
@ -230,7 +230,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mProfile.put("max_daily_safety_multiplier", SP.getInt("openapsama_max_daily_safety_multiplier", 3));
|
mProfile.put("max_daily_safety_multiplier", SP.getInt("openapsama_max_daily_safety_multiplier", 3));
|
||||||
mProfile.put("current_basal_safety_multiplier", SP.getInt("openapsama_current_basal_safety_multiplier", 4));
|
mProfile.put("current_basal_safety_multiplier", SP.getInt("openapsama_current_basal_safety_multiplier", 4));
|
||||||
mProfile.put("skip_neutral_temps", true);
|
mProfile.put("skip_neutral_temps", true);
|
||||||
mProfile.put("current_basal", pump.getBaseBasalRate());
|
mProfile.put("current_basal", basalrate);
|
||||||
mProfile.put("temptargetSet", tempTargetSet);
|
mProfile.put("temptargetSet", tempTargetSet);
|
||||||
mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true));
|
||||||
mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", 3d));
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
|
@ -77,12 +78,12 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == APS && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
return type == APS && fragmentEnabled && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == APS && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
return type == APS && fragmentVisible && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,7 +150,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.noprofileselected)));
|
||||||
|
@ -230,7 +231,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
start = new Date();
|
start = new Date();
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
|
determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
||||||
lastAutosensResult.ratio, //autosensDataRatio
|
lastAutosensResult.ratio, //autosensDataRatio
|
||||||
isTempTarget,
|
isTempTarget,
|
||||||
true //microBolusAllowed
|
true //microBolusAllowed
|
||||||
|
@ -250,7 +251,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
||||||
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
if (!MainApp.getConfigBuilder().isClosedModeEnabled()) {
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
if (MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - MainApp.getConfigBuilder().getTempBasalAbsoluteRateHistory()) < 0.1)
|
||||||
determineBasalResultSMB.changeRequested = false;
|
determineBasalResultSMB.changeRequested = false;
|
||||||
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - MainApp.getConfigBuilder().getBaseBasalRate()) < 0.1)
|
if (!MainApp.getConfigBuilder().isTempBasalInProgress() && Math.abs(determineBasalResultSMB.rate - pump.getBaseBasalRate()) < 0.1)
|
||||||
determineBasalResultSMB.changeRequested = false;
|
determineBasalResultSMB.changeRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
case R.id.overview_bolusprogress_stop:
|
case R.id.overview_bolusprogress_stop:
|
||||||
log.debug("Stop bolus delivery button pressed");
|
log.debug("Stop bolus delivery button pressed");
|
||||||
stopPressedView.setVisibility(View.VISIBLE);
|
stopPressedView.setVisibility(View.VISIBLE);
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
stopButton.setVisibility(View.INVISIBLE);
|
||||||
pump.stopBolusDelivering();
|
ConfigBuilderPlugin.getActivePump().stopBolusDelivering();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
||||||
if(BolusProgressDialog.running){
|
if (BolusProgressDialog.running) {
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.Services.AlarmSoundService;
|
||||||
|
|
||||||
|
public class ErrorDialog extends DialogFragment implements View.OnClickListener {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(ErrorDialog.class);
|
||||||
|
Button okButton;
|
||||||
|
TextView statusView;
|
||||||
|
ErrorHelperActivity helperActivity;
|
||||||
|
|
||||||
|
static String status;
|
||||||
|
static String title;
|
||||||
|
static int soundId;
|
||||||
|
|
||||||
|
public ErrorDialog() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSound(int soundId) {
|
||||||
|
this.soundId = soundId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHelperActivity(ErrorHelperActivity activity) {
|
||||||
|
this.helperActivity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
getDialog().setTitle(title);
|
||||||
|
View view = inflater.inflate(R.layout.overview_error_dialog, container, false);
|
||||||
|
okButton = (Button) view.findViewById(R.id.overview_error_ok);
|
||||||
|
statusView = (TextView) view.findViewById(R.id.overview_error_status);
|
||||||
|
okButton.setOnClickListener(this);
|
||||||
|
setCancelable(false);
|
||||||
|
|
||||||
|
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||||
|
alarm.putExtra("soundid", soundId);
|
||||||
|
MainApp.instance().startService(alarm);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (getDialog() != null)
|
||||||
|
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
statusView.setText(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismiss() {
|
||||||
|
super.dismiss();
|
||||||
|
if (helperActivity != null) {
|
||||||
|
helperActivity.finish();
|
||||||
|
}
|
||||||
|
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||||
|
MainApp.instance().stopService(alarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.overview_error_ok:
|
||||||
|
log.debug("Error dialog ok button pressed");
|
||||||
|
dismiss();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
public class ErrorHelperActivity extends AppCompatActivity {
|
||||||
|
public ErrorHelperActivity() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
ErrorDialog errorDialog = new ErrorDialog();
|
||||||
|
errorDialog.setHelperActivity(this);
|
||||||
|
errorDialog.setStatus(getIntent().getStringExtra("status"));
|
||||||
|
errorDialog.setSound(getIntent().getIntExtra("soundid", 0));
|
||||||
|
errorDialog.setTitle(getIntent().getStringExtra("title"));
|
||||||
|
errorDialog.show(this.getSupportFragmentManager(), "Error");
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,8 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -30,12 +29,11 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -49,12 +47,11 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
private Integer maxCarbs;
|
private Integer maxCarbs;
|
||||||
private Double maxInsulin;
|
private Double maxInsulin;
|
||||||
|
|
||||||
private Handler mHandler;
|
//one shot guards
|
||||||
|
private boolean accepted;
|
||||||
|
private boolean okClicked;
|
||||||
|
|
||||||
public NewTreatmentDialog() {
|
public NewTreatmentDialog() {
|
||||||
HandlerThread mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final private TextWatcher textWatcher = new TextWatcher() {
|
final private TextWatcher textWatcher = new TextWatcher() {
|
||||||
|
@ -103,15 +100,21 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
||||||
|
|
||||||
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, MainApp.getConfigBuilder().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher);
|
editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public synchronized void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.ok:
|
case R.id.ok:
|
||||||
|
if (okClicked) {
|
||||||
|
log.debug("guarding: ok already clicked");
|
||||||
|
dismiss();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
okClicked = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
||||||
|
@ -132,48 +135,51 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
||||||
final int finalCarbsAfterConstraints = carbsAfterConstraints;
|
final int finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||||
|
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
|
||||||
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||||
builder.setMessage(Html.fromHtml(confirmMessage));
|
builder.setMessage(Html.fromHtml(confirmMessage));
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
synchronized (builder) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
if (accepted) {
|
||||||
mHandler.post(new Runnable() {
|
log.debug("guarding: already accepted");
|
||||||
@Override
|
return;
|
||||||
public void run() {
|
}
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
accepted = true;
|
||||||
if (finalInsulinAfterConstraints == 0)
|
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||||
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
if (finalCarbsAfterConstraints == 0)
|
if (finalInsulinAfterConstraints == 0)
|
||||||
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
|
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
|
||||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
if (finalCarbsAfterConstraints == 0)
|
||||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
|
||||||
detailedBolusInfo.context = context;
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
detailedBolusInfo.context = context;
|
||||||
if (!result.success) {
|
detailedBolusInfo.source = Source.USER;
|
||||||
try {
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
@Override
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
public void run() {
|
||||||
builder.setMessage(result.comment);
|
if (!result.success) {
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
builder.show();
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
i.putExtra("status", result.comment);
|
||||||
// window has been destroyed
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
Answers.getInstance().logCustom(new CustomEvent("Bolus"));
|
||||||
Answers.getInstance().logCustom(new CustomEvent("Bolus"));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(getString(R.string.cancel), null);
|
builder.setNegativeButton(
|
||||||
|
|
||||||
|
getString(R.string.cancel), null);
|
||||||
builder.show();
|
builder.show();
|
||||||
|
|
||||||
dismiss();
|
dismiss();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
|
|
@ -3,9 +3,8 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
@ -32,7 +31,6 @@ import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.mozilla.javascript.tools.debugger.Main;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -47,7 +45,6 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
@ -59,13 +56,11 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|
||||||
import info.nightscout.utils.BolusWizard;
|
import info.nightscout.utils.BolusWizard;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.OKDialog;
|
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -109,16 +104,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
JSONObject boluscalcJSON;
|
JSONObject boluscalcJSON;
|
||||||
boolean cobAvailable = false;
|
boolean cobAvailable = false;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
public static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
|
//one shot guards
|
||||||
|
private boolean accepted;
|
||||||
|
private boolean okClicked;
|
||||||
|
|
||||||
public WizardDialog() {
|
public WizardDialog() {
|
||||||
super();
|
super();
|
||||||
mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -253,7 +246,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
|
|
||||||
editBg.setParams(0d, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, textWatcher);
|
editBg.setParams(0d, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, textWatcher);
|
||||||
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
|
||||||
double bolusstep = MainApp.getConfigBuilder().getPumpDescription().bolusStep;
|
double bolusstep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep;
|
||||||
editCorr.setParams(0d, -maxCorrection, maxCorrection, bolusstep, new DecimalFormat("0.00"), false, textWatcher);
|
editCorr.setParams(0d, -maxCorrection, maxCorrection, bolusstep, new DecimalFormat("0.00"), false, textWatcher);
|
||||||
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
|
editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false);
|
||||||
initDialog();
|
initDialog();
|
||||||
|
@ -300,6 +293,12 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.ok:
|
case R.id.ok:
|
||||||
|
if (okClicked) {
|
||||||
|
log.debug("guarding: ok already clicked");
|
||||||
|
dismiss();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
okClicked = true;
|
||||||
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
|
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
|
||||||
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
||||||
|
|
||||||
|
@ -327,56 +326,63 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
final int carbTime = SafeParse.stringToInt(editCarbTime.getText());
|
final int carbTime = SafeParse.stringToInt(editCarbTime.getText());
|
||||||
final boolean useSuperBolus = superbolusCheckbox.isChecked();
|
final boolean useSuperBolus = superbolusCheckbox.isChecked();
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||||
builder.setMessage(Html.fromHtml(confirmMessage));
|
builder.setMessage(Html.fromHtml(confirmMessage));
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
synchronized (builder) {
|
||||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
if (accepted) {
|
||||||
mHandler.post(new Runnable() {
|
log.debug("guarding: already accepted");
|
||||||
@Override
|
return;
|
||||||
public void run() {
|
}
|
||||||
PumpEnactResult result;
|
accepted = true;
|
||||||
if (useSuperBolus) {
|
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
if (useSuperBolus) {
|
||||||
if (activeloop != null) {
|
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
|
||||||
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
if (activeloop != null) {
|
||||||
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
|
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||||
}
|
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
|
||||||
pump.cancelTempBasal(true);
|
|
||||||
result = pump.setTempBasalAbsolute(0d, 120, true);
|
|
||||||
if (!result.success) {
|
|
||||||
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror), result.comment, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 120, true, new Callback() {
|
||||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
@Override
|
||||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
public void run() {
|
||||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
if (!result.success) {
|
||||||
detailedBolusInfo.context = context;
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
detailedBolusInfo.glucose = bg;
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
detailedBolusInfo.glucoseType = "Manual";
|
i.putExtra("status", result.comment);
|
||||||
detailedBolusInfo.carbTime = carbTime;
|
i.putExtra("title", MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
detailedBolusInfo.source = Source.USER;
|
MainApp.instance().startActivity(i);
|
||||||
result = pump.deliverTreatment(detailedBolusInfo);
|
}
|
||||||
if (!result.success) {
|
|
||||||
try {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
|
||||||
builder.setMessage(result.comment);
|
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
|
||||||
builder.show();
|
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
|
||||||
// window has been destroyed
|
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
});
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
Answers.getInstance().logCustom(new CustomEvent("Wizard"));
|
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||||
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
|
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||||
|
detailedBolusInfo.context = context;
|
||||||
|
detailedBolusInfo.glucose = bg;
|
||||||
|
detailedBolusInfo.glucoseType = "Manual";
|
||||||
|
detailedBolusInfo.carbTime = carbTime;
|
||||||
|
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||||
|
detailedBolusInfo.source = Source.USER;
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!result.success) {
|
||||||
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
|
i.putExtra("status", result.comment);
|
||||||
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Answers.getInstance().logCustom(new CustomEvent("Wizard"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -393,7 +399,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
|
|
||||||
private void initDialog() {
|
private void initDialog() {
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile();
|
ProfileStore profileStore = ConfigBuilderPlugin.getActiveProfileInterface().getProfile();
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile));
|
||||||
|
@ -403,7 +409,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
ArrayList<CharSequence> profileList;
|
ArrayList<CharSequence> profileList;
|
||||||
profileList = profileStore.getProfileList();
|
profileList = profileStore.getProfileList();
|
||||||
profileList.add(0, MainApp.sResources.getString(R.string.active));
|
profileList.add(0, MainApp.sResources.getString(R.string.active));
|
||||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),
|
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(),
|
||||||
R.layout.spinner_centered, profileList);
|
R.layout.spinner_centered, profileList);
|
||||||
|
|
||||||
profileSpinner.setAdapter(adapter);
|
profileSpinner.setAdapter(adapter);
|
||||||
|
@ -444,7 +450,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateInsulin() {
|
private void calculateInsulin() {
|
||||||
ProfileStore profile = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile();
|
ProfileStore profile = ConfigBuilderPlugin.getActiveProfileInterface().getProfile();
|
||||||
if (profileSpinner == null || profileSpinner.getSelectedItem() == null)
|
if (profileSpinner == null || profileSpinner.getSelectedItem() == null)
|
||||||
return; // not initialized yet
|
return; // not initialized yet
|
||||||
String selectedAlternativeProfile = profileSpinner.getSelectedItem().toString();
|
String selectedAlternativeProfile = profileSpinner.getSelectedItem().toString();
|
||||||
|
|
|
@ -5,12 +5,11 @@ import android.app.Activity;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.DashPathEffect;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
@ -26,7 +25,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
@ -37,11 +35,6 @@ import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.answers.Answers;
|
import com.crashlytics.android.answers.Answers;
|
||||||
import com.crashlytics.android.answers.CustomEvent;
|
import com.crashlytics.android.answers.CustomEvent;
|
||||||
import com.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
import com.jjoe64.graphview.ValueDependentColor;
|
|
||||||
import com.jjoe64.graphview.series.BarGraphSeries;
|
|
||||||
import com.jjoe64.graphview.series.DataPoint;
|
|
||||||
import com.jjoe64.graphview.series.LineGraphSeries;
|
|
||||||
import com.jjoe64.graphview.series.Series;
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -50,7 +43,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -69,7 +61,6 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
@ -102,16 +93,17 @@ import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastA
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
|
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.FixedLineGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
|
import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
|
||||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.BolusWizard;
|
import info.nightscout.utils.BolusWizard;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
@ -175,24 +167,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
public static boolean shorttextmode = false;
|
public static boolean shorttextmode = false;
|
||||||
|
|
||||||
|
private boolean accepted;
|
||||||
|
|
||||||
private int rangeToDisplay = 6; // for graph
|
private int rangeToDisplay = 6; // for graph
|
||||||
|
|
||||||
Handler sLoopHandler = new Handler();
|
Handler sLoopHandler = new Handler();
|
||||||
Runnable sRefreshLoop = null;
|
Runnable sRefreshLoop = null;
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private static ScheduledFuture<?> scheduledUpdate = null;
|
private static ScheduledFuture<?> scheduledUpdate = null;
|
||||||
|
|
||||||
public OverviewFragment() {
|
public OverviewFragment() {
|
||||||
super();
|
super();
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(OverviewFragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -211,9 +197,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
View view;
|
View view;
|
||||||
|
|
||||||
if (MainApp.sResources.getBoolean(R.bool.isTablet) && BuildConfig.NSCLIENTOLNY) {
|
if (MainApp.sResources.getBoolean(R.bool.isTablet) && (Config.NSCLIENT || Config.G5UPLOADER)) {
|
||||||
view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false);
|
view = inflater.inflate(R.layout.overview_fragment_nsclient_tablet, container, false);
|
||||||
} else if (BuildConfig.NSCLIENTOLNY) {
|
} else if (Config.NSCLIENT || Config.G5UPLOADER) {
|
||||||
view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false);
|
view = inflater.inflate(R.layout.overview_fragment_nsclient, container, false);
|
||||||
shorttextmode = true;
|
shorttextmode = true;
|
||||||
} else if (smallHeight || landscape) {
|
} else if (smallHeight || landscape) {
|
||||||
|
@ -407,10 +393,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
activeloop.setFragmentVisible(PluginBase.LOOP, false);
|
activeloop.setFragmentVisible(PluginBase.LOOP, false);
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -428,10 +413,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
|
||||||
activeloop.suspendTo(0L);
|
activeloop.suspendTo(0L);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -442,10 +426,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -456,10 +439,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -470,10 +452,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -484,10 +465,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 10 * 60L * 60 * 1000);
|
activeloop.suspendTo(System.currentTimeMillis() + 10 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -496,12 +476,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(600);
|
NSUpload.uploadOpenAPSOffline(600);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 30L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 30L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 30, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 30, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -510,12 +489,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(30);
|
NSUpload.uploadOpenAPSOffline(30);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 60, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 60, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -524,12 +502,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(60);
|
NSUpload.uploadOpenAPSOffline(60);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 2 * 60, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 2 * 60, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -538,12 +515,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NSUpload.uploadOpenAPSOffline(120);
|
NSUpload.uploadOpenAPSOffline(120);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
activeloop.disconnectTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000);
|
||||||
updateGUI("suspendmenu");
|
updateGUI("suspendmenu");
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 3 * 60, true, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 3 * 60, true);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror));
|
||||||
}
|
}
|
||||||
|
@ -589,13 +565,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
treatmentDialogFragment.show(manager, "TreatmentDialog");
|
treatmentDialogFragment.show(manager, "TreatmentDialog");
|
||||||
break;
|
break;
|
||||||
case R.id.overview_pumpstatus:
|
case R.id.overview_pumpstatus:
|
||||||
if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized())
|
if (ConfigBuilderPlugin.getActivePump().isSuspended() || !ConfigBuilderPlugin.getActivePump().isInitialized())
|
||||||
sHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().readStatus("RefreshClicked", null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MainApp.getConfigBuilder().refreshDataFromPump("RefreshClicked");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,14 +582,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
|
builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
|
||||||
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
sHandler.post(new Runnable() {
|
hideTempRecommendation();
|
||||||
|
clearNotification();
|
||||||
|
MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
hideTempRecommendation();
|
if (result.enacted) {
|
||||||
clearNotification();
|
finalLastRun.setByPump = result;
|
||||||
PumpEnactResult applyResult = MainApp.getConfigBuilder().applyAPSRequest(finalLastRun.constraintsProcessed);
|
|
||||||
if (applyResult.enacted) {
|
|
||||||
finalLastRun.setByPump = applyResult;
|
|
||||||
finalLastRun.lastEnact = new Date();
|
finalLastRun.lastEnact = new Date();
|
||||||
finalLastRun.lastOpenModeAccept = new Date();
|
finalLastRun.lastOpenModeAccept = new Date();
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
|
@ -695,40 +665,41 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
||||||
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
accepted = false;
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
|
||||||
builder.setMessage(confirmMessage);
|
builder.setMessage(confirmMessage);
|
||||||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
synchronized (builder) {
|
||||||
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
if (accepted) {
|
||||||
sHandler.post(new Runnable() {
|
log.debug("guarding: already accepted");
|
||||||
@Override
|
return;
|
||||||
public void run() {
|
}
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
accepted = true;
|
||||||
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
|
||||||
detailedBolusInfo.context = context;
|
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||||
detailedBolusInfo.boluscalc = boluscalcJSON;
|
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
|
||||||
detailedBolusInfo.source = Source.USER;
|
detailedBolusInfo.context = context;
|
||||||
PumpEnactResult result = pump.deliverTreatment(detailedBolusInfo);
|
detailedBolusInfo.boluscalc = boluscalcJSON;
|
||||||
if (!result.success) {
|
detailedBolusInfo.source = Source.USER;
|
||||||
try {
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
@Override
|
||||||
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
public void run() {
|
||||||
builder.setMessage(result.comment);
|
if (!result.success) {
|
||||||
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||||
builder.show();
|
i.putExtra("soundid", R.raw.boluserror);
|
||||||
} catch (WindowManager.BadTokenException | NullPointerException e) {
|
i.putExtra("status", result.comment);
|
||||||
// window has been destroyed
|
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
Notification notification = new Notification(Notification.BOLUS_DELIVERY_ERROR, MainApp.sResources.getString(R.string.treatmentdeliveryerror), Notification.URGENT);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
Answers.getInstance().logCustom(new CustomEvent("QuickWizard"));
|
||||||
Answers.getInstance().logCustom(new CustomEvent("QuickWizard"));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -916,7 +887,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
BgReading actualBG = DatabaseHelper.actualBg();
|
BgReading actualBG = DatabaseHelper.actualBg();
|
||||||
BgReading lastBG = DatabaseHelper.lastBg();
|
BgReading lastBG = DatabaseHelper.lastBg();
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
String units = profile.getUnits();
|
String units = profile.getUnits();
|
||||||
|
@ -958,7 +929,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
// open loop mode
|
// open loop mode
|
||||||
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||||
if (Config.APS && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable) {
|
if (Config.APS && pump.getPumpDescription().isTempBasalCapable) {
|
||||||
apsModeView.setVisibility(View.VISIBLE);
|
apsModeView.setVisibility(View.VISIBLE);
|
||||||
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled));
|
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled));
|
||||||
apsModeView.setTextColor(Color.BLACK);
|
apsModeView.setTextColor(Color.BLACK);
|
||||||
|
@ -1003,7 +974,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units));
|
tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units));
|
||||||
tempTargetView.setVisibility(View.VISIBLE);
|
tempTargetView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
if (Config.NSCLIENT && tempTarget == null) {
|
if ((Config.NSCLIENT || Config.G5UPLOADER) && tempTarget == null) {
|
||||||
tempTargetView.setVisibility(View.GONE);
|
tempTargetView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,7 +1025,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
if (activeTemp != null) {
|
if (activeTemp != null) {
|
||||||
basalText = activeTemp.toStringFull() + " ";
|
basalText = activeTemp.toStringFull() + " ";
|
||||||
}
|
}
|
||||||
if (Config.NSCLIENT)
|
if (Config.NSCLIENT || Config.G5UPLOADER)
|
||||||
basalText += "(" + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h)";
|
basalText += "(" + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + " U/h)";
|
||||||
else if (pump.getPumpDescription().isTempBasalCapable) {
|
else if (pump.getPumpDescription().isTempBasalCapable) {
|
||||||
basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)";
|
basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)";
|
||||||
|
@ -1071,15 +1042,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
final ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
final ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
String extendedBolusText = "";
|
String extendedBolusText = "";
|
||||||
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
|
||||||
extendedBolusText = extendedBolus.toString();
|
|
||||||
}
|
|
||||||
if (extendedBolusView != null) { // must not exists in all layouts
|
if (extendedBolusView != null) { // must not exists in all layouts
|
||||||
if (shorttextmode) {
|
if (shorttextmode) {
|
||||||
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
||||||
extendedBolusText = DecimalFormatter.to2Decimal(extendedBolus.absoluteRate()) + "U/h";
|
extendedBolusText = DecimalFormatter.to2Decimal(extendedBolus.absoluteRate()) + "U/h";
|
||||||
} else {
|
|
||||||
extendedBolusText = "";
|
|
||||||
}
|
}
|
||||||
extendedBolusView.setText(extendedBolusText);
|
extendedBolusView.setText(extendedBolusText);
|
||||||
extendedBolusView.setOnClickListener(new View.OnClickListener() {
|
extendedBolusView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -1090,8 +1056,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses()) {
|
||||||
|
extendedBolusText = extendedBolus.toString();
|
||||||
|
}
|
||||||
extendedBolusView.setText(extendedBolusText);
|
extendedBolusView.setText(extendedBolusText);
|
||||||
}
|
}
|
||||||
|
if (extendedBolusText.equals(""))
|
||||||
|
extendedBolusView.setVisibility(View.GONE);
|
||||||
|
else
|
||||||
|
extendedBolusView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
activeProfileView.setText(MainApp.getConfigBuilder().getProfileName());
|
activeProfileView.setText(MainApp.getConfigBuilder().getProfileName());
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.Overview.events;
|
package info.nightscout.androidaps.plugins.Overview.events;
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 03.12.2016.
|
* Created by mike on 03.12.2016.
|
||||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
||||||
|
@ -234,7 +235,7 @@ public class GraphData {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extended bolus
|
// Extended bolus
|
||||||
if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
if (!ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
|
||||||
List<ExtendedBolus> extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList();
|
List<ExtendedBolus> extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList();
|
||||||
|
|
||||||
for (int tx = 0; tx < extendedBoluses.size(); tx++) {
|
for (int tx = 0; tx < extendedBoluses.size(); tx++) {
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Overview.notifications;
|
||||||
|
|
||||||
|
import android.app.IntentService;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
|
|
||||||
|
public class DismissNotificationService extends IntentService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an IntentService. Invoked by your subclass's constructor.
|
||||||
|
*
|
||||||
|
* @param name Used to name the worker thread, important only for debugging.
|
||||||
|
*/
|
||||||
|
public DismissNotificationService(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DismissNotificationService(){
|
||||||
|
super("DismissNotificationService");
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onHandleIntent(@Nullable Intent intent) {
|
||||||
|
MainApp.bus().post(new EventDismissNotification(intent.getIntExtra("alertID", -1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PendingIntent deleteIntent(int id){
|
||||||
|
Intent intent = new Intent(MainApp.instance(), DismissNotificationService.class);
|
||||||
|
intent.putExtra("alertID", id);
|
||||||
|
return PendingIntent.getService(MainApp.instance(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
|
|
||||||
package info.nightscout.androidaps.plugins.Overview;
|
package info.nightscout.androidaps.plugins.Overview.notifications;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -11,8 +14,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
// Added by Rumen for debugging
|
// Added by Rumen for debugging
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 03.12.2016.
|
* Created by mike on 03.12.2016.
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +52,9 @@ public class Notification {
|
||||||
public static final int SHORT_DIA = 21;
|
public static final int SHORT_DIA = 21;
|
||||||
public static final int TOAST_ALARM = 22;
|
public static final int TOAST_ALARM = 22;
|
||||||
public static final int WRONGBASALSTEP = 23;
|
public static final int WRONGBASALSTEP = 23;
|
||||||
public static final int BOLUS_DELIVERY_ERROR = 24;
|
public static final int WRONG_DRIVER = 24;
|
||||||
|
public static final int PUMP_UNREACHABLE = 26;
|
||||||
|
public static final int BG_READINGS_MISSED = 27;
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
public Date date;
|
public Date date;
|
||||||
|
@ -61,9 +65,6 @@ public class Notification {
|
||||||
public NSAlarm nsAlarm = null;
|
public NSAlarm nsAlarm = null;
|
||||||
public Integer soundId = null;
|
public Integer soundId = null;
|
||||||
|
|
||||||
public Notification() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Notification(int id, Date date, String text, int level, Date validTo) {
|
public Notification(int id, Date date, String text, int level, Date validTo) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
|
@ -88,6 +89,27 @@ public class Notification {
|
||||||
this.validTo = new Date(0);
|
this.validTo = new Date(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Notification(int id) {
|
||||||
|
this.id = id;
|
||||||
|
this.date = new Date();
|
||||||
|
this.validTo = new Date(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notification text(String text) {
|
||||||
|
this.text = text;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notification level(int level) {
|
||||||
|
this.level = level;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notification sound(int soundId) {
|
||||||
|
this.soundId = soundId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Notification(NSAlarm nsAlarm) {
|
public Notification(NSAlarm nsAlarm) {
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.validTo = new Date(0);
|
this.validTo = new Date(0);
|
||||||
|
@ -103,7 +125,7 @@ public class Notification {
|
||||||
this.id = NSALARM;
|
this.id = NSALARM;
|
||||||
this.level = NORMAL;
|
this.level = NORMAL;
|
||||||
this.text = nsAlarm.getTile();
|
this.text = nsAlarm.getTile();
|
||||||
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata,false))
|
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata, false))
|
||||||
this.soundId = R.raw.alarm;
|
this.soundId = R.raw.alarm;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -121,8 +143,7 @@ public class Notification {
|
||||||
return true;
|
return true;
|
||||||
if (level == ANNOUNCEMENT)
|
if (level == ANNOUNCEMENT)
|
||||||
return true;
|
return true;
|
||||||
if (level == NORMAL && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata, false))
|
if (level == NORMAL && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata, false)) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (level == URGENT && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_urgent_staledata, false))
|
if (level == URGENT && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_urgent_staledata, false))
|
||||||
|
@ -154,9 +175,9 @@ public class Notification {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isAlarmForStaleData(){
|
static boolean isAlarmForStaleData() {
|
||||||
if(SP.getLong("snoozedTo", 0L) != 0L){
|
if (SP.getLong("snoozedTo", 0L) != 0L) {
|
||||||
if(System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
|
if (System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
|
||||||
//log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo", 0L)-System.currentTimeMillis())/1000+" seconds");
|
//log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo", 0L)-System.currentTimeMillis())/1000+" seconds");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -168,20 +189,20 @@ public class Notification {
|
||||||
int bgReadingAgoMin = (int) (bgReadingAgo / (1000 * 60));
|
int bgReadingAgoMin = (int) (bgReadingAgo / (1000 * 60));
|
||||||
// Added for testing
|
// Added for testing
|
||||||
//bgReadingAgoMin = 20;
|
//bgReadingAgoMin = 20;
|
||||||
log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin);
|
log.debug("bgReadingAgoMin value is:" + bgReadingAgoMin);
|
||||||
Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins");
|
Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins");
|
||||||
boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts();
|
boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts();
|
||||||
log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
|
log.debug("OpenAPS Alerts enabled: " + openAPSEnabledAlerts);
|
||||||
// if no thresshold from Ns get it loccally
|
// if no thresshold from Ns get it loccally
|
||||||
if(threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue,15D);
|
if (threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue, 15D);
|
||||||
// No threshold of OpenAPS Alarm so using the one for BG
|
// No threshold of OpenAPS Alarm so using the one for BG
|
||||||
// Added OpenAPSEnabledAlerts to alarm check
|
// Added OpenAPSEnabledAlerts to alarm check
|
||||||
if((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false))||(bgReadingAgoMin > threshold && openAPSEnabledAlerts)){
|
if ((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false)) || (bgReadingAgoMin > threshold && openAPSEnabledAlerts)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//snoozing for threshold
|
//snoozing for threshold
|
||||||
SP.putLong("snoozedTo", (long) (bgReading.date+(threshold*1000*60L)));
|
SP.putLong("snoozedTo", (long) (bgReading.date + (threshold * 1000 * 60L)));
|
||||||
//log.debug("New bg data is available Alarm is snoozed for next "+threshold*1000*60+" seconds");
|
//log.debug("New bg data is available Alarm is snoozed for next "+threshold*1000*60+" seconds");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,14 @@
|
||||||
package info.nightscout.androidaps.plugins.Overview;
|
package info.nightscout.androidaps.plugins.Overview.notifications;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.media.AudioAttributes;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -8,7 +16,6 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -26,6 +33,7 @@ public class NotificationStore {
|
||||||
private static Logger log = LoggerFactory.getLogger(NotificationStore.class);
|
private static Logger log = LoggerFactory.getLogger(NotificationStore.class);
|
||||||
public List<Notification> store = new ArrayList<Notification>();
|
public List<Notification> store = new ArrayList<Notification>();
|
||||||
public long snoozedUntil = 0L;
|
public long snoozedUntil = 0L;
|
||||||
|
|
||||||
public NotificationStore() {
|
public NotificationStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,21 +57,50 @@ public class NotificationStore {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (n.soundId != null) {
|
|
||||||
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
|
||||||
alarm.putExtra("soundid", n.soundId);
|
|
||||||
MainApp.instance().startService(alarm);
|
|
||||||
}
|
|
||||||
store.add(n);
|
store.add(n);
|
||||||
|
|
||||||
|
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_raise_notifications_as_android_notifications), false)) {
|
||||||
|
raiseSystemNotification(n);
|
||||||
|
} else {
|
||||||
|
if (n.soundId != null) {
|
||||||
|
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||||
|
alarm.putExtra("soundid", n.soundId);
|
||||||
|
MainApp.instance().startService(alarm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
|
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
|
||||||
if(wearPlugin!= null && wearPlugin.isEnabled()) {
|
if (wearPlugin != null && wearPlugin.isEnabled()) {
|
||||||
wearPlugin.overviewNotification(n.id, "OverviewNotification:\n" + n.text);
|
wearPlugin.overviewNotification(n.id, "OverviewNotification:\n" + n.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(store, new NotificationComparator());
|
Collections.sort(store, new NotificationComparator());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void raiseSystemNotification(Notification n) {
|
||||||
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
|
NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.blueowl);
|
||||||
|
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
||||||
|
NotificationCompat.Builder notificationBuilder =
|
||||||
|
new NotificationCompat.Builder(context)
|
||||||
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
|
.setLargeIcon(largeIcon)
|
||||||
|
.setContentText(n.text)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||||
|
.setDeleteIntent(DismissNotificationService.deleteIntent(n.id));
|
||||||
|
if (n.level == Notification.URGENT) {
|
||||||
|
notificationBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000})
|
||||||
|
.setContentTitle(MainApp.sResources.getString(R.string.urgent_alarm))
|
||||||
|
.setSound(sound, AudioAttributes.USAGE_ALARM);
|
||||||
|
} else {
|
||||||
|
notificationBuilder.setVibrate(new long[]{0, 100, 50, 100, 50})
|
||||||
|
.setContentTitle(MainApp.sResources.getString(R.string.info))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
mgr.notify(n.id, notificationBuilder.build());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean remove(int id) {
|
public boolean remove(int id) {
|
||||||
for (int i = 0; i < store.size(); i++) {
|
for (int i = 0; i < store.size(); i++) {
|
||||||
if (get(i).id == id) {
|
if (get(i).id == id) {
|
||||||
|
@ -88,13 +125,13 @@ public class NotificationStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void snoozeTo(long timeToSnooze){
|
public void snoozeTo(long timeToSnooze) {
|
||||||
log.debug("Snoozing alarm until: "+timeToSnooze);
|
log.debug("Snoozing alarm until: " + timeToSnooze);
|
||||||
SP.putLong("snoozedTo", timeToSnooze);
|
SP.putLong("snoozedTo", timeToSnooze);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unSnooze(){
|
public void unSnooze() {
|
||||||
if(Notification.isAlarmForStaleData()){
|
if (Notification.isAlarmForStaleData()) {
|
||||||
Notification notification = new Notification(Notification.NSALARM, MainApp.sResources.getString(R.string.nsalarm_staledata), Notification.URGENT);
|
Notification notification = new Notification(Notification.NSALARM, MainApp.sResources.getString(R.string.nsalarm_staledata), Notification.URGENT);
|
||||||
SP.putLong("snoozedTo", System.currentTimeMillis());
|
SP.putLong("snoozedTo", System.currentTimeMillis());
|
||||||
add(notification);
|
add(notification);
|
|
@ -29,7 +29,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,25 +95,28 @@ public class PersistentNotificationPlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
|
|
||||||
if (getType() == type) {
|
if (getType() == type) {
|
||||||
this.fragmentEnabled = fragmentEnabled;
|
this.fragmentEnabled = fragmentEnabled;
|
||||||
|
enableDisableNotification(fragmentEnabled);
|
||||||
checkBusRegistration();
|
checkBusRegistration();
|
||||||
//updateNotification();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateNotification() {
|
private void enableDisableNotification(boolean fragmentEnabled) {
|
||||||
|
|
||||||
if (!fragmentEnabled) {
|
if (!fragmentEnabled) {
|
||||||
NotificationManager mNotificationManager =
|
NotificationManager mNotificationManager =
|
||||||
(NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
|
(NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
mNotificationManager.cancel(ONGOING_NOTIFICATION_ID);
|
mNotificationManager.cancel(ONGOING_NOTIFICATION_ID);
|
||||||
|
} else {
|
||||||
|
updateNotification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNotification() {
|
||||||
|
if (!fragmentEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String line1 = ctx.getString(R.string.noprofile);
|
String line1 = ctx.getString(R.string.noprofile);
|
||||||
|
|
||||||
if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || MainApp.getConfigBuilder().getProfile() == null)
|
if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || MainApp.getConfigBuilder().getProfile() == null)
|
||||||
|
@ -136,8 +139,6 @@ public class PersistentNotificationPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
|
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||||
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
line1 += " " + activeTemp.toStringShort();
|
line1 += " " + activeTemp.toStringShort();
|
||||||
|
@ -154,7 +155,7 @@ public class PersistentNotificationPlugin implements PluginBase {
|
||||||
+ ctx.getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
+ ctx.getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
||||||
|
|
||||||
|
|
||||||
String line3 = DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + " U/h";
|
String line3 = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h";
|
||||||
|
|
||||||
|
|
||||||
line3 += " - " + MainApp.getConfigBuilder().getProfileName();
|
line3 += " - " + MainApp.getConfigBuilder().getProfileName();
|
||||||
|
@ -191,11 +192,16 @@ public class PersistentNotificationPlugin implements PluginBase {
|
||||||
|
|
||||||
private void checkBusRegistration() {
|
private void checkBusRegistration() {
|
||||||
if (fragmentEnabled) {
|
if (fragmentEnabled) {
|
||||||
MainApp.bus().register(this);
|
try {
|
||||||
|
MainApp.bus().register(this);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// already registered
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().unregister(this);
|
MainApp.bus().unregister(this);
|
||||||
} catch (Exception e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
// already unregistered
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
import info.nightscout.androidaps.events.EventProfileSwitchChange;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
@ -151,8 +151,7 @@ public class CircadianPercentageProfileFragment extends SubscriberFragment {
|
||||||
iceditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_icedit);
|
iceditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_icedit);
|
||||||
isfeditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_isfedit);
|
isfeditIcon = (ImageView) layout.findViewById(R.id.circadianpercentageprofile_isfedit);
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) {
|
||||||
if (!pump.getPumpDescription().isTempBasalCapable) {
|
|
||||||
layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal_layout).setVisibility(View.GONE);
|
layout.findViewById(R.id.circadianpercentageprofile_baseprofilebasal_layout).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +333,8 @@ public class CircadianPercentageProfileFragment extends SubscriberFragment {
|
||||||
adb.setPositiveButton("MIGRATE", new DialogInterface.OnClickListener() {
|
adb.setPositiveButton("MIGRATE", new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
CircadianPercentageProfilePlugin.migrateToLP();
|
CircadianPercentageProfilePlugin.migrateToLP();
|
||||||
} });
|
}
|
||||||
|
});
|
||||||
adb.setNegativeButton("Cancel", null);
|
adb.setNegativeButton("Cancel", null);
|
||||||
adb.show();
|
adb.show();
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ public class CircadianPercentageProfileFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customSnackbar(View view, final String Msg, Object snackbarCaller) {
|
private void customSnackbar(View view, final String Msg, Object snackbarCaller) {
|
||||||
if(mSnackBar!= null) mSnackBar.dismiss();
|
if (mSnackBar != null) mSnackBar.dismiss();
|
||||||
|
|
||||||
this.snackbarCaller = snackbarCaller;
|
this.snackbarCaller = snackbarCaller;
|
||||||
if (timeshiftViewHint || percentageViewHint) {
|
if (timeshiftViewHint || percentageViewHint) {
|
||||||
|
@ -522,7 +522,7 @@ public class CircadianPercentageProfileFragment extends SubscriberFragment {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) {
|
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended()) {
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
profileswitchButton.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
profileswitchButton.setVisibility(View.VISIBLE);
|
profileswitchButton.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -16,12 +16,10 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
|
@ -173,34 +171,33 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
|
|
||||||
if (!fragmentEnabled){
|
if (!fragmentEnabled) {
|
||||||
msg+= "NO CPP!" + "\n";
|
msg += "NO CPP!" + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
//check for validity
|
//check for validity
|
||||||
if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) {
|
if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) {
|
||||||
msg+= String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n";
|
msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n";
|
||||||
}
|
}
|
||||||
if (timeshift < 0 || timeshift > 23) {
|
if (timeshift < 0 || timeshift > 23) {
|
||||||
msg+= String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n";
|
msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n";
|
||||||
}
|
}
|
||||||
if(!SP.getBoolean("syncprofiletopump", false)){
|
if (!SP.getBoolean("syncprofiletopump", false)) {
|
||||||
msg+= MainApp.sResources.getString(R.string.syncprofiletopump_title) + " " + MainApp.sResources.getString(R.string.cpp_sync_setting_missing) + "\n";
|
msg += MainApp.sResources.getString(R.string.syncprofiletopump_title) + " " + MainApp.sResources.getString(R.string.cpp_sync_setting_missing) + "\n";
|
||||||
}
|
}
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
|
||||||
if (pump == null || profile == null || profile.getBasal() == null){
|
if (profile == null || profile.getBasal() == null) {
|
||||||
msg+= MainApp.sResources.getString(R.string.cpp_notloadedplugins) + "\n";
|
msg += MainApp.sResources.getString(R.string.cpp_notloadedplugins) + "\n";
|
||||||
}
|
}
|
||||||
if(!"".equals(msg)) {
|
if (!"".equals(msg)) {
|
||||||
msg += MainApp.sResources.getString(R.string.cpp_valuesnotstored);
|
msg += MainApp.sResources.getString(R.string.cpp_valuesnotstored);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
//store profile
|
//store profile
|
||||||
this.timeshift= timeshift;
|
this.timeshift = timeshift;
|
||||||
this.percentage = percentage;
|
this.percentage = percentage;
|
||||||
storeSettings();
|
storeSettings();
|
||||||
|
|
||||||
|
|
||||||
|
@ -218,7 +215,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void migrateToLP(){
|
public static void migrateToLP() {
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putBoolean("LocalProfile" + "mmol", SP.getBoolean(SETTINGS_PREFIX + "mmol", false));
|
editor.putBoolean("LocalProfile" + "mmol", SP.getBoolean(SETTINGS_PREFIX + "mmol", false));
|
||||||
|
@ -232,7 +229,7 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
JSONArray targetHigh = new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", SP.getDouble(SETTINGS_PREFIX + "targethigh", 120d)));
|
JSONArray targetHigh = new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", SP.getDouble(SETTINGS_PREFIX + "targethigh", 120d)));
|
||||||
editor.putString("LocalProfile" + "targetlow", targetLow.toString());
|
editor.putString("LocalProfile" + "targetlow", targetLow.toString());
|
||||||
editor.putString("LocalProfile" + "targethigh", targetHigh.toString());
|
editor.putString("LocalProfile" + "targethigh", targetHigh.toString());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
@ -247,19 +244,19 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLPisf(){
|
public static String getLPisf() {
|
||||||
return getLPConversion("baseisf", 35d);
|
return getLPConversion("baseisf", 35d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLPic(){
|
public static String getLPic() {
|
||||||
return getLPConversion("baseic", 4);
|
return getLPConversion("baseic", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLPbasal(){
|
public static String getLPbasal() {
|
||||||
return getLPConversion("basebasal", 1);
|
return getLPConversion("basebasal", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLPConversion(String type, double defaultValue){
|
public static String getLPConversion(String type, double defaultValue) {
|
||||||
try {
|
try {
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray jsonArray = new JSONArray();
|
||||||
double last = -1d;
|
double last = -1d;
|
||||||
|
@ -269,10 +266,10 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
|
||||||
String time;
|
String time;
|
||||||
DecimalFormat df = new DecimalFormat("00");
|
DecimalFormat df = new DecimalFormat("00");
|
||||||
time = df.format(i) + ":00";
|
time = df.format(i) + ":00";
|
||||||
if(last != value) {
|
if (last != value) {
|
||||||
jsonArray.put(new JSONObject().put("time", time).put("timeAsSeconds", i * 60 * 60).put("value", value));
|
jsonArray.put(new JSONObject().put("time", time).put("timeAsSeconds", i * 60 * 60).put("value", value));
|
||||||
}
|
}
|
||||||
last = value;
|
last = value;
|
||||||
}
|
}
|
||||||
return jsonArray.toString();
|
return jsonArray.toString();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
|
@ -23,11 +23,11 @@ import java.text.DecimalFormat;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
@ -59,8 +59,8 @@ public class LocalProfileFragment extends SubscriberFragment {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
localProfilePlugin.storeSettings();
|
localProfilePlugin.storeSettings();
|
||||||
if(basalView!=null){
|
if (basalView != null) {
|
||||||
basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label)+ ": "+ getSumLabel());
|
basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -91,12 +91,11 @@ public class LocalProfileFragment extends SubscriberFragment {
|
||||||
mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol);
|
mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol);
|
||||||
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", getPlugin().ic, null, 0.1d, new DecimalFormat("0.0"), save);
|
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", getPlugin().ic, null, 0.1d, new DecimalFormat("0.0"), save);
|
||||||
isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", getPlugin().isf, null, 0.1d, new DecimalFormat("0.0"), save);
|
isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", getPlugin().isf, null, 0.1d, new DecimalFormat("0.0"), save);
|
||||||
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label)+ ": " + getSumLabel(), getPlugin().basal, null, 0.01d, new DecimalFormat("0.00"), save);
|
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), getPlugin().basal, null, 0.01d, new DecimalFormat("0.00"), save);
|
||||||
targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label)+ ":", getPlugin().targetLow, getPlugin().targetHigh, 0.1d, new DecimalFormat("0.0"), save);
|
targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", getPlugin().targetLow, getPlugin().targetHigh, 0.1d, new DecimalFormat("0.0"), save);
|
||||||
profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch);
|
profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch);
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) {
|
||||||
if (!pump.getPumpDescription().isTempBasalCapable) {
|
|
||||||
layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE);
|
layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +147,7 @@ public class LocalProfileFragment extends SubscriberFragment {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getSumLabel() {
|
public String getSumLabel() {
|
||||||
return " ∑" + DecimalFormatter.to2Decimal(localProfilePlugin.getProfile().getDefaultProfile().baseBasalSum()) +"U";
|
return " ∑" + DecimalFormatter.to2Decimal(localProfilePlugin.getProfile().getDefaultProfile().baseBasalSum()) + "U";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
@ -163,7 +162,7 @@ public class LocalProfileFragment extends SubscriberFragment {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) {
|
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended()) {
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
profileswitchButton.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
profileswitchButton.setVisibility(View.VISIBLE);
|
profileswitchButton.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -18,9 +18,10 @@ import info.nightscout.androidaps.Services.Intents;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI;
|
import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,12 +72,12 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled(int type) {
|
public boolean isEnabled(int type) {
|
||||||
return type == PROFILE && (Config.NSCLIENT || fragmentEnabled);
|
return type == PROFILE && (Config.NSCLIENT || Config.G5UPLOADER|| fragmentEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isVisibleInTabs(int type) {
|
public boolean isVisibleInTabs(int type) {
|
||||||
return type == PROFILE && (Config.NSCLIENT ||fragmentVisible);
|
return type == PROFILE && (Config.NSCLIENT || Config.G5UPLOADER|| fragmentVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,7 +92,7 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showInList(int type) {
|
public boolean showInList(int type) {
|
||||||
return !Config.NSCLIENT;
|
return !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,16 +120,19 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
|
||||||
profile = new ProfileStore(newProfile.getData());
|
profile = new ProfileStore(newProfile.getData());
|
||||||
storeNSProfile();
|
storeNSProfile();
|
||||||
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
MainApp.bus().post(new EventNSProfileUpdateGUI());
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
if (SP.getBoolean("syncprofiletopump", false)) {
|
if (SP.getBoolean("syncprofiletopump", false)) {
|
||||||
if (pump.setNewBasalProfile(MainApp.getConfigBuilder().getProfile()) == PumpInterface.SUCCESS) {
|
ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() {
|
||||||
SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
|
@Override
|
||||||
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
|
public void run() {
|
||||||
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
|
if (result.enacted) {
|
||||||
|
SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
|
||||||
|
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
|
||||||
|
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void storeNSProfile() {
|
private static void storeNSProfile() {
|
||||||
|
|
|
@ -18,14 +18,13 @@ import com.squareup.otto.Subscribe;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
public class SimpleProfileFragment extends SubscriberFragment {
|
public class SimpleProfileFragment extends SubscriberFragment {
|
||||||
|
@ -56,8 +55,7 @@ public class SimpleProfileFragment extends SubscriberFragment {
|
||||||
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
|
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
|
||||||
profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch);
|
profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch);
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) {
|
||||||
if (!pump.getPumpDescription().isTempBasalCapable) {
|
|
||||||
layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE);
|
layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE);
|
||||||
layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE);
|
layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +154,7 @@ public class SimpleProfileFragment extends SubscriberFragment {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) {
|
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended()) {
|
||||||
profileswitchButton.setVisibility(View.GONE);
|
profileswitchButton.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
profileswitchButton.setVisibility(View.VISIBLE);
|
profileswitchButton.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -6,8 +6,8 @@ import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.text.Spanned;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -27,10 +27,12 @@ import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRStatsActivity;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||||
|
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.SetWarnColor;
|
import info.nightscout.utils.SetWarnColor;
|
||||||
|
@ -38,11 +40,14 @@ import info.nightscout.utils.SetWarnColor;
|
||||||
public class DanaRFragment extends SubscriberFragment {
|
public class DanaRFragment extends SubscriberFragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRFragment.class);
|
private static Logger log = LoggerFactory.getLogger(DanaRFragment.class);
|
||||||
|
|
||||||
private static Handler sHandler;
|
|
||||||
private static HandlerThread sHandlerThread;
|
|
||||||
|
|
||||||
private Handler loopHandler = new Handler();
|
private Handler loopHandler = new Handler();
|
||||||
private Runnable refreshLoop = null;
|
private Runnable refreshLoop = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateGUI();
|
||||||
|
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TextView lastConnectionView;
|
TextView lastConnectionView;
|
||||||
TextView btConnectionView;
|
TextView btConnectionView;
|
||||||
|
@ -58,6 +63,7 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
TextView basalStepView;
|
TextView basalStepView;
|
||||||
TextView bolusStepView;
|
TextView bolusStepView;
|
||||||
TextView serialNumberView;
|
TextView serialNumberView;
|
||||||
|
TextView queueView;
|
||||||
Button viewProfileButton;
|
Button viewProfileButton;
|
||||||
Button historyButton;
|
Button historyButton;
|
||||||
Button statsButton;
|
Button statsButton;
|
||||||
|
@ -65,35 +71,19 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
LinearLayout pumpStatusLayout;
|
LinearLayout pumpStatusLayout;
|
||||||
TextView pumpStatusView;
|
TextView pumpStatusView;
|
||||||
|
|
||||||
static Runnable connectRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MainApp.getConfigBuilder().refreshDataFromPump("Connect request from GUI");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
public DanaRFragment() {
|
public DanaRFragment() {
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(DanaRFragment.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (refreshLoop == null) {
|
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
||||||
refreshLoop = new Runnable() {
|
}
|
||||||
@Override
|
|
||||||
public void run() {
|
@Override
|
||||||
updateGUI();
|
public void onDestroy() {
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
super.onDestroy();
|
||||||
}
|
loopHandler.removeCallbacks(refreshLoop);
|
||||||
};
|
|
||||||
loopHandler.postDelayed(refreshLoop, 60 * 1000L);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,6 +108,7 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
|
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
|
||||||
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
|
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
|
||||||
serialNumberView = (TextView) view.findViewById(R.id.danar_serialnumber);
|
serialNumberView = (TextView) view.findViewById(R.id.danar_serialnumber);
|
||||||
|
queueView = (TextView) view.findViewById(R.id.danar_queue);
|
||||||
|
|
||||||
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
|
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
|
||||||
pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder));
|
pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder));
|
||||||
|
@ -150,7 +141,7 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
log.debug("Clicked connect to pump");
|
log.debug("Clicked connect to pump");
|
||||||
sHandler.post(connectRunnable);
|
ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -206,6 +197,11 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
updateGUI();
|
updateGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventQueueChanged s) {
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
// GUI functions
|
// GUI functions
|
||||||
@Override
|
@Override
|
||||||
protected void updateGUI() {
|
protected void updateGUI() {
|
||||||
|
@ -226,15 +222,15 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
|
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
|
||||||
double agoHours = agoMsec / 60d / 60d / 1000d;
|
double agoHours = agoMsec / 60d / 60d / 1000d;
|
||||||
if (agoHours < 6) // max 6h back
|
if (agoHours < 6) // max 6h back
|
||||||
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
|
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
|
||||||
else lastBolusView.setText("");
|
else lastBolusView.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
||||||
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
||||||
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getBaseBasalRate()) + " U/h");
|
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h");
|
||||||
// DanaRPlugin, DanaRKoreanPlugin
|
// DanaRPlugin, DanaRKoreanPlugin
|
||||||
if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
|
||||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||||
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
|
||||||
} else {
|
} else {
|
||||||
|
@ -266,10 +262,17 @@ public class DanaRFragment extends SubscriberFragment {
|
||||||
basalStepView.setText("" + pump.basalStep);
|
basalStepView.setText("" + pump.basalStep);
|
||||||
bolusStepView.setText("" + pump.bolusStep);
|
bolusStepView.setText("" + pump.bolusStep);
|
||||||
serialNumberView.setText("" + pump.serialNumber);
|
serialNumberView.setText("" + pump.serialNumber);
|
||||||
|
if (queueView != null) {
|
||||||
|
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
|
||||||
|
if (status.toString().equals("")) {
|
||||||
|
queueView.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
queueView.setVisibility(View.VISIBLE);
|
||||||
|
queueView.setText(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
|
@ -229,7 +229,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return pump.lastConnection.getTime() > 0 && pump.isExtendedBolusEnabled;
|
return pump.lastConnection.getTime() > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -245,27 +245,35 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
|
|
||||||
// Pump interface
|
// Pump interface
|
||||||
@Override
|
@Override
|
||||||
public int setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
if (sExecutionService == null) {
|
if (sExecutionService == null) {
|
||||||
log.error("setNewBasalProfile sExecutionService is null");
|
log.error("setNewBasalProfile sExecutionService is null");
|
||||||
return FAILED;
|
result.comment = "setNewBasalProfile sExecutionService is null";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
log.error("setNewBasalProfile not initialized");
|
log.error("setNewBasalProfile not initialized");
|
||||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
return FAILED;
|
result.comment = MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
}
|
}
|
||||||
if (!sExecutionService.updateBasalsInPump(profile)) {
|
if (!sExecutionService.updateBasalsInPump(profile)) {
|
||||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
return FAILED;
|
result.comment = MainApp.sResources.getString(R.string.failedupdatebasalprofile);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||||
return SUCCESS;
|
result.success = true;
|
||||||
|
result.enacted = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,13 +302,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
doConnect(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -349,9 +350,10 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||||
// Recheck pump status if older than 30 min
|
// Recheck pump status if older than 30 min
|
||||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
//This should not be needed while using queue because connection should be done before calling this
|
||||||
doConnect("setTempBasalAbsolute old data");
|
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
}
|
// connect("setTempBasalAbsolute old data");
|
||||||
|
//}
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
|
@ -414,7 +416,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
log.debug("setTempBasalAbsolute: currently running: " + running.toString());
|
log.debug("setTempBasalAbsolute: currently running: " + running.toString());
|
||||||
if (running.percentRate == percentRate) {
|
if (running.percentRate == percentRate) {
|
||||||
if (enforceNew) {
|
if (enforceNew) {
|
||||||
cancelTempBasal(true);
|
cancelTempBasal(true);
|
||||||
} else {
|
} else {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.percent = percentRate;
|
result.percent = percentRate;
|
||||||
|
@ -542,7 +544,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
}
|
}
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
result.success = false;
|
result.success = false;
|
||||||
result.comment = MainApp.instance().getString(R.string.danar_valuenotsetproperly);
|
result.comment = MainApp.instance().getString(R.string.tempbasaldeliveryerror);
|
||||||
log.error("setTempBasalPercent: Failed to set temp basal");
|
log.error("setTempBasalPercent: Failed to set temp basal");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -553,7 +555,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||||
// needs to be rounded
|
// needs to be rounded
|
||||||
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||||
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1));
|
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
|
@ -653,7 +655,8 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doConnect(String from) {
|
@Override
|
||||||
|
public void connect(String from) {
|
||||||
if (sExecutionService != null) {
|
if (sExecutionService != null) {
|
||||||
sExecutionService.connect(from);
|
sExecutionService.connect(from);
|
||||||
pumpDescription.basalStep = pump.basalStep;
|
pumpDescription.basalStep = pump.basalStep;
|
||||||
|
@ -661,18 +664,31 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnected() {
|
@Override
|
||||||
|
public boolean isConnected() {
|
||||||
return sExecutionService != null && sExecutionService.isConnected();
|
return sExecutionService != null && sExecutionService.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnecting() {
|
@Override
|
||||||
|
public boolean isConnecting() {
|
||||||
return sExecutionService != null && sExecutionService.isConnecting();
|
return sExecutionService != null && sExecutionService.isConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doDisconnect(String from) {
|
@Override
|
||||||
|
public void disconnect(String from) {
|
||||||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
if (sExecutionService != null) sExecutionService.stopConnecting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
if (sExecutionService != null) sExecutionService.getPumpStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getJSONStatus() {
|
public JSONObject getJSONStatus() {
|
||||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
@ -736,10 +752,15 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return null; // no history, not needed
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraint interface
|
* Constraint interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
|
@ -44,14 +45,7 @@ public class ProfileViewDialog extends DialogFragment {
|
||||||
|
|
||||||
private Button refreshButton;
|
private Button refreshButton;
|
||||||
|
|
||||||
Handler mHandler;
|
|
||||||
static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
public ProfileViewDialog() {
|
public ProfileViewDialog() {
|
||||||
mHandlerThread = new HandlerThread(ProfileViewDialog.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
|
|
||||||
mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,18 +66,7 @@ public class ProfileViewDialog extends DialogFragment {
|
||||||
refreshButton.setOnClickListener(new View.OnClickListener() {
|
refreshButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mHandler.post(new Runnable() {
|
ConfigBuilderPlugin.getCommandQueue().readStatus("ProfileViewDialog", null);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
DanaRPump.getInstance().lastSettingsRead = new Date(0);
|
|
||||||
if (MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
DanaRPlugin.doConnect("ProfileViewDialog");
|
|
||||||
if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
DanaRKoreanPlugin.doConnect("ProfileViewDialog");
|
|
||||||
if (MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
DanaRv2Plugin.doConnect("ProfileViewDialog");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,11 +38,13 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -122,8 +124,8 @@ public class DanaRHistoryActivity extends Activity {
|
||||||
|
|
||||||
statusView.setVisibility(View.GONE);
|
statusView.setVisibility(View.GONE);
|
||||||
|
|
||||||
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP);
|
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP);
|
||||||
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginBase.PUMP);
|
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginBase.PUMP);
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
|
|
||||||
|
@ -150,25 +152,19 @@ public class DanaRHistoryActivity extends Activity {
|
||||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
final TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem();
|
||||||
if (pump.isBusy()) {
|
runOnUiThread(new Runnable() {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
@Override
|
||||||
return;
|
public void run() {
|
||||||
}
|
reloadButton.setVisibility(View.GONE);
|
||||||
mHandler.post(new Runnable() {
|
syncButton.setVisibility(View.GONE);
|
||||||
|
statusView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clearCardView();
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().loadHistory(selected.type, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TypeList selected = (TypeList) historyTypeSpinner.getSelectedItem();
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
reloadButton.setVisibility(View.GONE);
|
|
||||||
syncButton.setVisibility(View.GONE);
|
|
||||||
statusView.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
clearCardView();
|
|
||||||
((DanaRInterface)pump).loadHistory(selected.type);
|
|
||||||
loadDataFromDB(selected.type);
|
loadDataFromDB(selected.type);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,24 +40,17 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
public class DanaRStatsActivity extends Activity {
|
public class DanaRStatsActivity extends Activity {
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRStatsActivity.class);
|
private static Logger log = LoggerFactory.getLogger(DanaRStatsActivity.class);
|
||||||
|
|
||||||
private boolean mBounded;
|
|
||||||
|
|
||||||
private Handler mHandler;
|
|
||||||
private static HandlerThread mHandlerThread;
|
|
||||||
|
|
||||||
TextView statusView, statsMessage, totalBaseBasal2;
|
TextView statusView, statsMessage, totalBaseBasal2;
|
||||||
EditText totalBaseBasal;
|
EditText totalBaseBasal;
|
||||||
Button reloadButton;
|
Button reloadButton;
|
||||||
|
@ -72,9 +65,6 @@ public class DanaRStatsActivity extends Activity {
|
||||||
|
|
||||||
public DanaRStatsActivity() {
|
public DanaRStatsActivity() {
|
||||||
super();
|
super();
|
||||||
mHandlerThread = new HandlerThread(DanaRStatsActivity.class.getSimpleName());
|
|
||||||
mHandlerThread.start();
|
|
||||||
this.mHandler = new Handler(mHandlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -233,24 +223,18 @@ public class DanaRStatsActivity extends Activity {
|
||||||
reloadButton.setOnClickListener(new View.OnClickListener() {
|
reloadButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
runOnUiThread(new Runnable() {
|
||||||
if (pump.isBusy()) {
|
@Override
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.pumpbusy));
|
public void run() {
|
||||||
return;
|
reloadButton.setVisibility(View.GONE);
|
||||||
}
|
statusView.setVisibility(View.VISIBLE);
|
||||||
mHandler.post(new Runnable() {
|
statsMessage.setVisibility(View.VISIBLE);
|
||||||
|
statsMessage.setText(getString(R.string.danar_stats_warning_Message));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().loadHistory(RecordTypes.RECORD_TYPE_DAILY, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
reloadButton.setVisibility(View.GONE);
|
|
||||||
statusView.setVisibility(View.VISIBLE);
|
|
||||||
statsMessage.setVisibility(View.VISIBLE);
|
|
||||||
statsMessage.setText(getString(R.string.danar_stats_warning_Message));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
((DanaRInterface) pump).loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
|
||||||
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,8 +31,7 @@ public class MsgCheckValue extends MessageBase {
|
||||||
pump.protocol = intFromBuff(bytes, 1, 1);
|
pump.protocol = intFromBuff(bytes, 1, 1);
|
||||||
pump.productCode = intFromBuff(bytes, 2, 1);
|
pump.productCode = intFromBuff(bytes, 2, 1);
|
||||||
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
|
||||||
((DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class)).doDisconnect("Wrong Model");
|
|
||||||
log.debug("Wrong model selected");
|
log.debug("Wrong model selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,14 @@ import java.util.Date;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
public class MsgInitConnStatusTime extends MessageBase {
|
public class MsgInitConnStatusTime extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusTime.class);
|
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusTime.class);
|
||||||
|
@ -25,8 +27,9 @@ public class MsgInitConnStatusTime extends MessageBase {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(byte[] bytes) {
|
public void handleMessage(byte[] bytes) {
|
||||||
if (bytes.length - 10 > 7) {
|
if (bytes.length - 10 > 7) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
((DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class)).doDisconnect("Wrong Model");
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
|
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
|
||||||
log.debug("Wrong model selected. Switching to Korean DanaR");
|
log.debug("Wrong model selected. Switching to Korean DanaR");
|
||||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
|
||||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
|
||||||
|
@ -41,7 +44,8 @@ public class MsgInitConnStatusTime extends MessageBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshOverview("MsgInitConnStatusTime"));
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
|
||||||
public class MsgSetBasalProfile extends MessageBase {
|
public class MsgSetBasalProfile extends MessageBase {
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaR.comm;
|
package info.nightscout.androidaps.plugins.PumpDanaR.comm;
|
||||||
|
|
||||||
import com.j256.ormlite.stmt.query.Not;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
|
||||||
public class MsgSetSingleBasalProfile extends MessageBase {
|
public class MsgSetSingleBasalProfile extends MessageBase {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -27,13 +26,14 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
@ -79,8 +79,9 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -94,14 +95,12 @@ public class DanaRExecutionService extends Service {
|
||||||
private BluetoothSocket mRfcommSocket;
|
private BluetoothSocket mRfcommSocket;
|
||||||
private BluetoothDevice mBTDevice;
|
private BluetoothDevice mBTDevice;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
private DanaRPump danaRPump = DanaRPump.getInstance();
|
private DanaRPump danaRPump = DanaRPump.getInstance();
|
||||||
private Treatment bolusingTreatment = null;
|
private Treatment bolusingTreatment = null;
|
||||||
|
|
||||||
private static Boolean connectionInProgress = false;
|
private static Boolean connectionInProgress = false;
|
||||||
private static final Object connectionLock = new Object();
|
|
||||||
|
|
||||||
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
||||||
|
|
||||||
|
@ -125,9 +124,6 @@ public class DanaRExecutionService extends Service {
|
||||||
public DanaRExecutionService() {
|
public DanaRExecutionService() {
|
||||||
registerBus();
|
registerBus();
|
||||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRExecutionService");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
|
@ -189,35 +185,28 @@ public class DanaRExecutionService extends Service {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (isConnected() || isConnecting()) {
|
|
||||||
if (Config.logDanaBTComm)
|
if (connectionInProgress)
|
||||||
log.debug("already connected/connecting from: " + from);
|
return;
|
||||||
waitMsec(3000);
|
|
||||||
}
|
new Thread(new Runnable() {
|
||||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
@Override
|
||||||
synchronized (connectionLock) {
|
public void run() {
|
||||||
//log.debug("entering connection while loop");
|
connectionInProgress = true;
|
||||||
connectionInProgress = true;
|
getBTSocketForSelectedPump();
|
||||||
mWakeLock.acquire();
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
getBTSocketForSelectedPump();
|
connectionInProgress = false;
|
||||||
if (mRfcommSocket == null || mBTDevice == null)
|
return; // Device not found
|
||||||
return; // Device not found
|
}
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
while (!isConnected() && startTime + maxConnectionTime >= System.currentTimeMillis()) {
|
|
||||||
long secondsElapsed = (System.currentTimeMillis() - startTime) / 1000L;
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
|
||||||
if (Config.logDanaBTComm)
|
|
||||||
log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
|
|
||||||
try {
|
try {
|
||||||
mRfcommSocket.connect();
|
mRfcommSocket.connect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//log.error("Unhandled exception", e);
|
//log.error("Unhandled exception", e);
|
||||||
if (e.getMessage().contains("socket closed")) {
|
if (e.getMessage().contains("socket closed")) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitMsec(1000);
|
|
||||||
|
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
if (mSerialIOThread != null) {
|
if (mSerialIOThread != null) {
|
||||||
|
@ -225,23 +214,16 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
||||||
if (!getPumpStatus()) {
|
|
||||||
mSerialIOThread.disconnect("getPumpStatus failed");
|
|
||||||
waitMsec(3000);
|
|
||||||
if (!MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
return;
|
|
||||||
getBTSocketForSelectedPump();
|
|
||||||
startTime = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectionInProgress = false;
|
||||||
}
|
}
|
||||||
if (!isConnected()) {
|
}).start();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
}
|
||||||
log.error("Pump connection timed out");
|
|
||||||
}
|
public void stopConnecting() {
|
||||||
connectionInProgress = false;
|
if (mSerialIOThread != null)
|
||||||
mWakeLock.release();
|
mSerialIOThread.disconnect("stopConnecting");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBTSocketForSelectedPump() {
|
private void getBTSocketForSelectedPump() {
|
||||||
|
@ -276,7 +258,7 @@ public class DanaRExecutionService extends Service {
|
||||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
||||||
MsgStatus statusMsg = new MsgStatus();
|
MsgStatus statusMsg = new MsgStatus();
|
||||||
|
@ -288,7 +270,7 @@ public class DanaRExecutionService extends Service {
|
||||||
if (danaRPump.isNewPump) {
|
if (danaRPump.isNewPump) {
|
||||||
mSerialIOThread.sendMessage(checkValue);
|
mSerialIOThread.sendMessage(checkValue);
|
||||||
if (!checkValue.received) {
|
if (!checkValue.received) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,28 +282,6 @@ public class DanaRExecutionService extends Service {
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
mSerialIOThread.sendMessage(exStatusMsg);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
|
|
||||||
if (!statusMsg.received) {
|
|
||||||
mSerialIOThread.sendMessage(statusMsg);
|
|
||||||
}
|
|
||||||
if (!statusBasicMsg.received) {
|
|
||||||
mSerialIOThread.sendMessage(statusBasicMsg);
|
|
||||||
}
|
|
||||||
if (!tempStatusMsg.received) {
|
|
||||||
// Load of status of current basal rate failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(tempStatusMsg);
|
|
||||||
}
|
|
||||||
if (!exStatusMsg.received) {
|
|
||||||
// Load of status of current extended bolus failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check we have really current status of pump
|
|
||||||
if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) {
|
|
||||||
waitMsec(10 * 1000);
|
|
||||||
log.debug("getPumpStatus failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRPlugin.class).isInitialized()) {
|
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRPlugin.class).isInitialized()) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
||||||
|
@ -352,7 +312,7 @@ public class DanaRExecutionService extends Service {
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
MainApp.bus().post(new EventDanaRNewStatus());
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) {
|
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
||||||
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
|
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
|
||||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT);
|
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(reportFail));
|
MainApp.bus().post(new EventNewNotification(reportFail));
|
||||||
|
@ -361,11 +321,9 @@ public class DanaRExecutionService extends Service {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasal(int percent, int durationInHours) {
|
public boolean tempBasal(int percent, int durationInHours) {
|
||||||
connect("tempBasal");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
if (danaRPump.isTempBasalInProgress) {
|
if (danaRPump.isTempBasalInProgress) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
|
@ -380,7 +338,6 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasalStop() {
|
public boolean tempBasalStop() {
|
||||||
connect("tempBasalStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
||||||
|
@ -390,7 +347,6 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
||||||
connect("extendedBolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
||||||
|
@ -400,7 +356,6 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolusStop() {
|
public boolean extendedBolusStop() {
|
||||||
connect("extendedBolusStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
||||||
|
@ -409,7 +364,7 @@ public class DanaRExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean bolus(double amount, int carbs, Treatment t) {
|
public boolean bolus(double amount, int carbs, final Treatment t) {
|
||||||
bolusingTreatment = t;
|
bolusingTreatment = t;
|
||||||
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||||
MessageBase start;
|
MessageBase start;
|
||||||
|
@ -419,7 +374,6 @@ public class DanaRExecutionService extends Service {
|
||||||
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
||||||
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||||
|
|
||||||
connect("bolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
|
||||||
if (carbs > 0) {
|
if (carbs > 0) {
|
||||||
|
@ -437,7 +391,7 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
while (!stop.stopped && !start.failed) {
|
while (!stop.stopped && !start.failed) {
|
||||||
waitMsec(100);
|
waitMsec(100);
|
||||||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
|
||||||
stop.stopped = true;
|
stop.stopped = true;
|
||||||
stop.forced = true;
|
stop.forced = true;
|
||||||
log.debug("Communication stopped");
|
log.debug("Communication stopped");
|
||||||
|
@ -475,16 +429,27 @@ public class DanaRExecutionService extends Service {
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
}
|
}
|
||||||
connect("bolusingInterrupted");
|
|
||||||
getPumpStatus();
|
final Object o = new Object();
|
||||||
if (danaRPump.lastBolusTime.getTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
|
ConfigBuilderPlugin.getCommandQueue().readStatus("bolusingInterrupted", new Callback() {
|
||||||
t.insulin = danaRPump.lastBolusAmount;
|
@Override
|
||||||
log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount);
|
public void run() {
|
||||||
} else {
|
if (danaRPump.lastBolusTime.getTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
|
||||||
log.debug("Bolus amount in history too old: " + danaRPump.lastBolusTime.toLocaleString());
|
t.insulin = danaRPump.lastBolusAmount;
|
||||||
|
log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount);
|
||||||
|
} else {
|
||||||
|
log.debug("Bolus amount in history too old: " + danaRPump.lastBolusTime.toLocaleString());
|
||||||
|
}
|
||||||
|
o.notify();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
o.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getPumpStatus();
|
ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -506,16 +471,15 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean carbsEntry(int amount) {
|
public boolean carbsEntry(int amount) {
|
||||||
connect("carbsEntry");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(System.currentTimeMillis(), amount);
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(System.currentTimeMillis(), amount);
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
connect("loadHistory");
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return result;
|
||||||
MessageBase msg = null;
|
MessageBase msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -555,11 +519,12 @@ public class DanaRExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateBasalsInPump(final Profile profile) {
|
public boolean updateBasalsInPump(final Profile profile) {
|
||||||
connect("updateBasalsInPump");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
||||||
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
||||||
|
|
|
@ -38,7 +38,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
|
@ -61,9 +61,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
return DanaRFragment.class.getName();
|
return DanaRFragment.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fragmentPumpEnabled = false;
|
private static boolean fragmentPumpEnabled = false;
|
||||||
private boolean fragmentProfileEnabled = false;
|
private static boolean fragmentProfileEnabled = false;
|
||||||
private boolean fragmentPumpVisible = true;
|
private static boolean fragmentPumpVisible = true;
|
||||||
|
|
||||||
private static DanaRKoreanExecutionService sExecutionService;
|
private static DanaRKoreanExecutionService sExecutionService;
|
||||||
|
|
||||||
|
@ -201,11 +201,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
@Override
|
@Override
|
||||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
if (type == PluginBase.PROFILE)
|
if (type == PluginBase.PROFILE)
|
||||||
this.fragmentProfileEnabled = fragmentEnabled;
|
fragmentProfileEnabled = fragmentEnabled;
|
||||||
else if (type == PluginBase.PUMP)
|
else if (type == PluginBase.PUMP)
|
||||||
this.fragmentPumpEnabled = fragmentEnabled;
|
fragmentPumpEnabled = fragmentEnabled;
|
||||||
// if pump profile was enabled need to switch to another too
|
// if pump profile was enabled need to switch to another too
|
||||||
if (type == PluginBase.PUMP && !fragmentEnabled && this.fragmentProfileEnabled) {
|
if (type == PluginBase.PUMP && !fragmentEnabled && fragmentProfileEnabled) {
|
||||||
setFragmentEnabled(PluginBase.PROFILE, false);
|
setFragmentEnabled(PluginBase.PROFILE, false);
|
||||||
setFragmentVisible(PluginBase.PROFILE, false);
|
setFragmentVisible(PluginBase.PROFILE, false);
|
||||||
NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true);
|
NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true);
|
||||||
|
@ -216,7 +216,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
@Override
|
@Override
|
||||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||||
if (type == PluginBase.PUMP)
|
if (type == PluginBase.PUMP)
|
||||||
this.fragmentPumpVisible = fragmentVisible;
|
fragmentPumpVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -231,7 +231,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return pump.lastConnection.getTime() > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled;
|
return pump.lastConnection.getTime() > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -247,27 +247,35 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
|
|
||||||
// Pump interface
|
// Pump interface
|
||||||
@Override
|
@Override
|
||||||
public int setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
if (sExecutionService == null) {
|
if (sExecutionService == null) {
|
||||||
log.error("setNewBasalProfile sExecutionService is null");
|
log.error("setNewBasalProfile sExecutionService is null");
|
||||||
return FAILED;
|
result.comment = "setNewBasalProfile sExecutionService is null";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
log.error("setNewBasalProfile not initialized");
|
log.error("setNewBasalProfile not initialized");
|
||||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
return FAILED;
|
result.comment = MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
}
|
}
|
||||||
if (!sExecutionService.updateBasalsInPump(profile)) {
|
if (!sExecutionService.updateBasalsInPump(profile)) {
|
||||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
return FAILED;
|
result.comment = MainApp.sResources.getString(R.string.failedupdatebasalprofile);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||||
return SUCCESS;
|
result.success = true;
|
||||||
|
result.enacted = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,13 +304,6 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
doConnect(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -315,8 +316,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
Treatment t = new Treatment();
|
Treatment t = new Treatment();
|
||||||
boolean connectionOK = false;
|
boolean connectionOK = false;
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t);
|
||||||
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, t);
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
result.success = connectionOK;
|
result.success = connectionOK;
|
||||||
result.bolusDelivered = t.insulin;
|
result.bolusDelivered = t.insulin;
|
||||||
|
@ -352,9 +352,10 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||||
// Recheck pump status if older than 30 min
|
// Recheck pump status if older than 30 min
|
||||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
//This should not be needed while using queue because connection should be done before calling this
|
||||||
doConnect("setTempBasalAbsolute old data");
|
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
}
|
// connect("setTempBasalAbsolute old data");
|
||||||
|
//}
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
|
@ -393,9 +394,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
Integer percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
|
||||||
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
if (percentRate < 100) percentRate = Round.ceilTo((double) percentRate, 10d).intValue();
|
||||||
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
else percentRate = Round.floorTo((double) percentRate, 10d).intValue();
|
||||||
if (percentRate > 200) {
|
if (percentRate > getPumpDescription().maxTempPercent) {
|
||||||
percentRate = 200;
|
percentRate = getPumpDescription().maxTempPercent;
|
||||||
}
|
}
|
||||||
|
if (Config.logPumpActions)
|
||||||
|
log.debug("setTempBasalAbsolute: Calculated percent rate: " + percentRate);
|
||||||
|
|
||||||
// If extended in progress
|
// If extended in progress
|
||||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) {
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
|
@ -409,7 +413,10 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
// Check if some temp is already in progress
|
// Check if some temp is already in progress
|
||||||
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||||
// Correct basal already set ?
|
// Correct basal already set ?
|
||||||
if (MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
|
TemporaryBasal running = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||||
|
if (Config.logPumpActions)
|
||||||
|
log.debug("setTempBasalAbsolute: currently running: " + running.toString());
|
||||||
|
if (running.percentRate == percentRate) {
|
||||||
if (enforceNew) {
|
if (enforceNew) {
|
||||||
cancelTempBasal(true);
|
cancelTempBasal(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -450,7 +457,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
Double extendedRateToSet = absoluteRate - getBaseBasalRate();
|
Double extendedRateToSet = absoluteRate - getBaseBasalRate();
|
||||||
extendedRateToSet = configBuilderPlugin.applyBasalConstraints(extendedRateToSet);
|
extendedRateToSet = configBuilderPlugin.applyBasalConstraints(extendedRateToSet);
|
||||||
// needs to be rounded to 0.1
|
// needs to be rounded to 0.1
|
||||||
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of 30 min
|
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of halfhours
|
||||||
|
|
||||||
// What is current rate of extended bolusing in u/h?
|
// What is current rate of extended bolusing in u/h?
|
||||||
if (Config.logPumpActions) {
|
if (Config.logPumpActions) {
|
||||||
|
@ -550,7 +557,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||||
// needs to be rounded
|
// needs to be rounded
|
||||||
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||||
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1));
|
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
|
@ -650,7 +657,8 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doConnect(String from) {
|
@Override
|
||||||
|
public void connect(String from) {
|
||||||
if (sExecutionService != null) {
|
if (sExecutionService != null) {
|
||||||
sExecutionService.connect(from);
|
sExecutionService.connect(from);
|
||||||
pumpDescription.basalStep = pump.basalStep;
|
pumpDescription.basalStep = pump.basalStep;
|
||||||
|
@ -658,18 +666,31 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnected() {
|
@Override
|
||||||
|
public boolean isConnected() {
|
||||||
return sExecutionService != null && sExecutionService.isConnected();
|
return sExecutionService != null && sExecutionService.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnecting() {
|
@Override
|
||||||
|
public boolean isConnecting() {
|
||||||
return sExecutionService != null && sExecutionService.isConnecting();
|
return sExecutionService != null && sExecutionService.isConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doDisconnect(String from) {
|
@Override
|
||||||
|
public void disconnect(String from) {
|
||||||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
if (sExecutionService != null) sExecutionService.stopConnecting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
if (sExecutionService != null) sExecutionService.getPumpStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getJSONStatus() {
|
public JSONObject getJSONStatus() {
|
||||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
@ -733,10 +754,15 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return null; // no history, not needed
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraint interface
|
* Constraint interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,8 +32,7 @@ public class MsgCheckValue_k extends MessageBase {
|
||||||
pump.protocol = intFromBuff(bytes, 1, 1);
|
pump.protocol = intFromBuff(bytes, 1, 1);
|
||||||
pump.productCode = intFromBuff(bytes, 2, 1);
|
pump.productCode = intFromBuff(bytes, 2, 1);
|
||||||
if (pump.model != DanaRPump.DOMESTIC_MODEL) {
|
if (pump.model != DanaRPump.DOMESTIC_MODEL) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
||||||
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).doDisconnect("Wrong Model");
|
|
||||||
log.debug("Wrong model selected");
|
log.debug("Wrong model selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,15 @@ import java.util.Date;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
public class MsgInitConnStatusTime_k extends MessageBase {
|
public class MsgInitConnStatusTime_k extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusTime_k.class);
|
private static Logger log = LoggerFactory.getLogger(MsgInitConnStatusTime_k.class);
|
||||||
|
@ -27,8 +29,9 @@ public class MsgInitConnStatusTime_k extends MessageBase {
|
||||||
public void handleMessage(byte[] bytes) {
|
public void handleMessage(byte[] bytes) {
|
||||||
|
|
||||||
if (bytes.length - 10 < 10) {
|
if (bytes.length - 10 < 10) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
((DanaRKoreanPlugin)MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).doDisconnect("Wrong Model");
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
|
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
||||||
log.debug("Wrong model selected. Switching to export DanaR");
|
log.debug("Wrong model selected. Switching to export DanaR");
|
||||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
|
||||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, false);
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, false);
|
||||||
|
@ -37,13 +40,14 @@ public class MsgInitConnStatusTime_k extends MessageBase {
|
||||||
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
|
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
|
||||||
|
|
||||||
//If profile coming from pump, switch it as well
|
//If profile coming from pump, switch it as well
|
||||||
if(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)){
|
if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)) {
|
||||||
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
|
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
|
||||||
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
|
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshOverview("MsgInitConnStatusTime_k"));
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -27,13 +26,15 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress;
|
||||||
|
@ -70,11 +71,12 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.SerialIOThread;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.SerialIOThread;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgCheckValue_k;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgCheckValue_k;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingBasal_k;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgSettingBasal_k;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBasic_k;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBasic_k;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -88,14 +90,12 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
private BluetoothSocket mRfcommSocket;
|
private BluetoothSocket mRfcommSocket;
|
||||||
private BluetoothDevice mBTDevice;
|
private BluetoothDevice mBTDevice;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
private DanaRPump danaRPump = DanaRPump.getInstance();
|
private DanaRPump danaRPump = DanaRPump.getInstance();
|
||||||
private Treatment bolusingTreatment = null;
|
private Treatment bolusingTreatment = null;
|
||||||
|
|
||||||
private static Boolean connectionInProgress = false;
|
private static Boolean connectionInProgress = false;
|
||||||
private static final Object connectionLock = new Object();
|
|
||||||
|
|
||||||
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
||||||
|
|
||||||
|
@ -119,9 +119,6 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
public DanaRKoreanExecutionService() {
|
public DanaRKoreanExecutionService() {
|
||||||
registerBus();
|
registerBus();
|
||||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRKoreanExecutionService");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
|
@ -183,35 +180,28 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (isConnected() || isConnecting()) {
|
|
||||||
if (Config.logDanaBTComm)
|
if (connectionInProgress)
|
||||||
log.debug("already connected/connecting from: " + from);
|
return;
|
||||||
waitMsec(3000);
|
|
||||||
}
|
new Thread(new Runnable() {
|
||||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
@Override
|
||||||
synchronized (connectionLock) {
|
public void run() {
|
||||||
//log.debug("entering connection while loop");
|
connectionInProgress = true;
|
||||||
connectionInProgress = true;
|
getBTSocketForSelectedPump();
|
||||||
mWakeLock.acquire();
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
getBTSocketForSelectedPump();
|
connectionInProgress = false;
|
||||||
if (mRfcommSocket == null || mBTDevice == null)
|
return; // Device not found
|
||||||
return; // Device not found
|
}
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
while (!isConnected() && startTime + maxConnectionTime >= System.currentTimeMillis()) {
|
|
||||||
long secondsElapsed = (System.currentTimeMillis() - startTime) / 1000L;
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
|
||||||
if (Config.logDanaBTComm)
|
|
||||||
log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
|
|
||||||
try {
|
try {
|
||||||
mRfcommSocket.connect();
|
mRfcommSocket.connect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//log.error("Unhandled exception", e);
|
//log.error("Unhandled exception", e);
|
||||||
if (e.getMessage().contains("socket closed")) {
|
if (e.getMessage().contains("socket closed")) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitMsec(1000);
|
|
||||||
|
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
if (mSerialIOThread != null) {
|
if (mSerialIOThread != null) {
|
||||||
|
@ -219,23 +209,16 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
||||||
if (!getPumpStatus()) {
|
|
||||||
mSerialIOThread.disconnect("getPumpStatus failed");
|
|
||||||
waitMsec(3000);
|
|
||||||
if (!MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
return;
|
|
||||||
getBTSocketForSelectedPump();
|
|
||||||
startTime = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectionInProgress = false;
|
||||||
}
|
}
|
||||||
if (!isConnected()) {
|
}).start();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
}
|
||||||
log.error("Pump connection timed out");
|
|
||||||
}
|
public void stopConnecting() {
|
||||||
connectionInProgress = false;
|
if (mSerialIOThread != null)
|
||||||
mWakeLock.release();
|
mSerialIOThread.disconnect("stopConnecting");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBTSocketForSelectedPump() {
|
private void getBTSocketForSelectedPump() {
|
||||||
|
@ -270,7 +253,7 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
||||||
//MsgStatus_k statusMsg = new MsgStatus_k();
|
//MsgStatus_k statusMsg = new MsgStatus_k();
|
||||||
|
@ -282,7 +265,7 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
if (danaRPump.isNewPump) {
|
if (danaRPump.isNewPump) {
|
||||||
mSerialIOThread.sendMessage(checkValue);
|
mSerialIOThread.sendMessage(checkValue);
|
||||||
if (!checkValue.received) {
|
if (!checkValue.received) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,28 +277,6 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
mSerialIOThread.sendMessage(exStatusMsg);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
|
|
||||||
// if (!statusMsg.received) {
|
|
||||||
// mSerialIOThread.sendMessage(statusMsg);
|
|
||||||
// }
|
|
||||||
if (!statusBasicMsg.received) {
|
|
||||||
mSerialIOThread.sendMessage(statusBasicMsg);
|
|
||||||
}
|
|
||||||
if (!tempStatusMsg.received) {
|
|
||||||
// Load of status of current basal rate failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(tempStatusMsg);
|
|
||||||
}
|
|
||||||
if (!exStatusMsg.received) {
|
|
||||||
// Load of status of current extended bolus failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check we have really current status of pump
|
|
||||||
if (/*!statusMsg.received || */!statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) {
|
|
||||||
waitMsec(10 * 1000);
|
|
||||||
log.debug("getPumpStatus failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isInitialized()) {
|
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isInitialized()) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
||||||
|
@ -343,7 +304,7 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
MainApp.bus().post(new EventDanaRNewStatus());
|
MainApp.bus().post(new EventDanaRNewStatus());
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning ) {
|
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
|
||||||
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
|
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
|
||||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT);
|
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(reportFail));
|
MainApp.bus().post(new EventNewNotification(reportFail));
|
||||||
|
@ -352,11 +313,10 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasal(int percent, int durationInHours) {
|
public boolean tempBasal(int percent, int durationInHours) {
|
||||||
connect("tempBasal");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
if (danaRPump.isTempBasalInProgress) {
|
if (danaRPump.isTempBasalInProgress) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
|
@ -371,7 +331,6 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasalStop() {
|
public boolean tempBasalStop() {
|
||||||
connect("tempBasalStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
||||||
|
@ -381,7 +340,6 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
||||||
connect("extendedBolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
||||||
|
@ -391,7 +349,6 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolusStop() {
|
public boolean extendedBolusStop() {
|
||||||
connect("extendedBolusStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
||||||
|
@ -400,12 +357,11 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean bolus(double amount, int carbs, Treatment t) {
|
public boolean bolus(double amount, int carbs, final Treatment t) {
|
||||||
bolusingTreatment = t;
|
bolusingTreatment = t;
|
||||||
MsgBolusStart start = new MsgBolusStart(amount);
|
MsgBolusStart start = new MsgBolusStart(amount);
|
||||||
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||||
|
|
||||||
connect("bolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
|
||||||
if (carbs > 0) {
|
if (carbs > 0) {
|
||||||
|
@ -413,6 +369,7 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
MsgBolusProgress progress = new MsgBolusProgress(amount, t); // initialize static variables
|
||||||
|
long bolusStart = System.currentTimeMillis();
|
||||||
|
|
||||||
if (!stop.stopped) {
|
if (!stop.stopped) {
|
||||||
mSerialIOThread.sendMessage(start);
|
mSerialIOThread.sendMessage(start);
|
||||||
|
@ -422,15 +379,56 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
while (!stop.stopped && !start.failed) {
|
while (!stop.stopped && !start.failed) {
|
||||||
waitMsec(100);
|
waitMsec(100);
|
||||||
if ((System.currentTimeMillis() - progress.lastReceive) > 5 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
|
||||||
stop.stopped = true;
|
stop.stopped = true;
|
||||||
stop.forced = true;
|
stop.forced = true;
|
||||||
log.debug("Communication stopped");
|
log.debug("Communication stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitMsec(300);
|
waitMsec(300);
|
||||||
|
|
||||||
|
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
|
bolusingEvent.t = t;
|
||||||
|
bolusingEvent.percent = 99;
|
||||||
|
|
||||||
bolusingTreatment = null;
|
bolusingTreatment = null;
|
||||||
getPumpStatus();
|
|
||||||
|
int speed = 12;
|
||||||
|
|
||||||
|
// try to find real amount if bolusing was interrupted or comm failed
|
||||||
|
if (t.insulin != amount) {
|
||||||
|
disconnect("bolusingInterrupted");
|
||||||
|
long bolusDurationInMSec = (long) (amount * speed * 1000);
|
||||||
|
long expectedEnd = bolusStart + bolusDurationInMSec + 3000;
|
||||||
|
|
||||||
|
while (System.currentTimeMillis() < expectedEnd) {
|
||||||
|
long waitTime = expectedEnd - System.currentTimeMillis();
|
||||||
|
bolusingEvent.status = String.format(MainApp.sResources.getString(R.string.waitingforestimatedbolusend), waitTime / 1000);
|
||||||
|
MainApp.bus().post(bolusingEvent);
|
||||||
|
SystemClock.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Object o = new Object();
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("bolusingInterrupted", new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (danaRPump.lastBolusTime.getTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
|
||||||
|
t.insulin = danaRPump.lastBolusAmount;
|
||||||
|
log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount);
|
||||||
|
} else {
|
||||||
|
log.debug("Bolus amount in history too old: " + danaRPump.lastBolusTime.toLocaleString());
|
||||||
|
}
|
||||||
|
o.notify();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
o.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("bolusOK", null);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,16 +449,15 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean carbsEntry(int amount) {
|
public boolean carbsEntry(int amount) {
|
||||||
connect("carbsEntry");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(System.currentTimeMillis(), amount);
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(System.currentTimeMillis(), amount);
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
connect("loadHistory");
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return result;
|
||||||
MessageBase msg = null;
|
MessageBase msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -500,11 +497,12 @@ public class DanaRKoreanExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateBasalsInPump(final Profile profile) {
|
public boolean updateBasalsInPump(final Profile profile) {
|
||||||
connect("updateBasalsInPump");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
||||||
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.util.Objects;
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
|
@ -27,7 +29,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
import info.nightscout.androidaps.interfaces.DanaRInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
@ -36,16 +38,12 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -219,60 +217,54 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
mDeviceName = SP.getString(R.string.key_danars_name, "");
|
mDeviceName = SP.getString(R.string.key_danars_name, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void connectIfNotConnected(String from) {
|
@Override
|
||||||
if (!isConnected())
|
public void connect(String from) {
|
||||||
connect(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void connect(String from) {
|
|
||||||
log.debug("RS connect from: " + from);
|
log.debug("RS connect from: " + from);
|
||||||
if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) {
|
if (danaRSService != null && !mDeviceAddress.equals("") && !mDeviceName.equals("")) {
|
||||||
final Object o = new Object();
|
final Object o = new Object();
|
||||||
|
|
||||||
danaRSService.connect(from, mDeviceAddress, o);
|
danaRSService.connect(from, mDeviceAddress, o);
|
||||||
synchronized (o) {
|
|
||||||
try {
|
|
||||||
o.wait(20000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.error("InterruptedException " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pumpDescription.basalStep = pump.basalStep;
|
pumpDescription.basalStep = pump.basalStep;
|
||||||
pumpDescription.bolusStep = pump.bolusStep;
|
pumpDescription.bolusStep = pump.bolusStep;
|
||||||
if (isConnected())
|
|
||||||
log.debug("RS connected: " + from);
|
|
||||||
else {
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout)));
|
|
||||||
danaRSService.stopConnecting();
|
|
||||||
log.debug("RS connect failed from: " + from);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnected() {
|
@Override
|
||||||
|
public boolean isConnected() {
|
||||||
return danaRSService != null && danaRSService.isConnected();
|
return danaRSService != null && danaRSService.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnecting() {
|
@Override
|
||||||
|
public boolean isConnecting() {
|
||||||
return danaRSService != null && danaRSService.isConnecting();
|
return danaRSService != null && danaRSService.isConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disconnect(String from) {
|
@Override
|
||||||
|
public void disconnect(String from) {
|
||||||
if (danaRSService != null) danaRSService.disconnect(from);
|
if (danaRSService != null) danaRSService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessage(DanaRS_Packet message) {
|
@Override
|
||||||
if (danaRSService != null) danaRSService.sendMessage(message);
|
public void stopConnecting() {
|
||||||
|
if (danaRSService != null) danaRSService.stopConnecting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
if (danaRSService != null)
|
||||||
|
danaRSService.getPumpStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// DanaR interface
|
// DanaR interface
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
connectIfNotConnected("loadHistory");
|
return danaRSService.loadHistory(type);
|
||||||
danaRSService.loadHistory(type);
|
}
|
||||||
disconnect("LoadHistory");
|
|
||||||
return true;
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return danaRSService.loadEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constraints interface
|
// Constraints interface
|
||||||
|
@ -368,7 +360,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return pump.lastConnection.getTime() > 0;
|
return pump.lastConnection.getTime() > 0 && pump.maxBasal > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -383,30 +375,35 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized int setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
if (danaRSService == null) {
|
if (danaRSService == null) {
|
||||||
log.error("setNewBasalProfile sExecutionService is null");
|
log.error("setNewBasalProfile sExecutionService is null");
|
||||||
return FAILED;
|
result.comment = "setNewBasalProfile sExecutionService is null";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
log.error("setNewBasalProfile not initialized");
|
log.error("setNewBasalProfile not initialized");
|
||||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
return FAILED;
|
result.comment = MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
}
|
}
|
||||||
connectIfNotConnected("updateBasalsInPump");
|
|
||||||
if (!danaRSService.updateBasalsInPump(profile)) {
|
if (!danaRSService.updateBasalsInPump(profile)) {
|
||||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
disconnect("SetNewBasalProfile");
|
result.comment = MainApp.sResources.getString(R.string.failedupdatebasalprofile);
|
||||||
return FAILED;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||||
disconnect("SetNewBasalProfile");
|
result.success = true;
|
||||||
return SUCCESS;
|
result.enacted = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,16 +432,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void refreshDataFromPump(String reason) {
|
|
||||||
log.debug("Refreshing data from pump");
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
connect(reason);
|
|
||||||
disconnect("RefreshDataFromPump");
|
|
||||||
} else
|
|
||||||
log.debug("Already connecting ...");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -482,7 +469,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
Treatment t = new Treatment();
|
Treatment t = new Treatment();
|
||||||
boolean connectionOK = false;
|
boolean connectionOK = false;
|
||||||
connectIfNotConnected("bolus");
|
|
||||||
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
if (detailedBolusInfo.insulin > 0 || carbs > 0)
|
||||||
connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, System.currentTimeMillis() + carbTime * 60 * 1000 + 1000, t); // +1000 to make the record different
|
connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, System.currentTimeMillis() + carbTime * 60 * 1000 + 1000, t); // +1000 to make the record different
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -492,7 +478,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered);
|
||||||
disconnect("DeliverTreatment");
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
@ -518,9 +503,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
@Override
|
@Override
|
||||||
public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
public synchronized PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||||
// Recheck pump status if older than 30 min
|
// Recheck pump status if older than 30 min
|
||||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
|
||||||
connect("setTempBasalAbsolute old data");
|
//This should not be needed while using queue because connection should be done before calling this
|
||||||
}
|
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
// connect("setTempBasalAbsolute old data");
|
||||||
|
//}
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
|
@ -607,7 +594,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
if (percent > getPumpDescription().maxTempPercent)
|
if (percent > getPumpDescription().maxTempPercent)
|
||||||
percent = getPumpDescription().maxTempPercent;
|
percent = getPumpDescription().maxTempPercent;
|
||||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (runningTB != null && runningTB.percentRate == percent) {
|
if (runningTB != null && runningTB.percentRate == percent) {
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
@ -622,7 +609,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
int durationInHours = Math.max(durationInMinutes / 60, 1);
|
int durationInHours = Math.max(durationInMinutes / 60, 1);
|
||||||
connectIfNotConnected("tempbasal");
|
|
||||||
boolean connectionOK = danaRSService.tempBasal(percent, durationInHours);
|
boolean connectionOK = danaRSService.tempBasal(percent, durationInHours);
|
||||||
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -635,7 +621,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.isPercent = true;
|
result.isPercent = true;
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("setTempBasalPercent: OK");
|
log.debug("setTempBasalPercent: OK");
|
||||||
disconnect("setTempBasalPercent");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -647,7 +632,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
public synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
connectIfNotConnected("hightempbasal");
|
|
||||||
boolean connectionOK = danaRSService.highTempBasal(percent);
|
boolean connectionOK = danaRSService.highTempBasal(percent);
|
||||||
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -659,7 +643,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.isPercent = true;
|
result.isPercent = true;
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("setHighTempBasalPercent: OK");
|
log.debug("setHighTempBasalPercent: OK");
|
||||||
disconnect("setHighTempBasalPercent");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -675,7 +658,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||||
// needs to be rounded
|
// needs to be rounded
|
||||||
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||||
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1));
|
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
|
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
|
||||||
|
@ -690,9 +673,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
|
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
connectIfNotConnected("extendedBolus");
|
|
||||||
boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours);
|
boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours);
|
||||||
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
|
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAbsoluteRate - insulin) < getPumpDescription().extendedBolusStep) {
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
|
@ -703,7 +685,6 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
result.isPercent = false;
|
result.isPercent = false;
|
||||||
if (Config.logPumpActions)
|
if (Config.logPumpActions)
|
||||||
log.debug("setExtendedBolus: OK");
|
log.debug("setExtendedBolus: OK");
|
||||||
disconnect("setExtendedBolus");
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -716,13 +697,11 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
@Override
|
@Override
|
||||||
public synchronized PumpEnactResult cancelTempBasal(boolean force) {
|
public synchronized PumpEnactResult cancelTempBasal(boolean force) {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (runningTB != null) {
|
if (runningTB != null) {
|
||||||
connectIfNotConnected("tempBasalStop");
|
|
||||||
danaRSService.tempBasalStop();
|
danaRSService.tempBasalStop();
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.isTempCancel = true;
|
result.isTempCancel = true;
|
||||||
disconnect("cancelTempBasal");
|
|
||||||
}
|
}
|
||||||
if (!pump.isTempBasalInProgress) {
|
if (!pump.isTempBasalInProgress) {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
@ -745,11 +724,9 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
if (runningEB != null) {
|
if (runningEB != null) {
|
||||||
connectIfNotConnected("extendedBolusStop");
|
|
||||||
danaRSService.extendedBolusStop();
|
danaRSService.extendedBolusStop();
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
result.isTempCancel = true;
|
result.isTempCancel = true;
|
||||||
disconnect("extendedBolusStop");
|
|
||||||
}
|
}
|
||||||
if (!pump.isExtendedInProgress) {
|
if (!pump.isExtendedInProgress) {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
||||||
private int min = 0;
|
private int min = 0;
|
||||||
private int sec = 0;
|
private int sec = 0;
|
||||||
|
|
||||||
public boolean done;
|
public static boolean done;
|
||||||
private int totalCount;
|
private static int totalCount;
|
||||||
|
|
||||||
public static long lastEventTimeLoaded = 0;
|
public static long lastEventTimeLoaded = 0;
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
||||||
// Last record
|
// Last record
|
||||||
if (recordCode == (byte) 0xFF) {
|
if (recordCode == (byte) 0xFF) {
|
||||||
done = true;
|
done = true;
|
||||||
|
log.debug("Last record received");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.cozmo.danar.util.BleCommandUtil;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
|
|
@ -33,14 +33,14 @@ public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packe
|
||||||
dataSize = 2;
|
dataSize = 2;
|
||||||
pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
|
pump.initialBolusAmount = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
|
||||||
|
|
||||||
Date lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today
|
pump.lastBolusTime = new Date(); // it doesn't provide day only hour+min, workaround: expecting today
|
||||||
dataIndex += dataSize;
|
dataIndex += dataSize;
|
||||||
dataSize = 1;
|
dataSize = 1;
|
||||||
lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
|
pump.lastBolusTime.setHours(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
|
||||||
|
|
||||||
dataIndex += dataSize;
|
dataIndex += dataSize;
|
||||||
dataSize = 1;
|
dataSize = 1;
|
||||||
lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
|
pump.lastBolusTime.setMinutes(byteArrayToInt(getBytes(data, dataIndex, dataSize)));
|
||||||
|
|
||||||
dataIndex += dataSize;
|
dataIndex += dataSize;
|
||||||
dataSize = 2;
|
dataSize = 2;
|
||||||
|
@ -58,7 +58,7 @@ public class DanaRS_Packet_Bolus_Get_Step_Bolus_Information extends DanaRS_Packe
|
||||||
log.debug("Result: " + error);
|
log.debug("Result: " + error);
|
||||||
log.debug("BolusType: " + bolusType);
|
log.debug("BolusType: " + bolusType);
|
||||||
log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U");
|
log.debug("Initial bolus amount: " + pump.initialBolusAmount + " U");
|
||||||
log.debug("Last bolus time: " + lastBolusTime.toLocaleString());
|
log.debug("Last bolus time: " + pump.lastBolusTime.toLocaleString());
|
||||||
log.debug("Last bolus amount: " + pump.lastBolusAmount);
|
log.debug("Last bolus amount: " + pump.lastBolusAmount);
|
||||||
log.debug("Max bolus: " + pump.maxBolus + " U");
|
log.debug("Max bolus: " + pump.maxBolus + " U");
|
||||||
log.debug("Bolus step: " + pump.bolusStep + " U");
|
log.debug("Bolus step: " + pump.bolusStep + " U");
|
||||||
|
|
|
@ -6,11 +6,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
|
||||||
public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet {
|
public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet {
|
||||||
|
|
|
@ -10,8 +10,6 @@ import android.bluetooth.BluetoothManager;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import com.cozmo.danar.util.BleCommandUtil;
|
import com.cozmo.danar.util.BleCommandUtil;
|
||||||
|
@ -25,7 +23,6 @@ import java.util.UUID;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -33,7 +30,6 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingHelperActivity;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.activities.PairingProgressDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRSMessageHashTable;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPacket;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSPacket;
|
||||||
|
@ -62,27 +58,12 @@ public class BLEComm {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object mConfirmConnect = null;
|
|
||||||
|
|
||||||
private final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
private final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private ScheduledFuture<?> scheduledDisconnection = null;
|
private ScheduledFuture<?> scheduledDisconnection = null;
|
||||||
|
|
||||||
private DanaRS_Packet processsedMessage = null;
|
private DanaRS_Packet processsedMessage = null;
|
||||||
private ArrayList<byte[]> mSendQueue = new ArrayList<>();
|
private ArrayList<byte[]> mSendQueue = new ArrayList<>();
|
||||||
|
|
||||||
// Variables for connection progress (elapsed time)
|
|
||||||
private Handler sHandler;
|
|
||||||
private HandlerThread sHandlerThread;
|
|
||||||
private long connectionStartTime = 0;
|
|
||||||
private final Runnable updateProgress = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
|
||||||
sHandler.postDelayed(updateProgress, 1000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private BluetoothManager mBluetoothManager = null;
|
private BluetoothManager mBluetoothManager = null;
|
||||||
private BluetoothAdapter mBluetoothAdapter = null;
|
private BluetoothAdapter mBluetoothAdapter = null;
|
||||||
private BluetoothDevice mBluetoothDevice = null;
|
private BluetoothDevice mBluetoothDevice = null;
|
||||||
|
@ -101,12 +82,6 @@ public class BLEComm {
|
||||||
BLEComm(DanaRSService service) {
|
BLEComm(DanaRSService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
if (sHandlerThread == null) {
|
|
||||||
sHandlerThread = new HandlerThread(PairingProgressDialog.class.getSimpleName());
|
|
||||||
sHandlerThread.start();
|
|
||||||
sHandler = new Handler(sHandlerThread.getLooper());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean initialize() {
|
private boolean initialize() {
|
||||||
|
@ -138,7 +113,6 @@ public class BLEComm {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connect(String from, String address, Object confirmConnect) {
|
public boolean connect(String from, String address, Object confirmConnect) {
|
||||||
mConfirmConnect = confirmConnect;
|
|
||||||
BluetoothManager tBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE));
|
BluetoothManager tBluetoothManager = ((BluetoothManager) MainApp.instance().getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE));
|
||||||
if (tBluetoothManager == null) {
|
if (tBluetoothManager == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -160,9 +134,6 @@ public class BLEComm {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionStartTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING));
|
|
||||||
isConnecting = true;
|
isConnecting = true;
|
||||||
|
|
||||||
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
|
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
|
||||||
|
@ -171,10 +142,9 @@ public class BLEComm {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sHandler.post(updateProgress);
|
log.debug("Trying to create a new connection.");
|
||||||
mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback);
|
mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback);
|
||||||
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
||||||
log.debug("Trying to create a new connection.");
|
|
||||||
mBluetoothDevice = device;
|
mBluetoothDevice = device;
|
||||||
mBluetoothDeviceAddress = address;
|
mBluetoothDeviceAddress = address;
|
||||||
mBluetoothDeviceName = device.getName();
|
mBluetoothDeviceName = device.getName();
|
||||||
|
@ -183,7 +153,6 @@ public class BLEComm {
|
||||||
|
|
||||||
public void stopConnecting() {
|
public void stopConnecting() {
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
sHandler.removeCallbacks(updateProgress); // just to be sure
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(String from) {
|
public void disconnect(String from) {
|
||||||
|
@ -234,7 +203,7 @@ public class BLEComm {
|
||||||
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
|
||||||
close();
|
close();
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
sHandler.removeCallbacks(updateProgress); // just to be sure
|
isConnecting = false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
||||||
log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected
|
log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected
|
||||||
}
|
}
|
||||||
|
@ -242,14 +211,9 @@ public class BLEComm {
|
||||||
|
|
||||||
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
|
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
|
||||||
log.debug("onServicesDiscovered");
|
log.debug("onServicesDiscovered");
|
||||||
|
|
||||||
isConnecting = false;
|
|
||||||
|
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||||
findCharacteristic();
|
findCharacteristic();
|
||||||
}
|
}
|
||||||
// stop sending connection progress
|
|
||||||
sHandler.removeCallbacks(updateProgress);
|
|
||||||
SendPumpCheck();
|
SendPumpCheck();
|
||||||
// 1st message sent to pump after connect
|
// 1st message sent to pump after connect
|
||||||
}
|
}
|
||||||
|
@ -516,18 +480,11 @@ public class BLEComm {
|
||||||
pass = pass ^ 3463;
|
pass = pass ^ 3463;
|
||||||
DanaRPump.getInstance().rs_password = Integer.toHexString(pass);
|
DanaRPump.getInstance().rs_password = Integer.toHexString(pass);
|
||||||
log.debug("Pump user password: " + Integer.toHexString(pass));
|
log.debug("Pump user password: " + Integer.toHexString(pass));
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED));
|
|
||||||
|
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED));
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
service.getPumpStatus();
|
log.debug("RS connected and status read");
|
||||||
scheduleDisconnection();
|
|
||||||
if (mConfirmConnect != null) {
|
|
||||||
synchronized (mConfirmConnect) {
|
|
||||||
mConfirmConnect.notify();
|
|
||||||
mConfirmConnect = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -557,7 +514,6 @@ public class BLEComm {
|
||||||
} else {
|
} else {
|
||||||
log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer));
|
log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer));
|
||||||
}
|
}
|
||||||
scheduleDisconnection();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -652,7 +608,6 @@ public class BLEComm {
|
||||||
if (!message.isReceived()) {
|
if (!message.isReceived()) {
|
||||||
log.warn("Reply not received " + message.getFriendlyName());
|
log.warn("Reply not received " + message.getFriendlyName());
|
||||||
}
|
}
|
||||||
scheduleDisconnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendPairingRequest() {
|
private void SendPairingRequest() {
|
||||||
|
@ -681,22 +636,4 @@ public class BLEComm {
|
||||||
writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes);
|
writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduleDisconnection() {
|
|
||||||
|
|
||||||
class DisconnectRunnable implements Runnable {
|
|
||||||
public void run() {
|
|
||||||
disconnect("scheduleDisconnection");
|
|
||||||
scheduledDisconnection = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// prepare task for execution in 30 sec
|
|
||||||
// cancel waiting task to prevent sending multiple disconnections
|
|
||||||
if (scheduledDisconnection != null)
|
|
||||||
scheduledDisconnection.cancel(false);
|
|
||||||
Runnable task = new DisconnectRunnable();
|
|
||||||
final int sec = 30;
|
|
||||||
scheduledDisconnection = worker.schedule(task, sec, TimeUnit.SECONDS);
|
|
||||||
log.debug("Disconnection scheduled");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaRS.services;
|
package info.nightscout.androidaps.plugins.PumpDanaRS.services;
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -20,11 +18,13 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
@ -69,6 +69,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_D
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
@ -77,7 +78,6 @@ public class DanaRSService extends Service {
|
||||||
|
|
||||||
private BLEComm bleComm = BLEComm.getInstance(this);
|
private BLEComm bleComm = BLEComm.getInstance(this);
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
private DanaRPump danaRPump = DanaRPump.getInstance();
|
private DanaRPump danaRPump = DanaRPump.getInstance();
|
||||||
|
@ -92,10 +92,6 @@ public class DanaRSService extends Service {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, DanaRSService.class.getSimpleName());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
|
@ -122,7 +118,7 @@ public class DanaRSService extends Service {
|
||||||
bleComm.sendMessage(message);
|
bleComm.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
||||||
|
|
||||||
|
@ -130,7 +126,7 @@ public class DanaRSService extends Service {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State());
|
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State());
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
|
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus, bolusStep, maxBolus
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingtempbasalstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingtempbasalstatus)));
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
|
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
|
||||||
|
|
||||||
|
@ -141,7 +137,6 @@ public class DanaRSService extends Service {
|
||||||
bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check()); // firmware
|
bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check()); // firmware
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number());
|
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number());
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option()); // isExtendedEnabled
|
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option()); // isExtendedEnabled
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // bolusStep, maxBolus
|
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate()); // basal profile, basalStep, maxBasal
|
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate()); // basal profile, basalStep, maxBasal
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Calculation_Information()); // target
|
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Calculation_Information()); // target
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_CIR_CF_Array());
|
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_CIR_CF_Array());
|
||||||
|
@ -173,10 +168,10 @@ public class DanaRSService extends Service {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return true;
|
log.debug("Pump status loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadEvents() {
|
public PumpEnactResult loadEvents() {
|
||||||
DanaRS_Packet_APS_History_Events msg;
|
DanaRS_Packet_APS_History_Events msg;
|
||||||
if (lastHistoryFetched == 0) {
|
if (lastHistoryFetched == 0) {
|
||||||
msg = new DanaRS_Packet_APS_History_Events(0);
|
msg = new DanaRS_Packet_APS_History_Events(0);
|
||||||
|
@ -190,7 +185,8 @@ public class DanaRSService extends Service {
|
||||||
SystemClock.sleep(100);
|
SystemClock.sleep(100);
|
||||||
}
|
}
|
||||||
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded;
|
||||||
return true;
|
log.debug("Events loaded");
|
||||||
|
return new PumpEnactResult().success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -232,7 +228,7 @@ public class DanaRSService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
bolusingEvent.t = t;
|
bolusingEvent.t = t;
|
||||||
bolusingEvent.percent = 99;
|
bolusingEvent.percent = 99;
|
||||||
|
|
||||||
|
@ -257,14 +253,16 @@ public class DanaRSService extends Service {
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
}
|
}
|
||||||
if (!(isConnected()))
|
ConfigBuilderPlugin.getCommandQueue().loadEvents(new Callback() {
|
||||||
DanaRSPlugin.getPlugin().connect("loadEvents");
|
@Override
|
||||||
loadEvents();
|
public void run() {
|
||||||
// reread bolus status
|
// reread bolus status
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
|
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information()); // last bolus
|
||||||
bolusingEvent.percent = 100;
|
bolusingEvent.percent = 100;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,8 +357,9 @@ public class DanaRSService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
if (!isConnected()) return false;
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
if (!isConnected()) return result;
|
||||||
DanaRS_Packet_History_ msg = null;
|
DanaRS_Packet_History_ msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -401,7 +400,9 @@ public class DanaRSService extends Service {
|
||||||
SystemClock.sleep(200);
|
SystemClock.sleep(200);
|
||||||
bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(0));
|
bleComm.sendMessage(new DanaRS_Packet_General_Set_History_Upload_Mode(0));
|
||||||
}
|
}
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
|
@ -61,9 +61,9 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return DanaRFragment.class.getName();
|
return DanaRFragment.class.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fragmentPumpEnabled = false;
|
private static boolean fragmentPumpEnabled = false;
|
||||||
private boolean fragmentProfileEnabled = false;
|
private static boolean fragmentProfileEnabled = false;
|
||||||
private boolean fragmentPumpVisible = false;
|
private static boolean fragmentPumpVisible = true;
|
||||||
|
|
||||||
private static DanaRv2ExecutionService sExecutionService;
|
private static DanaRv2ExecutionService sExecutionService;
|
||||||
|
|
||||||
|
@ -186,11 +186,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
@Override
|
@Override
|
||||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
if (type == PluginBase.PROFILE)
|
if (type == PluginBase.PROFILE)
|
||||||
this.fragmentProfileEnabled = fragmentEnabled;
|
fragmentProfileEnabled = fragmentEnabled;
|
||||||
else if (type == PluginBase.PUMP)
|
else if (type == PluginBase.PUMP)
|
||||||
this.fragmentPumpEnabled = fragmentEnabled;
|
fragmentPumpEnabled = fragmentEnabled;
|
||||||
// if pump profile was enabled need to switch to another too
|
// if pump profile was enabled need to switch to another too
|
||||||
if (type == PluginBase.PUMP && !fragmentEnabled && this.fragmentProfileEnabled) {
|
if (type == PluginBase.PUMP && !fragmentEnabled && fragmentProfileEnabled) {
|
||||||
setFragmentEnabled(PluginBase.PROFILE, false);
|
setFragmentEnabled(PluginBase.PROFILE, false);
|
||||||
setFragmentVisible(PluginBase.PROFILE, false);
|
setFragmentVisible(PluginBase.PROFILE, false);
|
||||||
NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true);
|
NSProfilePlugin.getPlugin().setFragmentEnabled(PluginBase.PROFILE, true);
|
||||||
|
@ -201,7 +201,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
@Override
|
@Override
|
||||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||||
if (type == PluginBase.PUMP)
|
if (type == PluginBase.PUMP)
|
||||||
this.fragmentPumpVisible = fragmentVisible;
|
fragmentPumpVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -216,7 +216,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
return pump.lastConnection.getTime() > 0;
|
return pump.lastConnection.getTime() > 0 && pump.maxBasal > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -232,27 +232,35 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
|
|
||||||
// Pump interface
|
// Pump interface
|
||||||
@Override
|
@Override
|
||||||
public int setNewBasalProfile(Profile profile) {
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
if (sExecutionService == null) {
|
if (sExecutionService == null) {
|
||||||
log.error("setNewBasalProfile sExecutionService is null");
|
log.error("setNewBasalProfile sExecutionService is null");
|
||||||
return FAILED;
|
result.comment = "setNewBasalProfile sExecutionService is null";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
if (!isInitialized()) {
|
if (!isInitialized()) {
|
||||||
log.error("setNewBasalProfile not initialized");
|
log.error("setNewBasalProfile not initialized");
|
||||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
return FAILED;
|
result.comment = MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
}
|
}
|
||||||
if (!sExecutionService.updateBasalsInPump(profile)) {
|
if (!sExecutionService.updateBasalsInPump(profile)) {
|
||||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
return FAILED;
|
result.comment = MainApp.sResources.getString(R.string.failedupdatebasalprofile);
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||||
return SUCCESS;
|
result.success = true;
|
||||||
|
result.enacted = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,13 +289,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
return pump.lastConnection;
|
return pump.lastConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!isConnected() && !isConnecting()) {
|
|
||||||
doConnect(reason);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return pump.currentBasal;
|
return pump.currentBasal;
|
||||||
|
@ -360,9 +361,10 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew) {
|
||||||
// Recheck pump status if older than 30 min
|
// Recheck pump status if older than 30 min
|
||||||
if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
//This should not be needed while using queue because connection should be done before calling this
|
||||||
doConnect("setTempBasalAbsolute old data");
|
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
}
|
// connect("setTempBasalAbsolute old data");
|
||||||
|
//}
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
|
@ -397,7 +399,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
if (percentRate > 500) // Special high temp 500/15min
|
if (percentRate > 500) // Special high temp 500/15min
|
||||||
percentRate = 500;
|
percentRate = 500;
|
||||||
// Check if some temp is already in progress
|
// Check if some temp is already in progress
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||||
// Correct basal already set ?
|
// Correct basal already set ?
|
||||||
if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
|
if (MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).percentRate == percentRate) {
|
||||||
if (!enforceNew) {
|
if (!enforceNew) {
|
||||||
|
@ -513,7 +515,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
insulin = configBuilderPlugin.applyBolusConstraints(insulin);
|
||||||
// needs to be rounded
|
// needs to be rounded
|
||||||
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||||
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep * (1 + durationInHalfHours % 1));
|
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||||
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
|
if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) {
|
||||||
|
@ -597,7 +600,8 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doConnect(String from) {
|
@Override
|
||||||
|
public void connect(String from) {
|
||||||
if (sExecutionService != null) {
|
if (sExecutionService != null) {
|
||||||
sExecutionService.connect(from);
|
sExecutionService.connect(from);
|
||||||
pumpDescription.basalStep = pump.basalStep;
|
pumpDescription.basalStep = pump.basalStep;
|
||||||
|
@ -605,18 +609,31 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnected() {
|
@Override
|
||||||
|
public boolean isConnected() {
|
||||||
return sExecutionService != null && sExecutionService.isConnected();
|
return sExecutionService != null && sExecutionService.isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConnecting() {
|
@Override
|
||||||
|
public boolean isConnecting() {
|
||||||
return sExecutionService != null && sExecutionService.isConnecting();
|
return sExecutionService != null && sExecutionService.isConnecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doDisconnect(String from) {
|
@Override
|
||||||
|
public void disconnect(String from) {
|
||||||
if (sExecutionService != null) sExecutionService.disconnect(from);
|
if (sExecutionService != null) sExecutionService.disconnect(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
if (sExecutionService != null) sExecutionService.stopConnecting();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
if (sExecutionService != null) sExecutionService.getPumpStatus();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getJSONStatus() {
|
public JSONObject getJSONStatus() {
|
||||||
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
if (pump.lastConnection.getTime() + 5 * 60 * 1000L < System.currentTimeMillis()) {
|
||||||
|
@ -680,10 +697,15 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
return sExecutionService.loadHistory(type);
|
return sExecutionService.loadHistory(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult loadEvents() {
|
||||||
|
return sExecutionService.loadEvents();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constraint interface
|
* Constraint interface
|
||||||
*/
|
*/
|
||||||
|
@ -787,7 +809,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
if (pump.lastBolusTime.getTime() != 0) {
|
if (pump.lastBolusTime.getTime() != 0) {
|
||||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
|
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
|
||||||
}
|
}
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) {
|
||||||
ret += "Temp: " + MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull() + "\n";
|
ret += "Temp: " + MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull() + "\n";
|
||||||
}
|
}
|
||||||
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) {
|
||||||
|
@ -801,7 +823,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
|
||||||
ret += "Batt: " + pump.batteryRemaining + "\n";
|
ret += "Batt: " + pump.batteryRemaining + "\n";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: daily total constraint
|
// TODO: daily total constraint
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,21 @@ package info.nightscout.androidaps.plugins.PumpDanaRv2.comm;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 30.06.2016.
|
* Created by mike on 30.06.2016.
|
||||||
|
@ -36,14 +40,32 @@ public class MsgCheckValue_v2 extends MessageBase {
|
||||||
pump.protocol = intFromBuff(bytes, 1, 1);
|
pump.protocol = intFromBuff(bytes, 1, 1);
|
||||||
pump.productCode = intFromBuff(bytes, 2, 1);
|
pump.productCode = intFromBuff(bytes, 2, 1);
|
||||||
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
if (pump.model != DanaRPump.EXPORT_MODEL) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
DanaRv2Plugin.doDisconnect("Wrong Model");
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
log.debug("Wrong model selected");
|
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
|
||||||
|
log.debug("Wrong model selected. Switching to Korean DanaR");
|
||||||
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentEnabled(PluginBase.PUMP, true);
|
||||||
|
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true);
|
||||||
|
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentEnabled(PluginBase.PUMP, false);
|
||||||
|
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false);
|
||||||
|
DanaRPump.getInstance().lastConnection = new Date(0); // mark not initialized
|
||||||
|
|
||||||
|
//If profile coming from pump, switch it as well
|
||||||
|
if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){
|
||||||
|
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, false);
|
||||||
|
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setFragmentEnabled(PluginBase.PROFILE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pump.protocol != 2) {
|
if (pump.protocol != 2) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.wrongpumpdriverselected), R.raw.error);
|
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||||
DanaRKoreanPlugin.doDisconnect("Wrong Model");
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
|
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
||||||
log.debug("Wrong model selected. Switching to non APS DanaR");
|
log.debug("Wrong model selected. Switching to non APS DanaR");
|
||||||
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
|
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentEnabled(PluginBase.PUMP, false);
|
||||||
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentVisible(PluginBase.PUMP, false);
|
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentVisible(PluginBase.PUMP, false);
|
||||||
|
@ -57,7 +79,8 @@ public class MsgCheckValue_v2 extends MessageBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
MainApp.bus().post(new EventRefreshOverview("MsgCheckValue_v2"));
|
MainApp.bus().post(new EventRefreshGui());
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Config.logDanaMessageDetail) {
|
if (Config.logDanaMessageDetail) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
@ -27,14 +26,15 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
@ -61,14 +62,12 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
private BluetoothSocket mRfcommSocket;
|
private BluetoothSocket mRfcommSocket;
|
||||||
private BluetoothDevice mBTDevice;
|
private BluetoothDevice mBTDevice;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
|
||||||
private IBinder mBinder = new LocalBinder();
|
private IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
private DanaRPump danaRPump;
|
private DanaRPump danaRPump;
|
||||||
private Treatment bolusingTreatment = null;
|
private Treatment bolusingTreatment = null;
|
||||||
|
|
||||||
private static Boolean connectionInProgress = false;
|
private static Boolean connectionInProgress = false;
|
||||||
private static final Object connectionLock = new Object();
|
|
||||||
|
|
||||||
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
private static final UUID SPP_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
||||||
|
|
||||||
|
@ -95,9 +94,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
registerBus();
|
registerBus();
|
||||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||||
danaRPump = DanaRPump.getInstance();
|
danaRPump = DanaRPump.getInstance();
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaRv2ExecutionService");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
|
@ -159,35 +155,28 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (isConnected() || isConnecting()) {
|
|
||||||
if (Config.logDanaBTComm)
|
if (connectionInProgress)
|
||||||
log.debug("already connected/connecting from: " + from);
|
return;
|
||||||
waitMsec(3000);
|
|
||||||
}
|
new Thread(new Runnable() {
|
||||||
final long maxConnectionTime = 5 * 60 * 1000L; // 5 min
|
@Override
|
||||||
synchronized (connectionLock) {
|
public void run() {
|
||||||
//log.debug("entering connection while loop");
|
connectionInProgress = true;
|
||||||
connectionInProgress = true;
|
getBTSocketForSelectedPump();
|
||||||
mWakeLock.acquire();
|
if (mRfcommSocket == null || mBTDevice == null) {
|
||||||
getBTSocketForSelectedPump();
|
connectionInProgress = false;
|
||||||
if (mRfcommSocket == null || mBTDevice == null)
|
return; // Device not found
|
||||||
return; // Device not found
|
}
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
while (!isConnected() && startTime + maxConnectionTime >= System.currentTimeMillis()) {
|
|
||||||
long secondsElapsed = (System.currentTimeMillis() - startTime) / 1000L;
|
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
|
||||||
if (Config.logDanaBTComm)
|
|
||||||
log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
|
|
||||||
try {
|
try {
|
||||||
mRfcommSocket.connect();
|
mRfcommSocket.connect();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//log.error("Unhandled exception", e);
|
//log.error("Unhandled exception", e);
|
||||||
if (e.getMessage().contains("socket closed")) {
|
if (e.getMessage().contains("socket closed")) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitMsec(1000);
|
|
||||||
|
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
if (mSerialIOThread != null) {
|
if (mSerialIOThread != null) {
|
||||||
|
@ -195,23 +184,16 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
|
||||||
if (!getPumpStatus()) {
|
|
||||||
mSerialIOThread.disconnect("getPumpStatus failed");
|
|
||||||
waitMsec(3000);
|
|
||||||
if (!MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginBase.PUMP))
|
|
||||||
return;
|
|
||||||
getBTSocketForSelectedPump();
|
|
||||||
startTime = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectionInProgress = false;
|
||||||
}
|
}
|
||||||
if (!isConnected()) {
|
}).start();
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
}
|
||||||
log.error("Pump connection timed out");
|
|
||||||
}
|
public void stopConnecting() {
|
||||||
connectionInProgress = false;
|
if (mSerialIOThread != null)
|
||||||
mWakeLock.release();
|
mSerialIOThread.disconnect("stopConnecting");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBTSocketForSelectedPump() {
|
private void getBTSocketForSelectedPump() {
|
||||||
|
@ -246,7 +228,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
|
||||||
MsgStatus statusMsg = new MsgStatus();
|
MsgStatus statusMsg = new MsgStatus();
|
||||||
|
@ -258,7 +240,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
if (danaRPump.isNewPump) {
|
if (danaRPump.isNewPump) {
|
||||||
mSerialIOThread.sendMessage(checkValue);
|
mSerialIOThread.sendMessage(checkValue);
|
||||||
if (!checkValue.received) {
|
if (!checkValue.received) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,28 +252,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingextendedbolusstatus)));
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
mSerialIOThread.sendMessage(exStatusMsg);
|
||||||
|
|
||||||
if (!statusMsg.received) {
|
|
||||||
mSerialIOThread.sendMessage(statusMsg);
|
|
||||||
}
|
|
||||||
if (!statusBasicMsg.received) {
|
|
||||||
mSerialIOThread.sendMessage(statusBasicMsg);
|
|
||||||
}
|
|
||||||
if (!tempStatusMsg.received) {
|
|
||||||
// Load of status of current basal rate failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(tempStatusMsg);
|
|
||||||
}
|
|
||||||
if (!exStatusMsg.received) {
|
|
||||||
// Load of status of current extended bolus failed, give one more try
|
|
||||||
mSerialIOThread.sendMessage(exStatusMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check we have really current status of pump
|
|
||||||
if (!statusMsg.received || !statusBasicMsg.received || !tempStatusMsg.received || !exStatusMsg.received) {
|
|
||||||
waitMsec(10 * 1000);
|
|
||||||
log.debug("getPumpStatus failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) {
|
if (danaRPump.lastSettingsRead.getTime() + 60 * 60 * 1000L < now.getTime() || !MainApp.getSpecificPlugin(DanaRv2Plugin.class).isInitialized()) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpsettings)));
|
||||||
|
@ -333,11 +293,10 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasal(int percent, int durationInHours) {
|
public boolean tempBasal(int percent, int durationInHours) {
|
||||||
connect("tempBasal");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
if (danaRPump.isTempBasalInProgress) {
|
if (danaRPump.isTempBasalInProgress) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
|
@ -353,7 +312,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean highTempBasal(int percent) {
|
public boolean highTempBasal(int percent) {
|
||||||
connect("highTempBasal");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
if (danaRPump.isTempBasalInProgress) {
|
if (danaRPump.isTempBasalInProgress) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
|
@ -369,7 +327,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tempBasalStop() {
|
public boolean tempBasalStop() {
|
||||||
connect("tempBasalStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
|
||||||
|
@ -380,7 +337,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
public boolean extendedBolus(double insulin, int durationInHalfHours) {
|
||||||
connect("extendedBolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
||||||
|
@ -391,7 +347,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendedBolusStop() {
|
public boolean extendedBolusStop() {
|
||||||
connect("extendedBolusStop");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
||||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
||||||
|
@ -401,7 +356,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean bolus(final double amount, int carbs, long carbtime, Treatment t) {
|
public boolean bolus(final double amount, int carbs, long carbtime, final Treatment t) {
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.startingbolus)));
|
||||||
bolusingTreatment = t;
|
bolusingTreatment = t;
|
||||||
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
final int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||||
|
@ -412,7 +367,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
start = new MsgBolusStartWithSpeed(amount, preferencesSpeed);
|
||||||
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
MsgBolusStop stop = new MsgBolusStop(amount, t);
|
||||||
|
|
||||||
connect("bolus");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
|
|
||||||
if (carbs > 0) {
|
if (carbs > 0) {
|
||||||
|
@ -435,7 +389,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
while (!stop.stopped && !start.failed) {
|
while (!stop.stopped && !start.failed) {
|
||||||
waitMsec(100);
|
waitMsec(100);
|
||||||
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 5 sec expecting broken comm
|
if ((System.currentTimeMillis() - progress.lastReceive) > 15 * 1000L) { // if i didn't receive status for more than 15 sec expecting broken comm
|
||||||
stop.stopped = true;
|
stop.stopped = true;
|
||||||
stop.forced = true;
|
stop.forced = true;
|
||||||
log.debug("Communication stopped");
|
log.debug("Communication stopped");
|
||||||
|
@ -443,7 +397,7 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
final EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance();
|
||||||
bolusingEvent.t = t;
|
bolusingEvent.t = t;
|
||||||
bolusingEvent.percent = 99;
|
bolusingEvent.percent = 99;
|
||||||
|
|
||||||
|
@ -468,16 +422,18 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
MainApp.bus().post(bolusingEvent);
|
MainApp.bus().post(bolusingEvent);
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
}
|
}
|
||||||
if (!(isConnected()))
|
ConfigBuilderPlugin.getCommandQueue().loadEvents(new Callback() {
|
||||||
connect("loadEvents");
|
@Override
|
||||||
loadEvents();
|
public void run() {
|
||||||
// load last bolus status
|
// load last bolus status
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingbolusstatus)));
|
||||||
mSerialIOThread.sendMessage(new MsgStatus());
|
mSerialIOThread.sendMessage(new MsgStatus());
|
||||||
bolusingEvent.percent = 100;
|
bolusingEvent.percent = 100;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.disconnecting)));
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bolusStop() {
|
public void bolusStop() {
|
||||||
if (Config.logDanaBTComm)
|
if (Config.logDanaBTComm)
|
||||||
|
@ -496,7 +452,6 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean carbsEntry(int amount, long time) {
|
public boolean carbsEntry(int amount, long time) {
|
||||||
connect("carbsEntry");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
MsgSetCarbsEntry msg = new MsgSetCarbsEntry(time, amount);
|
||||||
mSerialIOThread.sendMessage(msg);
|
mSerialIOThread.sendMessage(msg);
|
||||||
|
@ -506,9 +461,9 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadHistory(byte type) {
|
public PumpEnactResult loadHistory(byte type) {
|
||||||
connect("loadHistory");
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return result;
|
||||||
MessageBase msg = null;
|
MessageBase msg = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
|
@ -548,11 +503,14 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
mSerialIOThread.sendMessage(new MsgPCCommStop());
|
||||||
return true;
|
result.success = true;
|
||||||
|
result.comment = "OK";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadEvents() {
|
public PumpEnactResult loadEvents() {
|
||||||
if (!isConnected()) return false;
|
if (!isConnected())
|
||||||
|
return new PumpEnactResult().success(false);
|
||||||
waitMsec(300);
|
waitMsec(300);
|
||||||
MsgHistoryEvents_v2 msg;
|
MsgHistoryEvents_v2 msg;
|
||||||
if (lastHistoryFetched == 0) {
|
if (lastHistoryFetched == 0) {
|
||||||
|
@ -568,11 +526,10 @@ public class DanaRv2ExecutionService extends Service {
|
||||||
}
|
}
|
||||||
waitMsec(200);
|
waitMsec(200);
|
||||||
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded;
|
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded;
|
||||||
return true;
|
return new PumpEnactResult().success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateBasalsInPump(final Profile profile) {
|
public boolean updateBasalsInPump(final Profile profile) {
|
||||||
connect("updateBasalsInPump");
|
|
||||||
if (!isConnected()) return false;
|
if (!isConnected()) return false;
|
||||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
|
||||||
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
double[] basal = DanaRPump.buildDanaRProfileRecord(profile);
|
||||||
|
|
|
@ -130,9 +130,37 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int setNewBasalProfile(Profile profile) {
|
public boolean isConnected() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConnecting() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect(String reason) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect(String reason) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||||
return SUCCESS;
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
result.success = true;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,11 +173,6 @@ public class MDIPlugin implements PluginBase, PumpInterface {
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
return 0d;
|
return 0d;
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class VirtualPumpFragment extends SubscriberFragment {
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
try {
|
try {
|
||||||
View view = inflater.inflate(R.layout.vitualpump_fragment, container, false);
|
View view = inflater.inflate(R.layout.virtualpump_fragment, container, false);
|
||||||
basaBasalRateView = (TextView) view.findViewById(R.id.virtualpump_basabasalrate);
|
basaBasalRateView = (TextView) view.findViewById(R.id.virtualpump_basabasalrate);
|
||||||
tempBasalView = (TextView) view.findViewById(R.id.virtualpump_tempbasal);
|
tempBasalView = (TextView) view.findViewById(R.id.virtualpump_tempbasal);
|
||||||
extendedBolusView = (TextView) view.findViewById(R.id.virtualpump_extendedbolus);
|
extendedBolusView = (TextView) view.findViewById(R.id.virtualpump_extendedbolus);
|
||||||
|
|
|
@ -166,7 +166,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFakingTempsByExtendedBoluses() {
|
public boolean isFakingTempsByExtendedBoluses() {
|
||||||
return Config.NSCLIENT && fromNSAreCommingFakedExtendedBoluses;
|
return (Config.NSCLIENT || Config.G5UPLOADER) && fromNSAreCommingFakedExtendedBoluses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -185,10 +185,41 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int setNewBasalProfile(Profile profile) {
|
public boolean isConnected() {
|
||||||
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConnecting() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect(String reason) {
|
||||||
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
|
NSUpload.uploadDeviceStatus();
|
||||||
lastDataTime = new Date();
|
lastDataTime = new Date();
|
||||||
return SUCCESS;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnect(String reason) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopConnecting() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getPumpStatus() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PumpEnactResult setNewBasalProfile(Profile profile) {
|
||||||
|
lastDataTime = new Date();
|
||||||
|
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
result.success = true;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -201,13 +232,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
return lastDataTime;
|
return lastDataTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDataFromPump(String reason) {
|
|
||||||
if (!BuildConfig.NSCLIENTOLNY)
|
|
||||||
NSUpload.uploadDeviceStatus();
|
|
||||||
lastDataTime = new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBaseBasalRate() {
|
public double getBaseBasalRate() {
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
|
|
@ -25,22 +25,21 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
|
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -225,7 +224,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSms(Sms receivedSms) {
|
private void processSms(final Sms receivedSms) {
|
||||||
if (!isEnabled(PluginBase.GENERAL)) {
|
if (!isEnabled(PluginBase.GENERAL)) {
|
||||||
log.debug("Ignoring SMS. Plugin disabled.");
|
log.debug("Ignoring SMS. Plugin disabled.");
|
||||||
return;
|
return;
|
||||||
|
@ -287,11 +286,15 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
|
LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
|
||||||
if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) {
|
if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) {
|
||||||
loopPlugin.setFragmentEnabled(PluginBase.LOOP, false);
|
loopPlugin.setFragmentEnabled(PluginBase.LOOP, false);
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP"));
|
@Override
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeendisabled) + " " +
|
public void run() {
|
||||||
MainApp.sResources.getString(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
|
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP"));
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
String reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeendisabled) + " " +
|
||||||
|
MainApp.sResources.getString(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Stop"));
|
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Stop"));
|
||||||
|
@ -435,7 +438,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
|
if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_remotebolusnotallowed);
|
reply = MainApp.sResources.getString(R.string.smscommunicator_remotebolusnotallowed);
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
} else if (MainApp.getConfigBuilder().isSuspended()) {
|
} else if (ConfigBuilderPlugin.getActivePump().isSuspended()) {
|
||||||
reply = MainApp.sResources.getString(R.string.pumpsuspended);
|
reply = MainApp.sResources.getString(R.string.pumpsuspended);
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
} else if (splited.length > 1) {
|
} else if (splited.length > 1) {
|
||||||
|
@ -476,64 +479,61 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed &&
|
if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed &&
|
||||||
bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||||
bolusWaitingForConfirmation.processed = true;
|
bolusWaitingForConfirmation.processed = true;
|
||||||
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
if (pumpInterface != null) {
|
detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested;
|
||||||
danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
detailedBolusInfo.source = Source.USER;
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested;
|
@Override
|
||||||
detailedBolusInfo.source = Source.USER;
|
public void run() {
|
||||||
PumpEnactResult result = pumpInterface.deliverTreatment(detailedBolusInfo);
|
DanaRPlugin danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
String reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
||||||
if (danaRPlugin != null)
|
if (danaRPlugin != null)
|
||||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||||
lastRemoteBolusTime = new Date();
|
lastRemoteBolusTime = new Date();
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
} else {
|
} else {
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_bolusfailed);
|
String reply = MainApp.sResources.getString(R.string.smscommunicator_bolusfailed);
|
||||||
if (danaRPlugin != null)
|
if (danaRPlugin != null)
|
||||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
} else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed &&
|
} else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed &&
|
||||||
tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||||
tempBasalWaitingForConfirmation.processed = true;
|
tempBasalWaitingForConfirmation.processed = true;
|
||||||
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(tempBasalWaitingForConfirmation.tempBasal, 30, true, new Callback() {
|
||||||
if (pumpInterface != null) {
|
@Override
|
||||||
danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
public void run() {
|
||||||
PumpEnactResult result = pumpInterface.setTempBasalAbsolute(tempBasalWaitingForConfirmation.tempBasal, 30, true);
|
if (result.success) {
|
||||||
if (result.success) {
|
String reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
|
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
|
||||||
if (danaRPlugin != null)
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
} else {
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalfailed);
|
||||||
} else {
|
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalfailed);
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
if (danaRPlugin != null)
|
}
|
||||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
} else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed &&
|
} else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed &&
|
||||||
cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||||
cancelTempBasalWaitingForConfirmation.processed = true;
|
cancelTempBasalWaitingForConfirmation.processed = true;
|
||||||
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
if (pumpInterface != null) {
|
@Override
|
||||||
danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
public void run() {
|
||||||
PumpEnactResult result = pumpInterface.cancelTempBasal(true);
|
if (result.success) {
|
||||||
if (result.success) {
|
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled);
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled);
|
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
|
||||||
if (danaRPlugin != null)
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
} else {
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed);
|
||||||
} else {
|
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed);
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
if (danaRPlugin != null)
|
}
|
||||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
} else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed &&
|
} else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed &&
|
||||||
calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||||
calibrationWaitingForConfirmation.processed = true;
|
calibrationWaitingForConfirmation.processed = true;
|
||||||
|
@ -548,14 +548,24 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
|
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
|
||||||
suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||||
suspendWaitingForConfirmation.processed = true;
|
suspendWaitingForConfirmation.processed = true;
|
||||||
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
|
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
|
||||||
activeloop.suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000);
|
@Override
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true);
|
public void run() {
|
||||||
NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60);
|
if (result.success) {
|
||||||
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED"));
|
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended) + " " +
|
activeloop.suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000);
|
||||||
MainApp.sResources.getString(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
|
NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60);
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED"));
|
||||||
|
String reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended) + " " +
|
||||||
|
MainApp.sResources.getString(result.success ? R.string.smscommunicator_tempbasalcanceled : R.string.smscommunicator_tempbasalcancelfailed);
|
||||||
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
|
} else {
|
||||||
|
String reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed);
|
||||||
|
reply += "\n" + ConfigBuilderPlugin.getActivePump().shortStatus(true);
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.sResources.getString(R.string.smscommunicator_unknowncommand), new Date()));
|
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.sResources.getString(R.string.smscommunicator_unknowncommand), new Date()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
package info.nightscout.androidaps.plugins.SourceDexcomG5;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Config;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 28.11.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface {
|
||||||
|
private boolean fragmentEnabled = false;
|
||||||
|
|
||||||
|
private static SourceDexcomG5Plugin plugin = null;
|
||||||
|
|
||||||
|
public static SourceDexcomG5Plugin getPlugin() {
|
||||||
|
if (plugin == null)
|
||||||
|
plugin = new SourceDexcomG5Plugin();
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFragmentClass() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getType() {
|
||||||
|
return PluginBase.BGSOURCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return MainApp.instance().getString(R.string.DexcomG5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNameShort() {
|
||||||
|
// use long name as fallback (no tabs)
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int type) {
|
||||||
|
return Config.G5UPLOADER || type == BGSOURCE && 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 !Config.G5UPLOADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
|
if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferencesId() {
|
||||||
|
return R.xml.pref_dexcomg5;
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,19 +9,23 @@ import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsBolusFragment;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsBolusFragment;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsExtendedBolusesFragment;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsExtendedBolusesFragment;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsProfileSwitchFragment;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsProfileSwitchFragment;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempTargetFragment;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempTargetFragment;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTemporaryBasalsFragment;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTemporaryBasalsFragment;
|
||||||
|
|
||||||
public class TreatmentsFragment extends Fragment implements View.OnClickListener {
|
public class TreatmentsFragment extends SubscriberFragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
|
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
|
||||||
|
|
||||||
TextView treatmentsTab;
|
TextView treatmentsTab;
|
||||||
|
@ -102,4 +106,19 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener
|
||||||
profileSwitchTab.setBackgroundColor(MainApp.sResources.getColor(R.color.defaultbackground));
|
profileSwitchTab.setBackgroundColor(MainApp.sResources.getColor(R.color.defaultbackground));
|
||||||
selected.setBackgroundColor(MainApp.sResources.getColor(R.color.tabBgColorSelected));
|
selected.setBackgroundColor(MainApp.sResources.getColor(R.color.tabBgColorSelected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateGUI() {
|
||||||
|
if (ConfigBuilderPlugin.getActivePump().getPumpDescription().isExtendedBolusCapable
|
||||||
|
|| MainApp.getConfigBuilder().getExtendedBolusesFromHistory().size() > 0) {
|
||||||
|
extendedBolusesTab.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
extendedBolusesTab.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -16,10 +16,10 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
import info.nightscout.androidaps.data.Intervals;
|
||||||
import info.nightscout.androidaps.data.Iob;
|
import info.nightscout.androidaps.data.Iob;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.data.Intervals;
|
|
||||||
import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
||||||
import info.nightscout.androidaps.data.OverlappingIntervals;
|
import info.nightscout.androidaps.data.OverlappingIntervals;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
@ -34,8 +34,8 @@ import info.nightscout.androidaps.events.EventReloadTempBasalData;
|
||||||
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
||||||
import info.nightscout.androidaps.events.EventTempTargetChange;
|
import info.nightscout.androidaps.events.EventTempTargetChange;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -109,7 +109,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showInList(int type) {
|
public boolean showInList(int type) {
|
||||||
return !Config.NSCLIENT;
|
return !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -201,8 +201,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
if (!t.isSMB) {
|
if (!t.isSMB) {
|
||||||
// instead of dividing the DIA that only worked on the bilinear curves,
|
// instead of dividing the DIA that only worked on the bilinear curves,
|
||||||
// multiply the time the treatment is seen active.
|
// multiply the time the treatment is seen active.
|
||||||
long timeSinceTreatment = time - t.date;
|
long timeSinceTreatment = time - t.date;
|
||||||
long snoozeTime = t.date + (long)(timeSinceTreatment * SP.getDouble("openapsama_bolussnooze_dia_divisor", 2.0));
|
long snoozeTime = t.date + (long) (timeSinceTreatment * SP.getDouble("openapsama_bolussnooze_dia_divisor", 2.0));
|
||||||
Iob bIOB = t.iobCalc(snoozeTime, dia);
|
Iob bIOB = t.iobCalc(snoozeTime, dia);
|
||||||
total.bolussnooze += bIOB.iobContrib;
|
total.bolussnooze += bIOB.iobContrib;
|
||||||
} else {
|
} else {
|
||||||
|
@ -216,7 +216,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses())
|
if (!ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses())
|
||||||
synchronized (extendedBoluses) {
|
synchronized (extendedBoluses) {
|
||||||
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
||||||
ExtendedBolus e = extendedBoluses.get(pos);
|
ExtendedBolus e = extendedBoluses.get(pos);
|
||||||
|
@ -351,7 +351,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
total.plus(calc);
|
total.plus(calc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) {
|
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
|
||||||
IobTotal totalExt = new IobTotal(time);
|
IobTotal totalExt = new IobTotal(time);
|
||||||
synchronized (extendedBoluses) {
|
synchronized (extendedBoluses) {
|
||||||
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
||||||
|
@ -383,7 +383,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
if (tb != null)
|
if (tb != null)
|
||||||
return tb;
|
return tb;
|
||||||
ExtendedBolus eb = getExtendedBolusFromHistory(time);
|
ExtendedBolus eb = getExtendedBolusFromHistory(time);
|
||||||
if (eb != null && MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses())
|
if (eb != null && ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses())
|
||||||
return new TemporaryBasal(eb);
|
return new TemporaryBasal(eb);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -406,18 +406,16 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getTempBasalAbsoluteRateHistory() {
|
public double getTempBasalAbsoluteRateHistory() {
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
|
|
||||||
TemporaryBasal tb = getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal tb = getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
if (tb != null) {
|
if (tb != null) {
|
||||||
if (tb.isFakeExtended){
|
if (tb.isFakeExtended) {
|
||||||
double baseRate = pump.getBaseBasalRate();
|
double baseRate = ConfigBuilderPlugin.getActivePump().getBaseBasalRate();
|
||||||
double tempRate = baseRate + tb.netExtendedRate;
|
double tempRate = baseRate + tb.netExtendedRate;
|
||||||
return tempRate;
|
return tempRate;
|
||||||
} else if (tb.isAbsolute) {
|
} else if (tb.isAbsolute) {
|
||||||
return tb.absoluteRate;
|
return tb.absoluteRate;
|
||||||
} else {
|
} else {
|
||||||
double baseRate = pump.getBaseBasalRate();
|
double baseRate = ConfigBuilderPlugin.getActivePump().getBaseBasalRate();
|
||||||
double tempRate = baseRate * (tb.percentRate / 100d);
|
double tempRate = baseRate * (tb.percentRate / 100d);
|
||||||
return tempRate;
|
return tempRate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,12 @@ import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
@ -33,15 +32,16 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
|
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.BolusWizard;
|
import info.nightscout.utils.BolusWizard;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
@ -173,8 +173,8 @@ public class ActionStringHandler {
|
||||||
} else if ("loop".equals(act[1])) {
|
} else if ("loop".equals(act[1])) {
|
||||||
rTitle += " LOOP";
|
rTitle += " LOOP";
|
||||||
rMessage = "TARGETS:\n" + getTargetsStatus();
|
rMessage = "TARGETS:\n" + getTargetsStatus();
|
||||||
rMessage += "\n\n" + getLoopStatus();
|
rMessage += "\n\n" + getLoopStatus();
|
||||||
rMessage += "\n\nOAPS RESULT:\n" + getOAPSResultStatus();
|
rMessage += "\n\nOAPS RESULT:\n" + getOAPSResultStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ("wizard".equals(act[0])) {
|
} else if ("wizard".equals(act[0])) {
|
||||||
|
@ -236,15 +236,15 @@ public class ActionStringHandler {
|
||||||
rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
|
rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
|
||||||
if (useBasalIOB)
|
if (useBasalIOB)
|
||||||
rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
|
rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
|
||||||
if(percentage != 100){
|
if (percentage != 100) {
|
||||||
rMessage += "\nPercentage: " +format.format(bolusWizard.totalBeforePercentageAdjustment) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.calculatedTotalInsulin) + "U";
|
rMessage += "\nPercentage: " + format.format(bolusWizard.totalBeforePercentageAdjustment) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.calculatedTotalInsulin) + "U";
|
||||||
}
|
}
|
||||||
|
|
||||||
lastBolusWizard = bolusWizard;
|
lastBolusWizard = bolusWizard;
|
||||||
|
|
||||||
} else if("opencpp".equals(act[0])){
|
} else if ("opencpp".equals(act[0])) {
|
||||||
ProfileSwitch activeProfileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
ProfileSwitch activeProfileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
if(activeProfileSwitch==null){
|
if (activeProfileSwitch == null) {
|
||||||
sendError("No active profile switch!");
|
sendError("No active profile switch!");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,30 +254,30 @@ public class ActionStringHandler {
|
||||||
rAction = "opencpp" + " " + activeProfileSwitch.percentage + " " + activeProfileSwitch.timeshift;
|
rAction = "opencpp" + " " + activeProfileSwitch.percentage + " " + activeProfileSwitch.timeshift;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if("cppset".equals(act[0])){
|
} else if ("cppset".equals(act[0])) {
|
||||||
ProfileSwitch activeProfileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
ProfileSwitch activeProfileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||||
if(activeProfileSwitch==null){
|
if (activeProfileSwitch == null) {
|
||||||
sendError("No active profile switch!");
|
sendError("No active profile switch!");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// read CPP values
|
// read CPP values
|
||||||
rMessage = "CPP:" + "\n\n"+
|
rMessage = "CPP:" + "\n\n" +
|
||||||
"Timeshift: " + act[1] + "\n" +
|
"Timeshift: " + act[1] + "\n" +
|
||||||
"Percentage: " + act[2] + "%";
|
"Percentage: " + act[2] + "%";
|
||||||
rAction = actionstring;
|
rAction = actionstring;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if("tddstats".equals(act[0])){
|
} else if ("tddstats".equals(act[0])) {
|
||||||
Object activePump = MainApp.getConfigBuilder().getActivePump();
|
Object activePump = MainApp.getConfigBuilder().getActivePump();
|
||||||
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||||
PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
||||||
PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
|
PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
|
||||||
|
|
||||||
|
|
||||||
if((dana == null || dana != activePump) &&
|
if ((dana == null || dana != activePump) &&
|
||||||
(danaV2 == null || danaV2 != activePump) &&
|
(danaV2 == null || danaV2 != activePump) &&
|
||||||
(danaKorean == null || danaKorean != activePump)
|
(danaKorean == null || danaKorean != activePump)
|
||||||
){
|
) {
|
||||||
sendError("Pump does not support TDDs!");
|
sendError("Pump does not support TDDs!");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -285,7 +285,7 @@ public class ActionStringHandler {
|
||||||
List<DanaRHistoryRecord> dummies = new LinkedList<DanaRHistoryRecord>();
|
List<DanaRHistoryRecord> dummies = new LinkedList<DanaRHistoryRecord>();
|
||||||
List<DanaRHistoryRecord> historyList = getTDDList(dummies);
|
List<DanaRHistoryRecord> historyList = getTDDList(dummies);
|
||||||
|
|
||||||
if(isOldData(historyList)){
|
if (isOldData(historyList)) {
|
||||||
rTitle = "TDD";
|
rTitle = "TDD";
|
||||||
rAction = "statusmessage";
|
rAction = "statusmessage";
|
||||||
rMessage = "OLD DATA - ";
|
rMessage = "OLD DATA - ";
|
||||||
|
@ -300,10 +300,10 @@ public class ActionStringHandler {
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
((DanaRInterface)pump).loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
((DanaRInterface) pump).loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
||||||
List<DanaRHistoryRecord> dummies = new LinkedList<DanaRHistoryRecord>();
|
List<DanaRHistoryRecord> dummies = new LinkedList<DanaRHistoryRecord>();
|
||||||
List<DanaRHistoryRecord> historyList = getTDDList(dummies);
|
List<DanaRHistoryRecord> historyList = getTDDList(dummies);
|
||||||
if(isOldData(historyList)){
|
if (isOldData(historyList)) {
|
||||||
sendStatusmessage("TDD", "TDD: Still old data! Cannot load from pump.");
|
sendStatusmessage("TDD", "TDD: Still old data! Cannot load from pump.");
|
||||||
} else {
|
} else {
|
||||||
sendStatusmessage("TDD", generateTDDMessage(historyList, dummies));
|
sendStatusmessage("TDD", generateTDDMessage(historyList, dummies));
|
||||||
|
@ -319,8 +319,7 @@ public class ActionStringHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else return;
|
||||||
else return;
|
|
||||||
|
|
||||||
|
|
||||||
// send result
|
// send result
|
||||||
|
@ -333,14 +332,14 @@ public class ActionStringHandler {
|
||||||
|
|
||||||
ProfileInterface activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
|
ProfileInterface activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
|
||||||
|
|
||||||
if(activeProfile == null){
|
if (activeProfile == null) {
|
||||||
return "No profile loaded :(";
|
return "No profile loaded :(";
|
||||||
}
|
}
|
||||||
|
|
||||||
DateFormat df = new SimpleDateFormat("dd.MM.");
|
DateFormat df = new SimpleDateFormat("dd.MM.");
|
||||||
String message = "";
|
String message = "";
|
||||||
|
|
||||||
double refTDD = activeProfile.getProfile().getDefaultProfile().baseBasalSum()*2;
|
double refTDD = activeProfile.getProfile().getDefaultProfile().baseBasalSum() * 2;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
double sum = 0d;
|
double sum = 0d;
|
||||||
|
@ -364,15 +363,15 @@ public class ActionStringHandler {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
message += "weighted:\n";
|
message += "weighted:\n";
|
||||||
message += "0.3: " + DecimalFormatter.to2Decimal(weighted03) + "U " + (DecimalFormatter.to0Decimal(100*weighted03/refTDD) + "%") + "\n";
|
message += "0.3: " + DecimalFormatter.to2Decimal(weighted03) + "U " + (DecimalFormatter.to0Decimal(100 * weighted03 / refTDD) + "%") + "\n";
|
||||||
message += "0.5: " + DecimalFormatter.to2Decimal(weighted05) + "U " + (DecimalFormatter.to0Decimal(100*weighted05/refTDD) + "%") + "\n";
|
message += "0.5: " + DecimalFormatter.to2Decimal(weighted05) + "U " + (DecimalFormatter.to0Decimal(100 * weighted05 / refTDD) + "%") + "\n";
|
||||||
message += "0.7: " + DecimalFormatter.to2Decimal(weighted07) + "U " + (DecimalFormatter.to0Decimal(100*weighted07/refTDD) + "%") + "\n";
|
message += "0.7: " + DecimalFormatter.to2Decimal(weighted07) + "U " + (DecimalFormatter.to0Decimal(100 * weighted07 / refTDD) + "%") + "\n";
|
||||||
message += "\n";
|
message += "\n";
|
||||||
|
|
||||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||||
if (pump != null && pump instanceof DanaRPlugin) {
|
if (pump != null && pump instanceof DanaRPlugin) {
|
||||||
double tdd = DanaRPump.getInstance().dailyTotalUnits;
|
double tdd = DanaRPump.getInstance().dailyTotalUnits;
|
||||||
message += "Today: " + DecimalFormatter.to2Decimal(tdd) + "U " + (DecimalFormatter.to0Decimal(100*tdd/refTDD) + "%") + "\n";
|
message += "Today: " + DecimalFormatter.to2Decimal(tdd) + "U " + (DecimalFormatter.to0Decimal(100 * tdd / refTDD) + "%") + "\n";
|
||||||
message += "\n";
|
message += "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +379,7 @@ public class ActionStringHandler {
|
||||||
Collections.reverse(historyList);
|
Collections.reverse(historyList);
|
||||||
for (DanaRHistoryRecord record : historyList) {
|
for (DanaRHistoryRecord record : historyList) {
|
||||||
double tdd = record.recordDailyBolus + record.recordDailyBasal;
|
double tdd = record.recordDailyBolus + record.recordDailyBasal;
|
||||||
message += df.format(new Date(record.recordDate)) + " " + DecimalFormatter.to2Decimal(tdd) +"U " + (DecimalFormatter.to0Decimal(100*tdd/refTDD) + "%") + (dummies.contains(record)?"x":"") +"\n";
|
message += df.format(new Date(record.recordDate)) + " " + DecimalFormatter.to2Decimal(tdd) + "U " + (DecimalFormatter.to0Decimal(100 * tdd / refTDD) + "%") + (dummies.contains(record) ? "x" : "") + "\n";
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
@ -398,17 +397,17 @@ public class ActionStringHandler {
|
||||||
historyList = historyList.subList(0, Math.min(10, historyList.size()));
|
historyList = historyList.subList(0, Math.min(10, historyList.size()));
|
||||||
|
|
||||||
//fill single gaps
|
//fill single gaps
|
||||||
List<DanaRHistoryRecord> dummies = (returnDummies!=null)?returnDummies:(new LinkedList());
|
List<DanaRHistoryRecord> dummies = (returnDummies != null) ? returnDummies : (new LinkedList());
|
||||||
DateFormat df = new SimpleDateFormat("dd.MM.");
|
DateFormat df = new SimpleDateFormat("dd.MM.");
|
||||||
for(int i = 0; i < historyList.size()-1; i++){
|
for (int i = 0; i < historyList.size() - 1; i++) {
|
||||||
DanaRHistoryRecord elem1 = historyList.get(i);
|
DanaRHistoryRecord elem1 = historyList.get(i);
|
||||||
DanaRHistoryRecord elem2 = historyList.get(i+1);
|
DanaRHistoryRecord elem2 = historyList.get(i + 1);
|
||||||
|
|
||||||
if (!df.format(new Date(elem1.recordDate)).equals(df.format(new Date(elem2.recordDate + 25*60*60*1000)))){
|
if (!df.format(new Date(elem1.recordDate)).equals(df.format(new Date(elem2.recordDate + 25 * 60 * 60 * 1000)))) {
|
||||||
DanaRHistoryRecord dummy = new DanaRHistoryRecord();
|
DanaRHistoryRecord dummy = new DanaRHistoryRecord();
|
||||||
dummy.recordDate = elem1.recordDate - 24*60*60*1000;
|
dummy.recordDate = elem1.recordDate - 24 * 60 * 60 * 1000;
|
||||||
dummy.recordDailyBasal = elem1.recordDailyBasal/2;
|
dummy.recordDailyBasal = elem1.recordDailyBasal / 2;
|
||||||
dummy.recordDailyBolus = elem1.recordDailyBolus/2;
|
dummy.recordDailyBolus = elem1.recordDailyBolus / 2;
|
||||||
dummies.add(dummy);
|
dummies.add(dummy);
|
||||||
elem1.recordDailyBasal /= 2;
|
elem1.recordDailyBasal /= 2;
|
||||||
elem1.recordDailyBolus /= 2;
|
elem1.recordDailyBolus /= 2;
|
||||||
|
@ -418,7 +417,7 @@ public class ActionStringHandler {
|
||||||
Collections.sort(historyList, new Comparator<DanaRHistoryRecord>() {
|
Collections.sort(historyList, new Comparator<DanaRHistoryRecord>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(DanaRHistoryRecord lhs, DanaRHistoryRecord rhs) {
|
public int compare(DanaRHistoryRecord lhs, DanaRHistoryRecord rhs) {
|
||||||
return (int) (rhs.recordDate-lhs.recordDate);
|
return (int) (rhs.recordDate - lhs.recordDate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return historyList;
|
return historyList;
|
||||||
|
@ -426,7 +425,7 @@ public class ActionStringHandler {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static String getPumpStatus() {
|
private static String getPumpStatus() {
|
||||||
return MainApp.getConfigBuilder().shortStatus(false);
|
return ConfigBuilderPlugin.getActivePump().shortStatus(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -505,12 +504,12 @@ public class ActionStringHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.changeRequested) {
|
if (!result.changeRequested) {
|
||||||
ret += MainApp.sResources.getString(R.string.nochangerequested) + "\n";
|
ret += MainApp.sResources.getString(R.string.nochangerequested) + "\n";
|
||||||
} else if (result.rate == 0 && result.duration == 0) {
|
} else if (result.rate == 0 && result.duration == 0) {
|
||||||
ret += MainApp.sResources.getString(R.string.canceltemp)+ "\n";
|
ret += MainApp.sResources.getString(R.string.canceltemp) + "\n";
|
||||||
} else {
|
} else {
|
||||||
ret += MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(result.rate) + " U/h " +
|
ret += MainApp.sResources.getString(R.string.rate) + ": " + DecimalFormatter.to2Decimal(result.rate) + " U/h " +
|
||||||
"(" + DecimalFormatter.to2Decimal(result.rate / MainApp.getConfigBuilder().getBaseBasalRate() * 100) + "%)\n" +
|
"(" + DecimalFormatter.to2Decimal(result.rate / ConfigBuilderPlugin.getActivePump().getBaseBasalRate() * 100) + "%)\n" +
|
||||||
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(result.duration) + " min\n";
|
MainApp.sResources.getString(R.string.duration) + ": " + DecimalFormatter.to0Decimal(result.duration) + " min\n";
|
||||||
}
|
}
|
||||||
ret += "\n" + MainApp.sResources.getString(R.string.reason) + ": " + result.reason;
|
ret += "\n" + MainApp.sResources.getString(R.string.reason) + ": " + result.reason;
|
||||||
|
@ -565,7 +564,7 @@ public class ActionStringHandler {
|
||||||
int timeshift = SafeParse.stringToInt(act[1]);
|
int timeshift = SafeParse.stringToInt(act[1]);
|
||||||
int percentage = SafeParse.stringToInt(act[2]);
|
int percentage = SafeParse.stringToInt(act[2]);
|
||||||
setCPP(timeshift, percentage);
|
setCPP(timeshift, percentage);
|
||||||
} else if ("dismissoverviewnotification".equals(act[0])){
|
} else if ("dismissoverviewnotification".equals(act[0])) {
|
||||||
MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1])));
|
MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1])));
|
||||||
}
|
}
|
||||||
lastBolusWizard = null;
|
lastBolusWizard = null;
|
||||||
|
@ -578,21 +577,20 @@ public class ActionStringHandler {
|
||||||
|
|
||||||
//check for validity
|
//check for validity
|
||||||
if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) {
|
if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) {
|
||||||
msg+= String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n";
|
msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n";
|
||||||
}
|
}
|
||||||
if (timeshift < 0 || timeshift > 23) {
|
if (timeshift < 0 || timeshift > 23) {
|
||||||
msg+= String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n";
|
msg += String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Timeshift") + "\n";
|
||||||
}
|
}
|
||||||
if(!SP.getBoolean("syncprofiletopump", false)){
|
if (!SP.getBoolean("syncprofiletopump", false)) {
|
||||||
msg+= MainApp.sResources.getString(R.string.syncprofiletopump_title) + " " + MainApp.sResources.getString(R.string.cpp_sync_setting_missing) + "\n";
|
msg += MainApp.sResources.getString(R.string.syncprofiletopump_title) + " " + MainApp.sResources.getString(R.string.cpp_sync_setting_missing) + "\n";
|
||||||
}
|
}
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
|
||||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
|
||||||
if (pump == null || profile == null || profile.getBasal() == null){
|
if (profile == null || profile.getBasal() == null) {
|
||||||
msg+= MainApp.sResources.getString(R.string.cpp_notloadedplugins) + "\n";
|
msg += MainApp.sResources.getString(R.string.cpp_notloadedplugins) + "\n";
|
||||||
}
|
}
|
||||||
if(!"".equals(msg)) {
|
if (!"".equals(msg)) {
|
||||||
msg += MainApp.sResources.getString(R.string.cpp_valuesnotstored);
|
msg += MainApp.sResources.getString(R.string.cpp_valuesnotstored);
|
||||||
String rTitle = "STATUS";
|
String rTitle = "STATUS";
|
||||||
String rAction = "statusmessage";
|
String rAction = "statusmessage";
|
||||||
|
@ -627,16 +625,13 @@ public class ActionStringHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doFillBolus(final Double amount) {
|
private static void doFillBolus(final Double amount) {
|
||||||
//if(1==1)return;
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
Handler handler = new Handler(handlerThread.getLooper());
|
detailedBolusInfo.insulin = amount;
|
||||||
handler.post(new Runnable() {
|
detailedBolusInfo.isValid = false;
|
||||||
|
detailedBolusInfo.source = Source.USER;
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
|
||||||
detailedBolusInfo.insulin = amount;
|
|
||||||
detailedBolusInfo.isValid = false;
|
|
||||||
detailedBolusInfo.source = Source.USER;
|
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(detailedBolusInfo);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||||
"\n" +
|
"\n" +
|
||||||
|
@ -647,16 +642,13 @@ public class ActionStringHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doBolus(final Double amount, final Integer carbs) {
|
private static void doBolus(final Double amount, final Integer carbs) {
|
||||||
//if(1==1)return;
|
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||||
Handler handler = new Handler(handlerThread.getLooper());
|
detailedBolusInfo.insulin = amount;
|
||||||
handler.post(new Runnable() {
|
detailedBolusInfo.carbs = carbs;
|
||||||
|
detailedBolusInfo.source = Source.USER;
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
|
||||||
detailedBolusInfo.insulin = amount;
|
|
||||||
detailedBolusInfo.carbs = carbs;
|
|
||||||
detailedBolusInfo.source = Source.USER;
|
|
||||||
PumpEnactResult result = MainApp.getConfigBuilder().deliverTreatment(detailedBolusInfo);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
sendError(MainApp.sResources.getString(R.string.treatmentdeliveryerror) +
|
||||||
"\n" +
|
"\n" +
|
||||||
|
|
|
@ -35,8 +35,8 @@ import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
|
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
|
||||||
|
@ -189,8 +189,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancelBolus() {
|
private void cancelBolus() {
|
||||||
PumpInterface pump = MainApp.getConfigBuilder();
|
ConfigBuilderPlugin.getActivePump().stopBolusDelivering();
|
||||||
pump.stopBolusDelivering();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendData() {
|
private void sendData() {
|
||||||
|
@ -533,7 +532,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
private void sendPreferences() {
|
private void sendPreferences() {
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
|
|
||||||
boolean wearcontrol = SP.getBoolean("wearcontrol",false);
|
boolean wearcontrol = SP.getBoolean("wearcontrol", false);
|
||||||
|
|
||||||
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_PREFERENCES_PATH);
|
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_PREFERENCES_PATH);
|
||||||
//unique content
|
//unique content
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean showInList(int type) {
|
public boolean showInList(int type) {
|
||||||
return !Config.NSCLIENT;
|
return !Config.NSCLIENT && !Config.G5UPLOADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package info.nightscout.androidaps.queue;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 09.11.2017.
|
||||||
|
*/
|
||||||
|
public abstract class Callback implements Runnable {
|
||||||
|
public PumpEnactResult result;
|
||||||
|
|
||||||
|
public Callback result(PumpEnactResult result) {
|
||||||
|
this.result = result;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,409 @@
|
||||||
|
package info.nightscout.androidaps.queue;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.Spanned;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.events.EventBolusRequested;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperActivity;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
import info.nightscout.androidaps.queue.commands.Command;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandBolus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandCancelTempBasal;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandExtendedBolus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandLoadEvents;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandLoadHistory;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandReadStatus;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandSetProfile;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CommandTempBasalPercent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 08.11.2017.
|
||||||
|
*
|
||||||
|
* DATA FLOW:
|
||||||
|
* ---------
|
||||||
|
*
|
||||||
|
* (request) - > ConfigBuilder.getCommandQueue().bolus(...)
|
||||||
|
*
|
||||||
|
* app no longer waits for result but passes Callback
|
||||||
|
*
|
||||||
|
* request is added to queue, if another request of the same type already exists in queue, it's removed prior adding
|
||||||
|
* but if request of the same type is currently executed (probably important only for bolus which is running long time), new request is declined
|
||||||
|
* new QueueThread is created and started if current if finished
|
||||||
|
* CommandReadStatus is added automatically before command if queue is empty
|
||||||
|
*
|
||||||
|
* biggest change is we don't need exec pump commands in Handler because it's finished immediately
|
||||||
|
* command queueing if not realized by stacking in different Handlers and threads anymore but by internal queue with better control
|
||||||
|
*
|
||||||
|
* QueueThread calls ConfigBuilder#connect which is passed to getActivePump().connect
|
||||||
|
* connect should be executed on background and return immediately. afterwards isConnecting() is expected to be true
|
||||||
|
*
|
||||||
|
* while isConnecting() == true GUI is updated by posting connection progress
|
||||||
|
*
|
||||||
|
* if connect is successful: isConnected() becomes true, isConnecting() becomes false
|
||||||
|
* CommandQueue starts calling execute() of commands. execute() is expected to be blocking (return after finish).
|
||||||
|
* callback with result is called after finish automatically
|
||||||
|
* if connect failed: isConnected() becomes false, isConnecting() becomes false
|
||||||
|
* connect() is called again
|
||||||
|
*
|
||||||
|
* when queue is empty, disconnect is called
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class CommandQueue {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(CommandQueue.class);
|
||||||
|
|
||||||
|
private LinkedList<Command> queue = new LinkedList<>();
|
||||||
|
private Command performing;
|
||||||
|
|
||||||
|
private QueueThread thread = null;
|
||||||
|
|
||||||
|
private PumpEnactResult executingNowError() {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
result.success = false;
|
||||||
|
result.enacted = false;
|
||||||
|
result.comment = MainApp.sResources.getString(R.string.executingrightnow);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning(Command.CommandType type) {
|
||||||
|
if (performing != null && performing.commandType == type)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void removeAll(Command.CommandType type) {
|
||||||
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
|
if (queue.get(i).commandType == type) {
|
||||||
|
queue.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void add(Command command) {
|
||||||
|
// inject reading of status when adding first command to the queue
|
||||||
|
if (queue.size() == 0 && command.commandType != Command.CommandType.READSTATUS)
|
||||||
|
queue.add(new CommandReadStatus("Queue", null));
|
||||||
|
queue.add(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void pickup() {
|
||||||
|
performing = queue.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void clear() {
|
||||||
|
performing = null;
|
||||||
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
|
queue.get(i).cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return queue.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command performing() {
|
||||||
|
return performing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetPerforming() {
|
||||||
|
performing = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// After new command added to the queue
|
||||||
|
// start thread again if not already running
|
||||||
|
private void notifyAboutNewCommand() {
|
||||||
|
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||||
|
thread = new QueueThread(this);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.BOLUS)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished boluses
|
||||||
|
removeAll(Command.CommandType.BOLUS);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandBolus(detailedBolusInfo, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
// Notify Wear about upcoming bolus
|
||||||
|
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.setInsulin(detailedBolusInfo.insulin);
|
||||||
|
bolusProgressDialog.show(((AppCompatActivity) detailedBolusInfo.context).getSupportFragmentManager(), "BolusProgress");
|
||||||
|
} else {
|
||||||
|
Intent i = new Intent();
|
||||||
|
i.putExtra("insulin", detailedBolusInfo.insulin);
|
||||||
|
i.setClass(MainApp.instance(), BolusProgressHelperActivity.class);
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
MainApp.instance().startActivity(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean tempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
|
Double rateAfterConstraints = MainApp.getConfigBuilder().applyBasalConstraints(absoluteRate);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandTempBasalAbsolute(rateAfterConstraints, durationInMinutes, enforceNew, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean tempBasalPercent(int percent, int durationInMinutes, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
|
Integer percentAfterConstraints = MainApp.getConfigBuilder().applyBasalConstraints(percent);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean extendedBolus(double insulin, int durationInMinutes, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.EXTENDEDBOLUS)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Double rateAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin);
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandExtendedBolus(rateAfterConstraints, durationInMinutes, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean cancelTempBasal(boolean enforceNew, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.TEMPBASAL)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandCancelTempBasal(enforceNew, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean cancelExtended(Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.EXTENDEDBOLUS)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandCancelExtendedBolus(callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean setProfile(Profile profile, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.BASALPROFILE)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare with pump limits
|
||||||
|
Profile.BasalValue[] basalValues = profile.getBasalValues();
|
||||||
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
|
for (int index = 0; index < basalValues.length; index++) {
|
||||||
|
if (basalValues[index].value < pump.getPumpDescription().basalMinimumRate) {
|
||||||
|
Notification notification = new Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, MainApp.sResources.getString(R.string.basalvaluebelowminimum), Notification.URGENT);
|
||||||
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(new PumpEnactResult().success(false).comment(MainApp.sResources.getString(R.string.basalvaluebelowminimum))).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MainApp.bus().post(new EventDismissNotification(Notification.BASAL_VALUE_BELOW_MINIMUM));
|
||||||
|
|
||||||
|
if (isThisProfileSet(profile)) {
|
||||||
|
log.debug("Correct profile already set");
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(new PumpEnactResult().success(true).enacted(false)).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.BASALPROFILE);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandSetProfile(profile, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean readStatus(String reason, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.READSTATUS)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.READSTATUS);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandReadStatus(reason, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean loadHistory(byte type, Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.LOADHISTORY)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.LOADHISTORY);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandLoadHistory(type, callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true if command is queued
|
||||||
|
public boolean loadEvents(Callback callback) {
|
||||||
|
if (isRunning(Command.CommandType.LOADEVENTS)) {
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(executingNowError()).run();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unfinished
|
||||||
|
removeAll(Command.CommandType.LOADEVENTS);
|
||||||
|
|
||||||
|
// add new command to queue
|
||||||
|
add(new CommandLoadEvents(callback));
|
||||||
|
|
||||||
|
notifyAboutNewCommand();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Spanned spannedStatus() {
|
||||||
|
String s = "";
|
||||||
|
int line = 0;
|
||||||
|
if (performing != null) {
|
||||||
|
s += "<b>" + performing.status() + "</b>";
|
||||||
|
line++;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < queue.size(); i++) {
|
||||||
|
if (line != 0)
|
||||||
|
s += "<br>";
|
||||||
|
s += queue.get(i).status();
|
||||||
|
line++;
|
||||||
|
}
|
||||||
|
return Html.fromHtml(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
|
PumpInterface activePump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
if (activePump != null) {
|
||||||
|
boolean result = activePump.isThisProfileSet(profile);
|
||||||
|
if (!result) {
|
||||||
|
log.debug("Current profile: " + MainApp.getConfigBuilder().getProfile().getData().toString());
|
||||||
|
log.debug("New profile: " + profile.getData().toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package info.nightscout.androidaps.queue;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
||||||
|
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 09.11.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class QueueThread extends Thread {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(QueueThread.class);
|
||||||
|
|
||||||
|
CommandQueue queue;
|
||||||
|
|
||||||
|
private long connectionStartTime = 0;
|
||||||
|
|
||||||
|
private PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
|
public QueueThread(CommandQueue queue) {
|
||||||
|
super(QueueThread.class.toString());
|
||||||
|
|
||||||
|
this.queue = queue;
|
||||||
|
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||||
|
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "QueueThread");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void run() {
|
||||||
|
mWakeLock.acquire();
|
||||||
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
|
connectionStartTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||||
|
log.debug("Looping ...");
|
||||||
|
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
|
||||||
|
if (pump.isConnecting()) {
|
||||||
|
log.debug("State: connecting");
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
||||||
|
SystemClock.sleep(1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
|
||||||
|
log.debug("State: timed out");
|
||||||
|
MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult()));
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout)));
|
||||||
|
pump.stopConnecting();
|
||||||
|
queue.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pump.isConnected()) {
|
||||||
|
log.debug("State: connect");
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
|
||||||
|
pump.connect("Connection needed");
|
||||||
|
SystemClock.sleep(1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queue.performing() == null) {
|
||||||
|
// Pickup 1st command and set performing variable
|
||||||
|
if (queue.size() > 0) {
|
||||||
|
log.debug("State: performing");
|
||||||
|
queue.pickup();
|
||||||
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
|
queue.performing().execute();
|
||||||
|
queue.resetPerforming();
|
||||||
|
MainApp.bus().post(new EventQueueChanged());
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queue.size() == 0 && queue.performing() == null) {
|
||||||
|
log.debug("State: queue empty. disconnect");
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||||
|
pump.disconnect("Queue empty");
|
||||||
|
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
mWakeLock.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package info.nightscout.androidaps.queue.commands;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 09.11.2017.
|
||||||
|
*/
|
||||||
|
public abstract class Command {
|
||||||
|
public enum CommandType {
|
||||||
|
BOLUS,
|
||||||
|
TEMPBASAL,
|
||||||
|
EXTENDEDBOLUS,
|
||||||
|
BASALPROFILE,
|
||||||
|
READSTATUS,
|
||||||
|
LOADHISTORY, // so far only Dana specific
|
||||||
|
LOADEVENTS // so far only Dana specific
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandType commandType;
|
||||||
|
protected Callback callback;
|
||||||
|
|
||||||
|
public abstract void execute();
|
||||||
|
|
||||||
|
public abstract String status();
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
result.success = false;
|
||||||
|
result.comment = MainApp.sResources.getString(R.string.connectiontimedout);
|
||||||
|
if (callback != null)
|
||||||
|
callback.result(result).run();
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue