Round requested absolute TBR to percent TBR.

This commit is contained in:
Johannes Mockenhaupt 2017-07-15 03:04:25 +02:00
parent a21da8aba7
commit 8e2cd844a5
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -310,15 +310,25 @@ public class ComboPlugin implements PluginBase, PumpInterface {
// till pump times out or raises an error
}
// TODO
@Override
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
return OPERATION_NOT_SUPPORTED;
log.debug("setTempBasalAbsolute called with a rate of " + absoluteRate + " for " + durationInMinutes + " min.");
int unroundedPercentage = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
int roundedPercentage = (int) (Math.round(absoluteRate/ getBaseBasalRate() * 10) * 10);
if (unroundedPercentage != roundedPercentage)
log.debug("Rounded requested rate " + unroundedPercentage + "% -> " + roundedPercentage + "%");
return setTempBasalPercent(roundedPercentage, durationInMinutes);
}
@Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min");
if (percent % 10 != 0) {
int rounded = percent;
while (rounded % 10 != 0) rounded = rounded - 1;
log.debug("Rounded requested percentage from " + percent + " to " + rounded);
percent = rounded;
}
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
CommandResult commandResult = runCommand(new SetTbrCommand(percent, durationInMinutes));
if (commandResult.enacted) {