Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.Constants#HOUR_IN_MS

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.Constants#HOUR_IN_MS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Reminders.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private long getPeriod(RadioButton rbday, RadioButton rbhour, RadioButton rbweek) {
    long period;
    try {
        period = Integer.parseInt(reminderDaysEdt.getText().toString());
    } catch (NumberFormatException e) {
        period = 1; // TODO avoid this happening from the UI
        try {
            reminderDaysEdt.setText("" + period);
        } catch (Exception ee) {
            //
        }
    }
    if (rbday.isChecked()) {
        period = period * Constants.DAY_IN_MS;
    } else if (rbhour.isChecked()) {
        period = period * Constants.HOUR_IN_MS;
    } else if (rbweek.isChecked()) {
        period = period * Constants.WEEK_IN_MS;
    }
    return period;
}
 
Example 2
Source File: Reminders.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private long getPeriod(RadioButton rbday, RadioButton rbhour, RadioButton rbweek) {
    long period;
    try {
        period = Integer.parseInt(reminderDaysEdt.getText().toString());
    } catch (NumberFormatException e) {
        period = 1; // TODO avoid this happening from the UI
        try {
            reminderDaysEdt.setText("" + period);
        } catch (Exception ee) {
            //
        }
    }
    if (rbday.isChecked()) {
        period = period * Constants.DAY_IN_MS;
    } else if (rbhour.isChecked()) {
        period = period * Constants.HOUR_IN_MS;
    } else if (rbweek.isChecked()) {
        period = period * Constants.WEEK_IN_MS;
    }
    return period;
}
 
Example 3
Source File: BluetoothGlucoseMeter.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void startIfNoRecentData() {
    if (JoH.quietratelimit("bluetooth-recent-check", 1800)) {
        if (Pref.getBoolean("bluetooth_meter_enabled", false)) {
            final List<BloodTest> btl = BloodTest.lastMatching(1, BLUETOOTH_GLUCOSE_METER_TAG + "%");
            if ((btl == null) || (btl.size() == 0) || (JoH.msSince(btl.get(0).created_timestamp) > Constants.HOUR_IN_MS * 6)) {
                if (JoH.pratelimit("restart_bluetooth_service", 3600 * 5)) {
                    UserError.Log.uel(TAG, "Restarting Bluetooth Glucose meter service");
                    startIfEnabled();
                }
            }
        }
    }
}
 
Example 4
Source File: Reminders.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void snoozeAdjust(View v) {
    final String button_text = ((Button) v).getTag().toString(); //changed String to Tag, to make the texts translateable
    Log.d(TAG, "Snooze adjust button: " + button_text);
    long multiplier = Constants.MINUTE_IN_MS;
    final String[] button_textA = button_text.split(" ");
    switch (button_textA[1].toLowerCase()) {
        case "hour":
        case "hours":
            multiplier = Constants.HOUR_IN_MS;
            break;

        case "day":
        case "days":
            multiplier = Constants.DAY_IN_MS;
            break;

        case "week":
        case "weeks":
            multiplier = Constants.WEEK_IN_MS;
            break;
    }
    final long snooze_adjust = Integer.parseInt(button_textA[0]) * multiplier;
    Log.d(TAG, "Snoozed adjust button result: " + snooze_adjust);
    dismissItem(last_swiped);
    snoozeReminder(last_swiped, snooze_adjust);
    reinject(last_swiped);
}
 
Example 5
Source File: BlueJayService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void sendGlucose() {
    val last = BgReading.last();
    if (last != null && msSince(last.timestamp) < Constants.HOUR_IN_MS) {
        val info = BlueJayInfo.getInfo(BlueJay.getMac());
        if (Math.abs(info.lastReadingTime - last.timestamp) > Constants.MINUTE_IN_MS * 3) {
            val glucoseTx = new GlucoseTx(last);
            if (glucoseTx.isValid()) {
                val item = new QueueMe()
                        .setBytes(glucoseTx.getBytes())
                        .expireInSeconds(60)
                        .setDescription("Glucose to watch");

                item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) {
                    @Override
                    public void process(byte[] bytes) {
                        UserError.Log.d(TAG, "Glucose Incoming reply processor: " + HexDump.dumpHexString(bytes));
                        info.displayUpdated();
                    }
                }).setTag(item));

                item.queue();
                doQueue();
            } else {
                UserError.Log.d(TAG, "GlucoseTX wasn't valid so not sending.");
            }
        } else {
            UserError.Log.d(TAG, "Watch already has recent reading");
            // watch reading too close to the reading we were going to send
        }
    }
}
 
