mirror of
https://github.com/wled/WLED.git
synced 2025-07-19 00:36:36 +00:00
Added multiple ledmaps, selectable via JSON API.
This commit is contained in:
parent
a52386e6ad
commit
89543e927a
@ -603,7 +603,8 @@ class WS2812FX {
|
|||||||
setPixelColor(uint16_t n, uint32_t c),
|
setPixelColor(uint16_t n, uint32_t c),
|
||||||
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
|
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
|
||||||
show(void),
|
show(void),
|
||||||
setPixelSegment(uint8_t n);
|
setPixelSegment(uint8_t n),
|
||||||
|
deserializeMap(uint8_t n=0);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
isRgbw = false,
|
isRgbw = false,
|
||||||
@ -835,8 +836,7 @@ class WS2812FX {
|
|||||||
|
|
||||||
void
|
void
|
||||||
blendPixelColor(uint16_t n, uint32_t color, uint8_t blend),
|
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),
|
startTransition(uint8_t oldBri, uint32_t oldCol, uint16_t dur, uint8_t segn, uint8_t slot);
|
||||||
deserializeMap(void);
|
|
||||||
|
|
||||||
uint16_t* customMappingTable = nullptr;
|
uint16_t* customMappingTable = nullptr;
|
||||||
uint16_t customMappingSize = 0;
|
uint16_t customMappingSize = 0;
|
||||||
|
@ -995,18 +995,33 @@ bool WS2812FX::segmentsAreIdentical(Segment* a, Segment* b)
|
|||||||
|
|
||||||
|
|
||||||
//load custom mapping table from JSON file
|
//load custom mapping table from JSON file
|
||||||
void WS2812FX::deserializeMap(void) {
|
void WS2812FX::deserializeMap(uint8_t n) {
|
||||||
if (!WLED_FS.exists("/ledmap.json")) return;
|
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
|
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(fileName.c_str(), nullptr, &doc)) return; //if file does not exist just exit
|
||||||
|
|
||||||
if (!readObjectFromFile("/ledmap.json", nullptr, &doc)) return; //if file does not exist just exit
|
|
||||||
|
|
||||||
|
// erase old custom ledmap
|
||||||
if (customMappingTable != nullptr) {
|
if (customMappingTable != nullptr) {
|
||||||
|
customMappingSize = 0;
|
||||||
delete[] customMappingTable;
|
delete[] customMappingTable;
|
||||||
customMappingTable = nullptr;
|
customMappingTable = nullptr;
|
||||||
customMappingSize = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray map = doc[F("map")];
|
JsonArray map = doc[F("map")];
|
||||||
|
@ -269,6 +269,11 @@ bool deserializeState(JsonObject root)
|
|||||||
|
|
||||||
usermods.readFromJsonState(root);
|
usermods.readFromJsonState(root);
|
||||||
|
|
||||||
|
int8_t ledmap = root[F("ledmap")] | -1;
|
||||||
|
if (ledmap >= 0) {
|
||||||
|
strip.deserializeMap(ledmap);
|
||||||
|
}
|
||||||
|
|
||||||
int ps = root[F("psave")] | -1;
|
int ps = root[F("psave")] | -1;
|
||||||
if (ps > 0) {
|
if (ps > 0) {
|
||||||
savePreset(ps, true, nullptr, root);
|
savePreset(ps, true, nullptr, root);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// 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
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user