Search in sources :

Example 11 with Sensor

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

the class Home method setupCharts.

private void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);
    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) chart.getLayoutParams();
        params.topMargin = 130;
        chart.setLayoutParams(params);
    }
    chart.setBackgroundColor(getCol(X.color_home_chart_background));
    chart.setZoomType(ZoomType.HORIZONTAL);
    // Transmitter Battery Level
    final Sensor sensor = Sensor.currentSensor();
    // ????????? what about tomato here ?????
    if (sensor != null && sensor.latest_battery_level != 0 && !DexCollectionService.getBestLimitterHardwareName().equalsIgnoreCase("BlueReader") && sensor.latest_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW && !Pref.getBoolean("disable_battery_warning", false)) {
        Drawable background = new Drawable() {

            @Override
            public void draw(Canvas canvas) {
                DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
                int px = (int) (30 * (metrics.densityDpi / 160f));
                Paint paint = new Paint();
                paint.setTextSize(px);
                paint.setAntiAlias(true);
                paint.setColor(Color.parseColor("#FFFFAA"));
                paint.setStyle(Paint.Style.STROKE);
                paint.setAlpha(100);
                canvas.drawText(getString(R.string.transmitter_battery), 10, chart.getHeight() / 3 - (int) (1.2 * px), paint);
                if (sensor.latest_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_EMPTY) {
                    paint.setTextSize((int) (px * 1.5));
                    canvas.drawText(getString(R.string.very_low), 10, chart.getHeight() / 3, paint);
                } else {
                    canvas.drawText(getString(R.string.low), 10, chart.getHeight() / 3, paint);
                }
            }

            @Override
            public void setAlpha(int alpha) {
            }

            @Override
            public void setColorFilter(ColorFilter cf) {
            }

            @Override
            public int getOpacity() {
                // TODO Which pixel format should this be?
                return 0;
            }
        };
        chart.setBackground(background);
    }
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    chart.setLineChartData(bgGraphBuilder.lineData());
    chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(mActivity));
    previewChart.setBackgroundColor(getCol(X.color_home_chart_background));
    previewChart.setZoomType(ZoomType.HORIZONTAL);
    previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData()));
    previewChart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportCalculationEnabled(true);
    chart.setViewportChangeListener(new ChartViewPortListener());
    updateStuff = true;
    setViewport();
    if (small_height) {
        previewChart.setVisibility(View.GONE);
        // quick test
        Viewport moveViewPort = new Viewport(chart.getMaximumViewport());
        float tempwidth = (float) moveViewPort.width() / 4;
        holdViewport.left = moveViewPort.right - tempwidth;
        holdViewport.right = moveViewPort.right + (moveViewPort.width() / 24);
        holdViewport.top = moveViewPort.top;
        holdViewport.bottom = moveViewPort.bottom;
        chart.setCurrentViewport(holdViewport);
        previewChart.setCurrentViewport(holdViewport);
    } else {
        if (homeShelf.get("time_buttons")) {
            final long which_hour = PersistentStore.getLong("home-locked-hours");
            if (which_hour > 0) {
                hours = which_hour;
                setHoursViewPort();
            } else {
                hours = DEFAULT_CHART_HOURS;
            }
        } else {
            hours = DEFAULT_CHART_HOURS;
        }
        previewChart.setVisibility(homeShelf.get("chart_preview") ? View.VISIBLE : View.GONE);
    }
    if (insulinset || glucoseset || carbsset || timeset) {
        if (chart != null) {
            chart.setAlpha((float) 0.10);
        // TODO also set buttons alpha
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Viewport(lecho.lib.hellocharts.model.Viewport) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) Point(android.graphics.Point) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder) ColorFilter(android.graphics.ColorFilter) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 12 with Sensor

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

the class Home method naturalLanguageRecognition.

