Skip to content

Commit

Permalink
Clean up UserMod settings: grouping of variables and add preInfo to v…
Browse files Browse the repository at this point in the history
…ariables (Aircoookie#2894)

* Grouping um settings, add pre and post Info, update  SR & 4LD settings

Settings_um.htm: 
- modify addField (grouping)
- addInfo (pre and post texts)

Add preInfo to audio reactive and 4ld usermod

Extra:
platformio: wemos_shield: add audio reactive usermod and update to alt display

* um settings: cpp: lowercase, js: initcap

* um settings: txt only pre, txt2 only post and initCap as function

* Fix rotary encoder info string

Co-authored-by: Blaž Kristan <[email protected]>
  • Loading branch information
ewoudwijma and blazoncek authored Nov 26, 2022
1 parent f03abf2 commit 78e9f5b
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 199 deletions.
3 changes: 3 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,12 @@ build_flags = ${common.build_flags_esp32}
-D USERMOD_DALLASTEMPERATURE
-D USERMOD_FOUR_LINE_DISPLAY
-D TEMPERATURE_PIN=23
-D USE_ALT_DISPlAY ; new versions of USERMOD_FOUR_LINE_DISPLAY and USERMOD_ROTARY_ENCODER_UI
-D USERMOD_AUDIOREACTIVE
lib_deps = ${esp32.lib_deps}
OneWire@~2.3.5
olikraus/U8g2 @ ^2.28.8
https://github.com/blazoncek/arduinoFFT.git
board_build.partitions = ${esp32.default_partitions}

[env:m5atom]
Expand Down
52 changes: 26 additions & 26 deletions usermods/audioreactive/audio_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -1554,18 +1554,18 @@ class AudioReactive : public Usermod {
pinArray.add(sdaPin);
pinArray.add(sclPin);

JsonObject cfg = top.createNestedObject("cfg");
JsonObject cfg = top.createNestedObject("config");
cfg[F("squelch")] = soundSquelch;
cfg[F("gain")] = sampleGain;
cfg[F("AGC")] = soundAgc;

JsonObject dynLim = top.createNestedObject("dynamics");
dynLim[F("Limiter")] = limiterOn;
dynLim[F("Rise")] = attackTime;
dynLim[F("Fall")] = decayTime;
dynLim[F("limiter")] = limiterOn;
dynLim[F("rise")] = attackTime;
dynLim[F("fall")] = decayTime;

JsonObject freqScale = top.createNestedObject("Frequency");
freqScale[F("Scale")] = FFTScalingMode;
JsonObject freqScale = top.createNestedObject("frequency");
freqScale[F("scale")] = FFTScalingMode;

JsonObject sync = top.createNestedObject("sync");
sync[F("port")] = audioSyncPort;
Expand Down Expand Up @@ -1605,15 +1605,15 @@ class AudioReactive : public Usermod {
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][4], sdaPin);
configComplete &= getJsonValue(top[FPSTR(_digitalmic)]["pin"][5], sclPin);

configComplete &= getJsonValue(top["cfg"][F("squelch")], soundSquelch);
configComplete &= getJsonValue(top["cfg"][F("gain")], sampleGain);
configComplete &= getJsonValue(top["cfg"][F("AGC")], soundAgc);
configComplete &= getJsonValue(top["config"][F("squelch")], soundSquelch);
configComplete &= getJsonValue(top["config"][F("gain")], sampleGain);
configComplete &= getJsonValue(top["config"][F("AGC")], soundAgc);

configComplete &= getJsonValue(top["dynamics"][F("Limiter")], limiterOn);
configComplete &= getJsonValue(top["dynamics"][F("Rise")], attackTime);
configComplete &= getJsonValue(top["dynamics"][F("Fall")], decayTime);
configComplete &= getJsonValue(top["dynamics"][F("limiter")], limiterOn);
configComplete &= getJsonValue(top["dynamics"][F("rise")], attackTime);
configComplete &= getJsonValue(top["dynamics"][F("fall")], decayTime);

configComplete &= getJsonValue(top["Frequency"][F("Scale")], FFTScalingMode);
configComplete &= getJsonValue(top["frequency"][F("scale")], FFTScalingMode);

configComplete &= getJsonValue(top["sync"][F("port")], audioSyncPort);
configComplete &= getJsonValue(top["sync"][F("mode")], audioSyncEnabled);
Expand All @@ -1635,20 +1635,20 @@ class AudioReactive : public Usermod {
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
oappend(SET_F("addOption(dd,'Generic I2S PDM',5);"));
#endif
oappend(SET_F("dd=addDropdown('AudioReactive','cfg:AGC');"));
oappend(SET_F("dd=addDropdown('AudioReactive','config:AGC');"));
oappend(SET_F("addOption(dd,'Off',0);"));
oappend(SET_F("addOption(dd,'Normal',1);"));
oappend(SET_F("addOption(dd,'Vivid',2);"));
oappend(SET_F("addOption(dd,'Lazy',3);"));

oappend(SET_F("dd=addDropdown('AudioReactive','dynamics:Limiter');"));
oappend(SET_F("dd=addDropdown('AudioReactive','dynamics:limiter');"));
oappend(SET_F("addOption(dd,'Off',0);"));
oappend(SET_F("addOption(dd,'On',1);"));
oappend(SET_F("addInfo('AudioReactive:dynamics:Limiter',0,' On ');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('AudioReactive:dynamics:Rise',1,'ms <i>(&#x266A; effects only)</i>');"));
oappend(SET_F("addInfo('AudioReactive:dynamics:Fall',1,'ms <i>(&#x266A; effects only)</i>');"));
oappend(SET_F("addInfo('AudioReactive:dynamics:limiter',0,' On ');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('AudioReactive:dynamics:rise',1,'ms <i>(&#x266A; effects only)</i>');"));
oappend(SET_F("addInfo('AudioReactive:dynamics:fall',1,'ms <i>(&#x266A; effects only)</i>');"));

oappend(SET_F("dd=addDropdown('AudioReactive','Frequency:Scale');"));
oappend(SET_F("dd=addDropdown('AudioReactive','frequency:scale');"));
oappend(SET_F("addOption(dd,'None',0);"));
oappend(SET_F("addOption(dd,'Linear (Amplitude)',2);"));
oappend(SET_F("addOption(dd,'Square Root (Energy)',3);"));
Expand All @@ -1659,16 +1659,16 @@ class AudioReactive : public Usermod {
oappend(SET_F("addOption(dd,'Send',1);"));
oappend(SET_F("addOption(dd,'Receive',2);"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:type',1,'<i>requires reboot!</i>');")); // 0 is field type, 1 is actual field
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'I2S SD');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'I2S WS');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'I2S SCK');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',0,'I2S Serial Data', '<i><span class=\"h\">sd/data/dout</span></i>');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',1,'I2S L/R Clock','<i><span class=\"h\">ws/clk/lrck</span></i>');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',2,'I2S Serial Clock','<i>sck/bclk</i>');"));
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK <i>only use -1, 0, 1 or 3 for MCLK</i>');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK','<i>only use -1, 0, 1 or 3</i>');"));
#else
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'I2S Master CLK');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',3,'', 'I2S Master CLK');"));
#endif
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'I2C SDA');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'I2C SCL');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'', 'I2C SDA');"));
oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'', 'I2C SCL');"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,11 +1032,11 @@ class FourLineDisplayUsermod : public Usermod {
oappend(SET_F("addOption(dd,'SSD1305 128x64',5);"));
oappend(SET_F("addOption(dd,'SSD1306 SPI',6);"));
oappend(SET_F("addOption(dd,'SSD1306 SPI 128x64',7);"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'I2C/SPI CLK (-1 use global)');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'I2C/SPI DTA (-1 use global)');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'SPI CS');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'SPI DC');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'SPI RST');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',0,'<i>-1 use global</i>','I2C/SPI CLK');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'<i>-1 use global</i>','I2C/SPI DTA');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',2,'','SPI CS');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',3,'','SPI DC');"));
oappend(SET_F("addInfo('4LineDisplay:pin[]',4,'','SPI RST');"));
}

