Clean up pump init.
This commit is contained in:
parent
6af28479d6
commit
88b3857fb9
|
@ -324,56 +324,55 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
return new Date(pump.lastSuccessfulCmdTime);
|
return new Date(pump.lastSuccessfulCmdTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Runs pump initializing if needed and reads the pump state from the main screen. */
|
||||||
* Runs pump initializing if needed, checks for boluses given on the pump, updates the
|
|
||||||
* reservoir level and checks the running TBR on the pump.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void getPumpStatus() {
|
public synchronized void getPumpStatus() {
|
||||||
log.debug("getPumpStatus called");
|
log.debug("getPumpStatus called");
|
||||||
if (!pump.initialized) {
|
if (!pump.initialized) {
|
||||||
long maxWait = System.currentTimeMillis() + 15 * 1000;
|
initializePump();
|
||||||
while (!ruffyScripter.isPumpAvailable()) {
|
} else {
|
||||||
log.debug("Waiting for ruffy service to come up ...");
|
runCommand(MainApp.sResources.getString(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readPumpState);
|
||||||
SystemClock.sleep(100);
|
}
|
||||||
if (System.currentTimeMillis() > maxWait) {
|
}
|
||||||
log.debug("ruffy service unavailable, wtf");
|
|
||||||
return;
|
private synchronized void initializePump() {
|
||||||
}
|
long maxWait = System.currentTimeMillis() + 15 * 1000;
|
||||||
|
while (!ruffyScripter.isPumpAvailable()) {
|
||||||
|
log.debug("Waiting for ruffy service to come up ...");
|
||||||
|
SystemClock.sleep(100);
|
||||||
|
if (System.currentTimeMillis() > maxWait) {
|
||||||
|
log.debug("ruffy service unavailable, wtf");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult stateResult = runCommand(pump.initialized ? MainApp.sResources.getString(R.string.combo_pump_action_refreshing) : MainApp.sResources.getString(R.string.combo_pump_action_initializing),
|
CommandResult stateResult = runCommand(MainApp.sResources.getString(R.string.combo_pump_action_initializing),1, ruffyScripter::readPumpState);
|
||||||
1, ruffyScripter::readPumpState);
|
|
||||||
if (!stateResult.success) {
|
if (!stateResult.success) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read basal profile into cache and update pump profile if needed
|
if (stateResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BASAL_RATE_PROFILE) {
|
||||||
if (!pump.initialized) {
|
Notification n = new Notification(Notification.COMBO_PUMP_ALARM,
|
||||||
if (stateResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BASAL_RATE_PROFILE) {
|
MainApp.sResources.getString(R.string.combo_force_disabled_notification),
|
||||||
Notification n = new Notification(Notification.COMBO_PUMP_ALARM,
|
Notification.URGENT);
|
||||||
MainApp.sResources.getString(R.string.combo_force_disabled_notification),
|
n.soundId = R.raw.alarm;
|
||||||
Notification.URGENT);
|
MainApp.bus().post(new EventNewNotification(n));
|
||||||
n.soundId = R.raw.alarm;
|
violationWarningRaisedForViolationAt = lowSuspendOnlyLoopEnforcedUntil;
|
||||||
MainApp.bus().post(new EventNewNotification(n));
|
return;
|
||||||
violationWarningRaisedForViolationAt = lowSuspendOnlyLoopEnforcedUntil;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CommandResult readBasalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
|
|
||||||
if (!readBasalResult.success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pump.basalProfile = readBasalResult.basalProfile;
|
|
||||||
validBasalRateProfileSelectedOnPump = true;
|
|
||||||
|
|
||||||
pump.initialized = true;
|
|
||||||
MainApp.bus().post(new EventInitializationChanged());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ComboFragment updates state fully only after the pump has initialized,
|
// read basal profile into cache (KeepAlive will trigger a profile update if needed)
|
||||||
// this fetches state again and updates the UI proper
|
CommandResult readBasalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
|
||||||
runCommand(null, 0, ruffyScripter::readPumpState);
|
if (!readBasalResult.success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pump.basalProfile = readBasalResult.basalProfile;
|
||||||
|
validBasalRateProfileSelectedOnPump = true;
|
||||||
|
pump.initialized = true;
|
||||||
|
MainApp.bus().post(new EventInitializationChanged());
|
||||||
|
|
||||||
|
// ComboFragment updates state fully only after the pump has initialized, so run this manually here
|
||||||
|
updateLocalData(readBasalResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLocalData(CommandResult result) {
|
private void updateLocalData(CommandResult result) {
|
||||||
|
|
Loading…
Reference in a new issue