void DashboardInstrument_Moon::SetUtcTime( wxDateTime data ) { if (data.IsValid()) { m_phase = moon_phase(data.GetYear(), data.GetMonth() + 1, data.GetDay()); } }
moon_phase calendar::moon() { int phase = day / (DAYS_IN_SEASON / 4); //phase %= 4; Redundant? if (phase == 3) return MOON_HALF; else return moon_phase(phase); }
moon_phase calendar::moon() const { int phase = day / (OPTIONS["SEASON_LENGTH"] / 4); //phase %= 4; Redundant? if (phase == 3) return MOON_HALF; else return moon_phase(phase); }
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; } }
moon_phase calendar::moon() const { int phase = int(day / (season_length() / 4)); //phase %= 4; Redundant? if (phase == 3) { return MOON_HALF; } else { return moon_phase(phase); } }
moon_phase calendar::moon() const { //One full phase every 2 rl months = 2/3 season length static float phase_change_per_day = 1.0 / ((float(season_length()) * 2.0 / 3.0) / float(MOON_PHASE_MAX)); //Switch moon phase at noon so it stays the same all night const int current_day = round( (calendar::turn.get_turn() + DAYS(1) / 2) / DAYS(1) ); const int current_phase = int(round(float(current_day) * phase_change_per_day)) % int(MOON_PHASE_MAX); return moon_phase(current_phase); }
moon_phase calendar::moon() { int phase = day / (DAYS_IN_SEASON / 4); //CAT-mgs: not redundant, necessary phase %= 4; if(phase == 3) return MOON_HALF; else return moon_phase(phase); }
int calc_moonphase_number(double latitude) { // moon int moonphase_number = 0; time_t timeNow; timeNow = time(NULL); moonphase_number = moon_phase(tm2jd(gmtime(&timeNow))); // correct for southern hemisphere if ((moonphase_number > 0) && (latitude < 0)) moonphase_number = 28 - moonphase_number; return moonphase_number; //static int i = 0; //i++; //if (i > 27) i = 0; //return i; }
// Called once per day void handle_day(AppContextRef ctx, PebbleTickEvent *t) { (void)t; (void)ctx; static char moon[] = "m"; int moonphase_number = 0; PblTm *time = t->tick_time; if(!t) get_time(time); // date //string_format_time(date, sizeof(date), "%m/%d/%Y", time); //text_layer_set_text(&dateLayer, date); // moon moonphase_number = moon_phase(tm2jd(time)); // correct for southern hemisphere if ((moonphase_number > 0) && (realLatitude < 0)) moonphase_number = 28 - moonphase_number; // select correct font char if (moonphase_number == 14) { moon[0] = (unsigned char)(48); } else if (moonphase_number == 0) { moon[0] = (unsigned char)(49); } else if (moonphase_number < 14) { moon[0] = (unsigned char)(moonphase_number+96); } else { moon[0] = (unsigned char)(moonphase_number+95); } text_layer_set_text(&moonLayer, moon); }
//-- Called each minute static void handle_minute_tick(struct tm *tick_time, TimeUnits units_changed) { // Need to be static because they're used by the system later. static char time_text[] = "00:00"; char *time_format; static char wday_str[] = " Xxxxxxxx"; static char daymonth_str[] = "00 Xxxxxxxxxx"; static char weeknumber_str[] = "Semaine 00"; //static char battery_str[] = "000%"; //-- Refresh week day snprintf(wday_str,sizeof(wday_str),"%s",WEEKDAYS[tick_time->tm_wday]); text_layer_set_text(text_wday_layer,wday_str); //-- Refresh day and month if (DAYMONTH_FORMAT==0) snprintf(daymonth_str,sizeof(daymonth_str),"%d %s",(int)tick_time->tm_mday,MONTHS[tick_time->tm_mon]); else snprintf(daymonth_str,sizeof(daymonth_str),"%s %d",MONTHS[tick_time->tm_mon],(int)tick_time->tm_mday); text_layer_set_text(text_day_month_layer, daymonth_str); //-- Refresh week number snprintf(weeknumber_str,sizeof(weeknumber_str),WEEK,weeknumber(tick_time->tm_mday, tick_time->tm_mon+1, tick_time->tm_year+1900)); text_layer_set_text(text_weeknumber_layer, weeknumber_str); //-- Refresh battery level BatteryChargeState charge_state = battery_state_service_peek(); gbitmap_destroy(bitmap_battery); bitmap_battery=gbitmap_create_with_resource(BATT_IMG[charge_state.charge_percent/10]); bitmap_layer_set_bitmap(img_battery_layer,bitmap_battery); //-- Refresh Time if (clock_is_24h_style()) { time_format = "%R"; } else { time_format = "%I:%M"; } strftime(time_text,sizeof(time_text), time_format, tick_time); // Kludge to handle lack of non-padded hour format string // for twelve hour clock. if (!clock_is_24h_style() && (time_text[0] == '0')) { memmove(time_text, &time_text[1], sizeof(time_text) - 1); } text_layer_set_text(text_time_layer, time_text); //-- Bluetooth connection indicator /* gbitmap_destroy(bitmap_bluetooth); if (bluetooth_connection_service_peek()) bitmap_bluetooth=gbitmap_create_with_resource(RESOURCE_ID_IMG_BLUETOOTH); else bitmap_bluetooth=gbitmap_create_with_resource(RESOURCE_ID_IMG_EMPTY); bitmap_layer_set_bitmap(img_bluetooth_layer,bitmap_bluetooth); */ layer_set_hidden(bitmap_layer_get_layer(img_bluetooth_layer),(!bluetooth_connection_service_peek())); //-- Moon indicator gbitmap_destroy(bitmap_moon); int mph=moon_phase( julianday(tick_time->tm_mday, tick_time->tm_mon+1, tick_time->tm_year+1900) ); if (mph==0) mph=1; //In some case there is this problem bitmap_moon=gbitmap_create_with_resource(MOON_IMG[mph-1]); bitmap_layer_set_bitmap(img_moon_layer,bitmap_moon); //-- Vibrate function - 1 vibrate each 30min / 2 vibrates each hour (from 9h to 21h) int h; h= (tick_time->tm_hour)*100 + tick_time->tm_min; //if ((htick_time->tm_hour>=9) && (tick_time->tm_hour<=21)) { if ((h>=900) && (h<=2100)) { if ( (tick_time->tm_min==30) && (tick_time->tm_sec==0) ) vibes_short_pulse(); if ( (tick_time->tm_min==00) && (tick_time->tm_sec==0) ) vibes_double_pulse(); } }
// Called once per day void handle_day(AppContextRef ctx, PebbleTickEvent* t) { (void)t; (void)ctx; static char riseText[] = "00:00a 00:00a"; static char setText[] = "00:00a 00:00a"; static char moon1Text[] = "<00:00a\n<00:00a"; static char moon2Text[] = "00:00a>\n00:00a>"; static char date[] = "00/00/0000"; static char moon[] = "m"; static char moonp[] = "-----"; char riseTemp[] = "00:00a"; char setTemp[] = "00:00a"; float moonphase_number = 0.0; int moonphase_letter = 0; float sunrise, sunset, dawn, dusk, moonrise[3], moonset[3]; PblTm* time = t->tick_time; if (!t) get_time(time); // date string_format_time(date, sizeof(date), DATEFMT, time); text_layer_set_text(&dateLayer, date); moonphase_number = moon_phase(tm2jd(time)); moonphase_letter = (int)(moonphase_number*27 + 0.5); // correct for southern hemisphere if ((moonphase_letter > 0) && (LAT < 0)) moonphase_letter = 28 - moonphase_letter; // select correct font char if (moonphase_letter == 14) { moon[0] = (unsigned char)(48); } else if (moonphase_letter == 0) { moon[0] = (unsigned char)(49); } else if (moonphase_letter < 14) { moon[0] = (unsigned char)(moonphase_letter+96); } else { moon[0] = (unsigned char)(moonphase_letter+95); } text_layer_set_text(&moonLayer, moon); if (moonphase_number >= 0.5) { mini_snprintf(moonp,sizeof(moonp)," %d-",(int)((1-(1+pbl_cos(moonphase_number*M_PI*2))/2)*100)); } else { mini_snprintf(moonp,sizeof(moonp)," %d+",(int)((1-(1+pbl_cos(moonphase_number*M_PI*2))/2)*100)); } text_layer_set_text(&moonPercent, moonp); //sun rise set sunmooncalc(tm2jd(time), TZ, LAT, -LON, 1, &sunrise, &sunset); sunmooncalc(tm2jd(time), TZ, LAT, -LON, 2, &dawn, &dusk); (dawn == 99.0) ? mini_snprintf(riseTemp,sizeof(riseTemp),"--:--") : mini_snprintf(riseTemp,sizeof(riseTemp),"%s",thr(dawn,0)); (sunrise == 99.0) ? mini_snprintf(riseText,sizeof(riseText),"%s --:--",riseTemp) : mini_snprintf(riseText,sizeof(riseText),"%s %s",riseTemp,thr(sunrise,0)); (sunset == 99.0) ? mini_snprintf(setTemp,sizeof(setTemp),"--:--") : mini_snprintf(setTemp,sizeof(setTemp),"%s",thr(sunset,0)); (dusk == 99.0) ? mini_snprintf(setText,sizeof(setText),"%s --:--",setTemp) : mini_snprintf(setText,sizeof(setText),"%s %s",setTemp,thr(dusk,0)); text_layer_set_text(&riseLayer, riseText); text_layer_set_text(&setLayer, setText); //moon times sunmooncalc(tm2jd(time)-1, TZ, LAT, -LON, 0, &moonrise[0], &moonset[0]); // yesterday sunmooncalc(tm2jd(time), TZ, LAT, -LON, 0, &moonrise[1], &moonset[1]); // today sunmooncalc(tm2jd(time)+1, TZ, LAT, -LON, 0, &moonrise[2], &moonset[2]); // tomorrow if (moonrise[1] == 99.0) { // moon didn't rise today mini_snprintf(moon1Text,sizeof(moon1Text),"<%s",mthr(moonrise[0],moonset[1],"\0")); mini_snprintf(moon2Text,sizeof(moon2Text),"%s>",mthr(moonrise[2],moonset[2],">")); } else if (moonset[1] == 99.0) { // moon didn't set today mini_snprintf(moon1Text,sizeof(moon1Text),"%s>",mthr(moonrise[1],moonset[2],"\0")); mini_snprintf(moon2Text,sizeof(moon2Text),"%s>\n--:--",thr(moonrise[2],1)); } else if (moonrise[1] > moonset[1]) { // moon rose before midnight, rises again today mini_snprintf(moon1Text,sizeof(moon1Text),"<%s",mthr(moonrise[0],moonset[1],"\0")); mini_snprintf(moon2Text,sizeof(moon2Text),"%s>",mthr(moonrise[1],moonset[2],"\0")); } else { // moon was down at midnight, rose today mini_snprintf(moon1Text,sizeof(moon1Text),"%s",mthr(moonrise[1],moonset[1],"\0")); mini_snprintf(moon2Text,sizeof(moon2Text),"%s>",mthr(moonrise[2],moonset[2],">")); } text_layer_set_text(&moonLeft, moon1Text); text_layer_set_text(&moonRight, moon2Text); }