Skip to content

Commit

Permalink
improve API for text display
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Sep 19, 2024
1 parent 8bbcacd commit 9274f53
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 181 deletions.
10 changes: 5 additions & 5 deletions watch-faces/clock/simple_clock_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
if (date_time.unit.hour == 0) date_time.unit.hour = 12;
}
#endif
watch_display_top_left((char *) watch_utility_get_weekday(date_time));
watch_display_text(WATCH_POSITION_TOP_LEFT, (char *) watch_utility_get_weekday(date_time));
sprintf(buf, "%2d%2d%02d%02d", date_time.unit.day, date_time.unit.hour, date_time.unit.minute, date_time.unit.second);
watch_display_top_right(buf);
watch_display_hours(buf + 2);
watch_display_minutes(buf + 4);
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
watch_display_text(WATCH_POSITION_HOURS, buf + 2);
watch_display_text(WATCH_POSITION_MINUTES, buf + 4);
if (event.event_type == EVENT_LOW_ENERGY_UPDATE) {
if (!watch_tick_animation_is_running()) watch_start_tick_animation(500);
} else {
watch_display_seconds(buf + 6);
watch_display_text(WATCH_POSITION_SECONDS, buf + 6);
}
}

Expand Down
14 changes: 7 additions & 7 deletions watch-faces/settings/set_time_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
}

char buf[11];
watch_display_top_left((char *) set_time_face_titles[current_page]);
watch_display_top_right(" ");
watch_display_text(WATCH_POSITION_TOP_LEFT, (char *) set_time_face_titles[current_page]);
watch_display_text(WATCH_POSITION_TOP_RIGHT, " ");
if (current_page < 3) {
watch_set_colon();
if (settings->bit.clock_mode_24h) {
Expand All @@ -150,27 +150,27 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
memset(buf, ' ', sizeof(buf));
} else {
watch_set_colon();
if (movement_timezone_offsets[settings->bit.time_zone] < 0) watch_display_top_right(" -");
if (movement_timezone_offsets[settings->bit.time_zone] < 0) watch_display_text(WATCH_POSITION_TOP_RIGHT, " -");
sprintf(buf, "%2d%02d ", (int8_t) abs(movement_timezone_offsets[settings->bit.time_zone] / 60), (int8_t) (movement_timezone_offsets[settings->bit.time_zone] % 60) * (movement_timezone_offsets[settings->bit.time_zone] < 0 ? -1 : 1));
}
}

watch_display_main_line(buf);
watch_display_text(WATCH_POSITION_BOTTOM, buf);

// blink up the parameter we're setting
if (event.subsecond % 2 && !_quick_ticks_running) {
switch (current_page) {
case 0:
case 3:
watch_display_hours(" ");
watch_display_text(WATCH_POSITION_HOURS, " ");
break;
case 1:
case 4:
watch_display_minutes(" ");
watch_display_text(WATCH_POSITION_MINUTES, " ");
break;
case 2:
case 5:
watch_display_seconds(" ");
watch_display_text(WATCH_POSITION_SECONDS, " ");
break;
}
}
Expand Down
181 changes: 96 additions & 85 deletions watch-library/shared/watch/watch_common_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,103 +150,114 @@ void watch_display_string(char *string, uint8_t position) {
}
}