Example 6
Source File: NightscoutBackfillActivity.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    xdrip.checkForcedEnglish(this);
    setTitle("Nightscout Backfill");
    super.onResume();
    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), "Nightscout Backfill", this);

    if (JoH.msSince(locked) < Constants.HOUR_IN_MS) {
        JoH.static_toast_long(gs(R.string.still_processing_previous_backfill_request));
        finish();
    }
}
 
Example 7
Source File: APStatus.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static List<APStatus> latestForGraph(int number, long startTime, long endTime) {
    try {
        final List<APStatus> results = new Select()
                .from(APStatus.class)
                .where("timestamp >= " + Math.max(startTime, 0))
                .where("timestamp <= " + endTime)
                .orderBy("timestamp asc") // warn asc!
                .limit(number)
                .execute();
        // extend line to now if we have current data but it is continuation of last record
        // so not generating a new efficient record.
        if (results != null && (results.size() > 0)) {
            final APStatus last = results.get(results.size() - 1);
            final long last_raw_record_timestamp = ExternalStatusService.getLastStatusLineTime();
            // check are not already using the latest.
            if (last_raw_record_timestamp > last.timestamp) {
                final Integer last_recorded_tbr = ExternalStatusService.getTBRInt();
                if (last_recorded_tbr != null) {
                    if ((last.basal_percent == last_recorded_tbr)
                            && (JoH.msSince(last.timestamp) < Constants.HOUR_IN_MS * 3)
                            && (JoH.msSince(ExternalStatusService.getLastStatusLineTime()) < Constants.MINUTE_IN_MS * 20)) {
                        results.add(new APStatus(JoH.tsl(), last_recorded_tbr));
                        UserError.Log.d(TAG, "Adding extension record");
                    }
                }
            }
        }
        return results;
    } catch (android.database.sqlite.SQLiteException e) {
        updateDB();
        return new ArrayList<>();
    }
}
 
Example 8
Source File: BlueJayService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void sendGlucose() {
    val last = BgReading.last();
    if (last != null && msSince(last.timestamp) < Constants.HOUR_IN_MS) {
        val info = BlueJayInfo.getInfo(BlueJay.getMac());
        if (Math.abs(info.lastReadingTime - last.timestamp) > Constants.MINUTE_IN_MS * 3) {
            val glucoseTx = new GlucoseTx(last);
            if (glucoseTx.isValid()) {
                val item = new QueueMe()
                        .setBytes(glucoseTx.getBytes())
                        .expireInSeconds(60)
                        .setDescription("Glucose to watch");

                item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) {
                    @Override
                    public void process(byte[] bytes) {
                        UserError.Log.d(TAG, "Glucose Incoming reply processor: " + HexDump.dumpHexString(bytes));
                        info.displayUpdated();
                    }
                }).setTag(item));

                item.queue();
                doQueue();
            } else {
                UserError.Log.d(TAG, "GlucoseTX wasn't valid so not sending.");
            }
        } else {
            UserError.Log.d(TAG, "Watch already has recent reading");
            // watch reading too close to the reading we were going to send
        }
    }
}
 
Example 9
Source File: Reminders.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void snoozeAdjust(View v) {
    final String button_text = ((Button) v).getTag().toString(); //changed String to Tag, to make the texts translateable
    Log.d(TAG, "Snooze adjust button: " + button_text);
    long multiplier = Constants.MINUTE_IN_MS;
    final String[] button_textA = button_text.split(" ");
    switch (button_textA[1].toLowerCase()) {
        case "hour":
        case "hours":
            multiplier = Constants.HOUR_IN_MS;
            break;

        case "day":
        case "days":
            multiplier = Constants.DAY_IN_MS;
            break;

        case "week":
        case "weeks":
            multiplier = Constants.WEEK_IN_MS;
            break;
    }
    final long snooze_adjust = Integer.parseInt(button_textA[0]) * multiplier;
    Log.d(TAG, "Snoozed adjust button result: " + snooze_adjust);
    dismissItem(last_swiped);
    snoozeReminder(last_swiped, snooze_adjust);
    reinject(last_swiped);
}
 
Example 10
Source File: JoH.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static String niceTimeScalarShortWithDecimalHours(long t) {
    if (t > Constants.HOUR_IN_MS) {
        return niceTimeScalar(t,1).replaceFirst("([A-z]).*$", "$1");
    } else {
        return niceTimeScalar(t).replaceFirst("([A-z]).*$", "$1");
    }
}
 
