Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to add presets to the sunrise and sunset face #420

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions movement/watch_faces/complication/sunrise_sunset_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <emscripten.h>
#endif

static const uint8_t _location_count = sizeof(longLatPresets) / sizeof(long_lat_presets_t);

static void _sunrise_sunset_set_expiration(sunrise_sunset_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);
Expand All @@ -46,7 +48,13 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
char buf[14];
double rise, set, minutes, seconds;
bool show_next_match = false;
movement_location_t movement_location = (movement_location_t) watch_get_backup_data(1);
movement_location_t movement_location;
if (state->longLatToUse == 0)
movement_location = (movement_location_t) watch_get_backup_data(1);
else{
movement_location.bit.latitude = longLatPresets[state->longLatToUse].latitude;
movement_location.bit.longitude = longLatPresets[state->longLatToUse].longitude;
}

if (movement_location.reg == 0) {
watch_display_string("RI no Loc", 0);
Expand Down Expand Up @@ -109,7 +117,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM);
else watch_clear_indicator(WATCH_INDICATOR_PM);
}
sprintf(buf, "rI%2d%2d%02d ", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute);
sprintf(buf, "rI%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);
return;
} else {
Expand All @@ -136,7 +144,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM);
else watch_clear_indicator(WATCH_INDICATOR_PM);
}
sprintf(buf, "SE%2d%2d%02d ", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute);
sprintf(buf, "SE%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);
return;
} else {
Expand Down Expand Up @@ -351,14 +359,24 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti
_sunrise_sunset_face_update_location_register(state);
}
_sunrise_sunset_face_update_settings_display(event, context);
} else {
} else if (_location_count == 1) {
movement_illuminate_led();
}
if (state->page == 0) {
movement_request_tick_frequency(1);
_sunrise_sunset_face_update(settings, state);
}
break;
case EVENT_LIGHT_LONG_PRESS:
if (_location_count == 1) break;
else if (!state->page) movement_illuminate_led();
break;
case EVENT_LIGHT_BUTTON_UP:
if (state->page == 0 && _location_count > 1) {
state->longLatToUse = (state->longLatToUse + 1) % _location_count;
_sunrise_sunset_face_update(settings, state);
}
break;
case EVENT_ALARM_BUTTON_UP:
if (state->page) {
_sunrise_sunset_face_advance_digit(state);
Expand All @@ -370,12 +388,23 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti
break;
case EVENT_ALARM_LONG_PRESS:
if (state->page == 0) {
if (state->longLatToUse != 0) {
state->longLatToUse = 0;
_sunrise_sunset_face_update(settings, state);
break;
}
state->page++;
state->active_digit = 0;
watch_clear_display();
movement_request_tick_frequency(4);
_sunrise_sunset_face_update_settings_display(event, context);
}
else {
state->active_digit = 0;
state->page = 0;
_sunrise_sunset_face_update_location_register(state);
_sunrise_sunset_face_update(settings, state);
}
break;
case EVENT_TIMEOUT:
if (watch_get_backup_data(1) == 0) {
Expand Down
15 changes: 15 additions & 0 deletions movement/watch_faces/complication/sunrise_sunset_face.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef struct {
watch_date_time rise_set_expires;
sunrise_sunset_lat_lon_settings_t working_latitude;
sunrise_sunset_lat_lon_settings_t working_longitude;
uint8_t longLatToUse;
} sunrise_sunset_state_t;

void sunrise_sunset_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
Expand All @@ -70,4 +71,18 @@ void sunrise_sunset_face_resign(movement_settings_t *settings, void *context);
NULL, \
})

typedef struct {
char name[2];
int16_t latitude;
int16_t longitude;
} long_lat_presets_t;

static const long_lat_presets_t longLatPresets[] =
{
{ .name = " "}, // Default, the long and lat get replaced by what's set in the watch
// { .name = "Ny", .latitude = 4072, .longitude = -7401 }, // New York City, NY
// { .name = "LA", .latitude = 3405, .longitude = -11824 }, // Los Angeles, CA
// { .name = "dE", .latitude = 4221, .longitude = -8305 }, // Detroit, MI
};

#endif // SUNRISE_SUNSET_FACE_H_
Loading