Skip to content

Commit

Permalink
Improved bootscreen animation
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jan 2, 2021
1 parent a87e519 commit 3efbd45
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
15 changes: 15 additions & 0 deletions Marlin/src/lcd/dogm/dogm_Bootscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,30 @@

#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)

typedef struct {
const unsigned char *bitmap;
const unsigned short duration;
} boot_frame_t;

#include "../../../_Bootscreen.h"

#ifndef CUSTOM_BOOTSCREEN_BMPWIDTH
#define CUSTOM_BOOTSCREEN_BMPWIDTH 128
#endif
#ifndef CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH
#define CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8)
#endif
#ifndef CUSTOM_BOOTSCREEN_BMPHEIGHT
#define CUSTOM_BOOTSCREEN_BMPHEIGHT (sizeof(custom_start_bmp) / (CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH))
#endif

#ifndef CUSTOM_BOOTSCREEN_Y
#if ENABLED(CUSTOM_BOOTSCREEN_BOTTOM_JUSTIFY)
#define CUSTOM_BOOTSCREEN_Y (LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT))
#else
#define CUSTOM_BOOTSCREEN_Y ((LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2)
#endif
#endif
#endif

#if ENABLED(BOOT_MARLIN_LOGO_SMALL)
Expand Down
37 changes: 20 additions & 17 deletions Marlin/src/lcd/dogm/marlinui_DOGM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,21 @@ bool MarlinUI::detected() { return true; }
// Draws a slice of a particular frame of the custom bootscreen, without the u8g loop
void MarlinUI::draw_custom_bootscreen(const uint8_t frame/*=0*/) {
constexpr u8g_uint_t left = u8g_uint_t((LCD_PIXEL_WIDTH - (CUSTOM_BOOTSCREEN_BMPWIDTH)) / 2),
top = u8g_uint_t((LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2);
top = u8g_uint_t(CUSTOM_BOOTSCREEN_Y);
#if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
constexpr u8g_uint_t right = left + CUSTOM_BOOTSCREEN_BMPWIDTH,
bottom = top + CUSTOM_BOOTSCREEN_BMPHEIGHT;
#endif

const u8g_pgm_uint8_t * const bmp =
#if ENABLED(CUSTOM_BOOTSCREEN_ANIMATED)
(u8g_pgm_uint8_t*)pgm_read_ptr(&custom_bootscreen_animation[frame])
#else
custom_start_bmp
#endif
;
const void * const frame_ptr = pgm_read_ptr(&custom_bootscreen_animation[frame]);

#if BOTH(CUSTOM_BOOTSCREEN_ANIMATED, CUSTOM_BOOTSCREEN_TIME_PER_FRAME)
const boot_frame_t * const frame_info = (boot_frame_t*)frame_ptr;
const u8g_pgm_uint8_t * const bmp = (u8g_pgm_uint8_t*)pgm_read_ptr(&frame_info->bitmap);
#else
const u8g_pgm_uint8_t * const bmp = TERN(CUSTOM_BOOTSCREEN_ANIMATED, (u8g_pgm_uint8_t*)frame_ptr, custom_start_bmp);
#endif

UNUSED(frame);

u8g.drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp);
Expand All @@ -141,22 +143,23 @@ bool MarlinUI::detected() { return true; }
// Shows the custom bootscreen, with the u8g loop, animations and delays
void MarlinUI::show_custom_bootscreen() {
#if DISABLED(CUSTOM_BOOTSCREEN_ANIMATED)
constexpr millis_t d = 0;
constexpr millis_t frame_time = 0;
constexpr uint8_t f = 0;
#else
#if DISABLED(CUSTOM_BOOTSCREEN_ANIMATED_FRAME_TIME)
constexpr millis_t d = CUSTOM_BOOTSCREEN_FRAME_TIME;
#if DISABLED(CUSTOM_BOOTSCREEN_TIME_PER_FRAME)
constexpr millis_t frame_time = CUSTOM_BOOTSCREEN_FRAME_TIME;
#endif
LOOP_L_N(f, COUNT(custom_bootscreen_animation))
#endif
{
#if ENABLED(CUSTOM_BOOTSCREEN_ANIMATED_FRAME_TIME)
const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_frame_time) - 1);
const millis_t d = custom_bootscreen_frame_time[fr];
#if ENABLED(CUSTOM_BOOTSCREEN_TIME_PER_FRAME)
const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_animation) - 1);
const boot_frame_t * const frame_info = (boot_frame_t*)pgm_read_ptr(&custom_bootscreen_animation[fr]);
const millis_t frame_time = pgm_read_word(&frame_info->duration);
#endif
u8g.firstPage();
do { draw_custom_bootscreen(f); } while (u8g.nextPage());
if (d) safe_delay(d);
if (frame_time) safe_delay(frame_time);
}

#ifndef CUSTOM_BOOTSCREEN_TIMEOUT
Expand Down Expand Up @@ -218,10 +221,10 @@ bool MarlinUI::detected() { return true; }
#if DISABLED(BOOT_MARLIN_LOGO_ANIMATED)
draw_bootscreen_bmp(start_bmp);
#else
constexpr millis_t d = MARLIN_BOOTSCREEN_FRAME_TIME;
constexpr millis_t frame_time = MARLIN_BOOTSCREEN_FRAME_TIME;
LOOP_L_N(f, COUNT(marlin_bootscreen_animation)) {
draw_bootscreen_bmp((uint8_t*)pgm_read_ptr(&marlin_bootscreen_animation[f]));
if (d) safe_delay(d);
if (frame_time) safe_delay(frame_time);
}
#endif
}
Expand Down

0 comments on commit 3efbd45

Please sign in to comment.