From 24fda89665819fc480fdec356190160ac7f72ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Mon, 25 Jul 2022 14:36:54 +0200 Subject: [PATCH] Defaults cleanup. --- wled00/json.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wled00/json.cpp b/wled00/json.cpp index f054f46f..35599862 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -179,7 +179,15 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) // load default values from effect string if effect is selected without // any other effect parameter (i.e. effect clicked in UI) - if (elem[F("sx")].isNull() && elem[F("ix")].isNull() && elem["pal"].isNull() && elem[F("c1")].isNull() && elem[F("c2")].isNull() && elem[F("c3")].isNull()) { + if (!elem["fx"].isNull() // effect must not be empty + && elem[F("sx")].isNull() + && elem[F("ix")].isNull() + && elem["pal"].isNull() + && elem[F("c1")].isNull() + && elem[F("c2")].isNull() + && elem[F("c3")].isNull()) + { + // compatibility mode begin char buf[5]; // dummy buffer for (int i=0; i<5; i++) { uint8_t *var; @@ -193,19 +201,20 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId) extractModeSlider(fx, i, buf, 4, var); } extractModeSlider(fx, 255, buf, 4, &seg.palette); + //end compatibility mode int16_t sOpt; sOpt = extractModeDefaults(fx, SET_F("sx")); if (sOpt >= 0) seg.speed = sOpt; sOpt = extractModeDefaults(fx, SET_F("ix")); if (sOpt >= 0) seg.intensity = sOpt; sOpt = extractModeDefaults(fx, SET_F("c1")); if (sOpt >= 0) seg.custom1 = sOpt; sOpt = extractModeDefaults(fx, SET_F("c2")); if (sOpt >= 0) seg.custom2 = sOpt; sOpt = extractModeDefaults(fx, SET_F("c3")); if (sOpt >= 0) seg.custom3 = sOpt; - sOpt = extractModeDefaults(fx, "pal"); if (sOpt >= 0) seg.palette = sOpt; + sOpt = extractModeDefaults(fx, "pal"); if (sOpt >= 0 && sOpt < strip.getPaletteCount()) seg.palette = sOpt; sOpt = extractModeDefaults(fx, SET_F("mp12")); if (sOpt >= 0) seg.map1D2D = sOpt & 0x03; sOpt = extractModeDefaults(fx, SET_F("ssim")); if (sOpt >= 0) seg.soundSim = sOpt & 0x07; - sOpt = extractModeDefaults(fx, "rev"); if (sOpt >= 0) seg.setOption(SEG_OPTION_REVERSED, (bool)sOpt); - sOpt = extractModeDefaults(fx, SET_F("mi")); if (sOpt >= 0) seg.setOption(SEG_OPTION_MIRROR, (bool)sOpt); - sOpt = extractModeDefaults(fx, SET_F("rY")); if (sOpt >= 0) seg.setOption(SEG_OPTION_REVERSED_Y, (bool)sOpt); - sOpt = extractModeDefaults(fx, SET_F("mY")); if (sOpt >= 0) seg.setOption(SEG_OPTION_MIRROR_Y, (bool)sOpt); + sOpt = extractModeDefaults(fx, "rev"); if (sOpt >= 0) seg.reverse = (bool)sOpt; // setOption(SEG_OPTION_REVERSED, (bool)sOpt); // NOTE: setting this option is a risky business + sOpt = extractModeDefaults(fx, SET_F("mi")); if (sOpt >= 0) seg.mirror = (bool)sOpt; // setOption(SEG_OPTION_MIRROR, (bool)sOpt); // NOTE: setting this option is a risky business + sOpt = extractModeDefaults(fx, SET_F("rY")); if (sOpt >= 0) seg.reverse_y = (bool)sOpt; // setOption(SEG_OPTION_REVERSED_Y, (bool)sOpt); // NOTE: setting this option is a risky business + sOpt = extractModeDefaults(fx, SET_F("mY")); if (sOpt >= 0) seg.mirror_y = (bool)sOpt; // setOption(SEG_OPTION_MIRROR_Y, (bool)sOpt); // NOTE: setting this option is a risky business } //getVal also supports inc/decrementing and random