Example 11
Source File: NightscoutBackfillActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    xdrip.checkForcedEnglish(this);
    setTitle("Nightscout Backfill");
    super.onResume();
    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), "Nightscout Backfill", this);

    if (JoH.msSince(locked) < Constants.HOUR_IN_MS) {
        JoH.static_toast_long(gs(R.string.still_processing_previous_backfill_request));
        finish();
    }
}
 
Example 12
Source File: DesertSync.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static List<String> getActivePeers() {
    final List<String> list = new ArrayList<>();
    if (peers != null) {
        for (final Map.Entry<InetAddress, Long> entry : peers.entrySet()) {
            if (JoH.msSince(entry.getValue()) < Constants.HOUR_IN_MS * 3) {
                list.add(ip(entry.getKey()));
            }
        }
    }
    return list;
}
 
Example 13
Source File: BluetoothGlucoseMeter.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void startIfNoRecentData() {
    if (JoH.quietratelimit("bluetooth-recent-check", 1800)) {
        if (Pref.getBoolean("bluetooth_meter_enabled", false)) {
            final List<BloodTest> btl = BloodTest.lastMatching(1, BLUETOOTH_GLUCOSE_METER_TAG + "%");
            if ((btl == null) || (btl.size() == 0) || (JoH.msSince(btl.get(0).created_timestamp) > Constants.HOUR_IN_MS * 6)) {
                if (JoH.pratelimit("restart_bluetooth_service", 3600 * 5)) {
                    UserError.Log.uel(TAG, "Restarting Bluetooth Glucose meter service");
                    startIfEnabled();
                }
            }
        }
    }
}
 
Example 14
Source File: APStatus.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static List<APStatus> latestForGraph(int number, long startTime, long endTime) {
    try {
        final List<APStatus> results = new Select()
                .from(APStatus.class)
                .where("timestamp >= " + Math.max(startTime, 0))
                .where("timestamp <= " + endTime)
                .orderBy("timestamp asc") // warn asc!
                .limit(number)
                .execute();
        // extend line to now if we have current data but it is continuation of last record
        // so not generating a new efficient record.
        if (results != null && (results.size() > 0)) {
            final APStatus last = results.get(results.size() - 1);
            final long last_raw_record_timestamp = ExternalStatusService.getLastStatusLineTime();
            // check are not already using the latest.
            if (last_raw_record_timestamp > last.timestamp) {
                final Integer last_recorded_tbr = ExternalStatusService.getTBRInt();
                if (last_recorded_tbr != null) {
                    if ((last.basal_percent == last_recorded_tbr)
                            && (JoH.msSince(last.timestamp) < Constants.HOUR_IN_MS * 3)
                            && (JoH.msSince(ExternalStatusService.getLastStatusLineTime()) < Constants.MINUTE_IN_MS * 20)) {
                        results.add(new APStatus(JoH.tsl(), last_recorded_tbr));
                        UserError.Log.d(TAG, "Adding extension record");
                    }
                }
            }
        }
        return results;
    } catch (android.database.sqlite.SQLiteException e) {
        updateDB();
        return new ArrayList<>();
    }
}
 
