Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eversense mod #5

Open
wants to merge 21 commits into
base: esel-for-patched-app
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Esel

1. Chose a phone where sqlite3 is available. Easiest solution: Use LineageOS
2. Root your phone (su needs to work - so allow it for this app in the developer options or whatever tool you use to manage access to su)
3. Install the Eversense app and use it as described by the vendor
4. Build https://github.com/AdrianLxM/Esel and install it on your phone.
5. Configuration:
1. Uninstall the Eversense App (Warning: your local historical data (older than 1 week) will be lost!)
2. Install the patched Eversense app (mod_com.senseonics.gen12androidapp-release.apk) and use it as described by the vendor
* You need to enable installation of Apps from unknown sources
* Start the Eversense App, login, connect to your transmitter and use it just like the normal app.
3. Build https://github.com/BernhardRo/Esel and install it on your phone.
4. Configuration:
* Allow ESEL to run in the background (it will ask for it)
* Don't touch the "DB Path" setting unless you changed the default data path when installing the Eversense app and know what you are doing!
* Upload to Nightscout: Activate "Send to NightScout" in the preferences. It needs a configured AndroidAPS with internal NSClient or NSClient itself installed on the same phone
* Inter-App-Broadcasts: Activate "Send to AAPS and xDrip". In xDrip and/or AndroidAPS activate the input method "640g/Eversense".
* As this app is very experimental, please contact @AdrianLxM for positive/negative feedback and to register for future updates.
6. For the modification of the Eversense App, see: https://github.com/BernhardRo/Esel/wiki/How-to-modify-the-Android-Eversense-App
* "Smooth Data" applies a smoothing algorithm to the raw values and provides these smoothed values instead of the raw readings. Smoothing is per default disabled.
* For feedback contact @BernhardRo
4. For the modification of the Eversense App, see: https://github.com/BernhardRo/Esel/wiki/How-to-modify-the-Android-Eversense-App

If you run esel with a fresh installation of Eversense for the first time, it can take up to 15min until your first values appear in xDrip!
18 changes: 18 additions & 0 deletions apk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Eversense

1. Uninstall the Eversense App (Warning: your local historical data (older than 1 week) will be lost!)
2. Install the patched Eversense app (mod_com.senseonics.gen12androidapp-release.apk) and use it as described by the vendor
* You need to enable installation of Apps from unknown sources
* Start the Eversense App, login, connect to your transmitter and use it just like the normal app.
3. Install esel.apk on your phone.
4. Configuration:
* Allow ESEL to run in the background (it will ask for it)
* Upload to Nightscout: Activate "Send to NightScout" in the preferences. It needs a configured AndroidAPS with internal NSClient or NSClient itself installed on the same phone
* Inter-App-Broadcasts: Activate "Send to AAPS and xDrip". In xDrip and/or AndroidAPS activate the input method "640g/Eversense".
* "Smooth Data" applies a smoothing algorithm to the raw values and provides these smoothed values instead of the raw readings. Smoothing is per default disabled.
5. Install xDrip: https://jamorham.github.io/#xdrip-plus (Download latest APK)
* Use as Datasource 640G / EverSense

If you run esel with a fresh installation of Eversense for the first time, it can take up to 15min until your first values appear in xDrip!


Binary file added apk/esel.apk
Binary file not shown.
Binary file not shown.
Binary file added app/debug/app-debug.apk
Binary file not shown.
Binary file added app/debug/esel.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/debug/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}]
Binary file added app/release/release/app.aab
Binary file not shown.
54 changes: 40 additions & 14 deletions app/src/main/java/esel/esel/esel/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
import esel.esel.esel.datareader.SGV;
import esel.esel.esel.preferences.Preferences;
import esel.esel.esel.preferences.PrefsFragment;
import esel.esel.esel.receivers.ReadReceiver;
import esel.esel.esel.util.LocalBroadcaster;
import esel.esel.esel.util.SP;
import esel.esel.esel.util.ToastUtils;

public class MainActivity extends MenuActivity {

private Button buttonReadValue;
private Button buttonSync;
private TextView textViewValue;

@Override
Expand All @@ -48,6 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
setupView(R.layout.activity_main);
askForBatteryOptimizationPermission();
buttonReadValue = (Button) findViewById(R.id.button_readvalue);
buttonSync = (Button) findViewById(R.id.button_manualsync);
textViewValue = (TextView) findViewById(R.id.textview_main);

/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
Expand All @@ -62,30 +65,53 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
try {
// String datastring = Datareader.readData();

List<SGV> valueArray = Datareader.readDataFromContentProvider(getBaseContext());
long currentTime = System.currentTimeMillis();

if(valueArray !=null && valueArray.size() > 0) {
SGV sgv = valueArray.get(0);
textViewValue.setText(sgv.toString());
LocalBroadcaster.broadcast(sgv);
long syncTime = 30 * 60 * 1000L;

List<SGV> valueArray = Datareader.readDataFromContentProvider(getBaseContext(), 6, currentTime - syncTime);

if (valueArray != null && valueArray.size() > 0) {
textViewValue.setText("");
for (int i = 0; i < valueArray.size(); i++) {
SGV sgv = valueArray.get(i);
textViewValue.append(sgv.toString() + "\n");
//LocalBroadcaster.broadcast(sgv);
}
} else {
ToastUtils.makeToast("DB not readable!");
}
//sgv.timestamp = System.currentTimeMillis();
//LocalBroadcaster.broadcast(sgv);

//} catch (IOException e) {
// e.printStackTrace();
//} catch (InterruptedException e) {
// e.printStackTrace();
}catch (Exception e){


}catch (android.database.CursorIndexOutOfBoundsException eb) {
eb.printStackTrace();
ToastUtils.makeToast("DB is empty!\nIt can take up to 15min with running Eversense App until values are available!");
} catch (Exception e) {
e.printStackTrace();
}
}
});

