Merge pull request #26 from MilosKozak/rsoption

update
This commit is contained in:
Roumen Georgiev 2018-06-07 09:30:22 +03:00 committed by GitHub
commit 4b7f8615bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 162 additions and 146 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,13 +1,15 @@
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;
import android.widget.Switch;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -16,11 +18,15 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.Constants;
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;
/**
* Created by Rumen Georgiev on 5/31/2018.
*/
@ -73,116 +79,99 @@ public class DanaRUserOptionsActivity extends Activity {
lowReservoir = (NumberPicker) 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();
}
});
saveToPumpButton.setOnClickListener(v -> onSaveClick());
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);
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("UserOptionsLoaded:" + (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);
}
screenTimeout.setParams((double) pump.lcdOnTimeSec, 5d, 240d, 5d, new DecimalFormat("1"), false);
backlightTimeout.setParams((double) pump.backlightOnTimeSec, 1d, 60d, 1d, new DecimalFormat("1"), false);
shutdown.setParams((double) pump.shutdownHour, 0d, 24d, 1d, new DecimalFormat("1"), true);
lowReservoir.setParams((double) pump.lowReservoirRate, 10d, 60d, 10d, new DecimalFormat("10"), false);
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);
}
});
if (pump.lastSettingsRead == 0)
log.debug("No settings loaded from pump!");
else
setData();
}
public void onSaveClick(){
public void setData() {
DanaRPump pump = DanaRPump.getInstance();
timeFormat.setChecked(pump.timeDisplayType == 0);
buttonScroll.setChecked(pump.buttonScrollOnOff != 0);
beep.setChecked(pump.beepAndAlarm != 0);
screenTimeout.setValue((double) pump.lcdOnTimeSec);
backlightTimeout.setValue((double) pump.backlightOnTimeSec);
pumpUnits.setChecked(pump.getUnits() != null && pump.getUnits().equals(Constants.MMOL));
shutdown.setValue((double) pump.shutdownHour);
lowReservoir.setValue((double) pump.lowReservoirRate);
}
@Subscribe
public void onEventInitializationChanged(EventInitializationChanged ignored) {
runOnUiThread(this::setData);
}
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())
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

@ -26,9 +26,6 @@ import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ExtendedBolus;
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.Treatments.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
@ -47,8 +44,10 @@ import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange;
import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService;
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -224,6 +223,11 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
return danaRSService.loadEvents();
}
@Override
public PumpEnactResult setUserSettings() {
return danaRSService.setUserSettings();
}
// Constraints interface
@Override
@ -760,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

@ -23,7 +23,7 @@ public class DanaRS_Packet_Option_Set_User_Option extends DanaRS_Packet {
@Override
public byte[] getRequestParams() {
DanaRPump pump = DanaRPump.getInstance();
log.debug("UserOptionsLoadedd4:"+(System.currentTimeMillis() - pump.lastConnection)/1000+" s ago"
log.debug("UserOptions:"+(System.currentTimeMillis() - pump.lastConnection)/1000+" s ago"
+"\ntimeDisplayType:"+pump.timeDisplayType
+"\nbuttonScroll:"+pump.buttonScrollOnOff
+"\ntimeDisplayType:"+pump.timeDisplayType

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,13 @@ public class DanaRSService extends Service {
}
public PumpEnactResult setUserSettings() {
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";
}
}

View file

@ -701,7 +701,7 @@
android:id="@+id/danar_viewprofile"
style="@style/ButtonSmallFontStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/icon_danarprofile"
android:paddingLeft="0dp"
@ -713,7 +713,7 @@
android:id="@+id/danar_history"
style="@style/ButtonSmallFontStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/icon_danarhistory"
android:paddingLeft="0dp"
@ -724,17 +724,18 @@
android:id="@+id/danar_stats"
style="@style/ButtonSmallFontStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/icon_danarstats"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:text="@string/danar_stats" />
<Button
android:id="@+id/danar_user_options"
style="@style/ButtonSmallFontStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/icon_danar_useropt"
android:paddingLeft="0dp"

View file

@ -2,7 +2,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.PumpDanaR.DanaRUserOptions">
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRUserOptionsActivity">
<RelativeLayout
@ -22,6 +24,14 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:text="@string/danar_pump_settings"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<LinearLayout
android:id="@+id/overview_pumpstatuslayout"
android:layout_width="match_parent"
@ -159,42 +169,28 @@
android:text="@string/danar_pumpalarm"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<RadioGroup
android:id="@+id/danar_pumpalarm"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checkedButton="@+id/danar_pumpalarm_sound">
<RadioButton
android:id="@+id/danar_pumpalarm_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/danar_pumpalarm_sound" />
<RadioButton
android:id="@+id/danar_pumpalarm_vibrate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/danar_pumpalarm_vibrate" />
<RadioButton
android:id="@+id/danar_pumpalarm_both"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/danar_pumpalarm_both" />
</RadioGroup>
@ -344,7 +340,6 @@
android:textSize="14sp" />
<info.nightscout.utils.NumberPicker
android:id="@+id/danar_shutdown"
android:layout_width="wrap_content"
@ -395,36 +390,17 @@
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
<Button
android:id="@+id/save_user_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/danar_saveuseroptions" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:background="@color/listdelimiter" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>