private void naturalLanguageRecognition(String allWords) {
    if (searchWords == null) {
        Toast.makeText(getApplicationContext(), "Word lexicon not loaded!", Toast.LENGTH_LONG).show();
        return;
    }
    Log.d(TAG, "Processing speech input allWords: " + allWords);
    thisuuid = "";
    int end = allWords.indexOf(" uuid ");
    if (end > 0) {
        thisuuid = (end > 0 ? allWords.substring(0, end) : "");
        allWords = allWords.substring(end + 6, allWords.length());
    }
    allWords = allWords.trim();
    // fix real times
    allWords = allWords.replaceAll(":", ".");
    // fix like 22mm
    allWords = allWords.replaceAll("(\\d)([a-zA-Z])", "$1 $2");
    // fix multi number order like blood 3.622 grams
    allWords = allWords.replaceAll("([0-9]\\.[0-9])([0-9][0-9])", "$1 $2");
    allWords = allWords.toLowerCase();
    Log.d(TAG, "Processing speech input allWords second: " + allWords + " UUID: " + thisuuid);
    if (allWords.contentEquals("delete last treatment") || allWords.contentEquals("cancel last treatment") || allWords.contentEquals("erase last treatment")) {
        Treatments.delete_last(true);
        updateCurrentBgInfo("delete last treatment");
    } else if ((allWords.contentEquals("delete all treatments")) || (allWords.contentEquals("delete all treatment"))) {
        Treatments.delete_all(true);
        updateCurrentBgInfo("delete all treatment");
    } else if (allWords.contentEquals("delete last calibration") || allWords.contentEquals("clear last calibration")) {
        Calibration.clearLastCalibration();
    } else if (allWords.contentEquals("force google reboot")) {
        SdcardImportExport.forceGMSreset();
    } else if (allWords.contentEquals("enable engineering mode")) {
        Pref.setBoolean("engineering_mode", true);
        JoH.static_toast(getApplicationContext(), "Engineering mode enabled - be careful", Toast.LENGTH_LONG);
    } else if (get_engineering_mode() && allWords.contentEquals("enable fake data source")) {
        Pref.setString(DexCollectionType.DEX_COLLECTION_METHOD, DexCollectionType.Mock.toString());
        JoH.static_toast_long("YOU ARE NOW USING FAKE DATA!!!");
    } else if (allWords.contentEquals("reset heart rate sync")) {
        PersistentStore.setLong("nightscout-rest-heartrate-synced-time", 0);
        JoH.static_toast_long("Cleared heart rate sync data");
    } else if (allWords.contentEquals("reset step count sync")) {
        PersistentStore.setLong("nightscout-rest-steps-synced-time", 0);
        JoH.static_toast_long("Cleared step count sync data");
    } else if (allWords.contentEquals("reset motion count sync")) {
        PersistentStore.setLong("nightscout-rest-motion-synced-time", 0);
        JoH.static_toast_long("Cleared motion count sync data");
    } else if (allWords.contentEquals("vehicle mode test")) {
        ActivityRecognizedService.spoofActivityRecogniser(mActivity, JoH.tsl() + "^" + 0);
        staticRefreshBGCharts();
    } else if (allWords.contentEquals("vehicle mode quit")) {
        ActivityRecognizedService.spoofActivityRecogniser(mActivity, JoH.tsl() + "^" + 3);
        staticRefreshBGCharts();
    } else if (allWords.contentEquals("vehicle mode walk")) {
        ActivityRecognizedService.spoofActivityRecogniser(mActivity, JoH.tsl() + "^" + 2);
        staticRefreshBGCharts();
    } else if (allWords.contentEquals("delete all glucose data")) {
        deleteAllBG(null);
        LibreAlarmReceiver.clearSensorStats();
    } else if (allWords.contentEquals("delete selected glucose meter") || allWords.contentEquals("delete selected glucose metre")) {
        Pref.setString("selected_bluetooth_meter_address", "");
    } else if (allWords.contentEquals("delete all finger stick data") || (allWords.contentEquals("delete all fingerstick data"))) {
        BloodTest.cleanup(-100000);
    } else if (allWords.contentEquals("delete all persistent store")) {
        SdcardImportExport.deletePersistentStore();
    } else if (allWords.contentEquals("delete uploader queue")) {
        UploaderQueue.emptyQueue();
    } else if (allWords.contentEquals("clear battery warning")) {
        try {
            final Sensor sensor = Sensor.currentSensor();
            if (sensor != null) {
                sensor.latest_battery_level = 0;
                sensor.save();
            }
        } catch (Exception e) {
        // do nothing
        }
    }
    // reset parameters for new speech
    watchkeypad = false;
    watchkeypadset = false;
    glucoseset = false;
    insulinset = false;
    carbsset = false;
    timeset = false;
    thisnumber = -1;
    thisword = "";
    final String[] wordsArray = allWords.split(" ");
    for (int i = 0; i < wordsArray.length; i++) {
        // per word in input stream
        try {
            double thisdouble = Double.parseDouble(wordsArray[i]);
            // if no exception
            thisnumber = thisdouble;
            handleWordPair();
        } catch (NumberFormatException nfe) {
            // detection of number or not
            final String result = classifyWord(wordsArray[i]);
            if (result != null)
                thisword = result;
            handleWordPair();
            if (thisword.equals("note")) {
                String note_text = "";
                for (int j = i + 1; j < wordsArray.length; j++) {
                    if (note_text.length() > 0)
                        note_text += " ";
                    note_text += wordsArray[j];
                }
                if (note_text.length() > 0) {
                    // TODO respect historic timeset?
                    Treatments.create_note(note_text, JoH.tsl());
                    staticRefreshBGCharts();
                    // don't process any more
                    break;
                }
            }
        }
    }
}
Also used : Paint(android.graphics.Paint) Point(android.graphics.Point) IOException(java.io.IOException) ParseException(java.text.ParseException) ActivityNotFoundException(android.content.ActivityNotFoundException) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 13 with Sensor

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

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 14 with Sensor

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

