Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public abstract class PebbleDisplayAbstract implements PebbleDisplayInterface {
protected static final int BG_DELTA_KEY = 4;
protected static final int UPLOADER_BATTERY_KEY = 5;
protected static final int NAME_KEY = 6;
protected static final int TBR_KEY = 7;
protected static final int IOB_KEY = 8;

protected static final int NUM_VALUES =(60/5)*24;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.eveningoutpost.dexdrip.UtilityModels.pebble;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;

import com.eveningoutpost.dexdrip.BestGlucose;
import com.eveningoutpost.dexdrip.Models.BgReading;
import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.Models.UserError;
import com.eveningoutpost.dexdrip.Models.UserError.Log;
import com.getpebble.android.kit.PebbleKit;
import com.getpebble.android.kit.util.PebbleDictionary;
Expand All @@ -23,10 +26,18 @@ public class PebbleDisplayStandard extends PebbleDisplayAbstract {

private static double last_time_seen = 0;

private String StatusLine="";


@Override
public void startDeviceCommand() {
sendData();
Handler handler = new Handler();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this delay is for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This delay is necessary to display the latest loop status. AAPS needs some connection and action time for setting treatment data. Without delay, outdated (5min) loop data will be shown on the watchface. The delay time depends on connection speed of pump model. Dana R is faster than Combo and i think 20sec should be enough. For Combo users maybe 30-40sec would be necessary. The best solution would be to send a new packet to the pebble right after the StatusLine has been updated.

handler.postDelayed(new Runnable() {
public void run() {
sendData(); // Actions to do after 30 seconds
}
}, 20000);

}


Expand All @@ -36,7 +47,14 @@ public void receiveData(int transactionId, PebbleDictionary data) {
PebbleWatchSync.lastTransactionId = transactionId;
Log.d(TAG, "Received Query. data: " + data.size() + ". sending ACK and data");
PebbleKit.sendAckToPebble(this.context, transactionId);
sendData();

//Handler handler = new Handler();
//handler.postDelayed(new Runnable() {
// public void run() {
sendData(); // Actions to do after 30 seconds
// }
//}, 30000);

} else {
Log.d(TAG, "receiveData: lastTransactionId is " + String.valueOf(PebbleWatchSync.lastTransactionId) + ", sending NACK");
PebbleKit.sendNackToPebble(this.context, transactionId);
Expand All @@ -50,20 +68,27 @@ private PebbleDictionary buildDictionary() {
Date now = new Date();
int offsetFromUTC = tz.getOffset(now.getTime());

SharedPreferences loopstatus = context.getSharedPreferences("loopstatus", 0);
StatusLine = loopstatus.getString("loopstatus", null);

final String bgDelta = getBgDelta();
final String bgReadingS = getBgReading();
final String slopeOrdinal = getSlopeOrdinal();
final String insulinOnBoard = getIOB();
final String tempBasalRate = getTBR();
//boolean no_signal;

if (use_best_glucose) {
Log.v(TAG, "buildDictionary: slopeOrdinal-" + slopeOrdinal + " bgReading-" + bgReadingS + //
" now-" + (int) now.getTime() / 1000 + " bgTime-" + (int) (dg.timestamp / 1000) + //
" phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta());
" phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta() + //
" IOB-" + getIOB() + " TBR-" + getTBR());
// no_signal = (dg.mssince > Home.stale_data_millis());
} else {
Log.v(TAG, "buildDictionary: slopeOrdinal-" + slopeOrdinal + " bgReading-" + bgReadingS + //
" now-" + (int) now.getTime() / 1000 + " bgTime-" + (int) (this.bgReading.timestamp / 1000) + //
" phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta());
" phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta() + //
" IOB-" + getIOB() + " TBR-" + getTBR());
// no_signal = ((new Date().getTime()) - Home.stale_data_millis() - this.bgReading.timestamp > 0);
}

Expand All @@ -81,6 +106,9 @@ private PebbleDictionary buildDictionary() {

addBatteryStatusToDictionary(dictionary);

dictionary.addString(IOB_KEY, insulinOnBoard);
dictionary.addString(TBR_KEY, tempBasalRate);

return dictionary;
}

Expand Down Expand Up @@ -131,6 +159,41 @@ private void watchdog() {
}
}

public String getIOB() {
String check = StatusLine.replaceAll("[^%]", "");
if ( (StatusLine != null) && (check.length() > 0) ) {
UserError.Log.v("LOOP-STATUS-PEBBLE ", StatusLine);
return StatusLine.substring( (StatusLine.lastIndexOf('%')+2), (StatusLine.lastIndexOf('%')+6));

}
else if ( (StatusLine != null) && (check.length() == 0) ) {
UserError.Log.v("LOOP-STATUS-PEBBLE ", StatusLine);
return StatusLine.substring(0, 4);

}
else return "???";

}


public String getTBR() {
String check = StatusLine.replaceAll("[^%]", "");
if ( (StatusLine != null) && (check.length() > 0) ) {
int index1 = 0, index2 = 4;
UserError.Log.v("LOOP-STATUS-PEBBLE ", StatusLine);
if ( (StatusLine.lastIndexOf('%') == 3) ) index2 = 4;
else if ( (StatusLine.lastIndexOf('%') == 2) ) index2 = 3;
else if ( (StatusLine.lastIndexOf('%') == 1) ) index2 = 2;
return StatusLine.substring(index1, index2);

}
else if ( (StatusLine != null) && (check.length() == 0) )
return "100%";
else
return "???";
}



}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.support.v4.content.WakefulBroadcastReceiver;
Expand All @@ -18,6 +19,7 @@ public class ExternalStatusService extends IntentService{
public static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline";
public static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE";
public static final int MAX_LEN = 40;
public static final String LOOP_STATUS = "loopstatus";
private final static String TAG = ExternalStatusService.class.getSimpleName();

public ExternalStatusService() {
Expand All @@ -44,6 +46,11 @@ protected void onHandleIntent(Intent intent) {
statusline = statusline.substring(0, MAX_LEN);
}

SharedPreferences loopstatus = getSharedPreferences("loopstatus", 0);
SharedPreferences.Editor editor = loopstatus.edit();
editor.putString ("loopstatus", statusline);
editor.commit();

// send to wear
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("wear_sync", false)) {
startWatchUpdaterService(this, WatchUpdaterService.ACTION_SEND_STATUS, TAG, "externalStatusString", "" + statusline);
Expand All @@ -61,4 +68,4 @@ protected void onHandleIntent(Intent intent) {
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
}
}
}