From 8c759cb65a8cc4faa4be5ab2ac5c5651f011f160 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 11 Jun 2022 18:55:23 +0200 Subject: [PATCH] Usermod config info & data. --- usermods/audioreactive/audio_reactive.h | 22 ++ .../usermod_v2_four_line_display_ALT.h | 19 +- wled00/data/settings_um.htm | 40 +++ wled00/fcn_declare.h | 6 +- wled00/html_settings.h | 244 ++++++++++-------- wled00/um_manager.cpp | 7 +- wled00/xml.cpp | 1 + 7 files changed, 219 insertions(+), 120 deletions(-) diff --git a/usermods/audioreactive/audio_reactive.h b/usermods/audioreactive/audio_reactive.h index cf6aed2d5..aaac238c9 100644 --- a/usermods/audioreactive/audio_reactive.h +++ b/usermods/audioreactive/audio_reactive.h @@ -1185,6 +1185,28 @@ class AudioReactive : public Usermod { } + void appendConfigData() { + oappend(SET_F("dd=addDropdown('AudioReactive','digitalmic:type');")); + oappend(SET_F("addOption(dd,'Generic Analog',0);")); + oappend(SET_F("addOption(dd,'Generic I2S',1);")); + oappend(SET_F("addOption(dd,'ES7243',2);")); + oappend(SET_F("addOption(dd,'SPH0654',3);")); + oappend(SET_F("addOption(dd,'Generic I2S with Mclk',4);")); + oappend(SET_F("addOption(dd,'Generic I2S PDM',5);")); + oappend(SET_F("dd=addDropdown('AudioReactive','cfg: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("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[]',3,'I2S Master CLK');")); + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',4,'I2C SDA');")); + oappend(SET_F("addInfo('AudioReactive:digitalmic:pin[]',5,'I2C SCL');")); + } + + /* * handleOverlayDraw() is called just before every show() (LED strip update frame) after effects have set the colors. * Use this to blank out some LEDs or set them to a different color regardless of the set effect mode. diff --git a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h index 383accc52..05352613d 100644 --- a/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h +++ b/usermods/usermod_v2_four_line_display_ALT/usermod_v2_four_line_display_ALT.h @@ -941,6 +941,23 @@ class FourLineDisplayUsermod : public Usermod { // if (!initDone) return; // prevent crash on boot applyPreset() //} + void appendConfigData() { + oappend(SET_F("dd=addDropdown('4LineDisplay','type');")); + oappend(SET_F("addOption(dd,'None',0);")); + oappend(SET_F("addOption(dd,'SSD1306',1);")); + oappend(SET_F("addOption(dd,'SH1106',2);")); + oappend(SET_F("addOption(dd,'SSD1306 128x64',3);")); + oappend(SET_F("addOption(dd,'SSD1305',4);")); + 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');")); + oappend(SET_F("addInfo('4LineDisplay:pin[]',1,'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');")); + } + /* * addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object. * It will be called by WLED when settings are actually saved (for example, LED settings are saved) @@ -960,9 +977,7 @@ class FourLineDisplayUsermod : public Usermod { top[FPSTR(_enabled)] = enabled; JsonArray io_pin = top.createNestedArray("pin"); for (byte i=0; i<5; i++) io_pin.add(ioPin[i]); - top["help4Pins"] = F("Clk,Data,CS,DC,RST"); // help for Settings page top["type"] = type; - top["help4Type"] = F("1=SSD1306,2=SH1106,3=SSD1306_128x64,4=SSD1305,5=SSD1305_128x64,6=SSD1306_SPI,7=SSD1306_SPI_128x64"); // help for Settings page top[FPSTR(_flip)] = (bool) flip; top[FPSTR(_contrast)] = contrast; top[FPSTR(_contrastFix)] = (bool) contrastFix; diff --git a/wled00/data/settings_um.htm b/wled00/data/settings_um.htm index 646b068ab..1448fa73f 100644 --- a/wled00/data/settings_um.htm +++ b/wled00/data/settings_um.htm @@ -100,6 +100,46 @@ urows += `
`; } } + // https://stackoverflow.com/questions/39729741/javascript-change-input-text-to-select-option + function addDropdown(um,fld) { + let sel = d.createElement('select'); + let arr = d.getElementsByName(um+":"+fld); + let inp = arr[1]; // assume 1st field to be hidden (type) + if (inp && inp.tagName === "INPUT" && (inp.type === "text" || inp.type === "number")) { // may also use nodeName + let v = inp.value; + let n = inp.name; + // copy the existing input element's attributes to the new select element + for (var i = 0; i < inp.attributes.length; ++ i) { + var att = inp.attributes[i]; + // type and value don't apply, so skip them + // ** you might also want to skip style, or others -- modify as needed ** + if (att.name != 'type' && att.name != 'value' && att.name != 'class' && att.name != 'style') { + sel.setAttribute(att.name, att.value); + } + } + sel.setAttribute("data-val", v); + // finally, replace the old input element with the new select element + inp.parentElement.replaceChild(sel, inp); + return obj; + } + return null; + } + function addOption(sel,txt,val) { + if (sel===null) return; + let opt = d.createElement("option"); + opt.value = val; + opt.text = txt; + sel.appendChild(opt); + for (let i=0; isetup(); } +void UsermodManager::connected() { for (byte i = 0; i < numMods; i++) ums[i]->connected(); } void UsermodManager::loop() { for (byte i = 0; i < numMods; i++) ums[i]->loop(); } void UsermodManager::handleOverlayDraw() { for (byte i = 0; i < numMods; i++) ums[i]->handleOverlayDraw(); } +void UsermodManager::appendConfigData() { for (byte i = 0; i < numMods; i++) ums[i]->appendConfigData(); } bool UsermodManager::handleButton(uint8_t b) { bool overrideIO = false; for (byte i = 0; i < numMods; i++) { @@ -20,10 +23,6 @@ bool UsermodManager::getUMData(um_data_t **data, uint8_t mod_id) { } return false; } - -void UsermodManager::setup() { for (byte i = 0; i < numMods; i++) ums[i]->setup(); } -void UsermodManager::connected() { for (byte i = 0; i < numMods; i++) ums[i]->connected(); } - void UsermodManager::addToJsonState(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->addToJsonState(obj); } void UsermodManager::addToJsonInfo(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->addToJsonInfo(obj); } void UsermodManager::readFromJsonState(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->readFromJsonState(obj); } diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 2ebeb7acd..b621012fd 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -615,6 +615,7 @@ void getSettingsJS(byte subPage, char* dest) oappend(SET_F("numM=")); oappendi(usermods.getModCount()); oappend(";"); + usermods.appendConfigData(); } if (subPage == 9) // update