Dana R & v2 speed selection

This commit is contained in:
Milos Kozak 2017-10-10 19:14:43 +02:00
parent d142d2e4f9
commit 24099222f3
11 changed files with 129 additions and 10 deletions

View file

@ -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);
}

View file

@ -18,6 +18,7 @@ public class MessageHashTable {
messages = new HashMap<Integer, MessageBase>();
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

View file

@ -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);
}
}
}

View file

@ -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");

View file

@ -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;

View file

@ -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;

View file

@ -22,6 +22,7 @@ public class MessageHashTable_v2 {
messages = new HashMap<Integer, MessageBase>();
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

View file

@ -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");

View file

@ -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" />
<EditTextPreference
android:title="@string/danar_password_title"
android:key="@string/key_danar_password"
android:inputType="numberPassword">
</EditTextPreference>
<ListPreference
android:title="@string/bolusspeed"
android:key="@string/key_danars_bolusspeed"
android:defaultValue="0"
android:entries="@array/danaSpeedArray"
android:entryValues="@array/danaSpeedValues"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_danar_useextended"
android:title="@string/danar_useextended_title" />
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/key_danar_useextended"
android:key="@string/key_danar_visualizeextendedaspercentage"
android:title="@string/danar_visualizeextendedaspercentage_title" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="danar"
android:title="@string/danar_pump_settings">
<info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference
android:dialogTitle="@string/danar_bt_name_title"
android:key="@string/key_danar_bt_name"
android:title="@string/danar_bt_name_title" />
<EditTextPreference
android:title="@string/danar_password_title"
android:key="@string/key_danar_password"
android:inputType="numberPassword">
</EditTextPreference>
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_danar_useextended"
android:title="@string/danar_useextended_title" />
<SwitchPreference
android:defaultValue="false"
android:dependency="@string/key_danar_useextended"
android:key="@string/key_danar_visualizeextendedaspercentage"
android:title="@string/danar_visualizeextendedaspercentage_title" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -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" />
<EditTextPreference
android:title="@string/danar_password_title"
android:inputType="numberPassword"
android:key="@string/key_danar_password"
android:inputType="numberPassword">
</EditTextPreference>
android:title="@string/danar_password_title"></EditTextPreference>
<ListPreference
android:defaultValue="0"
android:entries="@array/danaSpeedArray"
android:entryValues="@array/danaSpeedValues"
android:key="@string/key_danars_bolusspeed"
android:title="@string/bolusspeed" />
</PreferenceCategory>
</PreferenceScreen>