Eopatch: fix pairing
This commit is contained in:
parent
7ae9ad1105
commit
9d14db71c7
3 changed files with 69 additions and 75 deletions
|
@ -82,40 +82,41 @@ public class PatchManager implements IPatchManager {
|
||||||
private Disposable mConnectingDisposable = null;
|
private Disposable mConnectingDisposable = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PatchManager() {}
|
public PatchManager() {
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
void onInit() {
|
void onInit() {
|
||||||
patchScanner = new PatchScanner(context);
|
patchScanner = new PatchScanner(context);
|
||||||
|
|
||||||
mCompositeDisposable.add(observePatchConnectionState()
|
mCompositeDisposable.add(observePatchConnectionState()
|
||||||
.subscribe(bleConnectionState -> {
|
.subscribe(bleConnectionState -> {
|
||||||
switch (bleConnectionState) {
|
switch (bleConnectionState) {
|
||||||
case DISCONNECTED:
|
case DISCONNECTED:
|
||||||
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED));
|
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED));
|
||||||
rxBus.send(new EventRefreshOverview("Eopatch connection state: " + bleConnectionState.name(), true));
|
rxBus.send(new EventRefreshOverview("Eopatch connection state: " + bleConnectionState.name(), true));
|
||||||
rxBus.send(new EventCustomActionsChanged());
|
rxBus.send(new EventCustomActionsChanged());
|
||||||
stopObservingConnection();
|
stopObservingConnection();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONNECTED:
|
case CONNECTED:
|
||||||
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED));
|
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED));
|
||||||
rxBus.send(new EventRefreshOverview("Eopatch connection state: " + bleConnectionState.name(), true));
|
rxBus.send(new EventRefreshOverview("Eopatch connection state: " + bleConnectionState.name(), true));
|
||||||
rxBus.send(new EventCustomActionsChanged());
|
rxBus.send(new EventCustomActionsChanged());
|
||||||
stopObservingConnection();
|
stopObservingConnection();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONNECTING:
|
case CONNECTING:
|
||||||
mConnectingDisposable = Observable.interval(0, 1, TimeUnit.SECONDS)
|
mConnectingDisposable = Observable.interval(0, 1, TimeUnit.SECONDS)
|
||||||
.observeOn(aapsSchedulers.getMain())
|
.observeOn(aapsSchedulers.getMain())
|
||||||
.takeUntil(n -> getPatchConnectionState().isConnected() || n > 10 * 60)
|
.takeUntil(n -> getPatchConnectionState().isConnected() || n > 10 * 60)
|
||||||
.subscribe(n -> rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, n.intValue())));
|
.subscribe(n -> rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, n.intValue())));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
stopObservingConnection();
|
stopObservingConnection();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
mCompositeDisposable.add(rxBus
|
mCompositeDisposable.add(rxBus
|
||||||
.toObservable(EventPatchActivationNotComplete.class)
|
.toObservable(EventPatchActivationNotComplete.class)
|
||||||
|
@ -137,8 +138,8 @@ public class PatchManager implements IPatchManager {
|
||||||
setConnection();
|
setConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopObservingConnection(){
|
private void stopObservingConnection() {
|
||||||
if(mConnectingDisposable != null) {
|
if (mConnectingDisposable != null) {
|
||||||
mConnectingDisposable.dispose();
|
mConnectingDisposable.dispose();
|
||||||
mConnectingDisposable = null;
|
mConnectingDisposable = null;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +217,7 @@ public class PatchManager implements IPatchManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setConnection() {
|
public void setConnection() {
|
||||||
if(pm.getPatchConfig().hasMacAddress()){
|
if (pm.getPatchConfig().hasMacAddress()) {
|
||||||
patchManager.updateMacAddress(pm.getPatchConfig().getMacAddress(), false);
|
patchManager.updateMacAddress(pm.getPatchConfig().getMacAddress(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,24 +257,26 @@ public class PatchManager implements IPatchManager {
|
||||||
public Single<Boolean> patchActivation(long timeout) {
|
public Single<Boolean> patchActivation(long timeout) {
|
||||||
return patchManager.patchActivation(timeout)
|
return patchManager.patchActivation(timeout)
|
||||||
.doOnSuccess(success -> {
|
.doOnSuccess(success -> {
|
||||||
// if (success) {
|
if (success) {
|
||||||
// pumpSync.insertTherapyEventIfNewWithTimestamp(
|
pumpSync.connectNewPump(true);
|
||||||
// getPatchConfig().getPatchWakeupTimestamp(),
|
Thread.sleep(1000);
|
||||||
// DetailedBolusInfo.EventType.CANNULA_CHANGE,
|
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||||
// null,
|
System.currentTimeMillis(),
|
||||||
// null,
|
DetailedBolusInfo.EventType.CANNULA_CHANGE,
|
||||||
// PumpType.EOFLOW_EOPATCH2,
|
null,
|
||||||
// getPatchConfig().getPatchSerialNumber()
|
null,
|
||||||
// );
|
PumpType.EOFLOW_EOPATCH2,
|
||||||
// pumpSync.insertTherapyEventIfNewWithTimestamp(
|
getPatchConfig().getPatchSerialNumber()
|
||||||
// getPatchConfig().getPatchWakeupTimestamp(),
|
);
|
||||||
// DetailedBolusInfo.EventType.INSULIN_CHANGE,
|
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
||||||
// null,
|
System.currentTimeMillis(),
|
||||||
// null,
|
DetailedBolusInfo.EventType.INSULIN_CHANGE,
|
||||||
// PumpType.EOFLOW_EOPATCH2,
|
null,
|
||||||
// getPatchConfig().getPatchSerialNumber()
|
null,
|
||||||
// );
|
PumpType.EOFLOW_EOPATCH2,
|
||||||
// }
|
getPatchConfig().getPatchSerialNumber()
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +331,7 @@ public class PatchManager implements IPatchManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Single<ComboBolusStopResponse> stopComboBolus(){
|
public Single<ComboBolusStopResponse> stopComboBolus() {
|
||||||
return patchManager.stopComboBolus();
|
return patchManager.stopComboBolus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +366,7 @@ public class PatchManager implements IPatchManager {
|
||||||
public void addBolusToHistory(DetailedBolusInfo originalDetailedBolusInfo) {
|
public void addBolusToHistory(DetailedBolusInfo originalDetailedBolusInfo) {
|
||||||
DetailedBolusInfo detailedBolusInfo = originalDetailedBolusInfo.copy();
|
DetailedBolusInfo detailedBolusInfo = originalDetailedBolusInfo.copy();
|
||||||
|
|
||||||
if(detailedBolusInfo.insulin > 0) {
|
if (detailedBolusInfo.insulin > 0) {
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
detailedBolusInfo.timestamp,
|
detailedBolusInfo.timestamp,
|
||||||
detailedBolusInfo.insulin,
|
detailedBolusInfo.insulin,
|
||||||
|
@ -387,7 +390,7 @@ public class PatchManager implements IPatchManager {
|
||||||
@Override
|
@Override
|
||||||
public void changeBuzzerSetting() {
|
public void changeBuzzerSetting() {
|
||||||
boolean buzzer = sp.getBoolean(SettingKeys.Companion.getBUZZER_REMINDERS(), false);
|
boolean buzzer = sp.getBoolean(SettingKeys.Companion.getBUZZER_REMINDERS(), false);
|
||||||
if(pm.getPatchConfig().getInfoReminder() != buzzer) {
|
if (pm.getPatchConfig().getInfoReminder() != buzzer) {
|
||||||
if (isActivated()) {
|
if (isActivated()) {
|
||||||
mCompositeDisposable.add(infoReminderSet(buzzer)
|
mCompositeDisposable.add(infoReminderSet(buzzer)
|
||||||
.observeOn(aapsSchedulers.getMain())
|
.observeOn(aapsSchedulers.getMain())
|
||||||
|
@ -407,23 +410,23 @@ public class PatchManager implements IPatchManager {
|
||||||
int doseUnit = sp.getInt(SettingKeys.Companion.getLOW_RESERVOIR_REMINDERS(), 0);
|
int doseUnit = sp.getInt(SettingKeys.Companion.getLOW_RESERVOIR_REMINDERS(), 0);
|
||||||
int hours = sp.getInt(SettingKeys.Companion.getEXPIRATION_REMINDERS(), 0);
|
int hours = sp.getInt(SettingKeys.Companion.getEXPIRATION_REMINDERS(), 0);
|
||||||
PatchConfig pc = pm.getPatchConfig();
|
PatchConfig pc = pm.getPatchConfig();
|
||||||
if(pc.getLowReservoirAlertAmount() != doseUnit || pc.getPatchExpireAlertTime() != hours) {
|
if (pc.getLowReservoirAlertAmount() != doseUnit || pc.getPatchExpireAlertTime() != hours) {
|
||||||
if (isActivated()) {
|
if (isActivated()) {
|
||||||
mCompositeDisposable.add(setLowReservoir(doseUnit, hours)
|
mCompositeDisposable.add(setLowReservoir(doseUnit, hours)
|
||||||
.observeOn(aapsSchedulers.getMain())
|
.observeOn(aapsSchedulers.getMain())
|
||||||
.doOnSubscribe(disposable -> {
|
.doOnSubscribe(disposable -> {
|
||||||
if(pc.getPatchExpireAlertTime() != hours){
|
if (pc.getPatchExpireAlertTime() != hours) {
|
||||||
Maybe.just(AlarmCode.B000)
|
Maybe.just(AlarmCode.B000)
|
||||||
.flatMap(alarmCode -> alarmRegistry.remove(alarmCode))
|
.flatMap(alarmCode -> alarmRegistry.remove(alarmCode))
|
||||||
.flatMap(alarmCode -> alarmRegistry.add(alarmCode, (pc.getExpireTimestamp() - System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours)), false))
|
.flatMap(alarmCode -> alarmRegistry.add(alarmCode, (pc.getExpireTimestamp() - System.currentTimeMillis() - TimeUnit.HOURS.toMillis(hours)), false))
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.subscribe(patchBooleanResponse -> {
|
.subscribe(patchBooleanResponse -> {
|
||||||
pc.setLowReservoirAlertAmount(doseUnit);
|
pc.setLowReservoirAlertAmount(doseUnit);
|
||||||
pc.setPatchExpireAlertTime(hours);
|
pc.setPatchExpireAlertTime(hours);
|
||||||
pm.flushPatchConfig();
|
pm.flushPatchConfig();
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
pc.setLowReservoirAlertAmount(doseUnit);
|
pc.setLowReservoirAlertAmount(doseUnit);
|
||||||
pc.setPatchExpireAlertTime(hours);
|
pc.setPatchExpireAlertTime(hours);
|
||||||
|
@ -433,8 +436,8 @@ public class PatchManager implements IPatchManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkActivationProcess(){
|
public void checkActivationProcess() {
|
||||||
if(getPatchConfig().getLifecycleEvent().isSubStepRunning()
|
if (getPatchConfig().getLifecycleEvent().isSubStepRunning()
|
||||||
&& !pm.getAlarms().isOccurring(AlarmCode.A005)
|
&& !pm.getAlarms().isOccurring(AlarmCode.A005)
|
||||||
&& !pm.getAlarms().isOccurring(AlarmCode.A020)) {
|
&& !pm.getAlarms().isOccurring(AlarmCode.A020)) {
|
||||||
rxAction.runOnMainThread(() -> rxBus.send(new EventPatchActivationNotComplete()));
|
rxAction.runOnMainThread(() -> rxBus.send(new EventPatchActivationNotComplete()));
|
||||||
|
|
|
@ -382,14 +382,6 @@ public class PatchManagerImpl {
|
||||||
if (success) {
|
if (success) {
|
||||||
TaskBase.enqueue(TaskFunc.LOW_RESERVOIR);
|
TaskBase.enqueue(TaskFunc.LOW_RESERVOIR);
|
||||||
TaskBase.enqueue(TaskFunc.INFO_REMINDER);
|
TaskBase.enqueue(TaskFunc.INFO_REMINDER);
|
||||||
pumpSync.connectNewPump(true);
|
|
||||||
pumpSync.insertTherapyEventIfNewWithTimestamp(
|
|
||||||
System.currentTimeMillis(),
|
|
||||||
DetailedBolusInfo.EventType.INSULIN_CHANGE,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
PumpType.EOFLOW_EOPATCH2,
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,6 @@ class EopatchActivity : EoBaseActivity<ActivityEopatchBinding>() {
|
||||||
this@EopatchActivity.finish()
|
this@EopatchActivity.finish()
|
||||||
}
|
}
|
||||||
start()
|
start()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue