cpp-watch first roundtrip

This commit is contained in:
AdrianLxM 2017-07-09 21:49:19 +02:00
parent 85d028abff
commit 26f3362ffc
2 changed files with 48 additions and 11 deletions

View file

@ -165,20 +165,24 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
String msg = "";
if (!fragmentEnabled){
msg+= "NO CPP!" + "\n";
}
//check for validity
if (percentage < Constants.CPP_MIN_PERCENTAGE || percentage > Constants.CPP_MAX_PERCENTAGE) {
msg+= String.format(MainApp.sResources.getString(R.string.openapsma_valueoutofrange), "Profile-Percentage") + "\n";
}
if (timeshift < 0 || percentage > 23) {
if (timeshift < 0 || timeshift > 23) {
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";
}
final PumpInterface pump = MainApp.getConfigBuilder();
final Profile profile = MainApp.getConfigBuilder().getProfile();
if (pump != null && profile != null && profile.getBasal() != null){
if (pump == null || profile == null || profile.getBasal() == null){
msg+= MainApp.sResources.getString(R.string.cpp_notloadedplugins) + "\n";
}
if(!"".equals(msg)) {
@ -201,14 +205,17 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte
}
});
t.start();
msg += "syctopump";
} else {
msg += "SP.getBoolean(\"syncprofiletopump\", false): " + SP.getBoolean("syncprofiletopump", false) + " \n";
msg += "pump.isThisProfileSet(profile): " + pump.isThisProfileSet(profile);
}
//return formatted string
msg += "%: " + this.percentage + " h: +" + this.timeshift;
/*msg += "%: " + this.percentage + " h: +" + this.timeshift;
msg += "\n";
msg += "\nBasal:\n" + basalString() + "\n";
msg += "\nISF:\n" + isfString() + "\n";
msg += "\nIC:\n" + isfString() + "\n";
msg += "\nIC:\n" + isfString() + "\n";*/
return msg;
}

View file

@ -227,14 +227,12 @@ public class ActionStringHandler {
lastBolusWizard = bolusWizard;
} else if("opencpp".equals(act[0])){
//TODO ADRIAN open cpp
Object activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class);
if(cpp == null || activeProfile==null || cpp != activeProfile){
rTitle = "STATUS";
rAction = "statusmessage";
rMessage = "CPP not activated";
sendError("CPP not activated!");
return;
} else {
// read CPP values
rTitle = "opencpp";
@ -242,7 +240,23 @@ public class ActionStringHandler {
rAction = "opencpp" + " " + cpp.getPercentage() + " " + cpp.getTimeshift();
}
}else return;
} else if("cppset".equals(act[0])){
Object activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class);
if(cpp == null || activeProfile==null || cpp != activeProfile){
sendError("CPP not activated!");
return;
} else {
// read CPP values
rMessage = "CPP:" + "\n\n"+
"Percentage: " + act[1] + "%\n" +
"Timeshift: " + act[2];
rAction = actionstring;
}
}
else return;
// send result
@ -397,10 +411,26 @@ public class ActionStringHandler {
double insulin = SafeParse.stringToDouble(act[1]);
int carbs = SafeParse.stringToInt(act[2]);
doBolus(insulin, carbs);
} else if ("cppset".equals(act[0])) {
int timeshift = SafeParse.stringToInt(act[1]);
int percentage = SafeParse.stringToInt(act[2]);
setCPP(percentage, timeshift);
}
lastBolusWizard = null;
}
private static void setCPP(int percentage, int timeshift) {
Object activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface();
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getSpecificPlugin(CircadianPercentageProfilePlugin.class);
if(cpp == null || activeProfile==null || cpp != activeProfile){
sendError("CPP not activated!");
return;
}
String msg = cpp.externallySetParameters(timeshift, percentage);
ToastUtils.showToastInUiThread(MainApp.instance(), msg);
}
private static void generateTempTarget(int duration, double low, double high) {
TempTarget tempTarget = new TempTarget();
tempTarget.date = System.currentTimeMillis();