acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
MultipleAnimatedGIF.ino (9871B)
1 /******************************************************************************* 2 * Animated GIF Image Viewer 3 * This is a simple Animated GIF image viewer exsample 4 * Image Source: https://www.geocities.ws/finalfantasyfive/ff5animations.html 5 * optimized with ezgif.com 6 * 7 * Setup steps: 8 * 1. Change your LCD parameters in Arduino_GFX setting 9 * 2. Upload Animated GIF file 10 * FFat (ESP32): 11 * upload FFat (FatFS) data with ESP32 Sketch Data Upload: 12 * ESP32: https://github.com/lorol/arduino-esp32fs-plugin 13 * LittleFS (ESP32 / ESP8266 / Pico): 14 * upload LittleFS data with ESP8266 LittleFS Data Upload: 15 * ESP32: https://github.com/lorol/arduino-esp32fs-plugin 16 * ESP8266: https://github.com/earlephilhower/arduino-esp8266littlefs-plugin 17 * Pico: https://github.com/earlephilhower/arduino-pico-littlefs-plugin.git 18 * SPIFFS (ESP32): 19 * upload SPIFFS data with ESP32 Sketch Data Upload: 20 * ESP32: https://github.com/lorol/arduino-esp32fs-plugin 21 ******************************************************************************/ 22 #define GIF_FILENAME1 "/jobs.gif" 23 #define GIF_FILENAME2 "/archer.gif" 24 #define GIF_FILENAME3 "/white.gif" 25 #define GIF_FILENAME4 "/lancer.gif" 26 27 /******************************************************************************* 28 * Start of Arduino_GFX setting 29 ******************************************************************************/ 30 #include <Arduino_GFX_Library.h> 31 32 /* all display share same SPI Data Bus with individual CS, RST pins connected to MCU RST pin */ 33 Arduino_DataBus *bus1 = new Arduino_HWSPI(DF_GFX_DC, 21 /* CS */); 34 Arduino_GFX *gfx1 = new Arduino_SSD1331(bus1, GFX_NOT_DEFINED /* RST */, 0 /* rotation */); 35 36 Arduino_DataBus *bus2 = new Arduino_HWSPI(DF_GFX_DC, 32 /* CS */); 37 Arduino_GFX *gfx2 = new Arduino_ST7735(bus2, GFX_NOT_DEFINED /* RST */, 3 /* rotation */, true /* IPS */, 80 /* width */, 160 /* height */, 26 /* col offset 1 */, 1 /* row offset 1 */, 26 /* col offset 2 */, 1 /* row offset 2 */); 38 39 Arduino_DataBus *bus3 = new Arduino_HWSPI(DF_GFX_DC, 22 /* CS */); 40 Arduino_GFX *gfx3 = new Arduino_ST7789(bus3, GFX_NOT_DEFINED /* RST */, 0 /* rotation */, true /* IPS */, 240 /* width */, 240 /* height */, 0 /* col offset 1 */, 0 /* row offset 1 */, 0 /* col offset 2 */, 80 /* row offset 2 */); 41 42 Arduino_DataBus *bus4 = new Arduino_HWSPI(DF_GFX_DC, 5 /* CS */); 43 Arduino_GFX *gfx4 = new Arduino_ILI9341(bus4, GFX_NOT_DEFINED /* RST */, 0 /* rotation */, false /* IPS */); 44 /******************************************************************************* 45 * End of Arduino_GFX setting 46 ******************************************************************************/ 47 48 #if defined(TARGET_RP2040) 49 #include <LittleFS.h> 50 #include <SD.h> 51 #elif defined(ESP32) 52 #include <FFat.h> 53 #include <LittleFS.h> 54 #include <SPIFFS.h> 55 #include <SD.h> 56 #elif defined(ESP8266) 57 #include <LittleFS.h> 58 #include <SD.h> 59 #else 60 #include <SD.h> 61 #endif 62 63 #include "GifClass.h" 64 static GifClass gifClass1; 65 static GifClass gifClass2; 66 static GifClass gifClass3; 67 static GifClass gifClass4; 68 69 void setup() 70 { 71 Serial.begin(115200); 72 // Serial.setDebugOutput(true); 73 // while(!Serial); 74 Serial.println("Arduino_GFX library Multiple Device Animated GIF Test!"); 75 76 #ifdef GFX_EXTRA_PRE_INIT 77 GFX_EXTRA_PRE_INIT(); 78 #endif 79 80 gfx1->begin(); 81 gfx1->fillScreen(RED); 82 delay(200); 83 84 gfx2->begin(); 85 gfx2->fillScreen(YELLOW); 86 delay(200); 87 88 gfx3->begin(); 89 gfx3->fillScreen(GREEN); 90 delay(200); 91 92 gfx4->begin(); 93 gfx4->fillScreen(BLUE); 94 delay(200); 95 96 #if defined(TARGET_RP2040) 97 if (!LittleFS.begin()) 98 // if (!SD.begin(SS)) 99 #elif defined(ESP32) 100 // if (!FFat.begin()) 101 if (!LittleFS.begin()) 102 // if (!SPIFFS.begin()) 103 // if (!SD.begin(SS)) 104 #elif defined(ESP8266) 105 if (!LittleFS.begin()) 106 // if (!SD.begin(SS)) 107 #else 108 if (!SD.begin()) 109 #endif 110 { 111 Serial.println(F("ERROR: File System Mount Failed!")); 112 gfx4->println(F("ERROR: File System Mount Failed!")); 113 exit(0); 114 } 115 } 116 117 void loop() 118 { 119 #if defined(TARGET_RP2040) 120 File gifFile1 = LittleFS.open(GIF_FILENAME1, "r"); 121 File gifFile2 = LittleFS.open(GIF_FILENAME2, "r"); 122 File gifFile3 = LittleFS.open(GIF_FILENAME3, "r"); 123 File gifFile4 = LittleFS.open(GIF_FILENAME4, "r"); 124 #elif defined(ESP32) 125 File gifFile1 = LittleFS.open(GIF_FILENAME1, "r"); 126 File gifFile2 = LittleFS.open(GIF_FILENAME2, "r"); 127 File gifFile3 = LittleFS.open(GIF_FILENAME3, "r"); 128 File gifFile4 = LittleFS.open(GIF_FILENAME4, "r"); 129 #elif defined(ESP8266) 130 File gifFile1 = LittleFS.open(GIF_FILENAME1, "r"); 131 File gifFile2 = LittleFS.open(GIF_FILENAME2, "r"); 132 File gifFile3 = LittleFS.open(GIF_FILENAME3, "r"); 133 File gifFile4 = LittleFS.open(GIF_FILENAME4, "r"); 134 #else 135 File gifFile1 = SD.open(GIF_FILENAME1, FILE_READ); 136 File gifFile2 = SD.open(GIF_FILENAME2, FILE_READ); 137 File gifFile3 = SD.open(GIF_FILENAME3, FILE_READ); 138 File gifFile4 = SD.open(GIF_FILENAME4, FILE_READ); 139 #endif 140 141 if (!gifFile1 || gifFile1.isDirectory()) 142 { 143 Serial.println(F("ERROR: open gifFile1 Failed!")); 144 gfx1->println(F("ERROR: open gifFile1 Failed!")); 145 } 146 else if (!gifFile2 || gifFile2.isDirectory()) 147 { 148 Serial.println(F("ERROR: open gifFile2 Failed!")); 149 gfx2->println(F("ERROR: open gifFile2 Failed!")); 150 } 151 else if (!gifFile3 || gifFile3.isDirectory()) 152 { 153 Serial.println(F("ERROR: open gifFile3 Failed!")); 154 gfx3->println(F("ERROR: open gifFile3 Failed!")); 155 } 156 else if (!gifFile4 || gifFile4.isDirectory()) 157 { 158 Serial.println(F("ERROR: open gifFile4 Failed!")); 159 gfx4->println(F("ERROR: open gifFile4 Failed!")); 160 } 161 else 162 { 163 // read GIF file header 164 gd_GIF *gif1 = gifClass1.gd_open_gif(&gifFile1); 165 gd_GIF *gif2 = gifClass2.gd_open_gif(&gifFile2); 166 gd_GIF *gif3 = gifClass3.gd_open_gif(&gifFile3); 167 gd_GIF *gif4 = gifClass4.gd_open_gif(&gifFile4); 168 if (!gif1) 169 { 170 Serial.println(F("gd_open_gif(&gifFile1) failed!")); 171 } 172 else if (!gif2) 173 { 174 Serial.println(F("gd_open_gif(&gifFile2) failed!")); 175 } 176 else if (!gif3) 177 { 178 Serial.println(F("gd_open_gif(&gifFile3) failed!")); 179 } 180 else if (!gif4) 181 { 182 Serial.println(F("gd_open_gif(&gifFile4) failed!")); 183 } 184 else 185 { 186 uint8_t *buf1 = (uint8_t *)malloc(gif1->width * gif1->height); 187 uint8_t *buf2 = (uint8_t *)malloc(gif2->width * gif2->height); 188 uint8_t *buf3 = (uint8_t *)malloc(gif3->width * gif3->height); 189 uint8_t *buf4 = (uint8_t *)malloc(gif4->width * gif4->height); 190 if (!buf1) 191 { 192 Serial.println(F("buf1 malloc failed!")); 193 } 194 if (!buf2) 195 { 196 Serial.println(F("buf2 malloc failed!")); 197 } 198 if (!buf3) 199 { 200 Serial.println(F("buf3 malloc failed!")); 201 } 202 if (!buf4) 203 { 204 Serial.println(F("buf4 malloc failed!")); 205 } 206 else 207 { 208 int16_t x1 = (gfx1->width() - gif1->width) / 2; 209 int16_t y1 = (gfx1->height() - gif1->height) / 2; 210 int16_t x2 = (gfx2->width() - gif2->width) / 2; 211 int16_t y2 = (gfx2->height() - gif2->height) / 2; 212 int16_t x3 = (gfx3->width() - gif3->width) / 2; 213 int16_t y3 = (gfx3->height() - gif3->height) / 2; 214 int16_t x4 = (gfx4->width() - gif4->width) / 2; 215 int16_t y4 = (gfx4->height() - gif4->height) / 2; 216 217 Serial.println(F("GIF video start")); 218 int32_t res1, res2, res3, res4; 219 uint32_t duration = 0, remain = 0; 220 while (1) 221 { 222 res1 = gifClass1.gd_get_frame(gif1, buf1); 223 res2 = gifClass2.gd_get_frame(gif2, buf2); 224 res3 = gifClass3.gd_get_frame(gif3, buf3); 225 res4 = gifClass4.gd_get_frame(gif4, buf4); 226 if (res1 < 0) 227 { 228 Serial.println(F("ERROR: gd_get_frame(gif1, buf1) failed!")); 229 break; 230 } 231 else if (res1 == 0) 232 { 233 Serial.println(F("rewind gif1")); 234 gifClass1.gd_rewind(gif1); 235 } 236 else 237 { 238 gfx1->drawIndexedBitmap(x1, y1, buf1, gif1->palette->colors, gif1->width, gif1->height); 239 } 240 241 if (res2 < 0) 242 { 243 Serial.println(F("ERROR: gd_get_frame(gif2, buf2) failed!")); 244 break; 245 } 246 else if (res2 == 0) 247 { 248 Serial.println(F("rewind gif2")); 249 gifClass2.gd_rewind(gif2); 250 } 251 else 252 { 253 gfx2->drawIndexedBitmap(x2, y2, buf2, gif2->palette->colors, gif2->width, gif2->height); 254 } 255 256 if (res3 < 0) 257 { 258 Serial.println(F("ERROR: gd_get_frame(gif3, buf3) failed!")); 259 break; 260 } 261 else if (res3 == 0) 262 { 263 Serial.println(F("rewind gif3")); 264 gifClass3.gd_rewind(gif3); 265 } 266 else 267 { 268 gfx3->drawIndexedBitmap(x3, y3, buf3, gif3->palette->colors, gif3->width, gif3->height); 269 } 270 271 if (res4 < 0) 272 { 273 Serial.println(F("ERROR: gd_get_frame(gif4, buf4) failed!")); 274 break; 275 } 276 else if (res4 == 0) 277 { 278 Serial.println(F("rewind gif4")); 279 gifClass4.gd_rewind(gif4); 280 } 281 else 282 { 283 gfx4->drawIndexedBitmap(x4, y4, buf4, gif4->palette->colors, gif4->width, gif4->height); 284 } 285 } 286 Serial.println(F("GIF video end")); 287 Serial.print(F("duration: ")); 288 Serial.print(duration); 289 Serial.print(F(", remain: ")); 290 Serial.print(remain); 291 Serial.print(F(" (")); 292 Serial.print(100.0 * remain / duration); 293 Serial.println(F("%)")); 294 295 gifClass1.gd_close_gif(gif1); 296 gifClass2.gd_close_gif(gif2); 297 gifClass3.gd_close_gif(gif3); 298 gifClass4.gd_close_gif(gif4); 299 free(buf1); 300 free(buf2); 301 free(buf3); 302 free(buf4); 303 } 304 } 305 } 306 }