/* 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"; 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); 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); }
/* 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(); } }
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(); } ******/ } } }
/* 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 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(); } ******/ } } }