push new settings to pump
This commit is contained in:
parent
75dbf71a70
commit
054003460c
4 changed files with 107 additions and 11 deletions
|
@ -1,10 +1,7 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaR.activities;
|
package info.nightscout.androidaps.plugins.PumpDanaR.activities;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
@ -14,7 +11,6 @@ import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -28,6 +24,8 @@ import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
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.androidaps.plugins.PumpDanaRS.services.DanaRSService;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Rumen Georgiev on 5/31/2018.
|
* Created by Rumen Georgiev on 5/31/2018.
|
||||||
|
@ -36,11 +34,6 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
||||||
public class DanaRUserOptionsActivity extends Activity {
|
public class DanaRUserOptionsActivity extends Activity {
|
||||||
private static Logger log = LoggerFactory.getLogger(DanaRUserOptionsActivity.class);
|
private static Logger log = LoggerFactory.getLogger(DanaRUserOptionsActivity.class);
|
||||||
|
|
||||||
private Handler mHandler;
|
|
||||||
private static HandlerThread mHandlerThread;
|
|
||||||
LinearLayoutManager llm;
|
|
||||||
RecyclerView recyclerView;
|
|
||||||
|
|
||||||
Switch timeFormat;
|
Switch timeFormat;
|
||||||
Switch buttonScroll;
|
Switch buttonScroll;
|
||||||
Switch beep;
|
Switch beep;
|
||||||
|
@ -53,7 +46,7 @@ public class DanaRUserOptionsActivity extends Activity {
|
||||||
EditText backlightTimeout;
|
EditText backlightTimeout;
|
||||||
EditText shutdown;
|
EditText shutdown;
|
||||||
EditText lowReservoir;
|
EditText lowReservoir;
|
||||||
|
Button saveToPumpButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
@ -84,6 +77,14 @@ public class DanaRUserOptionsActivity extends Activity {
|
||||||
pumpUnits = (Switch) findViewById(R.id.danar_units);
|
pumpUnits = (Switch) findViewById(R.id.danar_units);
|
||||||
shutdown = (EditText) findViewById(R.id.danar_shutdown);
|
shutdown = (EditText) findViewById(R.id.danar_shutdown);
|
||||||
lowReservoir = (EditText) findViewById(R.id.danar_lowreservoir);
|
lowReservoir = (EditText) findViewById(R.id.danar_lowreservoir);
|
||||||
|
saveToPumpButton = (Button) findViewById(R.id.save_user_options);
|
||||||
|
|
||||||
|
saveToPumpButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
onSaveClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
|
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
|
||||||
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);
|
||||||
|
@ -132,4 +133,56 @@ public class DanaRUserOptionsActivity extends Activity {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onSaveClick(){
|
||||||
|
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP);
|
||||||
|
if(!isRS){
|
||||||
|
//exit if pump is not DanaRS
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
|
||||||
|
if(timeFormat.isChecked())
|
||||||
|
pump.timeDisplayType = 1;
|
||||||
|
else
|
||||||
|
pump.timeDisplayType = 0;
|
||||||
|
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){
|
||||||
|
pump.lcdOnTimeSec = screenTimeoutValue;
|
||||||
|
} else {
|
||||||
|
pump.lcdOnTimeSec = 5;
|
||||||
|
}
|
||||||
|
int backlightTimeoutValue = Integer.parseInt(backlightTimeout.getText().toString());
|
||||||
|
if(backlightTimeoutValue > 0 && backlightTimeoutValue < 61){
|
||||||
|
pump.backlightOnTimeSec = backlightTimeoutValue;
|
||||||
|
}
|
||||||
|
if(pumpUnits.isChecked()){
|
||||||
|
pump.units = 1;
|
||||||
|
} else {
|
||||||
|
pump.units = 0;
|
||||||
|
}
|
||||||
|
int shutDownValue = Integer.parseInt(shutdown.getText().toString());
|
||||||
|
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){
|
||||||
|
pump.lowReservoirRate = lowReservoirValue;
|
||||||
|
} 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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
|
@ -758,4 +759,20 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
public PumpEnactResult loadTDDs() {
|
public PumpEnactResult loadTDDs() {
|
||||||
return loadHistory(RecordTypes.RECORD_TYPE_DAILY);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,14 @@ public class DanaRS_Packet_Option_Set_User_Option extends DanaRS_Packet {
|
||||||
@Override
|
@Override
|
||||||
public byte[] getRequestParams() {
|
public byte[] getRequestParams() {
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
log.debug("UserOptionsLoadedd4:"+(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);
|
||||||
byte[] request = new byte[13];
|
byte[] request = new byte[13];
|
||||||
request[0] = (byte) (pump.timeDisplayType & 0xff);
|
request[0] = (byte) (pump.timeDisplayType & 0xff);
|
||||||
request[1] = (byte) (pump.buttonScrollOnOff & 0xff);
|
request[1] = (byte) (pump.buttonScrollOnOff & 0xff);
|
||||||
|
|
|
@ -71,6 +71,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_D
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Notify_Delivery_Rate_Display;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Get_Pump_Time;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_Pump_Time;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Option_Set_User_Option;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
|
@ -181,6 +182,24 @@ public class DanaRSService extends Service {
|
||||||
log.debug("Pump status loaded");
|
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() {
|
public PumpEnactResult loadEvents() {
|
||||||
DanaRS_Packet_APS_History_Events msg;
|
DanaRS_Packet_APS_History_Events msg;
|
||||||
if (lastHistoryFetched == 0) {
|
if (lastHistoryFetched == 0) {
|
||||||
|
|
Loading…
Reference in a new issue