Skip to content

Commit

Permalink
Wear: sync bgreading and notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Jun 29, 2018
1 parent 4524141 commit 2a49473
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ public static void create(EGVRecord egvRecord, long addativeOffset, Context cont
bgReading.save();
bgReading.find_new_curve();
bgReading.find_new_raw_curve();
context.startService(new Intent(context, Notifications.class));
//context.startService(new Intent(context, Notifications.class));
Notifications.start(); // this may not be needed as it is duplicated in handleNewBgReading
BgSendQueue.handleNewBgReading(bgReading, "create", context);
}
}
Expand Down Expand Up @@ -582,7 +583,8 @@ public static BgReading create(double raw_data, double filtered_data, Context co
BloodTest.opportunisticCalibration();
}

context.startService(new Intent(context, Notifications.class));
//context.startService(new Intent(context, Notifications.class));
// allow this instead to be fired inside handleNewBgReading when noise will have been injected already
}
bgReading.injectNoise(true); // Add noise parameter for nightscout
bgReading.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); // Add display glucose for nightscout
Expand Down Expand Up @@ -1058,7 +1060,7 @@ public boolean isBackfilled() {
public static final double SPECIAL_G5_PLACEHOLDER = -0.1597;

// TODO remember to sync this with wear code base
public static synchronized BgReading bgReadingInsertFromG5(double calculated_value, long timestamp) {
public static synchronized BgReading bgReadingInsertFromG5(double calculated_value, long timestamp, String sourceInfoAppend) {

final Sensor sensor = Sensor.currentSensor();
if (sensor == null) {
Expand All @@ -1077,10 +1079,14 @@ public static synchronized BgReading bgReadingInsertFromG5(double calculated_val
bgr.calculated_value = calculated_value;
bgr.raw_data = SPECIAL_G5_PLACEHOLDER; // placeholder
bgr.appendSourceInfo("G5 Native");
if (sourceInfoAppend != null && sourceInfoAppend.length() > 0) {
bgr.appendSourceInfo(sourceInfoAppend);
}
bgr.save();
if (JoH.ratelimit("sync wakelock", 15)) {
final PowerManager.WakeLock linger = JoH.getWakeLock("G5 Insert", 4000);
}
// TODO make Inevitable
new Thread(() -> {
JoH.threadSleep(3000);
notifyAndSync(bgr);
Expand All @@ -1094,7 +1100,7 @@ public static synchronized BgReading bgReadingInsertFromG5(double calculated_val
public static void notifyAndSync(final BgReading bgr) {
final boolean recent = bgr.isCurrent();
if (recent) {
xdrip.getAppContext().startService(new Intent(xdrip.getAppContext(), Notifications.class)); // alerts et al
Notifications.start(); // may not be needed as this is duplicated in handleNewBgReading
// probably not wanted for G5 internal values?
//bgr.injectNoise(true); // Add noise parameter for nightscout
//bgr.injectDisplayGlucose(BestGlucose.getDisplayGlucose()); // Add display glucose for nightscout
Expand Down Expand Up @@ -1125,7 +1131,8 @@ public static void bgReadingInsertFromJson(String json, boolean do_notification,
}
bgr.save();
if (do_notification) {
xdrip.getAppContext().startService(new Intent(xdrip.getAppContext(), Notifications.class)); // alerts et al
Notifications.start(); // this may not be needed as it fires in handleNewBgReading
//xdrip.getAppContext().startService(new Intent(xdrip.getAppContext(), Notifications.class)); // alerts et al
BgSendQueue.handleNewBgReading(bgr, "create", xdrip.getAppContext(), Home.get_follower()); // pebble and widget and follower
}
} else {
Expand Down Expand Up @@ -1174,7 +1181,8 @@ public static void bgReadingInsertFromInt(int value, long timestamp, boolean do_
bgr.save();
bgr.find_slope();
if (do_notification) {
xdrip.getAppContext().startService(new Intent(xdrip.getAppContext(), Notifications.class)); // alerts et al
// xdrip.getAppContext().startService(new Intent(xdrip.getAppContext(), Notifications.class)); // alerts et al
Notifications.start(); // this may not be needed as it is duplicated in handleNewBgReading
}
BgSendQueue.handleNewBgReading(bgr, "create", xdrip.getAppContext(), false, !do_notification); // pebble and widget
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public static void handleNewBgReading(BgReading bgReading, String operation_type
wakeLock.acquire(120000);
try {

Notifications.start();
CustomComplicationProviderService.refresh();

if (!is_follower) addToQueue(bgReading, operation_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,13 @@ public static String unitsConvert2Disp(boolean doMgdl, double threshold) {

return df.format(threshold / Constants.MMOLL_TO_MGDL);
}

// rate limited
public static void start() {
// TODO consider how inevitable task could change dynamic of this instead of rate limit
if (JoH.ratelimit("start-notifications",10)) {
JoH.startService(Notifications.class);
}
}

}

0 comments on commit 2a49473

Please sign in to comment.