diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java index 1c5ee83834..a3e26c96d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/DanaRInterface.java @@ -9,4 +9,5 @@ import info.nightscout.androidaps.data.PumpEnactResult; public interface DanaRInterface { PumpEnactResult loadHistory(byte type); // for history browser PumpEnactResult loadEvents(); // events history to build treatments from + PumpEnactResult setUserSettings(); // like AnyDana does } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 279a93340f..c2143ad9ec 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -379,4 +379,9 @@ public class DanaRPlugin extends AbstractDanaRPlugin { public PumpEnactResult loadEvents() { return null; // no history, not needed } + + @Override + public PumpEnactResult setUserSettings() { + return null; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java index e3e2bb2dcd..31b7d22147 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java @@ -1,8 +1,8 @@ package info.nightscout.androidaps.plugins.PumpDanaR.activities; import android.app.Activity; +import android.content.Intent; import android.os.Bundle; -import android.view.View; import android.widget.Button; import android.widget.RadioButton; import android.widget.RadioGroup; @@ -20,9 +20,11 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; +import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.NumberPicker; /** @@ -168,12 +170,8 @@ public class DanaRUserOptionsActivity extends Activity { } else pump.lowReservoirRate = 10; - // push new settings to pump - DanaRSPlugin pumpPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class); - if (!pumpPlugin.isConnected()) - pumpPlugin.connect("UpdateUserOptions"); - pumpPlugin.updateUserOptions(); - pumpPlugin.disconnect("UpdateUserOprions"); + MainApp.getConfigBuilder().getCommandQueue().setUserSettings(null); + finish(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 092febec61..59430b8793 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -380,4 +380,9 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { public PumpEnactResult loadEvents() { return null; // no history, not needed } + + @Override + public PumpEnactResult setUserSettings() { + return null; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 6048b04dc9..299d06503e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -223,6 +223,11 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return danaRSService.loadEvents(); } + @Override + public PumpEnactResult setUserSettings() { + return danaRSService.setUserSettings(); + } + // Constraints interface @Override @@ -759,19 +764,4 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return loadHistory(RecordTypes.RECORD_TYPE_DAILY); } - public void updateUserOptions() { - if (danaRSService == null) { - log.error("updateUserOptions sExecutionService is null"); - return; - } - log.debug("UserOptionsLoadedd2:"+(System.currentTimeMillis() - pump.lastConnection)/1000+" s ago" - +"\ntimeDisplayType:"+pump.timeDisplayType - +"\nbuttonScroll:"+pump.buttonScrollOnOff - +"\ntimeDisplayType:"+pump.timeDisplayType - +"\nlcdOnTimeSec:"+pump.lcdOnTimeSec - +"\nbacklight:"+pump.backlightOnTimeSec - +"\npumpUnits:"+pump.units - +"\nlowReservoir:"+pump.lowReservoirRate); - danaRSService.updateUserOptions(); - } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index 5e6b641db6..51f67cbac6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -182,24 +182,6 @@ public class DanaRSService extends Service { log.debug("Pump status loaded"); } - public void updateUserOptions() { - try { - DanaRPump pump = DanaRPump.getInstance(); - log.debug("UserOptionsLoadedd3:"+(System.currentTimeMillis() - pump.lastConnection)/1000+" s ago" - +"\ntimeDisplayType:"+pump.timeDisplayType - +"\nbuttonScroll:"+pump.buttonScrollOnOff - +"\ntimeDisplayType:"+pump.timeDisplayType - +"\nlcdOnTimeSec:"+pump.lcdOnTimeSec - +"\nbacklight:"+pump.backlightOnTimeSec - +"\npumpUnits:"+pump.units - +"\nlowReservoir:"+pump.lowReservoirRate); - //bleComm.sendMessage(new DanaRS_Packet_Option_Set_User_Option()); - } catch (Exception e) { - log.error("Unhandled exception", e); - } - log.debug("User options updates"); - } - public PumpEnactResult loadEvents() { DanaRS_Packet_APS_History_Events msg; if (lastHistoryFetched == 0) { @@ -223,6 +205,22 @@ public class DanaRSService extends Service { } + public PumpEnactResult setUserSettings() { + DanaRPump pump = DanaRPump.getInstance(); + log.debug("setUserSettings:"+(System.currentTimeMillis() - pump.lastConnection)/1000+" s ago" + +"\ntimeDisplayType:"+pump.timeDisplayType + +"\nbuttonScroll:"+pump.buttonScrollOnOff + +"\ntimeDisplayType:"+pump.timeDisplayType + +"\nlcdOnTimeSec:"+pump.lcdOnTimeSec + +"\nbacklight:"+pump.backlightOnTimeSec + +"\npumpUnits:"+pump.units + +"\nlowReservoir:"+pump.lowReservoirRate); + bleComm.sendMessage(new DanaRS_Packet_Option_Set_User_Option()); + bleComm.sendMessage(new DanaRS_Packet_Option_Get_User_Option()); + return new PumpEnactResult().success(true); + } + + public boolean bolus(final double insulin, int carbs, long carbtime, Treatment t) { if (!isConnected()) return false; if (BolusProgressDialog.stopPressed) return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 7c13707949..0d50e74a51 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -389,4 +389,9 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { return sExecutionService.loadEvents(); } + @Override + public PumpEnactResult setUserSettings() { + return null; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index cc28eb28a0..f76e6044aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -37,6 +37,7 @@ import info.nightscout.androidaps.queue.commands.CommandLoadTDDs; import info.nightscout.androidaps.queue.commands.CommandReadStatus; import info.nightscout.androidaps.queue.commands.CommandSMBBolus; import info.nightscout.androidaps.queue.commands.CommandSetProfile; +import info.nightscout.androidaps.queue.commands.CommandSetUserSettings; import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute; import info.nightscout.androidaps.queue.commands.CommandTempBasalPercent; @@ -403,6 +404,25 @@ public class CommandQueue { return true; } + // returns true if command is queued + public boolean setUserSettings(Callback callback) { + if (isRunning(Command.CommandType.SETUSERSETTINGS)) { + if (callback != null) + callback.result(executingNowError()).run(); + return false; + } + + // remove all unfinished + removeAll(Command.CommandType.SETUSERSETTINGS); + + // add new command to queue + add(new CommandSetUserSettings(callback)); + + notifyAboutNewCommand(); + + return true; + } + // returns true if command is queued public boolean loadTDDs(Callback callback) { if (isRunning(Command.CommandType.LOADHISTORY)) { diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java index b865fac86e..7156a72f25 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java @@ -18,7 +18,8 @@ public abstract class Command { BASALPROFILE, READSTATUS, LOADHISTORY, // TDDs and so far only Dana specific - LOADEVENTS // so far only Dana specific + LOADEVENTS, // so far only Dana specific + SETUSERSETTINGS // so far only Dana specific } public CommandType commandType; diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.java new file mode 100644 index 0000000000..cad3fe379c --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.java @@ -0,0 +1,35 @@ +package info.nightscout.androidaps.queue.commands; + +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.interfaces.DanaRInterface; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.queue.Callback; + +/** + * Created by mike on 10.11.2017. + */ + +public class CommandSetUserSettings extends Command { + + public CommandSetUserSettings(Callback callback) { + commandType = CommandType.SETUSERSETTINGS; + this.callback = callback; + } + + @Override + public void execute() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + if (pump instanceof DanaRInterface) { + DanaRInterface danaPump = (DanaRInterface) pump; + PumpEnactResult r = danaPump.setUserSettings(); + if (callback != null) + callback.result(r).run(); + } + } + + @Override + public String status() { + return "SETUSERSETTINGS"; + } +}