pump status tweaking

This commit is contained in:
Milos Kozak 2017-02-19 19:15:14 +01:00
parent de124b8e3e
commit 5f4eb1e4c4
21 changed files with 263 additions and 286 deletions

View file

@ -0,0 +1,50 @@
package info.nightscout.androidaps.events;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/**
* Created by mike on 19.02.2017.
*/
public class EventPumpStatusChanged {
public static final int CONNECTING = 0;
public static final int CONNECTED = 1;
public static final int PERFORMING = 2;
public static final int DISCONNECTING = 3;
public static final int DISCONNECTED = 4;
public int sStatus = DISCONNECTED;
public int sSecondsElapsed = 0;
public String sPerfomingAction = "";
public EventPumpStatusChanged(int status) {
sStatus = status;
sSecondsElapsed = 0;
}
public EventPumpStatusChanged(int status, int secondsElapsed) {
sStatus = status;
sSecondsElapsed = secondsElapsed;
}
public EventPumpStatusChanged(String action) {
sStatus = PERFORMING;
sSecondsElapsed = 0;
sPerfomingAction = action;
}
public String textStatus() {
if (sStatus == CONNECTING)
return String.format(MainApp.sResources.getString(R.string.danar_history_connectingfor), sSecondsElapsed);
else if (sStatus == CONNECTED)
return MainApp.sResources.getString(R.string.connected);
else if (sStatus == PERFORMING)
return sPerfomingAction;
else if (sStatus == DISCONNECTING)
return MainApp.sResources.getString(R.string.disconnecting);
else if (sStatus == DISCONNECTED)
return "";
return "";
}
}

View file

