Skip to content
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ Alerts have been removed except for the falling rate-of-change alerts.
This watch face is meant for patients to use with xDrip, not for parents/carers.
All notifications/alerts are generated within xDrip (except for falling rate-of-change).
Ensure you enable notifications from xDrip in the Pebble App, and enable Third Party notifications, otherwise these will NOT come through on the pebble.

<a href="https://ibb.co/dtUFdn"><img src="https://preview.ibb.co/eR5oyn/IMG_1238.jpg" alt="IMG_1238" border="0"></a>
<a href="https://ibb.co/kunXTA"><img src="https://preview.ibb.co/d5qVFq/IMG-1240.jpg" alt="IMG-1240" border="0"></a>

Choose "Standard Watchface (old)" in xDrip and activate "xdrip Statusline (watch)" in your ConfigBuilder of AAPS.
Then install this watchface manually over the existing one:
Activate the developer option in your pebble app and have a look at the given IP adress.
Switch to the main directory from terminal and execute:

export PEBBLE_PHONE="192.168.xxx.xxx"

pebble install
Binary file added build/xDrip-pebble-master.pbw
Binary file not shown.
Binary file removed build/xDrip-pebble.pbw
Binary file not shown.
127 changes: 84 additions & 43 deletions src/xdrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ TextLayer *watch_battlevel_layer = NULL;
TextLayer *time_watch_layer = NULL;
TextLayer *time_app_layer = NULL;
TextLayer *date_app_layer = NULL;
TextLayer *appicon_layer = NULL;

BitmapLayer *icon_layer = NULL;
BitmapLayer *appicon_layer = NULL;

GBitmap *icon_bitmap = NULL;
GBitmap *appicon_bitmap = NULL;
Expand Down Expand Up @@ -55,6 +55,8 @@ static uint32_t current_cgm_time = 0;
static uint32_t current_app_time = 0;
static char current_bg_delta[10];
static int converted_bgDelta = 0;
static char insulinOnBoard[6];
static char tempBasalRate[4];

// global BG snooze timer
static uint8_t lastAlertTime = 0;
Expand All @@ -75,7 +77,7 @@ static bool AppMsgInDropAlert = false;
static bool AppMsgOutFailAlert = false;
static bool BluetoothAlert = false;
static bool BT_timer_pop = false;
//static bool CGMOffAlert = false;
static bool CGMOffAlert = false;
static bool PhoneOffAlert = false;
static bool LowBatteryAlert = false;

