Made enums on tide face follow other faces
This commit is contained in:
@@ -40,9 +40,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
spring_tide, // Less than 1.8 days away from a full or new moon.
|
TIDE_SPRING, // Less than 1.8 days away from a full or new moon.
|
||||||
neap_tide, // Less than 1.8 days away from a first or third quarter moon.
|
TIDE_NEAP, // Less than 1.8 days away from a first or third quarter moon.
|
||||||
medium_tide, // The rest
|
TIDE_MEDIUM, // The rest
|
||||||
} tide_amplitude_t;
|
} tide_amplitude_t;
|
||||||
|
|
||||||
static tide_amplitude_t _get_tide_amplitude(uint32_t time) {
|
static tide_amplitude_t _get_tide_amplitude(uint32_t time) {
|
||||||
@@ -50,25 +50,25 @@ static tide_amplitude_t _get_tide_amplitude(uint32_t time) {
|
|||||||
double moon_age = fmod(((double)(time - FIRST_MOON)) / 86400, LUNAR_DAYS / 2);
|
double moon_age = fmod(((double)(time - FIRST_MOON)) / 86400, LUNAR_DAYS / 2);
|
||||||
|
|
||||||
if (moon_age <= LUNAR_DAYS / 16 || moon_age >= LUNAR_DAYS * 7 / 16) {
|
if (moon_age <= LUNAR_DAYS / 16 || moon_age >= LUNAR_DAYS * 7 / 16) {
|
||||||
return spring_tide;
|
return TIDE_SPRING;
|
||||||
} else if (moon_age > LUNAR_DAYS * 3 / 16 && moon_age < LUNAR_DAYS * 5 / 16) {
|
} else if (moon_age > LUNAR_DAYS * 3 / 16 && moon_age < LUNAR_DAYS * 5 / 16) {
|
||||||
return neap_tide;
|
return TIDE_NEAP;
|
||||||
} else {
|
} else {
|
||||||
return medium_tide;
|
return TIDE_MEDIUM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
empty, // No tide data set.
|
TIDE_SCREEN_EMPTY, // No tide data set.
|
||||||
current, // Default screen, showing the current tide.
|
TIDE_SCREEN_CURRENT, // Default screen, showing the current tide.
|
||||||
future, // Screen showing the time of future high and low tides.
|
TIDE_SCREEN_FUTURE, // Screen showing the time of future high and low tides.
|
||||||
setting_hour, // Setting screen, setting the hour of the next high tide.
|
TIDE_SCREEN_SETTING_HOUR, // Setting screen, setting the hour of the next high tide.
|
||||||
setting_min, // Setting screen, setting the minute of the next high tide.
|
TIDE_SCREEN_SETTING_MIN, // Setting screen, setting the minute of the next high tide.
|
||||||
} tide_mode_t;
|
} tide_mode_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
high_tide,
|
TIDE_HIGH,
|
||||||
low_tide,
|
TIDE_LOW,
|
||||||
} tide_type_t;
|
} tide_type_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -86,7 +86,7 @@ void tide_face_setup(uint8_t watch_face_index, void** state_ptr) {
|
|||||||
// Boot time initialization.
|
// Boot time initialization.
|
||||||
*state_ptr = malloc(sizeof(tide_state_t));
|
*state_ptr = malloc(sizeof(tide_state_t));
|
||||||
tide_state_t* state = (tide_state_t*)*state_ptr;
|
tide_state_t* state = (tide_state_t*)*state_ptr;
|
||||||
state->mode = empty;
|
state->mode = TIDE_SCREEN_EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +105,8 @@ static void _move_next_high_tide(tide_state_t* state, uint32_t now) {
|
|||||||
|
|
||||||
void tide_face_activate(void* context) {
|
void tide_face_activate(void* context) {
|
||||||
tide_state_t* state = (tide_state_t*)context;
|
tide_state_t* state = (tide_state_t*)context;
|
||||||
if (state->mode != empty) {
|
if (state->mode != TIDE_SCREEN_EMPTY) {
|
||||||
state->mode = current;
|
state->mode = TIDE_SCREEN_CURRENT;
|
||||||
}
|
}
|
||||||
// int64 so that the substraction below works (we need a signed number and int32 will overflow soon).
|
// int64 so that the substraction below works (we need a signed number and int32 will overflow soon).
|
||||||
// using int64 everywhere for the unix time would probably be better.
|
// using int64 everywhere for the unix time would probably be better.
|
||||||
@@ -114,7 +114,7 @@ void tide_face_activate(void* context) {
|
|||||||
if (llabs(now - state->next_high_tide) > 60 * 86400) {
|
if (llabs(now - state->next_high_tide) > 60 * 86400) {
|
||||||
// We revert to the empty mode if the next high tide is more than 2
|
// We revert to the empty mode if the next high tide is more than 2
|
||||||
// months from now, to avoid accumulating too much errors.
|
// months from now, to avoid accumulating too much errors.
|
||||||
state->mode = empty;
|
state->mode = TIDE_SCREEN_EMPTY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_move_next_high_tide(state, now);
|
_move_next_high_tide(state, now);
|
||||||
@@ -128,13 +128,13 @@ static void _draw_tide_amplitude(uint32_t time) {
|
|||||||
const digit_mapping_t* digit_mapping =
|
const digit_mapping_t* digit_mapping =
|
||||||
watch_get_lcd_type() == WATCH_LCD_TYPE_CLASSIC ? Classic_LCD_Display_Mapping : Custom_LCD_Display_Mapping;
|
watch_get_lcd_type() == WATCH_LCD_TYPE_CLASSIC ? Classic_LCD_Display_Mapping : Custom_LCD_Display_Mapping;
|
||||||
switch (_get_tide_amplitude(time)) {
|
switch (_get_tide_amplitude(time)) {
|
||||||
case spring_tide:
|
case TIDE_SPRING:
|
||||||
_set_pixel(digit_mapping[9].segment[0]); // top horizontal bar on the bottom-right character.
|
_set_pixel(digit_mapping[9].segment[0]); // top horizontal bar on the bottom-right character.
|
||||||
// fall-through
|
// fall-through
|
||||||
case medium_tide:
|
case TIDE_MEDIUM:
|
||||||
_set_pixel(digit_mapping[9].segment[6]); // mid horizontal bar on the bottom-right character.
|
_set_pixel(digit_mapping[9].segment[6]); // mid horizontal bar on the bottom-right character.
|
||||||
// fall-through
|
// fall-through
|
||||||
case neap_tide:
|
case TIDE_NEAP:
|
||||||
_set_pixel(digit_mapping[9].segment[3]); // bottom horizontal bar on the bottom-right character.
|
_set_pixel(digit_mapping[9].segment[3]); // bottom horizontal bar on the bottom-right character.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -175,11 +175,11 @@ static void _draw_day_and_time(uint32_t time, bool show_day, bool show_hour, boo
|
|||||||
static void _draw(tide_state_t *state, uint32_t now, uint8_t subsecond) {
|
static void _draw(tide_state_t *state, uint32_t now, uint8_t subsecond) {
|
||||||
watch_clear_display();
|
watch_clear_display();
|
||||||
switch (state->mode) {
|
switch (state->mode) {
|
||||||
case empty:
|
case TIDE_SCREEN_EMPTY:
|
||||||
watch_display_text_with_fallback(WATCH_POSITION_TOP, "TIDE", "TI");
|
watch_display_text_with_fallback(WATCH_POSITION_TOP, "TIDE", "TI");
|
||||||
watch_display_text(WATCH_POSITION_BOTTOM, "----");
|
watch_display_text(WATCH_POSITION_BOTTOM, "----");
|
||||||
break;
|
break;
|
||||||
case current: {
|
case TIDE_SCREEN_CURRENT: {
|
||||||
double tide_age = state->next_high_tide - now;
|
double tide_age = state->next_high_tide - now;
|
||||||
_draw_tide_amplitude(now);
|
_draw_tide_amplitude(now);
|
||||||
double tide_percent = (cos(tide_age / SEMI_DIURNAL_TIDAL_PERIOD * M_PI * 2) + 1) * 50;
|
double tide_percent = (cos(tide_age / SEMI_DIURNAL_TIDAL_PERIOD * M_PI * 2) + 1) * 50;
|
||||||
@@ -214,8 +214,8 @@ static void _draw(tide_state_t *state, uint32_t now, uint8_t subsecond) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case future:
|
case TIDE_SCREEN_FUTURE:
|
||||||
if (state->future_tide_type == low_tide) {
|
if (state->future_tide_type == TIDE_LOW) {
|
||||||
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "LOW", "LO");
|
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "LOW", "LO");
|
||||||
} else {
|
} else {
|
||||||
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "HIG", "HI");
|
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "HIG", "HI");
|
||||||
@@ -223,15 +223,15 @@ static void _draw(tide_state_t *state, uint32_t now, uint8_t subsecond) {
|
|||||||
_draw_day_and_time(state->future_tide_time, true, true, true);
|
_draw_day_and_time(state->future_tide_time, true, true, true);
|
||||||
_draw_tide_amplitude(state->future_tide_time);
|
_draw_tide_amplitude(state->future_tide_time);
|
||||||
break;
|
break;
|
||||||
case setting_hour:
|
case TIDE_SCREEN_SETTING_HOUR:
|
||||||
case setting_min:
|
case TIDE_SCREEN_SETTING_MIN:
|
||||||
if (state->start_setting) {
|
if (state->start_setting) {
|
||||||
watch_display_text_with_fallback(WATCH_POSITION_TOP, "HIGH", "HI");
|
watch_display_text_with_fallback(WATCH_POSITION_TOP, "HIGH", "HI");
|
||||||
} else {
|
} else {
|
||||||
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "HIG", "HI");
|
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "HIG", "HI");
|
||||||
}
|
}
|
||||||
_draw_day_and_time(state->next_high_tide, !state->start_setting,
|
_draw_day_and_time(state->next_high_tide, !state->start_setting,
|
||||||
(state->mode != setting_hour || subsecond % 2), (state->mode != setting_min || subsecond % 2));
|
(state->mode != TIDE_SCREEN_SETTING_HOUR || subsecond % 2), (state->mode != TIDE_SCREEN_SETTING_MIN || subsecond % 2));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,21 +252,21 @@ bool tide_face_loop(movement_event_t event, void* context) {
|
|||||||
switch (event.event_type) {
|
switch (event.event_type) {
|
||||||
case EVENT_ACTIVATE:
|
case EVENT_ACTIVATE:
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
if (state->mode == current) {
|
if (state->mode == TIDE_SCREEN_CURRENT) {
|
||||||
state->last_current_update_time = now;
|
state->last_current_update_time = now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EVENT_TICK:
|
case EVENT_TICK:
|
||||||
switch (state->mode) {
|
switch (state->mode) {
|
||||||
case current:
|
case TIDE_SCREEN_CURRENT:
|
||||||
if (now - state->last_current_update_time >= 60) {
|
if (now - state->last_current_update_time >= 60) {
|
||||||
_move_next_high_tide(state, now);
|
_move_next_high_tide(state, now);
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
state->last_current_update_time = now;
|
state->last_current_update_time = now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case setting_hour:
|
case TIDE_SCREEN_SETTING_HOUR:
|
||||||
case setting_min:
|
case TIDE_SCREEN_SETTING_MIN:
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -283,12 +283,12 @@ bool tide_face_loop(movement_event_t event, void* context) {
|
|||||||
break;
|
break;
|
||||||
case EVENT_LIGHT_BUTTON_DOWN:
|
case EVENT_LIGHT_BUTTON_DOWN:
|
||||||
switch (state->mode) {
|
switch (state->mode) {
|
||||||
case setting_hour:
|
case TIDE_SCREEN_SETTING_HOUR:
|
||||||
state->mode = setting_min;
|
state->mode = TIDE_SCREEN_SETTING_MIN;
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
break;
|
break;
|
||||||
case setting_min:
|
case TIDE_SCREEN_SETTING_MIN:
|
||||||
state->mode = current;
|
state->mode = TIDE_SCREEN_CURRENT;
|
||||||
_move_next_high_tide(state, _get_current_unix_time());
|
_move_next_high_tide(state, _get_current_unix_time());
|
||||||
movement_request_tick_frequency(1);
|
movement_request_tick_frequency(1);
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
@@ -299,18 +299,18 @@ bool tide_face_loop(movement_event_t event, void* context) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EVENT_LIGHT_LONG_PRESS:
|
case EVENT_LIGHT_LONG_PRESS:
|
||||||
if (state->mode == future) {
|
if (state->mode == TIDE_SCREEN_FUTURE) {
|
||||||
state->mode = current;
|
state->mode = TIDE_SCREEN_CURRENT;
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
state->last_current_update_time = now;
|
state->last_current_update_time = now;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EVENT_ALARM_BUTTON_DOWN:
|
case EVENT_ALARM_BUTTON_DOWN:
|
||||||
switch(state->mode) {
|
switch(state->mode) {
|
||||||
case setting_hour:
|
case TIDE_SCREEN_SETTING_HOUR:
|
||||||
_offset_next_high_tide(state, 3600);
|
_offset_next_high_tide(state, 3600);
|
||||||
break;
|
break;
|
||||||
case setting_min:
|
case TIDE_SCREEN_SETTING_MIN:
|
||||||
_offset_next_high_tide(state, 60);
|
_offset_next_high_tide(state, 60);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -319,21 +319,21 @@ bool tide_face_loop(movement_event_t event, void* context) {
|
|||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
break;
|
break;
|
||||||
case EVENT_ALARM_BUTTON_UP:
|
case EVENT_ALARM_BUTTON_UP:
|
||||||
// We react to UP event only so that we don’t switch to a future day at the beginning of a long press.
|
// We react to UP event only so that we don’t switch to a TIDE_SCREEN_FUTURE day at the beginning of a long press.
|
||||||
switch(state->mode) {
|
switch(state->mode) {
|
||||||
case current:
|
case TIDE_SCREEN_CURRENT:
|
||||||
if (state->next_high_tide - now > SEMI_DIURNAL_TIDAL_PERIOD / 2) {
|
if (state->next_high_tide - now > SEMI_DIURNAL_TIDAL_PERIOD / 2) {
|
||||||
state->future_tide_time = state->next_high_tide - SEMI_DIURNAL_TIDAL_PERIOD / 2;
|
state->future_tide_time = state->next_high_tide - SEMI_DIURNAL_TIDAL_PERIOD / 2;
|
||||||
state->future_tide_type = low_tide;
|
state->future_tide_type = TIDE_LOW;
|
||||||
} else {
|
} else {
|
||||||
state->future_tide_time = state->next_high_tide;
|
state->future_tide_time = state->next_high_tide;
|
||||||
state->future_tide_type = high_tide;
|
state->future_tide_type = TIDE_HIGH;
|
||||||
}
|
}
|
||||||
state->mode = future;
|
state->mode = TIDE_SCREEN_FUTURE;
|
||||||
break;
|
break;
|
||||||
case future:
|
case TIDE_SCREEN_FUTURE:
|
||||||
state->future_tide_time += SEMI_DIURNAL_TIDAL_PERIOD / 2;
|
state->future_tide_time += SEMI_DIURNAL_TIDAL_PERIOD / 2;
|
||||||
state->future_tide_type = state->future_tide_type == low_tide ? high_tide : low_tide;
|
state->future_tide_type = state->future_tide_type == TIDE_LOW ? TIDE_HIGH : TIDE_LOW;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -342,27 +342,27 @@ bool tide_face_loop(movement_event_t event, void* context) {
|
|||||||
break;
|
break;
|
||||||
case EVENT_ALARM_LONG_PRESS:
|
case EVENT_ALARM_LONG_PRESS:
|
||||||
switch(state->mode) {
|
switch(state->mode) {
|
||||||
case empty:
|
case TIDE_SCREEN_EMPTY:
|
||||||
state->next_high_tide = _get_current_unix_time();
|
state->next_high_tide = _get_current_unix_time();
|
||||||
// fall-through
|
// fall-through
|
||||||
case current:
|
case TIDE_SCREEN_CURRENT:
|
||||||
case future:
|
case TIDE_SCREEN_FUTURE:
|
||||||
state->mode = setting_hour;
|
state->mode = TIDE_SCREEN_SETTING_HOUR;
|
||||||
state->start_setting = true;
|
state->start_setting = true;
|
||||||
movement_request_tick_frequency(4);
|
movement_request_tick_frequency(4);
|
||||||
break;
|
break;
|
||||||
case setting_hour:
|
case TIDE_SCREEN_SETTING_HOUR:
|
||||||
case setting_min:
|
case TIDE_SCREEN_SETTING_MIN:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
break;
|
break;
|
||||||
case EVENT_MODE_BUTTON_DOWN:
|
case EVENT_MODE_BUTTON_DOWN:
|
||||||
switch(state->mode) {
|
switch(state->mode) {
|
||||||
case setting_hour:
|
case TIDE_SCREEN_SETTING_HOUR:
|
||||||
_offset_next_high_tide(state, -3600);
|
_offset_next_high_tide(state, -3600);
|
||||||
break;
|
break;
|
||||||
case setting_min:
|
case TIDE_SCREEN_SETTING_MIN:
|
||||||
_offset_next_high_tide(state, -60);
|
_offset_next_high_tide(state, -60);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -373,16 +373,16 @@ bool tide_face_loop(movement_event_t event, void* context) {
|
|||||||
case EVENT_MODE_BUTTON_UP:
|
case EVENT_MODE_BUTTON_UP:
|
||||||
case EVENT_MODE_LONG_PRESS:
|
case EVENT_MODE_LONG_PRESS:
|
||||||
switch(state->mode) {
|
switch(state->mode) {
|
||||||
case setting_hour:
|
case TIDE_SCREEN_SETTING_HOUR:
|
||||||
case setting_min:
|
case TIDE_SCREEN_SETTING_MIN:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return movement_default_loop_handler(event);
|
return movement_default_loop_handler(event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EVENT_TIMEOUT:
|
case EVENT_TIMEOUT:
|
||||||
if (state->mode == setting_min || state->mode == setting_hour) {
|
if (state->mode == TIDE_SCREEN_SETTING_MIN || state->mode == TIDE_SCREEN_SETTING_HOUR) {
|
||||||
state->mode = current;
|
state->mode = TIDE_SCREEN_CURRENT;
|
||||||
_draw(state, now, event.subsecond);
|
_draw(state, now, event.subsecond);
|
||||||
}
|
}
|
||||||
// fall-through
|
// fall-through
|
||||||
@@ -397,7 +397,7 @@ bool tide_face_loop(movement_event_t event, void* context) {
|
|||||||
void tide_face_resign(void* context) {
|
void tide_face_resign(void* context) {
|
||||||
// Any cleanup needed before the watch face goes off-screen.
|
// Any cleanup needed before the watch face goes off-screen.
|
||||||
tide_state_t* state = (tide_state_t*)context;
|
tide_state_t* state = (tide_state_t*)context;
|
||||||
if (state->mode == setting_hour || state->mode == setting_min) {
|
if (state->mode == TIDE_SCREEN_SETTING_HOUR || state->mode == TIDE_SCREEN_SETTING_MIN) {
|
||||||
// Not strictly needed because it will be done upon re-entering the
|
// Not strictly needed because it will be done upon re-entering the
|
||||||
// watch face. But let’s leave a clean state.
|
// watch face. But let’s leave a clean state.
|
||||||
_move_next_high_tide(state, _get_current_unix_time());
|
_move_next_high_tide(state, _get_current_unix_time());
|
||||||
|
|||||||
Reference in New Issue
Block a user