Пример #1
0
void weather_layer_set_precipitation_forecast(WeatherLayer* weather_layer, uint8_t* forecast, uint8_t length) {
	weather_layer->forecast = forecast;
	weather_layer->forecast_count = length;
	// Check whether we actually have precipitation in the next half hour.
	bool has_forecast = false;
	for(uint8_t i = 0; i < 30 && i < length; ++i) {
		if(forecast[i]) {
			has_forecast = true;
			break;
		}
	}
	if(has_forecast) {
		// Get rid of the weather icon, if we have one.
		if(weather_layer->has_weather_icon) {
			layer_remove_from_parent(&weather_layer->icon_layer.layer.layer);
			bmp_deinit_container(&weather_layer->icon_layer);
			weather_layer->has_weather_icon = false;
		}
		graph_layer_set_data(&weather_layer->graph_layer, forecast, length);
		layer_add_child(&weather_layer->layer, &weather_layer->graph_layer.layer);
		weather_layer->has_forecast = true;
	} else {
		weather_layer_clear_precipitation_forecast(weather_layer);
	}
}
Пример #2
0
void handle_tick(AppContextRef app_ctx, PebbleTickEvent *event) {
	time_layer_set_time(&time_layer, *(event->tick_time));
	if(precip_forecast_index >= 0) {
		++precip_forecast_index;
		if(precip_forecast_index > 60) {
			weather_layer_clear_precipitation_forecast(&weather_layer);
			precip_forecast_index = -1;
		} else {
			weather_layer_set_precipitation_forecast(&weather_layer, &precip_forecast[precip_forecast_index], 60 - precip_forecast_index);
		}
	}
}
Пример #3
0
void success(int32_t cookie, int http_status, DictionaryIterator* received, void* context) 
{
	if(cookie != WEATHER_HTTP_COOKIE) return;
	Tuple* data_tuple = dict_find(received, WEATHER_KEY_CURRENT);
	if(data_tuple) {
		// The below bitwise dance is so we can actually fit our precipitation forecast.
		uint16_t value = data_tuple->value->int16;
		uint8_t icon = value >> 11;
		if(icon < 10) {
			weather_layer_set_icon(&weather_layer, icon);
		} else {
			weather_layer_set_icon(&weather_layer, WEATHER_ICON_NO_WEATHER);
		}
		int16_t temp = value & 0x3ff;
		if(value & 0x400) temp = -temp;
		weather_layer_set_temperature(&weather_layer, temp);
	}
	Tuple* forecast_tuple = dict_find(received, WEATHER_KEY_PRECIPITATION);
	if(forecast_tuple) {
		// It's going to rain!
		memset(precip_forecast, 0, 60);
		memcpy(precip_forecast, forecast_tuple->value->data, forecast_tuple->length > 60 ? 60 : forecast_tuple->length);
		precip_forecast_index = 0;
		weather_layer_set_precipitation_forecast(&weather_layer, precip_forecast, 60);
	} else {
		weather_layer_clear_precipitation_forecast(&weather_layer);
	}

	/*
	if(cookie != WEATHER_HTTP_COOKIE) 
		return;
	Tuple* data_tuple = dict_find(received, TEMPERATURE_KEY_CURRENT);
	if(data_tuple) 
	{
		weather_layer_set_temperature_str(&weather_layer, data_tuple->value->cstring);
	}
	*/
}