Cleanups.
This commit is contained in:
parent
29cb1def50
commit
63131f73d0
3 changed files with 36 additions and 39 deletions
|
@ -11,5 +11,4 @@ interface IRuffyService {
|
||||||
void doRTDisconnect();
|
void doRTDisconnect();
|
||||||
void rtSendKey(byte keyCode, boolean changed);
|
void rtSendKey(byte keyCode, boolean changed);
|
||||||
void resetPairing();
|
void resetPairing();
|
||||||
boolean isConnected();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import de.jotomo.ruffyscripter.PumpState;
|
||||||
public class CommandResult {
|
public class CommandResult {
|
||||||
public boolean success;
|
public boolean success;
|
||||||
public boolean enacted;
|
public boolean enacted;
|
||||||
// TODO not really happy with that name "time the command finished executing"
|
|
||||||
public long completionTime;
|
public long completionTime;
|
||||||
public Exception exception;
|
public Exception exception;
|
||||||
public String message;
|
public String message;
|
||||||
|
|
|
@ -123,27 +123,26 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
int id = 1000;
|
int id = 1000;
|
||||||
long lastAlarmTime = 0;
|
long lastAlarmTime = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
CommandResult lastCmdResult = ComboPlugin.this.lastCmdResult;
|
Command localLastCmd = lastCmd;
|
||||||
if (lastCmdResult != null && !lastCmdResult.success) {
|
CommandResult localLastCmdResult = lastCmdResult;
|
||||||
|
if (localLastCmdResult != null && !localLastCmdResult.success) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
|
long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
|
||||||
if (now > fiveMinutesSinceLastAlarm) {
|
if (now > fiveMinutesSinceLastAlarm) {
|
||||||
log.error("Command failed: " + lastCmd);
|
log.error("Command failed: " + localLastCmd);
|
||||||
log.error("Command result: " + lastCmdResult);
|
log.error("Command result: " + localLastCmdResult);
|
||||||
PumpState pumpState = ComboPlugin.this.pumpState;
|
PumpState localPumpState = pumpState;
|
||||||
if (pumpState!=null) {
|
if (localPumpState != null && localPumpState.errorMsg != null) {
|
||||||
if (pumpState.errorMsg != null) {
|
log.warn("Pump is in error state, displayng; " + localPumpState.errorMsg);
|
||||||
log.warn("Pump is in error state, displayng; " + pumpState.errorMsg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
long[] vibratePattern = new long[]{1000, 1000, 1000, 1000, 1000};
|
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000};
|
||||||
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
||||||
NotificationCompat.Builder notificationBuilder =
|
NotificationCompat.Builder notificationBuilder =
|
||||||
new NotificationCompat.Builder(context)
|
new NotificationCompat.Builder(context)
|
||||||
.setSmallIcon(R.drawable.notif_icon)
|
.setSmallIcon(R.drawable.notif_icon)
|
||||||
.setSmallIcon(R.drawable.icon_bolus)
|
.setSmallIcon(R.drawable.icon_bolus)
|
||||||
.setContentTitle("Combo communication error")
|
.setContentTitle("Combo communication error")
|
||||||
.setContentText(lastCmdResult.message)
|
.setContentText(localLastCmdResult.message)
|
||||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||||
.setLights(Color.BLUE, 1000, 0)
|
.setLights(Color.BLUE, 1000, 0)
|
||||||
.setSound(uri)
|
.setSound(uri)
|
||||||
|
@ -151,7 +150,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
mgr.notify(id, notificationBuilder.build());
|
mgr.notify(id, notificationBuilder.build());
|
||||||
lastAlarmTime = now;
|
lastAlarmTime = now;
|
||||||
} else {
|
} else {
|
||||||
log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + lastCmdResult.message);
|
log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + localLastCmdResult.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SystemClock.sleep(5 * 1000);
|
SystemClock.sleep(5 * 1000);
|
||||||
|
@ -336,27 +335,27 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
if (detailedBolusInfo.insulin > 0) {
|
if (detailedBolusInfo.insulin > 0) {
|
||||||
// bolus needed, ask pump to deliver it
|
// bolus needed, ask pump to deliver it
|
||||||
CommandResult bolusCmdResult = runCommand(new BolusCommand(detailedBolusInfo.insulin));
|
CommandResult bolusCmdResult = runCommand(new BolusCommand(detailedBolusInfo.insulin));
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||||
result.success = bolusCmdResult.success;
|
pumpEnactResult.success = bolusCmdResult.success;
|
||||||
result.enacted = bolusCmdResult.enacted;
|
pumpEnactResult.enacted = bolusCmdResult.enacted;
|
||||||
result.comment = bolusCmdResult.message;
|
pumpEnactResult.comment = bolusCmdResult.message;
|
||||||
|
|
||||||
// if enacted, add bolus and carbs to treatment history
|
// if enacted, add bolus and carbs to treatment history
|
||||||
if (result.enacted) {
|
if (pumpEnactResult.enacted) {
|
||||||
// TODO if no error occurred, the requested bolus is what the pump delievered,
|
// TODO if no error occurred, the requested bolus is what the pump delievered,
|
||||||
// that has been checked. If an error occurred, we should check how much insulin
|
// that has been checked. If an error occurred, we should check how much insulin
|
||||||
// was delivered, e.g. when the cartridge went empty mid-bolus
|
// was delivered, e.g. when the cartridge went empty mid-bolus
|
||||||
// For the first iteration, the alert the pump raises must suffice
|
// For the first iteration, the alert the pump raises must suffice
|
||||||
result.bolusDelivered = detailedBolusInfo.insulin;
|
pumpEnactResult.bolusDelivered = detailedBolusInfo.insulin;
|
||||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
pumpEnactResult.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
|
|
||||||
detailedBolusInfo.date = bolusCmdResult.completionTime;
|
detailedBolusInfo.date = bolusCmdResult.completionTime;
|
||||||
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
|
||||||
} else {
|
} else {
|
||||||
result.bolusDelivered = 0d;
|
pumpEnactResult.bolusDelivered = 0d;
|
||||||
result.carbsDelivered = 0d;
|
pumpEnactResult.carbsDelivered = 0d;
|
||||||
}
|
}
|
||||||
return result;
|
return pumpEnactResult;
|
||||||
} else {
|
} else {
|
||||||
// no bolus required
|
// no bolus required
|
||||||
|
|
||||||
|
@ -364,23 +363,24 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
// so just wait, yeah, this is dumb. for now; proper fix via GL#10
|
// so just wait, yeah, this is dumb. for now; proper fix via GL#10
|
||||||
// info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog.scheduleDismiss()
|
// info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog.scheduleDismiss()
|
||||||
SystemClock.sleep(6000);
|
SystemClock.sleep(6000);
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||||
result.success = true;
|
pumpEnactResult.success = true;
|
||||||
result.enacted = true;
|
pumpEnactResult.enacted = true;
|
||||||
result.bolusDelivered = 0d;
|
pumpEnactResult.bolusDelivered = 0d;
|
||||||
result.carbsDelivered = detailedBolusInfo.carbs;
|
pumpEnactResult.carbsDelivered = detailedBolusInfo.carbs;
|
||||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
pumpEnactResult.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||||
return result;
|
return pumpEnactResult;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
// neither carbs nor bolus requested
|
||||||
result.success = false;
|
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||||
result.enacted = false;
|
pumpEnactResult.success = false;
|
||||||
result.bolusDelivered = 0d;
|
pumpEnactResult.enacted = false;
|
||||||
result.carbsDelivered = 0d;
|
pumpEnactResult.bolusDelivered = 0d;
|
||||||
result.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
pumpEnactResult.carbsDelivered = 0d;
|
||||||
|
pumpEnactResult.comment = MainApp.instance().getString(R.string.danar_invalidinput);
|
||||||
log.error("deliverTreatment: Invalid input");
|
log.error("deliverTreatment: Invalid input");
|
||||||
return result;
|
return pumpEnactResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +463,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
CommandResult commandResult = runCommand(new SetTbrCommand(percent, durationInMinutes));
|
CommandResult commandResult = runCommand(new SetTbrCommand(percent, durationInMinutes));
|
||||||
if (commandResult.enacted) {
|
if (commandResult.enacted) {
|
||||||
// make sure we're not skipping a loop iteration by a few secs
|
|
||||||
TemporaryBasal tempStart = new TemporaryBasal(commandResult.completionTime);
|
TemporaryBasal tempStart = new TemporaryBasal(commandResult.completionTime);
|
||||||
// TODO commandResult.state.tbrRemainingDuration might already display 29 if 30 was set, since 29:59 is shown as 29 ...
|
// TODO commandResult.state.tbrRemainingDuration might already display 29 if 30 was set, since 29:59 is shown as 29 ...
|
||||||
// we should check this, but really ... something must be really screwed up if that number was anything different
|
// we should check this, but really ... something must be really screwed up if that number was anything different
|
||||||
|
|
Loading…
Reference in a new issue