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 calcZmanim(struct Zmanim* out_zmanim, int year, int month, int day, float latitude, float longitude) { float sunrise = calcSunRise( year, month, day, latitude, longitude, 90.5f); float sunset = calcSunSet( year, month, day, latitude, longitude, 90.5f); float alos = calcSunRise( year, month, day, latitude, longitude, 106.6f); float mishyakir = calcSunRise( year, month, day, latitude, longitude, 102.0f); float tzais= calcSunSet( year, month, day, latitude, longitude, 99.0f); time_t day_start=time_start_of_today(); float haneitz=sunrise*60*60+day_start; float shkiya=sunset*60*60+day_start; float sha_gra = (shkiya-haneitz)/12.0f; float shma_gra=haneitz+sha_gra*3; float tefila_gra=haneitz+sha_gra*4; float chatzos=haneitz+sha_gra*6; float mincha_gedloa=haneitz+sha_gra*6.5; APP_LOG(APP_LOG_LEVEL_DEBUG, "start of today %d", (int) day_start); APP_LOG(APP_LOG_LEVEL_DEBUG, "sha gra %d", (int) sha_gra); APP_LOG(APP_LOG_LEVEL_DEBUG, "tefila gra %d", (int) tefila_gra); APP_LOG(APP_LOG_LEVEL_DEBUG, "sunrise %d", (int) sunrise*1000); APP_LOG(APP_LOG_LEVEL_DEBUG, "sunset %d", (int) sunset*1000); APP_LOG(APP_LOG_LEVEL_DEBUG, "haneitz %d", (int) haneitz); APP_LOG(APP_LOG_LEVEL_DEBUG, "shkiya %d", (int) shkiya); out_zmanim->alos=alos*60*60+day_start; out_zmanim->mishyakir=mishyakir*60*60+day_start; out_zmanim->haneitz=haneitz; out_zmanim->shma_gra=shma_gra; out_zmanim->tefila_gra=tefila_gra; out_zmanim->chatzos=chatzos; out_zmanim->mincha_gedloa=mincha_gedloa; out_zmanim->shkiya=shkiya; out_zmanim->tzais=tzais*60*60+day_start; out_zmanim->tzais_rt=(sunset*60*60+day_start)+72*60; out_zmanim->chatzos_halaila=chatzos+(12*60*60); APP_LOG(APP_LOG_LEVEL_DEBUG, "chatzos %d", (int) out_zmanim->chatzos); APP_LOG(APP_LOG_LEVEL_DEBUG, "chatzos haliala %d", (int) out_zmanim->chatzos_halaila); }
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); }