KeepAliveReceiver: add alarm for missed readings.
This commit is contained in:
parent
001a56728d
commit
4539b5a9e5
1 changed files with 25 additions and 10 deletions
|
@ -21,6 +21,8 @@ import java.util.Date;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
|
@ -35,21 +37,37 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
||||||
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
|
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
|
||||||
wl.acquire();
|
wl.acquire();
|
||||||
|
|
||||||
|
checkBg();
|
||||||
|
checkPump();
|
||||||
|
|
||||||
|
log.debug("KeepAlive received");
|
||||||
|
wl.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBg() {
|
||||||
|
BgReading bgReading = DatabaseHelper.lastBg();
|
||||||
|
if (bgReading != null && bgReading.date + 25 * 60 * 1000 < System.currentTimeMillis()) {
|
||||||
|
Notification n = new Notification(Notification.PUMP_UNREACHABLE, "Missed BG readings", Notification.URGENT);
|
||||||
|
n.soundId = R.raw.alarm;
|
||||||
|
MainApp.bus().post(new EventNewNotification(n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPump() {
|
||||||
final PumpInterface pump = MainApp.getConfigBuilder();
|
final PumpInterface pump = MainApp.getConfigBuilder();
|
||||||
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
final Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
if (pump != null && profile != null && profile.getBasal() != null) {
|
if (pump != null && profile != null && profile.getBasal() != null) {
|
||||||
boolean isBasalOutdated = false;
|
|
||||||
boolean isStatusOutdated = false;
|
|
||||||
|
|
||||||
Date lastConnection = pump.lastDataTime();
|
Date lastConnection = pump.lastDataTime();
|
||||||
if (lastConnection.getTime() + 15 * 60 * 1000L < System.currentTimeMillis())
|
|
||||||
isStatusOutdated = true;
|
boolean isStatusOutdated = lastConnection.getTime() + 15 * 60 * 1000L < System.currentTimeMillis();
|
||||||
if (Math.abs(profile.getBasal() - pump.getBaseBasalRate()) > pump.getPumpDescription().basalStep)
|
boolean isBasalOutdated = Math.abs(profile.getBasal() - pump.getBaseBasalRate()) > pump.getPumpDescription().basalStep;
|
||||||
isBasalOutdated = true;
|
|
||||||
|
|
||||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
if (isStatusOutdated && lastConnection.getTime() + 25 * 60 * 1000 < System.currentTimeMillis()) {
|
if (isStatusOutdated && lastConnection.getTime() + 25 * 60 * 1000 < System.currentTimeMillis()) {
|
||||||
|
// TODO the alarm will trigger every 5m until the problem is resolved. That can get annoying quiet quickly if
|
||||||
|
// fixing the problem takes longer (or is not immediately possible because the pump was forgotten)?
|
||||||
|
// suppress this for another 25m if the message was dismissed?
|
||||||
|
// The alarm sound is played back as regular media, that means it might be muted if sound level is at 0
|
||||||
Notification n = new Notification(Notification.PUMP_UNREACHABLE, "Pump unreachable", Notification.URGENT);
|
Notification n = new Notification(Notification.PUMP_UNREACHABLE, "Pump unreachable", Notification.URGENT);
|
||||||
n.soundId = R.raw.alarm;
|
n.soundId = R.raw.alarm;
|
||||||
MainApp.bus().post(new EventNewNotification(n));
|
MainApp.bus().post(new EventNewNotification(n));
|
||||||
|
@ -79,9 +97,6 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("KeepAlive received");
|
|
||||||
wl.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlarm(Context context) {
|
public void setAlarm(Context context) {
|
||||||
|
|
Loading…
Reference in a new issue