use of com.getpebble.android.kit.util.PebbleDictionary in project xDrip-plus by jamorham.
the class PebbleDisplayStandard method sendDownload.
public void sendDownload() {
if (PebbleKit.isWatchConnected(this.context)) {
PebbleDictionary dictionary = buildDictionary();
if (dictionary != null && this.context != null) {
Log.d(TAG, "sendDownload: Sending data to pebble");
sendDataToPebble(dictionary);
last_time_seen = JoH.ts();
}
} else {
watchdog();
}
}
use of com.getpebble.android.kit.util.PebbleDictionary in project xDrip-plus by jamorham.
the class PebbleDisplayTrend method buildDictionary.
public void buildDictionary() {
TimeZone tz = TimeZone.getDefault();
Date now = new Date();
int offsetFromUTC = tz.getOffset(now.getTime());
if (dictionary == null) {
dictionary = new PebbleDictionary();
}
// check for alerts
boolean alerting = ActiveBgAlert.currentlyAlerting();
alerting = alerting && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("pebble_vibe_alerts", true);
if (alerting) {
dictionary.addInt8(VIBE_KEY, (byte) 0x03);
} else {
dictionary.addInt8(VIBE_KEY, (byte) 0x00);
}
if (mBgReading != null) {
Log.v(TAG, "buildDictionary: slopeOrdinal-" + slopeOrdinal() + " bgReading-" + bgReading() + " now-" + (int) now.getTime() / 1000 + " bgTime-" + (int) (mBgReading.timestamp / 1000) + " phoneTime-" + (int) (new Date().getTime() / 1000) + " bgDelta-" + bgDelta());
no_signal = ((new Date().getTime()) - (60000 * 16) - mBgReading.timestamp > 0);
if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("pebble_show_arrows", true)) {
dictionary.addString(ICON_KEY, "0");
} else {
dictionary.addString(ICON_KEY, slopeOrdinal());
}
if (no_signal) {
dictionary.addString(BG_KEY, "?RF");
if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("pebble_vibrate_no_signal", true)) {
if (!alerting)
dictionary.addInt8(VIBE_KEY, (byte) 0x01);
}
} else {
dictionary.addString(BG_KEY, bgReading());
if (!alerting)
dictionary.addInt8(VIBE_KEY, (byte) 0x00);
}
dictionary.addUint32(RECORD_TIME_KEY, (int) (((mBgReading.timestamp + offsetFromUTC) / 1000)));
if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("pebble_show_delta", true)) {
if (no_signal) {
dictionary.addString(BG_DELTA_KEY, "No Signal");
} else {
dictionary.addString(BG_DELTA_KEY, bgDelta());
}
} else {
dictionary.addString(BG_DELTA_KEY, "");
}
String msg = PreferenceManager.getDefaultSharedPreferences(mContext).getString("pebble_special_value", "");
if (bgReading().compareTo(msg) == 0) {
dictionary.addString(MESSAGE_KEY, PreferenceManager.getDefaultSharedPreferences(mContext).getString("pebble_special_text", "BAZINGA!"));
} else {
dictionary.addString(MESSAGE_KEY, "");
}
} else {
Log.v(TAG, "buildDictionary: latest mBgReading is null, so sending default values");
dictionary.addString(ICON_KEY, slopeOrdinal());
dictionary.addString(BG_KEY, "?SN");
// dictionary.addString(BG_KEY, bgReading());
dictionary.addUint32(RECORD_TIME_KEY, (int) ((new Date().getTime() + offsetFromUTC / 1000)));
dictionary.addString(BG_DELTA_KEY, "No Sensor");
dictionary.addString(MESSAGE_KEY, "");
}
dictionary.addUint32(PHONE_TIME_KEY, (int) ((new Date().getTime() + offsetFromUTC) / 1000));
if (PreferenceManager.getDefaultSharedPreferences(mContext).getString("dex_collection_method", "DexbridgeWixel").compareTo("DexbridgeWixel") == 0 && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("display_bridge_battery", true)) {
dictionary.addString(UPLOADER_BATTERY_KEY, bridgeBatteryString());
dictionary.addString(NAME_KEY, "Bridge");
} else {
dictionary.addString(UPLOADER_BATTERY_KEY, phoneBattery());
dictionary.addString(NAME_KEY, "Phone");
}
}
use of com.getpebble.android.kit.util.PebbleDictionary in project android-uploader by nightscout.
the class WearableTest method createMockPebbleDictionary.
private PebbleDictionary createMockPebbleDictionary() {
PebbleDictionary dict = new PebbleDictionary();
dict.addString(0, String.valueOf(TrendArrow.FLAT.ordinal()));
dict.addString(1, "100");
dict.addUint32(2, 1417990743);
dict.addUint32(3, 1417990743);
dict.addString(4, "0");
dict.addString(5, "100");
dict.addString(6, "Bob");
return dict;
}
use of com.getpebble.android.kit.util.PebbleDictionary in project xDrip by NightscoutFoundation.
the class PebbleDisplayStandard method buildDictionary.
private PebbleDictionary buildDictionary() {
PebbleDictionary dictionary = new PebbleDictionary();
TimeZone tz = TimeZone.getDefault();
Date now = new Date();
int offsetFromUTC = tz.getOffset(now.getTime());
final String bgDelta = getBgDelta();
final String bgReadingS = getBgReading();
final String slopeOrdinal = getSlopeOrdinal();
if (use_best_glucose) {
Log.v(TAG, //
"buildDictionary: slopeOrdinal-" + slopeOrdinal + " bgReading-" + bgReadingS + " now-" + (int) now.getTime() / 1000 + " bgTime-" + //
(int) (dg.timestamp / 1000) + " phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta());
// no_signal = (dg.mssince > Home.stale_data_millis());
} else {
Log.v(TAG, //
"buildDictionary: slopeOrdinal-" + slopeOrdinal + " bgReading-" + bgReadingS + " now-" + (int) now.getTime() / 1000 + " bgTime-" + //
(int) (this.bgReading.timestamp / 1000) + " phoneTime-" + (int) (new Date().getTime() / 1000) + " getBgDelta-" + getBgDelta());
// no_signal = ((new Date().getTime()) - Home.stale_data_millis() - this.bgReading.timestamp > 0);
}
dictionary.addString(ICON_KEY, slopeOrdinal);
dictionary.addString(BG_KEY, bgReadingS);
if (use_best_glucose) {
dictionary.addUint32(RECORD_TIME_KEY, (int) (((dg.timestamp + offsetFromUTC) / 1000)));
} else {
dictionary.addUint32(RECORD_TIME_KEY, (int) (((this.bgReading.timestamp + offsetFromUTC) / 1000)));
}
dictionary.addUint32(PHONE_TIME_KEY, (int) ((new Date().getTime() + offsetFromUTC) / 1000));
dictionary.addString(BG_DELTA_KEY, bgDelta);
addBatteryStatusToDictionary(dictionary);
return dictionary;
}
use of com.getpebble.android.kit.util.PebbleDictionary in project xDrip by NightscoutFoundation.
the class PebbleWatchSync method init.
protected void init() {
Log.i(TAG, "Initialising...");
Log.i(TAG, "configuring PebbleDataReceiver for: " + currentWatchFaceUUID.toString());
PebbleKit.registerReceivedDataHandler(context, new PebbleKit.PebbleDataReceiver(currentWatchFaceUUID) {
@Override
public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
getActivePebbleDisplay().receiveData(transactionId, data);
}
});
PebbleKit.registerReceivedAckHandler(context, new PebbleKit.PebbleAckReceiver(currentWatchFaceUUID) {
@Override
public void receiveAck(Context context, int transactionId) {
getActivePebbleDisplay().receiveAck(transactionId);
}
});
PebbleKit.registerReceivedNackHandler(context, new PebbleKit.PebbleNackReceiver(currentWatchFaceUUID) {
@Override
public void receiveNack(Context context, int transactionId) {
getActivePebbleDisplay().receiveNack(transactionId);
}
});
PebbleKit.registerDataLogReceiver(context, new PebbleKit.PebbleDataLogReceiver(currentWatchFaceUUID) {
@Override
public void receiveData(Context context, UUID logUuid, Long timestamp, Long tag, int data) {
if (d)
Log.d(TAG, "receiveLogData: uuid:" + logUuid + " " + JoH.dateTimeText(timestamp * 1000) + " tag:" + tag + " data: " + data);
}
@Override
public void receiveData(Context context, UUID logUuid, Long timestamp, Long tag, Long data) {
Log.d(TAG, "receiveLogData: uuid:" + logUuid + " started: " + JoH.dateTimeText(timestamp * 1000) + " tag:" + tag + " data: " + data);
if (Pref.getBoolean("use_pebble_health", true)) {
if ((tag != null) && (data != null)) {
// alternator
final int s = ((int) (long) tag) & 0xfffffff7;
switch(s) {
case HEARTRATE_LOG:
if (data > sanity_timestamp) {
if (last_heartrate_timestamp > 0) {
Log.e(TAG, "Out of sequence heartrate timestamp received!");
}
last_heartrate_timestamp = data;
} else {
if (data > 0) {
if (last_heartrate_timestamp > 0) {
final HeartRate hr = new HeartRate();
hr.timestamp = last_heartrate_timestamp * 1000;
hr.bpm = (int) (long) data;
Log.d(TAG, "Saving HeartRate: " + hr.toS());
hr.saveit();
// reset state
last_heartrate_timestamp = 0;
} else {
Log.e(TAG, "Out of sequence heartrate value received!");
}
}
}
break;
case MOVEMENT_LOG:
if (data > sanity_timestamp) {
if (last_movement_timestamp > 0) {
Log.e(TAG, "Out of sequence movement timestamp received!");
}
last_movement_timestamp = data;
} else {
if (data > 0) {
if (last_movement_timestamp > 0) {
final StepCounter pm = StepCounter.createEfficientRecord(last_movement_timestamp * 1000, (int) (long) data);
Log.d(TAG, "Saving Movement: " + pm.toS());
// reset state
last_movement_timestamp = 0;
} else {
Log.e(TAG, "Out of sequence movement value received!");
}
}
}
break;
default:
Log.e(TAG, "Unknown pebble data log type received: " + s);
break;
}
} else {
Log.e(TAG, "Got null Long in receive data");
}
}
}
@Override
public void receiveData(Context context, UUID logUuid, Long timestamp, Long tag, byte[] data) {
if (d)
Log.d(TAG, "receiveLogData: uuid:" + logUuid + " " + JoH.dateTimeText(timestamp * 1000) + " tag:" + tag + " hexdata: " + JoH.bytesToHex(data));
}
@Override
public void onFinishSession(Context context, UUID logUuid, Long timestamp, Long tag) {
if (d)
Log.i(TAG, "Session " + tag + " finished!");
}
});
// control app
PebbleKit.registerReceivedDataHandler(context, new PebbleKit.PebbleDataReceiver(PEBBLE_CONTROL_APP_UUID) {
@Override
public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
getActivePebbleDisplay().receiveAppData(transactionId, data);
}
});
}
Aggregations