Clean up pump init.

This commit is contained in:
Johannes Mockenhaupt 2017-12-27 00:43:42 +01:00
parent 6af28479d6
commit 88b3857fb9
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -324,14 +324,18 @@ 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) {
initializePump();
} else {
runCommand(MainApp.sResources.getString(R.string.combo_pump_action_refreshing), 1, ruffyScripter::readPumpState);
}
}
private synchronized void initializePump() {
long maxWait = System.currentTimeMillis() + 15 * 1000; long maxWait = System.currentTimeMillis() + 15 * 1000;
while (!ruffyScripter.isPumpAvailable()) { while (!ruffyScripter.isPumpAvailable()) {
log.debug("Waiting for ruffy service to come up ..."); log.debug("Waiting for ruffy service to come up ...");
@ -341,16 +345,12 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return; 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 (!pump.initialized) {
if (stateResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BASAL_RATE_PROFILE) { if (stateResult.state.unsafeUsageDetected == PumpState.UNSUPPORTED_BASAL_RATE_PROFILE) {
Notification n = new Notification(Notification.COMBO_PUMP_ALARM, Notification n = new Notification(Notification.COMBO_PUMP_ALARM,
MainApp.sResources.getString(R.string.combo_force_disabled_notification), MainApp.sResources.getString(R.string.combo_force_disabled_notification),
@ -360,20 +360,19 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
violationWarningRaisedForViolationAt = lowSuspendOnlyLoopEnforcedUntil; violationWarningRaisedForViolationAt = lowSuspendOnlyLoopEnforcedUntil;
return; return;
} }
// read basal profile into cache (KeepAlive will trigger a profile update if needed)
CommandResult readBasalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile); CommandResult readBasalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
if (!readBasalResult.success) { if (!readBasalResult.success) {
return; return;
} }
pump.basalProfile = readBasalResult.basalProfile; pump.basalProfile = readBasalResult.basalProfile;
validBasalRateProfileSelectedOnPump = true; validBasalRateProfileSelectedOnPump = true;
pump.initialized = true; pump.initialized = true;
MainApp.bus().post(new EventInitializationChanged()); MainApp.bus().post(new EventInitializationChanged());
}
// ComboFragment updates state fully only after the pump has initialized, // ComboFragment updates state fully only after the pump has initialized, so run this manually here
// this fetches state again and updates the UI proper updateLocalData(readBasalResult);
runCommand(null, 0, ruffyScripter::readPumpState);
} }
private void updateLocalData(CommandResult result) { private void updateLocalData(CommandResult result) {