forked from StephenBlackWasAlreadyTaken/xDrip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set up option to broadcast to local pebble
- Loading branch information
1 parent
05c4125
commit c6d577d
Showing
9 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
app/src/main/java/com/eveningoutpost/dexdrip/UtilityModels/PebbleSync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.eveningoutpost.dexdrip.UtilityModels; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.os.BatteryManager; | ||
import android.util.Log; | ||
|
||
import com.eveningoutpost.dexdrip.Models.BgReading; | ||
import com.getpebble.android.kit.PebbleKit; | ||
import com.getpebble.android.kit.util.PebbleDictionary; | ||
|
||
import java.util.Date; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Created by THE NIGHTSCOUT PROJECT CONTRIBUTORS (and adapted to fit the needs of this project) | ||
*/ | ||
public class PebbleSync { | ||
// CGM_ICON_KEY = 0x0, // TUPLE_CSTRING, MAX 2 BYTES (10) | ||
// CGM_BG_KEY = 0x1, // TUPLE_CSTRING, MAX 4 BYTES (253 OR 22.2) | ||
// CGM_TCGM_KEY = 0x2, // TUPLE_INT, 4 BYTES (CGM TIME) | ||
// CGM_TAPP_KEY = 0x3, // TUPLE_INT, 4 BYTES (APP / PHONE TIME) | ||
// CGM_DLTA_KEY = 0x4, // TUPLE_CSTRING, MAX 5 BYTES (BG DELTA, -100 or -10.0) | ||
// CGM_UBAT_KEY = 0x5, // TUPLE_CSTRING, MAX 3 BYTES (UPLOADER BATTERY, 100) | ||
// CGM_NAME_KEY = 0x6 // TUPLE_CSTRING, MAX 9 BYTES (DexDrip) | ||
public static final UUID PEBBLEAPP_UUID = UUID.fromString("2c3f5ab3-7506-44e7-b8d0-2c63de32e1ec"); | ||
public static final int ICON_KEY = 0; | ||
public static final int BG_KEY = 1; | ||
public static final int RECORD_TIME_KEY = 2; | ||
public static final int PHONE_TIME_KEY = 3; | ||
public static final int BG_DELTA_KEY = 4; | ||
public static final int UPLOADER_BATTERY_KEY = 5; | ||
public static final int NAME_KEY = 6; | ||
|
||
private Context mContext; | ||
private BgGraphBuilder bgGraphBuilder; | ||
private BgReading mBgReading; | ||
|
||
public PebbleDictionary buildDictionary() { | ||
PebbleDictionary dictionary = new PebbleDictionary(); | ||
dictionary.addString(ICON_KEY, slopeOrdinal()); | ||
dictionary.addString(BG_KEY, bgReading()); | ||
dictionary.addUint32(RECORD_TIME_KEY, (int) mBgReading.timestamp); | ||
dictionary.addUint32(PHONE_TIME_KEY, (int) new Date().getTime()); | ||
dictionary.addString(BG_DELTA_KEY, bgDelta()); | ||
dictionary.addString(UPLOADER_BATTERY_KEY, phoneBattery()); | ||
dictionary.addString(NAME_KEY, "DexDrip"); | ||
return dictionary; | ||
} | ||
|
||
public void sendData(Context context, BgReading bgReading){ | ||
mContext = context; | ||
bgGraphBuilder = new BgGraphBuilder(mContext); | ||
mBgReading = BgReading.last(); | ||
sendDownload(buildDictionary()); | ||
} | ||
|
||
public String bgReading() { | ||
return bgGraphBuilder.unitized_string(mBgReading.calculated_value); | ||
} | ||
|
||
public String bgDelta() { | ||
String deltaString = bgGraphBuilder.unitized_string((mBgReading.calculated_value_slope * (5 * 60 * 1000))); | ||
if(mBgReading.calculated_value_slope > 0) { | ||
return ("+"+deltaString); | ||
} else { | ||
return deltaString; | ||
} | ||
} | ||
|
||
public String phoneBattery() { | ||
return String.valueOf(getBatteryLevel()); | ||
} | ||
|
||
public String bgUnit() { | ||
return bgGraphBuilder.unit(); | ||
} | ||
|
||
public void sendDownload(PebbleDictionary dictionary) { | ||
if (PebbleKit.isWatchConnected(mContext)) { | ||
if (dictionary != null && mContext != null) { | ||
Log.d("PEBBLE PUSHER", "Sending data to pebble"); | ||
PebbleKit.sendDataToPebble(mContext, PEBBLEAPP_UUID, dictionary); | ||
} | ||
} | ||
} | ||
|
||
public int getBatteryLevel() { | ||
Intent batteryIntent = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); | ||
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); | ||
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); | ||
if(level == -1 || scale == -1) { | ||
return 50; | ||
} | ||
return (int)(((float)level / (float)scale) * 100.0f); | ||
} | ||
|
||
public String slopeOrdinal(){ | ||
double slope_by_minute = mBgReading.calculated_value_slope * 60000; | ||
String arrow = "0"; | ||
if (slope_by_minute <= (-3.5)) { | ||
arrow = "7"; | ||
} else if (slope_by_minute <= (-2)) { | ||
arrow = "6"; | ||
} else if (slope_by_minute <= (-1)) { | ||
arrow = "5"; | ||
} else if (slope_by_minute <= (1)) { | ||
arrow = "4"; | ||
} else if (slope_by_minute <= (2)) { | ||
arrow = "3"; | ||
} else if (slope_by_minute <= (3.5)) { | ||
arrow = "2"; | ||
} else { | ||
arrow = "1"; | ||
} | ||
return arrow; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters