Skip to content

Commit

Permalink
Wear: more preparations for ob1 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Apr 21, 2018
1 parent df20ef5 commit 42ec5cc
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public static void sendBridgeBattery(int i) {

}

public static void requestSensorCalibrationsUpdate() {

}

}
3 changes: 3 additions & 0 deletions wear/src/main/java/com/eveningoutpost/dexdrip/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ private void checkBatteryOptimization() {
public static boolean get_master() {
return false;
}

public static void staticRefreshBGCharts() {
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,9 @@ private static void fixUpTable() {
}
patched = true;
}

public static void opportunisticCalibration() {
// stub placeholder on wear
}
}

16 changes: 16 additions & 0 deletions wear/src/main/java/com/eveningoutpost/dexdrip/Models/JoH.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.res.Configuration;
import android.graphics.Bitmap;
//KS import android.graphics.Canvas;
//KS import android.graphics.Color;
Expand Down Expand Up @@ -53,6 +54,7 @@
import android.view.View;
import android.widget.Toast;

import com.activeandroid.ActiveAndroid;
import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.R;
import com.eveningoutpost.dexdrip.UtilityModels.Constants;
Expand Down Expand Up @@ -1152,6 +1154,12 @@ public static void lockOrientation(Activity activity) {
}
}

public static boolean areWeRunningOnAndroidWear() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH
&& (xdrip.getAppContext().getResources().getConfiguration().uiMode
& Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH;
}

public static boolean isAirplaneModeEnabled(Context context) {
return Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
Expand Down Expand Up @@ -1526,4 +1534,12 @@ public static int parseIntWithDefault(String number, int radix, int defaultVal)
return defaultVal;
}
}

