Skip to content

Commit

Permalink
Merge pull request #2294 from bigdigital/add_simulated_iob_to_broadca…
Browse files Browse the repository at this point in the history
…stservice

Add predicted iob data to broadcastservice
  • Loading branch information
jamorham authored Mar 28, 2023
2 parents 3254cca + bb52610 commit 4e5abd9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public synchronized void Snooze(Context ctx, int repeatTime) {
&& Pref.getBooleanDefaultFalse("pref_amazfit_BG_alert_enable_key")) {
Amazfitservice.start("xDrip_AlarmCancel");
}

BroadcastEntry.cancelAlert();
}

public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public static void sendLatestBG() {
}
}

public static void cancelAlert() {
if (isEnabled()) {
JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_CANCEL_ALERT);
}
}

public static void sendAlert(String type, String message) {
if (isEnabled()) {
Inevitable.task("broadcast-service-send-alert", 100, () -> JoH.startService(BroadcastService.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.eveningoutpost.dexdrip.UtilityModels.Pref;
import com.eveningoutpost.dexdrip.UtilityModels.PumpStatus;
import com.eveningoutpost.dexdrip.stats.StatsResult;
import com.eveningoutpost.dexdrip.store.FastStore;
import com.eveningoutpost.dexdrip.store.KeyStore;
import com.eveningoutpost.dexdrip.utils.PowerStateReceiver;
import com.eveningoutpost.dexdrip.services.broadcastservice.models.BroadcastModel;
import com.eveningoutpost.dexdrip.services.broadcastservice.models.GraphLine;
Expand All @@ -45,6 +47,10 @@

import static com.eveningoutpost.dexdrip.UtilityModels.Constants.DAY_IN_MS;

// External status line from AAPS added
import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLine;
import static com.eveningoutpost.dexdrip.wearintegration.ExternalStatusService.getLastStatusLineTime;

/**
* Broadcast API which provides common data like, bg values, graph info, statistic info.
* Also it can handle different alarms, save HR data, steps and treatments.
Expand Down Expand Up @@ -76,6 +82,8 @@ public class BroadcastService extends Service {
protected String TAG = this.getClass().getSimpleName();
protected Map<String, BroadcastModel> broadcastEntities;

protected KeyStore keyStore = FastStore.getInstance();

/**
* The receiver listening {@link ACTION_WATCH_COMMUNICATION_RECEIVER} action.
* Every Receiver command requires {@link Const.INTENT_PACKAGE_KEY}
Expand Down Expand Up @@ -209,7 +217,6 @@ public void onReceive(Context context, Intent intent) {
}
};


@Override
public IBinder onBind(Intent intent) {
return null;
Expand All @@ -227,6 +234,7 @@ public void onCreate() {
registerReceiver(broadcastReceiver, new IntentFilter(ACTION_WATCH_COMMUNICATION_RECEIVER));

JoH.startService(BroadcastService.class, Const.INTENT_FUNCTION_KEY, Const.CMD_START);

super.onCreate();
}

Expand Down Expand Up @@ -294,6 +302,9 @@ private void handleCommand(String function, Intent intent) {
bundle.putString("message", intent.getStringExtra("message"));
sendBroadcast(function, receiver, bundle);
break;
case Const.CMD_CANCEL_ALERT:
sendBroadcast(function, receiver, bundle);
break;
}
}

Expand All @@ -318,6 +329,9 @@ private void handleCommand(String function, Intent intent) {
broadcastModel = broadcastEntities.get(receiver);
bundle = prepareBgBundle(broadcastModel);
break;
case Const.CMD_CANCEL_ALERT:
receiver = null; //broadcast
break;
case Const.CMD_SNOOZE_ALERT:
String alertName = "";
String replyMsg = "";
Expand Down Expand Up @@ -513,7 +527,7 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) {
bundle.putDouble("lowMark", JoH.tolerantParseDouble(prefs.getString("lowValue", "70"), 70));

BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(xdrip.getAppContext(), start, end);
bgGraphBuilder.defaultLines(true); // simple mode
bgGraphBuilder.defaultLines(false); // not simple mode in order to receive simulated data

bundle.putParcelable("graph.lowLine", new GraphLine(bgGraphBuilder.lowLine()));
bundle.putParcelable("graph.highLine", new GraphLine(bgGraphBuilder.highLine()));
Expand All @@ -530,7 +544,25 @@ protected Bundle prepareBgBundle(BroadcastModel broadcastModel) {
bundle.putParcelable("graph.cob", new GraphLine(treatments[6])); //cobValues
bundle.putParcelable("graph.polyBg", new GraphLine(treatments[7])); //poly predict ;
}

String last_iob = keyStore.getS("last_iob");
if ( last_iob != null){
bundle.putString("predict.IOB", last_iob);
bundle.putLong("predict.IOB.timeStamp", keyStore.getL("last_iob_timestamp"));
}

String last_bwp = keyStore.getS("last_bwp");
if ( last_bwp != null){
bundle.putString("predict.BWP", last_bwp);
bundle.putLong("predict.BWP.timeStamp", keyStore.getL("last_bwp_timestamp"));
}

// External status line from AAPS added
bundle.putString("external.statusLine", getLastStatusLine());
bundle.putLong("external.timeStamp", getLastStatusLineTime());

}
return bundle;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Const {
public static final String CMD_SET_SETTINGS = "set_settings";
public static final String CMD_UPDATE_BG_FORCE = "update_bg_force";
public static final String CMD_ALERT = "alarm";
public static final String CMD_CANCEL_ALERT = "cancel_alarm";
public static final String CMD_SNOOZE_ALERT = "snooze_alarm";
public static final String CMD_ADD_STEPS = "add_steps";
public static final String CMD_ADD_HR = "add_hrs";
Expand Down

0 comments on commit 4e5abd9

Please sign in to comment.