Example 15
Source File: BluetoothGlucoseMeter.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void evaluateLastRecords() {
    if (lastBloodTest != null) {
        GcmActivity.syncBloodTests();

        final boolean delay_calibration = true;
        final GlucoseReadingRx lastGlucoseRecord = lastBloodTest.glucoseReadingRx;
        if ((lastGlucoseRecord != null) && (lastGlucoseRecord.device != null) && (ct != null)) {
            final String sequence_id = "last-btm-sequence-" + lastGlucoseRecord.device;
            final String timestamp_id = "last-btm-timestamp" + lastGlucoseRecord.device;
            // sequence numbers start from 0 so we add 1
            if ((lastGlucoseRecord.sequence + 1) > PersistentStore.getLong(sequence_id)) {
                PersistentStore.setLong(sequence_id, lastGlucoseRecord.sequence + 1);
                // get adjusted timestamp
                if (lastBloodTest.timestamp > PersistentStore.getLong(timestamp_id)) {
                    PersistentStore.setLong(timestamp_id, lastBloodTest.timestamp);
                    Log.d(TAG, "evaluateLastRecords: appears to be a new record: sequence:" + lastGlucoseRecord.sequence);
                    JoH.runOnUiThreadDelayed(Home::staticRefreshBGCharts, 300);
                    if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")
                            || Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
                        final long time_since = JoH.msSince(lastBloodTest.timestamp);
                        if (time_since >= 0) {
                            if (time_since < (12 * Constants.HOUR_IN_MS)) {
                                final Calibration calibration = Calibration.lastValid();
                                // check must also be younger than most recent calibration
                                if ((calibration == null) || (lastBloodTest.timestamp > calibration.timestamp)) {
                                    UserError.Log.ueh(TAG, "Prompting for calibration for: " + BgGraphBuilder.unitized_string_with_units_static(lastBloodTest.mgdl) + " from: " + JoH.dateTimeText(lastBloodTest.timestamp));
                                    JoH.clearCache();
                                    Home.startHomeWithExtra(getApplicationContext(), Home.HOME_FULL_WAKEUP, "1");
                                    JoH.runOnUiThreadDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            Home.staticRefreshBGCharts();
                                            // requires offset in past

                                            if ((Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto") && isSlopeFlatEnough())) {
                                                Log.d(TAG, "Slope flat enough for auto calibration");
                                                if (!delay_calibration) {
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "auto");
                                                } else {
                                                    Log.d(TAG, "Delaying calibration for later");
                                                    JoH.static_toast_long("Waiting for 15 minutes more sensor data for calibration");
                                                }
                                            } else {
                                                if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")) {
                                                    // manual calibration
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "manual");
                                                } else {
                                                    Log.d(TAG, "Not flat enough slope for auto calibration and manual calibration not enabled");
                                                }
                                            }
                                        }
                                    }, 500);
                                } else {
                                    UserError.Log.e(TAG, "evaluateLastRecords: meter reading is at least as old as last calibration - ignoring");
                                }
                            } else {
                                UserError.Log.e(TAG, "evaluateLastRecords: meter reading is too far in the past: " + JoH.dateTimeText(lastBloodTest.timestamp));
                            }
                        } else {
                            UserError.Log.e(TAG, "evaluateLastRecords: time is in the future - ignoring");
                        }
                    }
                }
            } else {
                UserError.Log.d(TAG, "evaluateLastRecords: sequence isn't newer");
            }
        } else {
            UserError.Log.e(TAG, "evaluateLastRecords: Data missing for evaluation");
        }
    } else {
        UserError.Log.e(TAG, "evaluateLastRecords: lastBloodTest is Null!!");
    }
}
 
Example 16
Source File: MissedReadingService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final boolean bg_missed_alerts;

    final PowerManager.WakeLock wl = JoH.getWakeLock("missed-reading-service", 60000);
    try {

        final boolean sensorActive = Sensor.isActive();

        Log.d(TAG, "MissedReadingService onHandleIntent"); // test debug log

        final long stale_millis = Home.stale_data_millis();


        // send to pebble
        if (Pref.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType() != 1) && !BgReading.last_within_millis(stale_millis)) {
            if (JoH.ratelimit("peb-miss", 120)) {
                // TODO replace ratelimit with Inevitable.task?
                JoH.startService(PebbleWatchSync.class);
            }
            // update pebble even when we don't have data to ensure missed readings show
        }

        if (LeFunEntry.isEnabled() && (!BgReading.last_within_millis(stale_millis))) {
            LeFun.showLatestBG();
        }


        if ((Pref.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
            if (!BgReading.last_within_millis(stale_millis) && sensorActive && (!getLocalServiceCollectingState())) {
                if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                    Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: " + aggressive_backoff_timer);
                    if (aggressive_backoff_timer < 1200) aggressive_backoff_timer += 60;
                    CollectionServiceStarter.restartCollectionServiceBackground();
                } else {
                    aggressive_backoff_timer = 120; // reset
                }
            }
        }


        Reminder.processAnyDueReminders();
        BluetoothGlucoseMeter.immortality();
        XdripWebService.immortality(); //
        InPenEntry.immortality();
        DesertSync.pullAsEnabled();
        NanoStatus.keepFollowerUpdated();
        LockScreenWallPaper.timerPoll();

        // TODO functionalize the actual checking
        bg_missed_alerts = Pref.getBoolean("bg_missed_alerts", false);
        if (!bg_missed_alerts) {
            // we should not do anything in this case. if the ui, changes will be called again
            return;
        }
        if (!sensorActive) {
            // sensor not running we should return
            return;
        }

        if (!JoH.upForAtLeastMins(15)) {
            Log.d(TAG, "Uptime less than 15 minutes so not processing for missed reading");
            return;
        }


        if ((Home.get_forced_wear()) && Pref.getBoolean("disable_wearG5_on_missedreadings", false)) {
            int bg_wear_missed_minutes = Pref.getStringToInt("disable_wearG5_on_missedreadings_level", 30);
            if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
                Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
                startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
            }
        }

        final int bg_missed_minutes = Pref.getStringToInt("bg_missed_minutes", 30);
        final long now = JoH.tsl();

        // check if readings have been missed
        if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
                Pref.getLong("alerts_disabled_until", 0) <= now &&
                (BgReading.getTimeSinceLastReading() < (Constants.HOUR_IN_MS * 6)) &&
                inTimeFrame()) {
            Notifications.bgMissedAlert(xdrip.getAppContext());
            checkBackAfterSnoozeTime(xdrip.getAppContext(), now);
        } else {

            long disabletime = Pref.getLong("alerts_disabled_until", 0) - now;

            long missedTime = bg_missed_minutes * 1000 * 60 - BgReading.getTimeSinceLastReading();
            long alarmIn = Math.max(disabletime, missedTime);
            checkBackAfterMissedTime(alarmIn);
        }
    } finally {
        JoH.releaseWakeLock(wl);
    }
}
 
