Search in sources :

Example 26 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class WatchUpdaterService method sendSensorData.

private boolean sendSensorData() {
    // KS
    try {
        if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
            googleApiClient.connect();
        }
        if (googleApiClient != null) {
            Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                if (wear_integration) {
                    DataMap dataMap = new DataMap();
                    Log.d(TAG, "Sensor sendSensorData uuid=" + sensor.uuid + " started_at=" + sensor.started_at + " active=" + Sensor.isActive() + " battery=" + sensor.latest_battery_level + " location=" + sensor.sensor_location + " stopped_at=" + sensor.stopped_at);
                    String json = sensor.toS();
                    Log.d(TAG, "dataMap sendSensorData GSON: " + json);
                    // MOST IMPORTANT LINE FOR TIMESTAMP
                    dataMap.putLong("time", new Date().getTime());
                    // KS
                    dataMap.putString("dex_txid", mPrefs.getString("dex_txid", "ABCDEF"));
                    dataMap.putLong("started_at", sensor.started_at);
                    dataMap.putString("uuid", sensor.uuid);
                    dataMap.putInt("latest_battery_level", sensor.latest_battery_level);
                    dataMap.putString("sensor_location", sensor.sensor_location);
                    new SendToDataLayerThread(WEARABLE_SENSOR_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
                    return true;
                }
            } else
                Log.e(TAG, "sendSensorData current sensor is null!");
        } else {
            Log.e(TAG, "sendSensorData No connection to wearable available for send Sensor!");
            return false;
        }
    } catch (NullPointerException e) {
        Log.e(TAG, "Nullpointer exception in sendWearCalibrationData: " + e);
        return false;
    }
    return true;
}
Also used : Date(java.util.Date) Sensor(com.eveningoutpost.dexdrip.Models.Sensor) DataMap(com.google.android.gms.wearable.DataMap)

Example 27 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class WixelReader method setSerialDataToTransmitterRawData.

private void setSerialDataToTransmitterRawData(int raw_data, int filtered_data, int sensor_battery_leve, Long CaptureTime) {
    final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_leve, CaptureTime);
    if (transmitterData != null) {
        final Sensor sensor = Sensor.currentSensor();
        if (sensor != null) {
            BgReading bgReading = BgReading.create(transmitterData.raw_data, filtered_data, null, CaptureTime);
            // sensor.latest_battery_level = (sensor.latest_battery_level!=0)?Math.min(sensor.latest_battery_level, transmitterData.sensor_battery_level):transmitterData.sensor_battery_level;
            // don't lock it only going downwards
            sensor.latest_battery_level = transmitterData.sensor_battery_level;
            sensor.save();
        } else {
            Log.d(TAG, "No Active Sensor, Data only stored in Transmitter Data");
        }
    }
}
Also used : TransmitterData(com.eveningoutpost.dexdrip.Models.TransmitterData) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 28 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class Blukon method processNewTransmitterData.

