public String getExtendedText() { switch (this) { case Ok: if (DexSessionKeeper.isStarted()) { return getText() + " " + DexSessionKeeper.prettyTime(); } else { return getText() + " time?"; } case WarmingUp: if (DexSessionKeeper.isStarted()) { if (DexSessionKeeper.warmUpTimeValid()) { return getText() + "\n" + DexSessionKeeper.prettyTime() + " left"; } else { return getText(); } } else { return getText(); } default: return getText(); } } }
boolean insufficient() { return calibrationState().insufficientCalibration(); }
public boolean readyForCalibration() { return this == Ok || needsCalibration(); }
lastSensorStatus = state.getExtendedText(); lastSensorState = state; final boolean needs_calibration = state.needsCalibration(); final boolean was_needing_calibration = PersistentStore.getBoolean(NEEDING_CALIBRATION); final boolean is_started = state.sensorStarted(); final boolean was_started = PersistentStore.getBoolean(IS_STARTED); final boolean is_failed = state.sensorFailed(); final boolean was_failed = PersistentStore.getBoolean(IS_FAILED); final PendingIntent pi = PendingIntent.getActivity(xdrip.getAppContext(), G5_CALIBRATION_REQUEST, JoH.getStartActivityIntent(c), PendingIntent.FLAG_UPDATE_CURRENT); JoH.showNotification(state.getText(), "G5 Calibration Required", android_wear ? null : pi, G5_CALIBRATION_REQUEST, state == CalibrationState.NeedsFirstCalibration, true, false); if (state.ended()) { UserError.Log.uel(TAG, "Requesting time-travel restart"); Ob1G5StateMachine.restartSensorWithTimeTravel(); JoH.showNotification(state.getText(), "G5 Sensor Stopped", pi, G5_SENSOR_STARTED, true, true, false); UserError.Log.ueh(TAG, "Native Sensor is now Stopped: " + state.getExtendedText()); } else if (is_started && !was_started) { JoH.cancelNotification(G5_SENSOR_STARTED); UserError.Log.ueh(TAG, "Native Sensor is now Started: " + state.getExtendedText()); JoH.showNotification(state.getText(), "G5 Sensor FAILED", pi, G5_SENSOR_FAILED, true, true, false); UserError.Log.ueh(TAG, "Native Sensor is now marked FAILED: " + state.getExtendedText());
public static CalibrationState parse(int state) { return parse((byte) state); }
public static SpannableString nanoStatus() { if (android_wear) { final SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(lastSensorStatus != null ? lastSensorStatus + "\n" : ""); builder.append(state.getString()); return new SpannableString(builder); } else { if (lastSensorState != null && lastSensorState != CalibrationState.Ok) { return Span.colorSpan(lastSensorState.getExtendedText(), lastSensorState == CalibrationState.WarmingUp ? NOTICE.color() : lastSensorState.sensorFailed() ? CRITICAL.color() : BAD.color()); } else { return null; } } }
private static void glucoseRxCommon(final BaseGlucoseRxMessage glucose, final Ob1G5CollectionService parent, final RxBleConnection connection) { if (JoH.ratelimit("ob1-g5-also-read-raw", 20)) { enqueueUniqueCommand(new SensorTxMessage(), "Also read raw"); } if (JoH.pratelimit("g5-tx-time-since", 7200) || glucose.calibrationState().warmingUp() || !DexSessionKeeper.isStarted()) { if (JoH.ratelimit("g5-tx-time-governer", 30)) { enqueueUniqueCommand(new TimeTxMessage(), "Periodic Query Time"); } } // TODO check firmware version if (glucose.calibrationState().readyForBackfill() && !parent.getBatteryStatusNow) { backFillIfNeeded(parent, connection); } processGlucoseRxMessage(parent, glucose); parent.updateLast(JoH.tsl()); parent.clearErrors(); }
private static void storeCalibrationState(final CalibrationState state) { PersistentStore.setByte(OB1G5_STATESTORE, state.getValue()); PersistentStore.setLong(OB1G5_STATESTORE_TIME, JoH.tsl()); }
boolean OkToCalibrate() { return calibrationState().readyForCalibration(); }
if (glucose.calibrationState().sensorFailed()) { if (JoH.pratelimit("G5 Sensor Failed", 3600 * 3)) { JoH.showNotification(devName() + " SENSOR FAILED", "Sensor reporting failed", null, Constants.G5_SENSOR_ERROR, true, true, false);
lastSensorStatus = state.getExtendedText(); lastSensorState = state; final boolean needs_calibration = state.needsCalibration(); final boolean was_needing_calibration = PersistentStore.getBoolean(NEEDING_CALIBRATION); final boolean is_started = state.sensorStarted(); final boolean was_started = PersistentStore.getBoolean(IS_STARTED); final boolean is_failed = state.sensorFailed(); final boolean was_failed = PersistentStore.getBoolean(IS_FAILED); final PendingIntent pi = PendingIntent.getActivity(xdrip.getAppContext(), G5_CALIBRATION_REQUEST, JoH.getStartActivityIntent(c), PendingIntent.FLAG_UPDATE_CURRENT); JoH.showNotification(state.getText(), "G5 Calibration Required", android_wear ? null : pi, G5_CALIBRATION_REQUEST, state == CalibrationState.NeedsFirstCalibration, true, false); if (state.ended()) { UserError.Log.uel(TAG, "Requesting time-travel restart"); Ob1G5StateMachine.restartSensorWithTimeTravel(); JoH.showNotification(state.getText(), "G5 Sensor Stopped", pi, G5_SENSOR_STARTED, true, true, false); UserError.Log.ueh(TAG, "Native Sensor is now Stopped: " + state.getExtendedText()); } else if (is_started && !was_started) { JoH.cancelNotification(G5_SENSOR_STARTED); UserError.Log.ueh(TAG, "Native Sensor is now Started: " + state.getExtendedText()); JoH.showNotification(state.getText(), "G5 Sensor FAILED", pi, G5_SENSOR_FAILED, true, true, false); UserError.Log.ueh(TAG, "Native Sensor is now marked FAILED: " + state.getExtendedText());
CalibrationState calibrationState() { return CalibrationState.parse(state); }
public static SpannableString nanoStatus() { if (android_wear) { final SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(lastSensorStatus != null ? lastSensorStatus + "\n" : ""); builder.append(state.getString()); return new SpannableString(builder); } else { if (lastSensorState != null && lastSensorState != CalibrationState.Ok) { return Span.colorSpan(lastSensorState.getExtendedText(), lastSensorState == CalibrationState.WarmingUp ? NOTICE.color() : lastSensorState.sensorFailed() ? CRITICAL.color() : BAD.color()); } else { return null; } } }
private static void glucoseRxCommon(final BaseGlucoseRxMessage glucose, final Ob1G5CollectionService parent, final RxBleConnection connection) { if (JoH.ratelimit("ob1-g5-also-read-raw", 20)) { enqueueUniqueCommand(new SensorTxMessage(), "Also read raw"); } if (JoH.pratelimit("g5-tx-time-since", 7200) || glucose.calibrationState().warmingUp() || !DexSessionKeeper.isStarted()) { if (JoH.ratelimit("g5-tx-time-governer", 30)) { enqueueUniqueCommand(new TimeTxMessage(), "Periodic Query Time"); } } // TODO check firmware version if (glucose.calibrationState().readyForBackfill() && !parent.getBatteryStatusNow) { backFillIfNeeded(parent, connection); } processGlucoseRxMessage(parent, glucose); parent.updateLast(JoH.tsl()); parent.clearErrors(); }
private static void storeCalibrationState(final CalibrationState state) { PersistentStore.setByte(OB1G5_STATESTORE, state.getValue()); PersistentStore.setLong(OB1G5_STATESTORE_TIME, JoH.tsl()); }
boolean OkToCalibrate() { return calibrationState().readyForCalibration(); }
if (glucose.calibrationState().sensorFailed()) { if (JoH.pratelimit("G5 Sensor Failed", 3600 * 3)) { JoH.showNotification(devName() + " SENSOR FAILED", "Sensor reporting failed", null, Constants.G5_SENSOR_ERROR, true, true, false);
lastSensorStatus = state.getExtendedText(); lastSensorState = state; final boolean needs_calibration = state.needsCalibration(); final boolean was_needing_calibration = PersistentStore.getBoolean(NEEDING_CALIBRATION); final boolean is_started = state.sensorStarted(); final boolean was_started = PersistentStore.getBoolean(IS_STARTED); final boolean is_failed = state.sensorFailed(); final boolean was_failed = PersistentStore.getBoolean(IS_FAILED); final PendingIntent pi = PendingIntent.getActivity(xdrip.getAppContext(), G5_CALIBRATION_REQUEST, JoH.getStartActivityIntent(c), PendingIntent.FLAG_UPDATE_CURRENT); JoH.showNotification(state.getText(), "G5 Calibration Required", android_wear ? null : pi, G5_CALIBRATION_REQUEST, state == CalibrationState.NeedsFirstCalibration, true, false); if (state.ended()) { UserError.Log.uel(TAG, "Requesting time-travel restart"); Ob1G5StateMachine.restartSensorWithTimeTravel(); JoH.showNotification(state.getText(), "G5 Sensor Stopped", pi, G5_SENSOR_STARTED, true, true, false); UserError.Log.ueh(TAG, "Native Sensor is now Stopped: " + state.getExtendedText()); } else if (is_started && !was_started) { JoH.cancelNotification(G5_SENSOR_STARTED); UserError.Log.ueh(TAG, "Native Sensor is now Started: " + state.getExtendedText()); JoH.showNotification(state.getText(), "G5 Sensor FAILED", pi, G5_SENSOR_FAILED, true, true, false); UserError.Log.ueh(TAG, "Native Sensor is now marked FAILED: " + state.getExtendedText());
CalibrationState calibrationState() { return CalibrationState.parse(state); }
public static SpannableString nanoStatus() { if (android_wear) { final SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append(lastSensorStatus != null ? lastSensorStatus + "\n" : ""); builder.append(state.getString()); return new SpannableString(builder); } else { if (lastSensorState != null && lastSensorState != CalibrationState.Ok) { return Span.colorSpan(lastSensorState.getExtendedText(), lastSensorState == CalibrationState.WarmingUp ? NOTICE.color() : lastSensorState.sensorFailed() ? CRITICAL.color() : BAD.color()); } else { return null; } } }