Example 17
Source File: MissedReadingService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final boolean bg_missed_alerts;

    final PowerManager.WakeLock wl = JoH.getWakeLock("missed-reading-service", 60000);
    try {

        final boolean sensorActive = Sensor.isActive();

        Log.d(TAG, "MissedReadingService onHandleIntent"); // test debug log

        final long stale_millis = Home.stale_data_millis();


        // send to pebble
        if (Pref.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType() != 1) && !BgReading.last_within_millis(stale_millis)) {
            if (JoH.ratelimit("peb-miss", 120)) {
                // TODO replace ratelimit with Inevitable.task?
                JoH.startService(PebbleWatchSync.class);
            }
            // update pebble even when we don't have data to ensure missed readings show
        }

        if (LeFunEntry.isEnabled() && (!BgReading.last_within_millis(stale_millis))) {
            LeFun.showLatestBG();
        }


        if ((Pref.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
            if (!BgReading.last_within_millis(stale_millis) && sensorActive && (!getLocalServiceCollectingState())) {
                if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                    Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: " + aggressive_backoff_timer);
                    if (aggressive_backoff_timer < 1200) aggressive_backoff_timer += 60;
                    CollectionServiceStarter.restartCollectionServiceBackground();
                } else {
                    aggressive_backoff_timer = 120; // reset
                }
            }
        }


        Reminder.processAnyDueReminders();
        BluetoothGlucoseMeter.immortality();
        XdripWebService.immortality(); //
        InPenEntry.immortality();
        DesertSync.pullAsEnabled();
        NanoStatus.keepFollowerUpdated();
        LockScreenWallPaper.timerPoll();

        // TODO functionalize the actual checking
        bg_missed_alerts = Pref.getBoolean("bg_missed_alerts", false);
        if (!bg_missed_alerts) {
            // we should not do anything in this case. if the ui, changes will be called again
            return;
        }
        if (!sensorActive) {
            // sensor not running we should return
            return;
        }

        if (!JoH.upForAtLeastMins(15)) {
            Log.d(TAG, "Uptime less than 15 minutes so not processing for missed reading");
            return;
        }


        if ((Home.get_forced_wear()) && Pref.getBoolean("disable_wearG5_on_missedreadings", false)) {
            int bg_wear_missed_minutes = Pref.getStringToInt("disable_wearG5_on_missedreadings_level", 30);
            if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
                Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
                startWatchUpdaterService(xdrip.getAppContext(), WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
            }
        }

        final int bg_missed_minutes = Pref.getStringToInt("bg_missed_minutes", 30);
        final long now = JoH.tsl();

        // check if readings have been missed
        if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
                Pref.getLong("alerts_disabled_until", 0) <= now &&
                (BgReading.getTimeSinceLastReading() < (Constants.HOUR_IN_MS * 6)) &&
                inTimeFrame()) {
            Notifications.bgMissedAlert(xdrip.getAppContext());
            checkBackAfterSnoozeTime(xdrip.getAppContext(), now);
        } else {

            long disabletime = Pref.getLong("alerts_disabled_until", 0) - now;

            long missedTime = bg_missed_minutes * 1000 * 60 - BgReading.getTimeSinceLastReading();
            long alarmIn = Math.max(disabletime, missedTime);
            checkBackAfterMissedTime(alarmIn);
        }
    } finally {
        JoH.releaseWakeLock(wl);
    }
}
 