buttonSync.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int sync = 8;
try {

sync = SP.getInt("max-sync-hours", sync);

} catch (Exception e) {
e.printStackTrace();
}

ReadReceiver receiver = new ReadReceiver();
int written = receiver.FullSync(getBaseContext(), sync);
textViewValue.setText("Read " + written + " values from DB\n(last " + sync + " hours)");

}
});

}

private void askForBatteryOptimizationPermission() {
Expand Down
55 changes: 21 additions & 34 deletions app/src/main/java/esel/esel/esel/datareader/Datareader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,30 @@ public class Datareader {
public static String uriGlucose = "content://com.senseonics.gen12androidapp.glucose";
public static String uriTransmitter = "content://com.senseonics.gen12androidapp.transmitter";

public static List<SGV> readDataFromContentProvider(Context context) {

public static List<SGV> readDataFromContentProvider(Context context ) {
return readDataFromContentProvider(context, 2,0);
}

public static List<SGV> readDataFromContentProvider(Context context, int number, long lastReadingTime) {

Uri uri = Uri.parse(uriGlucose);;

String[] selection = {"timestamp","glucoseLevel"};

Cursor item = context.getContentResolver().query(uri, null, null, null, "timestamp desc LIMIT 2");
String where = null;
String sortOder = "timestamp asc LIMIT " + number;
if (lastReadingTime > 0) {
where = "timestamp > " + (lastReadingTime-1L);
}

Cursor item = context.getContentResolver().query(uri, null, where, null, sortOder);

String datastring = null;
boolean reverseorder = false;

if(item == null || item.getCount()==0){
item = context.getContentResolver().query(uri, null, null, null, "timestamp desc LIMIT 2");
reverseorder = true;
}

item.moveToFirst();

Expand Down Expand Up @@ -81,38 +94,12 @@ public static List<SGV> readDataFromContentProvider(Context context) {
// // Do work...
// } while (transmitter.moveToNext());

return valueArray;
}

public static String readData() throws IOException, InterruptedException {
Process p = Runtime.getRuntime().exec("su");
DataOutputStream dos = new DataOutputStream(p.getOutputStream());

BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(p.getInputStream()));
BufferedReader bufferedErrorReader = new BufferedReader(
new InputStreamReader(p.getErrorStream()));

String path = SP.getString("db-path-string", Esel.getsResources().getString(R.string.default_db_path));
dos.writeBytes("sqlite3 -csv " + path + " \"select timestamp, glucoseLevel from glucosereadings order by timestamp desc LIMIT 2;\"\n");
dos.writeBytes("exit\n");
dos.flush();
dos.close();
p.waitFor();
String data;

StringBuilder sb = new StringBuilder("");
while((data = bufferedErrorReader.readLine()) != null) {
sb.append(data + "\n");
if(reverseorder && valueArray.size()==2){
valueArray.add(valueArray.get(0));
valueArray.remove(0);
}

SP.putString("last-error", sb.toString());

if ((data = bufferedReader.readLine()) != null) {
return data;
} else {
return null;
}
return valueArray;
}

public static SGV generateSGV(String dataString){
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/esel/esel/esel/datareader/SGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.text.SimpleDateFormat;
import java.util.Date;

import esel.esel.esel.util.SP;

/**
* Created by adrian on 04/08/17.
*/
Expand Down Expand Up @@ -47,4 +49,25 @@ public void setDirection(double slope_by_minute) {
direction = "DoubleUp";
}
}

public void smooth(int last){
double smooth = this.value;

double lastSmooth = SP.getInt("readingSmooth",last*1000)/1000;
double factor = SP.getDouble("smooth_factor",0.3);
double correction = SP.getDouble("correction_factor",0.5);
int lastRaw = SP.getInt("lastReadingRaw", value);

SP.putInt("lastReadingRaw", this.value);

double a=lastSmooth+(factor*(this.value-lastSmooth));
smooth=a+correction*((lastRaw-lastSmooth)+(this.value-a))/2;

SP.putInt("readingSmooth",(int)Math.round(smooth*1000));

if(this.value > SP.getInt("lower_limit",65)){
this.value = (int)Math.round(smooth);
}

}
}
Loading