public static void clearCache() {
try {
ActiveAndroid.clearCache();
} catch (Exception e) {
Log.e(TAG, "Error clearing active android cache: " + e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.eveningoutpost.dexdrip.Models;

import com.eveningoutpost.dexdrip.utils.DexCollectionType;

/**
* Created by jamorham on 02/03/2018.
*
* Checks for whether sensor data is within a sane range
*
*/

public class SensorSanity {

public static final double DEXCOM_MIN_RAW = 5; // raw values below this will be treated as error
public static final double DEXCOM_MAX_RAW = 1000; // raw values above this will be treated as error

public static final double LIBRE_MIN_RAW = 5; // raw values below this will be treated as error

private static final String TAG = "SensorSanity";

public static boolean isRawValueSane(double raw_value) {
return isRawValueSane(raw_value, DexCollectionType.getDexCollectionType());
}

public static boolean isRawValueSane(double raw_value, DexCollectionType type) {
// passes by default!
boolean state = true;

// checks for each type of data source

if (DexCollectionType.hasDexcomRaw(type)) {
if (raw_value != BgReading.SPECIAL_G5_PLACEHOLDER) {
if (raw_value < DEXCOM_MIN_RAW) state = false;
else if (raw_value > DEXCOM_MAX_RAW) state = false;
}

} else if (DexCollectionType.hasLibre(type)) {
if (raw_value < LIBRE_MIN_RAW) state = false;
}

if (!state) {
if (JoH.ratelimit("sanity-failure", 20)) {
final String msg = "Sensor Raw Data Sanity Failure: " + raw_value;
UserError.Log.e(TAG, msg);
JoH.static_toast_long(msg);
}
}

return state;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class BgGraphBuilder {
private static final String TAG = BgGraphBuilder.class.getSimpleName();
public static final int FUZZER = (1000 * 30 * 5);
public final static double NOISE_TRIGGER = 10;
public final static double NOISE_TRIGGER_ULTRASENSITIVE = 1;
public final static double NOISE_TOO_HIGH_FOR_PREDICT = 60;
public final static double NOISE_HIGH = 200;
public final static double NOISE_FORGIVE = 100;
Expand Down Expand Up @@ -96,6 +97,8 @@ public class BgGraphBuilder {
public Viewport viewport;
public final static long DEXCOM_PERIOD = 300000;//KS from app / BgGraphBuilder.java
public static double last_noise = -99999;
public static double best_bg_estimate = -99999;
public static double last_bg_estimate = -99999;


public BgGraphBuilder(Context context){
Expand Down Expand Up @@ -681,4 +684,8 @@ public void onValueDeselected() {
// do nothing
}
}

public static void refreshNoiseIfOlderThan(long timestamp) {
// stub method for wear compatibility - update when noise calculations supported
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Constants {
public static final int G5_CALIBRATION_REJECT = 1008;
public static final int G5_START_REJECT = 1009;
public static final int G5_SENSOR_ERROR = 1010;
public static final int G5_SENSOR_FAILED = 1011;
public static final int G5_SENSOR_STARTED = 1012;

static final int NIGHTSCOUT_ERROR_NOTIFICATION_ID = 2001;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface Intents {
String EXTRA_NOISE_BLOCK_LEVEL = "com.eveningoutpost.dexdrip.Extras.NoiseBlockLevel";
String EXTRA_NS_NOISE_LEVEL = "com.eveningoutpost.dexdrip.Extras.NsNoiseLevel";
String XDRIP_DATA_SOURCE_DESCRIPTION = "com.eveningoutpost.dexdrip.Extras.SourceDesc";
String XDRIP_DATA_SOURCE_INFO = "com.eveningoutpost.dexdrip.Extras.SourceInfo";

String ACTION_REMOTE_CALIBRATION = "com.eveningoutpost.dexdrip.NewCalibration";
String ACTION_NEW_BG_ESTIMATE_NO_DATA = "com.eveningoutpost.dexdrip.BgEstimateNoData";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.eveningoutpost.dexdrip.utils;

// created by jamorham

import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

import com.activeandroid.Cache;
import com.eveningoutpost.dexdrip.Models.UserError;

import lombok.NonNull;


/* Wouldn't it be nice if you could search and replace inside an sqlite schema?
* That is what the SqliteRejigger is for!
*/

public class SqliteRejigger {

private static final String TAG = SqliteRejigger.class.getSimpleName();
private static final boolean d = false;

public static synchronized boolean rejigSchema(@NonNull String table_name, @NonNull String search, @NonNull String replace) {

final String temp_table = table_name + "_temp";

final String existing_schema = getSchema(table_name);

if (d) UserError.Log.d(TAG, existing_schema);

if (existing_schema.contains(search)) {
final String sql =
"PRAGMA foreign_keys=off;\n" +
"BEGIN TRANSACTION;\n" +
"DROP TABLE IF EXISTS " + temp_table + ";\n" +
"ALTER TABLE " + table_name + " RENAME TO " + temp_table + ";\n" +
existing_schema.replace(search, replace).replace("CREATE INDEX index_", "CREATE INDEX index__") +
"INSERT INTO " + table_name + " SELECT * FROM " + temp_table + ";\n" +
"DROP TABLE " + temp_table + ";\n" +
"COMMIT;\n" +
"PRAGMA foreign_keys=on;\n";
if (d) UserError.Log.d(TAG, sql);
try {
executeBatchSQL(sql);
UserError.Log.d(TAG, "Rejig probably successful for " + table_name + " " + replace);
return true;
} catch (SQLException e) {
UserError.Log.e(TAG, "Unable to rejig " + e + " on " + table_name + " " + replace);
return false;
}

} else {
UserError.Log.d(TAG, search + " not found in schema for " + table_name + " presumably this patch has already been applied");
return false;
}

}

private static void executeBatchSQL(String batch) throws SQLException {
final String[] statements = batch.split("\n");
final SQLiteDatabase db = Cache.openDatabase();
db.beginTransaction();
try {
for (String query : statements) {
db.execSQL(query);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}

private static String getSchema(String table_name) {
final StringBuilder sb = new StringBuilder();
final Cursor cursor = Cache.openDatabase().rawQuery("select sql from sqlite_master where type in ('table', 'index') and tbl_name = ?", new String[]{table_name});
while (cursor.moveToNext()) {
final String line = cursor.getString(0);
if (line != null) {
sb.append(line);
sb.append(";\n");
}
}
cursor.close();
return sb.toString();
}
}
2 changes: 2 additions & 0 deletions wear/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,6 @@
<string name="ok">OK</string>
<string name="enable_permission">Enable Permission</string>
<string name="tomato">Tomato</string>
<string name="space_minutes_ago">" Minutes ago"</string>
<string name="space_minute_ago">" Minute ago"</string>
</resources>

0 comments on commit 42ec5cc

Please sign in to comment.