Example 18
Source File: Reminder.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public long periodInUnits() {
    if (isDaysPeriod()) return period / Constants.DAY_IN_MS;
    if (isHoursPeriod()) return period / Constants.HOUR_IN_MS;
    if (isWeeksPeriod()) return period / Constants.WEEK_IN_MS;
    return -1; // ERROR
}
 
Example 19
Source File: Reminder.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public boolean isHoursPeriod() {
    return (period >= Constants.HOUR_IN_MS) && (period < Constants.DAY_IN_MS);
}
 
Example 20
Source File: BluetoothGlucoseMeter.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void evaluateLastRecords() {
    if (lastBloodTest != null) {
        GcmActivity.syncBloodTests();

        final boolean delay_calibration = true;
        final GlucoseReadingRx lastGlucoseRecord = lastBloodTest.glucoseReadingRx;
        if ((lastGlucoseRecord != null) && (lastGlucoseRecord.device != null) && (ct != null)) {
            final String sequence_id = "last-btm-sequence-" + lastGlucoseRecord.device;
            final String timestamp_id = "last-btm-timestamp" + lastGlucoseRecord.device;
            // sequence numbers start from 0 so we add 1
            if ((lastGlucoseRecord.sequence + 1) > PersistentStore.getLong(sequence_id)) {
                PersistentStore.setLong(sequence_id, lastGlucoseRecord.sequence + 1);
                // get adjusted timestamp
                if (lastBloodTest.timestamp > PersistentStore.getLong(timestamp_id)) {
                    PersistentStore.setLong(timestamp_id, lastBloodTest.timestamp);
                    Log.d(TAG, "evaluateLastRecords: appears to be a new record: sequence:" + lastGlucoseRecord.sequence);
                    JoH.runOnUiThreadDelayed(Home::staticRefreshBGCharts, 300);
                    if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")
                            || Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
                        final long time_since = JoH.msSince(lastBloodTest.timestamp);
                        if (time_since >= 0) {
                            if (time_since < (12 * Constants.HOUR_IN_MS)) {
                                final Calibration calibration = Calibration.lastValid();
                                // check must also be younger than most recent calibration
                                if ((calibration == null) || (lastBloodTest.timestamp > calibration.timestamp)) {
                                    UserError.Log.ueh(TAG, "Prompting for calibration for: " + BgGraphBuilder.unitized_string_with_units_static(lastBloodTest.mgdl) + " from: " + JoH.dateTimeText(lastBloodTest.timestamp));
                                    JoH.clearCache();
                                    Home.startHomeWithExtra(getApplicationContext(), Home.HOME_FULL_WAKEUP, "1");
                                    JoH.runOnUiThreadDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            Home.staticRefreshBGCharts();
                                            // requires offset in past

                                            if ((Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto") && isSlopeFlatEnough())) {
                                                Log.d(TAG, "Slope flat enough for auto calibration");
                                                if (!delay_calibration) {
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "auto");
                                                } else {
                                                    Log.d(TAG, "Delaying calibration for later");
                                                    JoH.static_toast_long("Waiting for 15 minutes more sensor data for calibration");
                                                }
                                            } else {
                                                if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations")) {
                                                    // manual calibration
                                                    Home.startHomeWithExtra(xdrip.getAppContext(),
                                                            Home.BLUETOOTH_METER_CALIBRATION,
                                                            BgGraphBuilder.unitized_string_static(lastBloodTest.mgdl),
                                                            Long.toString(time_since),
                                                            "manual");
                                                } else {
                                                    Log.d(TAG, "Not flat enough slope for auto calibration and manual calibration not enabled");
                                                }
                                            }
                                        }
                                    }, 500);
                                } else {
                                    UserError.Log.e(TAG, "evaluateLastRecords: meter reading is at least as old as last calibration - ignoring");
                                }
                            } else {
                                UserError.Log.e(TAG, "evaluateLastRecords: meter reading is too far in the past: " + JoH.dateTimeText(lastBloodTest.timestamp));
                            }
                        } else {
                            UserError.Log.e(TAG, "evaluateLastRecords: time is in the future - ignoring");
                        }
                    }
                }
            } else {
                UserError.Log.d(TAG, "evaluateLastRecords: sequence isn't newer");
            }
        } else {
            UserError.Log.e(TAG, "evaluateLastRecords: Data missing for evaluation");
        }
    } else {
        UserError.Log.e(TAG, "evaluateLastRecords: lastBloodTest is Null!!");
    }
}