Added multiple ledmaps, selectable via JSON API.

This commit is contained in:
Blaz Kristan 2021-04-04 13:54:34 +02:00
parent a52386e6ad
commit 89543e927a
4 changed files with 30 additions and 10 deletions

View File

@ -603,7 +603,8 @@ class WS2812FX {
setPixelColor(uint16_t n, uint32_t c),
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
show(void),
setPixelSegment(uint8_t n);
setPixelSegment(uint8_t n),
deserializeMap(uint8_t n=0);
bool
isRgbw = false,
@ -835,8 +836,7 @@ class WS2812FX {
void
blendPixelColor(uint16_t n, uint32_t color, uint8_t blend),
startTransition(uint8_t oldBri, uint32_t oldCol, uint16_t dur, uint8_t segn, uint8_t slot),
deserializeMap(void);
startTransition(uint8_t oldBri, uint32_t oldCol, uint16_t dur, uint8_t segn, uint8_t slot);
uint16_t* customMappingTable = nullptr;
uint16_t customMappingSize = 0;

View File

@ -995,18 +995,33 @@ bool WS2812FX::segmentsAreIdentical(Segment* a, Segment* b)
//load custom mapping table from JSON file
void WS2812FX::deserializeMap(void) {
if (!WLED_FS.exists("/ledmap.json")) return;
void WS2812FX::deserializeMap(uint8_t n) {
String fileName = String("/ledmap");
if (n) fileName += String(n);
fileName += String(".json");
bool isFile = WLED_FS.exists(fileName);
if (!isFile) {
// erase custom mapping if selecting nonexistent ledmap.json (n==0)
if (!n && customMappingTable != nullptr) {
customMappingSize = 0;
delete[] customMappingTable;
customMappingTable = nullptr;
}
return;
}
DynamicJsonDocument doc(JSON_BUFFER_SIZE); // full sized buffer for larger maps
DEBUG_PRINT(F("Reading LED map from "));
DEBUG_PRINTLN(fileName);
DEBUG_PRINTLN(F("Reading LED map from /ledmap.json..."));
if (!readObjectFromFile("/ledmap.json", nullptr, &doc)) return; //if file does not exist just exit
if (!readObjectFromFile(fileName.c_str(), nullptr, &doc)) return; //if file does not exist just exit
// erase old custom ledmap
if (customMappingTable != nullptr) {
customMappingSize = 0;
delete[] customMappingTable;
customMappingTable = nullptr;
customMappingSize = 0;
}
JsonArray map = doc[F("map")];

View File

@ -269,6 +269,11 @@ bool deserializeState(JsonObject root)
usermods.readFromJsonState(root);
int8_t ledmap = root[F("ledmap")] | -1;
if (ledmap >= 0) {
strip.deserializeMap(ledmap);
}
int ps = root[F("psave")] | -1;
if (ps > 0) {
savePreset(ps, true, nullptr, root);

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2104031
#define VERSION 2104041
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG