示例#1
0
void success(int32_t cookie, int http_status, DictionaryIterator* received, void* context) {
	
	if(cookie != WEATHER_HTTP_COOKIE) return;
	
	Tuple* icon_tuple = dict_find(received, WEATHER_KEY_ICON);
	if(icon_tuple) {
		int icon = icon_tuple->value->int8;
		if(icon >= 0 && icon < 10) {
			set_container_image(&weather_images[0], WEATHER_IMAGE_RESOURCE_IDS[icon], GPoint(12, 5));  // ---------- Weather Image
		} else {
			set_container_image(&weather_images[0], WEATHER_IMAGE_RESOURCE_IDS[10], GPoint(12, 5));
		}
	}
	
	Tuple* temperature_tuple = dict_find(received, WEATHER_KEY_TEMPERATURE);
	if(temperature_tuple) {
		
		static char temp_text[5];
		memcpy(temp_text, itoa(temperature_tuple->value->int16), 4);
		int degree_pos = strlen(temp_text);
		memcpy(&temp_text[degree_pos], "°", 3);
		text_layer_set_text(&text_temperature_layer, temp_text);
		temperature_set = true;
	}
	
	link_monitor_handle_success(&data);
	//display_counters(&calls_layer, data, 1);
	//display_counters(&sms_layer, data, 2);
}
示例#2
0
void app_received_msg(DictionaryIterator* received, void* context) {	
	link_monitor_handle_success(&data);
	if(read_state_data(received, &data)) 
	{
		//display_counters(&calls_layer, data, 1);
		//display_counters(&sms_layer, data, 2);
		if(!located)
		{
			request_weather();
		}
	}
}
示例#3
0
void success(int32_t cookie, int http_status, DictionaryIterator* received, void* context) {
	if(cookie != WEATHER_HTTP_COOKIE) return;
	Tuple* icon_tuple = dict_find(received, WEATHER_KEY_ICON);
	if(icon_tuple) {
		int icon = icon_tuple->value->int8;
		if(icon >= 0 && icon < 10) {
			weather_layer_set_icon(&weather_layer, icon);
		} else {
			weather_layer_set_icon(&weather_layer, WEATHER_ICON_NO_WEATHER);
		}
	}
	Tuple* temperature_tuple = dict_find(received, WEATHER_KEY_TEMPERATURE);
	if(temperature_tuple) {
		weather_layer_set_temperature(&weather_layer, temperature_tuple->value->int16);
	}
	
	link_monitor_handle_success();
}
示例#4
0
void success(int32_t cookie, int http_status, DictionaryIterator* received, void* context) {
	
	is_stale = false;
	
	if(cookie != WEATHER_HTTP_COOKIE) return;
	Tuple* icon_tuple = dict_find(received, WEATHER_KEY_ICON);
	if(icon_tuple) {
		int icon = icon_tuple->value->int8;
		if(icon >= 0 && icon < 18 && icon != 17) {
			weather_layer_set_icon(&weather_layer, icon);
		}
	}
	Tuple* temperature_tuple = dict_find(received, WEATHER_KEY_TEMPERATURE);
	if(temperature_tuple) {
		last_valid_temperature = temperature_tuple->value->int16;
		weather_layer_set_temperature(&weather_layer, temperature_tuple->value->int16, is_stale);
		has_temperature = true;
	}
	
	link_monitor_handle_success();
	has_failed = false;
	phone_disconnected = false;
}
示例#5
0
void success(int32_t cookie, int http_status, DictionaryIterator* received, void* context) {
	if(cookie != WEATHER_HTTP_COOKIE) return;
	Tuple* icon_tuple = dict_find(received, WEATHER_KEY_ICON);
	if(icon_tuple) {
		int icon = -1;
		char ipng[16];
		strcpy(ipng, icon_tuple->value->cstring);
		
		// map openweather to futura-weather icons
		// 01d.png	 01n.png	 sky is clear
		// 02d.png	 02n.png	 few clouds
		// 03d.png	 03n.png	 scattered clouds
		// 04d.png	 04n.png	 broken clouds
		// 09d.png	 09n.png	 shower rain
		// 10d.png	 10n.png	 Rain
		// 11d.png	 11n.png	 Thunderstorm
		// 13d.png	 13n.png	 snow
		// 50d.png	 50n.png	 mist
	    if (strcmp(ipng, "01d") == 0) icon = WEATHER_ICON_CLEAR_DAY;
	    if (strcmp(ipng, "01n") == 0) icon = WEATHER_ICON_CLEAR_NIGHT;
	    if (strcmp(ipng, "02d") == 0) icon = WEATHER_ICON_PARTLY_CLOUDY_DAY;
	    if (strcmp(ipng, "02n") == 0) icon = WEATHER_ICON_PARTLY_CLOUDY_NIGHT;
	    if (strcmp(ipng, "03d") == 0) icon = WEATHER_ICON_CLOUDY;
	    if (strcmp(ipng, "03n") == 0) icon = WEATHER_ICON_CLOUDY;
	    if (strcmp(ipng, "04d") == 0) icon = WEATHER_ICON_CLOUDY;
	    if (strcmp(ipng, "04n") == 0) icon = WEATHER_ICON_CLOUDY;
	    if (strcmp(ipng, "09d") == 0) icon = WEATHER_ICON_RAIN;
	    if (strcmp(ipng, "09n") == 0) icon = WEATHER_ICON_RAIN;
	    if (strcmp(ipng, "10d") == 0) icon = WEATHER_ICON_RAIN;
	    if (strcmp(ipng, "10n") == 0) icon = WEATHER_ICON_RAIN;
	    if (strcmp(ipng, "11d") == 0) icon = WEATHER_ICON_RAIN;
	    if (strcmp(ipng, "11n") == 0) icon = WEATHER_ICON_RAIN;
	    if (strcmp(ipng, "13d") == 0) icon = WEATHER_ICON_SNOW;
	    if (strcmp(ipng, "13n") == 0) icon = WEATHER_ICON_SNOW;
	    if (strcmp(ipng, "50d") == 0) icon = WEATHER_ICON_FOG;
	    if (strcmp(ipng, "50n") == 0) icon = WEATHER_ICON_FOG;	
		
		
		if(icon >= 0 && icon < 10) {
			weather_layer_set_icon(&weather_layer, icon);
		} else {
#ifndef ANTONIO
			weather_layer_set_icon(&weather_layer, WEATHER_ICON_NO_WEATHER);
#endif
		}
	}
	
	int min_temp = -1;
	int max_temp = -1;
	static char minmax[32];
	
	Tuple* min_temp_tuple = dict_find(received, WEATHER_KEY_MIN_TEMP);
	if (min_temp_tuple) { min_temp = min_temp_tuple->value->int16; }
	Tuple* max_temp_tuple = dict_find(received, WEATHER_KEY_MAX_TEMP);
	if (max_temp_tuple) { max_temp = max_temp_tuple->value->int16; }
	strcpy(minmax, itoa(max_temp)); strcat(minmax, "°/ ");
	strcat(minmax, itoa(min_temp)); strcat(minmax, "°");
	if (min_temp_tuple && max_temp_tuple) { text_layer_set_text(&minmax_layer, minmax); }

	Tuple* temperature_tuple = dict_find(received, WEATHER_KEY_TEMP);
	if (temperature_tuple) {
		weather_layer_set_temperature(&weather_layer, temperature_tuple->value->int16);
       	get_time(&updated_tm); set_updated(); 	// updated last successful wweather event
		has_temperature = true;
	}
	
	link_monitor_handle_success();
}