diff --git a/appinfo.json b/appinfo.json index c59d6dc..5a1d6cc 100644 --- a/appinfo.json +++ b/appinfo.json @@ -1,26 +1,29 @@ { - "uuid": "9f1e3aed-98f8-41ec-9bff-2c15fa4f3c24", - "shortName": "PbFaces", - "longName": "Pebble Faces", - "companyName": "MakeAwesomeHappen", - "versionCode": 3, - "versionLabel": "1.2", - "sdkVersion": "3", - "targetPlatforms": [ - "aplite", - "basalt" - ], - "watchapp": { - "watchface": false - }, - "appKeys": { - "NETDL_DATA": 1768777472, - "NETDL_BEGIN": 1768777473, - "NETDL_END": 1768777474, - "NETDL_CHUNK_SIZE": 1768777475, - "NETDL_URL": 1768777476 - }, - "resources": { - "media": [] - } + "appKeys": { + "NETDL_BEGIN": 1768777473, + "NETDL_CHUNK_SIZE": 1768777475, + "NETDL_DATA": 1768777472, + "NETDL_END": 1768777474, + "NETDL_URL": 1768777476 + }, + "capabilities": [ + "" + ], + "companyName": "MakeAwesomeHappen", + "longName": "Pebble Faces", + "projectType": "native", + "resources": { + "media": [] + }, + "sdkVersion": "3", + "shortName": "PbFaces", + "targetPlatforms": [ + "aplite", + "basalt" + ], + "uuid": "9f1e3aed-98f8-41ec-9bff-2c15fa4f3c24", + "versionLabel": "1.2", + "watchapp": { + "watchface": false + } } diff --git a/src/netdownload.c b/src/netdownload.c index 8d9bc62..db774a3 100644 --- a/src/netdownload.c +++ b/src/netdownload.c @@ -1,12 +1,14 @@ #include "netdownload.h" -NetDownloadContext* netdownload_create_context(NetDownloadCallback callback) { +NetDownloadContext* netdownload_create_context(NetDownloadCallback callback, CustomReceivedHandler custom_handler_callback, CustomErrorHandler custom_error_callback) { NetDownloadContext *ctx = malloc(sizeof(NetDownloadContext)); ctx->length = 0; ctx->index = 0; ctx->data = NULL; ctx->callback = callback; + ctx->custom_handler_callback = custom_handler_callback; + ctx->custom_error_callback = custom_error_callback; return ctx; } @@ -18,8 +20,8 @@ void netdownload_destroy_context(NetDownloadContext *ctx) { free(ctx); } -void netdownload_initialize(NetDownloadCallback callback) { - NetDownloadContext *ctx = netdownload_create_context(callback); +void netdownload_initialize(NetDownloadCallback callback, CustomReceivedHandler custom_handler_callback, CustomErrorHandler custom_error_callback) { + NetDownloadContext *ctx = netdownload_create_context(callback, custom_handler_callback, custom_error_callback); APP_LOG(APP_LOG_LEVEL_DEBUG, "NetDownloadContext = %p", ctx); app_message_set_context(ctx); @@ -27,7 +29,7 @@ void netdownload_initialize(NetDownloadCallback callback) { app_message_register_inbox_dropped(netdownload_dropped); app_message_register_outbox_sent(netdownload_out_success); app_message_register_outbox_failed(netdownload_out_failed); - APP_LOG(APP_LOG_LEVEL_DEBUG, "Max buffer sizes are %li / %li", app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); + APP_LOG(APP_LOG_LEVEL_DEBUG, "Max buffer sizes are in:%li / out:%li", app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); } @@ -111,7 +113,9 @@ void netdownload_receive(DictionaryIterator *iter, void *context) { } break; default: - APP_LOG(APP_LOG_LEVEL_WARNING, "Unknown key in dict: %lu", tuple->key); + APP_LOG(APP_LOG_LEVEL_WARNING, "Unknown key in dict: %lu, forwarding to custom handler", tuple->key); + if (ctx->custom_handler_callback != NULL) + ctx->custom_handler_callback(iter, context); break; } } @@ -137,7 +141,10 @@ char *translate_error(AppMessageResult result) { } void netdownload_dropped(AppMessageResult reason, void *context) { + NetDownloadContext *ctx = (NetDownloadContext*) context; APP_LOG(APP_LOG_LEVEL_ERROR, "Dropped message! Reason given: %s", translate_error(reason)); + if (ctx->custom_error_callback != NULL) + ctx->custom_error_callback(NULL, reason, context); } void netdownload_out_success(DictionaryIterator *iter, void *context) { @@ -145,6 +152,9 @@ void netdownload_out_success(DictionaryIterator *iter, void *context) { } void netdownload_out_failed(DictionaryIterator *iter, AppMessageResult reason, void *context) { + NetDownloadContext *ctx = (NetDownloadContext*) context; APP_LOG(APP_LOG_LEVEL_DEBUG, "Failed to send message. Reason = %s", translate_error(reason)); + if (ctx->custom_error_callback != NULL) + ctx->custom_error_callback(iter, reason, context); } diff --git a/src/netdownload.h b/src/netdownload.h index d354106..3bff859 100644 --- a/src/netdownload.h +++ b/src/netdownload.h @@ -1,3 +1,4 @@ +#pragma once #include /* The key used to transmit download data. Contains byte array. */ @@ -20,6 +21,8 @@ typedef struct { } NetDownload; typedef void (*NetDownloadCallback)(NetDownload *image); +typedef void (*CustomReceivedHandler)(DictionaryIterator *received, void *context); +typedef void (*CustomErrorHandler)(DictionaryIterator *iter, AppMessageResult reason, void *context); typedef struct { /* size of the data buffer allocated */ @@ -30,9 +33,13 @@ typedef struct { uint32_t index; /* Callback to call when we are done loading the data */ NetDownloadCallback callback; + /* Callback to call when received any other messages */ + CustomReceivedHandler custom_handler_callback; + /* Callback to call when any error occurs */ + CustomErrorHandler custom_error_callback; } NetDownloadContext; -NetDownloadContext* netdownload_create_context(NetDownloadCallback callback); +NetDownloadContext* netdownload_create_context(NetDownloadCallback callback, CustomReceivedHandler custom_handler_callback, CustomErrorHandler custom_error_callback); void netdownload_initialize(); void netdownload_deinitialize(); diff --git a/src/pebble-faces.c b/src/pebble-faces.c index 9e1c42f..0a2df74 100644 --- a/src/pebble-faces.c +++ b/src/pebble-faces.c @@ -16,7 +16,7 @@ static char *images[] = { "http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-faces/thomas.png", "http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-faces/matt.png", "http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-faces/katharine.png", - "http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-faces/katherine.png", + "http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-faces/katherinexxx.png", "http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-faces/alex.png", "http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-faces/lukasz.png" }; @@ -68,7 +68,7 @@ void download_complete_handler(NetDownload *download) { printf("Heap free is %u bytes", heap_bytes_free()); #ifdef PBL_PLATFORM_APLITE - GBitmap *bmp = gbitmap_create_with_png_data(download->data, download->length); + GBitmap *bmp = gbitmap_create_with_png_data(download->data, download->length); #else GBitmap *bmp = gbitmap_create_from_png_data(download->data, download->length); #endif @@ -95,10 +95,19 @@ void tap_handler(AccelAxisType accel, int32_t direction) { show_next_image(); } +static void down_click_handler(ClickRecognizerRef recognizer, void *context) { + show_next_image(); +} + +static void click_config_provider(void *context) { + // Register the ClickHandlers + window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler); +} + static void init(void) { // Need to initialize this first to make sure it is there when // the window_load function is called by window_stack_push. - netdownload_initialize(download_complete_handler); + netdownload_initialize(download_complete_handler, NULL, NULL); window = window_create(); #ifdef PBL_SDK_2 @@ -109,6 +118,7 @@ static void init(void) { .unload = window_unload, }); const bool animated = true; + window_set_click_config_provider(window, click_config_provider); window_stack_push(window, animated); accel_tap_service_subscribe(tap_handler);