move database actions from pump to treatments plugin
This commit is contained in:
parent
b1d9e647c6
commit
25110cfea4
|
@ -421,6 +421,28 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return new ArrayList<Treatment>();
|
||||
}
|
||||
|
||||
public int update(TempBasal tempBasal) {
|
||||
int updated = 0;
|
||||
try {
|
||||
updated = getDaoTempBasals().update(tempBasal);
|
||||
latestTreatmentChange = tempBasal.getTimeIndex();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
scheduleTreatmentChange();
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void create(TempBasal tempBasal) {
|
||||
try {
|
||||
getDaoTempBasals().create(tempBasal);
|
||||
latestTreatmentChange = tempBasal.getTimeIndex();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
scheduleTreatmentChange();
|
||||
}
|
||||
|
||||
public void delete(TempBasal tempBasal) {
|
||||
try {
|
||||
getDaoTempBasals().delete(tempBasal);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 15.05.2017.
|
||||
*/
|
||||
|
||||
public class EventExtendedBolusChange {
|
||||
}
|
|
@ -30,9 +30,13 @@ public interface TreatmentsInterface {
|
|||
TempBasal getTempBasal (long time);
|
||||
double getTempBasalAbsoluteRate();
|
||||
double getTempBasalRemainingMinutes();
|
||||
void tempBasalStart(TempBasal tempBasal);
|
||||
void tempBasalStop(long time);
|
||||
|
||||
boolean isExtendedBoluslInProgress();
|
||||
TempBasal getExtendedBolus (long time);
|
||||
void extendedBolusStart(TempBasal extendedBolus);
|
||||
void extendedBolusStop(long time);
|
||||
|
||||
long oldestDataAvaialable();
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
|||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventBolusRequested;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
|
@ -412,16 +413,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
return 0d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalAbsoluteRate() {
|
||||
return activeTreatments.getTempBasalAbsoluteRate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalRemainingMinutes() {
|
||||
return activeTreatments.getTempBasalRemainingMinutes();
|
||||
}
|
||||
|
||||
public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
|
||||
mWakeLock.acquire();
|
||||
PumpEnactResult result;
|
||||
|
@ -1141,7 +1132,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
}
|
||||
}
|
||||
|
||||
// Treatments interface
|
||||
// ****** Treatments interface *****
|
||||
@Override
|
||||
public void updateTotalIOBTreatments() {
|
||||
activeTreatments.updateTotalIOBTreatments();
|
||||
|
@ -1193,13 +1184,35 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isExtendedBoluslInProgress() {
|
||||
return activeTreatments.isExtendedBoluslInProgress();
|
||||
public TempBasal getTempBasal(long time) {
|
||||
return activeTreatments.getTempBasal(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TempBasal getTempBasal(long time) {
|
||||
return activeTreatments.getTempBasal(time);
|
||||
public double getTempBasalAbsoluteRate() {
|
||||
return activeTreatments.getTempBasalAbsoluteRate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalRemainingMinutes() {
|
||||
return activeTreatments.getTempBasalRemainingMinutes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempBasalStart(TempBasal tempBasal) {
|
||||
activeTreatments.tempBasalStart(tempBasal);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempBasalStop(long time) {
|
||||
activeTreatments.tempBasalStop(time);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExtendedBoluslInProgress() {
|
||||
return activeTreatments.isExtendedBoluslInProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1207,6 +1220,18 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
return activeTreatments.getExtendedBolus(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendedBolusStart(TempBasal tempBasal) {
|
||||
activeTreatments.extendedBolusStart(tempBasal);
|
||||
MainApp.bus().post(new EventExtendedBolusChange());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendedBolusStop(long time) {
|
||||
activeTreatments.extendedBolusStop(time);
|
||||
MainApp.bus().post(new EventExtendedBolusChange());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long oldestDataAvaialable() {
|
||||
return activeTreatments.oldestDataAvaialable();
|
||||
|
|
|
@ -69,6 +69,7 @@ import info.nightscout.androidaps.db.BgReading;
|
|||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.db.TempTarget;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
|
@ -695,9 +696,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
scheduleUpdateGUI("EventTempBasalChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
||||
scheduleUpdateGUI("EventExtendedBolusChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
scheduleUpdateGUI("EventTempBasalChange");
|
||||
scheduleUpdateGUI("EventNewBG");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
|
@ -238,6 +239,11 @@ public class PersistentNotificationPlugin implements PluginBase{
|
|||
updateNotification();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
||||
updateNotification();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
updateNotification();
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Date;
|
|||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog;
|
||||
|
@ -193,6 +194,11 @@ public class DanaRFragment extends Fragment {
|
|||
updateGUI();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange s) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
// GUI functions
|
||||
private void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
|
|
|
@ -5,15 +5,12 @@ import android.support.annotation.NonNull;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
|
||||
public class MsgStatusBolusExtended extends MessageBase {
|
||||
|
@ -30,6 +27,9 @@ public class MsgStatusBolusExtended extends MessageBase {
|
|||
|
||||
double extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100d;
|
||||
int extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3);
|
||||
// This is available only on korean, but not needed now
|
||||
// int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2);
|
||||
// int isEasyUIUserSleep = intFromBuff(bytes, 9, 1);
|
||||
|
||||
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
|
||||
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
|
||||
|
@ -66,48 +66,38 @@ public class MsgStatusBolusExtended extends MessageBase {
|
|||
public static void updateExtendedBolusInDB() {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
Date now = new Date();
|
||||
long now = new Date().getTime();
|
||||
|
||||
try {
|
||||
|
||||
if (treatmentsInterface.isExtendedBoluslInProgress()) {
|
||||
TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
|
||||
if (pump.isExtendedInProgress) {
|
||||
if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) {
|
||||
// Close current extended
|
||||
extendedBolus.timeEnd = now;
|
||||
MainApp.getDbHelper().getDaoTempBasals().update(extendedBolus);
|
||||
// Create new
|
||||
TempBasal newExtended = new TempBasal();
|
||||
newExtended.timeStart = now;
|
||||
newExtended.absolute = pump.extendedBolusAbsoluteRate;
|
||||
newExtended.isAbsolute = true;
|
||||
newExtended.duration = pump.extendedBolusMinutes;
|
||||
newExtended.isExtended = true;
|
||||
MainApp.getDbHelper().getDaoTempBasals().create(newExtended);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
} else {
|
||||
// Close curent temp basal
|
||||
extendedBolus.timeEnd = now;
|
||||
MainApp.getDbHelper().getDaoTempBasals().update(extendedBolus);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
} else {
|
||||
if (pump.isExtendedInProgress) {
|
||||
if (treatmentsInterface.isExtendedBoluslInProgress()) {
|
||||
TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
|
||||
if (pump.isExtendedInProgress) {
|
||||
if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) {
|
||||
// Close current extended
|
||||
treatmentsInterface.extendedBolusStop(now);
|
||||
// Create new
|
||||
TempBasal newExtended = new TempBasal();
|
||||
newExtended.timeStart = now;
|
||||
newExtended.timeStart = new Date(now);
|
||||
newExtended.absolute = pump.extendedBolusAbsoluteRate;
|
||||
newExtended.isAbsolute = true;
|
||||
newExtended.duration = pump.extendedBolusMinutes;
|
||||
newExtended.isExtended = true;
|
||||
MainApp.getDbHelper().getDaoTempBasals().create(newExtended);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
treatmentsInterface.extendedBolusStart(newExtended);
|
||||
}
|
||||
} else {
|
||||
// Close curent temp basal
|
||||
treatmentsInterface.extendedBolusStop(now);
|
||||
}
|
||||
} else {
|
||||
if (pump.isExtendedInProgress) {
|
||||
// Create new
|
||||
TempBasal newExtended = new TempBasal();
|
||||
newExtended.timeStart = new Date(now);
|
||||
newExtended.absolute = pump.extendedBolusAbsoluteRate;
|
||||
newExtended.isAbsolute = true;
|
||||
newExtended.duration = pump.extendedBolusMinutes;
|
||||
newExtended.isExtended = true;
|
||||
treatmentsInterface.extendedBolusStart(newExtended);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,11 @@ import android.support.annotation.NonNull;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
|
||||
|
@ -62,48 +60,38 @@ public class MsgStatusTempBasal extends MessageBase {
|
|||
public static void updateTempBasalInDB() {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
DanaRPump danaRPump = DanaRPump.getInstance();
|
||||
Date now = new Date();
|
||||
long now = new Date().getTime();
|
||||
|
||||
try {
|
||||
|
||||
if (treatmentsInterface.isTempBasalInProgress()) {
|
||||
TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
|
||||
if (danaRPump.isTempBasalInProgress) {
|
||||
if (tempBasal.percent != danaRPump.tempBasalPercent) {
|
||||
// Close current temp basal
|
||||
tempBasal.timeEnd = now;
|
||||
MainApp.getDbHelper().getDaoTempBasals().update(tempBasal);
|
||||
// Create new
|
||||
TempBasal newTempBasal = new TempBasal();
|
||||
newTempBasal.timeStart = now;
|
||||
newTempBasal.percent = danaRPump.tempBasalPercent;
|
||||
newTempBasal.isAbsolute = false;
|
||||
newTempBasal.duration = danaRPump.tempBasalTotalSec / 60;
|
||||
newTempBasal.isExtended = false;
|
||||
MainApp.getDbHelper().getDaoTempBasals().create(newTempBasal);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
} else {
|
||||
if (treatmentsInterface.isTempBasalInProgress()) {
|
||||
TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
|
||||
if (danaRPump.isTempBasalInProgress) {
|
||||
if (tempBasal.percent != danaRPump.tempBasalPercent) {
|
||||
// Close current temp basal
|
||||
tempBasal.timeEnd = now;
|
||||
MainApp.getDbHelper().getDaoTempBasals().update(tempBasal);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
} else {
|
||||
if (danaRPump.isTempBasalInProgress) {
|
||||
treatmentsInterface.tempBasalStop(now);
|
||||
// Create new
|
||||
TempBasal newTempBasal = new TempBasal();
|
||||
newTempBasal.timeStart = now;
|
||||
newTempBasal.timeStart = new Date(now);
|
||||
newTempBasal.percent = danaRPump.tempBasalPercent;
|
||||
newTempBasal.isAbsolute = false;
|
||||
newTempBasal.duration = danaRPump.tempBasalTotalSec / 60;
|
||||
newTempBasal.isExtended = false;
|
||||
MainApp.getDbHelper().getDaoTempBasals().create(newTempBasal);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
treatmentsInterface.tempBasalStart(newTempBasal);
|
||||
}
|
||||
} else {
|
||||
// Close current temp basal
|
||||
treatmentsInterface.tempBasalStop(now);
|
||||
}
|
||||
} else {
|
||||
if (danaRPump.isTempBasalInProgress) {
|
||||
// Create new
|
||||
TempBasal newTempBasal = new TempBasal();
|
||||
newTempBasal.timeStart = new Date(now);
|
||||
newTempBasal.percent = danaRPump.tempBasalPercent;
|
||||
newTempBasal.isAbsolute = false;
|
||||
newTempBasal.duration = danaRPump.tempBasalTotalSec / 60;
|
||||
newTempBasal.isExtended = false;
|
||||
treatmentsInterface.tempBasalStart(newTempBasal);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Date;
|
|||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
|
@ -191,6 +192,11 @@ public class DanaRKoreanFragment extends Fragment {
|
|||
updateGUI();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange s) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
// GUI functions
|
||||
private void updateGUI() {
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public class MessageHashTable_k {
|
|||
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
|
||||
put(new MsgStatusBolusExtended_k()); // 0x0207 CMD_PUMP_EXPANS_INS_I
|
||||
put(new MsgStatusBolusExtended()); // 0x0207 CMD_PUMP_EXPANS_INS_I
|
||||
put(new MsgStatusBasic_k()); // 0x020A CMD_PUMP_INITVIEW_I
|
||||
put(new MsgStatus_k()); // 0x020B CMD_PUMP_STATUS
|
||||
put(new MsgInitConnStatusTime_k()); // 0x0301 CMD_PUMPINIT_TIME_INFO
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.PumpDanaRKorean.comm;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||
|
||||
public class MsgStatusBolusExtended_k extends MessageBase {
|
||||
private static Logger log = LoggerFactory.getLogger(MsgStatusBolusExtended_k.class);
|
||||
|
||||
public MsgStatusBolusExtended_k() {
|
||||
SetCommand(0x0207);
|
||||
}
|
||||
|
||||
public void handleMessage(byte[] bytes) {
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
boolean isExtendedInProgress = intFromBuff(bytes, 0, 1) == 1;
|
||||
int extendedBolusHalfHours = intFromBuff(bytes, 1, 1);
|
||||
int extendedBolusMinutes = extendedBolusHalfHours * 30;
|
||||
|
||||
double extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100d;
|
||||
int extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3);
|
||||
int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2);
|
||||
int isEasyUIUserSleep = intFromBuff(bytes, 9, 1);
|
||||
|
||||
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
|
||||
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
|
||||
Date extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : new Date(0);
|
||||
int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes;
|
||||
|
||||
pump.isExtendedInProgress = isExtendedInProgress;
|
||||
pump.extendedBolusMinutes = extendedBolusMinutes;
|
||||
pump.extendedBolusAmount = extendedBolusAmount;
|
||||
pump.extendedBolusSoFarInMinutes = extendedBolusSoFarInMinutes;
|
||||
pump.extendedBolusAbsoluteRate = extendedBolusAbsoluteRate;
|
||||
pump.extendedBolusStart = extendedBolusStart;
|
||||
pump.extendedBolusRemainingMinutes = extendedBolusRemainingMinutes;
|
||||
|
||||
updateExtendedBolusInDB();
|
||||
|
||||
if (Config.logDanaMessageDetail) {
|
||||
log.debug("Is extended bolus running: " + isExtendedInProgress);
|
||||
log.debug("Extended bolus min: " + extendedBolusMinutes);
|
||||
log.debug("Extended bolus amount: " + extendedBolusAmount);
|
||||
log.debug("Extended bolus so far in minutes: " + extendedBolusSoFarInMinutes);
|
||||
log.debug("Extended bolus absolute rate: " + extendedBolusAbsoluteRate);
|
||||
log.debug("Extended bolus start: " + extendedBolusStart);
|
||||
log.debug("Extended bolus remaining minutes: " + extendedBolusRemainingMinutes);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Date getDateFromSecAgo(int tempBasalAgoSecs) {
|
||||
return new Date((long) (Math.ceil(new Date().getTime() / 1000d) - tempBasalAgoSecs) * 1000);
|
||||
}
|
||||
|
||||
public static void updateExtendedBolusInDB() {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
Date now = new Date();
|
||||
|
||||
try {
|
||||
|
||||
if (treatmentsInterface.isExtendedBoluslInProgress()) {
|
||||
TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
|
||||
if (pump.isExtendedInProgress) {
|
||||
if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) {
|
||||
// Close current extended
|
||||
extendedBolus.timeEnd = now;
|
||||
MainApp.getDbHelper().getDaoTempBasals().update(extendedBolus);
|
||||
// Create new
|
||||
TempBasal newExtended = new TempBasal();
|
||||
newExtended.timeStart = now;
|
||||
newExtended.absolute = pump.extendedBolusAbsoluteRate;
|
||||
newExtended.isAbsolute = true;
|
||||
newExtended.duration = pump.extendedBolusMinutes;
|
||||
newExtended.isExtended = true;
|
||||
MainApp.getDbHelper().getDaoTempBasals().create(newExtended);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
} else {
|
||||
// Close curent temp basal
|
||||
extendedBolus.timeEnd = now;
|
||||
MainApp.getDbHelper().getDaoTempBasals().update(extendedBolus);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
} else {
|
||||
if (pump.isExtendedInProgress) {
|
||||
// Create new
|
||||
TempBasal newExtended = new TempBasal();
|
||||
newExtended.timeStart = now;
|
||||
newExtended.absolute = pump.extendedBolusAbsoluteRate;
|
||||
newExtended.isAbsolute = true;
|
||||
newExtended.duration = pump.extendedBolusMinutes;
|
||||
newExtended.isExtended = true;
|
||||
MainApp.getDbHelper().getDaoTempBasals().create(newExtended);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,6 +63,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingMeal;
|
|||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingProfileRatios;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingPumpTime;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingShippingInfo;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusBolusExtended;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRBolusStart;
|
||||
|
@ -75,7 +76,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
|||
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.MsgStatusBasic_k;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.comm.MsgStatusBolusExtended_k;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
|
@ -276,7 +276,7 @@ public class DanaRKoreanExecutionService extends Service {
|
|||
//MsgStatus_k statusMsg = new MsgStatus_k();
|
||||
MsgStatusBasic_k statusBasicMsg = new MsgStatusBasic_k();
|
||||
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
|
||||
MsgStatusBolusExtended_k exStatusMsg = new MsgStatusBolusExtended_k();
|
||||
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
|
||||
MsgCheckValue_k checkValue = new MsgCheckValue_k();
|
||||
|
||||
if (danaRPump.isNewPump) {
|
||||
|
@ -369,7 +369,7 @@ public class DanaRKoreanExecutionService extends Service {
|
|||
if (!isConnected()) return false;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
|
||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
|
||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended_k());
|
||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||
return true;
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ public class DanaRKoreanExecutionService extends Service {
|
|||
if (!isConnected()) return false;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
|
||||
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
|
||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended_k());
|
||||
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Date;
|
|||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
|
@ -194,6 +195,11 @@ public class DanaRv2Fragment extends Fragment {
|
|||
updateGUI();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange s) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
// GUI functions
|
||||
private void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.InsulinInterface;
|
|||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui;
|
||||
|
@ -235,6 +236,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
PumpEnactResult result = cancelTempBasal();
|
||||
if (!result.success)
|
||||
return result;
|
||||
|
@ -249,13 +251,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
result.absolute = absoluteRate;
|
||||
result.duration = durationInMinutes;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().create(tempBasal);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
result.success = false;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_sqlerror);
|
||||
}
|
||||
treatmentsInterface.tempBasalStart(tempBasal);
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Setting temp basal absolute: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
|
@ -265,6 +261,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||
result = cancelTempBasal();
|
||||
|
@ -283,13 +280,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
result.isTempCancel = false;
|
||||
result.duration = durationInMinutes;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().create(tempBasal);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
result.success = false;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_sqlerror);
|
||||
}
|
||||
treatmentsInterface.tempBasalStart(tempBasal);
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Settings temp basal percent: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
|
@ -299,6 +290,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
PumpEnactResult result = cancelExtendedBolus();
|
||||
if (!result.success)
|
||||
return result;
|
||||
|
@ -314,14 +306,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
result.isTempCancel = false;
|
||||
result.duration = durationInMinutes;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().create(extendedBolus);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
result.success = false;
|
||||
result.enacted = false;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_sqlerror);
|
||||
}
|
||||
treatmentsInterface.extendedBolusStart(extendedBolus);
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Setting extended bolus: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
|
@ -331,26 +316,18 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public PumpEnactResult cancelTempBasal() {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
result.success = true;
|
||||
result.isTempCancel = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
||||
if (treatmentsInterface.isTempBasalInProgress()) {
|
||||
result.enacted = true;
|
||||
TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
|
||||
tb.timeEnd = new Date();
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().update(tb);
|
||||
//tempBasal = null;
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Canceling temp basal: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
result.success = false;
|
||||
result.enacted = false;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_sqlerror);
|
||||
}
|
||||
treatmentsInterface.tempBasalStop(new Date().getTime());
|
||||
//tempBasal = null;
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Canceling temp basal: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
}
|
||||
lastDataTime = new Date();
|
||||
return result;
|
||||
|
@ -358,17 +335,10 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public PumpEnactResult cancelExtendedBolus() {
|
||||
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
|
||||
TempBasal extendedBolus = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime());
|
||||
extendedBolus.timeEnd = new Date();
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().update(extendedBolus);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
result.success = false;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_sqlerror);
|
||||
}
|
||||
if (treatmentsInterface.isExtendedBoluslInProgress()) {
|
||||
treatmentsInterface.extendedBolusStop(new Date().getTime());
|
||||
}
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
|
@ -179,12 +180,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
}
|
||||
}
|
||||
if (update) {
|
||||
try {
|
||||
Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals();
|
||||
dao.update(t);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.getDbHelper().update(t);
|
||||
if (Config.logTempBasalsCut) {
|
||||
log.debug("Fixing unfinished temp end: " + t.log());
|
||||
if (position > 0)
|
||||
|
@ -346,6 +342,20 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendedBolusStart(TempBasal extendedBolus) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendedBolusStop(long time) {
|
||||
TempBasal extendedBolus = getExtendedBolus(time);
|
||||
if (extendedBolus != null) {
|
||||
extendedBolus.timeEnd = new Date(time);
|
||||
MainApp.getDbHelper().update(extendedBolus);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalAbsoluteRate() {
|
||||
PumpInterface pump = MainApp.getConfigBuilder();
|
||||
|
@ -376,6 +386,21 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempBasalStart(TempBasal tempBasal) {
|
||||
MainApp.getDbHelper().create(tempBasal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempBasalStop(long time) {
|
||||
TempBasal tempBasal = getTempBasal(time);
|
||||
if (tempBasal != null) {
|
||||
tempBasal.timeEnd = new Date(time);
|
||||
MainApp.getDbHelper().update(tempBasal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long oldestDataAvaialable() {
|
||||
long oldestTemp = new Date().getTime();
|
||||
|
@ -410,6 +435,11 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
initializeData();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
||||
initializeData();
|
||||
}
|
||||
|
||||
public void onStatusEvent(final EventPreferenceChange s) {
|
||||
if (s.isChanged("danar_useextended")) {
|
||||
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
|
||||
|
|
|
@ -177,12 +177,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
|||
}
|
||||
}
|
||||
if (update) {
|
||||
try {
|
||||
Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals();
|
||||
dao.update(t);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MainApp.getDbHelper().update(t);
|
||||
if (Config.logTempBasalsCut) {
|
||||
log.debug("Fixing unfinished temp end: " + t.log());
|
||||
if (position > 0)
|
||||
|
@ -342,6 +337,16 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendedBolusStart(TempBasal extendedBolus) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendedBolusStop(long time) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalAbsoluteRate() {
|
||||
PumpInterface pump = MainApp.getConfigBuilder();
|
||||
|
@ -366,6 +371,16 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempBasalStart(TempBasal tempBasal) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempBasalStop(long time) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long oldestDataAvaialable() {
|
||||
long oldestTemp = new Date().getTime();
|
||||
|
@ -377,10 +392,4 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
|||
return oldestTemp;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventTempBasalChange ev) {
|
||||
initializeData();
|
||||
updateTotalIOBTempBasals();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.Config;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventBolusRequested;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
|
@ -149,6 +150,11 @@ public class WearPlugin implements PluginBase {
|
|||
sendDataToWatch(true, true, false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
||||
sendDataToWatch(true, true, false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
sendDataToWatch(true, true, true);
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
|
@ -214,6 +215,11 @@ public class StatuslinePlugin implements PluginBase {
|
|||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBG ev) {
|
||||
sendStatus();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
android:key="danar"
|
||||
android:title="@string/danar_pump_settings">
|
||||
|
||||
<info.nightscout.androidaps.plugins.DanaR.BluetoothDevicePreference
|
||||
<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" />
|
||||
|
|
Loading…
Reference in a new issue