//Called if Httpebble is installed on phone. void have_time(int32_t dst_offset, bool is_dst, uint32_t unixtime, const char* tz_name, void* context) { if (!is_dst) { realTimezone = dst_offset/3600.0; } else { realTimezone = (dst_offset/3600.0) - 1; } //Now that we have timezone get location http_location_request(); }
/* Called by the OS once per minute. Update the time and date. */ void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { /* Need to be static because pointers to them are stored in the text * layers. */ static char date_text[] = "XXX, XXX 00"; static char hour_text[] = "00"; static char minute_text[] = ":00"; (void)ctx; /* prevent "unused parameter" warning */ if (t->units_changed & DAY_UNIT) { string_format_time(date_text, sizeof(date_text), "%a, %b %d", t->tick_time); text_layer_set_text(&date_layer, date_text); } if (clock_is_24h_style()) { string_format_time(hour_text, sizeof(hour_text), "%H", t->tick_time); } else { string_format_time(hour_text, sizeof(hour_text), "%I", t->tick_time); if (hour_text[0] == '0') { /* This is a hack to get rid of the leading zero. */ memmove(&hour_text[0], &hour_text[1], sizeof(hour_text) - 1); } } string_format_time(minute_text, sizeof(minute_text), ":%M", t->tick_time); time_layer_set_text(&time_layer, hour_text, minute_text); if(!located || !(t->tick_time->tm_min % 15)) { //Every 15 minutes, request updated weather http_location_request(); } else { //Every minute, ping the phone link_monitor_ping(); } }
void select_single_click_handler(ClickRecognizerRef recognizer, Window *window) { (void)recognizer; (void)window; http_location_request(); }
/* Called by the OS once per minute. Update the time and date. */ void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { /* Need to be static because pointers to them are stored in the text * layers. */ static char date_text[] = "XXX 00/00"; static char hour_text[] = "00"; static char minute_text[] = ":00"; (void)ctx; /* prevent "unused parameter" warning */ if (t->units_changed & DAY_UNIT) { string_format_time(date_text, sizeof(date_text), "%a %m/%d", t->tick_time); if (date_text[4] == '0') /* is day of month < 10? */ { /* This is a hack to get rid of the leading zero of the day of month */ memmove(&date_text[4], &date_text[5], sizeof(date_text) - 1); } text_layer_set_text(&date_layer, date_text); } if (clock_is_24h_style()) { string_format_time(hour_text, sizeof(hour_text), "%H", t->tick_time); if (hour_text[0] == '0') { /* This is a hack to get rid of the leading zero of the hour. */ memmove(&hour_text[0], &hour_text[1], sizeof(hour_text) - 1); } } else { string_format_time(hour_text, sizeof(hour_text), "%I", t->tick_time); if (hour_text[0] == '0') { /* This is a hack to get rid of the leading zero of the hour. */ memmove(&hour_text[0], &hour_text[1], sizeof(hour_text) - 1); } } string_format_time(minute_text, sizeof(minute_text), ":%M", t->tick_time); time_layer_set_text(&time_layer, hour_text, minute_text); if(initial_request || !has_temperature || (t->tick_time->tm_min % 30) == initial_minute) { // Every 30 minutes, request updated weather http_location_request(); initial_request = false; } else { // Ping the phone every minute link_monitor_ping(); } }
void failed(int32_t cookie, int http_status, void* context) { /* This is triggered by invalid responses from the bridge on the phone, * due to e.g. HTTP errors or phone disconnections. */ if(HTTP_INVALID_BRIDGE_RESPONSE) { // Phone can still be reached (assume HTTP error) if (http_time_request() == HTTP_OK) { /* Display 'cloud error' icon if: * - HTTP error is noticed upon inital load * - watch has recovered from a phone disconnection, but has no internet connection */ if (!has_temperature || phone_disconnected) { weather_layer_set_icon(&weather_layer, WEATHER_ICON_CLOUD_ERROR); phone_disconnected = false; } /* Assume that weather information is stale after 1 hour without a successful * weather request. Indicate this by removing the degree symbol. */ else if (has_timed_out || has_temperature || http_request_build_count > 0 || http_request_send_count > 0) { if (fail_count >= 60) { is_stale = true; weather_layer_set_temperature(&weather_layer, last_valid_temperature, is_stale); } } } else { /* Redundant check to make sure that HTTP time-outs are not triggering the * 'phone error' icon. If appearing to be timed out after 1 hour without a * successful weather request, indicate stale weather information by removing * the degree symbol. */ if (fail_count >= 60 && has_timed_out && !phone_disconnected) { is_stale = true; weather_layer_set_temperature(&weather_layer, last_valid_temperature, is_stale); } /* Display 'phone error' icon if: * - watch appears to be disconnected from phone * - watch appears to be disconnected from bridge app on phone * * In case this is triggered by a HTTP time-out, subsequently send a * weather request for a possible quick re-connection. */ else { if (http_status==1008) { phone_disconnected = true; weather_layer_set_icon(&weather_layer, WEATHER_ICON_PHONE_ERROR); link_monitor_handle_failure(http_status); http_location_request(); request_weather(); } } } } // Remove temperature text 30 minutes after a phone/bridge app disconnection if (fail_count >= 30 && phone_disconnected) { text_layer_set_text(weather_layer.temp_layer, " "); has_temperature = false; } // Indicate failure and activate fail counter (see handle_tick() function) has_failed = true; // Re-request the location and subsequently weather on next minute tick located = false; }
static void handle_tick(struct tm *tick_time, TimeUnits units_changed) { // 'Animate' loading icon until the first successful weather request if (!has_temperature && !has_failed) { if (load_count == 4) { weather_layer_set_icon(&weather_layer, WEATHER_ICON_LOADING1); } if (load_count == 5) { weather_layer_set_icon(&weather_layer, WEATHER_ICON_LOADING2); } if (load_count == 6) { weather_layer_set_icon(&weather_layer, WEATHER_ICON_LOADING3); load_count = 3; } load_count++; } // Subsequently update time and date once every minute if (units_changed & MINUTE_UNIT) { // Need to be static because pointers to them are stored in the text layers static char date_text[] = "XXX 00"; static char hour_text[] = "00"; static char minute_text[] = ":00"; if (units_changed & DAY_UNIT) { strftime(date_text, sizeof(date_text), "%a %d", tick_time); // Triggered if day of month < 10 if (date_text[4] == '0') { // Hack to get rid of the leading zero of the day of month memmove(&date_text[4], &date_text[5], sizeof(date_text) - 1); } text_layer_set_text(date_layer, date_text); } if (clock_is_24h_style()) { strftime(hour_text, sizeof(hour_text), "%H", tick_time); if (hour_text[0] == '0') { // Hack to get rid of the leading zero of the hour memmove(&hour_text[0], &hour_text[1], sizeof(hour_text) - 1); } } else { strftime(hour_text, sizeof(hour_text), "%I", tick_time); if (hour_text[0] == '0') { // Hack to get rid of the leading zero of the hour memmove(&hour_text[0], &hour_text[1], sizeof(hour_text) - 1); } } strftime(minute_text, sizeof(minute_text), ":%M", tick_time); time_layer_set_text(&time_layer, hour_text, minute_text); // Start a counter upon an error and increase by 1 each minute // Helps determine when to display error feedback and to stop trying to recover from errors if (has_failed) { fail_count++; } else { fail_count = 0; } // Request updated weather every 15 minutes // Stop requesting after 3 hours without any successful connection if(initial_request || !has_temperature || ((tick_time->tm_min % 15) == initial_minute && fail_count <= 180)) { http_location_request(); initial_request = false; } else { // Ping the phone once every minute to validate the connection // Stop pinging after 3 hours without any successful connection if (fail_count <= 180) { // Upon an error, also make a weather request with each ping if (fail_count > 0) { http_location_request(); } link_monitor_ping(); } /****** The code snippet below is used for the "no vibration" version // Ping the phone every 5 minutes if (!(tick_time->tm_min % 5) && fail_count == 0) { link_monitor_ping(); } // Upon an error, ping the phone every minute // Stop pinging after 3 hours without any successful connection else if (fail_count > 0 && fail_count <= 180) { http_location_request(); link_monitor_ping(); } ******/ } } }
void request_location() { http_location_request(); }
void handle_tick(AppContextRef ctx, PebbleTickEvent *t) { // 'Animate' loading icon until the first successful weather request if (!has_temperature && !has_failed) { if (load_count == 4) { weather_layer_set_icon(&weather_layer, WEATHER_ICON_LOADING1); } if (load_count == 5) { weather_layer_set_icon(&weather_layer, WEATHER_ICON_LOADING2); } if (load_count == 6) { weather_layer_set_icon(&weather_layer, WEATHER_ICON_LOADING3); load_count = 3; } load_count++; } // Subsequently update time and date once every minute if (t->units_changed & MINUTE_UNIT) { // Need to be static because pointers to them are stored in the text layers static char date_text[] = "XXX 00"; static char hour_text[] = "00"; static char minute_text[] = ":00"; (void)ctx; // Prevent "unused parameter" warning if (t->units_changed & DAY_UNIT) { string_format_time(date_text, sizeof(date_text), "%a %d", t->tick_time); // Triggered if day of month < 10 if (date_text[4] == '0') { // Hack to get rid of the leading zero of the day of month memmove(&date_text[4], &date_text[5], sizeof(date_text) - 1); } /*** LOCALIZATION CODE BEGIN *** // Primitive hack to translate the day of week to another language // Needs to be exactly 3 characters, e.g. "Mon" or "Mo " // Supported characters: A-Z, a-z, 0-9 if (date_text[0] == 'M') { memcpy(&date_text, "XXX", 3); // Monday } if (date_text[0] == 'T' && date_text[1] == 'u') { memcpy(&date_text, "XXX", 3); // Tuesday } if (date_text[0] == 'W') { memcpy(&date_text, "XXX", 3); // Wednesday } if (date_text[0] == 'T' && date_text[1] == 'h') { memcpy(&date_text, "XXX", 3); // Thursday } if (date_text[0] == 'F') { memcpy(&date_text, "XXX", 3); // Friday } if (date_text[0] == 'S' && date_text[1] == 'a') { memcpy(&date_text, "XXX", 3); // Saturday } if (date_text[0] == 'S' && date_text[1] == 'u') { memcpy(&date_text, "XXX", 3); // Sunday } // Uncomment the line below if your labels consist of 2 characters and 1 space, e.g. "Mo " //memmove(&date_text[3], &date_text[4], sizeof(date_text) - 1); *** LOCALIZATION CODE END ***/ text_layer_set_text(&date_layer, date_text); } if (clock_is_24h_style()) { string_format_time(hour_text, sizeof(hour_text), "%H", t->tick_time); if (hour_text[0] == '0') { // Hack to get rid of the leading zero of the hour memmove(&hour_text[0], &hour_text[1], sizeof(hour_text) - 1); } } else { string_format_time(hour_text, sizeof(hour_text), "%I", t->tick_time); if (hour_text[0] == '0') { // Hack to get rid of the leading zero of the hour memmove(&hour_text[0], &hour_text[1], sizeof(hour_text) - 1); } } string_format_time(minute_text, sizeof(minute_text), ":%M", t->tick_time); time_layer_set_text(&time_layer, hour_text, minute_text); // Start a counter upon an error and increase by 1 each minute // Helps determine when to display error feedback and to stop trying to recover from errors if (has_failed) { fail_count++; } else { fail_count = 0; } // Request updated weather every 15 minutes // Stop requesting after 3 hours without any successful connection if(initial_request || !has_temperature || ((t->tick_time->tm_min % 15) == initial_minute && fail_count <= 180)) { http_location_request(); initial_request = false; } else { // Ping the phone once every minute to validate the connection // Stop pinging after 3 hours without any successful connection if (fail_count <= 180) { // Upon an error, also make a weather request with each ping if (fail_count > 0) { http_location_request(); } link_monitor_ping(); } /****** The code snippet below is used for the "no vibration" version // Ping the phone every 5 minutes if (!(t->tick_time->tm_min % 5) && fail_count == 0) { link_monitor_ping(); } // Upon an error, ping the phone every minute // Stop pinging after 3 hours without any successful connection else if (fail_count > 0 && fail_count <= 180) { http_location_request(); link_monitor_ping(); } ******/ } } }