@ -29,8 +29,8 @@ public interface PumpInterface {
int setNewBasalProfile(NSProfile profile);
boolean isThisProfileSet(NSProfile profile);
Date lastStatusTime();
void updateStatus(String reason);
Date lastDataTime();
void refreshDataFromPump(String reason);
double getBaseBasalRate(); // base basal rate, not temp basal
double getTempBasalAbsoluteRate();
@ -51,7 +51,9 @@ public interface PumpInterface {
JSONObject getJSONStatus();
String deviceID();
// Pump capabilities
PumpDescription getPumpDescription();
public String shortStatus(boolean veryShort);
// Short info for SMS, Wear etc
String shortStatus(boolean veryShort);
}

View file

@ -390,13 +390,13 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public Date lastStatusTime() {
return activePump.lastStatusTime();
public Date lastDataTime() {
return activePump.lastDataTime();
}
@Override
public void updateStatus(String reason) {
activePump.updateStatus(reason);
public void refreshDataFromPump(String reason) {
activePump.refreshDataFromPump(reason);
}
@Override
@ -682,7 +682,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
public String deviceID() {
if (activePump != null)
return activePump.deviceID();
else return "Unknown";
else return "No Pump active!";
}
@Override

View file

@ -24,12 +24,12 @@ import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.DanaR.Dialogs.ProfileViewDialog;
import info.nightscout.androidaps.plugins.DanaR.History.DanaRHistoryActivity;
import info.nightscout.androidaps.plugins.DanaR.History.DanaRStatsActivity;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -165,18 +165,18 @@ public class DanaRFragment extends Fragment implements FragmentBase {
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {
public void onStatusEvent(final EventPumpStatusChanged c) {
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
if (c.sStatus == EventDanaRConnectionStatus.CONNECTING)
if (c.sStatus == EventPumpStatusChanged.CONNECTING)
btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s");
else if (c.sStatus == EventDanaRConnectionStatus.CONNECTED)
else if (c.sStatus == EventPumpStatusChanged.CONNECTED)
btConnectionView.setText("{fa-bluetooth}");
else
else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED)
btConnectionView.setText("{fa-bluetooth-b}");
}
}

View file

@ -285,12 +285,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
@Override
public Date lastStatusTime() {
public Date lastDataTime() {
return getDanaRPump().lastConnection;
}
@Override
public void updateStatus(String reason) {
public void refreshDataFromPump(String reason) {
if (!isConnected() && !isConnecting()) {
doConnect(reason);
}

View file

@ -38,10 +38,10 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
@ -306,7 +306,7 @@ public class DanaRHistoryActivity extends Activity {
case RecordTypes.RECORD_TYPE_DAILY:
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()+ record.getRecordDailyBasal()) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus() + record.getRecordDailyBasal()) + "U");
holder.time.setText(DateUtil.dateString(record.getRecordDate()));
holder.time.setVisibility(View.VISIBLE);
holder.value.setVisibility(View.GONE);
@ -434,21 +434,12 @@ public class DanaRHistoryActivity extends Activity {
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {
public void onStatusEvent(final EventPumpStatusChanged s) {
runOnUiThread(
new Runnable() {
@Override
public void run() {
if (c.sStatus == EventDanaRConnectionStatus.CONNECTING) {
statusView.setText(String.format(getString(R.string.danar_history_connectingfor), c.sSecondsElapsed));
log.debug("EventDanaRConnectionStatus: " + "Connecting for " + c.sSecondsElapsed + "s");
} else if (c.sStatus == EventDanaRConnectionStatus.CONNECTED) {
statusView.setText(MainApp.sResources.getString(R.string.connected));
log.debug("EventDanaRConnectionStatus: Connected");
} else {
statusView.setText(MainApp.sResources.getString(R.string.disconnected));
log.debug("EventDanaRConnectionStatus: Disconnected");
}
statusView.setText(s.textStatus());
}
}
);

View file

@ -48,12 +48,12 @@ import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.plugins.CircadianPercentageProfile.CircadianPercentageProfilePlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.Services.ExecutionService;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse;
@ -68,11 +68,11 @@ public class DanaRStatsActivity extends Activity {
private Handler mHandler;
private static HandlerThread mHandlerThread;
TextView statusView, statsMessage,totalBaseBasal2;
TextView statusView, statsMessage, totalBaseBasal2;
EditText totalBaseBasal;
Button reloadButton;
LinearLayoutManager llm;
TableLayout tl,ctl,etl;
TableLayout tl, ctl, etl;
String TBB;
double magicNumber;
DecimalFormat decimalFormat;
@ -118,15 +118,15 @@ public class DanaRStatsActivity extends Activity {
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View myView = getCurrentFocus();
if ( myView instanceof EditText) {
if (myView instanceof EditText) {
Rect rect = new Rect();
myView.getGlobalVisibleRect(rect);
if (!rect.contains((int)event.getRawX(), (int)event.getRawY())) {
if (!rect.contains((int) event.getRawX(), (int) event.getRawY())) {
myView.clearFocus();
}
}
}
return super.dispatchTouchEvent( event );
return super.dispatchTouchEvent(event);
}
ServiceConnection mConnection = new ServiceConnection() {
@ -172,11 +172,11 @@ public class DanaRStatsActivity extends Activity {
totalBaseBasal.setText(TBB);
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfile();
if (pi != null && pi instanceof CircadianPercentageProfilePlugin){
double cppTBB = ((CircadianPercentageProfilePlugin)pi).baseBasalSum();
if (pi != null && pi instanceof CircadianPercentageProfilePlugin) {
double cppTBB = ((CircadianPercentageProfilePlugin) pi).baseBasalSum();
totalBaseBasal.setText(decimalFormat.format(cppTBB));
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.putString("TBB", totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
}
@ -312,7 +312,7 @@ public class DanaRStatsActivity extends Activity {
totalBaseBasal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_DONE){
if (actionId == EditorInfo.IME_ACTION_DONE) {
totalBaseBasal.clearFocus();
return true;
}
@ -323,11 +323,11 @@ public class DanaRStatsActivity extends Activity {
totalBaseBasal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
if (hasFocus) {
totalBaseBasal.getText().clear();
} else {
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.putString("TBB", totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
@ -362,15 +362,14 @@ public class DanaRStatsActivity extends Activity {
cleanTable(etl);
DateFormat df = new SimpleDateFormat("dd.MM.");
if(TextUtils.isEmpty(TBB)) {
if (TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal");
return;
}
else {
} else {
magicNumber = SafeParse.stringToDouble(TBB);
}
magicNumber *=2;
magicNumber *= 2;
totalBaseBasal2.setText(decimalFormat.format(magicNumber));
int i = 0;
@ -379,45 +378,45 @@ public class DanaRStatsActivity extends Activity {
double weighted05 = 0d;
double weighted07 = 0d;
for (DanaRHistoryRecord record: historyList) {
double tdd= record.getRecordDailyBolus() + record.getRecordDailyBasal();
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
// Create the table row
TableRow tr = new TableRow(DanaRStatsActivity.this);
if(i%2!=0) tr.setBackgroundColor(Color.DKGRAY);
tr.setId(100+i);
if (i % 2 != 0) tr.setBackgroundColor(Color.DKGRAY);
tr.setId(100 + i);
tr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
TextView labelDATE = new TextView(DanaRStatsActivity.this);
labelDATE.setId(200+i);
labelDATE.setId(200 + i);
labelDATE.setText(df.format(new Date(record.getRecordDate())));
labelDATE.setTextColor(Color.WHITE);
tr.addView(labelDATE);
TextView labelBASAL = new TextView(DanaRStatsActivity.this);
labelBASAL.setId(300+i);
labelBASAL.setId(300 + i);
labelBASAL.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + " U");
labelBASAL.setTextColor(Color.WHITE);
tr.addView(labelBASAL);
TextView labelBOLUS = new TextView(DanaRStatsActivity.this);
labelBOLUS.setId(400+i);
labelBOLUS.setId(400 + i);
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + " U");
labelBOLUS.setTextColor(Color.WHITE);
tr.addView(labelBOLUS);
TextView labelTDD = new TextView(DanaRStatsActivity.this);
labelTDD.setId(500+i);
labelTDD.setId(500 + i);
labelTDD.setText(DecimalFormatter.to2Decimal(tdd) + " U");
labelTDD.setTextColor(Color.WHITE);
tr.addView(labelTDD);
TextView labelRATIO = new TextView(DanaRStatsActivity.this);
labelRATIO.setId(600+i);
labelRATIO.setText(Math.round(100*tdd/magicNumber) +" %");
labelRATIO.setId(600 + i);
labelRATIO.setText(Math.round(100 * tdd / magicNumber) + " %");
labelRATIO.setTextColor(Color.WHITE);
tr.addView(labelRATIO);
@ -431,28 +430,28 @@ public class DanaRStatsActivity extends Activity {
// Create the cumtable row
TableRow ctr = new TableRow(DanaRStatsActivity.this);
if(i%2==0) ctr.setBackgroundColor(Color.DKGRAY);
ctr.setId(700+i);
if (i % 2 == 0) ctr.setBackgroundColor(Color.DKGRAY);
ctr.setId(700 + i);
ctr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
TextView labelDAYS = new TextView(DanaRStatsActivity.this);
labelDAYS.setId(800+i);
labelDAYS.setId(800 + i);
labelDAYS.setText("" + i);
labelDAYS.setTextColor(Color.WHITE);
ctr.addView(labelDAYS);
TextView labelCUMTDD = new TextView(DanaRStatsActivity.this);
labelCUMTDD.setId(900+i);
labelCUMTDD.setText(DecimalFormatter.to2Decimal(sum/i) + " U");
labelCUMTDD.setId(900 + i);
labelCUMTDD.setText(DecimalFormatter.to2Decimal(sum / i) + " U");
labelCUMTDD.setTextColor(Color.WHITE);
ctr.addView(labelCUMTDD);
TextView labelCUMRATIO = new TextView(DanaRStatsActivity.this);
labelCUMRATIO.setId(1000+i);
labelCUMRATIO.setText(Math.round(100*sum/i/magicNumber) + " %");
labelCUMRATIO.setId(1000 + i);
labelCUMRATIO.setText(Math.round(100 * sum / i / magicNumber) + " %");
labelCUMRATIO.setTextColor(Color.WHITE);
ctr.addView(labelCUMRATIO);
@ -462,7 +461,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout.LayoutParams.WRAP_CONTENT));
}
if (historyList.size()<3 || !(df.format(new Date(historyList.get(0).getRecordDate())).equals(df.format(new Date(System.currentTimeMillis() - 1000*60*60*24))))){
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).getRecordDate())).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
statsMessage.setVisibility(View.VISIBLE);
statsMessage.setText(getString(R.string.danar_stats_olddata_Message));
@ -474,38 +473,38 @@ public class DanaRStatsActivity extends Activity {
i = 0;
for (DanaRHistoryRecord record: historyList) {
double tdd= record.getRecordDailyBolus() + record.getRecordDailyBasal();
if(i == 0 ) {
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
if (i == 0) {
weighted03 = tdd;
weighted05 = tdd;
weighted07 = tdd;
} else {
weighted07 = (weighted07*0.3 + tdd*0.7);
weighted05 = (weighted05*0.5 + tdd*0.5);
weighted03 = (weighted03*0.7 + tdd*0.3);
weighted07 = (weighted07 * 0.3 + tdd * 0.7);
weighted05 = (weighted05 * 0.5 + tdd * 0.5);
weighted03 = (weighted03 * 0.7 + tdd * 0.3);
}
i++;
}
// Create the exptable row
TableRow etr = new TableRow(DanaRStatsActivity.this);
if(i%2!=0) etr.setBackgroundColor(Color.DKGRAY);
etr.setId(1100+i);
if (i % 2 != 0) etr.setBackgroundColor(Color.DKGRAY);
etr.setId(1100 + i);
etr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
TextView labelWEIGHT = new TextView(DanaRStatsActivity.this);
labelWEIGHT.setId(1200+i);
labelWEIGHT.setId(1200 + i);
labelWEIGHT.setText("0.3\n" + "0.5\n" + "0.7");
labelWEIGHT.setTextColor(Color.WHITE);
etr.addView(labelWEIGHT);
TextView labelEXPTDD = new TextView(DanaRStatsActivity.this);
labelEXPTDD.setId(1300+i);
labelEXPTDD.setId(1300 + i);
labelEXPTDD.setText(DecimalFormatter.to2Decimal(weighted03)
+ " U\n" + DecimalFormatter.to2Decimal(weighted05)
+ " U\n" + DecimalFormatter.to2Decimal(weighted07) + " U");
@ -513,10 +512,10 @@ public class DanaRStatsActivity extends Activity {
etr.addView(labelEXPTDD);
TextView labelEXPRATIO = new TextView(DanaRStatsActivity.this);
labelEXPRATIO.setId(1400+i);
labelEXPRATIO.setText(Math.round(100*weighted03/magicNumber) +" %\n"
+ Math.round(100*weighted05/magicNumber) +" %\n"
+ Math.round(100*weighted07/magicNumber) +" %");
labelEXPRATIO.setId(1400 + i);
labelEXPRATIO.setText(Math.round(100 * weighted03 / magicNumber) + " %\n"
+ Math.round(100 * weighted05 / magicNumber) + " %\n"
+ Math.round(100 * weighted07 / magicNumber) + " %");
labelEXPRATIO.setTextColor(Color.WHITE);
etr.addView(labelEXPRATIO);
@ -549,21 +548,12 @@ public class DanaRStatsActivity extends Activity {
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {
public void onStatusEvent(final EventPumpStatusChanged c) {
runOnUiThread(
new Runnable() {
@Override
public void run() {
if (c.sStatus == EventDanaRConnectionStatus.CONNECTING) {
statusView.setText(String.format(getString(R.string.danar_history_connectingfor), c.sSecondsElapsed));
log.debug("EventDanaRConnectionStatus: " + "Connecting for " + c.sSecondsElapsed + "s");
} else if (c.sStatus == EventDanaRConnectionStatus.CONNECTED) {
statusView.setText(MainApp.sResources.getString(R.string.connected));
log.debug("EventDanaRConnectionStatus: Connected");
} else {
statusView.setText(MainApp.sResources.getString(R.string.disconnected));
log.debug("EventDanaRConnectionStatus: Disconnected");
}
statusView.setText(c.textStatus());
}
}
);

View file

@ -33,6 +33,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaR.DanaRPump;
@ -77,7 +78,6 @@ import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatusBolusExtended;
import info.nightscout.androidaps.plugins.DanaR.comm.MsgStatusTempBasal;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
@ -117,7 +117,7 @@ public class ExecutionService extends Service {
if (mSerialIOThread != null) {
mSerialIOThread.disconnect("BT disconnection broadcast");
}
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.DISCONNECTED, 0));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
}
}
}
@ -207,7 +207,7 @@ public class ExecutionService extends Service {
long startTime = new Date().getTime();
while (!isConnected() && startTime + maxConnectionTime >= new Date().getTime()) {
long secondsElapsed = (new Date().getTime() - startTime) / 1000L;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.CONNECTING, (int) secondsElapsed));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
if (Config.logDanaBTComm)
log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
try {
@ -226,18 +226,19 @@ public class ExecutionService extends Service {
mSerialIOThread.disconnect("Recreate SerialIOThread");
}
mSerialIOThread = new SerialIOThread(mRfcommSocket);
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.CONNECTED, 0));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0));
if (!getPumpStatus()) {
mSerialIOThread.disconnect("getPumpStatus failed");
waitMsec(3000);
if (!MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PUMP))
return;
getBTSocketForSelectedPump();
startTime = new Date().getTime();
}
}
}
if (!isConnected()) {
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.DISCONNECTED, 0));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
log.error("Pump connection timed out");
}
connectionInProgress = false;
@ -279,7 +280,7 @@ public class ExecutionService extends Service {
private boolean getPumpStatus() {
try {
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.gettingpumpstatus)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
MsgStatus statusMsg = new MsgStatus();
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
@ -356,39 +357,40 @@ public class ExecutionService extends Service {
public boolean tempBasal(int percent, int durationInHours) {
connect("tempBasal");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingtempbasal)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean tempBasalStop() {
connect("tempBasalStop");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingtempbasal)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean extendedBolus(double insulin, int durationInHalfHours) {
connect("extendedBolus");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingextendedbolus)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean extendedBolusStop() {
connect("extendedBolusStop");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingextendedbolus)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
@ -500,7 +502,7 @@ public class ExecutionService extends Service {
public boolean updateBasalsInPump(final NSProfile profile) {
connect("updateBasalsInPump");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.updatingbasalrates)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
double[] basal = buildDanaRProfileRecord(profile);
MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal);
mSerialIOThread.sendMessage(msgSet);
@ -508,7 +510,7 @@ public class ExecutionService extends Service {
mSerialIOThread.sendMessage(msgActivate);
danaRPump.lastSettingsRead = new Date(0); // force read full settings
getPumpStatus();
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}

View file

@ -1,23 +0,0 @@
package info.nightscout.androidaps.plugins.DanaR.events;
public class EventDanaRConnectionStatus {
public static final int CONNECTING = 0;
public static final int CONNECTED = 1;
public static final int DISCONNECTED = 2;
public static final int PERFORMING = 3;
public int sStatus = DISCONNECTED;
public int sSecondsElapsed = 0;
public String sAction = "";
public EventDanaRConnectionStatus(int status, int secondsElapsed) {
sStatus = status;
sSecondsElapsed = secondsElapsed;
}
public EventDanaRConnectionStatus(int status, int secondsElapsed, String action) {
sStatus = status;
sSecondsElapsed = secondsElapsed;
sAction = action;
}
}

View file

@ -24,10 +24,10 @@ import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.DanaR.Dialogs.ProfileViewDialog;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.DanaRKorean.History.DanaRHistoryActivity;
import info.nightscout.androidaps.plugins.DanaRKorean.History.DanaRStatsActivity;
@ -162,18 +162,18 @@ public class DanaRKoreanFragment extends Fragment implements FragmentBase {
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {
public void onStatusEvent(final EventPumpStatusChanged c) {
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
if (c.sStatus == EventDanaRConnectionStatus.CONNECTING)
if (c.sStatus == EventPumpStatusChanged.CONNECTING)
btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s");
else if (c.sStatus == EventDanaRConnectionStatus.CONNECTED)
else if (c.sStatus == EventPumpStatusChanged.CONNECTED)
btConnectionView.setText("{fa-bluetooth}");
else
else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED)
btConnectionView.setText("{fa-bluetooth-b}");
}
}

View file

@ -72,6 +72,8 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
return sDanaRKoreanPump;
}
String textStatus = "";
public DanaRKoreanPlugin() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
useExtendedBoluses = sharedPreferences.getBoolean("danar_useextended", false);
@ -285,12 +287,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
}
@Override
public Date lastStatusTime() {
public Date lastDataTime() {
return getDanaRPump().lastConnection;
}
@Override
public void updateStatus(String reason) {
public void refreshDataFromPump(String reason) {
if (!isConnected() && !isConnecting()) {
doConnect(reason);
}

View file

@ -38,10 +38,10 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.History.DanaRNSHistorySync;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
import info.nightscout.androidaps.plugins.DanaRKorean.Services.ExecutionService;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
@ -305,7 +305,7 @@ public class DanaRHistoryActivity extends Activity {
case RecordTypes.RECORD_TYPE_DAILY:
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()+ record.getRecordDailyBasal()) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus() + record.getRecordDailyBasal()) + "U");
holder.time.setText(DateUtil.dateString(record.getRecordDate()));
holder.time.setVisibility(View.VISIBLE);
holder.value.setVisibility(View.GONE);
@ -433,21 +433,12 @@ public class DanaRHistoryActivity extends Activity {
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {
public void onStatusEvent(final EventPumpStatusChanged c) {
runOnUiThread(
new Runnable() {
@Override
public void run() {
if (c.sStatus == EventDanaRConnectionStatus.CONNECTING) {
statusView.setText(String.format(getString(R.string.danar_history_connectingfor), c.sSecondsElapsed));
log.debug("EventDanaRConnectionStatus: " + "Connecting for " + c.sSecondsElapsed + "s");
} else if (c.sStatus == EventDanaRConnectionStatus.CONNECTED) {
statusView.setText(MainApp.sResources.getString(R.string.connected));
log.debug("EventDanaRConnectionStatus: Connected");
} else {
statusView.setText(MainApp.sResources.getString(R.string.disconnected));
log.debug("EventDanaRConnectionStatus: Disconnected");
}
statusView.setText(c.textStatus());
}
}
);

View file

@ -48,11 +48,11 @@ import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.plugins.CircadianPercentageProfile.CircadianPercentageProfilePlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
import info.nightscout.androidaps.plugins.DanaRKorean.Services.ExecutionService;
import info.nightscout.utils.DecimalFormatter;
@ -68,11 +68,11 @@ public class DanaRStatsActivity extends Activity {
private Handler mHandler;
private static HandlerThread mHandlerThread;
TextView statusView, statsMessage,totalBaseBasal2;
TextView statusView, statsMessage, totalBaseBasal2;
EditText totalBaseBasal;
Button reloadButton;
LinearLayoutManager llm;
TableLayout tl,ctl,etl;
TableLayout tl, ctl, etl;
String TBB;
double magicNumber;
DecimalFormat decimalFormat;
@ -118,15 +118,15 @@ public class DanaRStatsActivity extends Activity {
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View myView = getCurrentFocus();
if ( myView instanceof EditText) {
if (myView instanceof EditText) {
Rect rect = new Rect();
myView.getGlobalVisibleRect(rect);
if (!rect.contains((int)event.getRawX(), (int)event.getRawY())) {
if (!rect.contains((int) event.getRawX(), (int) event.getRawY())) {
myView.clearFocus();
}
}
}
return super.dispatchTouchEvent( event );
return super.dispatchTouchEvent(event);
}
ServiceConnection mConnection = new ServiceConnection() {
@ -172,11 +172,11 @@ public class DanaRStatsActivity extends Activity {
totalBaseBasal.setText(TBB);
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfile();
if (pi != null && pi instanceof CircadianPercentageProfilePlugin){
double cppTBB = ((CircadianPercentageProfilePlugin)pi).baseBasalSum();
if (pi != null && pi instanceof CircadianPercentageProfilePlugin) {
double cppTBB = ((CircadianPercentageProfilePlugin) pi).baseBasalSum();
totalBaseBasal.setText(decimalFormat.format(cppTBB));
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.putString("TBB", totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
}
@ -312,7 +312,7 @@ public class DanaRStatsActivity extends Activity {
totalBaseBasal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_DONE){
if (actionId == EditorInfo.IME_ACTION_DONE) {
totalBaseBasal.clearFocus();
return true;
}
@ -323,11 +323,11 @@ public class DanaRStatsActivity extends Activity {
totalBaseBasal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
if (hasFocus) {
totalBaseBasal.getText().clear();
} else {
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.putString("TBB", totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
@ -362,15 +362,14 @@ public class DanaRStatsActivity extends Activity {
cleanTable(etl);
DateFormat df = new SimpleDateFormat("dd.MM.");
if(TextUtils.isEmpty(TBB)) {
if (TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal");
return;
}
else {
} else {
magicNumber = SafeParse.stringToDouble(TBB);
}
magicNumber *=2;
magicNumber *= 2;
totalBaseBasal2.setText(decimalFormat.format(magicNumber));
int i = 0;
@ -379,45 +378,45 @@ public class DanaRStatsActivity extends Activity {
double weighted05 = 0d;
double weighted07 = 0d;
for (DanaRHistoryRecord record: historyList) {
double tdd= record.getRecordDailyBolus() + record.getRecordDailyBasal();
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
// Create the table row
TableRow tr = new TableRow(DanaRStatsActivity.this);
if(i%2!=0) tr.setBackgroundColor(Color.DKGRAY);
tr.setId(100+i);
if (i % 2 != 0) tr.setBackgroundColor(Color.DKGRAY);
tr.setId(100 + i);
tr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
TextView labelDATE = new TextView(DanaRStatsActivity.this);
labelDATE.setId(200+i);
labelDATE.setId(200 + i);
labelDATE.setText(df.format(new Date(record.getRecordDate())));
labelDATE.setTextColor(Color.WHITE);
tr.addView(labelDATE);
TextView labelBASAL = new TextView(DanaRStatsActivity.this);
labelBASAL.setId(300+i);
labelBASAL.setId(300 + i);
labelBASAL.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + " U");
labelBASAL.setTextColor(Color.WHITE);
tr.addView(labelBASAL);
TextView labelBOLUS = new TextView(DanaRStatsActivity.this);
labelBOLUS.setId(400+i);
labelBOLUS.setId(400 + i);
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + " U");
labelBOLUS.setTextColor(Color.WHITE);
tr.addView(labelBOLUS);
TextView labelTDD = new TextView(DanaRStatsActivity.this);
labelTDD.setId(500+i);
labelTDD.setId(500 + i);
labelTDD.setText(DecimalFormatter.to2Decimal(tdd) + " U");
labelTDD.setTextColor(Color.WHITE);
tr.addView(labelTDD);
TextView labelRATIO = new TextView(DanaRStatsActivity.this);
labelRATIO.setId(600+i);
labelRATIO.setText(Math.round(100*tdd/magicNumber) +" %");
labelRATIO.setId(600 + i);
labelRATIO.setText(Math.round(100 * tdd / magicNumber) + " %");
labelRATIO.setTextColor(Color.WHITE);
tr.addView(labelRATIO);
@ -431,28 +430,28 @@ public class DanaRStatsActivity extends Activity {
// Create the cumtable row
TableRow ctr = new TableRow(DanaRStatsActivity.this);
if(i%2==0) ctr.setBackgroundColor(Color.DKGRAY);
ctr.setId(700+i);
if (i % 2 == 0) ctr.setBackgroundColor(Color.DKGRAY);
ctr.setId(700 + i);
ctr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
TextView labelDAYS = new TextView(DanaRStatsActivity.this);
labelDAYS.setId(800+i);
labelDAYS.setId(800 + i);
labelDAYS.setText("" + i);
labelDAYS.setTextColor(Color.WHITE);
ctr.addView(labelDAYS);
TextView labelCUMTDD = new TextView(DanaRStatsActivity.this);
labelCUMTDD.setId(900+i);
labelCUMTDD.setText(DecimalFormatter.to2Decimal(sum/i) + " U");
labelCUMTDD.setId(900 + i);
labelCUMTDD.setText(DecimalFormatter.to2Decimal(sum / i) + " U");
labelCUMTDD.setTextColor(Color.WHITE);
ctr.addView(labelCUMTDD);
TextView labelCUMRATIO = new TextView(DanaRStatsActivity.this);
labelCUMRATIO.setId(1000+i);
labelCUMRATIO.setText(Math.round(100*sum/i/magicNumber) + " %");
labelCUMRATIO.setId(1000 + i);
labelCUMRATIO.setText(Math.round(100 * sum / i / magicNumber) + " %");
labelCUMRATIO.setTextColor(Color.WHITE);
ctr.addView(labelCUMRATIO);
@ -462,7 +461,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout.LayoutParams.WRAP_CONTENT));
}
if (historyList.size()<3 || !(df.format(new Date(historyList.get(0).getRecordDate())).equals(df.format(new Date(System.currentTimeMillis() - 1000*60*60*24))))){
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).getRecordDate())).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
statsMessage.setVisibility(View.VISIBLE);
statsMessage.setText(getString(R.string.danar_stats_olddata_Message));
@ -474,38 +473,38 @@ public class DanaRStatsActivity extends Activity {
i = 0;
for (DanaRHistoryRecord record: historyList) {
double tdd= record.getRecordDailyBolus() + record.getRecordDailyBasal();
if(i == 0 ) {
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
if (i == 0) {
weighted03 = tdd;
weighted05 = tdd;
weighted07 = tdd;
} else {
weighted07 = (weighted07*0.3 + tdd*0.7);
weighted05 = (weighted05*0.5 + tdd*0.5);
weighted03 = (weighted03*0.7 + tdd*0.3);
weighted07 = (weighted07 * 0.3 + tdd * 0.7);
weighted05 = (weighted05 * 0.5 + tdd * 0.5);
weighted03 = (weighted03 * 0.7 + tdd * 0.3);
}
i++;
}
// Create the exptable row
TableRow etr = new TableRow(DanaRStatsActivity.this);
if(i%2!=0) etr.setBackgroundColor(Color.DKGRAY);
etr.setId(1100+i);
if (i % 2 != 0) etr.setBackgroundColor(Color.DKGRAY);
etr.setId(1100 + i);
etr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
TextView labelWEIGHT = new TextView(DanaRStatsActivity.this);
labelWEIGHT.setId(1200+i);
labelWEIGHT.setId(1200 + i);
labelWEIGHT.setText("0.3\n" + "0.5\n" + "0.7");
labelWEIGHT.setTextColor(Color.WHITE);
etr.addView(labelWEIGHT);
TextView labelEXPTDD = new TextView(DanaRStatsActivity.this);
labelEXPTDD.setId(1300+i);
labelEXPTDD.setId(1300 + i);
labelEXPTDD.setText(DecimalFormatter.to2Decimal(weighted03)
+ " U\n" + DecimalFormatter.to2Decimal(weighted05)
+ " U\n" + DecimalFormatter.to2Decimal(weighted07) + " U");
@ -513,10 +512,10 @@ public class DanaRStatsActivity extends Activity {
etr.addView(labelEXPTDD);
TextView labelEXPRATIO = new TextView(DanaRStatsActivity.this);
labelEXPRATIO.setId(1400+i);
labelEXPRATIO.setText(Math.round(100*weighted03/magicNumber) +" %\n"
+ Math.round(100*weighted05/magicNumber) +" %\n"
+ Math.round(100*weighted07/magicNumber) +" %");
labelEXPRATIO.setId(1400 + i);
labelEXPRATIO.setText(Math.round(100 * weighted03 / magicNumber) + " %\n"
+ Math.round(100 * weighted05 / magicNumber) + " %\n"
+ Math.round(100 * weighted07 / magicNumber) + " %");
labelEXPRATIO.setTextColor(Color.WHITE);
etr.addView(labelEXPRATIO);
@ -549,21 +548,12 @@ public class DanaRStatsActivity extends Activity {
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {
public void onStatusEvent(final EventPumpStatusChanged c) {
runOnUiThread(
new Runnable() {
@Override
public void run() {
if (c.sStatus == EventDanaRConnectionStatus.CONNECTING) {
statusView.setText(String.format(getString(R.string.danar_history_connectingfor), c.sSecondsElapsed));
log.debug("EventDanaRConnectionStatus: " + "Connecting for " + c.sSecondsElapsed + "s");
} else if (c.sStatus == EventDanaRConnectionStatus.CONNECTED) {
statusView.setText(MainApp.sResources.getString(R.string.connected));
log.debug("EventDanaRConnectionStatus: Connected");
} else {
statusView.setText(MainApp.sResources.getString(R.string.disconnected));
log.debug("EventDanaRConnectionStatus: Disconnected");
}
statusView.setText(c.textStatus());
}
}
);

View file

@ -31,6 +31,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.DanaR.comm.MsgBolusProgress;
@ -57,7 +58,6 @@ import info.nightscout.androidaps.plugins.DanaR.comm.MsgSetTempBasalStop;
import info.nightscout.androidaps.plugins.DanaR.comm.MsgSetTime;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPump;
@ -110,7 +110,7 @@ public class ExecutionService extends Service {
if (mSerialIOThread != null) {
mSerialIOThread.disconnect("BT disconnection broadcast");
}
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.DISCONNECTED, 0));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
}
}
}
@ -200,7 +200,7 @@ public class ExecutionService extends Service {
long startTime = new Date().getTime();
while (!isConnected() && startTime + maxConnectionTime >= new Date().getTime()) {
long secondsElapsed = (new Date().getTime() - startTime) / 1000L;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.CONNECTING, (int) secondsElapsed));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTING, (int) secondsElapsed));
if (Config.logDanaBTComm)
log.debug("connect waiting " + secondsElapsed + "sec from: " + from);
try {
@ -219,18 +219,19 @@ public class ExecutionService extends Service {
mSerialIOThread.disconnect("Recreate SerialIOThread");
}
mSerialIOThread = new SerialIOThread(mRfcommSocket);
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.CONNECTED, 0));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED));
if (!getPumpStatus()) {
mSerialIOThread.disconnect("getPumpStatus failed");
waitMsec(3000);
if (!MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP))
return;
getBTSocketForSelectedPump();
startTime = new Date().getTime();
}
}
}
if (!isConnected()) {
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.DISCONNECTED, 0));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
log.error("Pump connection timed out");
}
connectionInProgress = false;
@ -272,7 +273,7 @@ public class ExecutionService extends Service {
private boolean getPumpStatus() {
try {
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.gettingpumpstatus)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.gettingpumpstatus)));
//MsgStatus statusMsg = new MsgStatus();
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
@ -347,40 +348,40 @@ public class ExecutionService extends Service {
public boolean tempBasal(int percent, int durationInHours) {
connect("tempBasal");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingtempbasal)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean tempBasalStop() {
connect("tempBasalStop");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingtempbasal)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean extendedBolus(double insulin, int durationInHalfHours) {
connect("extendedBolus");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.settingextendedbolus)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
public boolean extendedBolusStop() {
connect("extendedBolusStop");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.stoppingextendedbolus)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.stoppingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}
@ -493,13 +494,13 @@ public class ExecutionService extends Service {
public boolean updateBasalsInPump(final NSProfile profile) {
connect("updateBasalsInPump");
if (!isConnected()) return false;
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.updatingbasalrates)));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.updatingbasalrates)));
double[] basal = buildDanaRProfileRecord(profile);
MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal);
mSerialIOThread.sendMessage(msgSet);
danaRKoreanPump.lastSettingsRead = new Date(0); // force read full settings
getPumpStatus();
MainApp.bus().post(new EventDanaRConnectionStatus(EventDanaRConnectionStatus.PERFORMING, 0, MainApp.sResources.getString(R.string.disconnecting)));
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return true;
}

View file

@ -143,12 +143,12 @@ public class MDIPlugin implements PluginBase, PumpInterface {
}
@Override
public Date lastStatusTime() {
public Date lastDataTime() {
return new Date();
}
@Override
public void updateStatus(String reason) {
public void refreshDataFromPump(String reason) {
// do nothing
}

View file

@ -18,10 +18,10 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
public class BolusProgressDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(BolusProgressDialog.class);
@ -46,7 +46,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
bolusEnded = false;
}
public void setHelperActivity(BolusProgressHelperActivity activity){
public void setHelperActivity(BolusProgressHelperActivity activity) {
this.helperActivity = activity;
}
@ -77,9 +77,9 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
}
@Override
public void dismiss(){
public void dismiss() {
super.dismiss();
if (helperActivity!= null){
if (helperActivity != null) {
helperActivity.finish();
}
}
@ -128,7 +128,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus c) {
public void onStatusEvent(final EventPumpStatusChanged c) {
Activity activity = getActivity();
if (activity != null) {
@ -136,14 +136,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
new Runnable() {
@Override
public void run() {
if (c.sStatus == c.CONNECTING) {
statusView.setText(String.format(MainApp.sResources.getString(R.string.danar_history_connectingfor), c.sSecondsElapsed));
} else if (c.sStatus == c.CONNECTED) {
statusView.setText(MainApp.sResources.getString(R.string.connected));
} else {
statusView.setText(MainApp.sResources.getString(R.string.disconnected));
if (started) scheduleDismiss();
}
statusView.setText(c.textStatus());
}
}
);

View file

@ -63,6 +63,7 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
@ -71,7 +72,6 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
@ -93,7 +93,6 @@ import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;
import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
public class OverviewFragment extends Fragment {
@ -118,6 +117,8 @@ public class OverviewFragment extends Fragment {
TextView apsModeView;
TextView tempTargetView;
TextView pumpStatusView;
LinearLayout loopStatusLayout;
LinearLayout pumpStatusLayout;
GraphView bgGraph;
CheckBox showPredictionView;
@ -162,7 +163,9 @@ public class OverviewFragment extends Fragment {
baseBasalView = (TextView) view.findViewById(R.id.overview_basebasal);
basalLayout = (LinearLayout) view.findViewById(R.id.overview_basallayout);
activeProfileView = (TextView) view.findViewById(R.id.overview_activeprofile);
pumpStatusView = (TextView) view.findViewById(R.id.overview_initializing);
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
loopStatusLayout = (LinearLayout) view.findViewById(R.id.overview_looplayout);
pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
iobView = (TextView) view.findViewById(R.id.overview_iob);
apsModeView = (TextView) view.findViewById(R.id.overview_apsmode);
@ -295,7 +298,7 @@ public class OverviewFragment extends Fragment {
sHandler.post(new Runnable() {
@Override
public void run() {
MainApp.getConfigBuilder().updateStatus("RefreshClicked");
MainApp.getConfigBuilder().refreshDataFromPump("RefreshClicked");
}
});
}
@ -320,7 +323,7 @@ public class OverviewFragment extends Fragment {
final JSONObject boluscalcJSON = new JSONObject();
try {
boluscalcJSON.put("eventTime", DateUtil.toISOString(new Date()));
boluscalcJSON.put("eventTime", DateUtil.toISOString(new Date()));
boluscalcJSON.put("targetBGLow", wizard.targetBGLow);
boluscalcJSON.put("targetBGHigh", wizard.targetBGHigh);
boluscalcJSON.put("isf", wizard.sens);
@ -477,18 +480,13 @@ public class OverviewFragment extends Fragment {
}
@Subscribe
public void onStatusEvent(final EventDanaRConnectionStatus s) {
public void onStatusEvent(final EventPumpStatusChanged s) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (s.sStatus == EventDanaRConnectionStatus.CONNECTING)
updatePumpStatus(String.format(getString(R.string.danar_history_connectingfor), s.sSecondsElapsed));
else if (s.sStatus == EventDanaRConnectionStatus.PERFORMING)
updatePumpStatus(s.sAction);
else if (s.sStatus == EventDanaRConnectionStatus.DISCONNECTED)
updatePumpStatus(null);
updatePumpStatus(s.textStatus());
}
});
}
@ -517,30 +515,15 @@ public class OverviewFragment extends Fragment {
private void updatePumpStatus(String status) {
PumpInterface pump = MainApp.getConfigBuilder();
if (status != null) {
if (!status.equals("")) {
pumpStatusView.setText(status);
pumpStatusView.setVisibility(View.VISIBLE);
} else if (pump.isBusy()) {
pumpStatusView.setText(R.string.pumpbusy);
pumpStatusView.setVisibility(View.VISIBLE);
} else if (pump.isSuspended()) {
// disable all treatment buttons because we are not able to check constraints without profile
wizardButton.setVisibility(View.INVISIBLE);
treatmentButton.setVisibility(View.INVISIBLE);
quickWizardButton.setVisibility(View.INVISIBLE);
pumpStatusView.setText(R.string.pumpsuspendedclicktorefresh);
pumpStatusView.setVisibility(View.VISIBLE);
} else if (!pump.isInitialized()) {
// disable all treatment buttons because we are not able to check constraints without profile
wizardButton.setVisibility(View.INVISIBLE);
treatmentButton.setVisibility(View.INVISIBLE);
quickWizardButton.setVisibility(View.INVISIBLE);
pumpStatusView.setText(R.string.waitingforpumpclicktorefresh);
pumpStatusView.setVisibility(View.VISIBLE);
pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE);
} else {
wizardButton.setVisibility(View.VISIBLE);
treatmentButton.setVisibility(View.VISIBLE);
pumpStatusView.setVisibility(View.GONE);
pumpStatusLayout.setVisibility(View.GONE);
loopStatusLayout.setVisibility(View.VISIBLE);
}
}
@ -552,10 +535,12 @@ public class OverviewFragment extends Fragment {
if (MainApp.getConfigBuilder() == null || MainApp.getConfigBuilder().getActiveProfile() == null || MainApp.getConfigBuilder().getActiveProfile().getProfile() == null) {// app not initialized yet
pumpStatusView.setText(R.string.noprofileset);
pumpStatusView.setVisibility(View.VISIBLE);
pumpStatusLayout.setVisibility(View.VISIBLE);
loopStatusLayout.setVisibility(View.GONE);
return;
} else {
pumpStatusView.setVisibility(View.GONE);
pumpStatusLayout.setVisibility(View.GONE);
loopStatusLayout.setVisibility(View.VISIBLE);
}
// Skip if not initialized yet
@ -1003,7 +988,7 @@ public class OverviewFragment extends Fragment {
bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(ContextCompat.getColor(MainApp.instance(), R.color.background_material_dark)); // same color as backround = hide
}
updatePumpStatus(null);
//updatePumpStatus(null);
}
//Notifications

View file

@ -158,12 +158,12 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
}
@Override
public Date lastStatusTime() {
public Date lastDataTime() {
return new Date();
}
@Override
public void updateStatus(String reason) {
public void refreshDataFromPump(String reason) {
// do nothing
}

View file

@ -39,7 +39,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
boolean isBasalOutdated = false;
boolean isStatusOutdated = false;
Date lastConnection = pump.lastStatusTime();
Date lastConnection = pump.lastDataTime();
if (lastConnection.getTime() + 30 * 60 * 1000L < new Date().getTime())
isStatusOutdated = true;
if (Math.abs(profile.getBasal(NSProfile.secondsFromMidnight()) - pump.getBaseBasalRate()) > pump.getPumpDescription().basalStep)
@ -58,7 +58,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
pump.updateStatus("KeepAlive. Status outdated.");
pump.refreshDataFromPump("KeepAlive. Status outdated.");
}
});
t.start();
@ -66,7 +66,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
pump.updateStatus("KeepAlive. Basal outdated.");
pump.refreshDataFromPump("KeepAlive. Basal outdated.");
}
});
t.start();

View file

@ -21,6 +21,7 @@
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:id="@+id/overview_looplayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
@ -32,13 +33,13 @@
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="0.1"
android:background="@drawable/loopmodeborder"
android:gravity="center_vertical|center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Open Loop"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="0.1" />
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
@ -62,38 +63,40 @@
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp"
android:layout_weight="0.2"
android:background="@drawable/temptargetborder"
android:gravity="center_vertical|center_horizontal"
android:text="TempTarget"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="TempTarget"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/mdtp_white"
android:layout_weight="0.2" />
android:textColor="@color/mdtp_white" />
</LinearLayout>
<LinearLayout
android:id="@+id/overview_pumpstatuslayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="2dp">
<TextView
android:id="@+id/overview_initializing"
android:id="@+id/overview_pumpstatus"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/initializingborder"
android:gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/initializing"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="10dp" />
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/overview_bg"

View file

@ -3,7 +3,7 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorInitializingBorder">#ff2630</color>
<color name="colorInitializingBorder">#00695c</color>
<color name="cardColorBackground">#121212</color>
<color name="cardObjectiveText">#779ECB</color>