Add alerter thread to ComboPlugin that raises an alarm every 6 minutes (Android will by default silence alarms that go off within less than 5 minutes) when the pump state shows an error condition.
This commit is contained in:
parent
362c3681d5
commit
ccffa3bfca
1 changed files with 44 additions and 5 deletions
|
@ -1,12 +1,17 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpCombo;
|
package info.nightscout.androidaps.plugins.PumpCombo;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
|
@ -118,6 +123,41 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
log.error("Binding to ruffy service failed");
|
log.error("Binding to ruffy service failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
|
NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
int id = 1000;
|
||||||
|
long lastAlarmTime = 0;
|
||||||
|
while (true) {
|
||||||
|
String errorMsg = pumpState.errorMsg;
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
long sixMinutesSinceLastAlarm = lastAlarmTime + 6 * 60 * 1000;
|
||||||
|
if (errorMsg != null && now > sixMinutesSinceLastAlarm) {
|
||||||
|
log.warn("Pump is in error state, raising alert: " + errorMsg);
|
||||||
|
long[] vibratePattern = new long[]{1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000};
|
||||||
|
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
||||||
|
NotificationCompat.Builder notificationBuilder =
|
||||||
|
new NotificationCompat.Builder(context)
|
||||||
|
.setSmallIcon(R.drawable.notif_icon)
|
||||||
|
.setSmallIcon(R.drawable.icon_bolus)
|
||||||
|
.setContentTitle("Combo communication error")
|
||||||
|
.setContentText(errorMsg)
|
||||||
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||||
|
.setLights(Color.BLUE, 1000, 0)
|
||||||
|
.setSound(uri)
|
||||||
|
.setVibrate(vibratePattern);
|
||||||
|
mgr.notify(id, notificationBuilder.build());
|
||||||
|
lastAlarmTime = now;
|
||||||
|
} else {
|
||||||
|
log.debug("Pump state normal");
|
||||||
|
}
|
||||||
|
SystemClock.sleep(15_000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "combo-alerter").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void definePumpCapabilities() {
|
private void definePumpCapabilities() {
|
||||||
|
@ -325,11 +365,10 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
statusSummary = "Idle";
|
statusSummary = "Idle";
|
||||||
pumpState = commandResult.state;
|
pumpState = commandResult.state;
|
||||||
} else {
|
} else {
|
||||||
// TODO this is where we want to raise a noisily-vibrating alarm
|
|
||||||
statusSummary = "Command failed: " + command;
|
statusSummary = "Command failed: " + command;
|
||||||
if (commandResult.message != null) {
|
pumpState.errorMsg = commandResult.message != null
|
||||||
pumpState.errorMsg = commandResult.message;
|
? commandResult.message
|
||||||
}
|
: "Unknown error";
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||||
return commandResult;
|
return commandResult;
|
||||||
|
|
Loading…
Reference in a new issue