diff --git a/usermods/pov_display/README.md b/usermods/pov_display/README.md new file mode 100644 index 0000000000..779f90c99d --- /dev/null +++ b/usermods/pov_display/README.md @@ -0,0 +1,18 @@ +# Usermod for POV Display +This usermod helps you display images and graphics on a moving piece of LED strip. +The whole goal of the project is to use images like the one found on this website : https://visualpoi.zone/ +or any other image with a similar purpose. +It could be used for LED spoke lights attached to a bike, LED fans, or juggling devices. + +## How to make it work? +The images should be the same width as the length of your LED strip, and formatted as PNG. +The usermod also handles mirroring, which means you can "fold" a led strip in two to get the same image displayed on both side. +The effect will first draw the first line of your image, then very rapidly display the second line, etc, until the last line, and then it will loop to the first line. +Think of it as a "2D image to 1D strip converter" effect. +This could be used for lightpainting or to make a cheap hologram. + +The images should be uploaded to the filesystem (using /edit endpoint). +To display the image, select "POV Image" in the effect, and set the segment name as the filename of the image (including .png). + +To help you to use this project you could also use the GifPlayer from https://github.com/Manut38/WLED-GIFPlayer-html +you would have to update the effect ID in the html file to reflect the effect ID of the "POV Image" effect though. \ No newline at end of file diff --git a/usermods/pov_display/usermod_pov_display.h b/usermods/pov_display/usermod_pov_display.h index b1fc0dba60..7c1e9f6109 100644 --- a/usermods/pov_display/usermod_pov_display.h +++ b/usermods/pov_display/usermod_pov_display.h @@ -2,17 +2,21 @@ #include "wled.h" #include -void * openFile(const char *filename, int32_t *size) { - f = WLED_FS.open(filename); - *size = f.size(); - return &f; +PNG png_decoder; +File pov_image; +static const char _data_FX_MODE_POV_IMAGE[] PROGMEM = "POV Image@!;;;1"; + +void * PovOpenFile(const char *filename, int32_t *size) { + pov_image = WLED_FS.open(filename); + *size = pov_image.size(); + return &pov_image; } -void closeFile(void *handle) { - if (f) f.close(); +void PovCloseFile(void *handle) { + if (pov_image) pov_image.close(); } -int32_t readFile(PNGFILE *pFile, uint8_t *pBuf, int32_t iLen) +int32_t PovReadFile(PNGFILE *pFile, uint8_t *pBuf, int32_t iLen) { int32_t iBytesRead; iBytesRead = iLen; @@ -27,7 +31,7 @@ int32_t readFile(PNGFILE *pFile, uint8_t *pBuf, int32_t iLen) return iBytesRead; } -int32_t seekFile(PNGFILE *pFile, int32_t iPosition) +int32_t PovSeekFile(PNGFILE *pFile, int32_t iPosition) { int i = micros(); File *f = static_cast(pFile->fHandle); @@ -37,9 +41,9 @@ int32_t seekFile(PNGFILE *pFile, int32_t iPosition) return pFile->iPos; } -void draw(PNGDRAW *pDraw) { +void PovDraw(PNGDRAW *pDraw) { uint16_t usPixels[SEGLEN]; - png.getLineAsRGB565(pDraw, usPixels, PNG_RGB565_LITTLE_ENDIAN, 0xffffffff); + png_decoder.getLineAsRGB565(pDraw, usPixels, PNG_RGB565_LITTLE_ENDIAN, 0xffffffff); for(int x=0; x < SEGLEN; x++) { uint16_t color = usPixels[x]; byte r = ((color >> 11) & 0x1F); @@ -51,26 +55,33 @@ void draw(PNGDRAW *pDraw) { } uint16_t mode_pov_image(void) { - const char * filepath = SEGMENT.name; - int rc = png.open(filepath, openFile, closeFile, readFile, seekFile, draw); + char filepath[WLED_MAX_SEGNAME_LEN + 1] = "/"; + strncpy(filepath + 1, SEGMENT.name, WLED_MAX_SEGNAME_LEN); + int rc = png_decoder.open(filepath, PovOpenFile, PovCloseFile, PovReadFile, PovSeekFile, PovDraw); if (rc == PNG_SUCCESS) { - rc = png.decode(NULL, 0); - png.close(); + rc = png_decoder.decode(NULL, 0); + png_decoder.close(); return FRAMETIME; } return FRAMETIME; } -class PovDisplayUsermod : public Usermod -{ - public: - static const char _data_FX_MODE_POV_IMAGE[] PROGMEM = "POV Image@!;;;1"; +class PovDisplayUsermod : public Usermod { + protected: + bool enabled = false; //WLEDMM + const char *_name; //WLEDMM + bool initDone = false; //WLEDMM + unsigned long lastTime = 0; //WLEDMM - PNG png; - File f; + public: + PovDisplayUsermod(const char *name, bool enabled) { + this->_name = name; + this->enabled = enabled; + } //WLEDMM void setup() { strip.addEffect(255, &mode_pov_image, _data_FX_MODE_POV_IMAGE); + initDone = true; } void loop() { diff --git a/wled00/usermods_list.cpp b/wled00/usermods_list.cpp index 627fa6308a..a3dc1344f4 100644 --- a/wled00/usermods_list.cpp +++ b/wled00/usermods_list.cpp @@ -473,7 +473,7 @@ void registerUsermods() #endif #ifdef USERMOD_POV_DISPLAY - UsermodManager::add(new PovDisplayUsermod()); + UsermodManager::add(new PovDisplayUsermod("Pov Display", false)); #endif #ifdef USERMOD_DEEP_SLEEP