diff --git a/movement/watch_faces/complication/moonrise_face.c b/movement/watch_faces/complication/moonrise_face.c index e852ff30..b6b37225 100644 --- a/movement/watch_faces/complication/moonrise_face.c +++ b/movement/watch_faces/complication/moonrise_face.c @@ -39,14 +39,8 @@ static const uint8_t _location_count = sizeof(longLatPresets) / sizeof(long_lat_presets_t); -static void _moonrise_set_expiration(moonrise_state_t *state, watch_date_time next_rise_set) { - uint32_t timestamp = watch_utility_date_time_to_unix_time(next_rise_set, 0); - state->rise_set_expires = watch_utility_date_time_from_unix_time(timestamp + 60, 0); -} - static void _moonrise_face_update(movement_settings_t *settings, moonrise_state_t *state) { - char buf[14]; - bool show_next_match = false; + char buf[11]; movement_location_t movement_location; if (state->longLatToUse == 0 || _location_count <= 1) @@ -57,6 +51,7 @@ static void _moonrise_face_update(movement_settings_t *settings, moonrise_state_ } if (movement_location.reg == 0) { + watch_clear_colon(); watch_display_string("MR no Loc", 0); return; } @@ -75,81 +70,51 @@ static void _moonrise_face_update(movement_settings_t *settings, moonrise_state_ time_t t = watch_utility_date_time_to_unix_time(scratch_time, movement_timezone_offsets[settings->bit.time_zone] * 60); MoonRise mr = MoonRise_calculate(lat, lon, t); + if(mr.isVisible) watch_set_indicator(WATCH_INDICATOR_LAP); else watch_clear_indicator(WATCH_INDICATOR_LAP); - for(int i = 0; i < 2; i++) { - t = watch_utility_date_time_to_unix_time(scratch_time, movement_timezone_offsets[settings->bit.time_zone] * 60); - - MoonRise mr = MoonRise_calculate(lat, lon, t); - - if (!mr.hasRise && !mr.hasSet) { - watch_clear_colon(); - watch_clear_indicator(WATCH_INDICATOR_PM); - watch_clear_indicator(WATCH_INDICATOR_24H); - sprintf(buf, "MR%2d none ", scratch_time.unit.day); - watch_display_string(buf, 0); - return; - } - + if (!mr.hasRise && !mr.hasSet) { + watch_clear_colon(); + watch_clear_indicator(WATCH_INDICATOR_PM); + watch_clear_indicator(WATCH_INDICATOR_24H); + snprintf(buf, sizeof(buf), "MR%2d none ", scratch_time.unit.day); + watch_display_string(buf, 0); + return; + } watch_set_colon(); if (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) watch_set_indicator(WATCH_INDICATOR_24H); - scratch_time = watch_utility_date_time_from_unix_time(mr.riseTime, movement_timezone_offsets[settings->bit.time_zone] * 60); + if(state->rise_index == 0) + scratch_time = watch_utility_date_time_from_unix_time(mr.riseTime, movement_timezone_offsets[settings->bit.time_zone] * 60); + else + scratch_time = watch_utility_date_time_from_unix_time(mr.setTime, movement_timezone_offsets[settings->bit.time_zone] * 60); - if (date_time.reg < scratch_time.reg) _moonrise_set_expiration(state, scratch_time); + state->rise_set_expires.reg = scratch_time.reg; - if (date_time.reg < scratch_time.reg || show_next_match) { - if (state->rise_index == 0 || show_next_match) { - bool set_leading_zero = false; - if (!settings->bit.clock_mode_24h) { - if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM); - else watch_clear_indicator(WATCH_INDICATOR_PM); - } else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) { - set_leading_zero = true; - } - sprintf(buf, "M %2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); - watch_display_string(buf, 0); - watch_set_pixel(0,11); - if (set_leading_zero) - watch_display_string("0", 4); - return; - } else { - show_next_match = true; - } + + bool set_leading_zero = false; + if (!settings->bit.clock_mode_24h) + if (watch_utility_convert_to_12_hour(&scratch_time)) + watch_set_indicator(WATCH_INDICATOR_PM); + else + watch_clear_indicator(WATCH_INDICATOR_PM); + else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) { + set_leading_zero = true; } + snprintf(buf, sizeof(buf), "M %2d%2d%02d%2s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); + watch_display_string(buf, 0); + if(state->rise_index == 0) + watch_set_pixel(0,11); + else + watch_set_pixel(2,11); + if (set_leading_zero) + watch_display_string("0", 4); + return; - scratch_time = watch_utility_date_time_from_unix_time(mr.setTime, movement_timezone_offsets[settings->bit.time_zone] * 60); - - if (date_time.reg < scratch_time.reg) _moonrise_set_expiration(state, scratch_time); - - if (date_time.reg < scratch_time.reg || show_next_match) { - if (state->rise_index == 0 || show_next_match) { - bool set_leading_zero = false; - if (!settings->bit.clock_mode_24h) { - if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM); - else watch_clear_indicator(WATCH_INDICATOR_PM); - } else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) { - set_leading_zero = true; - } - sprintf(buf, "M %2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, longLatPresets[state->longLatToUse].name); - watch_display_string(buf, 0); - watch_set_pixel(2,11); - if (set_leading_zero) - watch_display_string("0", 4); - return; - } else { - show_next_match = true; - } - } - // it's after sunset. we need to display sunrise/sunset for tomorrow. - uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, 0); - timestamp += 86400; - scratch_time = watch_utility_date_time_from_unix_time(timestamp, 0); - } } static int16_t _moonrise_face_latlon_from_struct(moonrise_lat_lon_settings_t val) { @@ -201,10 +166,10 @@ static void _moonrise_face_update_settings_display(movement_event_t event, moonr case 0: return; case 1: - sprintf(buf, "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_latitude))); + snprintf(buf, sizeof(buf), "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_latitude))); break; case 2: - sprintf(buf, "LO %c%05d", state->working_longitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_longitude))); + snprintf(buf, sizeof(buf), "LO %c%05d", state->working_longitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_longitude))); break; } if (event.subsecond % 2) {