Implement optional looping for animated boot logo [#1839]

This commit is contained in:
Ivan Zorin
2023-11-21 01:38:10 +03:00
parent e3bad2adae
commit a02f8c8ae3
5 changed files with 60 additions and 31 deletions

View File

@@ -3,10 +3,11 @@
#include "Buttons.hpp"
#include "OLED.hpp"
#include "cmsis_os.h"
#define LOGO_PAGE_LENGTH 1024
void delay() {
if (getSettingValue(SettingsOptions::LOGOTime) == 5) {
if (getSettingValue(SettingsOptions::LOGOTime) >= logoMode_t::ONETIME) {
waitForButtonPress();
} else {
waitForButtonPressOrTimeout(TICKS_SECOND * getSettingValue(SettingsOptions::LOGOTime));
@@ -20,60 +21,75 @@ void BootLogo::handleShowingLogo(const uint8_t *ptrLogoArea) {
} else if (ptrLogoArea[0] == 0xAA) {
showNewFormat(ptrLogoArea + 1);
}
OLED::clearScreen();
OLED::refresh();
}
void BootLogo::showOldFormat(const uint8_t *ptrLogoArea) {
OLED::drawAreaSwapped(0, 0, 96, 16, (uint8_t *)(ptrLogoArea + 4));
OLED::refresh();
// Delay here until button is pressed or its been the amount of seconds set by the user
// Delay here with static logo until a button is pressed or its been the amount of seconds set by the user
delay();
}
void BootLogo::showNewFormat(const uint8_t *ptrLogoArea) {
if (getSettingValue(SettingsOptions::LOGOTime) == 0) {
if (getSettingValue(SettingsOptions::LOGOTime) == logoMode_t::SKIP) {
return;
}
// New logo format (a) fixes long standing byte swap quirk and (b) supports animation
uint8_t interFrameDelay = ptrLogoArea[0];
OLED::clearScreen();
ButtonState buttons = getButtonState();
// Now draw in the frames
int position = 1;
do {
while (getButtonState() == BUTTON_NONE) {
int len = (showNewFrame(ptrLogoArea + position));
OLED::refresh();
position += len;
buttons = getButtonState();
if (interFrameDelay) {
osDelay(interFrameDelay * 4);
}
// 1024 less the header type byte and the inter-frame-delay
if (getSettingValue(SettingsOptions::LOGOTime) > 0 && (position >= 1022 || len == 0)) {
// Delay here until button is pressed or its been the amount of seconds set by the user
delay();
return;
if (getSettingValue(SettingsOptions::LOGOTime) && (position >= 1022 || len == 0)) {
// Animated logo stops here ...
if (getSettingValue(SettingsOptions::LOGOTime) == logoMode_t::INFINITY) {
// ... but if it's infinite logo setting then keep it rolling over again until a button is pressed
osDelay(4 * TICKS_100MS);
OLED::clearScreen();
position = 1;
continue;
}
} else {
// Animation in progress so jumping to the next frame
continue;
}
} while (buttons == BUTTON_NONE);
// Static logo case ends up right here, so delay until a button is pressed or its been the amount of seconds set by the user
delay();
return;
}
}
int BootLogo::showNewFrame(const uint8_t *ptrLogoArea) {
uint8_t length = ptrLogoArea[0];
if (length == 0xFF) {
switch (length) {
case 0:
// End
return 0;
break;
case 0xFE:
return 1;
break;
case 0xFF:
// Full frame update
OLED::drawArea(0, 0, 96, 16, ptrLogoArea + 1);
length = 96;
} else if (length == 0xFE) {
return 1;
} else if (length == 0) {
return 0; // end
} else {
break;
default:
length /= 2;
// Draw length patches
for (int p = 0; p < length; p++) {