combo set basal: account for different granularity > 1 U/h
This commit is contained in:
parent
76cc6199c6
commit
3f10c316a4
3 changed files with 29 additions and 5 deletions
|
@ -44,6 +44,7 @@
|
||||||
- [x] Raise a warning if time clock is off
|
- [x] Raise a warning if time clock is off
|
||||||
- [-] Ruffy: support reading date/time menus
|
- [-] Ruffy: support reading date/time menus
|
||||||
- [ ] Setting pump basal profile
|
- [ ] Setting pump basal profile
|
||||||
|
- [ ] Overview notification on updated/failed basal profile
|
||||||
- [-] Pairing (and sourcing ruffy)
|
- [-] Pairing (and sourcing ruffy)
|
||||||
- [x] Run readReservoirAndBolusLevel after SetTbr too so boluses on the pump are caught sooner?
|
- [x] Run readReservoirAndBolusLevel after SetTbr too so boluses on the pump are caught sooner?
|
||||||
Currently the pump gets to know such a record when bolusing or when refresh() is called
|
Currently the pump gets to know such a record when bolusing or when refresh() is called
|
||||||
|
@ -92,3 +93,4 @@
|
||||||
- Application shut down is broken with PersistentNotification (never shut down) and WearPlugin -
|
- Application shut down is broken with PersistentNotification (never shut down) and WearPlugin -
|
||||||
Android logs it as crashed and restarts it, thereby restarting the app (or just keeping it alive,
|
Android logs it as crashed and restarts it, thereby restarting the app (or just keeping it alive,
|
||||||
also causes errors with the DB as there were attemtps to open a closed DB instance/ref.
|
also causes errors with the DB as there were attemtps to open a closed DB instance/ref.
|
||||||
|
- [ ] Check if TBRs are set to often from ConfigBuilder on high base basal rates (basalstep is 0.01; in reality larger on >1U/h base basal)
|
||||||
|
|
|
@ -245,7 +245,22 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
private BasalProfile convertProfileToComboProfile(Profile profile) {
|
private BasalProfile convertProfileToComboProfile(Profile profile) {
|
||||||
BasalProfile basalProfile = new BasalProfile();
|
BasalProfile basalProfile = new BasalProfile();
|
||||||
for (int i = 0; i < 24; i++) {
|
for (int i = 0; i < 24; i++) {
|
||||||
basalProfile.hourlyRates[i] = profile.getBasal(Integer.valueOf(i * 60 * 60));
|
double rate = profile.getBasal(Integer.valueOf(i * 60 * 60));
|
||||||
|
|
||||||
|
/*The Combo pump does hava a different granularity for basal rate:
|
||||||
|
* 0.01 - if below 1U/h
|
||||||
|
* 0.05 - if above 1U/h
|
||||||
|
* */
|
||||||
|
|
||||||
|
if(rate < 1){
|
||||||
|
//round to 0.01 granularity;
|
||||||
|
rate = Math.round(rate/0.01)*0.01;
|
||||||
|
} else {
|
||||||
|
//round to 0.05 granularity;
|
||||||
|
rate = Math.round(rate/0.05)*0.05;
|
||||||
|
}
|
||||||
|
|
||||||
|
basalProfile.hourlyRates[i] = rate;
|
||||||
}
|
}
|
||||||
return basalProfile;
|
return basalProfile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,7 @@ public class SetBasalProfileCommand extends BaseCommand {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
log.debug("Current rate: " + currentRate + ", requested: " + requestedRate);
|
log.debug("Current rate: " + currentRate + ", requested: " + requestedRate);
|
||||||
double change = requestedRate - currentRate;
|
long steps = stepsUpToOne(currentRate) - stepsUpToOne(requestedRate);
|
||||||
long steps = Math.round(change * 100);
|
|
||||||
boolean increasing = steps > 0;
|
boolean increasing = steps > 0;
|
||||||
log.debug("Pressing " + (increasing ? "up" : "down") + " " + Math.abs(steps) + " times");
|
log.debug("Pressing " + (increasing ? "up" : "down") + " " + Math.abs(steps) + " times");
|
||||||
for (int i = 0; i < Math.abs(steps); i++) {
|
for (int i = 0; i < Math.abs(steps); i++) {
|
||||||
|
@ -95,6 +94,14 @@ public class SetBasalProfileCommand extends BaseCommand {
|
||||||
return increasing;
|
return increasing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Steps UP to 1.0
|
||||||
|
* May return a negative value for steps down*/
|
||||||
|
private long stepsUpToOne(double rate){
|
||||||
|
double change = (1.0-rate);
|
||||||
|
if (rate > 1) return Math.round(change/0.05);
|
||||||
|
return Math.round(change/0.01);
|
||||||
|
}
|
||||||
|
|
||||||
private void verifyDisplayedRate(double requestedRate, boolean increasingPercentage) {
|
private void verifyDisplayedRate(double requestedRate, boolean increasingPercentage) {
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.BASAL_SET);
|
scripter.verifyMenuIsDisplayed(MenuType.BASAL_SET);
|
||||||
// wait up to 5s for any scrolling to finish
|
// wait up to 5s for any scrolling to finish
|
||||||
|
@ -110,7 +117,7 @@ public class SetBasalProfileCommand extends BaseCommand {
|
||||||
displayedRate = scripter.readBlinkingValue(Double.class, MenuAttribute.BASAL_RATE);
|
displayedRate = scripter.readBlinkingValue(Double.class, MenuAttribute.BASAL_RATE);
|
||||||
}
|
}
|
||||||
log.debug("Final displayed basal rate: " + displayedRate);
|
log.debug("Final displayed basal rate: " + displayedRate);
|
||||||
if (displayedRate != requestedRate) {
|
if (Math.abs(displayedRate - requestedRate) > 0.001) {
|
||||||
throw new CommandException("Failed to set basal rate, requested: "
|
throw new CommandException("Failed to set basal rate, requested: "
|
||||||
+ requestedRate + ", actual: " + displayedRate);
|
+ requestedRate + ", actual: " + displayedRate);
|
||||||
}
|
}
|
||||||
|
@ -120,7 +127,7 @@ public class SetBasalProfileCommand extends BaseCommand {
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.BASAL_SET);
|
scripter.verifyMenuIsDisplayed(MenuType.BASAL_SET);
|
||||||
double refreshedDisplayedRate = scripter.readBlinkingValue(Double.class, MenuAttribute.BASAL_RATE);
|
double refreshedDisplayedRate = scripter.readBlinkingValue(Double.class, MenuAttribute.BASAL_RATE);
|
||||||
if (displayedRate != refreshedDisplayedRate) {
|
if (Math.abs(displayedRate - refreshedDisplayedRate) > 0.001) {
|
||||||
throw new CommandException("Failed to set basal rate: " +
|
throw new CommandException("Failed to set basal rate: " +
|
||||||
"percentage changed after input stopped from "
|
"percentage changed after input stopped from "
|
||||||
+ displayedRate + " -> " + refreshedDisplayedRate);
|
+ displayedRate + " -> " + refreshedDisplayedRate);
|
||||||
|
|
Loading…
Reference in a new issue