From bfa78086c813893b315fd5ae87e2bb112d04c5ee Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 31 Aug 2023 17:26:23 -0400 Subject: [PATCH] animated gif --- .gitignore | 4 ++- AnimatedGIF.h | 3 ++ ESP32ManyRoundScreenTest.ino | 68 +++++++++++++++--------------------- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 1899660..360ee34 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ build -.vscode \ No newline at end of file +.vscode +AnimatedGIF.cpp +AnimatedGIF.h \ No newline at end of file diff --git a/AnimatedGIF.h b/AnimatedGIF.h index 35b4a14..0d300ef 100644 --- a/AnimatedGIF.h +++ b/AnimatedGIF.h @@ -149,8 +149,11 @@ typedef struct gif_image_tag unsigned short pPalette[384]; // can hold RGB565 or RGB888 - set in begin() unsigned short pLocalPalette[384]; // color palettes for GIF images unsigned char ucLZW[LZW_BUF_SIZE]; // holds 6 chunks (6x255) of GIF LZW data packed together + + // Modified from the original library // unsigned short usGIFTable[4096]; unsigned short *usGIFTable; + unsigned char ucGIFPixels[8192]; unsigned char bEndOfFrame; unsigned char ucGIFBits, ucBackground, ucTransparent, ucCodeStart, ucMap, bUseLocalPalette; diff --git a/ESP32ManyRoundScreenTest.ino b/ESP32ManyRoundScreenTest.ino index 1196d49..cbdf9ab 100644 --- a/ESP32ManyRoundScreenTest.ino +++ b/ESP32ManyRoundScreenTest.ino @@ -19,9 +19,9 @@ #include "images/bb8.h" // Adjust this value based on the number of displays -const int NUM_DISPLAYS = 6; +const int NUM_DISPLAYS = 1; // Add more CS pins if you have more displays, each display must have a dedicated pin -const int CS_PINS[NUM_DISPLAYS] = {19, 22, 21, 32, 33, 26}; +const int CS_PINS[NUM_DISPLAYS] = { 19 }; int currentScreenIndex = 0; AnimatedGIF gif_1; @@ -31,74 +31,62 @@ AnimatedGIF gif_4; AnimatedGIF gif_5; AnimatedGIF gif_6; + TFT_eSPI tft = TFT_eSPI(); unsigned long lastFrameSpeed = 0; -void setup() -{ +void setup() { Serial.begin(115200); tft.init(); - for (int i = 0; i < NUM_DISPLAYS; i++) - { + for (int i = 0; i < NUM_DISPLAYS; i++) { pinMode(CS_PINS[i], OUTPUT); - digitalWrite(CS_PINS[i], LOW); // select the display + digitalWrite(CS_PINS[i], LOW); // select the display tft.fillScreen(TFT_BLACK); - tft.setRotation(2); // Adjust Rotation of your screen (0-3) - digitalWrite(CS_PINS[i], HIGH); // Deselect the display + tft.setRotation(2); // Adjust Rotation of your screen (0-3) + digitalWrite(CS_PINS[i], HIGH); // Deselect the display } - - openGif(&gif_1, hyperspace, sizeof(hyperspace)); - openGif(&gif_2, hud_6, sizeof(hud_6)); - openGif(&gif_3, nostromo, sizeof(nostromo)); + // openGif(&gif_1, hyperspace, sizeof(hyperspace)); + // openGif(&gif_2, hud_6, sizeof(hud_6)); + // openGif(&gif_3, nostromo, sizeof(nostromo)); openGif(&gif_4, x_wing, sizeof(x_wing)); - openGif(&gif_5, hud_2, sizeof(hud_2)); - openGif(&gif_6, bb8, sizeof(bb8)); + // openGif(&gif_5, hud_2, sizeof(hud_2)); + // openGif(&gif_6, bb8, sizeof(bb8)); } -void loop() -{ - playGif(&gif_1, 0); - playGif(&gif_2, 1); - playGif(&gif_3, 2); - playGif(&gif_4, 3); - playGif(&gif_5, 4); - playGif(&gif_6, 5); +void loop() { + // playGif(&gif_1, 0); + // playGif(&gif_2, 1); + // playGif(&gif_3, 2); + // playGif(&gif_4, 3); + // playGif(&gif_5, 4); + playGif(&gif_4, 0); } -void openGif(AnimatedGIF *gif, const uint8_t *gifImage, int gifSize) -{ +void openGif(AnimatedGIF *gif, const uint8_t *gifImage, int gifSize) { gif->begin(BIG_ENDIAN_PIXELS); - if (!gif->open((uint8_t *)gifImage, gifSize, GIFDraw)) - { + if (!gif->open((uint8_t *)gifImage, gifSize, GIFDraw)) { Serial.printf("Could not open gif \n"); } } -void playGif(AnimatedGIF *gif, int screenIndex) -{ +void playGif(AnimatedGIF *gif, int screenIndex) { currentScreenIndex = screenIndex; int res = gif->playFrame(false, NULL); - if (res == 0) - { + if (res == 0) { // If no more frames are available, reset the GIF to the beginning gif->reset(); gif->playFrame(false, NULL); } - if (res == -1) - { + if (res == -1) { Serial.printf("Gif Error = %d on screen %d\n", gif->getLastError(), screenIndex); } - if (screenIndex == 0) - { - if (lastFrameSpeed == 0) - { + if (screenIndex == 0) { + if (lastFrameSpeed == 0) { lastFrameSpeed = millis(); - } - else - { + } else { Serial.printf("Screen 0 FPS=%f\n", 1000.0f / (millis() - lastFrameSpeed)); lastFrameSpeed = millis(); }