Skip to content

Commit 2f7be34

Browse files
committed
Updated mapping comment
1 parent 2544d2e commit 2f7be34

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

wled00/FX.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
Modified for WLED
2525
*/
2626

27+
#include "wled.h"
28+
2729
#ifndef WS2812FX_h
2830
#define WS2812FX_h
2931

@@ -847,7 +849,11 @@ class WS2812FX {
847849

848850
void
849851
blendPixelColor(uint16_t n, uint32_t color, uint8_t blend),
850-
startTransition(uint8_t oldBri, uint32_t oldCol, uint16_t dur, uint8_t segn, uint8_t slot);
852+
startTransition(uint8_t oldBri, uint32_t oldCol, uint16_t dur, uint8_t segn, uint8_t slot),
853+
deserializeMap(void);
854+
855+
uint16_t* customMappingTable = nullptr;
856+
uint16_t customMappingSize = 0;
851857

852858
uint32_t _lastPaletteChange = 0;
853859
uint32_t _lastShow = 0;

wled00/FX_fcn.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,50 +27,25 @@
2727
#include "FX.h"
2828
#include "palettes.h"
2929

30-
//enable custom per-LED mapping. This can allow for better effects on matrices or special displays
31-
/*
32-
//this is just an example (30 LEDs). It will first set all even, then all uneven LEDs.
33-
const uint16_t customMappingTable[] = {
34-
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28,
35-
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29};
36-
37-
//another example. Switches direction every 5 LEDs.
38-
const uint16_t customMappingTable[] = {
39-
0, 1, 2, 3, 4, 9, 8, 7, 6, 5, 10, 11, 12, 13, 14,
40-
19, 18, 17, 16, 15, 20, 21, 22, 23, 24, 29, 28, 27, 26, 25};
41-
42-
const uint16_t customMappingSize = sizeof(customMappingTable)/sizeof(uint16_t); //30 in example
43-
*/
44-
uint16_t* customMappingTable = nullptr;
45-
uint16_t customMappingSize = 0;
46-
4730
#ifndef PWM_INDEX
4831
#define PWM_INDEX 0
4932
#endif
5033

51-
void WS2812FX::deserializeMap(void) {
52-
DynamicJsonDocument doc(JSON_BUFFER_SIZE); // full sized buffer for larger maps
53-
54-
DEBUG_PRINTLN(F("Reading LED map from /ledmap.json..."));
34+
/*
35+
Custom per-LED mapping has moved!
5536
56-
if (!readObjectFromFile("/ledmap.json", nullptr, &doc)) return; //if file does not exist just exit
37+
Create a file "ledmap.json" using the edit page.
5738
58-
if (customMappingTable != nullptr) {
59-
delete[] customMappingTable;
60-
customMappingTable = nullptr;
61-
customMappingSize = 0;
62-
}
63-
64-
JsonArray map = doc[F("map")];
65-
if (!map.isNull() && map.size()) { // not an empty map
66-
customMappingSize = map.size();
67-
customMappingTable = new uint16_t[customMappingSize];
68-
for (uint16_t i=0; i<customMappingSize; i++) {
69-
customMappingTable[i] = (uint16_t) map[i];
70-
}
71-
}
72-
}
39+
this is just an example (30 LEDs). It will first set all even, then all uneven LEDs.
40+
{"map":[
41+
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28,
42+
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]}
7343
44+
another example. Switches direction every 5 LEDs.
45+
{"map":[
46+
0, 1, 2, 3, 4, 9, 8, 7, 6, 5, 10, 11, 12, 13, 14,
47+
19, 18, 17, 16, 15, 20, 21, 22, 23, 24, 29, 28, 27, 26, 25]
48+
*/
7449

7550
void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
7651
{
@@ -1026,6 +1001,31 @@ void WS2812FX::setRgbwPwm(void) {
10261001
void WS2812FX::setRgbwPwm() {}
10271002
#endif
10281003

1004+
//load custom mapping table from JSON file
1005+
void WS2812FX::deserializeMap(void) {
1006+
if (!WLED_FS.exists("/ledmap.json")) return;
1007+
DynamicJsonDocument doc(JSON_BUFFER_SIZE); // full sized buffer for larger maps
1008+
1009+
DEBUG_PRINTLN(F("Reading LED map from /ledmap.json..."));
1010+
1011+
if (!readObjectFromFile("/ledmap.json", nullptr, &doc)) return; //if file does not exist just exit
1012+
1013+
if (customMappingTable != nullptr) {
1014+
delete[] customMappingTable;
1015+
customMappingTable = nullptr;
1016+
customMappingSize = 0;
1017+
}
1018+
1019+
JsonArray map = doc[F("map")];
1020+
if (!map.isNull() && map.size()) { // not an empty map
1021+
customMappingSize = map.size();
1022+
customMappingTable = new uint16_t[customMappingSize];
1023+
for (uint16_t i=0; i<customMappingSize; i++) {
1024+
customMappingTable[i] = (uint16_t) map[i];
1025+
}
1026+
}
1027+
}
1028+
10291029
//gamma 2.8 lookup table used for color correction
10301030
byte gammaT[] = {
10311031
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0 commit comments

Comments
 (0)