Expand Down Expand Up @@ -174,7 +176,10 @@ enum CgmKey {
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 (Christine)
CGM_NAME_KEY = 0x6, // TUPLE_CSTRING, MAX 9 BYTES (Christine)
LOOP_TBR_KEY = 0xc, // Loop Data - Temp. Basal Rate
LOOP_IOB_KEY = 0xd // Loop Data - Insulin on Board

};
// TOTAL MESSAGE DATA 4x3+2+5+3+9 = 31 BYTES
// TOTAL KEY HEADER DATA (STRINGS) 4x6+2 = 26 BYTES
Expand Down Expand Up @@ -394,7 +399,7 @@ static void battery_handler(BatteryChargeState charge_state) {
if(charge_state.is_charging) {
#ifdef PBL_COLOR
//APP_LOG(APP_LOG_LEVEL_INFO, "COLOR DETECTED");
text_layer_set_text_color(watch_battlevel_layer, GColorDukeBlue);
text_layer_set_text_color(watch_battlevel_layer, GColorBlack);
text_layer_set_background_color(watch_battlevel_layer, GColorGreen);
#else
//APP_LOG(APP_LOG_LEVEL_INFO, "BW DETECTED");
Expand All @@ -404,17 +409,17 @@ static void battery_handler(BatteryChargeState charge_state) {
} else {
#ifdef PBL_COLOR
//APP_LOG(APP_LOG_LEVEL_INFO, "COLOR DETECTED");
if(charge_state.charge_percent > 40) {
if(charge_state.charge_percent > 30) {
//APP_LOG(APP_LOG_LEVEL_INFO, "BATTERY > 40");
text_layer_set_text_color(watch_battlevel_layer, GColorGreen);
} else if (charge_state.charge_percent > 20) {
} else if (charge_state.charge_percent > 10) {
//APP_LOG(APP_LOG_LEVEL_INFO, "BATTERY > 20");
text_layer_set_text_color(watch_battlevel_layer, GColorYellow);
} else {
//APP_LOG(APP_LOG_LEVEL_INFO, "BATTERY <= 20");
text_layer_set_text_color(watch_battlevel_layer, GColorRed);
}
text_layer_set_background_color(watch_battlevel_layer, GColorDukeBlue);
text_layer_set_background_color(watch_battlevel_layer, GColorBlack);
#else
//APP_LOG(APP_LOG_LEVEL_INFO, "BW DETECTED");
text_layer_set_text_color(watch_battlevel_layer, GColorWhite);
Expand Down Expand Up @@ -560,7 +565,7 @@ void handle_bluetooth_cgm(bool bt_connected) {
// erase cgm icon
//create_update_bitmap(&cgmicon_bitmap,cgmicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);
// turn phone icon off
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);
//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);
}

else {
Expand Down Expand Up @@ -687,12 +692,13 @@ void sync_error_callback_cgm(DictionaryResult appsync_dict_error, AppMessageResu
// erase cgm and app ago times
text_layer_set_text(cgmtime_layer, "");
text_layer_set_text(time_app_layer, "");
text_layer_set_text(appicon_layer, "");

// erase cgm icon
//create_update_bitmap(&cgmicon_bitmap,cgmicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);

// turn phone icon off
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);
//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);

// check if need to vibrate
if (!AppSyncErrAlert) {
Expand Down Expand Up @@ -764,12 +770,13 @@ void inbox_dropped_handler_cgm(AppMessageResult appmsg_indrop_error, void *conte
// erase cgm and app ago times
text_layer_set_text(cgmtime_layer, "");
text_layer_set_text(time_app_layer, "");
text_layer_set_text(appicon_layer, "");

// erase cgm icon
//create_update_bitmap(&cgmicon_bitmap,cgmicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);

// turn phone icon off
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);
//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);

// check if need to vibrate
if (!AppMsgInDropAlert) {
Expand Down Expand Up @@ -848,7 +855,7 @@ void outbox_failed_handler_cgm(DictionaryIterator *failed, AppMessageResult appm
//create_update_bitmap(&cgmicon_bitmap,cgmicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);

// turn phone icon off
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);
//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);

// check if need to vibrate
if (!AppMsgOutFailAlert) {
Expand Down Expand Up @@ -1363,11 +1370,12 @@ static void load_apptime(){
// check for init or error code
if (current_app_time == 0) {
text_layer_set_text(time_app_layer, "");
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);
text_layer_set_text(appicon_layer, "");
//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);
}
else {
// set phone on icon
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEON_ICON_INDX]);
//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEON_ICON_INDX]);

//time_now = time(NULL);
time_now = time(NULL);
Expand Down Expand Up @@ -1405,21 +1413,22 @@ static void load_apptime(){
strcat(formatted_app_timeago, app_label_buffer);
}
else {
strncpy (formatted_app_timeago, "ERR", TIMEAGO_BUFFER_SIZE);
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);
//strncpy (formatted_app_timeago, "ERR", TIMEAGO_BUFFER_SIZE);
;;//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[NONE_TIMEAGO_ICON_INDX]);
}

#if DEBUG_LEVEL > 0
APP_LOG(APP_LOG_LEVEL_DEBUG, "LOAD APPTIME, FORMATTED APP TIMEAGO STRING: %s", formatted_app_timeago);
#endif
text_layer_set_text(time_app_layer, formatted_app_timeago);

//text_layer_set_text(time_app_layer, formatted_app_timeago);
text_layer_set_text(time_app_layer, tempBasalRate);
text_layer_set_text(appicon_layer, insulinOnBoard);
//APP_LOG(APP_LOG_LEVEL_INFO, "LOAD APPTIME, CHECK FOR PHONE OFF ICON");
// check to see if we need to set phone off icon
//APP_LOG(APP_LOG_LEVEL_DEBUG, "LOAD APPTIME, app_timeago_diff: %d, PHONEOUT_WAIT_MIN: %d, app_label_buffer: %s", app_timeago_diff, PHONEOUT_WAIT_MIN, app_label_buffer);
if ( (app_timeago_diff >= PHONEOUT_WAIT_MIN) || ( (strcmp(app_label_buffer, "") != 0) && (strcmp(app_label_buffer, "m") != 0) ) ) {
// set phone off icon
create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);
//create_update_bitmap(&appicon_bitmap,appicon_layer,TIMEAGO_ICONS[PHONEOFF_ICON_INDX]);

// erase cgm ago times and cgm icon
text_layer_set_text(cgmtime_layer, "");
Expand Down Expand Up @@ -1590,7 +1599,7 @@ static void load_bg_delta() {
if((currentBG_isMMOL && current_bg == 55) || (!currentBG_isMMOL && (current_bg == 100 || current_bg == 99))) {
text_layer_set_text(message_layer, "BAZINGA!");
#ifdef PBL_COLOR
text_layer_set_text_color(message_layer, GColorDukeBlue);
text_layer_set_text_color(message_layer, GColorBlack);
#endif
} else {

Expand Down Expand Up @@ -1706,6 +1715,7 @@ void sync_tuple_changed_callback_cgm(const uint32_t key, const Tuple* new_tuple,
// CODE START

switch (key) {


case CGM_ICON_KEY:;
#if DEBUG_LEVEL > 0
Expand Down Expand Up @@ -1767,6 +1777,18 @@ void sync_tuple_changed_callback_cgm(const uint32_t key, const Tuple* new_tuple,
//APP_LOG(APP_LOG_LEVEL_INFO, "SYNC TUPLE: T1D NAME");
//text_layer_set_text(t1dname_layer, new_tuple->value->cstring);
break; // break for CGM_NAME_KEY

case LOOP_IOB_KEY:;
//APP_LOG(APP_LOG_LEVEL_INFO, "SYNC TUPLE: IOB CURRENT");
strncpy(insulinOnBoard, new_tuple->value->cstring, BG_MSGSTR_SIZE);
load_apptime();
break; // break for LOOP_IOB_KEY

case LOOP_TBR_KEY:;
//APP_LOG(APP_LOG_LEVEL_INFO, "SYNC TUPLE: TBR CURRENT");
strncpy(tempBasalRate, new_tuple->value->cstring, BG_MSGSTR_SIZE);
load_apptime();
break; // break for LOOP_TBR_KEY
} // end switch(key)

} // end sync_tuple_changed_callback_cgm()
Expand Down Expand Up @@ -1886,53 +1908,68 @@ void window_load_cgm(Window *window_cgm) {

// DELTA BG
#ifdef PBL_COLOR
message_layer = text_layer_create(GRect(0, 33, 144, 50));
text_layer_set_text_color(message_layer, GColorDukeBlue);
message_layer = text_layer_create(GRect(0,30, 144, 55));
text_layer_set_text_color(message_layer, GColorBlack);
text_layer_set_background_color(message_layer, GColorWhite);
text_layer_set_font(message_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
#else
message_layer = text_layer_create(GRect(0, 33, 144, 55));
text_layer_set_text_color(message_layer, GColorBlack);
text_layer_set_background_color(message_layer, GColorWhite);
text_layer_set_font(message_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
text_layer_set_font(message_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
#endif
text_layer_set_text_alignment(message_layer, GTextAlignmentCenter);
layer_add_child(window_layer_cgm, text_layer_get_layer(message_layer));

// ARROW OR SPECIAL VALUE
icon_layer = bitmap_layer_create(GRect(85, -7, 78, 50));
icon_layer = bitmap_layer_create(GRect(85, -9, 78, 50));
bitmap_layer_set_alignment(icon_layer, GAlignTopLeft);
bitmap_layer_set_background_color(icon_layer, GColorWhite);
layer_add_child(window_layer_cgm, bitmap_layer_get_layer(icon_layer));

// APP TIME AGO ICON
#ifdef PBL_COLOR
/*#ifdef PBL_COLOR
appicon_layer = bitmap_layer_create(GRect(118, 63, 40, 24));
#else
appicon_layer = bitmap_layer_create(GRect(118, 63, 40, 24));
#endif
bitmap_layer_set_alignment(appicon_layer, GAlignLeft);
bitmap_layer_set_background_color(appicon_layer, GColorWhite);
layer_add_child(window_layer_cgm, bitmap_layer_get_layer(appicon_layer));

// APP TIME AGO READING
*/

// APP TIME AGO READING (CHANGED TO TBR FOR LOOPING)
#ifdef PBL_COLOR
time_app_layer = text_layer_create(GRect(77, 58, 40, 24));
text_layer_set_text_color(time_app_layer, GColorDukeBlue);
appicon_layer = text_layer_create(GRect(80, 54, 60, 28));
text_layer_set_text_color(appicon_layer, GColorBlack);
text_layer_set_background_color(appicon_layer, GColorWhite);
#else
appicon_layer = text_layer_create(GRect(80, 54, 60, 28));
text_layer_set_text_color(appicon_layer, GColorBlack);
text_layer_set_background_color(appicon_layer, GColorClear);
#endif
text_layer_set_font(appicon_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
text_layer_set_text_alignment(appicon_layer, GTextAlignmentRight);
layer_add_child(window_layer_cgm, text_layer_get_layer(appicon_layer));

// APP TIME AGO READING (CHANGED TO IOB FOR LOOPING)
#ifdef PBL_COLOR
time_app_layer = text_layer_create(GRect(43, 54, 60, 28));
text_layer_set_text_color(time_app_layer, GColorBlack);
text_layer_set_background_color(time_app_layer, GColorWhite);
#else
time_app_layer = text_layer_create(GRect(77, 58, 40, 24));
time_app_layer = text_layer_create(GRect(43, 54, 60, 28));
text_layer_set_text_color(time_app_layer, GColorBlack);
text_layer_set_background_color(time_app_layer, GColorClear);
#endif
text_layer_set_font(time_app_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
text_layer_set_text_alignment(time_app_layer, GTextAlignmentRight);
text_layer_set_font(time_app_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
text_layer_set_text_alignment(time_app_layer, GTextAlignmentLeft);
layer_add_child(window_layer_cgm, text_layer_get_layer(time_app_layer));

// BG
#ifdef PBL_COLOR
bg_layer = text_layer_create(GRect(0, -5, 95, 47));
text_layer_set_text_color(bg_layer, GColorDukeBlue);
bg_layer = text_layer_create(GRect(0, -7, 95, 47));
text_layer_set_text_color(bg_layer, GColorBlack);
text_layer_set_background_color(bg_layer, GColorWhite);
#else
bg_layer = text_layer_create(GRect(0, -5, 95, 47));
Expand All @@ -1946,23 +1983,23 @@ void window_load_cgm(Window *window_cgm) {

// CGM TIME AGO READING
#ifdef PBL_COLOR
cgmtime_layer = text_layer_create(GRect(5, 58, 40, 24));
text_layer_set_text_color(cgmtime_layer, GColorDukeBlue);
cgmtime_layer = text_layer_create(GRect(5, 54, 40, 28));
text_layer_set_text_color(cgmtime_layer, GColorBlack);
text_layer_set_background_color(cgmtime_layer, GColorWhite);
#else
cgmtime_layer = text_layer_create(GRect(5, 58, 40, 24));
cgmtime_layer = text_layer_create(GRect(5, 54, 40, 28));
text_layer_set_text_color(cgmtime_layer, GColorBlack);
text_layer_set_background_color(cgmtime_layer, GColorClear);
#endif
text_layer_set_font(cgmtime_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
text_layer_set_font(cgmtime_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
text_layer_set_text_alignment(cgmtime_layer, GTextAlignmentLeft);
layer_add_child(window_layer_cgm, text_layer_get_layer(cgmtime_layer));

// PHONE BATTERY LEVEL
#ifdef PBL_COLOR
battlevel_layer = text_layer_create(GRect(0, 150, 80, 18));
text_layer_set_text_color(battlevel_layer, GColorGreen);
text_layer_set_background_color(battlevel_layer, GColorDukeBlue);
text_layer_set_background_color(battlevel_layer, GColorBlack);
#else
battlevel_layer = text_layer_create(GRect(0, 148, 59, 18));
text_layer_set_text_color(battlevel_layer, GColorWhite);
Expand Down Expand Up @@ -1992,7 +2029,7 @@ void window_load_cgm(Window *window_cgm) {
#ifdef PBL_COLOR
time_watch_layer = text_layer_create(GRect(0, 82, 144, 44));
text_layer_set_text_color(time_watch_layer, GColorWhite);
text_layer_set_background_color(time_watch_layer, GColorDukeBlue);
text_layer_set_background_color(time_watch_layer, GColorBlack);
#else
time_watch_layer = text_layer_create(GRect(0, 82, 144, 44));
text_layer_set_text_color(time_watch_layer, GColorWhite);
Expand All @@ -2006,9 +2043,9 @@ void window_load_cgm(Window *window_cgm) {
#ifdef PBL_COLOR
date_app_layer = text_layer_create(GRect(0, 124, 144, 26));
text_layer_set_text_color(date_app_layer, GColorWhite);
text_layer_set_background_color(date_app_layer, GColorDukeBlue);
text_layer_set_background_color(date_app_layer, GColorBlack);
#else
date_app_layer = text_layer_create(GRect(0, 120, 144, 29));
date_app_layer = text_layer_create(GRect(0, 120, 144, 25));
text_layer_set_text_color(date_app_layer, GColorWhite);
text_layer_set_background_color(date_app_layer, GColorClear);
#endif
Expand All @@ -2027,7 +2064,9 @@ void window_load_cgm(Window *window_cgm) {
TupletInteger(CGM_TAPP_KEY, 0),
TupletCString(CGM_DLTA_KEY, "LOAD"),
TupletCString(CGM_UBAT_KEY, " "),
TupletCString(CGM_NAME_KEY, " ")
TupletCString(CGM_NAME_KEY, " "),
TupletCString(LOOP_IOB_KEY, " "),
TupletCString(LOOP_TBR_KEY, " ")
};

//APP_LOG(APP_LOG_LEVEL_INFO, "WINDOW LOAD, ABOUT TO CALL APP SYNC INIT");
Expand Down Expand Up @@ -2059,7 +2098,7 @@ void window_unload_cgm(Window *window_cgm) {
//APP_LOG(APP_LOG_LEVEL_INFO, "WINDOW UNLOAD, DESTROY BITMAPS IF EXIST");
destroy_null_BitmapLayer(&icon_layer);
//destroy_null_BitmapLayer(&cgmicon_layer);
destroy_null_BitmapLayer(&appicon_layer);
destroy_null_TextLayer(&appicon_layer);
//destroy_null_BitmapLayer(&batticon_layer);

//APP_LOG(APP_LOG_LEVEL_INFO, "WINDOW UNLOAD, DESTROY TEXT LAYERS IF EXIST");
Expand All @@ -2072,6 +2111,8 @@ void window_unload_cgm(Window *window_cgm) {
destroy_null_TextLayer(&time_watch_layer);
destroy_null_TextLayer(&time_app_layer);
destroy_null_TextLayer(&date_app_layer);
destroy_null_TextLayer(&appicon_layer);


//APP_LOG(APP_LOG_LEVEL_INFO, "WINDOW UNLOAD, DESTROY INVERTER LAYERS IF EXIST");
//destroy_null_InverterLayer(&inv_battlevel_layer);
Expand Down