void updateDayAndNightInfo(bool update_everything)
{
  static char sunrise_text[] = "00:00";
  static char sunset_text[] = "00:00";

  PblTm pblTime;
  get_time(&pblTime);

  if(update_everything || currentData != pblTime.tm_hour) 
  {
    char *time_format;

    if (clock_is_24h_style()) 
    {
      time_format = "%R";
    } 
    else 
    {
      time_format = "%I:%M";
    }

    float sunriseTime = calcSunRise(pblTime.tm_year, pblTime.tm_mon+1, pblTime.tm_mday, realLatitude, realLongitude, 91.0f);
    float sunsetTime = calcSunSet(pblTime.tm_year, pblTime.tm_mon+1, pblTime.tm_mday, realLatitude, realLongitude, 91.0f);
    adjustTimezone(&sunriseTime);
    adjustTimezone(&sunsetTime);
    
    if (!pblTime.tm_isdst) 
    {
      sunriseTime+=1;
      sunsetTime+=1;
    } 
    
    pblTime.tm_min = (int)(60*(sunriseTime-((int)(sunriseTime))));
    pblTime.tm_hour = (int)sunriseTime;
    string_format_time(sunrise_text, sizeof(sunrise_text), time_format, &pblTime);
    text_layer_set_text(&text_sunrise_layer, sunrise_text);
    
    pblTime.tm_min = (int)(60*(sunsetTime-((int)(sunsetTime))));
    pblTime.tm_hour = (int)sunsetTime;
    string_format_time(sunset_text, sizeof(sunset_text), time_format, &pblTime);
    text_layer_set_text(&text_sunset_layer, sunset_text);
    text_layer_set_text_alignment(&text_sunset_layer, GTextAlignmentRight);

    sunriseTime+=12.0f;
    sun_path_info.points[1].x = (int16_t)(my_sin(sunriseTime/24 * M_PI * 2) * 120);
    sun_path_info.points[1].y = -(int16_t)(my_cos(sunriseTime/24 * M_PI * 2) * 120);

    sunsetTime+=12.0f;
    sun_path_info.points[4].x = (int16_t)(my_sin(sunsetTime/24 * M_PI * 2) * 120);
    sun_path_info.points[4].y = -(int16_t)(my_cos(sunsetTime/24 * M_PI * 2) * 120);

    currentData = pblTime.tm_hour;
    
    //Update location unless being called from location update
    if (!update_everything) {
      http_time_request();
    }
  }
}
示例#2
0
void link_monitor_ping()
{
	//Sending ANY message to the phone would do
	http_time_request();
}
示例#3
0
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;
}