void watch_display_top_left(char *string) {
watch_display_character(string[0], 0);
if (string[1]) {
watch_display_character(string[1], 1);
void watch_display_text(WatchDisplayLocation location, char *string) {
switch (location) {
case WATCH_POSITION_TOP_LEFT:
watch_display_character(string[0], 0);
if (string[1]) {
watch_display_character(string[1], 1);
}
break;
case WATCH_POSITION_TOP_RIGHT:
watch_display_character(string[0], 2);
if (string[1]) {
watch_display_character(string[1], 3);
}
break;
case WATCH_POSITION_BOTTOM:
{
#ifdef USE_CUSTOM_LCD
watch_clear_pixel(0, 22);
#endif
int i = 0;
while (string[i] != 0) {
watch_display_character(string[i], 4 + i);
i++;
}
}
break;
case WATCH_POSITION_HOURS:
watch_display_character(string[0], 4);
if (string[1]) {
watch_display_character(string[1], 5);
}
break;
case WATCH_POSITION_MINUTES:
watch_display_character(string[0], 6);
if (string[1]) {
watch_display_character(string[1], 7);
}
break;
case WATCH_POSITION_SECONDS:
watch_display_character(string[0], 8);
if (string[1]) {
watch_display_character(string[1], 9);
}
break;
case WATCH_POSITION_FULL:
default:
// This is deprecated, but we use it for the legacy behavior.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
watch_display_string(string, 0);
#pragma GCC diagnostic pop
}
}

void watch_display_top_left_with_fallback(char *string, char *fallback) {
void watch_display_text_with_fallback(WatchDisplayLocation location, char *string, char *fallback) {
#ifdef USE_CUSTOM_LCD
(void)fallback;
watch_display_character(string[0], 0);
if (string[1]) {
watch_display_character(string[1], 1);
} else {
return;
}
if (string[2]) {
// position 3 is at index 10 in the display mapping
watch_display_character(string[2], 10);
}
#else
(void)string;
watch_display_top_left(fallback);
#endif
}

void watch_display_top_right(char *string) {
watch_display_character(string[0], 2);
if (string[1]) {
watch_display_character(string[1], 3);
}
}

void watch_display_top_right_with_fallback(char *string, char *fallback) {
#ifdef USE_CUSTOM_LCD
(void)fallback;
watch_display_top_right(string);
#else
(void)string;
watch_display_top_right(fallback);
#endif
}

void watch_display_main_line(char *string) {
#ifdef USE_CUSTOM_LCD
watch_clear_pixel(0, 22);
#endif
int i = 0;
while (string[i] != 0) {
watch_display_character(string[i], 4 + i);
i++;
}
}

void watch_display_main_line_with_fallback(char *string, char *fallback) {
#ifdef USE_CUSTOM_LCD
(void)fallback;
watch_clear_pixel(0, 22);
int i = 0;
int offset = 0;
size_t len = strlen(string);
if (len == 7 && string[0] == '1') {
watch_set_pixel(0, 22);
offset = 1;
i++;
}
while (string[i] != 0) {
watch_display_character(string[i], 4 + i - offset);
i++;
switch (location) {
case WATCH_POSITION_TOP_LEFT:
watch_display_character(string[0], 0);
if (string[1]) {
watch_display_character(string[1], 1);
} else {
return;
}
if (string[2]) {
// position 3 is at index 10 in the display mapping
watch_display_character(string[2], 10);
}
break;
case WATCH_POSITION_BOTTOM:
{
watch_clear_pixel(0, 22);
int i = 0;
int offset = 0;
size_t len = strlen(string);
if (len == 7 && string[0] == '1') {
watch_set_pixel(0, 22);
offset = 1;
i++;
}
while (string[i] != 0) {
watch_display_character(string[i], 4 + i - offset);
i++;
}
}
break;
case WATCH_POSITION_TOP_RIGHT:
case WATCH_POSITION_HOURS:
case WATCH_POSITION_MINUTES:
case WATCH_POSITION_SECONDS:
watch_display_text(location, string);
break;
case WATCH_POSITION_FULL:
default:
// This is deprecated, but we use it for the legacy behavior.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
watch_display_string(string, 0);
#pragma GCC diagnostic pop
}
#else
(void)string;
watch_display_main_line(fallback);
watch_display_text(location, fallback);
#endif
}

void watch_display_hours(char *string) {
watch_display_character(string[0], 4);
if (string[1]) {
watch_display_character(string[1], 5);
}
}

void watch_display_minutes(char *string) {
watch_display_character(string[0], 6);
if (string[1]) {
watch_display_character(string[1], 7);
}
}

void watch_display_seconds(char *string) {
watch_display_character(string[0], 8);
if (string[1]) {
watch_display_character(string[1], 9);
}
}

void watch_set_colon(void) {
#ifdef USE_CUSTOM_LCD
watch_set_pixel(0, 0);
Expand Down
Loading

0 comments on commit 9274f53

Please sign in to comment.