private static synchronized void processNewTransmitterData(TransmitterData transmitterData) {
    if (transmitterData == null) {
        Log.e(TAG, "Got duplicated data! Last BG at " + JoH.dateTimeText(m_timeLastBg));
        return;
    }
    final Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        Log.i(TAG, "processNewTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }
    DexCollectionService.last_transmitter_Data = transmitterData;
    Log.d(TAG, "BgReading.create: new BG reading at " + transmitterData.timestamp);
    BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
}
Also used : Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 29 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip by NightscoutFoundation.

the class Notifications method FileBasedNotifications.

/*
 * *************************************************************************************************************
 * Function for new notifications
 */
private void FileBasedNotifications(Context context) {
    ReadPerfs(context);
    Sensor sensor = Sensor.currentSensor();
    final BgReading bgReading = BgReading.last();
    if (bgReading == null) {
        // Sensor is stopped, or there is not enough data
        AlertPlayer.getPlayer().stopAlert(context, true, false);
        return;
    }
    final double calculated_value;
    /* KS TODO BestGlucose
        if (use_best_glucose) {
            this.dg = BestGlucose.getDisplayGlucose();
            if (dg != null) {
                bgReading.calculated_value = dg.mgdl;
                calculated_value = dg.mgdl;
            } else {
                calculated_value = bgReading.calculated_value;
                Log.wtf(TAG, "Could not obtain best glucose value!");
            }
        } else {*/
    calculated_value = bgReading.calculated_value;
    // }
    Log.d(TAG, "FileBasedNotifications called bgReading.calculated_value = " + bgReading.calculated_value + " calculated value: " + calculated_value);
    // In all this cases, bgReading.calculated_value should be 0.
    if (((sensor != null) || (Home.get_follower())) && calculated_value != 0) {
        AlertType newAlert = AlertType.get_highest_active_alert(context, calculated_value);
        if (newAlert == null) {
            Log.d(TAG, "FileBasedNotifications - No active notifcation exists, stopping all alerts");
            // No alert should work, Stop all alerts, but keep the snoozing...
            AlertPlayer.getPlayer().stopAlert(context, false, true);
            return;
        }
        AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();
        if (activeBgAlert == null) {
            Log.d(TAG, "FileBasedNotifications we have a new alert, starting to play it... " + newAlert.name);
            // We need to create a new alert  and start playing
            boolean trendingToAlertEnd = trendingToAlertEnd(context, true, newAlert);
            // KS EditAlertActivity.
            AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, unitsConvert2Disp(doMgdl, calculated_value));
            return;
        }
        if (activeBgAlert.uuid.equals(newAlert.uuid)) {
            // disable alert on stale data
            if (prefs.getBoolean("disable_alerts_stale_data", false)) {
                int minutes = Integer.parseInt(prefs.getString("disable_alerts_stale_data_minutes", "15")) + 2;
                if ((new Date().getTime()) - (60000 * minutes) - BgReading.lastNoSenssor().timestamp > 0) {
                    Log.d(TAG, "FileBasedNotifications : active alert found but not replaying it because more than three readings missed :  " + newAlert.name);
                    return;
                }
            }
            Log.d(TAG, "FileBasedNotifications we have found an active alert, checking if we need to play it " + newAlert.name);
            boolean trendingToAlertEnd = trendingToAlertEnd(context, false, newAlert);
            // KS EditAlertActivity
            AlertPlayer.getPlayer().ClockTick(context, trendingToAlertEnd, unitsConvert2Disp(doMgdl, calculated_value));
            return;
        }
        // Currently the ui blocks having two alerts with the same alert value.
        boolean alertSnoozeOver = ActiveBgAlert.alertSnoozeOver();
        if (alertSnoozeOver) {
            Log.d(TAG, "FileBasedNotifications we had two alerts, the snoozed one is over, we fall down to deleting the snoozed and staring the new");
        // in such case it is not important which is higher.
        } else {
            // we have a new alert. If it is more important than the previous one. we need to stop
            // the older one and start a new one (We need to play even if we were snoozed).
            // If it is a lower level alert, we should keep being snoozed.
            // Example, if we have two alerts one for 90 and the other for 80. and we were already alerting for the 80
            // and we were snoozed. Now bg is 85, the alert for 80 is cleared, but we are alerting for 90.
            // We should not do anything if we are snoozed for the 80...
            // If one allert was high and the second one is low however, we alarm in any case (snoozing ignored).
            boolean opositeDirection = AlertType.OpositeDirection(activeBgAlert, newAlert);
            if (!opositeDirection) {
                AlertType newHigherAlert = AlertType.HigherAlert(activeBgAlert, newAlert);
                if ((newHigherAlert == activeBgAlert)) {
                    // the existing (snoozed) alert is the higher, No need to play it since it is snoozed.
                    Log.d(TAG, "FileBasedNotifications The new alert has the same direcotion, it is lower than the one snoozed, not playing it." + " newHigherAlert = " + newHigherAlert.name + "activeBgAlert = " + activeBgAlert.name);
                    return;
                }
            }
        }
        // For now, we are stopping the old alert and starting a new one.
        Log.d(TAG, "Found a new alert, that is higher than the previous one will play it. " + newAlert.name);
        AlertPlayer.getPlayer().stopAlert(context, true, false);
        boolean trendingToAlertEnd = trendingToAlertEnd(context, true, newAlert);
        // KS EditAlertActivity
        AlertPlayer.getPlayer().startAlert(context, trendingToAlertEnd, newAlert, unitsConvert2Disp(doMgdl, calculated_value));
    } else {
        AlertPlayer.getPlayer().stopAlert(context, true, false);
    }
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Date(java.util.Date) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 30 with Sensor

use of com.eveningoutpost.dexdrip.Models.Sensor in project xDrip-plus by jamorham.

the class Ob1G5StateMachine method processNewTransmitterData.

// Save/process the data in xDrip style
private static synchronized void processNewTransmitterData(int raw_data, int filtered_data, int sensor_battery_level, long captureTime) {
    final TransmitterData transmitterData = TransmitterData.create(raw_data, filtered_data, sensor_battery_level, captureTime);
    if (transmitterData == null) {
        UserError.Log.e(TAG, "TransmitterData.create failed: Duplicate packet");
        return;
    } else {
        UserError.Log.d(TAG, "Created transmitter data " + transmitterData.uuid + " " + JoH.dateTimeText(transmitterData.timestamp));
    // TODO timeInMillisecondsOfLastSuccessfulSensorRead = captureTime;
    }
    Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        UserError.Log.e(TAG, "setSerialDataToTransmitterRawData: No Active Sensor, Data only stored in Transmitter Data");
        return;
    }
    // TODO : LOG if unfiltered or filtered values are zero
    Sensor.updateBatteryLevel(sensor, transmitterData.sensor_battery_level);
    if (d)
        UserError.Log.i(TAG, "timestamp create: " + Long.toString(transmitterData.timestamp));
    BgReading bgreading = BgReading.create(transmitterData.raw_data, transmitterData.filtered_data, xdrip.getAppContext(), transmitterData.timestamp);
    // KS
    UserError.Log.d(TAG, "Dex raw_data " + Double.toString(transmitterData.raw_data));
    // KS
    UserError.Log.d(TAG, "Dex filtered_data " + Double.toString(transmitterData.filtered_data));
    // KS
    UserError.Log.d(TAG, "Dex sensor_battery_level " + Double.toString(transmitterData.sensor_battery_level));
    // KS
    UserError.Log.d(TAG, "Dex timestamp " + JoH.dateTimeText(transmitterData.timestamp));
    UserError.Log.d(TAG, "BgReading created: " + bgreading.uuid + " " + JoH.dateTimeText(bgreading.timestamp));
// TODO static_last_timestamp =  transmitterData.timestamp;
}
Also used : TransmitterData(com.eveningoutpost.dexdrip.Models.TransmitterData) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Aggregations

Sensor (com.eveningoutpost.dexdrip.Models.Sensor)38 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)16 Date (java.util.Date)14 DataMap (com.google.android.gms.wearable.DataMap)12 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)8 TransmitterData (com.eveningoutpost.dexdrip.Models.TransmitterData)8 Gson (com.google.gson.Gson)6 GsonBuilder (com.google.gson.GsonBuilder)6 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)6 Paint (android.graphics.Paint)4 Point (android.graphics.Point)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Canvas (android.graphics.Canvas)2 ColorFilter (android.graphics.ColorFilter)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 DisplayMetrics (android.util.DisplayMetrics)2