Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix POV Display usermod #4427

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions usermods/pov_display/README.md
Original file line number Diff line number Diff line change
@@ -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.
51 changes: 31 additions & 20 deletions usermods/pov_display/usermod_pov_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
#include "wled.h"
#include <PNGdec.h>

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;
Expand All @@ -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<File *>(pFile->fHandle);
Expand All @@ -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);
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion wled00/usermods_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down