/*
Expand Down
15 changes: 11 additions & 4 deletions wled00/data/settings_um.htm
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@
}
}
}
function initCap(s) {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
function addField(k,f,o,a=false) { //key, field, (sub)object, isArray
if (isO(o)) {
urows += '<hr class="sml">';
if (f!=='unknown' && !k.includes(":")) urows += `<p><u>${initCap(f)}</u></p>`; //show group title
for (const [s,v] of Object.entries(o)) {
// possibility to nest objects (only 1 level)
if (f!=='unknown' && !k.includes(":")) addField(k+":"+f,s,v);
Expand Down Expand Up @@ -135,8 +140,7 @@
t = "text"; c = `value="${o}" style="width:250px;"`;
break;
}
if (k.includes(":")) urows += k.substr(k.indexOf(":")+1);
urows += ` ${f}: `;
urows += ` ${initCap(f)} `; //only show field (key is shown in grouping)
// https://stackoverflow.com/questions/11657123/posting-both-checked-and-unchecked-checkboxes
if (t=="checkbox") urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="false">`;
else if (!a) urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="${t}">`;
Expand Down Expand Up @@ -179,11 +183,14 @@
}
}
// https://stackoverflow.com/questions/26440494/insert-text-after-this-input-element-with-javascript
function addInfo(name,el,txt) {
function addInfo(name,el,txt, txt2="") {
let obj = d.getElementsByName(name);
if (!obj.length) return;
if (typeof el === "string" && obj[0]) obj[0].placeholder = el;
else if (obj[el]) obj[el].insertAdjacentHTML('afterend', '&nbsp;'+txt);
else if (obj[el]) {
if (txt!="") obj[el].insertAdjacentHTML('afterend', '&nbsp;'+txt);
if (txt2!="") obj[el].insertAdjacentHTML('beforebegin', txt2 + '&nbsp;'); //add pre texts
}
}
// load settings and insert values into DOM
function ldS() {
Expand Down
Loading

0 comments on commit 78e9f5b

Please sign in to comment.