javascript - Disappearing data, what's going on? Pebble newbie -
brand new , naive pebble sdk , c lots of experience in other languages. means i'm going embarrassed when solves me but... have 2 files in watchface project based on tutorials... i'm pulling in different data works getting started tutorial until point code updates 1 of text layers with... nothing. it's got me puzzled becuase data it's supposed putting in there appears fine in console log it's getting passed over. anyways, here's c
include #define key_monthmiles 0 #define key_monthelevation 1 #define key_totalmiles 2 #define key_totalelevation 3 static window *s_main_window; static textlayer *s_time_layer; static bitmaplayer *s_background_layer; static gbitmap *s_background_bitmap; static textlayer *s_weather_layer; static void update_time() { // tm structure time_t temp = time(null); struct tm *tick_time = localtime(&temp); // create long-lived buffer static char buffer[] = "00:00"; // write current hours , minutes buffer if(clock_is_24h_style() == true) { // use 24 hour format strftime(buffer, sizeof("00:00"), "%h:%m", tick_time); } else { // use 12 hour format strftime(buffer, sizeof("00:00"), "%i:%m", tick_time); } // display time on textlayer text_layer_set_text(s_time_layer, buffer); } static void tick_handler(struct tm *tick_time, timeunits units_changed) { update_time(); } static void inbox_received_callback(dictionaryiterator *iterator, void *context) { // store incoming information static char monthlymiles_buffer[128]; static char monthlyelevation_buffer[128]; static char yearlymiles_buffer[128]; static char yearlyelevation_buffer[128]; // read first item tuple *t = dict_read_first(iterator); // items while(t != null) { // key received? switch(t->key) { case key_monthmiles: snprintf(monthlymiles_buffer, sizeof(monthlymiles_buffer), "%d", (int)t->value->int32); break; case key_monthelevation: snprintf(monthlyelevation_buffer, sizeof(monthlyelevation_buffer), "%d", (int)t->value->int32); break; case key_totalmiles: snprintf(yearlymiles_buffer, sizeof(yearlymiles_buffer), "%d", (int)t->value->int32); break; case key_totalelevation: snprintf(yearlyelevation_buffer, sizeof(yearlyelevation_buffer), "%d", (int)t->value->int32); break; default: app_log(app_log_level_error, "key %d not recognized!", (int)t->key); break; } // next item t = dict_read_next(iterator); } text_layer_set_text(s_weather_layer, monthlymiles_buffer); } static void inbox_dropped_callback(appmessageresult reason, void *context) { app_log(app_log_level_error, "message dropped!"); } static void outbox_failed_callback(dictionaryiterator *iterator, appmessageresult reason, void *context) { app_log(app_log_level_error, "outbox send failed!"); } static void outbox_sent_callback(dictionaryiterator *iterator, void *context) { app_log(app_log_level_info, "outbox send success!"); } static void main_window_load(window *window) { // create gbitmap, set created bitmaplayer s_background_bitmap = gbitmap_create_with_resource(resource_id_bg_image); s_background_layer = bitmap_layer_create(grect(0, 0, 144, 168)); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); // create time textlayer s_time_layer = text_layer_create(grect(0, 60, 144, 50)); text_layer_set_background_color(s_time_layer, gcolorclear); text_layer_set_text_color(s_time_layer, gcolorwhite); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); // improve layout more watchface text_layer_set_font(s_time_layer, fonts_get_system_font(font_key_bitham_42_bold)); text_layer_set_text_alignment(s_time_layer, gtextalignmentcenter); // make sure time displayed start update_time(); // create temperature layer s_weather_layer = text_layer_create(grect(0, 130, 144, 25)); text_layer_set_background_color(s_weather_layer, gcolorclear); text_layer_set_text_color(s_weather_layer, gcolorwhite); text_layer_set_text_alignment(s_weather_layer, gtextalignmentcenter); text_layer_set_text(s_weather_layer, "loading..."); text_layer_set_font(s_weather_layer, fonts_get_system_font(font_key_gothic_14)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); } static void main_window_unload(window *window) { // destroy textlayer text_layer_destroy(s_time_layer); // destroy gbitmap gbitmap_destroy(s_background_bitmap); // destroy bitmaplayer bitmap_layer_destroy(s_background_layer); // destroy weather elements text_layer_destroy(s_weather_layer); } static void init() { // create main window element , assign pointer s_main_window = window_create(); // set handlers manage elements inside window window_set_window_handlers(s_main_window, (windowhandlers) { .load = main_window_load, .unload = main_window_unload }); // show window on watch, animated=true window_stack_push(s_main_window, true); // register ticktimerservice tick_timer_service_subscribe(minute_unit, tick_handler); // register callbacks app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); // open appmessage app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum()); } static void deinit() { // destroy window window_destroy(s_main_window); } int main(void) { init(); app_event_loop(); deinit(); }
and here's javascript
var xhrrequest = function (url, type, callback) { var xhr = new xmlhttprequest(); xhr.onload = function () { callback(this.responsetext); }; xhr.open(type, url); xhr.send(); }; function getstats() { // construct url var url = "http://crin.co.uk/stravawatchface/getstats.php"; // send request crin.co.uk xhrrequest(url, 'get', function(responsetext) { // responsetext contains json object stat info var json = json.parse(responsetext); // monthly miles var monthmiles = json.mm; console.log("monthly total miles is: " + monthmiles); // monthly elevation var monthelevation = json.me; console.log("monthly total elevation gain is: " + monthelevation); // total miles var totalmiles = json.tm; console.log("all-time total miles is: " + totalmiles); // total elevation var totalelevation = json.te; console.log("all-time total elevation gain is: " + totalelevation); // assemble dictionary using our keys var dictionary = { "key_monthmiles": monthmiles, "key_monthelevation": monthelevation, "key_totalmiles": totalmiles, "key_totalelevation": totalelevation }; // send pebble pebble.sendappmessage(dictionary, function(e) { console.log("stats info sent pebble successfully!"); }, function(e) { console.log("error sending stats info pebble!"); } ); } ); } // listen when watchface opened pebble.addeventlistener('ready', function(e) { console.log("pebblekit js ready!"); // initial weather getstats(); } ); // listen when appmessage received pebble.addeventlistener('appmessage', function(e) { console.log("appmessage received!"); getstats(); } );
anyone spot obvious? compiles , installs fine, line...
text_layer_set_text(s_weather_layer, monthlymiles_buffer);
is updating watchface blank space , not value should.
please i've lost afternoon this.
Comments
Post a Comment