Skip to content

Commit 9520eed

Browse files
authored
prepare WS DDP for ESP8266 compatibility, fix compiler warnings in pacman FX, remove omggif.js for ESP8266 (#5734)
* prepare DDP for ESP8266 compatibility, fix compiler errros in pacman * fix C3 compile issues * remove unuseable omggif.js for ESP8266 and save 2.5k of flash. * hide image tool on ESP8266 as gif is not supported * run getLoc() before any fetch
1 parent 7ce236c commit 9520eed

4 files changed

Lines changed: 66 additions & 45 deletions

File tree

wled00/FX.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,25 +3150,25 @@ static const char _data_FX_MODE_ROLLINGBALLS[] PROGMEM = "Rolling Balls@!,# of b
31503150
* aux1 is the main counter for timing.
31513151
*/
31523152
typedef struct PacManChars {
3153-
signed pos;
3154-
signed topPos; // LED position of farthest PacMan has moved
3153+
int pos;
3154+
int topPos; // LED position of farthest PacMan has moved
31553155
uint32_t color;
31563156
bool direction; // true = moving away from first LED
31573157
bool blue; // used for ghosts only
31583158
bool eaten; // used for power dots only
31593159
} pacmancharacters_t;
31603160

31613161
static void mode_pacman(void) {
3162-
constexpr unsigned ORANGEYELLOW = 0xFFCC00;
3163-
constexpr unsigned PURPLEISH = 0xB000B0;
3164-
constexpr unsigned ORANGEISH = 0xFF8800;
3165-
constexpr unsigned WHITEISH = 0x999999;
3166-
constexpr unsigned PACMAN = 0; // PacMan is character[0]
3162+
constexpr uint32_t ORANGEYELLOW = 0xFFCC00;
3163+
constexpr uint32_t PURPLEISH = 0xB000B0;
3164+
constexpr uint32_t ORANGEISH = 0xFF8800;
3165+
constexpr uint32_t WHITEISH = 0x999999;
3166+
constexpr uint32_t PACMAN = 0; // PacMan is character[0]
31673167
constexpr uint32_t ghostColors[] = {RED, PURPLEISH, CYAN, ORANGEISH};
31683168

3169-
unsigned maxPowerDots = min(SEGLEN / 10U, 255U); // cap the max so packed state fits in 8 bits
3170-
unsigned numPowerDots = map(SEGMENT.intensity, 0, 255, 1, maxPowerDots);
3171-
unsigned numGhosts = map(SEGMENT.custom3, 0, 31, 2, 8);
3169+
uint32_t maxPowerDots = min(SEGLEN / 10U, 255U); // cap the max so packed state fits in 8 bits
3170+
uint32_t numPowerDots = map(SEGMENT.intensity, 0, 255, 1, maxPowerDots);
3171+
uint32_t numGhosts = map(SEGMENT.custom3, 0, 31, 2, 8);
31723172
bool smearMode = SEGMENT.check2;
31733173

31743174
// Pack two 8-bit values into one 16-bit field (stored in SEGENV.aux0)
@@ -3177,15 +3177,15 @@ static void mode_pacman(void) {
31773177
SEGENV.aux0 = combined_value;
31783178

31793179
// Allocate segment data
3180-
unsigned dataSize = sizeof(pacmancharacters_t) * (numGhosts + maxPowerDots + 1); // +1 is the PacMan character
3180+
uint32_t dataSize = sizeof(pacmancharacters_t) * (numGhosts + maxPowerDots + 1); // +1 is the PacMan character
31813181
if (SEGLEN <= 16 + (2*numGhosts) || !SEGENV.allocateData(dataSize)) FX_FALLBACK_STATIC;
31823182
pacmancharacters_t *character = reinterpret_cast<pacmancharacters_t *>(SEGENV.data);
31833183

31843184
// Calculate when blue ghosts start blinking.
31853185
// On first call (or after settings change), `topPos` is not known yet, so fall back to the full segment length in that case.
31863186
int maxBlinkPos = (SEGENV.call == 0) ? (int)SEGLEN - 1 : character[PACMAN].topPos;
31873187
if (maxBlinkPos < 20) maxBlinkPos = 20;
3188-
int startBlinkingGhostsLED = (SEGLEN < 64)
3188+
int startBlinkingGhostsLED = (SEGLEN < 64U)
31893189
? (int)SEGLEN / 3
31903190
: map(SEGMENT.custom1, 0, 255, 20, maxBlinkPos);
31913191

@@ -3199,19 +3199,19 @@ static void mode_pacman(void) {
31993199
character[PACMAN].blue = false;
32003200

32013201
// Initialize ghosts with alternating colors
3202-
for (int i = 1; i <= numGhosts; i++) {
3202+
for (uint32_t i = 1; i <= numGhosts; i++) {
32033203
character[i].color = ghostColors[(i-1) % 4];
3204-
character[i].pos = -2 * (i + 1);
3204+
character[i].pos = -2 * int32_t(i + 1);
32053205
character[i].direction = true;
32063206
character[i].blue = false;
32073207
}
32083208

32093209
// Initialize power dots
3210-
for (int i = 0; i < numPowerDots; i++) {
3210+
for (uint32_t i = 0; i < numPowerDots; i++) {
32113211
character[i + numGhosts + 1].color = ORANGEYELLOW;
32123212
character[i + numGhosts + 1].eaten = false;
32133213
}
3214-
character[numGhosts + 1].pos = SEGLEN - 1; // Last power dot at end
3214+
character[numGhosts + 1].pos = int32_t(SEGLEN - 1); // Last power dot at end
32153215
}
32163216

32173217
if (strip.now > SEGENV.step) {
@@ -3225,50 +3225,50 @@ static void mode_pacman(void) {
32253225
// Draw white dots in front of PacMan if option selected
32263226
if (SEGMENT.check1) {
32273227
int step = SEGMENT.check3 ? 1 : 2; // Compact or spaced dots
3228-
for (int i = SEGLEN - 1; i > character[PACMAN].topPos; i -= step) {
3228+
for (int i = (int32_t)(SEGLEN - 1); i > character[PACMAN].topPos; i -= step) {
32293229
SEGMENT.setPixelColor(i, WHITEISH);
32303230
}
32313231
}
32323232

32333233
// Update power dot positions dynamically
32343234
uint32_t everyXLeds = (((uint32_t)SEGLEN - 10U) << 8) / numPowerDots; // Fixed-point spacing for power dots: use 32-bit math to avoid overflow on long segments.
3235-
for (int i = 1; i < numPowerDots; i++) {
3236-
character[i + numGhosts + 1].pos = 10 + ((i * everyXLeds) >> 8);
3235+
for (uint32_t i = 1; i < numPowerDots; i++) {
3236+
character[i + numGhosts + 1].pos = int32_t(10 + ((i * everyXLeds) >> 8));
32373237
}
32383238

32393239
// Blink power dots every 10 ticks
3240-
if (SEGENV.aux1 % 10 == 0) {
3240+
if (SEGENV.aux1 % 10U == 0) {
32413241
uint32_t dotColor = (character[numGhosts + 1].color == ORANGEYELLOW) ? BLACK : ORANGEYELLOW;
3242-
for (int i = 0; i < numPowerDots; i++) {
3242+
for (uint32_t i = 0; i < numPowerDots; i++) {
32433243
character[i + numGhosts + 1].color = dotColor;
32443244
}
32453245
}
32463246

32473247
// Blink blue ghosts when nearing start
3248-
if (SEGENV.aux1 % 15 == 0 && character[1].blue && character[PACMAN].pos <= startBlinkingGhostsLED) {
3248+
if (SEGENV.aux1 % 15U == 0 && character[1].blue && character[PACMAN].pos <= startBlinkingGhostsLED) {
32493249
uint32_t ghostColor = (character[1].color == BLUE) ? WHITEISH : BLUE;
3250-
for (int i = 1; i <= numGhosts; i++) {
3250+
for (uint32_t i = 1; i <= numGhosts; i++) {
32513251
character[i].color = ghostColor;
32523252
}
32533253
}
32543254

32553255
// Draw uneaten power dots
3256-
for (int i = 0; i < numPowerDots; i++) {
3257-
if (!character[i + numGhosts + 1].eaten && (unsigned)character[i + numGhosts + 1].pos < SEGLEN) {
3256+
for (uint32_t i = 0; i < numPowerDots; i++) {
3257+
if (!character[i + numGhosts + 1].eaten && (uint32_t)character[i + numGhosts + 1].pos < SEGLEN) {
32583258
SEGMENT.setPixelColor(character[i + numGhosts + 1].pos, character[i + numGhosts + 1].color);
32593259
}
32603260
}
32613261

32623262
// Check if PacMan ate a power dot
3263-
for (int j = 0; j < numPowerDots; j++) {
3263+
for (uint32_t j = 0; j < numPowerDots; j++) {
32643264
auto &dot = character[j + numGhosts + 1];
32653265
if (character[PACMAN].pos == dot.pos && !dot.eaten) {
32663266
// Reverse all characters - PacMan now chases ghosts
3267-
for (int i = 0; i <= numGhosts; i++) {
3267+
for (uint32_t i = 0; i <= numGhosts; i++) {
32683268
character[i].direction = false;
32693269
}
32703270
// Turn ghosts blue
3271-
for (int i = 1; i <= numGhosts; i++) {
3271+
for (uint32_t i = 1; i <= numGhosts; i++) {
32723272
character[i].color = BLUE;
32733273
character[i].blue = true;
32743274
}
@@ -3280,42 +3280,42 @@ static void mode_pacman(void) {
32803280
// Reset when PacMan reaches start with blue ghosts
32813281
if (character[1].blue && character[PACMAN].pos <= 0) {
32823282
// Reverse direction back
3283-
for (int i = 0; i <= numGhosts; i++) {
3283+
for (uint32_t i = 0; i <= numGhosts; i++) {
32843284
character[i].direction = true;
32853285
}
32863286
// Reset ghost colors
3287-
for (int i = 1; i <= numGhosts; i++) {
3287+
for (uint32_t i = 1; i <= numGhosts; i++) {
32883288
character[i].color = ghostColors[(i-1) % 4];
32893289
character[i].blue = false;
32903290
}
32913291
// Reset power dots if last one was eaten
32923292
if (character[numGhosts + 1].eaten) {
3293-
for (int i = 0; i < numPowerDots; i++) {
3293+
for (uint32_t i = 0; i < numPowerDots; i++) {
32943294
character[i + numGhosts + 1].eaten = false;
32953295
}
32963296
character[PACMAN].topPos = 0; // set the top position of PacMan to LED 0 (beginning of the segment)
32973297
}
32983298
}
32993299

33003300
// Update and draw characters based on speed setting
3301-
bool updatePositions = (SEGENV.aux1 % map(SEGMENT.speed, 0, 255, 15, 1) == 0);
3301+
bool updatePositions = (SEGENV.aux1 % uint32_t(map(SEGMENT.speed, 0, 255, 15, 1)) == 0);
33023302

33033303
// update positions of characters if it's time to do so
33043304
if (updatePositions) {
33053305
character[PACMAN].pos += character[PACMAN].direction ? 1 : -1;
3306-
for (int i = 1; i <= numGhosts; i++) {
3306+
for (uint32_t i = 1; i <= numGhosts; i++) {
33073307
character[i].pos += character[i].direction ? 1 : -1;
33083308
}
33093309
}
33103310

33113311
// Draw PacMan
3312-
if ((unsigned)character[PACMAN].pos < SEGLEN) {
3312+
if ((uint32_t)character[PACMAN].pos < SEGLEN) {
33133313
SEGMENT.setPixelColor(character[PACMAN].pos, character[PACMAN].color);
33143314
}
33153315

33163316
// Draw ghosts
3317-
for (int i = 1; i <= numGhosts; i++) {
3318-
if ((unsigned)character[i].pos < SEGLEN) {
3317+
for (uint32_t i = 1; i <= numGhosts; i++) {
3318+
if ((uint32_t)character[i].pos < SEGLEN) {
33193319
SEGMENT.setPixelColor(character[i].pos, character[i].color);
33203320
}
33213321
}

wled00/data/common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ function connectWs(onOpen) {
213213
// start: start pixel index
214214
// len: number of pixels to send
215215
// colors: Uint8Array with RGB values (3*len bytes)
216-
function sendDDP(ws, start, len, colors) {
216+
function sendDDP(ws, start, len, colors, isESP8266=false) {
217217
if (!colors || colors.length < len * 3) return false; // not enough color data
218-
let maxDDPpx = 472; // must fit into one WebSocket frame of 1428 bytes, DDP header is 10+1 bytes -> 472 RGB pixels
219-
//let maxDDPpx = 172; // ESP8266: must fit into one WebSocket frame of 528 bytes -> 172 RGB pixels TODO: add support for ESP8266?
218+
// data must fit into one WebSocket frame of 1428 bytes, DDP header is 10+1 bytes -> 472 RGB pixels (ESP8266: 528 bytes -> 172 RGB pixels)
219+
let maxDDPpx = isESP8266 ? 172 : 472;
220220
if (!ws || ws.readyState !== WebSocket.OPEN) return false;
221221
// send in chunks of maxDDPpx
222222
for (let i = 0; i < len; i += maxDDPpx) {

wled00/data/pixelforge/pixelforge.htm

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
</div>
253253

254254
<div id="iTab" class="tabc active">
255+
<div id="iTabContent">
255256
<h3 style="margin-top:20px;">Target Segment</h3>
256257
<select id="seg"></select>
257258

@@ -320,6 +321,8 @@ <h3 style="margin-top:0;padding-top:0;border-top:0">Crop & Adjust Image</h3>
320321
</div>
321322
</div>
322323
<button class="btn" id="up">Convert & Upload to WLED</button>
324+
</div>
325+
<div id="iTab8266" style="display:none;">Not available on ESP8266</div>
323326
</div>
324327
</div>
325328

@@ -424,6 +427,7 @@ <h3>Custom Fonts</h3>
424427
const classics=['console_font_4x6.wbf','console_font_5x12.wbf','console_font_5x8.wbf','console_font_6x8.wbf','console_font_7x9.wbf']; // classic WLED fonts list
425428
let pT = []; // local tools list from JSON
426429
let wv = [0, 0]; // wled version [major, minor], updated in fsMem(), used to check tool compatibility
430+
let is8266 = false; // restrictions apply for ESP8266, set when getting the info
427431
const remoteURL = 'https://wled.github.io/wled-web-tools/pftools.json'; // tools list
428432
const toolsjson = 'pftools.json';
429433
// note: the pftools.json must use major.minor for tool versions (e.g. 0.95 or 1.1), otherwise the update check won't work
@@ -434,23 +438,25 @@ <h3>Custom Fonts</h3>
434438
const s = document.createElement('script');
435439
s.src = 'common.js';
436440
s.onerror = () => setTimeout(loadFiles, 100);
437-
s.onload = () => {
438-
loadResources(['style.css','omggif.js'], init); // load omggif.js then call init()
441+
s.onload = async () => {
442+
getLoc(); // set up loc/locip for getURL() before any fetch (file mode / reverse proxy)
443+
await fsMem(); // update & show file system memory info, also updates wled version (wv) and is8266
444+
const resources = ['style.css'];
445+
if (!is8266) resources.push('omggif.js'); // omggif is not available on ESP8266
446+
loadResources(resources, init); // load omggif.js then call init()
439447
};
440448
document.head.appendChild(s);
441449
})();
442450

443451
/* init */
444452
async function init() {
445-
getLoc();
446453
// create off screen canvas
447454
rv = cE('canvas');
448455
rvc = rv.getContext('2d',{willReadFrequently:true});
449456
rv.width = cv.width; rv.height = cv.height;
450457
await flU(); // update file list
451458
tabSw(localStorage.tab||'img'); // switch to last open tab or image tab by default
452459
await segLoad(); // load available segments
453-
await fsMem(); // update & show file system memory info, also updates wled version (wv)
454460
await loadTools(); // load additional tools list from pftools.json
455461
}
456462

@@ -707,6 +713,7 @@ <h3>${esc(t.name)} <small style="font-size:10px">v${esc(t.ver)}</small></h3>
707713
const m = info.ver.match(/\d+/g); // extract all numbers from version string (e.g. "16.1.0-beta" → [16, 1])
708714
wv = [parseInt(m[0]) || 0, parseInt(m[1]) || 0];
709715
}
716+
if (info.arch === 'esp8266') is8266 = true;
710717
}
711718
}catch(e){console.error(e);}
712719
}
@@ -1263,7 +1270,15 @@ <h3>${esc(t.name)} <small style="font-size:10px">v${esc(t.ver)}</small></h3>
12631270
getId(id).classList.toggle('active', tab===['img','txt','oth'][i%3]);
12641271
});
12651272
localStorage.tab=tab;
1266-
({txt:()=>{txtSegLoad(); scanFonts();}, img:imgLoad}[tab]||(()=>{}))(); // on tab switch, load images and available fonts
1273+
if (tab === 'img') {
1274+
getId('iTab8266').style.display = is8266 ? 'block' : 'none'; // show "not available" on ESP8266
1275+
getId('iTabContent').style.display = is8266 ? 'none' : ''; // show normal image tool on ESP32
1276+
if (!is8266) imgLoad();
1277+
}
1278+
if (tab === 'txt') {
1279+
txtSegLoad();
1280+
scanFonts();
1281+
}
12671282
}
12681283
'Img,Txt,Oth'.split(',').forEach((s,i)=>{
12691284
getId('t'+s).onclick=()=>tabSw(['img','txt','oth'][i]);

wled00/wled_server.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include "html_settings.h"
88
#include "html_other.h"
99
#include "js_iro.h"
10-
#include "js_omggif.h"
10+
#ifdef WLED_ENABLE_GIF
11+
#include "js_omggif.h"
12+
#endif
1113
#ifdef WLED_ENABLE_PIXART
1214
#include "html_pixart.h"
1315
#endif
@@ -42,7 +44,9 @@ static const char s_no_store[] PROGMEM = "no-store";
4244
static const char s_expires[] PROGMEM = "Expires";
4345
static const char _common_js[] PROGMEM = "/common.js";
4446
static const char _iro_js[] PROGMEM = "/iro.js";
47+
#ifdef WLED_ENABLE_GIF
4548
static const char _omggif_js[] PROGMEM = "/omggif.js";
49+
#endif
4650

4751
//Is this an IP?
4852
static bool isIp(const String &str) {
@@ -362,9 +366,11 @@ void initServer()
362366
handleStaticContent(request, FPSTR(_iro_js), 200, FPSTR(CONTENT_TYPE_JAVASCRIPT), JS_iro, JS_iro_length);
363367
});
364368

369+
#ifdef WLED_ENABLE_GIF
365370
server.on(_omggif_js, HTTP_GET, [](AsyncWebServerRequest *request) {
366371
handleStaticContent(request, FPSTR(_omggif_js), 200, FPSTR(CONTENT_TYPE_JAVASCRIPT), JS_omggif, JS_omggif_length);
367372
});
373+
#endif
368374

369375
//settings page
370376
server.on(F("/settings"), HTTP_GET, [](AsyncWebServerRequest *request){

0 commit comments

Comments
 (0)