the class WatchUpdaterService method sendWearCalibrationData.

private static boolean sendWearCalibrationData(Integer count, long startTime, List<Calibration> list) {
    try {
        if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
            googleApiClient.connect();
        }
        // if ((googleApiClient != null) && (googleApiClient.isConnected())) {
        if (googleApiClient != null) {
            Log.d(TAG, "sendWearCalibrationData");
            final Sensor sensor = Sensor.currentSensor();
            final Calibration last = list != null && list.size() > 0 ? list.get(0) : Calibration.last();
            List<Calibration> latest;
            BgReading lastBgReading = BgReading.last();
            // From BgReading:     lastBgReading.calibration.rawValueOverride()
            if (list != null)
                latest = list;
            else if (startTime != 0)
                latest = Calibration.latestForGraphSensor(count, startTime, Long.MAX_VALUE);
            else if (lastBgReading != null && lastBgReading.calibration != null && lastBgReading.calibration_flag == true) {
                Log.d(TAG, "sendWearCalibrationData lastBgReading.calibration_flag=" + lastBgReading.calibration_flag + " lastBgReading.timestamp: " + lastBgReading.timestamp + " lastBgReading.calibration.timestamp: " + lastBgReading.calibration.timestamp);
                latest = Calibration.allForSensor();
            } else {
                latest = Calibration.latest(count);
            }
            if ((sensor != null) && (last != null) && (latest != null && !latest.isEmpty())) {
                Log.d(TAG, "sendWearCalibrationData latest count = " + latest.size());
                final DataMap entries = dataMap(last);
                final ArrayList<DataMap> dataMaps = new ArrayList<>(latest.size());
                if (sensor.uuid != null) {
                    for (Calibration bg : latest) {
                        if ((bg != null) && (bg.sensor_uuid != null) && (bg.sensor_uuid.equals(sensor.uuid))) {
                            dataMaps.add(dataMap(bg));
                        }
                    }
                }
                // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putLong("time", new Date().getTime());
                entries.putDataMapArrayList("entries", dataMaps);
                new SendToDataLayerThread(WEARABLE_CALIBRATION_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
            } else
                Log.d(TAG, "sendWearCalibrationData latest count = 0");
        } else {
            Log.e(TAG, "sendWearCalibrationData No connection to wearable available for send treatment!");
            return false;
        }
    } catch (NullPointerException e) {
        Log.e(TAG, "Nullpointer exception in sendWearCalibrationData: " + e);
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Calibration(com.eveningoutpost.dexdrip.Models.Calibration) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) Date(java.util.Date) Sensor(com.eveningoutpost.dexdrip.Models.Sensor) DataMap(com.google.android.gms.wearable.DataMap)

Example 15 with Sensor

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

the class WatchUpdaterService method syncTransmitterData.

private synchronized void syncTransmitterData(DataMap dataMap, boolean bBenchmark) {
    // KS
    Log.d(TAG, "syncTransmitterData");
    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastBG = 0;
    Log.d(TAG, "syncTransmitterData add BgReading Table");
    if (entries != null) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
        int idx = 0;
        int count = entries.size();
        Log.d(TAG, "syncTransmitterData add BgReading Table entries count=" + count);
        for (DataMap entry : entries) {
            if (entry != null) {
                // Log.d(TAG, "syncTransmitterData add BgReading Table entry=" + entry);
                idx++;
                String bgrecord = entry.getString("bgs");
                if (bgrecord != null) {
                    // for (TransmitterData bgData : bgs) {
                    // Log.d(TAG, "syncTransmitterData add TransmitterData Table bgrecord=" + bgrecord);
                    TransmitterData bgData = gson.fromJson(bgrecord, TransmitterData.class);
                    // TransmitterData bgData = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(bgrecord, TransmitterData.class);
                    TransmitterData exists = TransmitterData.getForTimestamp(bgData.timestamp);
                    TransmitterData uuidexists = TransmitterData.findByUuid(bgData.uuid);
                    timeOfLastBG = bgData.timestamp + 1;
                    if (exists != null || uuidexists != null) {
                        Log.d(TAG, "syncTransmitterData BG already exists for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                    } else {
                        Log.d(TAG, "syncTransmitterData add BG; does NOT exist for uuid=" + bgData.uuid + " timestamp=" + bgData.timestamp + " timeString=" + JoH.dateTimeText(bgData.timestamp) + " raw_data=" + bgData.raw_data);
                        if (!bBenchmark) {
                            bgData.save();
                            // Check
                            if (TransmitterData.findByUuid(bgData.uuid) != null)
                                Log.d(TAG, "syncTransmitterData: TransmitterData was saved for uuid:" + bgData.uuid);
                            else {
                                Log.e(TAG, "syncTransmitterData: TransmitterData was NOT saved for uuid:" + bgData.uuid);
                                return;
                            }
                            // KS the following is from G5CollectionService processNewTransmitterData()
                            Sensor sensor = Sensor.currentSensor();
                            if (sensor == null) {
                                Log.e(TAG, "syncTransmitterData: No Active Sensor, Data only stored in Transmitter Data");
                                return;
                            }
                            // TODO : LOG if unfiltered or filtered values are zero
                            Sensor.updateBatteryLevel(sensor, bgData.sensor_battery_level);
                            // android.util.Log.i
                            Log.i(TAG, "syncTransmitterData: BG timestamp create " + Long.toString(bgData.timestamp));
                            BgReading bgExists;
                            // KS TODO wear implements limited alerts, therefore continue to process all alerts on phone for last entry
                            if (count > 1 && idx < count) {
                                // Disable Notifications for bulk insert
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp, true);
                            } else {
                                bgExists = BgReading.create(bgData.raw_data, bgData.filtered_data, this, bgData.timestamp);
                            }
                            if (bgExists != null)
                                Log.d(TAG, "syncTransmitterData BG GSON saved BG: " + bgExists.toS());
                            else
                                Log.e(TAG, "syncTransmitterData BG GSON NOT saved");
                        }
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_BGS count=" + entries.size(), timeOfLastBG, bBenchmark ? "BM" : "BG", -1);
    }
}
Also used : TransmitterData(com.eveningoutpost.dexdrip.Models.TransmitterData) DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) BgReading(com.eveningoutpost.dexdrip.Models.BgReading) DataMap(com.google.android.gms.wearable.DataMap) 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