This commit is contained in:
Milos Kozak 2018-06-06 16:57:00 +02:00
parent 7ef97a5334
commit bbeca6b83e

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
import info.nightscout.utils.NumberPicker; import info.nightscout.utils.NumberPicker;
/** /**
* Created by Rumen Georgiev on 5/31/2018. * Created by Rumen Georgiev on 5/31/2018.
*/ */
@ -84,102 +85,89 @@ public class DanaRUserOptionsActivity extends Activity {
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP); boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP);
Activity activity = this; DanaRPump pump = DanaRPump.getInstance();
if (activity != null) //used for debugging
activity.runOnUiThread(new Runnable() { log.debug("UserOptionsLoadedd:" + (System.currentTimeMillis() - pump.lastConnection) / 1000 + " s ago"
@Override + "\ntimeDisplayType:" + pump.timeDisplayType
public void run() { + "\nbuttonScroll:" + pump.buttonScrollOnOff
DanaRPump pump = DanaRPump.getInstance(); + "\ntimeDisplayType:" + pump.timeDisplayType
//used for debugging + "\nlcdOnTimeSec:" + pump.lcdOnTimeSec
log.debug("UserOptionsLoadedd:"+(System.currentTimeMillis() - pump.lastConnection)/1000+" s ago" + "\nbacklight:" + pump.backlightOnTimeSec
+"\ntimeDisplayType:"+pump.timeDisplayType + "\npumpUnits:" + pump.units
+"\nbuttonScroll:"+pump.buttonScrollOnOff + "\nlowReservoir:" + pump.lowReservoirRate);
+"\ntimeDisplayType:"+pump.timeDisplayType
+"\nlcdOnTimeSec:"+pump.lcdOnTimeSec
+"\nbacklight:"+pump.backlightOnTimeSec
+"\npumpUnits:"+pump.units
+"\nlowReservoir:"+pump.lowReservoirRate);
if (pump.timeDisplayType != 0) { if (pump.timeDisplayType != 0) {
timeFormat.setChecked(false); timeFormat.setChecked(false);
} }
if(pump.buttonScrollOnOff != 0) { if (pump.buttonScrollOnOff != 0) {
buttonScroll.setChecked(true); buttonScroll.setChecked(true);
} }
if (pump.beepAndAlarm != 0) { if (pump.beepAndAlarm != 0) {
beep.setChecked(true); beep.setChecked(true);
} }
screenTimeout.setValue((double) pump.lcdOnTimeSec); screenTimeout.setParams((double) pump.lcdOnTimeSec, 5d, 240d, 5d, new DecimalFormat("1"), false);
screenTimeout.setStep(5d); backlightTimeout.setParams((double) pump.backlightOnTimeSec, 1d, 60d, 1d, new DecimalFormat("1"), false);
screenTimeout.setParams(5d,5d,240d,5d,new DecimalFormat("1"), false); if (pump.lastSettingsRead == 0)
backlightTimeout.setValue((double) pump.backlightOnTimeSec); log.debug("No settings loaded from pump!");
backlightTimeout.setParams(1d,1d,60d,1d,new DecimalFormat("1"), false); if (pump.getUnits() != null) {
if(pump.lastSettingsRead == 0) if (pump.getUnits().equals(Constants.MMOL)) {
log.debug("No settings loaded from pump!"); pumpUnits.setChecked(true);
if (pump.getUnits() != null) { }
if(pump.getUnits().equals(Constants.MMOL)) { }
pumpUnits.setChecked(true); shutdown.setParams((double) pump.shutdownHour, 0d, 24d, 1d, new DecimalFormat("1"), true);
} lowReservoir.setParams((double) pump.lowReservoirRate, 10d, 60d, 10d, new DecimalFormat("10"), false);
}
shutdown.setValue((double) pump.shutdownHour);
shutdown.setParams(0d,0d,24d,1d,new DecimalFormat("1"), true);
lowReservoir.setValue((double) pump.lowReservoirRate);
lowReservoir.setStep(10D);
lowReservoir.setParams(10d,10d,60d,10d,new DecimalFormat("10"), false);
}
});
} }
public void onSaveClick(){ public void onSaveClick() {
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP); boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP);
if(!isRS){ if (!isRS) {
//exit if pump is not DanaRS //exit if pump is not DanaRS
return; return;
} }
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
if(timeFormat.isChecked()) if (timeFormat.isChecked())
pump.timeDisplayType = 1; pump.timeDisplayType = 1;
else else
pump.timeDisplayType = 0; pump.timeDisplayType = 0;
if(buttonScroll.isChecked()) if (buttonScroll.isChecked())
pump.buttonScrollOnOff = 1; pump.buttonScrollOnOff = 1;
else else
pump.buttonScrollOnOff = 0; pump.buttonScrollOnOff = 0;
// step is 5 seconds // step is 5 seconds
int screenTimeoutValue = (Integer.parseInt(screenTimeout.getText().toString()) / 5) * 5; int screenTimeoutValue = (Integer.parseInt(screenTimeout.getText().toString()) / 5) * 5;
if(screenTimeoutValue > 4 && screenTimeoutValue < 241){ if (screenTimeoutValue > 4 && screenTimeoutValue < 241) {
pump.lcdOnTimeSec = screenTimeoutValue; pump.lcdOnTimeSec = screenTimeoutValue;
} else { } else {
pump.lcdOnTimeSec = 5; pump.lcdOnTimeSec = 5;
} }
int backlightTimeoutValue = Integer.parseInt(backlightTimeout.getText().toString()); int backlightTimeoutValue = Integer.parseInt(backlightTimeout.getText().toString());
if(backlightTimeoutValue > 0 && backlightTimeoutValue < 61){ if (backlightTimeoutValue > 0 && backlightTimeoutValue < 61) {
pump.backlightOnTimeSec = backlightTimeoutValue; pump.backlightOnTimeSec = backlightTimeoutValue;
} }
if(pumpUnits.isChecked()){ if (pumpUnits.isChecked()) {
pump.units = 1; pump.units = 1;
} else { } else {
pump.units = 0; pump.units = 0;
} }
int shutDownValue = Integer.parseInt(shutdown.getText().toString()); int shutDownValue = Integer.parseInt(shutdown.getText().toString());
if(shutDownValue > -1 && shutDownValue < 25 ){ if (shutDownValue > -1 && shutDownValue < 25) {
pump.shutdownHour = shutDownValue; pump.shutdownHour = shutDownValue;
} else { } else {
pump.shutdownHour = 0; pump.shutdownHour = 0;
} }
int lowReservoirValue = ( Integer.parseInt(lowReservoir.getText().toString()) *10 )/10; int lowReservoirValue = (Integer.parseInt(lowReservoir.getText().toString()) * 10) / 10;
if(lowReservoirValue > 9 && lowReservoirValue <51){ if (lowReservoirValue > 9 && lowReservoirValue < 51) {
pump.lowReservoirRate = lowReservoirValue; pump.lowReservoirRate = lowReservoirValue;
} else } else
pump.lowReservoirRate = 10; pump.lowReservoirRate = 10;
// push new settings to pump // push new settings to pump
DanaRSPlugin pumpPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class); DanaRSPlugin pumpPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class);
if(!pumpPlugin.isConnected()) if (!pumpPlugin.isConnected())
pumpPlugin.connect("UpdateUserOptions"); pumpPlugin.connect("UpdateUserOptions");
pumpPlugin.updateUserOptions(); pumpPlugin.updateUserOptions();
pumpPlugin.disconnect("UpdateUserOprions"); pumpPlugin.disconnect("UpdateUserOprions");