addd setUserOption to Queue (Dana pumps)

This commit is contained in:
Milos Kozak 2018-06-06 18:29:40 +02:00
parent 6a4bb8a719
commit 04fffae811
10 changed files with 99 additions and 41 deletions

View file

@ -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
}

View file

@ -379,4 +379,9 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
public PumpEnactResult loadEvents() {
return null; // no history, not needed
}
@Override
public PumpEnactResult setUserSettings() {
return null;
}
}

View file

@ -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();
}
}

View file

@ -380,4 +380,9 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
public PumpEnactResult loadEvents() {
return null; // no history, not needed
}
@Override
public PumpEnactResult setUserSettings() {
return null;
}
}

View file

@ -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();
}
}

View file

@ -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;

View file

@ -389,4 +389,9 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
return sExecutionService.loadEvents();
}
@Override
public PumpEnactResult setUserSettings() {
return null;
}
}

View file

@ -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)) {

View file

@ -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;

View file

@ -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";
}
}