Add ease in / out and cleanup animation methods
This commit is contained in:
@@ -62,6 +62,14 @@ uint8_t OLED_Setup_Array[] = {
|
|||||||
const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80,
|
const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80,
|
||||||
0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 };
|
0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 };
|
||||||
|
|
||||||
|
static uint8_t easeInOutTiming(uint8_t t) {
|
||||||
|
return t * t * (300 - 2 * t) / 10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t lerp(uint8_t a, uint8_t b, uint8_t t) {
|
||||||
|
return a + t * (b - a) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
void OLED::initialize() {
|
void OLED::initialize() {
|
||||||
cursor_x = cursor_y = 0;
|
cursor_x = cursor_y = 0;
|
||||||
currentFont = USER_FONT_12;
|
currentFont = USER_FONT_12;
|
||||||
@@ -123,28 +131,30 @@ void OLED::presentSecondScreenBufferAnimatedBack() {
|
|||||||
set_framebuffer(NULL);
|
set_framebuffer(NULL);
|
||||||
|
|
||||||
uint32_t totalDuration = 50;
|
uint32_t totalDuration = 50;
|
||||||
|
|
||||||
uint32_t duration = 0;
|
uint32_t duration = 0;
|
||||||
uint32_t start = xTaskGetTickCount();
|
uint32_t start = xTaskGetTickCount();
|
||||||
uint8_t offset = 0;
|
uint8_t offset = 0;
|
||||||
while (duration <= totalDuration)
|
while (duration <= totalDuration) {
|
||||||
{
|
|
||||||
duration = xTaskGetTickCount() - start;
|
duration = xTaskGetTickCount() - start;
|
||||||
|
|
||||||
uint8_t progress = (duration * OLED_WIDTH) / totalDuration;
|
uint8_t progress = (duration * 100) / totalDuration;
|
||||||
|
progress = easeInOutTiming(progress);
|
||||||
for (uint8_t i = OLED_WIDTH - 1; i > progress; i--) {
|
progress = lerp(0, OLED_WIDTH, progress);
|
||||||
firstStripPtr[i] = firstStripPtr[(i - progress) + offset];
|
if (progress > OLED_WIDTH) {
|
||||||
secondStripPtr[i] = secondStripPtr[(i - progress) + offset];
|
progress = OLED_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memmove(&firstStripPtr[progress], &firstStripPtr[offset], OLED_WIDTH - progress);
|
||||||
|
memmove(&secondStripPtr[progress], &secondStripPtr[offset], OLED_WIDTH - progress);
|
||||||
offset = progress;
|
offset = progress;
|
||||||
|
|
||||||
|
memmove(
|
||||||
for (uint8_t i = 0; i < progress; i++) {
|
&firstStripPtr[0],
|
||||||
firstStripPtr[i] = firstBackStripPtr[(i - progress) + OLED_WIDTH];
|
&firstBackStripPtr[OLED_WIDTH - progress],
|
||||||
secondStripPtr[i] = secondBackStripPtr[(i - progress) + OLED_WIDTH];
|
progress);
|
||||||
}
|
memmove(&secondStripPtr[0],
|
||||||
|
&secondBackStripPtr[OLED_WIDTH - progress],
|
||||||
|
progress);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
osDelay(40);
|
osDelay(40);
|
||||||
@@ -157,28 +167,30 @@ void OLED::presentSecondScreenBufferAnimated() {
|
|||||||
set_framebuffer(NULL);
|
set_framebuffer(NULL);
|
||||||
|
|
||||||
uint32_t totalDuration = 50;
|
uint32_t totalDuration = 50;
|
||||||
|
|
||||||
uint32_t duration = 0;
|
uint32_t duration = 0;
|
||||||
uint32_t start = xTaskGetTickCount();
|
uint32_t start = xTaskGetTickCount();
|
||||||
uint8_t offset = 0;
|
uint8_t offset = 0;
|
||||||
while (duration < totalDuration)
|
while (duration < totalDuration) {
|
||||||
{
|
|
||||||
duration = xTaskGetTickCount() - start;
|
duration = xTaskGetTickCount() - start;
|
||||||
|
|
||||||
uint8_t progress = (duration * OLED_WIDTH) / totalDuration;
|
uint8_t progress = (duration * 100) / totalDuration;
|
||||||
|
progress = easeInOutTiming(progress);
|
||||||
for (uint8_t i = 0; i < OLED_WIDTH - progress; i++) {
|
progress = lerp(0, OLED_WIDTH, progress);
|
||||||
firstStripPtr[i] = firstStripPtr[i + progress - offset];
|
if (progress > OLED_WIDTH) {
|
||||||
secondStripPtr[i] = secondStripPtr[i + progress - offset];
|
progress = OLED_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memmove(&firstStripPtr[0], &firstStripPtr[progress - offset], OLED_WIDTH - progress);
|
||||||
|
memmove(&secondStripPtr[0], &secondStripPtr[progress - offset], OLED_WIDTH - progress);
|
||||||
offset = progress;
|
offset = progress;
|
||||||
|
|
||||||
|
memmove(
|
||||||
for (uint8_t i = OLED_WIDTH - progress; i < OLED_WIDTH; i++) {
|
&firstStripPtr[OLED_WIDTH - progress],
|
||||||
firstStripPtr[i] = firstBackStripPtr[i - (OLED_WIDTH - progress)];
|
&firstBackStripPtr[0],
|
||||||
secondStripPtr[i] = secondBackStripPtr[i - (OLED_WIDTH - progress)];
|
progress);
|
||||||
}
|
memmove(&secondStripPtr[OLED_WIDTH - progress],
|
||||||
|
&secondBackStripPtr[0],
|
||||||
|
progress);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
osDelay(40);
|
osDelay(40);
|
||||||
|
|||||||
Reference in New Issue
Block a user