From 24099222f3178c8c93851c6bf81f1a971b093acb Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 10 Oct 2017 19:14:43 +0200 Subject: [PATCH] Dana R & v2 speed selection --- .../androidaps/PreferencesActivity.java | 5 ++- .../PumpDanaR/comm/MessageHashTable.java | 1 + .../comm/MsgBolusStartWithSpeed.java | 43 +++++++++++++++++++ .../services/DanaRExecutionService.java | 8 +++- .../PumpDanaRKorean/DanaRKoreanPlugin.java | 2 +- .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 18 +++++++- .../PumpDanaRv2/comm/MessageHashTable_v2.java | 1 + .../services/DanaRv2ExecutionService.java | 9 +++- app/src/main/res/xml/pref_danar.xml | 11 +++++ app/src/main/res/xml/pref_danarkorean.xml | 27 ++++++++++++ app/src/main/res/xml/pref_danarv2.xml | 14 ++++-- 11 files changed, 129 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java create mode 100644 app/src/main/res/xml/pref_danarkorean.xml diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index 24486aeb72..123b0d112a 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -134,9 +134,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre DanaRKoreanPlugin danaRKoreanPlugin = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); DanaRv2Plugin danaRv2Plugin = MainApp.getSpecificPlugin(DanaRv2Plugin.class); DanaRSPlugin danaRSPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class); - if (danaRPlugin.isEnabled(PluginBase.PUMP) || danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) { + if (danaRPlugin.isEnabled(PluginBase.PUMP)) { addPreferencesFromResource(R.xml.pref_danar); } + if (danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) { + addPreferencesFromResource(R.xml.pref_danarkorean); + } if (danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PUMP)) { addPreferencesFromResource(R.xml.pref_danarv2); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java index debdd8a35f..10d2c0b091 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java @@ -18,6 +18,7 @@ public class MessageHashTable { messages = new HashMap(); put(new MsgBolusStop()); // 0x0101 CMD_MEALINS_STOP put(new MsgBolusStart()); // 0x0102 CMD_MEALINS_START_DATA + put(new MsgBolusStartWithSpeed()); // 0x0104 CMD_MEALINS_START_DATA_SPEED put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING put(new MsgStatusTempBasal()); // 0x0205 CMD_PUMP_EXERCISE_MODE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java new file mode 100644 index 0000000000..b04d501ef0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeed.java @@ -0,0 +1,43 @@ +package info.nightscout.androidaps.plugins.PumpDanaR.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; +import info.nightscout.utils.HardLimits; + +public class MsgBolusStartWithSpeed extends MessageBase { + private static Logger log = LoggerFactory.getLogger(MsgBolusStartWithSpeed.class); + + public MsgBolusStartWithSpeed() { + SetCommand(0x0104); + } + + public MsgBolusStartWithSpeed(double amount, int speed) { + this(); + + // HARDCODED LIMIT + amount = MainApp.getConfigBuilder().applyBolusConstraints(amount); + if (amount < 0) amount = 0d; + if (amount > HardLimits.maxBolus()) amount = HardLimits.maxBolus(); + + AddParamInt((int) (amount * 100)); + AddParamByte((byte) speed); + + if (Config.logDanaMessageDetail) + log.debug("Bolus start : " + amount + " speed: " + speed); + } + + @Override + public void handleMessage(byte[] bytes) { + int result = intFromBuff(bytes, 0, 1); + if (result != 2) { + failed = true; + log.debug("Messsage response: " + result + " FAILED!!"); + } else { + if (Config.logDanaMessageDetail) + log.debug("Messsage response: " + result); + } + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index c161a3954f..9d94634094 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -40,6 +40,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.SerialIOThread; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusProgress; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStart; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStartWithSpeed; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgBolusStop; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgCheckValue; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgHistoryAlarm; @@ -409,7 +410,12 @@ public class DanaRExecutionService extends Service { public boolean bolus(double amount, int carbs, Treatment t) { bolusingTreatment = t; - MsgBolusStart start = new MsgBolusStart(amount); + int speed = SP.getInt(R.string.key_danars_bolusspeed, 0); + MessageBase start; + if (speed == 0) + start = new MsgBolusStart(amount); + else + start = new MsgBolusStartWithSpeed(amount, speed); MsgBolusStop stop = new MsgBolusStop(amount, t); connect("bolus"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 3314b8adf9..f21174aabd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -68,7 +68,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf private static DanaRKoreanExecutionService sExecutionService; - private DanaRPump pump = DanaRPump.getInstance(); + private static DanaRPump pump = DanaRPump.getInstance(); private boolean useExtendedBoluses = false; private static DanaRKoreanPlugin plugin = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 9bb63112ae..d9322ea560 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionS import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.Round; +import info.nightscout.utils.SP; /** * Created by mike on 05.08.2016. @@ -294,8 +295,21 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) { DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history // v2 stores end time for bolus, we need to adjust time - // delivery speed is 12 U/min - detailedBolusInfo.date += detailedBolusInfo.insulin / 12d * 60 * 1000; + // default delivery speed is 12 U/min + int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0); + int speed = 12; + switch (preferencesSpeed) { + case 0: + speed = 12; + break; + case 1: + speed = 30; + break; + case 2: + speed = 60; + break; + } + detailedBolusInfo.date += detailedBolusInfo.insulin / speed * 60d * 1000; // clean carbs to prevent counting them as twice because they will picked up as another record // I don't think it's necessary to copy DetailedBolusInfo right now for carbs records double carbs = detailedBolusInfo.carbs; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java index 0940efd73f..cafba32239 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java @@ -22,6 +22,7 @@ public class MessageHashTable_v2 { messages = new HashMap(); put(new MsgBolusStop()); // 0x0101 CMD_MEALINS_STOP put(new MsgBolusStart()); // 0x0102 CMD_MEALINS_START_DATA + put(new MsgBolusStartWithSpeed()); // 0x0104 CMD_MEALINS_START_DATA_SPEED put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index f388f83e0d..fc3df19296 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -323,7 +323,7 @@ public class DanaRv2ExecutionService extends Service { MainApp.bus().post(new EventDanaRNewStatus()); MainApp.bus().post(new EventInitializationChanged()); 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); Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.sResources.getString(R.string.approachingdailylimit), Notification.URGENT); MainApp.bus().post(new EventNewNotification(reportFail)); @@ -402,7 +402,12 @@ public class DanaRv2ExecutionService extends Service { public boolean bolus(double amount, int carbs, long carbtime, Treatment t) { bolusingTreatment = t; - MsgBolusStart start = new MsgBolusStart(amount); + int speed = SP.getInt(R.string.key_danars_bolusspeed, 0); + MessageBase start; + if (speed == 0) + start = new MsgBolusStart(amount); + else + start = new MsgBolusStartWithSpeed(amount, speed); MsgBolusStop stop = new MsgBolusStop(amount, t); connect("bolus"); diff --git a/app/src/main/res/xml/pref_danar.xml b/app/src/main/res/xml/pref_danar.xml index e57a211a16..51c5003ec9 100644 --- a/app/src/main/res/xml/pref_danar.xml +++ b/app/src/main/res/xml/pref_danar.xml @@ -8,20 +8,31 @@ android:dialogTitle="@string/danar_bt_name_title" android:key="@string/key_danar_bt_name" android:title="@string/danar_bt_name_title" /> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_danarkorean.xml b/app/src/main/res/xml/pref_danarkorean.xml new file mode 100644 index 0000000000..e57a211a16 --- /dev/null +++ b/app/src/main/res/xml/pref_danarkorean.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_danarv2.xml b/app/src/main/res/xml/pref_danarv2.xml index 1029c43fb4..45906e8615 100644 --- a/app/src/main/res/xml/pref_danarv2.xml +++ b/app/src/main/res/xml/pref_danarv2.xml @@ -8,11 +8,19 @@ android:dialogTitle="@string/danar_bt_name_title" android:key="@string/key_danar_bt_name" android:title="@string/danar_bt_name_title" /> + - + android:title="@string/danar_password_title"> + + + \ No newline at end of file