Implement reading basal profile.
This commit is contained in:
parent
971a97a9e3
commit
75855f3f05
2 changed files with 45 additions and 30 deletions
|
@ -7,6 +7,7 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -230,8 +231,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
@Override
|
||||
public boolean isThisProfileSet(Profile profile) {
|
||||
return true;
|
||||
// return pump.basalProfile.equals(convertProfileToComboProfile(profile));
|
||||
return pump.basalProfile.equals(convertProfileToComboProfile(profile));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -284,18 +284,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
*/
|
||||
|
||||
// read basal profile into cache, update pump profile if needed
|
||||
/* not implemented by ruffiscripter
|
||||
if (!pump.initialized) {
|
||||
CommandResult readBasalResult = runCommand("Reading basal profile", 2, ruffyScripter::readBasalProfile);
|
||||
if (!readBasalResult.success) {
|
||||
return;
|
||||
}
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
setNewBasalProfile(profile);
|
||||
|
||||
pump.basalProfile = readBasalResult.basalProfile;
|
||||
}
|
||||
*/
|
||||
|
||||
if (!checkPumpHistory()) {
|
||||
return;
|
||||
|
@ -330,24 +325,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
|
||||
@Override
|
||||
public double getBaseBasalRate() {
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
Double basal = profile.getBasal();
|
||||
log.trace("getBaseBasalrate returning " + basal);
|
||||
return basal;
|
||||
|
||||
/* if (pump.basalProfile == null) {
|
||||
// when to force refresh this?
|
||||
CommandResult result = runCommand("Reading basal profile", new CommandExecution() {
|
||||
@Override
|
||||
public CommandResult execute() {
|
||||
return ruffyScripter.readBasalProfile(1);
|
||||
}
|
||||
});
|
||||
pump.basalProfile = result.basalProfile;
|
||||
// error handling ...
|
||||
}
|
||||
return pump.basalProfile.hourlyRates[Calendar.getInstance().get(Calendar.HOUR_OF_DAY)];
|
||||
*/
|
||||
int currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
|
||||
return pump.basalProfile.hourlyRates[currentHour];
|
||||
}
|
||||
|
||||
private static BolusProgressReporter nullBolusProgressReporter = (state, percent, delivered) -> {
|
||||
|
@ -964,6 +943,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
.tbrHistory(PumpHistoryRequest.FULL)
|
||||
.pumpErrorHistory(PumpHistoryRequest.FULL)
|
||||
.tddHistory(PumpHistoryRequest.FULL));
|
||||
CommandResult commandResult = runCommand("Reading basal profile", 2,
|
||||
ruffyScripter::readBasalProfile);
|
||||
if (commandResult.success) {
|
||||
pump.basalProfile = commandResult.basalProfile;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,14 +1,45 @@
|
|||
package de.jotomo.ruffyscripter.commands;
|
||||
|
||||
import org.monkey.d.ruffy.ruffy.driver.display.MenuAttribute;
|
||||
import org.monkey.d.ruffy.ruffy.driver.display.MenuType;
|
||||
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import de.jotomo.ruffy.spi.BasalProfile;
|
||||
|
||||
public class ReadBasalProfileCommand extends BaseCommand {
|
||||
private static final Logger log = LoggerFactory.getLogger(ReadBasalProfileCommand.class);
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
if (1==1) throw new RuntimeException("No implemented yet");
|
||||
// TODO
|
||||
result.basalProfile(new BasalProfile(new double[] {0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d, 0.5d}));
|
||||
//scripter.returnToRootMenu();
|
||||
result.success = true;
|
||||
scripter.navigateToMenu(MenuType.BASAL_1_MENU);
|
||||
scripter.verifyMenuIsDisplayed(MenuType.BASAL_1_MENU);
|
||||
scripter.pressCheckKey();
|
||||
|
||||
BasalProfile basalProfile = new BasalProfile();
|
||||
|
||||
// summary screen is shown; press menu to page through hours, wraps around to summary;
|
||||
scripter.verifyMenuIsDisplayed(MenuType.BASAL_TOTAL);
|
||||
for (int i = 0; i < 24; i++) {
|
||||
scripter.pressMenuKey();
|
||||
scripter.waitForScreenUpdate();
|
||||
scripter.verifyMenuIsDisplayed(MenuType.BASAL_SET);
|
||||
MenuTime startTime = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.BASAL_START);
|
||||
if (i != startTime.getHour()) {
|
||||
throw new CommandException("Attempting to read basal rate for hour " + i + ", but hour " + startTime.getHour() + " is displayed");
|
||||
}
|
||||
basalProfile.hourlyRates[i] = scripter.readBlinkingValue(Double.class, MenuAttribute.BASAL_RATE);
|
||||
log.debug("Read basal profile, hour " + i + ": " + basalProfile.hourlyRates[i]);
|
||||
}
|
||||
|
||||
log.debug("Basal profile read: " + Arrays.toString(basalProfile.hourlyRates));
|
||||
|
||||
scripter.returnToRootMenu();
|
||||
scripter.verifyRootMenuIsDisplayed();
|
||||
|
||||
result.success(true).basalProfile(basalProfile);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue