Skip to content

Commit 72d38f4

Browse files
authored
Merge pull request #3539 from Liliputech/pov_display
Added POV image effect
2 parents f6c47ac + ed5eb28 commit 72d38f4

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

platformio_override.sample.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ lib_deps = ${esp8266.lib_deps}
2929
; ;gmag11/QuickESPNow @ ~0.7.0 # will also load QuickDebug
3030
; https://github.com/blazoncek/QuickESPNow.git#optional-debug ;; exludes debug library
3131
; ${esp32.AR_lib_deps} ;; used for USERMOD_AUDIOREACTIVE
32+
; bitbank2/PNGdec@^1.0.1 ;; used for POV display uncomment following
33+
3234
build_unflags = ${common.build_unflags}
3335
build_flags = ${common.build_flags} ${esp8266.build_flags}
3436
;
@@ -152,6 +154,8 @@ build_flags = ${common.build_flags} ${esp8266.build_flags}
152154
; -D TACHO_PIN=33
153155
; -D PWM_PIN=32
154156
;
157+
; Use POV Display usermod
158+
; -D USERMOD_POV_DISPLAY
155159
; Use built-in or custom LED as a status indicator (assumes LED is connected to GPIO16)
156160
; -D STATUSLED=16
157161
;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#pragma once
2+
#include "wled.h"
3+
#include <PNGdec.h>
4+
5+
void * openFile(const char *filename, int32_t *size) {
6+
f = WLED_FS.open(filename);
7+
*size = f.size();
8+
return &f;
9+
}
10+
11+
void closeFile(void *handle) {
12+
if (f) f.close();
13+
}
14+
15+
int32_t readFile(PNGFILE *pFile, uint8_t *pBuf, int32_t iLen)
16+
{
17+
int32_t iBytesRead;
18+
iBytesRead = iLen;
19+
File *f = static_cast<File *>(pFile->fHandle);
20+
// Note: If you read a file all the way to the last byte, seek() stops working
21+
if ((pFile->iSize - pFile->iPos) < iLen)
22+
iBytesRead = pFile->iSize - pFile->iPos - 1; // <-- ugly work-around
23+
if (iBytesRead <= 0)
24+
return 0;
25+
iBytesRead = (int32_t)f->read(pBuf, iBytesRead);
26+
pFile->iPos = f->position();
27+
return iBytesRead;
28+
}
29+
30+
int32_t seekFile(PNGFILE *pFile, int32_t iPosition)
31+
{
32+
int i = micros();
33+
File *f = static_cast<File *>(pFile->fHandle);
34+
f->seek(iPosition);
35+
pFile->iPos = (int32_t)f->position();
36+
i = micros() - i;
37+
return pFile->iPos;
38+
}
39+
40+
void draw(PNGDRAW *pDraw) {
41+
uint16_t usPixels[SEGLEN];
42+
png.getLineAsRGB565(pDraw, usPixels, PNG_RGB565_LITTLE_ENDIAN, 0xffffffff);
43+
for(int x=0; x < SEGLEN; x++) {
44+
uint16_t color = usPixels[x];
45+
byte r = ((color >> 11) & 0x1F);
46+
byte g = ((color >> 5) & 0x3F);
47+
byte b = (color & 0x1F);
48+
SEGMENT.setPixelColor(x, RGBW32(r,g,b,0));
49+
}
50+
strip.show();
51+
}
52+
53+
uint16_t mode_pov_image(void) {
54+
const char * filepath = SEGMENT.name;
55+
int rc = png.open(filepath, openFile, closeFile, readFile, seekFile, draw);
56+
if (rc == PNG_SUCCESS) {
57+
rc = png.decode(NULL, 0);
58+
png.close();
59+
return FRAMETIME;
60+
}
61+
return FRAMETIME;
62+
}
63+
64+
class PovDisplayUsermod : public Usermod
65+
{
66+
public:
67+
static const char _data_FX_MODE_POV_IMAGE[] PROGMEM = "POV Image@!;;;1";
68+
69+
PNG png;
70+
File f;
71+
72+
void setup() {
73+
strip.addEffect(255, &mode_pov_image, _data_FX_MODE_POV_IMAGE);
74+
}
75+
76+
void loop() {
77+
}
78+
79+
uint16_t getId()
80+
{
81+
return USERMOD_ID_POV_DISPLAY;
82+
}
83+
84+
void connected() {}
85+
};

wled00/const.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
#define USERMOD_ID_INA226 50 //Usermod "usermod_ina226.h"
201201
#define USERMOD_ID_AHT10 51 //Usermod "usermod_aht10.h"
202202
#define USERMOD_ID_LD2410 52 //Usermod "usermod_ld2410.h"
203+
#define USERMOD_ID_POV_DISPLAY 53 //Usermod "usermod_pov_display.h"
203204

204205
//Access point behavior
205206
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot

wled00/usermods_list.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@
210210
#include "../usermods/LDR_Dusk_Dawn_v2/usermod_LDR_Dusk_Dawn_v2.h"
211211
#endif
212212

213+
#ifdef USERMOD_POV_DISPLAY
214+
#include "../usermods/pov_display/usermod_pov_display.h"
215+
#endif
216+
213217
#ifdef USERMOD_STAIRCASE_WIPE
214218
#include "../usermods/stairway_wipe_basic/stairway-wipe-usermod-v2.h"
215219
#endif
@@ -454,4 +458,8 @@ void registerUsermods()
454458
#ifdef USERMOD_LD2410
455459
usermods.add(new LD2410Usermod());
456460
#endif
461+
462+
#ifdef USERMOD_POV_DISPLAY
463+
usermods.add(new PovDisplayUsermod());
464+
#endif
457465
}

0 commit comments

Comments
 (0)