|
27 | 27 | #include "FX.h" |
28 | 28 | #include "palettes.h" |
29 | 29 |
|
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 | | - |
47 | 30 | #ifndef PWM_INDEX |
48 | 31 | #define PWM_INDEX 0 |
49 | 32 | #endif |
50 | 33 |
|
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! |
55 | 36 |
|
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. |
57 | 38 |
|
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]} |
73 | 43 |
|
| 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 | +*/ |
74 | 49 |
|
75 | 50 | void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst) |
76 | 51 | { |
@@ -1026,6 +1001,31 @@ void WS2812FX::setRgbwPwm(void) { |
1026 | 1001 | void WS2812FX::setRgbwPwm() {} |
1027 | 1002 | #endif |
1028 | 1003 |
|
| 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 | + |
1029 | 1029 | //gamma 2.8 lookup table used for color correction |
1030 | 1030 | byte gammaT[] = { |
1031 | 1031 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
0 commit comments