From ce44827316a60f01f6a36d6ea22d3d646255814d Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Tue, 24 Dec 2024 19:04:36 +0100 Subject: [PATCH 1/3] fix POV Display usermod --- usermods/pov_display/usermod_pov_display.h | 22 ++++++++++++++++------ wled00/usermods_list.cpp | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/usermods/pov_display/usermod_pov_display.h b/usermods/pov_display/usermod_pov_display.h index b1fc0dba60..f0011ebbc3 100644 --- a/usermods/pov_display/usermod_pov_display.h +++ b/usermods/pov_display/usermod_pov_display.h @@ -2,6 +2,10 @@ #include "wled.h" #include +PNG png; +File f; +static const char _data_FX_MODE_POV_IMAGE[] PROGMEM = "POV Image@!;;;1"; + void * openFile(const char *filename, int32_t *size) { f = WLED_FS.open(filename); *size = f.size(); @@ -61,16 +65,22 @@ uint16_t mode_pov_image(void) { 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 From 5e5554b12ec2a00121f485a4784eb5f8b0396296 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Sat, 8 Feb 2025 13:40:20 +0100 Subject: [PATCH 2/3] use more explicit and less conflicting functions and variable names --- usermods/pov_display/usermod_pov_display.h | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/usermods/pov_display/usermod_pov_display.h b/usermods/pov_display/usermod_pov_display.h index f0011ebbc3..7c1e9f6109 100644 --- a/usermods/pov_display/usermod_pov_display.h +++ b/usermods/pov_display/usermod_pov_display.h @@ -2,21 +2,21 @@ #include "wled.h" #include -PNG png; -File f; +PNG png_decoder; +File pov_image; static const char _data_FX_MODE_POV_IMAGE[] PROGMEM = "POV Image@!;;;1"; -void * openFile(const char *filename, int32_t *size) { - f = WLED_FS.open(filename); - *size = f.size(); - return &f; +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; @@ -31,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); @@ -41,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); @@ -55,11 +55,12 @@ 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; From ebd00007257d760015962b2c3422e18482531333 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Sat, 8 Feb 2025 14:07:30 +0100 Subject: [PATCH 3/3] add a README file for pov_display usermod --- usermods/pov_display/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 usermods/pov_display/README.md 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