From 95aa71ae7db0443924f00adf396feeafb709538b Mon Sep 17 00:00:00 2001 From: clach04 Date: Sun, 2 Feb 2020 12:20:25 -0800 Subject: [PATCH 01/16] Readme updated with text from app store description --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ec6249..66e9500 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,34 @@ # PebbleChecklist - A checklist—on your watch! -Thanks to the Pebble’s microphone and voice input, it’s now possible to keep track of anything on your wrist! Designed to stay out of your way, use Checklist to keep track of anything you need without needing to hold your phone. + +Thanks to the Pebble's microphone and voice input, it's now possible to keep track of anything on your wrist! Designed to stay out of your way, use Checklist to keep track of anything you need without needing to hold your phone—things to-do, shopping, and more! + Grocery shopping will never be the same. + +- Want to add multiple items at once? Just separate those items with periods or commas! (For example, saying "milk comma eggs comma cheese" will create 3 list items!) + + +- Don't want to use voice? Now you can enter items manually via your phone on the configuration page! + + + +"...only one app, a simple list-making app called Checklist, which uses the watch's microphone to add tasks, really proved useful." +—MIT Technology Review + +"I loved the convenience of adding items to the Checklist app just by speaking" +—Tom's Guide + + +****** + +Note: If voice isn't working, make sure your Pebble Time app is the newest version (3.6.1 on Android, 3.3.1 on iOS) and that your Pebble is running firmware 3.6 or higher. You can check under "Support" in the Pebble Time app. + + ## Want to try it? Grab it from the Rebble/Pebble app store: https://apps.rebble.io/en_US/application/5620e876768e7ada4e00007a?section=watchapps&dev_settings=true From f9f3a775bb9f75b017d3baf36b3c13454dd9ac74 Mon Sep 17 00:00:00 2001 From: clach04 Date: Sun, 2 Feb 2020 12:22:01 -0800 Subject: [PATCH 02/16] Mention and link to Rebble.io fr voice transcription --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 66e9500..5f434d7 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Grocery shopping will never be the same. Note: If voice isn't working, make sure your Pebble Time app is the newest version (3.6.1 on Android, 3.3.1 on iOS) and that your Pebble is running firmware 3.6 or higher. You can check under "Support" in the Pebble Time app. +In additon, ensure you are subscribed to a voice transcription service, for example http://rebble.io/ + ## Want to try it? Grab it from the Rebble/Pebble app store: From a26f23242be92b5109ee2200b6a8d92ddcff5831 Mon Sep 17 00:00:00 2001 From: clach04 Date: Thu, 6 Feb 2020 20:34:04 -0800 Subject: [PATCH 03/16] Replace utf-8 char with 7-bit us-ascii And newline cleanup --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5f434d7..d716e66 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # PebbleChecklist -A checklist—on your watch! +A checklist-on your watch! -Thanks to the Pebble's microphone and voice input, it's now possible to keep track of anything on your wrist! Designed to stay out of your way, use Checklist to keep track of anything you need without needing to hold your phone—things to-do, shopping, and more! +Thanks to the Pebble's microphone and voice input, it's now possible to keep track of anything on your wrist! Designed to stay out of your way, use Checklist to keep track of anything you need without needing to hold your phone-things to-do, shopping, and more! Grocery shopping will never be the same. @@ -18,10 +18,10 @@ Grocery shopping will never be the same. "...only one app, a simple list-making app called Checklist, which uses the watch's microphone to add tasks, really proved useful." -—MIT Technology Review +-MIT Technology Review "I loved the convenience of adding items to the Checklist app just by speaking" -—Tom's Guide +-Tom's Guide ****** @@ -32,5 +32,7 @@ In additon, ensure you are subscribed to a voice transcription service, for exam ## Want to try it? + Grab it from the Rebble/Pebble app store: + https://apps.rebble.io/en_US/application/5620e876768e7ada4e00007a?section=watchapps&dev_settings=true From 1d0d64748a3ae4ba16af0d93ab717c847c78f054 Mon Sep 17 00:00:00 2001 From: clach04 Date: Thu, 6 Feb 2020 21:38:43 -0800 Subject: [PATCH 04/16] Start of debug --- src/checklist.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/checklist.c b/src/checklist.c index 22b2356..f805e72 100644 --- a/src/checklist.c +++ b/src/checklist.c @@ -74,6 +74,8 @@ void read_data_from_storage() { // load checklist information from storage s_checklist_length = persist_read_int(PERSIST_KEY_CHECKLIST_LENGTH); s_checklist_num_checked = persist_read_int(PERSIST_KEY_CHECKLIST_NUM_CHECKED); + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 s_checklist_length: %d", (int) s_checklist_length); + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 s_checklist_num_checked: %d", (int) s_checklist_num_checked); // load the checklist by the block int num_blocks_required = s_checklist_length / s_items_per_block + 1; @@ -83,6 +85,9 @@ void read_data_from_storage() { &s_checklist_items[block * s_items_per_block], s_block_size); } + for(int i = 0; i < MAX_CHECKLIST_ITEMS; i++) { + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %s", (int) s_checklist_items[i].is_checked, s_checklist_items[i].name); + } } void save_data_to_storage() { From 9c0cb875a036a94c050249542255efb58f9db345 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 7 Feb 2020 05:49:32 +0000 Subject: [PATCH 05/16] Debug dump of all check notes to logging --- src/checklist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/checklist.c b/src/checklist.c index f805e72..a25715a 100644 --- a/src/checklist.c +++ b/src/checklist.c @@ -85,8 +85,9 @@ void read_data_from_storage() { &s_checklist_items[block * s_items_per_block], s_block_size); } - for(int i = 0; i < MAX_CHECKLIST_ITEMS; i++) { - APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %s", (int) s_checklist_items[i].is_checked, s_checklist_items[i].name); + // index 0 is the bottom of the list, higher numbers are top of list + for(int i = 0; i < MAX_CHECKLIST_ITEMS && strlen(s_checklist_items[i].name) > 0; i++) { + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %d %s", i, (int) s_checklist_items[i].is_checked, s_checklist_items[i].name); } } From 6e927ef88adab80e937bc2860c0f4626fd105859 Mon Sep 17 00:00:00 2001 From: clach04 Date: Thu, 6 Feb 2020 22:05:06 -0800 Subject: [PATCH 06/16] Add debug dump code to menu on long click/select --- src/windows/checklist_window.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/windows/checklist_window.c b/src/windows/checklist_window.c index 6c24e7b..4a93dd4 100644 --- a/src/windows/checklist_window.c +++ b/src/windows/checklist_window.c @@ -280,6 +280,22 @@ static void select_callback(struct MenuLayer *menu_layer, MenuIndex *cell_index, } } +static void select_long_callback(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context) { + if(cell_index->row == 0) { + // dump counts? export all non-checked? + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 select_long_callback() TOP checklist_get_num_items()=%d", checklist_get_num_items()); + } else if(cell_index->row == checklist_get_num_items() + 1) { + // dump all check, export all checked? + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 select_long_callback() BOTTOM (clear)"); + } else { + // Dump highlighted + int id = checklist_get_num_items() - (cell_index->row - 1) - 1; + + ChecklistItem *item = checklist_get_item_by_id(id); + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %d %s", id, (int) item->is_checked, item->.name); + } +} + static void window_load(Window *window) { checklist_init(); @@ -311,6 +327,7 @@ static void window_load(Window *window) { .draw_row = (MenuLayerDrawRowCallback)draw_row_callback, .get_cell_height = (MenuLayerGetCellHeightCallback)get_cell_height_callback, .select_click = (MenuLayerSelectCallback)select_callback, + .select_long_click = (MenuLayerSelectCallback)select_long_callback, }); window_set_background_color(window, BG_COLOR); From 62df27fdcace2aef9cc592635683678ebbfc833f Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 7 Feb 2020 06:10:34 +0000 Subject: [PATCH 07/16] Fix debug long press dump NOTE short press action occurs first --- src/windows/checklist_window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/checklist_window.c b/src/windows/checklist_window.c index 4a93dd4..ecb799e 100644 --- a/src/windows/checklist_window.c +++ b/src/windows/checklist_window.c @@ -292,7 +292,7 @@ static void select_long_callback(struct MenuLayer *menu_layer, MenuIndex *cell_i int id = checklist_get_num_items() - (cell_index->row - 1) - 1; ChecklistItem *item = checklist_get_item_by_id(id); - APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %d %s", id, (int) item->is_checked, item->.name); + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %d %s", id, (int) item->is_checked, item->name); } } From 16a4f4f49048ebeac5625645b9f68f8dd4e11971 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 7 Feb 2020 21:09:07 -0800 Subject: [PATCH 08/16] Update config URL for testing --- src/js/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/config.js b/src/js/config.js index 092fd2c..6278ffe 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -1,6 +1,6 @@ // var BASE_CONFIG_URL = 'http://localhost:4000/'; // var BASE_CONFIG_URL = 'http://192.168.0.103:4000/'; -var BASE_CONFIG_URL = 'http://freakified.github.io/PebbleChecklist/'; +var BASE_CONFIG_URL = 'http://clach04.github.io/PebbleChecklist/'; Pebble.addEventListener('ready', function(e) { console.log('JS component loaded!'); From 0da6c09fa19430d5e8baea4a0241b5b68797f1b6 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 7 Feb 2020 21:33:02 -0800 Subject: [PATCH 09/16] Add debug config site --- src/js/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/config.js b/src/js/config.js index 6278ffe..275102a 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -1,6 +1,6 @@ // var BASE_CONFIG_URL = 'http://localhost:4000/'; // var BASE_CONFIG_URL = 'http://192.168.0.103:4000/'; -var BASE_CONFIG_URL = 'http://clach04.github.io/PebbleChecklist/'; +var BASE_CONFIG_URL = 'http://clach04.github.io/pebble/checklist/'; Pebble.addEventListener('ready', function(e) { console.log('JS component loaded!'); From 80178d833151a286e27cb0ae7f9f57af7d543005 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 7 Feb 2020 21:36:35 -0800 Subject: [PATCH 10/16] Demo showing how to pass notes to config page --- src/js/config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/js/config.js b/src/js/config.js index 275102a..ac3c942 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -10,6 +10,8 @@ Pebble.addEventListener('ready', function(e) { Pebble.addEventListener('showConfiguration', function(e) { var configURL = BASE_CONFIG_URL + 'config.html'; + configURL = configURL + '?itemsToAdd=test,notes,here'; + Pebble.openURL(configURL); }); From 6a0642785994b2ffb20c292fafef96b6faac7780 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 7 Feb 2020 21:46:49 -0800 Subject: [PATCH 11/16] export code to config page partial code --- src/js/config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/config.js b/src/js/config.js index ac3c942..daee7f2 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -2,6 +2,9 @@ // var BASE_CONFIG_URL = 'http://192.168.0.103:4000/'; var BASE_CONFIG_URL = 'http://clach04.github.io/pebble/checklist/'; +var itemsToAdd = []; + + Pebble.addEventListener('ready', function(e) { console.log('JS component loaded!'); }); @@ -11,6 +14,7 @@ Pebble.addEventListener('showConfiguration', function(e) { var configURL = BASE_CONFIG_URL + 'config.html'; configURL = configURL + '?itemsToAdd=test,notes,here'; + //configURL = configURL + '?itemsToAdd=' + itemsToAdd.join(','); // TODO escape url Pebble.openURL(configURL); }); @@ -37,6 +41,7 @@ Pebble.addEventListener('webviewclosed', function(e) { // Send settings to Pebble watchapp Pebble.sendAppMessage(dict, function(){ console.log('Sent config data to Pebble'); + itemsToAdd = []; // reset export list }, function() { console.log('Failed to send config data!'); }); From 90bd9035ec8cc46aa4632d5e197e58ce880ab0b4 Mon Sep 17 00:00:00 2001 From: clach04 Date: Sat, 8 Feb 2020 00:09:56 -0800 Subject: [PATCH 12/16] Working export first (last in view) to config page --- src/js/config.js | 36 ++++++++++++++++++++++++++++++----- src/messaging.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/js/config.js b/src/js/config.js index daee7f2..d3a5d5c 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -2,8 +2,6 @@ // var BASE_CONFIG_URL = 'http://192.168.0.103:4000/'; var BASE_CONFIG_URL = 'http://clach04.github.io/pebble/checklist/'; -var itemsToAdd = []; - Pebble.addEventListener('ready', function(e) { console.log('JS component loaded!'); @@ -12,9 +10,22 @@ Pebble.addEventListener('ready', function(e) { // open the config page when requested Pebble.addEventListener('showConfiguration', function(e) { var configURL = BASE_CONFIG_URL + 'config.html'; + var itemsToAdd = localStorage.getItem('itemsToAdd') || '[]'; + + try { + itemsToAdd = JSON.parse(itemsToAdd); + } + catch(error) { + console.error('itemsToAdd parse failed, defaulting to [] - ' + error); + // expected output: ReferenceError: nonExistentFunction is not defined + // Note - error messages will vary depending on browser + itemsToAdd = []; + } - configURL = configURL + '?itemsToAdd=test,notes,here'; - //configURL = configURL + '?itemsToAdd=' + itemsToAdd.join(','); // TODO escape url + console.log('config itemsToAdd = ', JSON.stringify(itemsToAdd)); + //configURL = configURL + '?itemsToAdd=test,notes,here'; + //configURL = configURL + '?itemsToAdd=' + encodeURIComponent(itemsToAdd.join(',')); + configURL = configURL + '?itemsToAdd=' + itemsToAdd.join(','); Pebble.openURL(configURL); }); @@ -41,7 +52,7 @@ Pebble.addEventListener('webviewclosed', function(e) { // Send settings to Pebble watchapp Pebble.sendAppMessage(dict, function(){ console.log('Sent config data to Pebble'); - itemsToAdd = []; // reset export list + //itemsToAdd = []; // reset export list }, function() { console.log('Failed to send config data!'); }); @@ -49,3 +60,18 @@ Pebble.addEventListener('webviewclosed', function(e) { console.log("No settings changed!"); } }); + +Pebble.addEventListener("appmessage", function(e) { + if (e.payload.KEY_ITEMS_TO_ADD) { + var itemsToAdd = []; // only handle one message for now so no need to load + + console.log('Message from Pebble: ' + JSON.stringify(e.payload)); + console.log('Message from Pebble value: ' + e.payload.KEY_ITEMS_TO_ADD); + console.log('pre add itemsToAdd = ', JSON.stringify(itemsToAdd)); + itemsToAdd.push(e.payload.KEY_ITEMS_TO_ADD); + console.log('post add itemsToAdd = ', JSON.stringify(itemsToAdd)); + //itemsToAdd.push('static'); + //console.log('post add static itemsToAdd = ', JSON.stringify(itemsToAdd)); + localStorage.setItem('itemsToAdd', JSON.stringify(itemsToAdd)); // global variables do not persist even when watch app is still running, so store now + } +}); diff --git a/src/messaging.c b/src/messaging.c index 5243cb7..95d807d 100644 --- a/src/messaging.c +++ b/src/messaging.c @@ -18,6 +18,8 @@ void messaging_init(void (*processed_callback)(void)) { // Open AppMessage app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); + //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 app_message_outbox_size_maximum()=%d", app_message_outbox_size_maximum()); + // just under 8Kb, with 52 * 50 bytes could send entire checklist as one string to phone.... APP_LOG(APP_LOG_LEVEL_DEBUG, "Watch messaging is started!"); app_message_register_inbox_received(inbox_received_callback); @@ -29,8 +31,53 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { if(items_to_add_tuple != NULL) { strncpy(s_items_to_add_buffer, items_to_add_tuple->value->cstring, sizeof(s_items_to_add_buffer) - 1); + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 inbox value '%s'", s_items_to_add_buffer); + if (strncmp(s_items_to_add_buffer, "export", sizeof(s_items_to_add_buffer) - 1) == 0) + { + ChecklistItem *item=NULL; - checklist_add_items(s_items_to_add_buffer); + // magic export mode keyword found + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 got magic export mode keyword"); + + // index 0 is the bottom of the list, higher numbers are top of list + for(int id = 0; id < checklist_get_num_items() ; id++) { + item = checklist_get_item_by_id(id); + APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %d %s", id, (int) item->is_checked, item->name); + } + + // Declare the dictionary's iterator + DictionaryIterator *out_iter; + + // Prepare the outbox buffer for this message + AppMessageResult result = app_message_outbox_begin(&out_iter); + if(result == APP_MSG_OK) { + // Construct the message + // using the last item + DictionaryResult dict_result = dict_write_cstring(out_iter, KEY_ITEMS_TO_ADD, item->name); + + if (dict_result == DICT_OK) { + // Send this message + result = app_message_outbox_send(); + + // Check the result + if(result != APP_MSG_OK) { + APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result); + } + } + else { + APP_LOG(APP_LOG_LEVEL_ERROR, "Error writing cstring to out dict: %d", (int)dict_result); + } + + + } else { + // The outbox cannot be used right now + APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result); + } + } + else + { + checklist_add_items(s_items_to_add_buffer); + } } // notify the main screen, in case something changed From 406f3a5f8e3bd320cf5f33f3615e22f96d7d4cb6 Mon Sep 17 00:00:00 2001 From: clach04 Date: Thu, 13 Feb 2020 21:16:25 -0800 Subject: [PATCH 13/16] Working export support Open config enter in "export". Then re-open config and CSV of notes (without check mark information) will be displayed. NOTE notes will be stored in phone local storage until new note added via config. --- src/messaging.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/messaging.c b/src/messaging.c index 95d807d..6e7d37e 100644 --- a/src/messaging.c +++ b/src/messaging.c @@ -3,6 +3,7 @@ #include "checklist.h" static char s_items_to_add_buffer[512]; +static char all_text[(MAX_NAME_LENGTH * MAX_CHECKLIST_ITEMS) + 1]= ""; // space for commas and trailing blank - total should be smaller than app_message_outbox void (*message_processed_callback)(void); @@ -17,9 +18,13 @@ void messaging_init(void (*processed_callback)(void)) { app_message_register_outbox_sent(outbox_sent_callback); // Open AppMessage - app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); - //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 app_message_outbox_size_maximum()=%d", app_message_outbox_size_maximum()); + //app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); + //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 app_message_inbox_size_maximum()=%d", app_message_inbox_size_maximum ()); // 8200 bytes + //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 app_message_outbox_size_maximum()=%d", app_message_outbox_size_maximum()); // 8200 bytes // just under 8Kb, with 52 * 50 bytes could send entire checklist as one string to phone.... + app_message_open(sizeof(s_items_to_add_buffer) + /* safety net buffer */ + 100, (MAX_NAME_LENGTH * MAX_CHECKLIST_ITEMS) + /* safety net buffer */ + 100); + // FIXME s_items_to_add_buffer is too small, should really support full MAX_NAME_LENGTH * MAX_CHECKLIST_ITEMS + 1 (as minimum). + // increase and remove all_text[] APP_LOG(APP_LOG_LEVEL_DEBUG, "Watch messaging is started!"); app_message_register_inbox_received(inbox_received_callback); @@ -34,15 +39,24 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 inbox value '%s'", s_items_to_add_buffer); if (strncmp(s_items_to_add_buffer, "export", sizeof(s_items_to_add_buffer) - 1) == 0) { + // 2Kb too much for the stack to allocate here but statically allocating at top of module is fine + //char all_text[(MAX_NAME_LENGTH /* * MAX_CHECKLIST_ITEMS*/) + 1]= ""; // space for commas and trailing blank - total should be smaller than app_message_outbox ChecklistItem *item=NULL; // magic export mode keyword found APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 got magic export mode keyword"); // index 0 is the bottom of the list, higher numbers are top of list + // dump entire contents, should really make use of success handler + // for array sending but data small enough to do in one go so cheat :-) for(int id = 0; id < checklist_get_num_items() ; id++) { item = checklist_get_item_by_id(id); APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 [%02d] %d %s", id, (int) item->is_checked, item->name); + + // quick-n-dirty concat all items - ignore "checked" status + // FIXME below will get slower and slower as more items are added + strcat(all_text, item->name); + strcat(all_text, ","); } // Declare the dictionary's iterator @@ -52,8 +66,7 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { AppMessageResult result = app_message_outbox_begin(&out_iter); if(result == APP_MSG_OK) { // Construct the message - // using the last item - DictionaryResult dict_result = dict_write_cstring(out_iter, KEY_ITEMS_TO_ADD, item->name); + DictionaryResult dict_result = dict_write_cstring(out_iter, KEY_ITEMS_TO_ADD, all_text); if (dict_result == DICT_OK) { // Send this message From 2b16fc9a6858b61c6ff6355ea7d76bd08d7735c7 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 14 Feb 2020 20:25:31 -0800 Subject: [PATCH 14/16] Increse max size of import from config to match max size Refactor code to share buffers for import/export. --- src/js/config.js | 30 +++++++++++++++--------------- src/messaging.c | 18 ++++++++---------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/js/config.js b/src/js/config.js index d3a5d5c..b53a7b1 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -10,22 +10,22 @@ Pebble.addEventListener('ready', function(e) { // open the config page when requested Pebble.addEventListener('showConfiguration', function(e) { var configURL = BASE_CONFIG_URL + 'config.html'; - var itemsToAdd = localStorage.getItem('itemsToAdd') || '[]'; + var items_exported = localStorage.getItem('items_exported') || '[]'; try { - itemsToAdd = JSON.parse(itemsToAdd); + items_exported = JSON.parse(items_exported); } catch(error) { - console.error('itemsToAdd parse failed, defaulting to [] - ' + error); + console.error('items_exported parse failed, defaulting to [] - ' + error); // expected output: ReferenceError: nonExistentFunction is not defined // Note - error messages will vary depending on browser - itemsToAdd = []; + items_exported = []; } - console.log('config itemsToAdd = ', JSON.stringify(itemsToAdd)); - //configURL = configURL + '?itemsToAdd=test,notes,here'; - //configURL = configURL + '?itemsToAdd=' + encodeURIComponent(itemsToAdd.join(',')); - configURL = configURL + '?itemsToAdd=' + itemsToAdd.join(','); + console.log('config items_exported = ', JSON.stringify(items_exported)); + //configURL = configURL + '?items_exported=test,notes,here'; + //configURL = configURL + '?items_exported=' + encodeURIComponent(items_exported.join(',')); + configURL = configURL + '?items_exported=' + items_exported.join(','); Pebble.openURL(configURL); }); @@ -63,15 +63,15 @@ Pebble.addEventListener('webviewclosed', function(e) { Pebble.addEventListener("appmessage", function(e) { if (e.payload.KEY_ITEMS_TO_ADD) { - var itemsToAdd = []; // only handle one message for now so no need to load + var items_exported = []; console.log('Message from Pebble: ' + JSON.stringify(e.payload)); console.log('Message from Pebble value: ' + e.payload.KEY_ITEMS_TO_ADD); - console.log('pre add itemsToAdd = ', JSON.stringify(itemsToAdd)); - itemsToAdd.push(e.payload.KEY_ITEMS_TO_ADD); - console.log('post add itemsToAdd = ', JSON.stringify(itemsToAdd)); - //itemsToAdd.push('static'); - //console.log('post add static itemsToAdd = ', JSON.stringify(itemsToAdd)); - localStorage.setItem('itemsToAdd', JSON.stringify(itemsToAdd)); // global variables do not persist even when watch app is still running, so store now + console.log('pre add items_exported = ', JSON.stringify(items_exported)); + items_exported.push(e.payload.KEY_ITEMS_TO_ADD); + console.log('post add items_exported = ', JSON.stringify(items_exported)); + //items_exported.push('static'); + //console.log('post add static items_exported = ', JSON.stringify(items_exported)); + localStorage.setItem('items_exported', JSON.stringify(items_exported)); // global variables do not persist even when watch app is still running, so store now } }); diff --git a/src/messaging.c b/src/messaging.c index 6e7d37e..47e34a6 100644 --- a/src/messaging.c +++ b/src/messaging.c @@ -2,8 +2,7 @@ #include "messaging.h" #include "checklist.h" -static char s_items_to_add_buffer[512]; -static char all_text[(MAX_NAME_LENGTH * MAX_CHECKLIST_ITEMS) + 1]= ""; // space for commas and trailing blank - total should be smaller than app_message_outbox +static char s_items_to_add_buffer[(MAX_NAME_LENGTH * MAX_CHECKLIST_ITEMS) + (MAX_CHECKLIST_ITEMS * 1) + 1]= ""; // space for comma and a space, and final trailing blank - total should be smaller than app_message_outbox void (*message_processed_callback)(void); @@ -21,10 +20,10 @@ void messaging_init(void (*processed_callback)(void)) { //app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 app_message_inbox_size_maximum()=%d", app_message_inbox_size_maximum ()); // 8200 bytes //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 app_message_outbox_size_maximum()=%d", app_message_outbox_size_maximum()); // 8200 bytes - // just under 8Kb, with 52 * 50 bytes could send entire checklist as one string to phone.... + //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 PERSIST_DATA_MAX_LENGTH=%d", PERSIST_DATA_MAX_LENGTH); // 256 bytes + //APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 PERSIST_STRING_MAX_LENGTH=%d", PERSIST_STRING_MAX_LENGTH); // 256 bytes + // with 52 * 50 bytes could send entire checklist as one string to phone.... app_message_open(sizeof(s_items_to_add_buffer) + /* safety net buffer */ + 100, (MAX_NAME_LENGTH * MAX_CHECKLIST_ITEMS) + /* safety net buffer */ + 100); - // FIXME s_items_to_add_buffer is too small, should really support full MAX_NAME_LENGTH * MAX_CHECKLIST_ITEMS + 1 (as minimum). - // increase and remove all_text[] APP_LOG(APP_LOG_LEVEL_DEBUG, "Watch messaging is started!"); app_message_register_inbox_received(inbox_received_callback); @@ -39,8 +38,7 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "clach04 inbox value '%s'", s_items_to_add_buffer); if (strncmp(s_items_to_add_buffer, "export", sizeof(s_items_to_add_buffer) - 1) == 0) { - // 2Kb too much for the stack to allocate here but statically allocating at top of module is fine - //char all_text[(MAX_NAME_LENGTH /* * MAX_CHECKLIST_ITEMS*/) + 1]= ""; // space for commas and trailing blank - total should be smaller than app_message_outbox + s_items_to_add_buffer[0] = '\0'; ChecklistItem *item=NULL; // magic export mode keyword found @@ -55,8 +53,8 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { // quick-n-dirty concat all items - ignore "checked" status // FIXME below will get slower and slower as more items are added - strcat(all_text, item->name); - strcat(all_text, ","); + strcat(s_items_to_add_buffer, item->name); + strcat(s_items_to_add_buffer, ","); } // Declare the dictionary's iterator @@ -66,7 +64,7 @@ void inbox_received_callback(DictionaryIterator *iterator, void *context) { AppMessageResult result = app_message_outbox_begin(&out_iter); if(result == APP_MSG_OK) { // Construct the message - DictionaryResult dict_result = dict_write_cstring(out_iter, KEY_ITEMS_TO_ADD, all_text); + DictionaryResult dict_result = dict_write_cstring(out_iter, KEY_ITEMS_TO_ADD, s_items_to_add_buffer); if (dict_result == DICT_OK) { // Send this message From 127e5d024223303d5aa9016312b5b59ac3b1cf41 Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 14 Feb 2020 20:29:06 -0800 Subject: [PATCH 15/16] Doc export download link --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d716e66..d2eaeb3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # PebbleChecklist + A checklist-on your watch! @@ -36,3 +37,7 @@ In additon, ensure you are subscribed to a voice transcription service, for exam Grab it from the Rebble/Pebble app store: https://apps.rebble.io/en_US/application/5620e876768e7ada4e00007a?section=watchapps&dev_settings=true + +## Latest version with export + +Available from https://github.com/clach04/PebbleChecklist/releases From 587880811547f935c421ef81cff60933381a09ec Mon Sep 17 00:00:00 2001 From: clach04 Date: Fri, 14 Feb 2020 20:30:28 -0800 Subject: [PATCH 16/16] Doc export instructions --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d2eaeb3..5862dc9 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,12 @@ https://apps.rebble.io/en_US/application/5620e876768e7ada4e00007a?section=watcha ## Latest version with export Available from https://github.com/clach04/PebbleChecklist/releases + +To export notes: + + * open config + * add new note with title "config" (with no quotes), save + * open config again + * copy from the export field (which is the same format the add note field accepts + +NOTE check item status is NOT exported. Items end up in local storage.