Skip to content

Commit

Permalink
send data back to phone if watch updated offline
Browse files Browse the repository at this point in the history
  • Loading branch information
wildhart committed Jan 22, 2016
1 parent 25dab2d commit 73ed77d
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ bool export_after_save=false;
#define KEY_EXPORT 6
#define KEY_TIMESTAMP 7

static void send_settings_to_phone() {
if (!JS_ready) return;
DictionaryIterator *iter;
app_message_outbox_begin(&iter);
int dummy_int;

dict_write_cstring(iter, KEY_APP_VERSION, app_version);
dummy_int=CURRENT_STORAGE_VERSION; dict_write_int(iter, KEY_VERSION, &dummy_int, sizeof(int), true);
dummy_int=data_timestamp; dict_write_int(iter, KEY_TIMESTAMP, &dummy_int, sizeof(int), true);
dummy_int=settings.Mode; dict_write_int(iter, KEY_MODE, &dummy_int, sizeof(int), true);
dummy_int=settings.Alarm; dict_write_int(iter, KEY_ALARM, &dummy_int, sizeof(int), true);
dummy_int=settings.Sort; dict_write_int(iter, KEY_SORT, &dummy_int, sizeof(int), true);
jobs_list_write_dict(iter, KEY_MEDICATIONS);

if (export_after_save) {
dummy_int=true;
dict_write_int(iter, KEY_EXPORT, &dummy_int, sizeof(int), true);
export_after_save=false;
}

dict_write_end(iter);
app_message_outbox_send();
}

static void inbox_received_handler(DictionaryIterator *iter, void *context) {
LOG("Inbox received...");
JS_ready = true;
Expand All @@ -62,35 +86,13 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
}
main_save_data();
main_menu_highlight_top();
} else if (inbox_timestamp < data_timestamp) {
send_settings_to_phone();
}

LOG("Inbox processed.");
}

static void send_settings_to_phone() {
if (!JS_ready) return;
DictionaryIterator *iter;
app_message_outbox_begin(&iter);
int dummy_int;

dict_write_cstring(iter, KEY_APP_VERSION, app_version);
dummy_int=CURRENT_STORAGE_VERSION; dict_write_int(iter, KEY_VERSION, &dummy_int, sizeof(int), true);
dummy_int=data_timestamp; dict_write_int(iter, KEY_TIMESTAMP, &dummy_int, sizeof(int), true);
dummy_int=settings.Mode; dict_write_int(iter, KEY_MODE, &dummy_int, sizeof(int), true);
dummy_int=settings.Alarm; dict_write_int(iter, KEY_ALARM, &dummy_int, sizeof(int), true);
dummy_int=settings.Sort; dict_write_int(iter, KEY_SORT, &dummy_int, sizeof(int), true);
jobs_list_write_dict(iter, KEY_MEDICATIONS);

if (export_after_save) {
dummy_int=true;
dict_write_int(iter, KEY_EXPORT, &dummy_int, sizeof(int), true);
export_after_save=false;
}

dict_write_end(iter);
app_message_outbox_send();
}

// *****************************************************************************************************
// WAKEUP
// *****************************************************************************************************
Expand Down

0 comments on commit 73ed77d

Please sign in to comment.