Removing the stupid enum for minutes rounded and just using int. Also changing the display to be a bit more like what it should
This commit is contained in:
parent
9c470517ce
commit
f99273bf32
1 changed files with 60 additions and 128 deletions
178
src/c/tijd.c
178
src/c/tijd.c
|
|
@ -10,21 +10,6 @@ static TextLayer *s_addend_layer;
|
|||
static TextLayer *s_operator_layer;
|
||||
static Layer *s_operator_hand_layer;
|
||||
|
||||
enum MinutesRounded {
|
||||
MIN_ZERO,
|
||||
MIN_FIVE,
|
||||
MIN_TEN,
|
||||
MIN_FIFTEEN,
|
||||
MIN_TWENTY,
|
||||
MIN_TWENTYFIVE,
|
||||
MIN_THIRTY,
|
||||
MIN_THIRTYFIVE,
|
||||
MIN_FORTY,
|
||||
MIN_FORTYFIVE,
|
||||
MIN_FIFTY,
|
||||
MIN_FIFTYFIVE,
|
||||
};
|
||||
|
||||
enum Modifier {
|
||||
MOD_NONE,
|
||||
MOD_HOUR,
|
||||
|
|
@ -58,130 +43,73 @@ static bool time_components_eq(TimeComponents *tc1, TimeComponents *tc2) {
|
|||
tc1->add == tc2->add && tc1->mod == tc2->mod && tc1->op == tc2->op;
|
||||
}
|
||||
|
||||
static enum MinutesRounded get_minutes_rounded(struct tm *tick_time) {
|
||||
static int get_minutes_rounded(struct tm *tick_time) {
|
||||
int min_unrounded = tick_time->tm_min;
|
||||
int min_remainder = min_unrounded % 5;
|
||||
int min_base = min_unrounded - min_remainder;
|
||||
/**
|
||||
* rounded to nearest 5 mins where 3,4,5 round to 5 and 0,1,2 round to 0
|
||||
*/
|
||||
int min_rounded = min_base + (min_remainder >= 3 ? 5 : 0);
|
||||
APP_LOG(APP_LOG_LEVEL_INFO, "Minutes rounded: %d", min_rounded);
|
||||
switch (min_rounded) {
|
||||
case 0:
|
||||
return MIN_ZERO;
|
||||
case 5:
|
||||
return MIN_FIVE;
|
||||
case 10:
|
||||
return MIN_TEN;
|
||||
case 15:
|
||||
return MIN_FIFTEEN;
|
||||
case 20:
|
||||
return MIN_TWENTY;
|
||||
case 25:
|
||||
return MIN_TWENTYFIVE;
|
||||
case 30:
|
||||
return MIN_THIRTY;
|
||||
case 35:
|
||||
return MIN_THIRTYFIVE;
|
||||
case 40:
|
||||
return MIN_FORTY;
|
||||
case 45:
|
||||
return MIN_FORTYFIVE;
|
||||
case 50:
|
||||
return MIN_FIFTY;
|
||||
case 55:
|
||||
return MIN_FIFTY;
|
||||
case 60:
|
||||
default:
|
||||
return MIN_ZERO;
|
||||
}
|
||||
return min_base + (min_remainder >= 3 ? 5 : 0);
|
||||
}
|
||||
|
||||
static int get_hour_component(struct tm *tick_time, enum MinutesRounded mr) {
|
||||
int hour = ((tick_time->tm_hour) + (mr > 3 ? 1 : 0)) % 12;
|
||||
static int get_hour_component(struct tm *tick_time, int mr) {
|
||||
int hour = ((tick_time->tm_hour) + (mr >= 20 ? 1 : 0)) % 12;
|
||||
return hour == 0 ? 12 : hour;
|
||||
}
|
||||
|
||||
static enum Modifier get_modifier_component(enum MinutesRounded mr) {
|
||||
static enum Modifier get_modifier_component(int mr) {
|
||||
switch (mr) {
|
||||
case MIN_ZERO:
|
||||
case 0:
|
||||
case 60:
|
||||
return MOD_HOUR;
|
||||
case MIN_FIVE:
|
||||
return MOD_NONE;
|
||||
case MIN_TEN:
|
||||
return MOD_NONE;
|
||||
case MIN_FIFTEEN:
|
||||
return MOD_NONE;
|
||||
case MIN_TWENTY:
|
||||
case 20:
|
||||
case 25:
|
||||
case 30:
|
||||
case 35:
|
||||
case 40:
|
||||
return MOD_HALF;
|
||||
case MIN_TWENTYFIVE:
|
||||
return MOD_HALF;
|
||||
case MIN_THIRTY:
|
||||
return MOD_HALF;
|
||||
case MIN_THIRTYFIVE:
|
||||
return MOD_HALF;
|
||||
case MIN_FORTY:
|
||||
return MOD_HALF;
|
||||
case MIN_FORTYFIVE:
|
||||
return MOD_NONE;
|
||||
case MIN_FIFTY:
|
||||
return MOD_NONE;
|
||||
case MIN_FIFTYFIVE:
|
||||
return MOD_NONE;
|
||||
default:
|
||||
return MOD_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static enum Addend get_addend_component(enum MinutesRounded mr) {
|
||||
static enum Addend get_addend_component(int mr) {
|
||||
switch (mr) {
|
||||
case MIN_ZERO:
|
||||
case MIN_THIRTY:
|
||||
case 0:
|
||||
case 30:
|
||||
return ADDEND_ZERO;
|
||||
case MIN_FIVE:
|
||||
case MIN_TWENTYFIVE:
|
||||
case MIN_THIRTYFIVE:
|
||||
case MIN_FIFTYFIVE:
|
||||
case 5:
|
||||
case 25:
|
||||
case 35:
|
||||
case 55:
|
||||
return ADDEND_FIVE;
|
||||
case MIN_TEN:
|
||||
case MIN_TWENTY:
|
||||
case MIN_FORTY:
|
||||
case MIN_FIFTY:
|
||||
case 10:
|
||||
case 20:
|
||||
case 40:
|
||||
case 50:
|
||||
return ADDEND_TEN;
|
||||
case MIN_FIFTEEN:
|
||||
case MIN_FORTYFIVE:
|
||||
case 15:
|
||||
case 45:
|
||||
return ADDEND_QUARTER;
|
||||
default:
|
||||
return ADDEND_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
static enum Operator get_operator_component(enum MinutesRounded mr) {
|
||||
static enum Operator get_operator_component(int mr) {
|
||||
switch (mr) {
|
||||
case MIN_ZERO:
|
||||
return OPERATOR_NONE;
|
||||
case MIN_FIVE:
|
||||
case 5:
|
||||
case 10:
|
||||
case 15:
|
||||
case 35:
|
||||
case 40:
|
||||
return OPERATOR_PAST;
|
||||
case MIN_TEN:
|
||||
return OPERATOR_PAST;
|
||||
case MIN_FIFTEEN:
|
||||
return OPERATOR_PAST;
|
||||
case MIN_TWENTY:
|
||||
return OPERATOR_TILL;
|
||||
case MIN_TWENTYFIVE:
|
||||
return OPERATOR_TILL;
|
||||
case MIN_THIRTY:
|
||||
return OPERATOR_NONE;
|
||||
case MIN_THIRTYFIVE:
|
||||
return OPERATOR_PAST;
|
||||
case MIN_FORTY:
|
||||
return OPERATOR_PAST;
|
||||
case MIN_FORTYFIVE:
|
||||
return OPERATOR_TILL;
|
||||
case MIN_FIFTY:
|
||||
return OPERATOR_TILL;
|
||||
case MIN_FIFTYFIVE:
|
||||
case 20:
|
||||
case 25:
|
||||
case 45:
|
||||
case 50:
|
||||
case 55:
|
||||
return OPERATOR_TILL;
|
||||
default:
|
||||
return OPERATOR_NONE;
|
||||
|
|
@ -189,7 +117,7 @@ static enum Operator get_operator_component(enum MinutesRounded mr) {
|
|||
}
|
||||
|
||||
static TimeComponents get_time_components(struct tm *tick_time) {
|
||||
enum MinutesRounded mr = get_minutes_rounded(tick_time);
|
||||
int mr = get_minutes_rounded(tick_time);
|
||||
enum Modifier mod = get_modifier_component(mr);
|
||||
int hour = get_hour_component(tick_time, mr);
|
||||
enum Addend add = get_addend_component(mr);
|
||||
|
|
@ -277,9 +205,26 @@ static void update_time(struct tm *tick_time) {
|
|||
if (needs_redraw) {
|
||||
tc = new_tc;
|
||||
static char s_time_buffer[24];
|
||||
snprintf(s_time_buffer, sizeof(s_time_buffer), "\n%s\n%s\n%s\n%s",
|
||||
if (tc.mod == MOD_HOUR) {
|
||||
snprintf(s_time_buffer, sizeof(s_time_buffer), "%s\n%s",
|
||||
render_hour_component(tc.hour),
|
||||
render_modifier_component(tc.mod));
|
||||
} else if (tc.mod == MOD_HALF && tc.op != OPERATOR_NONE) {
|
||||
snprintf(
|
||||
s_time_buffer, sizeof(s_time_buffer), "%s\n%s\n%s\n%s",
|
||||
render_addend_component(tc.add), render_operator_component(tc.op),
|
||||
render_modifier_component(tc.mod), render_hour_component(tc.hour));
|
||||
} else if (tc.mod == MOD_HALF && tc.op == OPERATOR_NONE) {
|
||||
snprintf(s_time_buffer, sizeof(s_time_buffer), "%s\n%s",
|
||||
render_modifier_component(tc.mod),
|
||||
render_hour_component(tc.hour));
|
||||
} else {
|
||||
snprintf(s_time_buffer, sizeof(s_time_buffer), "%s\n%s\n%s",
|
||||
render_addend_component(tc.add),
|
||||
render_operator_component(tc.op),
|
||||
render_hour_component(tc.hour));
|
||||
}
|
||||
|
||||
layer_mark_dirty(s_operator_hand_layer);
|
||||
text_layer_set_text(s_time_layer, s_time_buffer);
|
||||
}
|
||||
|
|
@ -309,20 +254,7 @@ static void main_window_load(Window *window) {
|
|||
fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
|
||||
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
|
||||
|
||||
s_hour_layer = text_layer_create(bounds);
|
||||
text_layer_set_background_color(s_hour_layer, GColorClear);
|
||||
text_layer_set_text_color(s_hour_layer, GColorWhite);
|
||||
text_layer_set_font(s_hour_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
|
||||
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
|
||||
text_layer_set_text(s_time_layer, "TIJD");
|
||||
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_hour_layer));
|
||||
|
||||
GRect operator_hand_layer_bounds = GRect(bounds.origin.x + 20, bounds.origin.y + 20, bounds.size.w - 40, bounds.size.h - 40);
|
||||
s_operator_hand_layer = layer_create(operator_hand_layer_bounds);
|
||||
layer_set_update_proc(s_operator_hand_layer, operator_hand_layer_update_proc);
|
||||
layer_add_child(window_layer, s_operator_hand_layer);
|
||||
}
|
||||
|
||||
static void main_window_unload(Window *window) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue