From 07c92f188daa77c555c723c7d9e5425f91c37f56 Mon Sep 17 00:00:00 2001 From: Rahix Date: Fri, 1 Oct 2021 23:03:24 +0200 Subject: [PATCH] feat(epicardium): Add a boot animation to show off CTX --- epicardium/epic_boot.c | 53 ++++++++++++++++++++++++++++++++++++++++++ epicardium/main.c | 37 ++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 epicardium/epic_boot.c diff --git a/epicardium/epic_boot.c b/epicardium/epic_boot.c new file mode 100644 index 00000000..61fd5a0c --- /dev/null +++ b/epicardium/epic_boot.c @@ -0,0 +1,53 @@ +#include + +static const uint8_t pride_colors[6][3] = { + { 0xe4, 0x02, 0x02 }, { 0xff, 0x8c, 0x00 }, { 0xff, 0xed, 0x00 }, + { 0x00, 0x80, 0x26 }, { 0x00, 0x4d, 0xff }, { 0x75, 0x06, 0x87 }, +}; + +static void epic_frame(Ctx *epicardium_ctx, float frame) +{ + int num_colors = sizeof(pride_colors) / sizeof(pride_colors[0]); + for (int color = 0; color < num_colors; color++) { + ctx_rgba8_stroke( + epicardium_ctx, + pride_colors[color][0], + pride_colors[color][1], + pride_colors[color][2], + 0xff + ); + ctx_line_width(epicardium_ctx, 10.0); + ctx_line_cap(epicardium_ctx, CTX_CAP_ROUND); + + float width = + expf(-pow(frame / 2.0 - 5 + color / 2.0, 2)) * 55.0 + + 5.0; + + float ypos = color * 10.0 + 40.0 - (num_colors - 1) * 5.0; + + ctx_move_to(epicardium_ctx, 80.0 - width, ypos); + ctx_line_to(epicardium_ctx, 80.0 + width, ypos); + ctx_stroke(epicardium_ctx); + } + + ctx_save(epicardium_ctx); + + ctx_font_size(epicardium_ctx, 20.0f); + ctx_text_baseline(epicardium_ctx, CTX_TEXT_BASELINE_BOTTOM); + ctx_rgba8(epicardium_ctx, 0xff, 0xff, 0xff, 0xff); + + ctx_text_align(epicardium_ctx, CTX_TEXT_ALIGN_CENTER); + ctx_move_to(epicardium_ctx, 80.0f, 58.0f); + ctx_text(epicardium_ctx, "Epicardium"); + + if (strcmp(CARD10_VERSION, "v1.18") != 0) { + ctx_text_align(epicardium_ctx, CTX_TEXT_ALIGN_LEFT); + ctx_move_to(epicardium_ctx, 2.0f, 78.0f); + ctx_text(epicardium_ctx, CARD10_VERSION); + } else { + ctx_move_to(epicardium_ctx, 80.0f, 78.0f); + ctx_text(epicardium_ctx, "Queer Quinoa"); + } + + ctx_restore(epicardium_ctx); +} diff --git a/epicardium/main.c b/epicardium/main.c index c5288832..6b6dd641 100644 --- a/epicardium/main.c +++ b/epicardium/main.c @@ -20,6 +20,8 @@ #include #include +#include "epic_boot.c" + int main(void) { watchdog_init(); @@ -37,15 +39,14 @@ int main(void) epic_leds_set(12, 0, 0, 1); epic_leds_set(13, 0, 0, 1); epic_leds_set(14, 0, 0, 1); - for (int i = 0; i < 3; i++) { - epic_leds_set_rocket(i, 31); - mxc_delay(166666); - epic_leds_set_rocket(i, 0); - } - epic_leds_clear_all(0, 0, 0); epic_disp_clear(0x0000); +#if 0 /* reenable for future releases */ + epic_leds_set_rocket(0, 31); + epic_leds_set_rocket(1, 31); + epic_leds_set_rocket(2, 31); + // TODO: Use blit function here #if BYTE_ORDER == LITTLE_ENDIAN for (size_t i = 0; i < sizeof(epicardium_ctx_fb); i += 2) { @@ -74,6 +75,30 @@ int main(void) } epic_disp_update(); mxc_delay(2000000); +#else + for (uint32_t frame = 0; frame < 15; frame++) { + switch (frame) { + case 0: + epic_leds_set_rocket(0, 31); + break; + case 5: + epic_leds_set_rocket(1, 31); + break; + case 10: + epic_leds_set_rocket(2, 31); + break; + } + + epic_disp_clear(0x0000); + epic_frame(epicardium_ctx, frame); + epic_disp_update(); + } + + /* re-init for the first app */ + disp_ctx_reinit(); +#endif + + epic_leds_clear_all(0, 0, 0); LOG_DEBUG("startup", "Initializing tasks ..."); -- GitLab