Browse Source

Improved bootscreen animation

Scott Lahteine 3 years ago
parent
commit
3efbd45443
2 changed files with 35 additions and 17 deletions
  1. 15
    0
      Marlin/src/lcd/dogm/dogm_Bootscreen.h
  2. 20
    17
      Marlin/src/lcd/dogm/marlinui_DOGM.cpp

+ 15
- 0
Marlin/src/lcd/dogm/dogm_Bootscreen.h View File

@@ -32,8 +32,16 @@
32 32
 
33 33
 #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
34 34
 
35
+  typedef struct {
36
+    const unsigned char *bitmap;
37
+    const unsigned short duration;
38
+  } boot_frame_t;
39
+
35 40
   #include "../../../_Bootscreen.h"
36 41
 
42
+  #ifndef CUSTOM_BOOTSCREEN_BMPWIDTH
43
+    #define CUSTOM_BOOTSCREEN_BMPWIDTH 128
44
+  #endif
37 45
   #ifndef CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH
38 46
     #define CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8)
39 47
   #endif
@@ -41,6 +49,13 @@
41 49
     #define CUSTOM_BOOTSCREEN_BMPHEIGHT (sizeof(custom_start_bmp) / (CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH))
42 50
   #endif
43 51
 
52
+  #ifndef CUSTOM_BOOTSCREEN_Y
53
+    #if ENABLED(CUSTOM_BOOTSCREEN_BOTTOM_JUSTIFY)
54
+      #define CUSTOM_BOOTSCREEN_Y (LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT))
55
+    #else
56
+      #define CUSTOM_BOOTSCREEN_Y ((LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2)
57
+    #endif
58
+  #endif
44 59
 #endif
45 60
 
46 61
 #if ENABLED(BOOT_MARLIN_LOGO_SMALL)

+ 20
- 17
Marlin/src/lcd/dogm/marlinui_DOGM.cpp View File

@@ -110,19 +110,21 @@ bool MarlinUI::detected() { return true; }
110 110
     // Draws a slice of a particular frame of the custom bootscreen, without the u8g loop
111 111
     void MarlinUI::draw_custom_bootscreen(const uint8_t frame/*=0*/) {
112 112
       constexpr u8g_uint_t left = u8g_uint_t((LCD_PIXEL_WIDTH  - (CUSTOM_BOOTSCREEN_BMPWIDTH)) / 2),
113
-                            top = u8g_uint_t((LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2);
113
+                            top = u8g_uint_t(CUSTOM_BOOTSCREEN_Y);
114 114
       #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
115 115
         constexpr u8g_uint_t right = left + CUSTOM_BOOTSCREEN_BMPWIDTH,
116 116
                             bottom = top + CUSTOM_BOOTSCREEN_BMPHEIGHT;
117 117
       #endif
118 118
 
119
-      const u8g_pgm_uint8_t * const bmp =
120
-        #if ENABLED(CUSTOM_BOOTSCREEN_ANIMATED)
121
-          (u8g_pgm_uint8_t*)pgm_read_ptr(&custom_bootscreen_animation[frame])
122
-        #else
123
-          custom_start_bmp
124
-        #endif
125
-      ;
119
+      const void * const frame_ptr = pgm_read_ptr(&custom_bootscreen_animation[frame]);
120
+
121
+      #if BOTH(CUSTOM_BOOTSCREEN_ANIMATED, CUSTOM_BOOTSCREEN_TIME_PER_FRAME)
122
+        const boot_frame_t * const frame_info = (boot_frame_t*)frame_ptr;
123
+        const u8g_pgm_uint8_t * const bmp = (u8g_pgm_uint8_t*)pgm_read_ptr(&frame_info->bitmap);
124
+      #else
125
+        const u8g_pgm_uint8_t * const bmp = TERN(CUSTOM_BOOTSCREEN_ANIMATED, (u8g_pgm_uint8_t*)frame_ptr, custom_start_bmp);
126
+      #endif
127
+
126 128
       UNUSED(frame);
127 129
 
128 130
       u8g.drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp);
@@ -141,22 +143,23 @@ bool MarlinUI::detected() { return true; }
141 143
     // Shows the custom bootscreen, with the u8g loop, animations and delays
142 144
     void MarlinUI::show_custom_bootscreen() {
143 145
       #if DISABLED(CUSTOM_BOOTSCREEN_ANIMATED)
144
-        constexpr millis_t d = 0;
146
+        constexpr millis_t frame_time = 0;
145 147
         constexpr uint8_t f = 0;
146 148
       #else
147
-        #if DISABLED(CUSTOM_BOOTSCREEN_ANIMATED_FRAME_TIME)
148
-          constexpr millis_t d = CUSTOM_BOOTSCREEN_FRAME_TIME;
149
+        #if DISABLED(CUSTOM_BOOTSCREEN_TIME_PER_FRAME)
150
+          constexpr millis_t frame_time = CUSTOM_BOOTSCREEN_FRAME_TIME;
149 151
         #endif
150 152
         LOOP_L_N(f, COUNT(custom_bootscreen_animation))
151 153
       #endif
152 154
         {
153
-          #if ENABLED(CUSTOM_BOOTSCREEN_ANIMATED_FRAME_TIME)
154
-            const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_frame_time) - 1);
155
-            const millis_t d = custom_bootscreen_frame_time[fr];
155
+          #if ENABLED(CUSTOM_BOOTSCREEN_TIME_PER_FRAME)
156
+            const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_animation) - 1);
157
+            const boot_frame_t * const frame_info = (boot_frame_t*)pgm_read_ptr(&custom_bootscreen_animation[fr]);
158
+            const millis_t frame_time = pgm_read_word(&frame_info->duration);
156 159
           #endif
157 160
           u8g.firstPage();
158 161
           do { draw_custom_bootscreen(f); } while (u8g.nextPage());
159
-          if (d) safe_delay(d);
162
+          if (frame_time) safe_delay(frame_time);
160 163
         }
161 164
 
162 165
       #ifndef CUSTOM_BOOTSCREEN_TIMEOUT
@@ -218,10 +221,10 @@ bool MarlinUI::detected() { return true; }
218 221
     #if DISABLED(BOOT_MARLIN_LOGO_ANIMATED)
219 222
       draw_bootscreen_bmp(start_bmp);
220 223
     #else
221
-      constexpr millis_t d = MARLIN_BOOTSCREEN_FRAME_TIME;
224
+      constexpr millis_t frame_time = MARLIN_BOOTSCREEN_FRAME_TIME;
222 225
       LOOP_L_N(f, COUNT(marlin_bootscreen_animation)) {
223 226
         draw_bootscreen_bmp((uint8_t*)pgm_read_ptr(&marlin_bootscreen_animation[f]));
224
-        if (d) safe_delay(d);
227
+        if (frame_time) safe_delay(frame_time);
225 228
       }
226 229
     #endif
227 230
   }

Loading…
Cancel
Save