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 |
ImgViewerAnimatedGIF.ino (8220B)
1 /******************************************************************************* 2 * Animated GIF Image Viewer 3 * This is a simple Animated GIF image viewer exsample 4 * Image Source: https://www.pexels.com/video/earth-rotating-video-856356/ 5 * cropped: x: 598 y: 178 width: 720 height: 720 resized: 240x240 6 * optimized with ezgif.com 7 * 8 * Setup steps: 9 * 1. Change your LCD parameters in Arduino_GFX setting 10 * 2. Upload Animated GIF file 11 * FFat (ESP32): 12 * upload FFat (FatFS) data with ESP32 Sketch Data Upload: 13 * ESP32: https://github.com/lorol/arduino-esp32fs-plugin 14 * LittleFS (ESP32 / ESP8266 / Pico): 15 * upload LittleFS data with ESP8266 LittleFS Data Upload: 16 * ESP32: https://github.com/lorol/arduino-esp32fs-plugin 17 * ESP8266: https://github.com/earlephilhower/arduino-esp8266littlefs-plugin 18 * Pico: https://github.com/earlephilhower/arduino-pico-littlefs-plugin.git 19 * SPIFFS (ESP32): 20 * upload SPIFFS data with ESP32 Sketch Data Upload: 21 * ESP32: https://github.com/lorol/arduino-esp32fs-plugin 22 * SD: 23 * Most Arduino system built-in support SD file system. 24 * Wio Terminal require extra dependant Libraries: 25 * - Seeed_Arduino_FS: https://github.com/Seeed-Studio/Seeed_Arduino_FS.git 26 * - Seeed_Arduino_SFUD: https://github.com/Seeed-Studio/Seeed_Arduino_SFUD.git 27 ******************************************************************************/ 28 /* Wio Terminal */ 29 #if defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS) 30 #define GIF_FILENAME "/ezgif.com-optimize.gif" 31 #elif defined(TARGET_RP2040) 32 #define GIF_FILENAME "/ezgif.com-optimize.gif" 33 #elif defined(ESP32) 34 #define GIF_FILENAME "/ezgif.com-optimize.gif" 35 #else 36 #define GIF_FILENAME "/ezgif.com-resize.gif" 37 #endif 38 39 /******************************************************************************* 40 * Start of Arduino_GFX setting 41 * 42 * Arduino_GFX try to find the settings depends on selected board in Arduino IDE 43 * Or you can define the display dev kit not in the board list 44 * Defalult pin list for non display dev kit: 45 * Arduino Nano, Micro and more: CS: 9, DC: 8, RST: 7, BL: 6, SCK: 13, MOSI: 11, MISO: 12 46 * ESP32 various dev board : CS: 5, DC: 27, RST: 33, BL: 22, SCK: 18, MOSI: 23, MISO: nil 47 * ESP32-C3 various dev board : CS: 7, DC: 2, RST: 1, BL: 3, SCK: 4, MOSI: 6, MISO: nil 48 * ESP32-S2 various dev board : CS: 34, DC: 38, RST: 33, BL: 21, SCK: 36, MOSI: 35, MISO: nil 49 * ESP32-S3 various dev board : CS: 40, DC: 41, RST: 42, BL: 48, SCK: 36, MOSI: 35, MISO: nil 50 * ESP8266 various dev board : CS: 15, DC: 4, RST: 2, BL: 5, SCK: 14, MOSI: 13, MISO: 12 51 * Raspberry Pi Pico dev board : CS: 17, DC: 27, RST: 26, BL: 28, SCK: 18, MOSI: 19, MISO: 16 52 * RTL8720 BW16 old patch core : CS: 18, DC: 17, RST: 2, BL: 23, SCK: 19, MOSI: 21, MISO: 20 53 * RTL8720_BW16 Official core : CS: 9, DC: 8, RST: 6, BL: 3, SCK: 10, MOSI: 12, MISO: 11 54 * RTL8722 dev board : CS: 18, DC: 17, RST: 22, BL: 23, SCK: 13, MOSI: 11, MISO: 12 55 * RTL8722_mini dev board : CS: 12, DC: 14, RST: 15, BL: 13, SCK: 11, MOSI: 9, MISO: 10 56 * Seeeduino XIAO dev board : CS: 3, DC: 2, RST: 1, BL: 0, SCK: 8, MOSI: 10, MISO: 9 57 * Teensy 4.1 dev board : CS: 39, DC: 41, RST: 40, BL: 22, SCK: 13, MOSI: 11, MISO: 12 58 ******************************************************************************/ 59 #include <Arduino_GFX_Library.h> 60 61 #define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin 62 63 /* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */ 64 #if defined(DISPLAY_DEV_KIT) 65 Arduino_GFX *gfx = create_default_Arduino_GFX(); 66 #else /* !defined(DISPLAY_DEV_KIT) */ 67 68 /* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */ 69 Arduino_DataBus *bus = create_default_Arduino_DataBus(); 70 71 /* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */ 72 Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 3 /* rotation */, false /* IPS */); 73 74 #endif /* !defined(DISPLAY_DEV_KIT) */ 75 /******************************************************************************* 76 * End of Arduino_GFX setting 77 ******************************************************************************/ 78 79 /* Wio Terminal */ 80 #if defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS) 81 #include <Seeed_FS.h> 82 #include <SD/Seeed_SD.h> 83 #elif defined(TARGET_RP2040) 84 #include <LittleFS.h> 85 #include <SD.h> 86 #elif defined(ESP32) 87 #include <FFat.h> 88 #include <LittleFS.h> 89 #include <SPIFFS.h> 90 #include <SD.h> 91 #elif defined(ESP8266) 92 #include <LittleFS.h> 93 #include <SD.h> 94 #else 95 #include <SD.h> 96 #endif 97 98 #include "GifClass.h" 99 static GifClass gifClass; 100 101 void setup() 102 { 103 Serial.begin(115200); 104 // Serial.setDebugOutput(true); 105 // while(!Serial); 106 Serial.println("Animated GIF Image Viewer"); 107 108 #ifdef GFX_EXTRA_PRE_INIT 109 GFX_EXTRA_PRE_INIT(); 110 #endif 111 112 // Init Display 113 gfx->begin(); 114 gfx->fillScreen(BLACK); 115 116 #ifdef GFX_BL 117 pinMode(GFX_BL, OUTPUT); 118 digitalWrite(GFX_BL, HIGH); 119 #endif 120 121 /* Wio Terminal */ 122 #if defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS) 123 if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI, 4000000UL)) 124 #elif defined(TARGET_RP2040) 125 if (!LittleFS.begin()) 126 // if (!SD.begin(SS)) 127 #elif defined(ESP32) 128 // if (!FFat.begin()) 129 if (!LittleFS.begin()) 130 // if (!SPIFFS.begin()) 131 // if (!SD.begin(SS)) 132 #elif defined(ESP8266) 133 if (!LittleFS.begin()) 134 // if (!SD.begin(SS)) 135 #else 136 if (!SD.begin()) 137 #endif 138 { 139 Serial.println(F("ERROR: File System Mount Failed!")); 140 gfx->println(F("ERROR: File System Mount Failed!")); 141 exit(0); 142 } 143 } 144 145 void loop() 146 { 147 /* Wio Terminal */ 148 #if defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS) 149 File gifFile = SD.open(GIF_FILENAME, "r"); 150 #elif defined(TARGET_RP2040) 151 File gifFile = LittleFS.open(GIF_FILENAME, "r"); 152 // File gifFile = SD.open(GIF_FILENAME, "r"); 153 #elif defined(ESP32) 154 // File gifFile = FFat.open(GIF_FILENAME, "r"); 155 File gifFile = LittleFS.open(GIF_FILENAME, "r"); 156 // File gifFile = SPIFFS.open(GIF_FILENAME, "r"); 157 // File gifFile = SD.open(GIF_FILENAME, "r"); 158 #elif defined(ESP8266) 159 File gifFile = LittleFS.open(GIF_FILENAME, "r"); 160 // File gifFile = SD.open(GIF_FILENAME, "r"); 161 #else 162 File gifFile = SD.open(GIF_FILENAME, FILE_READ); 163 #endif 164 if (!gifFile || gifFile.isDirectory()) 165 { 166 Serial.println(F("ERROR: open gifFile Failed!")); 167 gfx->println(F("ERROR: open gifFile Failed!")); 168 } 169 else 170 { 171 // read GIF file header 172 gd_GIF *gif = gifClass.gd_open_gif(&gifFile); 173 if (!gif) 174 { 175 Serial.println(F("gd_open_gif() failed!")); 176 } 177 else 178 { 179 uint8_t *buf = (uint8_t *)malloc(gif->width * gif->height); 180 if (!buf) 181 { 182 Serial.println(F("buf malloc failed!")); 183 } 184 else 185 { 186 int16_t x = (gfx->width() - gif->width) / 2; 187 int16_t y = (gfx->height() - gif->height) / 2; 188 189 Serial.println(F("GIF video start")); 190 int32_t t_fstart, t_delay = 0, t_real_delay, delay_until; 191 int32_t res = 1; 192 int32_t duration = 0, remain = 0; 193 while (res > 0) 194 { 195 t_fstart = millis(); 196 t_delay = gif->gce.delay * 10; 197 res = gifClass.gd_get_frame(gif, buf); 198 if (res < 0) 199 { 200 Serial.println(F("ERROR: gd_get_frame() failed!")); 201 break; 202 } 203 else if (res > 0) 204 { 205 gfx->drawIndexedBitmap(x, y, buf, gif->palette->colors, gif->width, gif->height); 206 207 t_real_delay = t_delay - (millis() - t_fstart); 208 duration += t_delay; 209 remain += t_real_delay; 210 delay_until = millis() + t_real_delay; 211 while (millis() < delay_until) 212 { 213 delay(1); 214 } 215 } 216 } 217 Serial.println(F("GIF video end")); 218 Serial.print(F("duration: ")); 219 Serial.print(duration); 220 Serial.print(F(", remain: ")); 221 Serial.print(remain); 222 Serial.print(F(" (")); 223 Serial.print(100.0 * remain / duration); 224 Serial.println(F("%)")); 225 226 gifClass.gd_close_gif(gif); 227 free(buf); 228 } 229 } 230 } 231 }