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(); } } }
void updateDayAndNightInfo() { static char sunrise_text[] = "00:00"; static char sunset_text[] = "00:00"; PblTm pblTime; get_time(&pblTime); if(currentData != pblTime.tm_hour) { moonphase_text[0] = 'a' + 26.0f * moon_phase(1900 + pblTime.tm_year, 1 + pblTime.tm_mon, pblTime.tm_mday); 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, LATITUDE, LONGITUDE, 91.0f); float sunsetTime = calcSunSet(pblTime.tm_year, pblTime.tm_mon+1, pblTime.tm_mday, LATITUDE, LONGITUDE, 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; } }
void bgpicker_updateLocation(LocationInfo loc) { bgpicker_location = loc; APP_LOG(APP_LOG_LEVEL_DEBUG, "Calculating with location: Lat: %d, Lng: %d, TZ: %d ", (int)(loc.lat*100), (int)(loc.lng*100), (int)(loc.tzOffset*100)); // determine what day it is, since we'll need this time_t rawTime; struct tm * timeInfo; time(&rawTime); timeInfo = localtime(&rawTime); // get the sunrise/sunset data float sunRiseTime, sunSetTime; int sunRiseMin, sunSetMin; APP_LOG(APP_LOG_LEVEL_DEBUG, "Params 1: Year: %d, Month: %d, Day: %d, Z: %d", (int)timeInfo->tm_year, (int)timeInfo->tm_mon, (int)timeInfo->tm_mday, (int)ZENITH_OFFICIAL); sunRiseTime = calcSunRise(timeInfo->tm_year, timeInfo->tm_mon + 1, timeInfo->tm_mday, loc.lat, loc.lng, ZENITH_OFFICIAL); sunSetTime = calcSunSet(timeInfo->tm_year, timeInfo->tm_mon + 1, timeInfo->tm_mday, loc.lat, loc.lng, ZENITH_OFFICIAL); APP_LOG(APP_LOG_LEVEL_DEBUG, "Sunrise Time Initial R: %d, S: %d", (int)(sunRiseTime*100), (int)(sunSetTime*100)); sunRiseTime = adjustTimezone(sunRiseTime, loc.tzOffset); sunSetTime = adjustTimezone(sunSetTime, loc.tzOffset); // for some reason, we have to add/subtract 12 hours (720 minutes) sunRiseMin = (int)(sunRiseTime * 60) - 720; sunSetMin = (int)(sunSetTime * 60) + 720; APP_LOG(APP_LOG_LEVEL_DEBUG, "Sunrise Time Initial R: %d, S: %d", (int)(sunRiseTime*100), (int)(sunSetTime*100)); APP_LOG(APP_LOG_LEVEL_DEBUG, "Sunrise recalculated! R: %d, S: %d", sunRiseMin, sunSetMin); bgpicker_setSunriseSunset(sunRiseMin, sunSetMin); // save the new location data to persistent storage persist_write_data(BGPICKER_LOC_KEY, &loc, sizeof(LocationInfo)); }
void updateSunsetSunrise() { // Calculating Sunrise/sunset with courtesy of Michael Ehrmann // https://github.com/mehrmann/pebble-sunclock static char sunrise_text[] = "00:00"; static char sunset_text[] = "00:00"; PblTm pblTime; get_time(&pblTime); 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, our_latitude / 10000, our_longitude / 10000, 91.0f); float sunsetTime = calcSunSet(pblTime.tm_year, pblTime.tm_mon+1, pblTime.tm_mday, our_latitude / 10000, our_longitude / 10000, 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); }
/** * Calculate rise / set time pair for a given zenith value and UTC date. * * @param riseTime Set to local time (hour + fraction) sun rises to specified * zenith on given date. * @param setTime Set to local time (hour + fraction) sun sets to specified * zenith on given date. * @param dateLocal Local date to find rise/set values for. * @param zenith Definition of "rise" / "set": used to select true rise / set, * or various flavors of twilight. This is an unsigned deflection * angle in degrees, with zero representing "directly overhead" (noon). */ static void calcRiseAndSet(float *riseTime, float *setTime, const struct tm* dateLocal, float zenith) { float latitude = config_data_get_latitude(); float longitude = config_data_get_longitude(); //BUGBUG - date should be UTC! *riseTime = calcSunRise(dateLocal->tm_year, dateLocal->tm_mon + 1, dateLocal->tm_mday, latitude, longitude, zenith); *setTime = calcSunSet(dateLocal->tm_year, dateLocal->tm_mon + 1, dateLocal->tm_mday, latitude, longitude, zenith); // convert UTC outputs to local time adjustTimezone(riseTime); adjustTimezone(setTime); }