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.PumpDanaRS.DanaRSPlugin;
import info.nightscout.utils.NumberPicker;
/**
* 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);
Activity activity = this;
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
DanaRPump pump = DanaRPump.getInstance();
//used for debugging
log.debug("UserOptionsLoadedd:"+(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);
DanaRPump pump = DanaRPump.getInstance();
//used for debugging
log.debug("UserOptionsLoadedd:" + (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);
if (pump.timeDisplayType != 0) {
timeFormat.setChecked(false);
}
if (pump.timeDisplayType != 0) {
timeFormat.setChecked(false);
}
if(pump.buttonScrollOnOff != 0) {
buttonScroll.setChecked(true);
}
if (pump.beepAndAlarm != 0) {
beep.setChecked(true);
}
if (pump.buttonScrollOnOff != 0) {
buttonScroll.setChecked(true);
}
if (pump.beepAndAlarm != 0) {
beep.setChecked(true);
}
screenTimeout.setValue((double) pump.lcdOnTimeSec);
screenTimeout.setStep(5d);
screenTimeout.setParams(5d,5d,240d,5d,new DecimalFormat("1"), false);
backlightTimeout.setValue((double) pump.backlightOnTimeSec);
backlightTimeout.setParams(1d,1d,60d,1d,new DecimalFormat("1"), false);
if(pump.lastSettingsRead == 0)
log.debug("No settings loaded from pump!");
if (pump.getUnits() != null) {
if(pump.getUnits().equals(Constants.MMOL)) {
pumpUnits.setChecked(true);
}
}
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);
}
});
screenTimeout.setParams((double) pump.lcdOnTimeSec, 5d, 240d, 5d, new DecimalFormat("1"), false);
backlightTimeout.setParams((double) pump.backlightOnTimeSec, 1d, 60d, 1d, new DecimalFormat("1"), false);
if (pump.lastSettingsRead == 0)
log.debug("No settings loaded from pump!");
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);
}
public void onSaveClick(){
public void onSaveClick() {
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP);
if(!isRS){
if (!isRS) {
//exit if pump is not DanaRS
return;
}
DanaRPump pump = DanaRPump.getInstance();
if(timeFormat.isChecked())
if (timeFormat.isChecked())
pump.timeDisplayType = 1;
else
pump.timeDisplayType = 0;
if(buttonScroll.isChecked())
if (buttonScroll.isChecked())
pump.buttonScrollOnOff = 1;
else
pump.buttonScrollOnOff = 0;
// step is 5 seconds
int screenTimeoutValue = (Integer.parseInt(screenTimeout.getText().toString()) / 5) * 5;
if(screenTimeoutValue > 4 && screenTimeoutValue < 241){
if (screenTimeoutValue > 4 && screenTimeoutValue < 241) {
pump.lcdOnTimeSec = screenTimeoutValue;
} else {
pump.lcdOnTimeSec = 5;
}
int backlightTimeoutValue = Integer.parseInt(backlightTimeout.getText().toString());
if(backlightTimeoutValue > 0 && backlightTimeoutValue < 61){
if (backlightTimeoutValue > 0 && backlightTimeoutValue < 61) {
pump.backlightOnTimeSec = backlightTimeoutValue;
}
if(pumpUnits.isChecked()){
if (pumpUnits.isChecked()) {
pump.units = 1;
} else {
pump.units = 0;
}
int shutDownValue = Integer.parseInt(shutdown.getText().toString());
if(shutDownValue > -1 && shutDownValue < 25 ){
if (shutDownValue > -1 && shutDownValue < 25) {
pump.shutdownHour = shutDownValue;
} else {
pump.shutdownHour = 0;
}
int lowReservoirValue = ( Integer.parseInt(lowReservoir.getText().toString()) *10 )/10;
if(lowReservoirValue > 9 && lowReservoirValue <51){
int lowReservoirValue = (Integer.parseInt(lowReservoir.getText().toString()) * 10) / 10;
if (lowReservoirValue > 9 && lowReservoirValue < 51) {
pump.lowReservoirRate = lowReservoirValue;
} else
pump.lowReservoirRate = 10;
// push new settings to pump
DanaRSPlugin pumpPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class);
if(!pumpPlugin.isConnected())
if (!pumpPlugin.isConnected())
pumpPlugin.connect("UpdateUserOptions");
pumpPlugin.updateUserOptions();
pumpPlugin.disconnect("UpdateUserOprions");