Merge pull request #2841 from Aircoookie/0_14

Merge 0.14 to main
This commit is contained in:
Christian Schwinne 2022-10-20 00:51:59 +02:00 committed by GitHub
commit d7f6cd944c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
130 changed files with 42453 additions and 10415 deletions

3
.github/FUNDING.yml vendored
View File

@ -1,2 +1,5 @@
github: [Aircoookie] github: [Aircoookie]
custom: ['https://paypal.me/Aircoookie'] custom: ['https://paypal.me/Aircoookie']
github: [blazoncek]
custom: ['https://paypal.me/blazoncek']

5
.gitignore vendored
View File

@ -3,7 +3,6 @@
.pioenvs .pioenvs
.piolibdeps .piolibdeps
.vscode .vscode
!.vscode/extensions.json
/wled00/Release /wled00/Release
/wled00/extLibs /wled00/extLibs
/platformio_override.ini /platformio_override.ini
@ -15,3 +14,7 @@
node_modules node_modules
.idea .idea
.direnv .direnv
wled-update.sh
esp01-update.sh
/wled00/LittleFS
replace_fs.py

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "wled", "name": "wled",
"version": "0.13.3", "version": "0.14.0-b0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "wled", "name": "wled",
"version": "0.13.3", "version": "0.14.0-b0",
"description": "Tools for WLED project", "description": "Tools for WLED project",
"main": "tools/cdata.js", "main": "tools/cdata.js",
"directories": { "directories": {

View File

@ -56,14 +56,14 @@ extra_configs =
arduino_core_2_6_3 = espressif8266@2.3.3 arduino_core_2_6_3 = espressif8266@2.3.3
arduino_core_2_7_4 = espressif8266@2.6.2 arduino_core_2_7_4 = espressif8266@2.6.2
arduino_core_3_0_0 = espressif8266@3.0.0 arduino_core_3_0_0 = espressif8266@3.0.0
arduino_core_3_0_2 = espressif8266@3.2.0 arduino_core_3_2_0 = espressif8266@3.2.0
# Development platforms # Development platforms
arduino_core_develop = https://github.com/platformio/platform-espressif8266#develop arduino_core_develop = https://github.com/platformio/platform-espressif8266#develop
arduino_core_git = https://github.com/platformio/platform-espressif8266#feature/stage arduino_core_git = https://github.com/platformio/platform-espressif8266#feature/stage
# Platform to use for ESP8266 # Platform to use for ESP8266
platform_wled_default = ${common.arduino_core_2_7_4} platform_wled_default = ${common.arduino_core_3_2_0}
# We use 2.7.4.7 for all, includes PWM flicker fix and Wstring optimization # We use 2.7.4.7 for all, includes PWM flicker fix and Wstring optimization
platform_packages = tasmota/framework-arduinoespressif8266 @ 3.20704.7 platform_packages = tasmota/framework-arduinoespressif8266 @ 3.20704.7
platformio/toolchain-xtensa @ ~2.40802.200502 platformio/toolchain-xtensa @ ~2.40802.200502
@ -163,11 +163,12 @@ lib_compat_mode = strict
lib_deps = lib_deps =
fastled/FastLED @ 3.5.0 fastled/FastLED @ 3.5.0
IRremoteESP8266 @ 2.8.2 IRremoteESP8266 @ 2.8.2
https://github.com/Aircoookie/ESPAsyncWebServer.git @ ~2.0.4 https://github.com/Aircoookie/ESPAsyncWebServer.git @ ~2.0.7
#For use of the TTGO T-Display ESP32 Module with integrated TFT display uncomment the following line #For use of the TTGO T-Display ESP32 Module with integrated TFT display uncomment the following line
#TFT_eSPI #TFT_eSPI
#For use SSD1306 OLED display uncomment following #For use SSD1306 OLED display uncomment following
#U8g2@~2.27.2 #U8g2@~2.28.8
#U8g2@~2.32.10
#For Dallas sensor uncomment following 2 lines #For Dallas sensor uncomment following 2 lines
#OneWire@~2.3.5 #OneWire@~2.3.5
#milesburton/DallasTemperature@^3.9.0 #milesburton/DallasTemperature@^3.9.0
@ -184,8 +185,8 @@ build_flags =
-DESP8266 -DESP8266
-DFP_IN_IROM -DFP_IN_IROM
;-Wno-deprecated-declarations ;-Wno-deprecated-declarations
-Wno-register ;-Wno-register
-Wno-misleading-indentation ;-Wno-misleading-indentation
; NONOSDK22x_190703 = 2.2.2-dev(38a443e) ; NONOSDK22x_190703 = 2.2.2-dev(38a443e)
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_190703 -DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_190703
; lwIP 2 - Higher Bandwidth no Features ; lwIP 2 - Higher Bandwidth no Features
@ -251,6 +252,23 @@ lib_deps =
makuna/NeoPixelBus @ 2.6.9 makuna/NeoPixelBus @ 2.6.9
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0 https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
[esp32s3]
;; generic definitions for all ESP32-S3 boards
build_flags = -g
-DESP32
-DARDUINO_ARCH_ESP32
-DARDUINO_ARCH_ESP32S3
-DCONFIG_IDF_TARGET_ESP32S3
-D CONFIG_ASYNC_TCP_USE_WDT=0
-DCO
lib_deps =
${env.lib_deps}
;; currently we need the latest NeoPixelBus dev version, because it contains important bugfixes for -S3
https://github.com/Makuna/NeoPixelBus.git#master @ 2.7.0
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# WLED BUILDS # WLED BUILDS
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -263,6 +281,7 @@ board_build.ldscript = ${common.ldscript_4m1m}
build_unflags = ${common.build_unflags} build_unflags = ${common.build_unflags}
build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266 build_flags = ${common.build_flags_esp8266} -D WLED_RELEASE_NAME=ESP8266
lib_deps = ${esp8266.lib_deps} lib_deps = ${esp8266.lib_deps}
monitor_filters = esp8266_exception_decoder
[env:esp8266_2m] [env:esp8266_2m]
board = esp_wroom_02 board = esp_wroom_02
@ -364,15 +383,30 @@ build_unflags = ${common.build_unflags}
lib_deps = ${esp32s2.lib_deps} lib_deps = ${esp32s2.lib_deps}
[env:esp32c3] [env:esp32c3]
board = esp32-c3-devkitm-1 platform = espressif32@5.1.1
platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2/platform-tasmota-espressif32-2.0.2.zip
platform_packages =
framework = arduino framework = arduino
board = esp32-c3-devkitm-1
board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
build_flags = ${common.build_flags} ${esp32c3.build_flags} #-D WLED_RELEASE_NAME=ESP32-C3
-D WLED_WATCHDOG_TIMEOUT=0
upload_speed = 460800 upload_speed = 460800
build_unflags = ${common.build_unflags} build_unflags = ${common.build_unflags}
lib_deps = ${esp32c3.lib_deps} lib_deps = ${esp32c3.lib_deps}
[env:esp32s3dev_8MB]
;; ESP32-S3-DevKitC-1 development board, with 8MB FLASH, no PSRAM
board = esp32-s3-devkitc-1
platform = espressif32@5.1.1
platform_packages = platformio/framework-arduinoespressif32@3.20004.220825
upload_speed = 921600
build_unflags = ${common.build_unflags}
build_flags = ${common.build_flags} ${esp32s3.build_flags} -D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=0 -D ARDUINO_USB_MSC_ON_BOOT=0
lib_deps = ${esp32s3.lib_deps}
board_build.partitions = tools/WLED_ESP32_8MB.csv
board_build.f_flash = 80000000L
board_build.flash_mode = qio
monitor_filters = esp32_exception_decoder
[env:esp8285_4CH_MagicHome] [env:esp8285_4CH_MagicHome]
board = esp8285 board = esp8285
platform = ${common.platform_wled_default} platform = ${common.platform_wled_default}
@ -435,6 +469,29 @@ build_unflags = ${common.build_unflags}
build_flags = ${common.build_flags_esp8266} -D LEDPIN=12 -D IRPIN=-1 -D RLYPIN=2 build_flags = ${common.build_flags_esp8266} -D LEDPIN=12 -D IRPIN=-1 -D RLYPIN=2
lib_deps = ${esp8266.lib_deps} lib_deps = ${esp8266.lib_deps}
[env:lolin_s2_mini]
platform = espressif32@5.1.1
board = lolin_s2_mini
board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
build_unflags = ${common.build_unflags}
build_flags = ${common.build_flags} ${esp32s2.build_flags} #-D WLED_RELEASE_NAME=LolinS2
-DBOARD_HAS_PSRAM
-D ARDUINO_USB_CDC_ON_BOOT
-D WLED_USE_PSRAM
-D WLED_WATCHDOG_TIMEOUT=0
-D CONFIG_ASYNC_TCP_USE_WDT=0
-D LEDPIN=16
-D BTNPIN=18
-D RLYPIN=9
-D IRPIN=7
-D HW_PIN_SCL=35
-D HW_PIN_SDA=33
-D HW_PIN_CLOCKSPI=7
-D HW_PIN_DATASPI=11
-D HW_PIN_MISOSPI=9
; -D STATUSLED=15
lib_deps = ${esp32s2.lib_deps}
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# custom board configurations # custom board configurations
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------

View File

@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x180000,
app1, app, ota_1, 0x190000,0x180000,
spiffs, data, spiffs, 0x310000,0xF0000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x5000
3 otadata data ota 0xe000 0x2000
4 app0 app ota_0 0x10000 0x180000
5 app1 app ota_1 0x190000 0x180000
6 spiffs data spiffs 0x310000 0xF0000

View File

@ -16,21 +16,32 @@
*/ */
const fs = require("fs"); const fs = require("fs");
const inliner = require("inliner");
const zlib = require("zlib");
const CleanCSS = require("clean-css");
const MinifyHTML = require("html-minifier-terser").minify;
const packageJson = require("../package.json"); const packageJson = require("../package.json");
/** /**
* *
*/ */
function hexdump(buffer) { function hexdump(buffer,isHex=false) {
let lines = []; let lines = [];
for (let i = 0; i < buffer.length; i += 16) { for (let i = 0; i < buffer.length; i +=(isHex?32:16)) {
let block = buffer.slice(i, i + 16); // cut buffer into blocks of 16 var block;
let hexArray = []; let hexArray = [];
if (isHex) {
block = buffer.slice(i, i + 32)
for (let j = 0; j < block.length; j +=2 ) {
hexArray.push("0x" + block.slice(j,j+2))
}
} else {
block = buffer.slice(i, i + 16); // cut buffer into blocks of 16
for (let value of block) { for (let value of block) {
hexArray.push("0x" + value.toString(16).padStart(2, "0")); hexArray.push("0x" + value.toString(16).padStart(2, "0"));
} }
}
let hexString = hexArray.join(", "); let hexString = hexArray.join(", ");
let line = ` ${hexString}`; let line = ` ${hexString}`;
@ -40,9 +51,6 @@ function hexdump(buffer) {
return lines.join(",\n"); return lines.join(",\n");
} }
const inliner = require("inliner");
const zlib = require("zlib");
function strReplace(str, search, replacement) { function strReplace(str, search, replacement) {
return str.split(search).join(replacement); return str.split(search).join(replacement);
} }
@ -56,16 +64,52 @@ function adoptVersionAndRepo(html) {
html = strReplace(html, "https://github.com/atuline/WLED", repoUrl); html = strReplace(html, "https://github.com/atuline/WLED", repoUrl);
html = strReplace(html, "https://github.com/Aircoookie/WLED", repoUrl); html = strReplace(html, "https://github.com/Aircoookie/WLED", repoUrl);
} }
let version = packageJson.version; let version = packageJson.version;
if (version) { if (version) {
html = strReplace(html, "##VERSION##", version); html = strReplace(html, "##VERSION##", version);
} }
return html; return html;
} }
function writeHtmlGzipped(sourceFile, resultFile) { function filter(str, type) {
str = adoptVersionAndRepo(str);
if (type === undefined) {
return str;
} else if (type == "css-minify") {
return new CleanCSS({}).minify(str).styles;
} else if (type == "js-minify") {
return MinifyHTML('<script>' + str + '</script>', {
collapseWhitespace: true,
minifyJS: true,
continueOnParseError: false,
removeComments: true,
}).replace(/<[\/]*script>/g,'');
} else if (type == "html-minify") {
return MinifyHTML(str, {
collapseWhitespace: true,
maxLineLength: 80,
minifyCSS: true,
minifyJS: true,
continueOnParseError: false,
removeComments: true,
});
} else if (type == "html-minify-ui") {
return MinifyHTML(str, {
collapseWhitespace: true,
conservativeCollapse: true,
maxLineLength: 80,
minifyCSS: true,
minifyJS: true,
continueOnParseError: false,
removeComments: true,
});
} else {
console.warn("Unknown filter: " + type);
return str;
}
}
function writeHtmlGzipped(sourceFile, resultFile, page) {
console.info("Reading " + sourceFile); console.info("Reading " + sourceFile);
new inliner(sourceFile, function (error, html) { new inliner(sourceFile, function (error, html) {
console.info("Inlined " + html.length + " characters"); console.info("Inlined " + html.length + " characters");
@ -95,8 +139,8 @@ function writeHtmlGzipped(sourceFile, resultFile) {
*/ */
// Autogenerated from ${sourceFile}, do not edit!! // Autogenerated from ${sourceFile}, do not edit!!
const uint16_t PAGE_index_L = ${result.length}; const uint16_t PAGE_${page}_L = ${result.length};
const uint8_t PAGE_index[] PROGMEM = { const uint8_t PAGE_${page}[] PROGMEM = {
${array} ${array}
}; };
`; `;
@ -106,41 +150,6 @@ ${array}
}); });
} }
const CleanCSS = require("clean-css");
const MinifyHTML = require("html-minifier-terser").minify;
function filter(str, type) {
str = adoptVersionAndRepo(str);
if (type === undefined) {
return str;
} else if (type == "css-minify") {
return new CleanCSS({}).minify(str).styles;
} else if (type == "html-minify") {
return MinifyHTML(str, {
collapseWhitespace: true,
maxLineLength: 80,
minifyCSS: true,
minifyJS: true,
continueOnParseError: false,
removeComments: true,
});
} else if (type == "html-minify-ui") {
return MinifyHTML(str, {
collapseWhitespace: true,
conservativeCollapse: true,
maxLineLength: 80,
minifyCSS: true,
minifyJS: true,
continueOnParseError: false,
removeComments: true,
});
} else {
console.warn("Unknown filter: " + type);
return str;
}
}
function specToChunk(srcDir, s) { function specToChunk(srcDir, s) {
if (s.method == "plaintext") { if (s.method == "plaintext") {
const buf = fs.readFileSync(srcDir + "/" + s.file); const buf = fs.readFileSync(srcDir + "/" + s.file);
@ -153,6 +162,21 @@ const char ${s.name}[] PROGMEM = R"${s.prepend || ""}${filter(str, s.filter)}${
`; `;
return s.mangle ? s.mangle(chunk) : chunk; return s.mangle ? s.mangle(chunk) : chunk;
} else if (s.method == "gzip") {
const buf = fs.readFileSync(srcDir + "/" + s.file);
var str = buf.toString('utf-8');
if (s.mangle) str = s.mangle(str);
const zip = zlib.gzipSync(filter(str, s.filter), { level: zlib.constants.Z_BEST_COMPRESSION });
const result = hexdump(zip.toString('hex'), true);
const chunk = `
// Autogenerated from ${srcDir}/${s.file}, do not edit!!
const uint16_t ${s.name}_length = ${zip.length};
const uint8_t ${s.name}[] PROGMEM = {
${result}
};
`;
return chunk;
} else if (s.method == "binary") { } else if (s.method == "binary") {
const buf = fs.readFileSync(srcDir + "/" + s.file); const buf = fs.readFileSync(srcDir + "/" + s.file);
const result = hexdump(buf); const result = hexdump(buf);
@ -164,7 +188,7 @@ ${result}
}; };
`; `;
return s.mangle ? s.mangle(chunk) : chunk; return chunk;
} else { } else {
console.warn("Unknown method: " + s.method); console.warn("Unknown method: " + s.method);
return undefined; return undefined;
@ -194,160 +218,111 @@ function writeChunks(srcDir, specs, resultFile) {
fs.writeFileSync(resultFile, src); fs.writeFileSync(resultFile, src);
} }
writeHtmlGzipped("wled00/data/index.htm", "wled00/html_ui.h"); writeHtmlGzipped("wled00/data/index.htm", "wled00/html_ui.h", 'index');
writeHtmlGzipped("wled00/data/simple.htm", "wled00/html_simple.h", 'simple');
/*
writeChunks(
"wled00/data",
[
{
file: "simple.css",
name: "PAGE_simpleCss",
method: "gzip",
filter: "css-minify",
},
{
file: "simple.js",
name: "PAGE_simpleJs",
method: "gzip",
filter: "js-minify",
},
{
file: "simple.htm",
name: "PAGE_simple",
method: "gzip",
filter: "html-minify-ui",
}
],
"wled00/html_simplex.h"
);
*/
writeChunks( writeChunks(
"wled00/data", "wled00/data",
[ [
{ {
file: "style.css", file: "style.css",
name: "PAGE_settingsCss", name: "PAGE_settingsCss",
prepend: "=====(<style>", method: "gzip",
append: "</style>)=====",
method: "plaintext",
filter: "css-minify", filter: "css-minify",
mangle: (str) =>
str
.replace("%%","%")
}, },
{ {
file: "settings.htm", file: "settings.htm",
name: "PAGE_settings", name: "PAGE_settings",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace("%", "%%")
.replace(/Usermods\<\/button\>\<\/form\>/gms, "Usermods\<\/button\>\<\/form\>%DMXMENU%"),
}, },
{ {
file: "settings_wifi.htm", file: "settings_wifi.htm",
name: "PAGE_settings_wifi", name: "PAGE_settings_wifi",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace(/\<link rel="stylesheet".*\>/gms, "")
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%")
.replace(
/function GetV().*\<\/script\>/gms,
"function GetV() {var d=document;\n"
),
}, },
{ {
file: "settings_leds.htm", file: "settings_leds.htm",
name: "PAGE_settings_leds", name: "PAGE_settings_leds",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace(/\<link rel="stylesheet".*\>/gms, "")
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%")
.replace(
/function GetV().*\<\/script\>/gms,
"function GetV() {var d=document;\n"
),
}, },
{ {
file: "settings_dmx.htm", file: "settings_dmx.htm",
name: "PAGE_settings_dmx", name: "PAGE_settings_dmx",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) => {
const nocss = str
.replace(/\<link rel="stylesheet".*\>/gms, "")
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%")
.replace(
/function GetV().*\<\/script\>/gms,
"function GetV() {var d=document;\n"
);
return `
#ifdef WLED_ENABLE_DMX
${nocss}
#else
const char PAGE_settings_dmx[] PROGMEM = R"=====()=====";
#endif
`;
},
}, },
{ {
file: "settings_ui.htm", file: "settings_ui.htm",
name: "PAGE_settings_ui", name: "PAGE_settings_ui",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace(/\<link rel="stylesheet".*\>/gms, "")
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%")
.replace(
/function GetV().*\<\/script\>/gms,
"function GetV() {var d=document;\n"
),
}, },
{ {
file: "settings_sync.htm", file: "settings_sync.htm",
name: "PAGE_settings_sync", name: "PAGE_settings_sync",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace(/\<link rel="stylesheet".*\>/gms, "")
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%")
.replace(/function GetV().*\<\/script\>/gms, "function GetV() {\n"),
}, },
{ {
file: "settings_time.htm", file: "settings_time.htm",
name: "PAGE_settings_time", name: "PAGE_settings_time",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace(/\<link rel="stylesheet".*\>/gms, "")
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%")
.replace(/function GetV().*\<\/script\>/gms, "function GetV() {\n"),
}, },
{ {
file: "settings_sec.htm", file: "settings_sec.htm",
name: "PAGE_settings_sec", name: "PAGE_settings_sec",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace(/\<link rel="stylesheet".*\>/gms, "")
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%")
.replace(
/function GetV().*\<\/script\>/gms,
"function GetV() {var d=document;\n"
),
}, },
{ {
file: "settings_um.htm", file: "settings_um.htm",
name: "PAGE_settings_um", name: "PAGE_settings_um",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) => },
str {
.replace(/\<link rel="stylesheet".*\>/gms, "") file: "settings_2D.htm",
.replace(/\<style\>.*\<\/style\>/gms, "%CSS%%SCSS%") name: "PAGE_settings_2D",
.replace( method: "gzip",
/function GetV().*\<\/script\>/gms, filter: "html-minify",
"function GetV() {var d=document;\n" },
), {
file: "settings_pin.htm",
name: "PAGE_settings_pin",
method: "gzip",
filter: "html-minify"
} }
], ],
"wled00/html_settings.h" "wled00/html_settings.h"
@ -359,9 +334,7 @@ writeChunks(
{ {
file: "usermod.htm", file: "usermod.htm",
name: "PAGE_usermod", name: "PAGE_usermod",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) => mangle: (str) =>
str.replace(/fetch\("http\:\/\/.*\/win/gms, 'fetch("/win'), str.replace(/fetch\("http\:\/\/.*\/win/gms, 'fetch("/win'),
@ -393,41 +366,43 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
{ {
file: "update.htm", file: "update.htm",
name: "PAGE_update", name: "PAGE_update",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
mangle: (str) =>
str
.replace(
/function GetV().*\<\/script\>/gms,
"</script><script src=\"/settings/s.js?p=9\"></script>"
)
}, },
{ {
file: "welcome.htm", file: "welcome.htm",
name: "PAGE_welcome", name: "PAGE_welcome",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
}, },
{ {
file: "liveview.htm", file: "liveview.htm",
name: "PAGE_liveview", name: "PAGE_liveview",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
}, },
{ {
file: "liveviewws.htm", file: "liveviewws.htm",
name: "PAGE_liveviewws", name: "PAGE_liveviewws",
prepend: "=====(", method: "gzip",
append: ")=====", filter: "html-minify",
method: "plaintext", },
{
file: "liveviewws2D.htm",
name: "PAGE_liveviewws2D",
method: "gzip",
filter: "html-minify", filter: "html-minify",
}, },
{ {
file: "404.htm", file: "404.htm",
name: "PAGE_404", name: "PAGE_404",
prepend: "=====(", method: "gzip",
append: ")=====",
method: "plaintext",
filter: "html-minify", filter: "html-minify",
}, },
{ {
@ -435,6 +410,16 @@ const char PAGE_dmxmap[] PROGMEM = R"=====()=====";
name: "favicon", name: "favicon",
method: "binary", method: "binary",
}, },
{
file: "iro.js",
name: "iroJs",
method: "gzip"
},
{
file: "rangetouch.js",
name: "rangetouchJs",
method: "gzip"
}
], ],
"wled00/html_other.h" "wled00/html_other.h"
); );

View File

@ -103,25 +103,24 @@ class Animated_Staircase : public Usermod {
void updateSegments() { void updateSegments() {
mainSegmentId = strip.getMainSegmentId(); mainSegmentId = strip.getMainSegmentId();
WS2812FX::Segment* segments = strip.getSegments(); for (int i = 0; i < strip.getSegmentsNum(); i++) {
for (int i = 0; i < MAX_NUM_SEGMENTS; i++, segments++) { Segment &seg = strip.getSegment(i);
if (!segments->isActive()) { if (!seg.isActive()) {
maxSegmentId = i - 1; maxSegmentId = i - 1;
break; break;
} }
if (i >= onIndex && i < offIndex) { if (i >= onIndex && i < offIndex) {
segments->setOption(SEG_OPTION_ON, 1, i); seg.setOption(SEG_OPTION_ON, true);
// We may need to copy mode and colors from segment 0 to make sure // We may need to copy mode and colors from segment 0 to make sure
// changes are propagated even when the config is changed during a wipe // changes are propagated even when the config is changed during a wipe
// segments->mode = mainsegment.mode; // seg.setMode(mainsegment.mode);
// segments->colors[0] = mainsegment.colors[0]; // seg.setColor(0, mainsegment.colors[0]);
} else { } else {
segments->setOption(SEG_OPTION_ON, 0, i); seg.setOption(SEG_OPTION_ON, false);
} }
// Always mark segments as "transitional", we are animating the staircase // Always mark segments as "transitional", we are animating the staircase
segments->setOption(SEG_OPTION_TRANSITIONAL, 1, i); seg.setOption(SEG_OPTION_TRANSITIONAL, true);
} }
colorUpdated(CALL_MODE_DIRECT_CHANGE); colorUpdated(CALL_MODE_DIRECT_CHANGE);
} }
@ -290,13 +289,13 @@ class Animated_Staircase : public Usermod {
} }
} else { } else {
// Restore segment options // Restore segment options
WS2812FX::Segment* segments = strip.getSegments(); for (int i = 0; i < strip.getSegmentsNum(); i++) {
for (int i = 0; i < MAX_NUM_SEGMENTS; i++, segments++) { Segment &seg = strip.getSegment(i);
if (!segments->isActive()) { if (!seg.isActive()) {
maxSegmentId = i - 1; maxSegmentId = i - 1;
break; break;
} }
segments->setOption(SEG_OPTION_ON, 1, i); seg.setOption(SEG_OPTION_ON, true);
} }
colorUpdated(CALL_MODE_DIRECT_CHANGE); colorUpdated(CALL_MODE_DIRECT_CHANGE);
DEBUG_PRINTLN(F("Animated Staircase disabled.")); DEBUG_PRINTLN(F("Animated Staircase disabled."));
@ -406,6 +405,14 @@ class Animated_Staircase : public Usermod {
} }
} }
void appendConfigData() {
//oappend(SET_F("dd=addDropdown('staircase','selectfield');"));
//oappend(SET_F("addOption(dd,'1st value',0);"));
//oappend(SET_F("addOption(dd,'2nd value',1);"));
//oappend(SET_F("addInfo('staircase:selectfield',1,'additional info');")); // 0 is field type, 1 is actual field
}
/* /*
* Writes the configuration to internal flash memory. * Writes the configuration to internal flash memory.
*/ */
@ -500,22 +507,22 @@ class Animated_Staircase : public Usermod {
* tab of the web-UI. * tab of the web-UI.
*/ */
void addToJsonInfo(JsonObject& root) { void addToJsonInfo(JsonObject& root) {
JsonObject staircase = root["u"]; JsonObject user = root["u"];
if (staircase.isNull()) { if (user.isNull()) {
staircase = root.createNestedObject("u"); user = root.createNestedObject("u");
} }
JsonArray usermodEnabled = staircase.createNestedArray(F("Staircase")); // name JsonArray infoArr = user.createNestedArray(FPSTR(_name)); // name
String btn = F("<button class=\"btn infobtn\" onclick=\"requestJson({staircase:{enabled:");
if (enabled) { String uiDomString = F("<button class=\"btn btn-xs\" onclick=\"requestJson({");
btn += F("false}});\">"); uiDomString += FPSTR(_name);
btn += F("enabled"); uiDomString += F(":{");
} else { uiDomString += FPSTR(_enabled);
btn += F("true}});\">"); uiDomString += enabled ? F(":false}});\">") : F(":true}});\">");
btn += F("disabled"); uiDomString += F("<i class=\"icons ");
} uiDomString += enabled ? "on" : "off";
btn += F("</button>"); uiDomString += F("\">&#xe08f;</i></button>");
usermodEnabled.add(btn); // value infoArr.add(uiDomString);
} }
}; };

View File

@ -26,15 +26,10 @@ private:
bool HomeAssistantDiscovery = false; // Publish Home Assistant Device Information bool HomeAssistantDiscovery = false; // Publish Home Assistant Device Information
// set the default pins based on the architecture, these get overridden by Usermod menu settings // set the default pins based on the architecture, these get overridden by Usermod menu settings
#ifdef ARDUINO_ARCH_ESP32 // ESP32 boards #ifdef ESP8266
#define HW_PIN_SCL 22
#define HW_PIN_SDA 21
#else // ESP8266 boards
#define HW_PIN_SCL 5
#define HW_PIN_SDA 4
//uint8_t RST_PIN = 16; // Uncoment for Heltec WiFi-Kit-8 //uint8_t RST_PIN = 16; // Uncoment for Heltec WiFi-Kit-8
#endif #endif
int8_t ioPin[2] = {HW_PIN_SCL, HW_PIN_SDA}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup() int8_t ioPin[2] = {i2c_scl, i2c_sda}; // I2C pins: SCL, SDA...defaults to Arch hardware pins but overridden at setup()
bool initDone = false; bool initDone = false;
// BME280 sensor settings // BME280 sensor settings
@ -177,7 +172,7 @@ private:
public: public:
void setup() void setup()
{ {
bool HW_Pins_Used = (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA); // note whether architecture-based hardware SCL/SDA pins used bool HW_Pins_Used = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda); // note whether architecture-based hardware SCL/SDA pins used
PinOwner po = PinOwner::UM_BME280; // defaults to being pinowner for SCL/SDA pins PinOwner po = PinOwner::UM_BME280; // defaults to being pinowner for SCL/SDA pins
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; // allocate pins PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; // allocate pins
if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins if (HW_Pins_Used) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
@ -444,7 +439,7 @@ public:
for (byte i=0; i<2; i++) if (ioPin[i] != newPin[i]) { pinsChanged = true; break; } // check if any pins changed for (byte i=0; i<2; i++) if (ioPin[i] != newPin[i]) { pinsChanged = true; break; } // check if any pins changed
if (pinsChanged) { //if pins changed, deallocate old pins and allocate new ones if (pinsChanged) { //if pins changed, deallocate old pins and allocate new ones
PinOwner po = PinOwner::UM_BME280; PinOwner po = PinOwner::UM_BME280;
if (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins if (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
pinManager.deallocateMultiplePins((const uint8_t *)ioPin, 2, po); // deallocate pins pinManager.deallocateMultiplePins((const uint8_t *)ioPin, 2, po); // deallocate pins
for (byte i=0; i<2; i++) ioPin[i] = newPin[i]; for (byte i=0; i<2; i++) ioPin[i] = newPin[i];
setup(); setup();

View File

@ -249,7 +249,7 @@ class UsermodCronixie : public Usermod {
if (backlight && _digitOut[i] <11) if (backlight && _digitOut[i] <11)
{ {
uint32_t col = strip.gamma32(strip.getSegment(0).colors[1]); uint32_t col = gamma32(strip.getSegment(0).colors[1]);
for (uint16_t j=o; j< o+10; j++) { for (uint16_t j=o; j< o+10; j++) {
if (j != excl) strip.setPixelColor(j, col); if (j != excl) strip.setPixelColor(j, col);
} }

View File

@ -75,7 +75,7 @@ private:
uint8_t lineBuffer[w * 2]; uint8_t lineBuffer[w * 2];
if (!realtimeMode || realtimeOverride) strip.service(); if (!realtimeMode || realtimeOverride || (realtimeMode && useMainSegmentOnly)) strip.service();
// 0,0 coordinates are top left // 0,0 coordinates are top left
for (row = 0; row < h; row++) { for (row = 0; row < h; row++) {
@ -169,7 +169,7 @@ private:
uint32_t lineSize = ((bitDepth * w +31) >> 5) * 4; uint32_t lineSize = ((bitDepth * w +31) >> 5) * 4;
uint8_t lineBuffer[lineSize]; uint8_t lineBuffer[lineSize];
uint8_t serviceStrip = (!realtimeMode || realtimeOverride) ? 7 : 0; uint8_t serviceStrip = (!realtimeMode || realtimeOverride || (realtimeMode && useMainSegmentOnly)) ? 7 : 0;
// row is decremented as the BMP image is drawn bottom up // row is decremented as the BMP image is drawn bottom up
for (row = h-1; row >= 0; row--) { for (row = h-1; row >= 0; row--) {
if ((row & 0b00000111) == serviceStrip) strip.service(); //still refresh backlight to mitigate stutter every few rows if ((row & 0b00000111) == serviceStrip) strip.service(); //still refresh backlight to mitigate stutter every few rows
@ -250,7 +250,7 @@ private:
uint8_t lineBuffer[w * 2]; uint8_t lineBuffer[w * 2];
if (!realtimeMode || realtimeOverride) strip.service(); if (!realtimeMode || realtimeOverride || (realtimeMode && useMainSegmentOnly)) strip.service();
// 0,0 coordinates are top left // 0,0 coordinates are top left
for (row = 0; row < h; row++) { for (row = 0; row < h; row++) {
@ -355,7 +355,7 @@ public:
// Color in grayscale bitmaps if Segment 1 exists // Color in grayscale bitmaps if Segment 1 exists
// TODO If secondary and tertiary are black, color all in primary, // TODO If secondary and tertiary are black, color all in primary,
// else color first three from Seg 1 color slots and last three from Seg 2 color slots // else color first three from Seg 1 color slots and last three from Seg 2 color slots
WS2812FX::Segment& seg1 = strip.getSegment(tubeSegment); Segment& seg1 = strip.getSegment(tubeSegment);
if (seg1.isActive()) { if (seg1.isActive()) {
digitColor = strip.getPixelColor(seg1.start + digit); digitColor = strip.getPixelColor(seg1.start + digit);
dimming = seg1.opacity; dimming = seg1.opacity;

View File

@ -63,7 +63,7 @@ class ElekstubeIPSUsermod : public Usermod {
if (!toki.isTick()) return; if (!toki.isTick()) return;
updateLocalTime(); updateLocalTime();
WS2812FX::Segment& seg1 = strip.getSegment(tfts.tubeSegment); Segment& seg1 = strip.getSegment(tfts.tubeSegment);
if (seg1.isActive()) { if (seg1.isActive()) {
bool update = false; bool update = false;
if (seg1.opacity != lastBri) update = true; if (seg1.opacity != lastBri) update = true;

View File

@ -148,58 +148,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

View File

@ -191,58 +191,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

View File

@ -58,7 +58,6 @@ private:
byte prevPreset = 0; byte prevPreset = 0;
byte prevPlaylist = 0; byte prevPlaylist = 0;
bool savedState = false;
uint32_t offTimerStart = 0; // off timer start time uint32_t offTimerStart = 0; // off timer start time
byte NotifyUpdateMode = CALL_MODE_NO_NOTIFY; // notification mode for stateUpdated(): CALL_MODE_NO_NOTIFY or CALL_MODE_DIRECT_CHANGE byte NotifyUpdateMode = CALL_MODE_NO_NOTIFY; // notification mode for stateUpdated(): CALL_MODE_NO_NOTIFY or CALL_MODE_DIRECT_CHANGE
@ -77,6 +76,7 @@ private:
bool m_mqttOnly = false; // flag to send MQTT message only (assuming it is enabled) bool m_mqttOnly = false; // flag to send MQTT message only (assuming it is enabled)
// flag to enable triggering only if WLED is initially off (LEDs are not on, preventing running effect being overwritten by PIR) // flag to enable triggering only if WLED is initially off (LEDs are not on, preventing running effect being overwritten by PIR)
bool m_offOnly = false; bool m_offOnly = false;
bool m_offMode = offMode;
// strings to reduce flash memory usage (used more than twice) // strings to reduce flash memory usage (used more than twice)
static const char _name[]; static const char _name[];
@ -118,17 +118,20 @@ private:
*/ */
void switchStrip(bool switchOn) void switchStrip(bool switchOn)
{ {
if (m_offOnly && bri && (switchOn || (!PIRtriggered && !switchOn))) return; if (m_offOnly && bri && (switchOn || (!PIRtriggered && !switchOn))) return; //if lights on and off only, do nothing
if (PIRtriggered && switchOn) return; //if already on and triggered before, do nothing
PIRtriggered = switchOn; PIRtriggered = switchOn;
if (switchOn) { if (switchOn) {
if (m_onPreset) { if (m_onPreset) {
if (currentPlaylist>0) prevPlaylist = currentPlaylist; if (currentPlaylist>0 && !offMode) {
else if (currentPreset>0) prevPreset = currentPreset; prevPlaylist = currentPlaylist;
else { unloadPlaylist();
} else if (currentPreset>0 && !offMode) {
prevPreset = currentPreset;
} else {
saveTemporaryPreset(); saveTemporaryPreset();
savedState = true;
prevPlaylist = 0; prevPlaylist = 0;
prevPreset = 0; prevPreset = 255;
} }
applyPreset(m_onPreset, NotifyUpdateMode); applyPreset(m_onPreset, NotifyUpdateMode);
return; return;
@ -140,20 +143,17 @@ private:
} }
} else { } else {
if (m_offPreset) { if (m_offPreset) {
applyPreset(m_offPreset, NotifyUpdateMode); if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(m_offPreset, NotifyUpdateMode);
return; return;
} else if (prevPlaylist) { } else if (prevPlaylist) {
applyPreset(prevPlaylist, NotifyUpdateMode); if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(prevPlaylist, NotifyUpdateMode);
prevPlaylist = 0; prevPlaylist = 0;
return; return;
} else if (prevPreset) { } else if (prevPreset) {
applyPreset(prevPreset, NotifyUpdateMode); if (prevPreset<255) { if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyPreset(prevPreset, NotifyUpdateMode); }
else { if (currentPreset==m_onPreset || currentPlaylist==m_onPreset) applyTemporaryPreset(); }
prevPreset = 0; prevPreset = 0;
return; return;
} else if (savedState) {
applyTemporaryPreset();
savedState = false;
return;
} }
// preset not assigned // preset not assigned
if (bri != 0) { if (bri != 0) {
@ -188,10 +188,12 @@ private:
if (sensorPinState == HIGH) { if (sensorPinState == HIGH) {
offTimerStart = 0; offTimerStart = 0;
if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()))) switchStrip(true); if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()))) switchStrip(true);
else if (NotifyUpdateMode != CALL_MODE_NO_NOTIFY) updateInterfaces(CALL_MODE_WS_SEND);
publishMqtt("on"); publishMqtt("on");
} else /*if (bri != 0)*/ { } else {
// start switch off timer // start switch off timer
offTimerStart = millis(); offTimerStart = millis();
if (NotifyUpdateMode != CALL_MODE_NO_NOTIFY) updateInterfaces(CALL_MODE_WS_SEND);
} }
return true; return true;
} }
@ -203,14 +205,13 @@ private:
*/ */
bool handleOffTimer() bool handleOffTimer()
{ {
if (offTimerStart > 0 && millis() - offTimerStart > m_switchOffDelay) if (offTimerStart > 0 && millis() - offTimerStart > m_switchOffDelay) {
{ offTimerStart = 0;
if (enabled == true) if (enabled == true) {
{
if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()))) switchStrip(false); if (!m_mqttOnly && (!m_nightTimeOnly || (m_nightTimeOnly && !isDayTime()))) switchStrip(false);
else if (NotifyUpdateMode != CALL_MODE_NO_NOTIFY) updateInterfaces(CALL_MODE_WS_SEND);
publishMqtt("off"); publishMqtt("off");
} }
offTimerStart = 0;
return true; return true;
} }
return false; return false;
@ -274,20 +275,9 @@ public:
JsonObject user = root["u"]; JsonObject user = root["u"];
if (user.isNull()) user = root.createNestedObject("u"); if (user.isNull()) user = root.createNestedObject("u");
String uiDomString = F("<button class=\"btn\" onclick=\"requestJson({"); JsonArray infoArr = user.createNestedArray(FPSTR(_name));
uiDomString += FPSTR(_name);
uiDomString += F(":{");
uiDomString += FPSTR(_enabled);
if (enabled) {
uiDomString += F(":false}});\">");
uiDomString += F("PIR <i class=\"icons\">&#xe325;</i>");
} else {
uiDomString += F(":true}});\">");
uiDomString += F("PIR <i class=\"icons\">&#xe08f;</i>");
}
uiDomString += F("</button>");
JsonArray infoArr = user.createNestedArray(uiDomString); // timer value
String uiDomString;
if (enabled) { if (enabled) {
if (offTimerStart > 0) if (offTimerStart > 0)
{ {
@ -320,6 +310,24 @@ public:
} else { } else {
infoArr.add(F("disabled")); infoArr.add(F("disabled"));
} }
uiDomString = F(" <button class=\"btn btn-xs\" onclick=\"requestJson({");
uiDomString += FPSTR(_name);
uiDomString += F(":{");
uiDomString += FPSTR(_enabled);
if (enabled) {
uiDomString += F(":false}});\">");
uiDomString += F("<i class=\"icons on\">&#xe325;</i>");
} else {
uiDomString += F(":true}});\">");
uiDomString += F("<i class=\"icons off\">&#xe08f;</i>");
}
uiDomString += F("</button>");
infoArr.add(uiDomString);
JsonObject sensor = root[F("sensor")];
if (sensor.isNull()) sensor = root.createNestedObject(F("sensor"));
sensor[F("motion")] = sensorPinState || offTimerStart>0 ? true : false;
} }
/** /**

View File

@ -30,7 +30,16 @@ _NOTE:_ You may also need to tweak Dallas Temperature usermod sampling frequency
No special requirements. No special requirements.
## Control PWM fan speed using JSON API
You can use e.g. `{"PWM-fan":{"speed":30,"lock":true}}` to set fan speed to 30 percent of maximum speed (replace 30 with arbitrary value between 0 and 100) and lock the speed.
If you include `speed` property you can set fan speed in percent (%) of maximum speed.
If you include `lock` property you can lock (_true_) or unlock (_false_) fan speed.
If the fan speed is unlocked it will revert to temperature controlled speed on next update cycle. Once fan speed is locked it will remain so until it is unlocked by next API call.
## Change Log ## Change Log
2021-10 2021-10
* First public release * First public release
2022-05
* Added JSON API call to allow changing of speed

View File

@ -38,6 +38,7 @@ class PWMFanUsermod : public Usermod {
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
uint8_t pwmChannel = 255; uint8_t pwmChannel = 255;
#endif #endif
bool lockFan = false;
#ifdef USERMOD_DALLASTEMPERATURE #ifdef USERMOD_DALLASTEMPERATURE
UsermodTemperature* tempUM; UsermodTemperature* tempUM;
@ -47,9 +48,10 @@ class PWMFanUsermod : public Usermod {
int8_t tachoPin = TACHO_PIN; int8_t tachoPin = TACHO_PIN;
int8_t pwmPin = PWM_PIN; int8_t pwmPin = PWM_PIN;
uint8_t tachoUpdateSec = 30; uint8_t tachoUpdateSec = 30;
float targetTemperature = 25.0; float targetTemperature = 35.0;
uint8_t minPWMValuePct = 50; uint8_t minPWMValuePct = 0;
uint8_t numberOfInterrupsInOneSingleRotation = 2; // Number of interrupts ESP32 sees on tacho signal on a single fan rotation. All the fans I've seen trigger two interrups. uint8_t numberOfInterrupsInOneSingleRotation = 2; // Number of interrupts ESP32 sees on tacho signal on a single fan rotation. All the fans I've seen trigger two interrups.
uint8_t pwmValuePct = 0;
// strings to reduce flash memory usage (used more than twice) // strings to reduce flash memory usage (used more than twice)
static const char _name[]; static const char _name[];
@ -60,6 +62,8 @@ class PWMFanUsermod : public Usermod {
static const char _tachoUpdateSec[]; static const char _tachoUpdateSec[];
static const char _minPWMValuePct[]; static const char _minPWMValuePct[];
static const char _IRQperRotation[]; static const char _IRQperRotation[];
static const char _speed[];
static const char _lock[];
void initTacho(void) { void initTacho(void) {
if (tachoPin < 0 || !pinManager.allocatePin(tachoPin, false, PinOwner::UM_Unspecified)){ if (tachoPin < 0 || !pinManager.allocatePin(tachoPin, false, PinOwner::UM_Unspecified)){
@ -80,6 +84,8 @@ class PWMFanUsermod : public Usermod {
} }
void updateTacho(void) { void updateTacho(void) {
// store milliseconds when tacho was measured the last time
msLastTachoMeasurement = millis();
if (tachoPin < 0) return; if (tachoPin < 0) return;
// start of tacho measurement // start of tacho measurement
@ -90,8 +96,6 @@ class PWMFanUsermod : public Usermod {
last_rpm /= tachoUpdateSec; last_rpm /= tachoUpdateSec;
// reset counter // reset counter
counter_rpm = 0; counter_rpm = 0;
// store milliseconds when tacho was measured the last time
msLastTachoMeasurement = millis();
// attach interrupt again // attach interrupt again
attachInterrupt(digitalPinToInterrupt(tachoPin), rpm_fan, FALLING); attachInterrupt(digitalPinToInterrupt(tachoPin), rpm_fan, FALLING);
} }
@ -99,6 +103,7 @@ class PWMFanUsermod : public Usermod {
// https://randomnerdtutorials.com/esp32-pwm-arduino-ide/ // https://randomnerdtutorials.com/esp32-pwm-arduino-ide/
void initPWMfan(void) { void initPWMfan(void) {
if (pwmPin < 0 || !pinManager.allocatePin(pwmPin, true, PinOwner::UM_Unspecified)) { if (pwmPin < 0 || !pinManager.allocatePin(pwmPin, true, PinOwner::UM_Unspecified)) {
enabled = false;
pwmPin = -1; pwmPin = -1;
return; return;
} }
@ -130,7 +135,7 @@ class PWMFanUsermod : public Usermod {
} }
void updateFanSpeed(uint8_t pwmValue){ void updateFanSpeed(uint8_t pwmValue){
if (pwmPin < 0) return; if (!enabled || pwmPin < 0) return;
#ifdef ESP8266 #ifdef ESP8266
analogWrite(pwmPin, pwmValue); analogWrite(pwmPin, pwmValue);
@ -155,7 +160,7 @@ class PWMFanUsermod : public Usermod {
int pwmStep = ((100 - minPWMValuePct) * newPWMvalue) / (7*100); int pwmStep = ((100 - minPWMValuePct) * newPWMvalue) / (7*100);
int pwmMinimumValue = (minPWMValuePct * newPWMvalue) / 100; int pwmMinimumValue = (minPWMValuePct * newPWMvalue) / 100;
if ((temp == NAN) || (temp <= 0.0)) { if ((temp == NAN) || (temp <= -100.0)) {
DEBUG_PRINTLN(F("WARNING: no temperature value available. Cannot do temperature control. Will set PWM fan to 255.")); DEBUG_PRINTLN(F("WARNING: no temperature value available. Cannot do temperature control. Will set PWM fan to 255."));
} else if (difftemp <= 0.0) { } else if (difftemp <= 0.0) {
// Temperature is below target temperature. Run fan at minimum speed. // Temperature is below target temperature. Run fan at minimum speed.
@ -205,7 +210,7 @@ class PWMFanUsermod : public Usermod {
if ((now - msLastTachoMeasurement) < (tachoUpdateSec * 1000)) return; if ((now - msLastTachoMeasurement) < (tachoUpdateSec * 1000)) return;
updateTacho(); updateTacho();
setFanPWMbasedOnTemperature(); if (!lockFan) setFanPWMbasedOnTemperature();
} }
/* /*
@ -214,12 +219,41 @@ class PWMFanUsermod : public Usermod {
* Below it is shown how this could be used for e.g. a light sensor * Below it is shown how this could be used for e.g. a light sensor
*/ */
void addToJsonInfo(JsonObject& root) { void addToJsonInfo(JsonObject& root) {
if (tachoPin < 0) return;
JsonObject user = root["u"]; JsonObject user = root["u"];
if (user.isNull()) user = root.createNestedObject("u"); if (user.isNull()) user = root.createNestedObject("u");
JsonArray data = user.createNestedArray(FPSTR(_name));
JsonArray infoArr = user.createNestedArray(FPSTR(_name));
String uiDomString = F("<button class=\"btn btn-xs\" onclick=\"requestJson({'");
uiDomString += FPSTR(_name);
uiDomString += F("':{'");
uiDomString += FPSTR(_enabled);
uiDomString += F("':");
uiDomString += enabled ? "false" : "true";
uiDomString += F("}});\"><i class=\"icons ");
uiDomString += enabled ? "on" : "off";
uiDomString += F("\">&#xe08f;</i></button>");
infoArr.add(uiDomString);
if (enabled) {
JsonArray infoArr = user.createNestedArray(F("Manual"));
String uiDomString = F("<div class=\"slider\"><div class=\"sliderwrap il\"><input class=\"noslide\" onchange=\"requestJson({'");
uiDomString += FPSTR(_name);
uiDomString += F("':{'");
uiDomString += FPSTR(_speed);
uiDomString += F("':parseInt(this.value)}});\" oninput=\"updateTrail(this);\" max=100 min=0 type=\"range\" value=");
uiDomString += pwmValuePct;
uiDomString += F(" /><div class=\"sliderdisplay\"></div></div></div>"); //<output class=\"sliderbubble\"></output>
infoArr.add(uiDomString);
JsonArray data = user.createNestedArray(F("Speed"));
if (tachoPin >= 0) {
data.add(last_rpm); data.add(last_rpm);
data.add(F("rpm")); data.add(F("rpm"));
} else {
if (lockFan) data.add(F("locked"));
else data.add(F("auto"));
}
}
} }
/* /*
@ -233,9 +267,24 @@ class PWMFanUsermod : public Usermod {
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients * Values in the state object may be modified by connected clients
*/ */
//void readFromJsonState(JsonObject& root) { void readFromJsonState(JsonObject& root) {
// if (!initDone) return; // prevent crash on boot applyPreset() if (!initDone) return; // prevent crash on boot applyPreset()
//} JsonObject usermod = root[FPSTR(_name)];
if (!usermod.isNull()) {
if (usermod[FPSTR(_enabled)].is<bool>()) {
enabled = usermod[FPSTR(_enabled)].as<bool>();
if (!enabled) updateFanSpeed(0);
}
if (enabled && !usermod[FPSTR(_speed)].isNull() && usermod[FPSTR(_speed)].is<int>()) {
pwmValuePct = usermod[FPSTR(_speed)].as<int>();
updateFanSpeed((constrain(pwmValuePct,0,100) * 255) / 100);
if (pwmValuePct) lockFan = true;
}
if (enabled && !usermod[FPSTR(_lock)].isNull() && usermod[FPSTR(_lock)].is<bool>()) {
lockFan = usermod[FPSTR(_lock)].as<bool>();
}
}
}
/* /*
* addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object. * addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object.
@ -337,3 +386,5 @@ const char PWMFanUsermod::_temperature[] PROGMEM = "target-temp-C";
const char PWMFanUsermod::_tachoUpdateSec[] PROGMEM = "tacho-update-s"; const char PWMFanUsermod::_tachoUpdateSec[] PROGMEM = "tacho-update-s";
const char PWMFanUsermod::_minPWMValuePct[] PROGMEM = "min-PWM-percent"; const char PWMFanUsermod::_minPWMValuePct[] PROGMEM = "min-PWM-percent";
const char PWMFanUsermod::_IRQperRotation[] PROGMEM = "IRQs-per-rotation"; const char PWMFanUsermod::_IRQperRotation[] PROGMEM = "IRQs-per-rotation";
const char PWMFanUsermod::_speed[] PROGMEM = "speed";
const char PWMFanUsermod::_lock[] PROGMEM = "lock";

View File

@ -1,34 +0,0 @@
# QuinLED Dig Uno board
These files allow WLED 0.9.1 to report the temp sensor on the Quinled board to MQTT. I use it to report the board temp to Home Assistant via MQTT, so it will send notifications if something happens and the board start to heat up.
This code uses Aircookie's WLED software. It has a premade file for user modifications. I use it to publish the temperature from the dallas temperature sensor on the Quinled board. The entries for the top of the WLED00 file, initializes the required libraries, and variables for the sensor. The .ino file waits for 60 seconds, and checks to see if the MQTT server is connected (thanks Aircoookie). It then poles the sensor, and published it using the MQTT service already running, using the main topic programmed in the WLED UI.
Installation of file: Copy and replace file in wled00 directory
## Project link
* [QuinLED-Dig-Uno](https://quinled.info/2018/09/15/quinled-dig-uno/) - Project link
### Platformio requirements
Uncomment `DallasTemperature@~3.8.0`,`OneWire@~2.3.5 under` `[common]` section in `platformio.ini`:
```ini
# platformio.ini
...
[platformio]
...
; default_envs = esp07
default_envs = d1_mini
...
[common]
...
lib_deps_external =
...
#For use SSD1306 OLED display uncomment following
U8g2@~2.27.3
#For Dallas sensor uncomment following 2 lines
DallasTemperature@~3.8.0
OneWire@~2.3.5
...
```

View File

@ -1,54 +0,0 @@
#include <Arduino.h>
#include "wled.h"
//Intiating code for QuinLED Dig-Uno temp sensor
//Uncomment Celsius if that is your prefered temperature scale
#include <DallasTemperature.h> //Dallastemperature sensor
#ifdef ARDUINO_ARCH_ESP32 //ESP32 boards
OneWire oneWire(18);
#else //ESP8266 boards
OneWire oneWire(14);
#endif
DallasTemperature sensor(&oneWire);
long temptimer = millis();
long lastMeasure = 0;
#define Celsius // Show temperature mesaurement in Celcius otherwise is in Fahrenheit
void userSetup()
{
// Start the DS18B20 sensor
sensor.begin();
}
//gets called every time WiFi is (re-)connected. Initialize own network interfaces here
void userConnected()
{
}
void userLoop()
{
temptimer = millis();
// Timer to publishe new temperature every 60 seconds
if (temptimer - lastMeasure > 60000) {
lastMeasure = temptimer;
//Check if MQTT Connected, otherwise it will crash the 8266
if (mqtt != nullptr){
sensor.requestTemperatures();
//Gets prefered temperature scale based on selection in definitions section
#ifdef Celsius
float board_temperature = sensor.getTempCByIndex(0);
#else
float board_temperature = sensors.getTempFByIndex(0);
#endif
//Create character string populated with user defined device topic from the UI, and the read temperature. Then publish to MQTT server.
char subuf[38];
strcpy(subuf, mqttDeviceTopic);
strcat(subuf, "/temperature");
mqtt->publish(subuf, 0, true, String(board_temperature).c_str());
return;}
return;}
return;
}

View File

@ -3,14 +3,6 @@
#include "src/dependencies/time/DS1307RTC.h" #include "src/dependencies/time/DS1307RTC.h"
#include "wled.h" #include "wled.h"
#ifdef ARDUINO_ARCH_ESP32
#define HW_PIN_SCL 22
#define HW_PIN_SDA 21
#else
#define HW_PIN_SCL 5
#define HW_PIN_SDA 4
#endif
//Connect DS1307 to standard I2C pins (ESP32: GPIO 21 (SDA)/GPIO 22 (SCL)) //Connect DS1307 to standard I2C pins (ESP32: GPIO 21 (SDA)/GPIO 22 (SCL))
class RTCUsermod : public Usermod { class RTCUsermod : public Usermod {
@ -20,8 +12,9 @@ class RTCUsermod : public Usermod {
public: public:
void setup() { void setup() {
PinManagerPinType pins[2] = { { HW_PIN_SCL, true }, { HW_PIN_SDA, true } }; PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; } if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { disabled = true; return; }
RTC.begin();
time_t rtcTime = RTC.get(); time_t rtcTime = RTC.get();
if (rtcTime) { if (rtcTime) {
toki.setTime(rtcTime,TOKI_NO_MS_ACCURACY,TOKI_TS_RTC); toki.setTime(rtcTime,TOKI_NO_MS_ACCURACY,TOKI_TS_RTC);
@ -44,13 +37,13 @@ class RTCUsermod : public Usermod {
* It will be called by WLED when settings are actually saved (for example, LED settings are saved) * It will be called by WLED when settings are actually saved (for example, LED settings are saved)
* I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings! * I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings!
*/ */
void addToConfig(JsonObject& root) // void addToConfig(JsonObject& root)
{ // {
JsonObject top = root.createNestedObject("RTC"); // JsonObject top = root.createNestedObject("RTC");
JsonArray pins = top.createNestedArray("pin"); // JsonArray pins = top.createNestedArray("pin");
pins.add(HW_PIN_SCL); // pins.add(i2c_scl);
pins.add(HW_PIN_SDA); // pins.add(i2c_sda);
} // }
uint16_t getId() uint16_t getId()
{ {

View File

@ -2,11 +2,14 @@
This usermod allow to use 240x240 display to display following: This usermod allow to use 240x240 display to display following:
* current date and time;
* Network SSID; * Network SSID;
* IP address; * IP address;
* WiFi signal strength;
* Brightness; * Brightness;
* Chosen effect; * Chosen effect;
* Chosen palette; * Chosen palette;
* effect speed and intensity;
* Estimated current in mA; * Estimated current in mA;
## Hardware ## Hardware
@ -46,27 +49,29 @@ Add lines to section:
default_envs = esp32dev default_envs = esp32dev
build_flags = ${common.build_flags_esp32} build_flags = ${common.build_flags_esp32}
-D USERMOD_ST7789_DISPLAY -D USERMOD_ST7789_DISPLAY
-DUSER_SETUP_LOADED=1
-DST7789_DRIVER=1
-DTFT_WIDTH=240
-DTFT_HEIGHT=240
-DCGRAM_OFFSET=1
-DTFT_MOSI=21
-DTFT_SCLK=22
-DTFT_DC=27
-DTFT_RST=26
-DTFT_BL=14
-DLOAD_GLCD=1
;optional for WROVER
;-DCONFIG_SPIRAM_SUPPORT=1
``` ```
Save the `platformio.ini` file. Once this is saved, the required library files should be automatically downloaded for modifications in a later step. Save the `platformio.ini` file. Once this is saved, the required library files should be automatically downloaded for modifications in a later step.
### TFT_eSPI Library Adjustments ### TFT_eSPI Library Adjustments
We need to modify a file in the `TFT_eSPI` library. If you followed the directions to modify and save the `platformio.ini` file above, the `User_Setup_Select.h` file can be found in the `/.pio/libdeps/esp32dev/TFT_eSPI` folder. If you are not using PlatformIO you need to modify a file in the `TFT_eSPI` library. If you followed the directions to modify and save the `platformio.ini` file above, the `Setup24_ST7789.h` file can be found in the `/.pio/libdeps/esp32dev/TFT_eSPI/User_Setups/` folder.
Modify the `User_Setup_Select.h` file as follows: Edit `Setup_ST7789.h` file and uncomment nad changep GPIO pin numbers in lines containing `TFT_MOSI`, `TFT_SCLK`, `TFT_RST`, `TFT_DC`.
* Comment out the following line (which is the 'default' setup file): Modify the `User_Setup_Select.h` by uncommentig the line containing `#include <User_Setups/Setup24_ST7789.h>` and commenting out line containing `#include <User_Setup.h>`.
```ini If your display includes backlight enable pin, #define TFT_BL with backlight enable GPIO number.
//#include <User_Setup.h> // Default setup is root library folder
```
* Add following line:
```ini
#include <User_Setups/Setup_ST7789_Display.h> // Setup file for ESP32 ST7789V SPI bus TFT
```
* Copy file `"Setup_ST7789_Display.h"` from usermod folder to `/.pio/libdeps/esp32dev/TFT_eSPI/User_Setups`

View File

@ -7,33 +7,55 @@
#include <TFT_eSPI.h> #include <TFT_eSPI.h>
#include <SPI.h> #include <SPI.h>
#define USERMOD_ST7789_DISPLAY 97 #ifndef USER_SETUP_LOADED
#ifndef ST7789_DRIVER
#ifndef TFT_DISPOFF #error Please define ST7789_DRIVER
#define TFT_DISPOFF 0x28 #endif
#ifndef TFT_WIDTH
#error Please define TFT_WIDTH
#endif
#ifndef TFT_HEIGHT
#error Please define TFT_HEIGHT
#endif
#ifndef TFT_MOSI
#error Please define TFT_MOSI
#endif
#ifndef TFT_SCLK
#error Please define TFT_SCLK
#endif
#ifndef TFT_DC
#error Please define TFT_DC
#endif
#ifndef TFT_RST
#error Please define TFT_RST
#endif
#ifndef LOAD_GLCD
#error Please define LOAD_GLCD
#endif
#endif
#ifndef TFT_BL
#define TFT_BL -1
#endif #endif
#ifndef TFT_SLPIN #define USERMOD_ID_ST7789_DISPLAY 97
#define TFT_SLPIN 0x10
#endif
#define TFT_MOSI 21 TFT_eSPI tft = TFT_eSPI(TFT_WIDTH, TFT_HEIGHT); // Invoke custom library
#define TFT_SCLK 22
#define TFT_DC 18
#define TFT_RST 5
#define TFT_BL 26 // Display backlight control pin
TFT_eSPI tft = TFT_eSPI(240, 240); // Invoke custom library // Extra char (+1) for null
#define LINE_BUFFER_SIZE 20
// How often we are redrawing screen // How often we are redrawing screen
#define USER_LOOP_REFRESH_RATE_MS 1000 #define USER_LOOP_REFRESH_RATE_MS 1000
extern int getSignalQuality(int rssi);
//class name. Use something descriptive and leave the ": public Usermod" part :) //class name. Use something descriptive and leave the ": public Usermod" part :)
class St7789DisplayUsermod : public Usermod { class St7789DisplayUsermod : public Usermod {
private: private:
//Private class members. You can declare variables and functions only accessible to your usermod here //Private class members. You can declare variables and functions only accessible to your usermod here
unsigned long lastTime = 0; unsigned long lastTime = 0;
bool enabled = true;
bool displayTurnedOff = false; bool displayTurnedOff = false;
long lastRedraw = 0; long lastRedraw = 0;
@ -45,9 +67,70 @@ class St7789DisplayUsermod : public Usermod {
uint8_t knownBrightness = 0; uint8_t knownBrightness = 0;
uint8_t knownMode = 0; uint8_t knownMode = 0;
uint8_t knownPalette = 0; uint8_t knownPalette = 0;
uint8_t tftcharwidth = 19; // Number of chars that fit on screen with text size set to 2 uint8_t knownEffectSpeed = 0;
uint8_t knownEffectIntensity = 0;
uint8_t knownMinute = 99;
uint8_t knownHour = 99;
const uint8_t tftcharwidth = 19; // Number of chars that fit on screen with text size set to 2
long lastUpdate = 0; long lastUpdate = 0;
void center(String &line, uint8_t width) {
int len = line.length();
if (len<width) for (byte i=(width-len)/2; i>0; i--) line = ' ' + line;
for (byte i=line.length(); i<width; i++) line += ' ';
}
/**
* Display the current date and time in large characters
* on the middle rows. Based 24 or 12 hour depending on
* the useAMPM configuration.
*/
void showTime() {
if (!ntpEnabled) return;
char lineBuffer[LINE_BUFFER_SIZE];
updateLocalTime();
byte minuteCurrent = minute(localTime);
byte hourCurrent = hour(localTime);
//byte secondCurrent = second(localTime);
knownMinute = minuteCurrent;
knownHour = hourCurrent;
byte currentMonth = month(localTime);
sprintf_P(lineBuffer, PSTR("%s %2d "), monthShortStr(currentMonth), day(localTime));
tft.setTextColor(TFT_SILVER);
tft.setCursor(84, 0);
tft.setTextSize(2);
tft.print(lineBuffer);
byte showHour = hourCurrent;
boolean isAM = false;
if (useAMPM) {
if (showHour == 0) {
showHour = 12;
isAM = true;
} else if (showHour > 12) {
showHour -= 12;
isAM = false;
} else {
isAM = true;
}
}
sprintf_P(lineBuffer, PSTR("%2d:%02d"), (useAMPM ? showHour : hourCurrent), minuteCurrent);
tft.setTextColor(TFT_WHITE);
tft.setTextSize(4);
tft.setCursor(60, 24);
tft.print(lineBuffer);
tft.setTextSize(2);
tft.setCursor(186, 24);
//sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
if (useAMPM) tft.print(isAM ? "AM" : "PM");
//else tft.print(lineBuffer);
}
public: public:
//Functions called by WLED //Functions called by WLED
@ -57,6 +140,9 @@ class St7789DisplayUsermod : public Usermod {
*/ */
void setup() void setup()
{ {
PinManagerPinType pins[] = { { TFT_MOSI, true }, { TFT_MISO, false}, { TFT_SCLK, true }, { TFT_CS, true}, { TFT_DC, true}, { TFT_RST, true }, { TFT_BL, true } };
if (!pinManager.allocateMultiplePins(pins, 7, PinOwner::UM_FourLineDisplay)) { enabled = false; return; }
tft.init(); tft.init();
tft.setRotation(0); //Rotation here is set up for the text to be readable with the port on the left. Use 1 to flip. tft.setRotation(0); //Rotation here is set up for the text to be readable with the port on the left. Use 1 to flip.
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
@ -65,8 +151,8 @@ class St7789DisplayUsermod : public Usermod {
tft.setTextDatum(MC_DATUM); tft.setTextDatum(MC_DATUM);
tft.setTextSize(2); tft.setTextSize(2);
tft.print("Loading..."); tft.print("Loading...");
if (TFT_BL > 0) if (TFT_BL >= 0)
{ // TFT_BL has been set in the TFT_eSPI library {
pinMode(TFT_BL, OUTPUT); // Set backlight pin to output mode pinMode(TFT_BL, OUTPUT); // Set backlight pin to output mode
digitalWrite(TFT_BL, HIGH); // Turn backlight on. digitalWrite(TFT_BL, HIGH); // Turn backlight on.
} }
@ -91,6 +177,8 @@ class St7789DisplayUsermod : public Usermod {
* Instead, use a timer check as shown here. * Instead, use a timer check as shown here.
*/ */
void loop() { void loop() {
char buff[LINE_BUFFER_SIZE];
// Check if we time interval for redrawing passes. // Check if we time interval for redrawing passes.
if (millis() - lastUpdate < USER_LOOP_REFRESH_RATE_MS) if (millis() - lastUpdate < USER_LOOP_REFRESH_RATE_MS)
{ {
@ -101,28 +189,18 @@ class St7789DisplayUsermod : public Usermod {
// Turn off display after 5 minutes with no change. // Turn off display after 5 minutes with no change.
if (!displayTurnedOff && millis() - lastRedraw > 5*60*1000) if (!displayTurnedOff && millis() - lastRedraw > 5*60*1000)
{ {
digitalWrite(TFT_BL, LOW); // Turn backlight off. if (TFT_BL >= 0) digitalWrite(TFT_BL, LOW); // Turn backlight off.
displayTurnedOff = true; displayTurnedOff = true;
} }
// Check if values which are shown on display changed from the last time. // Check if values which are shown on display changed from the last time.
if (((apActive) ? String(apSSID) : WiFi.SSID()) != knownSsid) if ((((apActive) ? String(apSSID) : WiFi.SSID()) != knownSsid) ||
{ (knownIp != (apActive ? IPAddress(4, 3, 2, 1) : Network.localIP())) ||
needRedraw = true; (knownBrightness != bri) ||
} (knownEffectSpeed != strip.getMainSegment().speed) ||
else if (knownIp != (apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP())) (knownEffectIntensity != strip.getMainSegment().intensity) ||
{ (knownMode != strip.getMainSegment().mode) ||
needRedraw = true; (knownPalette != strip.getMainSegment().palette))
}
else if (knownBrightness != bri)
{
needRedraw = true;
}
else if (knownMode != strip.getMainSegment().mode)
{
needRedraw = true;
}
else if (knownPalette != strip.getMainSegment().palette)
{ {
needRedraw = true; needRedraw = true;
} }
@ -135,7 +213,7 @@ class St7789DisplayUsermod : public Usermod {
if (displayTurnedOff) if (displayTurnedOff)
{ {
digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); // Turn backlight on. digitalWrite(TFT_BL, HIGH); // Turn backlight on.
displayTurnedOff = false; displayTurnedOff = false;
} }
lastRedraw = millis(); lastRedraw = millis();
@ -150,133 +228,102 @@ class St7789DisplayUsermod : public Usermod {
knownBrightness = bri; knownBrightness = bri;
knownMode = strip.getMainSegment().mode; knownMode = strip.getMainSegment().mode;
knownPalette = strip.getMainSegment().palette; knownPalette = strip.getMainSegment().palette;
knownEffectSpeed = strip.getMainSegment().speed;
knownEffectIntensity = strip.getMainSegment().intensity;
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
// First row with Wifi name
tft.setTextColor(TFT_SILVER);
tft.setCursor(3, 40);
tft.print(knownSsid.substring(0, tftcharwidth > 1 ? tftcharwidth - 1 : 0));
// Print `~` char to indicate that SSID is longer, than our dicplay
if (knownSsid.length() > tftcharwidth)
tft.print("~");
// Second row with AP IP and Password or IP showTime();
tft.setTextSize(2);
// Wifi name
tft.setTextColor(TFT_GREEN); tft.setTextColor(TFT_GREEN);
tft.setTextSize(2); tft.setCursor(0, 60);
tft.setCursor(3, 64); String line = knownSsid.substring(0, tftcharwidth-1);
// Print AP IP and password in AP mode or knownIP if AP not active. // Print `~` char to indicate that SSID is longer, than our display
if (knownSsid.length() > tftcharwidth) line = line.substring(0, tftcharwidth-1) + '~';
center(line, tftcharwidth);
tft.print(line.c_str());
// Print AP IP and password in AP mode or knownIP if AP not active.
if (apActive) if (apActive)
{ {
tft.setTextColor(TFT_YELLOW); tft.setCursor(0, 84);
tft.print("AP IP: "); tft.print("AP IP: ");
tft.print(knownIp); tft.print(knownIp);
tft.setCursor(3,86); tft.setCursor(0,108);
tft.setTextColor(TFT_YELLOW);
tft.print("AP Pass:"); tft.print("AP Pass:");
tft.print(apPass); tft.print(apPass);
} }
else else
{ {
tft.setTextColor(TFT_GREEN); tft.setCursor(0, 84);
tft.print("IP: "); line = knownIp.toString();
tft.print(knownIp); center(line, tftcharwidth);
tft.setCursor(3,86); tft.print(line.c_str());
//tft.print("Signal Strength: "); // percent brightness
//tft.print(i.wifi.signal); tft.setCursor(0, 120);
tft.setTextColor(TFT_WHITE); tft.setTextColor(TFT_WHITE);
tft.print("Bri: "); tft.print("Bri: ");
tft.print(((float(bri)/255)*100),0); tft.print((((int)bri*100)/255));
tft.print("%");
// signal quality
tft.setCursor(124,120);
tft.print("Sig: ");
if (getSignalQuality(WiFi.RSSI()) < 10) {
tft.setTextColor(TFT_RED);
} else if (getSignalQuality(WiFi.RSSI()) < 25) {
tft.setTextColor(TFT_ORANGE);
} else {
tft.setTextColor(TFT_GREEN);
}
tft.print(getSignalQuality(WiFi.RSSI()));
tft.setTextColor(TFT_WHITE);
tft.print("%"); tft.print("%");
} }
// Third row with mode name // mode name
tft.setCursor(3, 108); tft.setTextColor(TFT_CYAN);
uint8_t qComma = 0; tft.setCursor(0, 144);
bool insideQuotes = false; char lineBuffer[tftcharwidth+1];
uint8_t printedChars = 0; extractModeName(knownMode, JSON_mode_names, lineBuffer, tftcharwidth);
char singleJsonSymbol; tft.print(lineBuffer);
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) // palette name
{
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol)
{
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
tft.setTextColor(TFT_MAGENTA);
tft.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > tftcharwidth - 1))
break;
}
// Fourth row with palette name
tft.setTextColor(TFT_YELLOW); tft.setTextColor(TFT_YELLOW);
tft.setCursor(3, 130); tft.setCursor(0, 168);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, tftcharwidth);
insideQuotes = false; tft.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON. tft.setCursor(0, 192);
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) tft.setTextColor(TFT_SILVER);
{ sprintf_P(buff, PSTR("FX Spd:%3d Int:%3d"), effectSpeed, effectIntensity);
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i); tft.print(buff);
switch (singleJsonSymbol)
{
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
tft.print(singleJsonSymbol);
printedChars++;
}
// The following is modified from the code from the u8g2/u8g8 based code (knownPalette was knownMode)
if ((qComma > knownPalette) || (printedChars > tftcharwidth - 1))
break;
}
// Fifth row with estimated mA usage // Fifth row with estimated mA usage
tft.setTextColor(TFT_SILVER); tft.setTextColor(TFT_SILVER);
tft.setCursor(3, 152); tft.setCursor(0, 216);
// Print estimated milliamp usage (must specify the LED type in LED prefs for this to be a reasonable estimate). // Print estimated milliamp usage (must specify the LED type in LED prefs for this to be a reasonable estimate).
tft.print("Current: "); tft.print("Current: ");
tft.setTextColor(TFT_ORANGE);
tft.print(strip.currentMilliamps); tft.print(strip.currentMilliamps);
tft.print("mA"); tft.print("mA");
} }
/* /*
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API. * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
* Below it is shown how this could be used for e.g. a light sensor * Below it is shown how this could be used for e.g. a light sensor
*/ */
/*
void addToJsonInfo(JsonObject& root) void addToJsonInfo(JsonObject& root)
{ {
int reading = 20;
//this code adds "u":{"Light":[20," lux"]} to the info object
JsonObject user = root["u"]; JsonObject user = root["u"];
if (user.isNull()) user = root.createNestedObject("u"); if (user.isNull()) user = root.createNestedObject("u");
JsonArray lightArr = user.createNestedArray("Light"); //name JsonArray lightArr = user.createNestedArray("ST7789"); //name
lightArr.add(reading); //value lightArr.add(enabled?F("installed"):F("disabled")); //unit
lightArr.add(" lux"); //unit
} }
*/
/* /*
@ -295,7 +342,7 @@ class St7789DisplayUsermod : public Usermod {
*/ */
void readFromJsonState(JsonObject& root) void readFromJsonState(JsonObject& root)
{ {
userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value //userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value
//if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!")); //if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!"));
} }
@ -316,8 +363,16 @@ class St7789DisplayUsermod : public Usermod {
*/ */
void addToConfig(JsonObject& root) void addToConfig(JsonObject& root)
{ {
JsonObject top = root.createNestedObject("exampleUsermod"); JsonObject top = root.createNestedObject("ST7789");
top["great"] = userVar0; //save this var persistently whenever settings are saved JsonArray pins = top.createNestedArray("pin");
pins.add(TFT_MOSI);
pins.add(TFT_MISO);
pins.add(TFT_SCLK);
pins.add(TFT_CS);
pins.add(TFT_DC);
pins.add(TFT_RST);
pins.add(TFT_BL);
//top["great"] = userVar0; //save this var persistently whenever settings are saved
} }
@ -329,10 +384,11 @@ class St7789DisplayUsermod : public Usermod {
* but also that if you want to write persistent values to a dynamic buffer, you'd need to allocate it here instead of in setup. * but also that if you want to write persistent values to a dynamic buffer, you'd need to allocate it here instead of in setup.
* If you don't know what that is, don't fret. It most likely doesn't affect your use case :) * If you don't know what that is, don't fret. It most likely doesn't affect your use case :)
*/ */
void readFromConfig(JsonObject& root) bool readFromConfig(JsonObject& root)
{ {
JsonObject top = root["top"]; //JsonObject top = root["top"];
userVar0 = top["great"] | 42; //The value right of the pipe "|" is the default value in case your setting was not present in cfg.json (e.g. first boot) //userVar0 = top["great"] | 42; //The value right of the pipe "|" is the default value in case your setting was not present in cfg.json (e.g. first boot)
return true;
} }
@ -342,7 +398,7 @@ class St7789DisplayUsermod : public Usermod {
*/ */
uint16_t getId() uint16_t getId()
{ {
return USERMOD_ST7789_DISPLAY; return USERMOD_ID_ST7789_DISPLAY;
} }
//More methods can be added in the future, this example will then be extended. //More methods can be added in the future, this example will then be extended.

View File

@ -1,39 +0,0 @@
// Setup for the ESP32 board with 1.5" 240x240 display
// See SetupX_Template.h for all options available
#define ST7789_DRIVER
#define TFT_SDA_READ // Display has a bidirectionsl SDA pin
#define TFT_WIDTH 240
#define TFT_HEIGHT 240
#define CGRAM_OFFSET // Library will add offsets required
//#define TFT_MISO -1
#define TFT_MOSI 21
#define TFT_SCLK 22
//#define TFT_CS 5
#define TFT_DC 18
#define TFT_RST 5
#define TFT_BL 26 // Display backlight control pin
#define TFT_BACKLIGHT_ON HIGH // HIGH or LOW are options
#define LOAD_GLCD
#define LOAD_FONT2
#define LOAD_FONT4
#define LOAD_FONT6
#define LOAD_FONT7
#define LOAD_FONT8
#define LOAD_GFXFF
//#define SMOOTH_FONT
//#define SPI_FREQUENCY 27000000
#define SPI_FREQUENCY 40000000 // Maximum for ILI9341
#define SPI_READ_FREQUENCY 6000000 // 6 MHz is the maximum SPI read speed for the ST7789V

View File

@ -177,58 +177,15 @@ void userLoop() {
// Third row with mode name // Third row with mode name
tft.setCursor(1, 68); tft.setCursor(1, 68);
uint8_t qComma = 0; char lineBuffer[tftcharwidth+1];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, tftcharwidth);
uint8_t printedChars = 0; tft.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
tft.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > tftcharwidth - 1))
break;
}
// Fourth row with palette name // Fourth row with palette name
tft.setCursor(1, 90); tft.setCursor(1, 90);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, tftcharwidth);
insideQuotes = false; tft.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
tft.print(singleJsonSymbol);
printedChars++;
}
// The following is modified from the code from the u8g2/u8g8 based code (knownPalette was knownMode)
if ((qComma > knownPalette) || (printedChars > tftcharwidth - 1))
break;
}
// Fifth row with estimated mA usage // Fifth row with estimated mA usage
tft.setCursor(1, 112); tft.setCursor(1, 112);
// Print estimated milliamp usage (must specify the LED type in LED prefs for this to be a reasonable estimate). // Print estimated milliamp usage (must specify the LED type in LED prefs for this to be a reasonable estimate).

View File

@ -46,6 +46,8 @@ class UsermodTemperature : public Usermod {
bool enabled = true; bool enabled = true;
bool HApublished = false;
// strings to reduce flash memory usage (used more than twice) // strings to reduce flash memory usage (used more than twice)
static const char _name[]; static const char _name[];
static const char _enabled[]; static const char _enabled[];
@ -132,6 +134,28 @@ class UsermodTemperature : public Usermod {
return false; return false;
} }
void publishHomeAssistantAutodiscovery() {
if (!WLED_MQTT_CONNECTED) return;
char json_str[1024], buf[128];
size_t payload_size;
StaticJsonDocument<1024> json;
sprintf_P(buf, PSTR("%s Temperature"), serverDescription);
json[F("name")] = buf;
strcpy(buf, mqttDeviceTopic);
strcat_P(buf, PSTR("/temperature"));
json[F("state_topic")] = buf;
json[F("device_class")] = F("temperature");
json[F("unique_id")] = escapedMac.c_str();
json[F("unit_of_measurement")] = F("°C");
payload_size = serializeJson(json, json_str);
sprintf_P(buf, PSTR("homeassistant/sensor/%s/config"), escapedMac.c_str());
mqtt->publish(buf, 0, true, json_str, payload_size);
HApublished = true;
}
public: public:
void setup() { void setup() {
@ -206,6 +230,23 @@ class UsermodTemperature : public Usermod {
} }
} }
/**
* connected() is called every time the WiFi is (re)connected
* Use it to initialize network interfaces
*/
//void connected() {}
/**
* subscribe to MQTT topic if needed
*/
void onMqttConnect(bool sessionPresent) {
//(re)subscribe to required topics
//char subuf[64];
if (mqttDeviceTopic[0] != 0) {
publishHomeAssistantAutodiscovery();
}
}
/* /*
* API calls te enable data exchange between WLED modules * API calls te enable data exchange between WLED modules
*/ */
@ -229,7 +270,6 @@ class UsermodTemperature : public Usermod {
if (user.isNull()) user = root.createNestedObject("u"); if (user.isNull()) user = root.createNestedObject("u");
JsonArray temp = user.createNestedArray(FPSTR(_name)); JsonArray temp = user.createNestedArray(FPSTR(_name));
//temp.add(F("Loaded."));
if (temperature <= -100.0f) { if (temperature <= -100.0f) {
temp.add(0); temp.add(0);
@ -238,8 +278,13 @@ class UsermodTemperature : public Usermod {
} }
temp.add(degC ? getTemperatureC() : getTemperatureF()); temp.add(degC ? getTemperatureC() : getTemperatureF());
if (degC) temp.add(F("°C")); temp.add(degC ? F("°C") : F("°F"));
else temp.add(F("°F"));
JsonObject sensor = root[F("sensor")];
if (sensor.isNull()) sensor = root.createNestedObject(F("sensor"));
temp = sensor.createNestedArray(F("temp"));
temp.add(degC ? temperature : (float)temperature * 1.8f + 32);
temp.add(degC ? F("°C") : F("°F"));
} }
/** /**

View File

@ -1,15 +0,0 @@
WLED v2 UserMod for running macros at sunrise and sunset.
At the time of this text, this user mod requires code to be changed to set certain variables:
1. To reflect the user's graphical location (latitude/longitude) used for calculating apparent sunrise/sunset
2. To specify which macros will be run at sunrise and/or sunset. (defaults to 15 at sunrise and 16 at sunset)
3. To optionally provide an offset from sunrise/sunset, in minutes (max of +/- 2 hours), when the macro will be run.
In addition, WLED must be configured to get time from NTP (and the time must be retrieved via NTP.)
Please open the UserMod_SunRiseAndSet.h file for instructions on what needs to be changed, where to copy files, etc.
If this usermod proves useful enough, the code might eventually be updated to allow prompting for the required information
via the web interface and to store settings in EEPROM instead of hard-coding in the .h file.
This usermod has only been tested on the esp32dev platform, but there's no reason it wouldn't work on other platforms.

View File

@ -1,166 +0,0 @@
#pragma once
#include "wled.h"
#include <Dusk2Dawn.h>
/*
*
* REQUIREMENTS:
* The Dusk2Dawn library must be installed. This can be found at https://github.com/dmkishi/Dusk2Dawn. The 1.0.1 version of this library found via
* Arduino or platformio library managers is buggy and won't compile. The latest version from github should be used.
*
* NTP must be enabled and functional. It simply makes no sense to have events on sunrise/sunset when an accurate time isn't available.
*
* The user's geographical latitude and longitude must be configured (in decimal, not degrees/minutes/etc) using m_fLatitude and m_fLongitude
*
* if desired, an offset of up to +/- 2 hours can be specified for each of sunrise/sunset using m_sunriseOffset and m_sunsetOffset (defaults to 0)
*
* The specific macro to run at sunrise and/or sunset can be changed using m_sunriseMacro and m_sunsetMacro. (defaults to 15 and 16)
*
* From the Dusk2Dawn library:
* HINT: An easy way to find the longitude and latitude for any location is
* to find the spot in Google Maps, right click the place on the map, and
* select "What's here?". At the bottom, youll see a card with the
* coordinates.
*
* Once configured, copy UserMod_SunRiseAndSet.h to the sketch file (the same folder as wled00.ino exists),
* and then edit "usermods_list.cpp":
* Add '#include "UserMod_SunRiseAndSet.h"' in the 'includes' area
* Add 'usermods.add(new UserMod_SunRiseAndSet());' in the registerUsermods() area
*
*/
class UserMod_SunRiseAndSet : public Usermod
{
private:
/**** USER SETTINGS ****/
float m_fLatitude = 40.6; // latitude where sunrise/set are calculated
float m_fLongitude = -79.80; // longitude where sunrise/set are calculated
int8_t m_sunriseOffset = 0; // offset from sunrise, in minutes, when macro should be run (negative for before sunrise, positive for after sunrise)
int8_t m_sunsetOffset = 0; // offset from sunset, in minutes, when macro should be run (negative for before sunset, positive for after sunset)
uint8_t m_sunriseMacro = 15; // macro number to run at sunrise
uint8_t m_sunsetMacro = 16; // macro number to run at sunset
/**** END OF USER SETTINGS. DO NOT EDIT BELOW THIS LINE! ****/
Dusk2Dawn *m_pD2D = NULL; // this must be dynamically allocated in order for parameters to be loaded from EEPROM
int m_nUserSunrise = -1; // time, in minutes from midnight, of sunrise
int m_nUserSunset = -1; // time, in minutes from midnight, of sunset
byte m_nLastRunMinute = -1; // indicates what minute the userloop was last run - used so that the code only runs once per minute
public:
virtual void setup(void)
{
/* TODO: From EEPROM, load the following variables:
*
* int16_t latitude16 = 4060; // user provided latitude, multiplied by 100 and rounded
* int16_t longitude16 = -7980; // user provided longitude, multiplied by 100 and rounded.
* int8_t sunrise_offset = 0; // number of minutes to offset the sunrise macro trigger (positive for minutes after sunrise, negative for minutes before)
* int8_t sunset_offset = 0; // number of minutes to offset the sunset macro trigger (positive for minutes after sunset, negative for minutes before)
*
* then:
* m_fLatitude = (float)latitude / 100.0;
* m_fLongitude = (float)longitude / 100.0;
* m_sunriseOffset = sunrise_offset;
* m_sunsetOffset = sunset_offset;
*/
if ((0.0 != m_fLatitude) || (0.0 != m_fLongitude))
{
m_pD2D = new Dusk2Dawn (m_fLatitude, m_fLongitude, 0 /* UTC */);
// can't really check for failures. if the alloc fails, the mod just doesn't work.
}
}
void loop(void)
{
// without NTP, or a configured lat/long, none of this stuff is going to work...
// As an alternative, need to figure out how to determine if the user has manually set the clock or not.
if (m_pD2D && (999000000L != ntpLastSyncTime))
{
// to prevent needing to import all the timezone stuff from other modules, work completely in UTC
time_t timeUTC = toki.second();
tmElements_t tmNow;
breakTime(timeUTC, tmNow);
int nCurMinute = tmNow.Minute;
if (m_nLastRunMinute != nCurMinute) //only check once a new minute begins
{
m_nLastRunMinute = nCurMinute;
int numMinutes = (60 * tmNow.Hour) + m_nLastRunMinute; // how many minutes into the day are we?
// check to see if sunrise/sunset should be re-determined. Only do this if neither sunrise nor sunset
// are set. That happens when the device has just stated, and after both sunrise/sunset have already run.
if ((-1 == m_nUserSunrise) && (-1 == m_nUserSunset))
{
m_nUserSunrise = m_pD2D->sunrise(tmNow.Year + 1970, tmNow.Month, tmNow.Day, false) % 1440;
m_nUserSunset = m_pD2D->sunset(tmNow.Year + 1970, tmNow.Month, tmNow.Day, false) % 1440;
if (m_nUserSunrise > numMinutes) // has sunrise already passed? if so, recompute for tomorrow
{
breakTime(timeUTC + (60*60*24), tmNow);
m_nUserSunrise = m_pD2D->sunrise(tmNow.Year + 1970, tmNow.Month, tmNow.Day, false) % 1440;
if (m_nUserSunset > numMinutes) // if sunset has also passed, recompute that as well
{
m_nUserSunset = m_pD2D->sunset(tmNow.Year + 1970, tmNow.Month, tmNow.Day, false) % 1440;
}
}
// offset by user provided values. becuase the offsets are signed bytes, the max offset is just over 2 hours.
m_nUserSunrise += m_sunriseOffset;
m_nUserSunset += m_sunsetOffset;
}
if (numMinutes == m_nUserSunrise) // Good Morning!
{
if (m_sunriseMacro)
applyMacro(m_sunriseMacro); // run macro 15
m_nUserSunrise = -1;
}
else if (numMinutes == m_nUserSunset) // Good Night!
{
if (m_sunsetMacro)
applyMacro(m_sunsetMacro); // run macro 16
m_nUserSunset = -1;
}
} // if (m_nLastRunMinute != nCurMinute)
} // if (m_pD2D && (999000000L != ntpLastSyncTime))
}
void addToJsonState(JsonObject& root)
{
JsonObject user = root["SunRiseAndSet"];
if (user.isNull()) user = root.createNestedObject("SunRiseAndSet");
char buf[10];
if (-1 != m_nUserSunrise)
{
snprintf(buf, 10, "%02d:%02d UTC", m_nUserSunrise / 60, m_nUserSunrise % 60);
user["rise"] = buf;
}
if (-1 != m_nUserSunset)
{
snprintf(buf, 10, "%02d:%02d UTC", m_nUserSunset / 60, m_nUserSunset % 60);
user["set"] = buf;
}
JsonObject vars = user.createNestedObject("vars");
vars["lat"] = m_fLatitude;
vars["long"] = m_fLongitude;
vars["rise_mac"] = m_sunriseMacro;
vars["set_mac"] = m_sunsetMacro;
vars["rise_off"] = m_sunriseOffset;
vars["set_off"] = m_sunsetOffset;
}
~UserMod_SunRiseAndSet(void)
{
if (m_pD2D) delete m_pD2D;
}
};

View File

@ -21,14 +21,6 @@
#include <Wire.h> #include <Wire.h>
#include <VL53L0X.h> #include <VL53L0X.h>
#ifdef ARDUINO_ARCH_ESP32
#define HW_PIN_SCL 22
#define HW_PIN_SDA 21
#else
#define HW_PIN_SCL 5
#define HW_PIN_SDA 4
#endif
#ifndef VL53L0X_MAX_RANGE_MM #ifndef VL53L0X_MAX_RANGE_MM
#define VL53L0X_MAX_RANGE_MM 230 // max height in millimiters to react for motions #define VL53L0X_MAX_RANGE_MM 230 // max height in millimiters to react for motions
#endif #endif
@ -59,7 +51,7 @@ class UsermodVL53L0XGestures : public Usermod {
public: public:
void setup() { void setup() {
PinManagerPinType pins[2] = { { HW_PIN_SCL, true }, { HW_PIN_SDA, true } }; PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; } if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; }
Wire.begin(); Wire.begin();
@ -127,13 +119,13 @@ class UsermodVL53L0XGestures : public Usermod {
* It will be called by WLED when settings are actually saved (for example, LED settings are saved) * It will be called by WLED when settings are actually saved (for example, LED settings are saved)
* I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings! * I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings!
*/ */
void addToConfig(JsonObject& root) // void addToConfig(JsonObject& root)
{ // {
JsonObject top = root.createNestedObject("VL53L0x"); // JsonObject top = root.createNestedObject("VL53L0x");
JsonArray pins = top.createNestedArray("pin"); // JsonArray pins = top.createNestedArray("pin");
pins.add(HW_PIN_SCL); // pins.add(i2c_scl);
pins.add(HW_PIN_SDA); // pins.add(i2c_sda);
} // }
/* /*
* getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!). * getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!).

View File

@ -185,58 +185,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

View File

@ -191,58 +191,14 @@ void userLoop() {
// Third row with mode name // Third row with mode name
u8x8.setCursor(2, 2); u8x8.setCursor(2, 2);
uint8_t qComma = 0; char lineBuffer[17];
bool insideQuotes = false; extractModeName(knownMode, JSON_mode_names, lineBuffer, 16);
uint8_t printedChars = 0; u8x8.print(lineBuffer);
char singleJsonSymbol;
// Find the mode name in JSON
for (size_t i = 0; i < strlen_P(JSON_mode_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_mode_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownMode))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
// Fourth row with palette name // Fourth row with palette name
u8x8.setCursor(2, 3); u8x8.setCursor(2, 3);
qComma = 0; extractModeName(knownPalette, JSON_palette_names, lineBuffer, 16);
insideQuotes = false; u8x8.print(lineBuffer);
printedChars = 0;
// Looking for palette name in JSON.
for (size_t i = 0; i < strlen_P(JSON_palette_names); i++) {
singleJsonSymbol = pgm_read_byte_near(JSON_palette_names + i);
switch (singleJsonSymbol) {
case '"':
insideQuotes = !insideQuotes;
break;
case '[':
case ']':
break;
case ',':
qComma++;
default:
if (!insideQuotes || (qComma != knownPalette))
break;
u8x8.print(singleJsonSymbol);
printedChars++;
}
if ((qComma > knownMode) || (printedChars > u8x8.getCols() - 2))
break;
}
u8x8.setFont(u8x8_font_open_iconic_embedded_1x1); u8x8.setFont(u8x8_font_open_iconic_embedded_1x1);
u8x8.drawGlyph(0, 0, 80); // wifi icon u8x8.drawGlyph(0, 0, 80); // wifi icon

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,602 @@
#pragma once
#include <Wire.h>
#include "wled.h"
#include <driver/i2s.h>
#include <driver/adc.h>
#include <soc/i2s_reg.h> // needed for SPH0465 timing workaround (classic ESP32)
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32C3)
#include <driver/adc_deprecated.h>
#include <driver/adc_types_deprecated.h>
#endif
// type of i2s_config_t.SampleRate was changed from "int" to "unsigned" in IDF 4.4.x
#define SRate_t uint32_t
#else
#define SRate_t int
#endif
//#include <driver/i2s_std.h>
//#include <driver/i2s_pdm.h>
//#include <driver/i2s_tdm.h>
//#include <driver/gpio.h>
// see https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/chip-series-comparison.html#related-documents
// and https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/i2s.html#overview-of-all-modes
#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C5) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2)
// there are two things in these MCUs that could lead to problems with audio processing:
// * no floating point hardware (FPU) support - FFT uses float calculations. If done in software, a strong slow-down can be expected (between 8x and 20x)
// * single core, so FFT task might slow down other things like LED updates
#warning This audio reactive usermod does not support ESP32-C2, ESP32-C3 or ESP32-S2.
#endif
/* ToDo: remove. ES7243 is controlled via compiler defines
Until this configuration is moved to the webinterface
*/
// if you have problems to get your microphone work on the left channel, uncomment the following line
//#define I2S_USE_RIGHT_CHANNEL // (experimental) define this to use right channel (digital mics only)
// Uncomment the line below to utilize ADC1 _exclusively_ for I2S sound input.
// benefit: analog mic inputs will be sampled contiously -> better response times and less "glitches"
// WARNING: this option WILL lock-up your device in case that any other analogRead() operation is performed;
// for example if you want to read "analog buttons"
//#define I2S_GRAB_ADC1_COMPLETELY // (experimental) continously sample analog ADC microphone. WARNING will cause analogRead() lock-up
// data type requested from the I2S driver - currently we always use 32bit
//#define I2S_USE_16BIT_SAMPLES // (experimental) define this to request 16bit - more efficient but possibly less compatible
#ifdef I2S_USE_16BIT_SAMPLES
#define I2S_SAMPLE_RESOLUTION I2S_BITS_PER_SAMPLE_16BIT
#define I2S_datatype int16_t
#define I2S_unsigned_datatype uint16_t
#define I2S_data_size I2S_BITS_PER_CHAN_16BIT
#undef I2S_SAMPLE_DOWNSCALE_TO_16BIT
#else
#define I2S_SAMPLE_RESOLUTION I2S_BITS_PER_SAMPLE_32BIT
//#define I2S_SAMPLE_RESOLUTION I2S_BITS_PER_SAMPLE_24BIT
#define I2S_datatype int32_t
#define I2S_unsigned_datatype uint32_t
#define I2S_data_size I2S_BITS_PER_CHAN_32BIT
#define I2S_SAMPLE_DOWNSCALE_TO_16BIT
#endif
/* There are several (confusing) options in IDF 4.4.x:
* I2S_CHANNEL_FMT_RIGHT_LEFT, I2S_CHANNEL_FMT_ALL_RIGHT and I2S_CHANNEL_FMT_ALL_LEFT stands for stereo mode, which means two channels will transport different data.
* I2S_CHANNEL_FMT_ONLY_RIGHT and I2S_CHANNEL_FMT_ONLY_LEFT they are mono mode, both channels will only transport same data.
* I2S_CHANNEL_FMT_MULTIPLE means TDM channels, up to 16 channel will available, and they are stereo as default.
* if you want to receive two channels, one is the actual data from microphone and another channel is suppose to receive 0, it's different data in two channels, you need to choose I2S_CHANNEL_FMT_RIGHT_LEFT in this case.
*/
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)) && (ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(4, 4, 3))
// espressif bug: only_left has no sound, left and right are swapped
// https://github.com/espressif/esp-idf/issues/9635 I2S mic not working since 4.4 (IDFGH-8138)
// https://github.com/espressif/esp-idf/issues/8538 I2S channel selection issue? (IDFGH-6918)
// https://github.com/espressif/esp-idf/issues/6625 I2S: left/right channels are swapped for read (IDFGH-4826)
#ifdef I2S_USE_RIGHT_CHANNEL
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
#define I2S_MIC_CHANNEL_TEXT "right channel only (work-around swapped channel bug in IDF 4.4)."
#else
//#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ALL_LEFT
//#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_RIGHT_LEFT
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_RIGHT
#define I2S_MIC_CHANNEL_TEXT "left channel only (work-around swapped channel bug in IDF 4.4)."
#endif
#else
// not swapped
#ifdef I2S_USE_RIGHT_CHANNEL
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_RIGHT
#define I2S_MIC_CHANNEL_TEXT "right channel only."
#else
#define I2S_MIC_CHANNEL I2S_CHANNEL_FMT_ONLY_LEFT
#define I2S_MIC_CHANNEL_TEXT "left channel only."
#endif
#endif
/* Interface class
AudioSource serves as base class for all microphone types
This enables accessing all microphones with one single interface
which simplifies the caller code
*/
class AudioSource {
public:
/* All public methods are virtual, so they can be overridden
Everything but the destructor is also removed, to make sure each mic
Implementation provides its version of this function
*/
virtual ~AudioSource() {};
/* Initialize
This function needs to take care of anything that needs to be done
before samples can be obtained from the microphone.
*/
virtual void initialize(int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) = 0;
/* Deinitialize
Release all resources and deactivate any functionality that is used
by this microphone
*/
virtual void deinitialize() = 0;
/* getSamples
Read num_samples from the microphone, and store them in the provided
buffer
*/
virtual void getSamples(float *buffer, uint16_t num_samples) = 0;
/* check if the audio source driver was initialized successfully */
virtual bool isInitialized(void) {return(_initialized);}
/* identify Audiosource type - I2S-ADC or I2S-digital */
typedef enum{Type_unknown=0, Type_I2SAdc=1, Type_I2SDigital=2} AudioSourceType;
virtual AudioSourceType getType(void) {return(Type_I2SDigital);} // default is "I2S digital source" - ADC type overrides this method
protected:
/* Post-process audio sample - currently on needed for I2SAdcSource*/
virtual I2S_datatype postProcessSample(I2S_datatype sample_in) {return(sample_in);} // default method can be overriden by instances (ADC) that need sample postprocessing
// Private constructor, to make sure it is not callable except from derived classes
AudioSource(SRate_t sampleRate, int blockSize) :
_sampleRate(sampleRate),
_blockSize(blockSize),
_initialized(false)
{};
SRate_t _sampleRate; // Microphone sampling rate
int _blockSize; // I2S block size
bool _initialized; // Gets set to true if initialization is successful
};
/* Basic I2S microphone source
All functions are marked virtual, so derived classes can replace them
*/
class I2SSource : public AudioSource {
public:
I2SSource(SRate_t sampleRate, int blockSize) :
AudioSource(sampleRate, blockSize) {
_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = _sampleRate,
.bits_per_sample = I2S_SAMPLE_RESOLUTION,
.channel_format = I2S_MIC_CHANNEL,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
//.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2,
.dma_buf_count = 8,
.dma_buf_len = _blockSize,
.use_apll = 0,
.bits_per_chan = I2S_data_size,
#else
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = _blockSize,
.use_apll = false
#endif
};
}
virtual void initialize(int8_t i2swsPin = I2S_PIN_NO_CHANGE, int8_t i2ssdPin = I2S_PIN_NO_CHANGE, int8_t i2sckPin = I2S_PIN_NO_CHANGE, int8_t mclkPin = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) {
if (i2swsPin != I2S_PIN_NO_CHANGE && i2ssdPin != I2S_PIN_NO_CHANGE) {
if (!pinManager.allocatePin(i2swsPin, true, PinOwner::UM_Audioreactive) ||
!pinManager.allocatePin(i2ssdPin, false, PinOwner::UM_Audioreactive)) { // #206
DEBUGSR_PRINTF("\nAR: Failed to allocate I2S pins: ws=%d, sd=%d\n", i2swsPin, i2ssdPin);
return;
}
}
// i2ssckPin needs special treatment, since it might be unused on PDM mics
if (i2sckPin != I2S_PIN_NO_CHANGE) {
if (!pinManager.allocatePin(i2sckPin, true, PinOwner::UM_Audioreactive)) {
DEBUGSR_PRINTF("\nAR: Failed to allocate I2S pins: sck=%d\n", i2sckPin);
return;
}
} else {
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3)
// This is an I2S PDM microphone, these microphones only use a clock and
// data line, to make it simpler to debug, use the WS pin as CLK and SD
// pin as DATA
_config.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); // Change mode to pdm if clock pin not provided. PDM is not supported on ESP32-S2. PDM RX not supported on ESP32-C3
#endif
}
// Reserve the master clock pin if provided
_mclkPin = mclkPin;
if (mclkPin != I2S_PIN_NO_CHANGE) {
if(!pinManager.allocatePin(mclkPin, true, PinOwner::UM_Audioreactive)) return;
_routeMclk(mclkPin);
}
_pinConfig = {
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
.mck_io_num = mclkPin, // "classic" ESP32 supports setting MCK on GPIO0/GPIO1/GPIO3 only. i2s_set_pin() will fail if wrong mck_io_num is provided.
#endif
.bck_io_num = i2sckPin,
.ws_io_num = i2swsPin,
.data_out_num = I2S_PIN_NO_CHANGE,
.data_in_num = i2ssdPin
};
esp_err_t err = i2s_driver_install(I2S_NUM_0, &_config, 0, nullptr);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to install i2s driver: %d\n", err);
return;
}
err = i2s_set_pin(I2S_NUM_0, &_pinConfig);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to set i2s pin config: %d\n", err);
i2s_driver_uninstall(I2S_NUM_0); // uninstall already-installed driver
return;
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
err = i2s_set_clk(I2S_NUM_0, _sampleRate, I2S_SAMPLE_RESOLUTION, I2S_CHANNEL_MONO); // set bit clocks. Also takes care of MCLK routing if needed.
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to configure i2s clocks: %d\n", err);
i2s_driver_uninstall(I2S_NUM_0); // uninstall already-installed driver
return;
}
#endif
_initialized = true;
}
virtual void deinitialize() {
_initialized = false;
esp_err_t err = i2s_driver_uninstall(I2S_NUM_0);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to uninstall i2s driver: %d\n", err);
return;
}
if (_pinConfig.ws_io_num != I2S_PIN_NO_CHANGE) pinManager.deallocatePin(_pinConfig.ws_io_num, PinOwner::UM_Audioreactive);
if (_pinConfig.data_in_num != I2S_PIN_NO_CHANGE) pinManager.deallocatePin(_pinConfig.data_in_num, PinOwner::UM_Audioreactive);
if (_pinConfig.bck_io_num != I2S_PIN_NO_CHANGE) pinManager.deallocatePin(_pinConfig.bck_io_num, PinOwner::UM_Audioreactive);
// Release the master clock pin
if (_mclkPin != I2S_PIN_NO_CHANGE) pinManager.deallocatePin(_mclkPin, PinOwner::UM_Audioreactive);
}
virtual void getSamples(float *buffer, uint16_t num_samples) {
if (_initialized) {
esp_err_t err;
size_t bytes_read = 0; /* Counter variable to check if we actually got enough data */
I2S_datatype newSamples[num_samples]; /* Intermediary sample storage */
err = i2s_read(I2S_NUM_0, (void *)newSamples, sizeof(newSamples), &bytes_read, portMAX_DELAY);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to get samples: %d\n", err);
return;
}
// For correct operation, we need to read exactly sizeof(samples) bytes from i2s
if (bytes_read != sizeof(newSamples)) {
DEBUGSR_PRINTF("Failed to get enough samples: wanted: %d read: %d\n", sizeof(newSamples), bytes_read);
return;
}
// Store samples in sample buffer and update DC offset
for (int i = 0; i < num_samples; i++) {
newSamples[i] = postProcessSample(newSamples[i]); // perform postprocessing (needed for ADC samples)
float currSample = 0.0f;
#ifdef I2S_SAMPLE_DOWNSCALE_TO_16BIT
currSample = (float) newSamples[i] / 65536.0f; // 32bit input -> 16bit; keeping lower 16bits as decimal places
#else
currSample = (float) newSamples[i]; // 16bit input -> use as-is
#endif
buffer[i] = currSample;
}
}
}
protected:
void _routeMclk(int8_t mclkPin) {
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
// MCLK routing by writing registers is not needed any more with IDF > 4.4.0
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 0)
// this way of MCLK routing only works on "classic" ESP32
/* Enable the mclk routing depending on the selected mclk pin (ESP32: only 0,1,3)
Only I2S_NUM_0 is supported
*/
if (mclkPin == GPIO_NUM_0) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
WRITE_PERI_REG(PIN_CTRL,0xFFF0);
} else if (mclkPin == GPIO_NUM_1) {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3);
WRITE_PERI_REG(PIN_CTRL, 0xF0F0);
} else {
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2);
WRITE_PERI_REG(PIN_CTRL, 0xFF00);
}
#endif
#endif
}
i2s_config_t _config;
i2s_pin_config_t _pinConfig;
int8_t _mclkPin;
};
/* ES7243 Microphone
This is an I2S microphone that requires ininitialization over
I2C before I2S data can be received
*/
class ES7243 : public I2SSource {
private:
// I2C initialization functions for ES7243
void _es7243I2cBegin() {
Wire.begin(pin_ES7243_SDA, pin_ES7243_SCL, 100000U);
}
void _es7243I2cWrite(uint8_t reg, uint8_t val) {
#ifndef ES7243_ADDR
Wire.beginTransmission(0x13);
#else
Wire.beginTransmission(ES7243_ADDR);
#endif
Wire.write((uint8_t)reg);
Wire.write((uint8_t)val);
Wire.endTransmission();
}
void _es7243InitAdc() {
_es7243I2cBegin();
_es7243I2cWrite(0x00, 0x01);
_es7243I2cWrite(0x06, 0x00);
_es7243I2cWrite(0x05, 0x1B);
_es7243I2cWrite(0x01, 0x00); // 0x00 for 24 bit to match INMP441 - not sure if this needs adjustment to get 16bit samples from I2S
_es7243I2cWrite(0x08, 0x43);
_es7243I2cWrite(0x05, 0x13);
}
public:
ES7243(SRate_t sampleRate, int blockSize) :
I2SSource(sampleRate, blockSize) {
_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT;
};
void initialize(int8_t sdaPin, int8_t sclPin, int8_t i2swsPin, int8_t i2ssdPin, int8_t i2sckPin, int8_t mclkPin) {
// Reserve SDA and SCL pins of the I2C interface
if (!pinManager.allocatePin(sdaPin, true, PinOwner::HW_I2C) ||
!pinManager.allocatePin(sclPin, true, PinOwner::HW_I2C)) {
return;
}
pin_ES7243_SDA = sdaPin;
pin_ES7243_SCL = sclPin;
// First route mclk, then configure ADC over I2C, then configure I2S
_es7243InitAdc();
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin, mclkPin);
}
void deinitialize() {
// Release SDA and SCL pins of the I2C interface
pinManager.deallocatePin(pin_ES7243_SDA, PinOwner::HW_I2C);
pinManager.deallocatePin(pin_ES7243_SCL, PinOwner::HW_I2C);
I2SSource::deinitialize();
}
private:
int8_t pin_ES7243_SDA;
int8_t pin_ES7243_SCL;
};
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
// ADC over I2S is only availeable in "classic" ESP32
/* ADC over I2S Microphone
This microphone is an ADC pin sampled via the I2S interval
This allows to use the I2S API to obtain ADC samples with high sample rates
without the need of manual timing of the samples
*/
class I2SAdcSource : public I2SSource {
public:
I2SAdcSource(SRate_t sampleRate, int blockSize) :
I2SSource(sampleRate, blockSize) {
_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_ADC_BUILT_IN),
.sample_rate = _sampleRate,
.bits_per_sample = I2S_SAMPLE_RESOLUTION,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),
#else
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
#endif
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = _blockSize,
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0
};
}
/* identify Audiosource type - I2S-ADC*/
AudioSourceType getType(void) {return(Type_I2SAdc);}
void initialize(int8_t audioPin, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) {
_myADCchannel = 0x0F;
if(!pinManager.allocatePin(audioPin, false, PinOwner::UM_Audioreactive)) {
DEBUGSR_PRINTF("failed to allocate GPIO for audio analog input: %d\n", audioPin);
return;
}
_audioPin = audioPin;
// Determine Analog channel. Only Channels on ADC1 are supported
int8_t channel = digitalPinToAnalogChannel(_audioPin);
if (channel > 9) {
DEBUGSR_PRINTF("Incompatible GPIO used for audio in: %d\n", _audioPin);
return;
} else {
adc_gpio_init(ADC_UNIT_1, adc_channel_t(channel));
_myADCchannel = channel;
}
// Install Driver
esp_err_t err = i2s_driver_install(I2S_NUM_0, &_config, 0, nullptr);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to install i2s driver: %d\n", err);
return;
}
adc1_config_width(ADC_WIDTH_BIT_12); // ensure that ADC runs with 12bit resolution
// Enable I2S mode of ADC
err = i2s_set_adc_mode(ADC_UNIT_1, adc1_channel_t(channel));
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to set i2s adc mode: %d\n", err);
return;
}
// see example in https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/I2S/HiFreq_ADC/HiFreq_ADC.ino
adc1_config_channel_atten(adc1_channel_t(channel), ADC_ATTEN_DB_11); // configure ADC input amplification
#if defined(I2S_GRAB_ADC1_COMPLETELY)
// according to docs from espressif, the ADC needs to be started explicitly
// fingers crossed
err = i2s_adc_enable(I2S_NUM_0);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to enable i2s adc: %d\n", err);
//return;
}
#else
err = i2s_adc_disable(I2S_NUM_0);
//err = i2s_stop(I2S_NUM_0);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to initially disable i2s adc: %d\n", err);
}
#endif
_initialized = true;
}
I2S_datatype postProcessSample(I2S_datatype sample_in) {
static I2S_datatype lastADCsample = 0; // last good sample
static unsigned int broken_samples_counter = 0; // number of consecutive broken (and fixed) ADC samples
I2S_datatype sample_out = 0;
// bring sample down down to 16bit unsigned
I2S_unsigned_datatype rawData = * reinterpret_cast<I2S_unsigned_datatype *> (&sample_in); // C++ acrobatics to get sample as "unsigned"
#ifndef I2S_USE_16BIT_SAMPLES
rawData = (rawData >> 16) & 0xFFFF; // scale input down from 32bit -> 16bit
I2S_datatype lastGoodSample = lastADCsample / 16384 ; // prepare "last good sample" accordingly (26bit-> 12bit with correct sign handling)
#else
rawData = rawData & 0xFFFF; // input is already in 16bit, just mask off possible junk
I2S_datatype lastGoodSample = lastADCsample * 4; // prepare "last good sample" accordingly (10bit-> 12bit)
#endif
// decode ADC sample data fields
uint16_t the_channel = (rawData >> 12) & 0x000F; // upper 4 bit = ADC channel
uint16_t the_sample = rawData & 0x0FFF; // lower 12bit -> ADC sample (unsigned)
I2S_datatype finalSample = (int(the_sample) - 2048); // convert unsigned sample to signed (centered at 0);
if ((the_channel != _myADCchannel) && (_myADCchannel != 0x0F)) { // 0x0F means "don't know what my channel is"
// fix bad sample
finalSample = lastGoodSample; // replace with last good ADC sample
broken_samples_counter ++;
if (broken_samples_counter > 256) _myADCchannel = 0x0F; // too many bad samples in a row -> disable sample corrections
//Serial.print("\n!ADC rogue sample 0x"); Serial.print(rawData, HEX); Serial.print("\tchannel:");Serial.println(the_channel);
} else broken_samples_counter = 0; // good sample - reset counter
// back to original resolution
#ifndef I2S_USE_16BIT_SAMPLES
finalSample = finalSample << 16; // scale up from 16bit -> 32bit;
#endif
finalSample = finalSample / 4; // mimic old analog driver behaviour (12bit -> 10bit)
sample_out = (3 * finalSample + lastADCsample) / 4; // apply low-pass filter (2-tap FIR)
//sample_out = (finalSample + lastADCsample) / 2; // apply stronger low-pass filter (2-tap FIR)
lastADCsample = sample_out; // update ADC last sample
return(sample_out);
}
void getSamples(float *buffer, uint16_t num_samples) {
/* Enable ADC. This has to be enabled and disabled directly before and
* after sampling, otherwise Wifi dies
*/
if (_initialized) {
#if !defined(I2S_GRAB_ADC1_COMPLETELY)
// old code - works for me without enable/disable, at least on ESP32.
//esp_err_t err = i2s_start(I2S_NUM_0);
esp_err_t err = i2s_adc_enable(I2S_NUM_0);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to enable i2s adc: %d\n", err);
return;
}
#endif
I2SSource::getSamples(buffer, num_samples);
#if !defined(I2S_GRAB_ADC1_COMPLETELY)
// old code - works for me without enable/disable, at least on ESP32.
err = i2s_adc_disable(I2S_NUM_0); //i2s_adc_disable() may cause crash with IDF 4.4 (https://github.com/espressif/arduino-esp32/issues/6832)
//err = i2s_stop(I2S_NUM_0);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to disable i2s adc: %d\n", err);
return;
}
#endif
}
}
void deinitialize() {
pinManager.deallocatePin(_audioPin, PinOwner::UM_Audioreactive);
_initialized = false;
_myADCchannel = 0x0F;
esp_err_t err;
#if defined(I2S_GRAB_ADC1_COMPLETELY)
// according to docs from espressif, the ADC needs to be stopped explicitly
// fingers crossed
err = i2s_adc_disable(I2S_NUM_0);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to disable i2s adc: %d\n", err);
}
#endif
i2s_stop(I2S_NUM_0);
err = i2s_driver_uninstall(I2S_NUM_0);
if (err != ESP_OK) {
DEBUGSR_PRINTF("Failed to uninstall i2s driver: %d\n", err);
return;
}
}
private:
int8_t _audioPin;
int8_t _myADCchannel = 0x0F; // current ADC channel for analog input. 0x0F means "undefined"
};
#endif
/* SPH0645 Microphone
This is an I2S microphone with some timing quirks that need
special consideration.
*/
// https://github.com/espressif/esp-idf/issues/7192 SPH0645 i2s microphone issue when migrate from legacy esp-idf version (IDFGH-5453)
// a user recommended this: Try to set .communication_format to I2S_COMM_FORMAT_STAND_I2S and call i2s_set_clk() after i2s_set_pin().
class SPH0654 : public I2SSource {
public:
SPH0654(SRate_t sampleRate, int blockSize) :
I2SSource(sampleRate, blockSize)
{}
void initialize(uint8_t i2swsPin, uint8_t i2ssdPin, uint8_t i2sckPin, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE, int8_t = I2S_PIN_NO_CHANGE) {
I2SSource::initialize(i2swsPin, i2ssdPin, i2sckPin);
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3)
// these registers are only existing in "classic" ESP32
REG_SET_BIT(I2S_TIMING_REG(I2S_NUM_0), BIT(9));
REG_SET_BIT(I2S_CONF_REG(I2S_NUM_0), I2S_RX_MSB_SHIFT);
#else
#warning FIX ME! Please.
#endif
}
};

View File

@ -0,0 +1,36 @@
# Audioreactive usermod
This usermod allows controlling LEDs using audio input. Audio input can be either microphone or analog-in (AUX) using appropriate adapter.
Supported microphones range from analog (MAX4466, MAX9814, ...) to digital (INMP441, ICS-43434, ...).
The usermod does audio processing and provides data structure that specially written effect can use.
The usermod **does not** provide effects or draws anything to LED strip/matrix.
## Installation
Add `-D USERMOD_AUDIOREACTIVE` to your PlatformIO environment as well as `arduinoFFT` to your `lib_deps`.
If you are not using PlatformIO (which you should) try adding `#define USERMOD_AUDIOREACTIVE` to *my_config.h* and make sure you have _arduinoFFT_ library downloaded and installed.
Customised _arduinoFFT_ library for use with this usermod can be found at https://github.com/blazoncek/arduinoFFT.git
## Configuration
All parameters are runtime configurable though some may require hard boot after change (I2S microphone or selected GPIOs).
If you want to define default GPIOs during compile time use the following (default values in parentheses):
- `DMTYPE=x` : defines digital microphone type: 0=analog, 1=generic I2S, 2=ES7243 I2S, 3=SPH0645 I2S, 4=generic I2S with master clock, 5=PDM I2S
- `AUDIOPIN=x` : GPIO for analog microphone/AUX-in (36)
- `I2S_SDPIN=x` : GPIO for SD pin on digital mcrophone (32)
- `I2S_WSPIN=x` : GPIO for WS pin on digital mcrophone (15)
- `I2S_CKPIN=x` : GPIO for SCK pin on digital mcrophone (14)
- `ES7243_SDAPIN` : GPIO for I2C SDA pin on ES7243 microphone (-1)
- `ES7243_SCLPIN` : GPIO for I2C SCL pin on ES7243 microphone (-1)
- `MCLK_PIN=x` : GPIO for master clock pin on digital mcrophone (-1)
**NOTE** Due to the fact that usermod uses I2S peripherial for analog audio sampling, use of analog *buttons* (i.e. potentiometers) is disabled while running this usermod with analog microphone.
## Release notes
2022-06 Ported from [soundreactive](https://github.com/atuline/WLED) by @blazoncek (AKA Blaz Kristan)

View File

@ -42,14 +42,6 @@
#include "Wire.h" #include "Wire.h"
#endif #endif
#ifdef ARDUINO_ARCH_ESP32
#define HW_PIN_SCL 22
#define HW_PIN_SDA 21
#else
#define HW_PIN_SCL 5
#define HW_PIN_SDA 4
#endif
// ================================================================ // ================================================================
// === INTERRUPT DETECTION ROUTINE === // === INTERRUPT DETECTION ROUTINE ===
// ================================================================ // ================================================================
@ -93,7 +85,7 @@ class MPU6050Driver : public Usermod {
* setup() is called once at boot. WiFi is not yet connected at this point. * setup() is called once at boot. WiFi is not yet connected at this point.
*/ */
void setup() { void setup() {
PinManagerPinType pins[2] = { { HW_PIN_SCL, true }, { HW_PIN_SDA, true } }; PinManagerPinType pins[2] = { { i2c_scl, true }, { i2c_sda, true } };
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; } if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::HW_I2C)) { enabled = false; return; }
// join I2C bus (I2Cdev library doesn't do this automatically) // join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
@ -258,20 +250,20 @@ class MPU6050Driver : public Usermod {
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object). * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients * Values in the state object may be modified by connected clients
*/ */
void addToJsonState(JsonObject& root) //void addToJsonState(JsonObject& root)
{ //{
//root["user0"] = userVar0; //root["user0"] = userVar0;
} //}
/* /*
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object). * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
* Values in the state object may be modified by connected clients * Values in the state object may be modified by connected clients
*/ */
void readFromJsonState(JsonObject& root) //void readFromJsonState(JsonObject& root)
{ //{
//if (root["bri"] == 255) DEBUG_PRINTLN(F("Don't burn down your garage!")); //if (root["bri"] == 255) DEBUG_PRINTLN(F("Don't burn down your garage!"));
} //}
/* /*
@ -279,13 +271,13 @@ class MPU6050Driver : public Usermod {
* It will be called by WLED when settings are actually saved (for example, LED settings are saved) * It will be called by WLED when settings are actually saved (for example, LED settings are saved)
* I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings! * I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings!
*/ */
void addToConfig(JsonObject& root) // void addToConfig(JsonObject& root)
{ // {
JsonObject top = root.createNestedObject("MPU6050_IMU"); // JsonObject top = root.createNestedObject("MPU6050_IMU");
JsonArray pins = top.createNestedArray("pin"); // JsonArray pins = top.createNestedArray("pin");
pins.add(HW_PIN_SCL); // pins.add(HW_PIN_SCL);
pins.add(HW_PIN_SDA); // pins.add(HW_PIN_SDA);
} // }
/* /*
* getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!). * getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!).

View File

@ -80,7 +80,7 @@ class MultiRelay : public Usermod {
void handleOffTimer() { void handleOffTimer() {
unsigned long now = millis(); unsigned long now = millis();
bool activeRelays = false; bool activeRelays = false;
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].active && _switchTimerStart > 0 && now - _switchTimerStart > (_relay[i].delay*1000)) { if (_relay[i].active && _switchTimerStart > 0 && now - _switchTimerStart > (_relay[i].delay*1000)) {
if (!_relay[i].external) toggleRelay(i); if (!_relay[i].external) toggleRelay(i);
_relay[i].active = false; _relay[i].active = false;
@ -182,7 +182,7 @@ class MultiRelay : public Usermod {
*/ */
MultiRelay() { MultiRelay() {
const int8_t defPins[] = {MULTI_RELAY_PINS}; const int8_t defPins[] = {MULTI_RELAY_PINS};
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
_relay[i].pin = i<sizeof(defPins) ? defPins[i] : -1; _relay[i].pin = i<sizeof(defPins) ? defPins[i] : -1;
_relay[i].delay = 0; _relay[i].delay = 0;
_relay[i].mode = false; _relay[i].mode = false;
@ -226,7 +226,7 @@ class MultiRelay : public Usermod {
uint8_t getActiveRelayCount() { uint8_t getActiveRelayCount() {
uint8_t count = 0; uint8_t count = 0;
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) if (_relay[i].pin>=0) count++; for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) if (_relay[i].pin>=0) count++;
return count; return count;
} }
@ -268,7 +268,7 @@ class MultiRelay : public Usermod {
strcat_P(subuf, PSTR("/relay/#")); strcat_P(subuf, PSTR("/relay/#"));
mqtt->subscribe(subuf, 0); mqtt->subscribe(subuf, 0);
if (HAautodiscovery) publishHomeAssistantAutodiscovery(); if (HAautodiscovery) publishHomeAssistantAutodiscovery();
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin<0) continue; if (_relay[i].pin<0) continue;
publishMqtt(i); //publish current state publishMqtt(i); //publish current state
} }
@ -276,7 +276,7 @@ class MultiRelay : public Usermod {
} }
void publishHomeAssistantAutodiscovery() { void publishHomeAssistantAutodiscovery() {
for (uint8_t i = 0; i < MULTI_RELAY_MAX_RELAYS; i++) { for (int i = 0; i < MULTI_RELAY_MAX_RELAYS; i++) {
char uid[24], json_str[1024], buf[128]; char uid[24], json_str[1024], buf[128];
size_t payload_size; size_t payload_size;
sprintf_P(uid, PSTR("%s_sw%d"), escapedMac.c_str(), i); sprintf_P(uid, PSTR("%s_sw%d"), escapedMac.c_str(), i);
@ -293,8 +293,8 @@ class MultiRelay : public Usermod {
json[F("stat_t")] = "~"; json[F("stat_t")] = "~";
json[F("cmd_t")] = F("~/command"); json[F("cmd_t")] = F("~/command");
json[F("pl_off")] = F("off"); json[F("pl_off")] = "off";
json[F("pl_on")] = F("on"); json[F("pl_on")] = "on";
json[F("uniq_id")] = uid; json[F("uniq_id")] = uid;
strcpy(buf, mqttDeviceTopic); //max length: 33 + 7 = 40 strcpy(buf, mqttDeviceTopic); //max length: 33 + 7 = 40
@ -320,7 +320,7 @@ class MultiRelay : public Usermod {
*/ */
void setup() { void setup() {
// pins retrieved from cfg.json (readFromConfig()) prior to running setup() // pins retrieved from cfg.json (readFromConfig()) prior to running setup()
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin<0) continue; if (_relay[i].pin<0) continue;
if (!pinManager.allocatePin(_relay[i].pin,true, PinOwner::UM_MultiRelay)) { if (!pinManager.allocatePin(_relay[i].pin,true, PinOwner::UM_MultiRelay)) {
_relay[i].pin = -1; // allocation failed _relay[i].pin = -1; // allocation failed
@ -357,7 +357,7 @@ class MultiRelay : public Usermod {
if (_oldMode != offMode) { if (_oldMode != offMode) {
_oldMode = offMode; _oldMode = offMode;
_switchTimerStart = millis(); _switchTimerStart = millis();
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin>=0 && !_relay[i].external) _relay[i].active = true; if (_relay[i].pin>=0 && !_relay[i].external) _relay[i].active = true;
} }
} }
@ -382,7 +382,7 @@ class MultiRelay : public Usermod {
} }
bool handled = false; bool handled = false;
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].button == b && _relay[i].external) { if (_relay[i].button == b && _relay[i].external) {
handled = true; handled = true;
} }
@ -402,8 +402,8 @@ class MultiRelay : public Usermod {
if (buttonLongPressed[b] == buttonPressedBefore[b]) return handled; if (buttonLongPressed[b] == buttonPressedBefore[b]) return handled;
if (now - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce) if (now - buttonPressedTime[b] > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce)
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin>=0 && _relay[i].button == b) { if (_relay[i].button == b) {
switchRelay(i, buttonPressedBefore[b]); switchRelay(i, buttonPressedBefore[b]);
buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state buttonLongPressed[b] = buttonPressedBefore[b]; //save the last "long term" switch state
} }
@ -450,8 +450,8 @@ class MultiRelay : public Usermod {
if (buttonWaitTime[b] && now - buttonWaitTime[b] > 350 && !buttonPressedBefore[b]) { if (buttonWaitTime[b] && now - buttonWaitTime[b] > 350 && !buttonPressedBefore[b]) {
buttonWaitTime[b] = 0; buttonWaitTime[b] = 0;
//shortPressAction(b); //not exposed //shortPressAction(b); //not exposed
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin>=0 && _relay[i].button == b) { if (_relay[i].button == b) {
toggleRelay(i); toggleRelay(i);
} }
} }
@ -468,13 +468,17 @@ class MultiRelay : public Usermod {
if (user.isNull()) if (user.isNull())
user = root.createNestedObject("u"); user = root.createNestedObject("u");
JsonArray infoArr = user.createNestedArray(F("Number of relays")); //name JsonArray infoArr = user.createNestedArray(FPSTR(_name)); //name
infoArr.add(String(getActiveRelayCount())); infoArr.add(String(getActiveRelayCount()));
infoArr.add(F(" relays"));
String uiDomString; String uiDomString;
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin<0 || !_relay[i].external) continue; if (_relay[i].pin<0 || !_relay[i].external) continue;
uiDomString = F("<button class=\"btn\" onclick=\"requestJson({"); uiDomString = F("Relay "); uiDomString += i;
JsonArray infoArr = user.createNestedArray(uiDomString); // timer value
uiDomString = F("<button class=\"btn btn-xs\" onclick=\"requestJson({");
uiDomString += FPSTR(_name); uiDomString += FPSTR(_name);
uiDomString += F(":{"); uiDomString += F(":{");
uiDomString += FPSTR(_relay_str); uiDomString += FPSTR(_relay_str);
@ -483,12 +487,10 @@ class MultiRelay : public Usermod {
uiDomString += F(",on:"); uiDomString += F(",on:");
uiDomString += _relay[i].state ? "false" : "true"; uiDomString += _relay[i].state ? "false" : "true";
uiDomString += F("}});\">"); uiDomString += F("}});\">");
uiDomString += F("Relay "); uiDomString += F("<i class=\"icons");
uiDomString += i; uiDomString += _relay[i].state ? F(" on") : F(" off");
uiDomString += F(" <i class=\"icons\">&#xe08f;</i></button>"); uiDomString += F("\">&#xe08f;</i></button>");
JsonArray infoArr = user.createNestedArray(uiDomString); // timer value infoArr.add(uiDomString);
infoArr.add(_relay[i].state ? "on" : "off");
} }
} }
} }
@ -505,7 +507,7 @@ class MultiRelay : public Usermod {
} }
#if MULTI_RELAY_MAX_RELAYS > 1 #if MULTI_RELAY_MAX_RELAYS > 1
JsonArray rel_arr = multiRelay.createNestedArray(F("relays")); JsonArray rel_arr = multiRelay.createNestedArray(F("relays"));
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin < 0) continue; if (_relay[i].pin < 0) continue;
JsonObject relay = rel_arr.createNestedObject(); JsonObject relay = rel_arr.createNestedObject();
relay[FPSTR(_relay_str)] = i; relay[FPSTR(_relay_str)] = i;
@ -525,14 +527,24 @@ class MultiRelay : public Usermod {
if (!initDone || !enabled) return; // prevent crash on boot applyPreset() if (!initDone || !enabled) return; // prevent crash on boot applyPreset()
JsonObject usermod = root[FPSTR(_name)]; JsonObject usermod = root[FPSTR(_name)];
if (!usermod.isNull()) { if (!usermod.isNull()) {
if (usermod["on"].is<bool>() && usermod[FPSTR(_relay_str)].is<int>() && usermod[FPSTR(_relay_str)].as<int>()>=0) { if (usermod[FPSTR(_relay_str)].is<int>() && usermod[FPSTR(_relay_str)].as<int>()>=0) {
switchRelay(usermod[FPSTR(_relay_str)].as<int>(), usermod["on"].as<bool>()); int rly = usermod[FPSTR(_relay_str)].as<int>();
if (usermod["on"].is<bool>()) {
switchRelay(rly, usermod["on"].as<bool>());
} else if (usermod["on"].is<const char*>() && usermod["on"].as<const char*>()[0] == 't') {
toggleRelay(rly);
}
} }
} else if (root[FPSTR(_name)].is<JsonArray>()) { } else if (root[FPSTR(_name)].is<JsonArray>()) {
JsonArray relays = root[FPSTR(_name)].as<JsonArray>(); JsonArray relays = root[FPSTR(_name)].as<JsonArray>();
for (JsonVariant r : relays) { for (JsonVariant r : relays) {
if (r["on"].is<bool>() && r[FPSTR(_relay_str)].is<int>() && r[FPSTR(_relay_str)].as<int>()>=0) { if (r[FPSTR(_relay_str)].is<int>() && r[FPSTR(_relay_str)].as<int>()>=0) {
switchRelay(r[FPSTR(_relay_str)].as<int>(), r["on"].as<bool>()); int rly = r[FPSTR(_relay_str)].as<int>();
if (r["on"].is<bool>()) {
switchRelay(rly, r["on"].as<bool>());
} else if (r["on"].is<const char*>() && r["on"].as<const char*>()[0] == 't') {
toggleRelay(rly);
}
} }
} }
} }
@ -546,7 +558,7 @@ class MultiRelay : public Usermod {
top[FPSTR(_enabled)] = enabled; top[FPSTR(_enabled)] = enabled;
top[FPSTR(_broadcast)] = periodicBroadcastSec; top[FPSTR(_broadcast)] = periodicBroadcastSec;
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
String parName = FPSTR(_relay_str); parName += '-'; parName += i; String parName = FPSTR(_relay_str); parName += '-'; parName += i;
JsonObject relay = top.createNestedObject(parName); JsonObject relay = top.createNestedObject(parName);
relay["pin"] = _relay[i].pin; relay["pin"] = _relay[i].pin;
@ -580,7 +592,7 @@ class MultiRelay : public Usermod {
periodicBroadcastSec = min(900,max(0,(int)periodicBroadcastSec)); periodicBroadcastSec = min(900,max(0,(int)periodicBroadcastSec));
HAautodiscovery = top[FPSTR(_HAautodiscovery)] | HAautodiscovery; HAautodiscovery = top[FPSTR(_HAautodiscovery)] | HAautodiscovery;
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
String parName = FPSTR(_relay_str); parName += '-'; parName += i; String parName = FPSTR(_relay_str); parName += '-'; parName += i;
oldPin[i] = _relay[i].pin; oldPin[i] = _relay[i].pin;
_relay[i].pin = top[parName]["pin"] | _relay[i].pin; _relay[i].pin = top[parName]["pin"] | _relay[i].pin;
@ -604,12 +616,12 @@ class MultiRelay : public Usermod {
DEBUG_PRINTLN(F(" config loaded.")); DEBUG_PRINTLN(F(" config loaded."));
} else { } else {
// deallocate all pins 1st // deallocate all pins 1st
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++)
if (oldPin[i]>=0) { if (oldPin[i]>=0) {
pinManager.deallocatePin(oldPin[i], PinOwner::UM_MultiRelay); pinManager.deallocatePin(oldPin[i], PinOwner::UM_MultiRelay);
} }
// allocate new pins // allocate new pins
for (uint8_t i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
if (_relay[i].pin>=0 && pinManager.allocatePin(_relay[i].pin, true, PinOwner::UM_MultiRelay)) { if (_relay[i].pin>=0 && pinManager.allocatePin(_relay[i].pin, true, PinOwner::UM_MultiRelay)) {
if (!_relay[i].external) { if (!_relay[i].external) {
_relay[i].state = !offMode; _relay[i].state = !offMode;

View File

@ -96,7 +96,7 @@ class StairwayWipeUsermod : public Usermod {
resetTimebase(); //make sure wipe starts from beginning resetTimebase(); //make sure wipe starts from beginning
//set wipe direction //set wipe direction
WS2812FX::Segment& seg = strip.getSegment(0); Segment& seg = strip.getSegment(0);
bool doReverse = (userVar0 == 2); bool doReverse = (userVar0 == 2);
seg.setOption(1, doReverse); seg.setOption(1, doReverse);

View File

@ -89,7 +89,7 @@ void startWipe()
resetTimebase(); //make sure wipe starts from beginning resetTimebase(); //make sure wipe starts from beginning
//set wipe direction //set wipe direction
WS2812FX::Segment& seg = strip.getSegment(0); Segment& seg = strip.getSegment(0);
bool doReverse = (userVar0 == 2); bool doReverse = (userVar0 == 2);
seg.setOption(1, doReverse); seg.setOption(1, doReverse);

View File

@ -1,20 +1,17 @@
# Auto Save # Auto Save
v2 Usermod to automatically save settings v2 Usermod to automatically save settings
to preset number AUTOSAVE_PRESET_NUM after a change to any of to preset number AUTOSAVE_PRESET_NUM after a change to any of:
* brightness * brightness
* effect speed * effect speed
* effect intensity * effect intensity
* mode (effect) * mode (effect)
* palette * palette
but it will wait for AUTOSAVE_SETTLE_MS milliseconds, a "settle" but it will wait for AUTOSAVE_AFTER_SEC seconds,
period in case there are other changes (any change will a "settle" period in case there are other changes (any change will extend the "settle" window).
extend the "settle" window).
It will additionally load preset AUTOSAVE_PRESET_NUM at startup. It will additionally load preset AUTOSAVE_PRESET_NUM at startup during the first `loop()`.
during the first `loop()`. Reasoning below.
AutoSaveUsermod is standalone, but if FourLineDisplayUsermod is installed, it will notify the user of the saved changes. AutoSaveUsermod is standalone, but if FourLineDisplayUsermod is installed, it will notify the user of the saved changes.
@ -29,9 +26,20 @@ This file should be placed in the same directory as `platformio.ini`.
### Define Your Options ### Define Your Options
* `USERMOD_AUTO_SAVE` - define this to have this the Auto Save usermod included wled00\usermods_list.cpp * `USERMOD_AUTO_SAVE` - define this to have this the Auto Save usermod included wled00\usermods_list.cpp
* `USERMOD_FOUR_LINE_DISPLAY` - define this to have this the Four Line Display mod included wled00\usermods_list.cpp - also tells this usermod that the display is available (see the Four Line Display usermod `readme.md` for more details) * `AUTOSAVE_AFTER_SEC` - define the delay time after the settings auto-saving routine should be executed
* `AUTOSAVE_PRESET_NUM` - define the preset number used by autosave usermod
* `USERMOD_AUTO_SAVE_ON_BOOT` - define if autosave should be enabled on boot
* `USERMOD_FOUR_LINE_DISPLAY` - define this to have this the Four Line Display mod included wled00\usermods_list.cpp
also tells this usermod that the display is available
(see the Four Line Display usermod `readme.md` for more details)
You can configure auto-save parameters using Usermods settings page. Example to add in platformio_override:
-D USERMOD_AUTO_SAVE
-D AUTOSAVE_AFTER_SEC=10
-D AUTOSAVE_PRESET_NUM=100
-D USERMOD_AUTO_SAVE_ON_BOOT=true
You can also configure auto-save parameters using Usermods settings page.
### PlatformIO requirements ### PlatformIO requirements

View File

@ -33,9 +33,23 @@ class AutoSaveUsermod : public Usermod {
bool enabled = true; bool enabled = true;
// configurable parameters // configurable parameters
#ifdef AUTOSAVE_AFTER_SEC
uint16_t autoSaveAfterSec = AUTOSAVE_AFTER_SEC;
#else
uint16_t autoSaveAfterSec = 15; // 15s by default uint16_t autoSaveAfterSec = 15; // 15s by default
#endif
#ifdef AUTOSAVE_PRESET_NUM
uint8_t autoSavePreset = AUTOSAVE_PRESET_NUM;
#else
uint8_t autoSavePreset = 250; // last possible preset uint8_t autoSavePreset = 250; // last possible preset
#endif
#ifdef USERMOD_AUTO_SAVE_ON_BOOT
bool applyAutoSaveOnBoot = USERMOD_AUTO_SAVE_ON_BOOT;
#else
bool applyAutoSaveOnBoot = false; // do we load auto-saved preset on boot? bool applyAutoSaveOnBoot = false; // do we load auto-saved preset on boot?
#endif
// If we've detected the need to auto save, this will be non zero. // If we've detected the need to auto save, this will be non zero.
unsigned long autoSaveAfter = 0; unsigned long autoSaveAfter = 0;
@ -64,6 +78,7 @@ class AutoSaveUsermod : public Usermod {
PSTR("~ %02d-%02d %02d:%02d:%02d ~"), PSTR("~ %02d-%02d %02d:%02d:%02d ~"),
month(localTime), day(localTime), month(localTime), day(localTime),
hour(localTime), minute(localTime), second(localTime)); hour(localTime), minute(localTime), second(localTime));
cacheInvalidate++; // force reload of presets
savePreset(autoSavePreset, presetNameBuffer); savePreset(autoSavePreset, presetNameBuffer);
} }

View File

@ -24,54 +24,31 @@
// //
//The SCL and SDA pins are defined here. //The SCL and SDA pins are defined here.
#ifdef ARDUINO_ARCH_ESP32
#define HW_PIN_SCL 22
#define HW_PIN_SDA 21
#define HW_PIN_CLOCKSPI 18
#define HW_PIN_DATASPI 23
#ifndef FLD_PIN_SCL #ifndef FLD_PIN_SCL
#define FLD_PIN_SCL 22 #define FLD_PIN_SCL i2c_scl
#endif #endif
#ifndef FLD_PIN_SDA #ifndef FLD_PIN_SDA
#define FLD_PIN_SDA 21 #define FLD_PIN_SDA i2c_sda
#endif #endif
#ifndef FLD_PIN_CLOCKSPI #ifndef FLD_PIN_CLOCKSPI
#define FLD_PIN_CLOCKSPI 18 #define FLD_PIN_CLOCKSPI spi_sclk
#endif #endif
#ifndef FLD_PIN_DATASPI #ifndef FLD_PIN_DATASPI
#define FLD_PIN_DATASPI 23 #define FLD_PIN_DATASPI spi_mosi
#endif
#ifndef FLD_PIN_DC
#define FLD_PIN_DC 19
#endif #endif
#ifndef FLD_PIN_CS #ifndef FLD_PIN_CS
#define FLD_PIN_CS 5 #define FLD_PIN_CS spi_cs
#endif
#ifdef ARDUINO_ARCH_ESP32
#ifndef FLD_PIN_DC
#define FLD_PIN_DC 19
#endif #endif
#ifndef FLD_PIN_RESET #ifndef FLD_PIN_RESET
#define FLD_PIN_RESET 26 #define FLD_PIN_RESET 26
#endif #endif
#else #else
#define HW_PIN_SCL 5
#define HW_PIN_SDA 4
#define HW_PIN_CLOCKSPI 14
#define HW_PIN_DATASPI 13
#ifndef FLD_PIN_SCL
#define FLD_PIN_SCL 5
#endif
#ifndef FLD_PIN_SDA
#define FLD_PIN_SDA 4
#endif
#ifndef FLD_PIN_CLOCKSPI
#define FLD_PIN_CLOCKSPI 14
#endif
#ifndef FLD_PIN_DATASPI
#define FLD_PIN_DATASPI 13
#endif
#ifndef FLD_PIN_DC #ifndef FLD_PIN_DC
#define FLD_PIN_DC 12 #define FLD_PIN_DC 12
#endif
#ifndef FLD_PIN_CS
#define FLD_PIN_CS 15
#endif #endif
#ifndef FLD_PIN_RESET #ifndef FLD_PIN_RESET
#define FLD_PIN_RESET 16 #define FLD_PIN_RESET 16
@ -192,13 +169,14 @@ class FourLineDisplayUsermod : public Usermod {
bool isHW; bool isHW;
PinOwner po = PinOwner::UM_FourLineDisplay; PinOwner po = PinOwner::UM_FourLineDisplay;
if (type == SSD1306_SPI || type == SSD1306_SPI64) { if (type == SSD1306_SPI || type == SSD1306_SPI64) {
isHW = (ioPin[0]==HW_PIN_CLOCKSPI && ioPin[1]==HW_PIN_DATASPI); isHW = (ioPin[0]==spi_sclk && ioPin[1]==spi_mosi);
if (isHW) po = PinOwner::HW_SPI; // allow multiple allocations of HW I2C bus pins
PinManagerPinType pins[5] = { { ioPin[0], true }, { ioPin[1], true }, { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true }}; PinManagerPinType pins[5] = { { ioPin[0], true }, { ioPin[1], true }, { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true }};
if (!pinManager.allocateMultiplePins(pins, 5, po)) { type=NONE; return; } if (!pinManager.allocateMultiplePins(pins, 5, po)) { type=NONE; return; }
} else { } else {
isHW = (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA); isHW = (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda);
if (isHW) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } }; PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } };
if (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; } if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; }
} }
@ -718,8 +696,14 @@ class FourLineDisplayUsermod : public Usermod {
if (pinsChanged || type!=newType) { if (pinsChanged || type!=newType) {
if (type != NONE) delete u8x8; if (type != NONE) delete u8x8;
PinOwner po = PinOwner::UM_FourLineDisplay; PinOwner po = PinOwner::UM_FourLineDisplay;
if (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
pinManager.deallocateMultiplePins((const uint8_t *)ioPin, (type == SSD1306_SPI || type == SSD1306_SPI64) ? 5 : 2, po); if (isSPI) {
if (ioPin[0]==spi_sclk && ioPin[1]==spi_mosi) po = PinOwner::HW_SPI; // allow multiple allocations of HW SPI bus pins
pinManager.deallocateMultiplePins((const uint8_t *)ioPin, 5, po);
} else {
if (ioPin[0]==i2c_scl && ioPin[1]==i2c_sda) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
pinManager.deallocateMultiplePins((const uint8_t *)ioPin, 2, po);
}
for (byte i=0; i<5; i++) ioPin[i] = newPin[i]; for (byte i=0; i<5; i++) ioPin[i] = newPin[i];
if (ioPin[0]<0 || ioPin[1]<0) { // data & clock must be > -1 if (ioPin[0]<0 || ioPin[1]<0) { // data & clock must be > -1
type = NONE; type = NONE;

View File

@ -25,54 +25,32 @@
// //
//The SCL and SDA pins are defined here. //The SCL and SDA pins are defined here.
#ifdef ARDUINO_ARCH_ESP32
#define HW_PIN_SCL 22
#define HW_PIN_SDA 21
#define HW_PIN_CLOCKSPI 18
#define HW_PIN_DATASPI 23
#ifndef FLD_PIN_SCL #ifndef FLD_PIN_SCL
#define FLD_PIN_SCL 22 #define FLD_PIN_SCL i2c_scl
#endif #endif
#ifndef FLD_PIN_SDA #ifndef FLD_PIN_SDA
#define FLD_PIN_SDA 21 #define FLD_PIN_SDA i2c_sda
#endif #endif
#ifndef FLD_PIN_CLOCKSPI #ifndef FLD_PIN_CLOCKSPI
#define FLD_PIN_CLOCKSPI 18 #define FLD_PIN_CLOCKSPI spi_sclk
#endif #endif
#ifndef FLD_PIN_DATASPI #ifndef FLD_PIN_DATASPI
#define FLD_PIN_DATASPI 23 #define FLD_PIN_DATASPI spi_mosi
#endif
#ifndef FLD_PIN_DC
#define FLD_PIN_DC 19
#endif #endif
#ifndef FLD_PIN_CS #ifndef FLD_PIN_CS
#define FLD_PIN_CS 5 #define FLD_PIN_CS spi_cs
#endif
#ifdef ARDUINO_ARCH_ESP32
#ifndef FLD_PIN_DC
#define FLD_PIN_DC 19
#endif #endif
#ifndef FLD_PIN_RESET #ifndef FLD_PIN_RESET
#define FLD_PIN_RESET 26 #define FLD_PIN_RESET 26
#endif #endif
#else #else
#define HW_PIN_SCL 5
#define HW_PIN_SDA 4
#define HW_PIN_CLOCKSPI 14
#define HW_PIN_DATASPI 13
#ifndef FLD_PIN_SCL
#define FLD_PIN_SCL 5
#endif
#ifndef FLD_PIN_SDA
#define FLD_PIN_SDA 4
#endif
#ifndef FLD_PIN_CLOCKSPI
#define FLD_PIN_CLOCKSPI 14
#endif
#ifndef FLD_PIN_DATASPI
#define FLD_PIN_DATASPI 13
#endif
#ifndef FLD_PIN_DC #ifndef FLD_PIN_DC
#define FLD_PIN_DC 12 #define FLD_PIN_DC 12
#endif
#ifndef FLD_PIN_CS
#define FLD_PIN_CS 15
#endif #endif
#ifndef FLD_PIN_RESET #ifndef FLD_PIN_RESET
#define FLD_PIN_RESET 16 #define FLD_PIN_RESET 16
@ -92,13 +70,20 @@
#define SCREEN_TIMEOUT_MS 60*1000 // 1 min #define SCREEN_TIMEOUT_MS 60*1000 // 1 min
// Minimum time between redrawing screen in ms // Minimum time between redrawing screen in ms
#define USER_LOOP_REFRESH_RATE_MS 1000 #define REFRESH_RATE_MS 1000
// Extra char (+1) for null // Extra char (+1) for null
#define LINE_BUFFER_SIZE 16+1 #define LINE_BUFFER_SIZE 16+1
#define MAX_JSON_CHARS 19+1 #define MAX_JSON_CHARS 19+1
#define MAX_MODE_LINE_SPACE 13+1 #define MAX_MODE_LINE_SPACE 13+1
#ifdef ARDUINO_ARCH_ESP32
static TaskHandle_t Display_Task = nullptr;
void DisplayTaskCode(void * parameter);
#endif
typedef enum { typedef enum {
NONE = 0, NONE = 0,
SSD1306, // U8X8_SSD1306_128X32_UNIVISION_HW_I2C SSD1306, // U8X8_SSD1306_128X32_UNIVISION_HW_I2C
@ -112,10 +97,15 @@ typedef enum {
class FourLineDisplayUsermod : public Usermod { class FourLineDisplayUsermod : public Usermod {
public:
FourLineDisplayUsermod() { if (!instance) instance = this; }
static FourLineDisplayUsermod* getInstance(void) { return instance; }
private: private:
static FourLineDisplayUsermod *instance;
bool initDone = false; bool initDone = false;
volatile bool drawing = false;
// HW interface & configuration // HW interface & configuration
U8X8 *u8x8 = nullptr; // pointer to U8X8 display object U8X8 *u8x8 = nullptr; // pointer to U8X8 display object
@ -132,7 +122,7 @@ class FourLineDisplayUsermod : public Usermod {
bool flip = false; // flip display 180° bool flip = false; // flip display 180°
uint8_t contrast = 10; // screen contrast uint8_t contrast = 10; // screen contrast
uint8_t lineHeight = 1; // 1 row or 2 rows uint8_t lineHeight = 1; // 1 row or 2 rows
uint16_t refreshRate = USER_LOOP_REFRESH_RATE_MS; // in ms uint16_t refreshRate = REFRESH_RATE_MS; // in ms
uint32_t screenTimeout = SCREEN_TIMEOUT_MS; // in ms uint32_t screenTimeout = SCREEN_TIMEOUT_MS; // in ms
bool sleepMode = true; // allow screen sleep? bool sleepMode = true; // allow screen sleep?
bool clockMode = false; // display clock bool clockMode = false; // display clock
@ -195,6 +185,123 @@ class FourLineDisplayUsermod : public Usermod {
u8x8_cad_EndTransfer(u8x8_struct); u8x8_cad_EndTransfer(u8x8_struct);
} }
/**
* Wrappers for screen drawing
*/
void setFlipMode(uint8_t mode) {
if (type == NONE || !enabled) return;
u8x8->setFlipMode(mode);
}
void setContrast(uint8_t contrast) {
if (type == NONE || !enabled) return;
u8x8->setContrast(contrast);
}
void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) {
if (type == NONE || !enabled) return;
u8x8->setFont(u8x8_font_chroma48medium8_r);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
else u8x8->drawString(col, row, string);
}
void draw2x2String(uint8_t col, uint8_t row, const char *string) {
if (type == NONE || !enabled) return;
u8x8->setFont(u8x8_font_chroma48medium8_r);
u8x8->draw2x2String(col, row, string);
}
void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) {
if (type == NONE || !enabled) return;
u8x8->setFont(font);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph);
else u8x8->drawGlyph(col, row, glyph);
}
void draw2x2Glyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font) {
if (type == NONE || !enabled) return;
u8x8->setFont(font);
u8x8->draw2x2Glyph(col, row, glyph);
}
uint8_t getCols() {
if (type==NONE || !enabled) return 0;
return u8x8->getCols();
}
void clear() {
if (type == NONE || !enabled) return;
u8x8->clear();
}
void setPowerSave(uint8_t save) {
if (type == NONE || !enabled) return;
u8x8->setPowerSave(save);
}
void center(String &line, uint8_t width) {
int len = line.length();
if (len<width) for (byte i=(width-len)/2; i>0; i--) line = ' ' + line;
for (byte i=line.length(); i<width; i++) line += ' ';
}
void draw2x2GlyphIcons() {
if (lineHeight == 2) {
drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x2, true); //brightness icon
drawGlyph( 5, 0, 2, u8x8_4LineDisplay_WLED_icons_2x2, true); //speed icon
drawGlyph( 9, 0, 3, u8x8_4LineDisplay_WLED_icons_2x2, true); //intensity icon
drawGlyph(14, 2*lineHeight, 4, u8x8_4LineDisplay_WLED_icons_2x2, true); //palette icon
drawGlyph(14, 3*lineHeight, 5, u8x8_4LineDisplay_WLED_icons_2x2, true); //effect icon
} else {
drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x1); //brightness icon
drawGlyph( 5, 0, 2, u8x8_4LineDisplay_WLED_icons_2x1); //speed icon
drawGlyph( 9, 0, 3, u8x8_4LineDisplay_WLED_icons_2x1); //intensity icon
drawGlyph(15, 2, 4, u8x8_4LineDisplay_WLED_icons_1x1); //palette icon
drawGlyph(15, 3, 5, u8x8_4LineDisplay_WLED_icons_1x1); //effect icon
}
}
/**
* Display the current date and time in large characters
* on the middle rows. Based 24 or 12 hour depending on
* the useAMPM configuration.
*/
void showTime() {
if (type == NONE || !enabled || !displayTurnedOff) return;
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
char lineBuffer[LINE_BUFFER_SIZE];
static byte lastSecond;
byte secondCurrent = second(localTime);
byte minuteCurrent = minute(localTime);
byte hourCurrent = hour(localTime);
if (knownMinute != minuteCurrent) { //only redraw clock if it has changed
//updateLocalTime();
byte AmPmHour = hourCurrent;
boolean isitAM = true;
if (useAMPM) {
if (AmPmHour > 11) { AmPmHour -= 12; isitAM = false; }
if (AmPmHour == 0) { AmPmHour = 12; }
}
if (knownHour != hourCurrent) {
// only update date when hour changes
sprintf_P(lineBuffer, PSTR("%s %2d "), monthShortStr(month(localTime)), day(localTime));
draw2x2String(2, lineHeight==1 ? 0 : lineHeight, lineBuffer); // adjust for 8 line displays, draw month and day
}
sprintf_P(lineBuffer,PSTR("%2d:%02d"), (useAMPM ? AmPmHour : hourCurrent), minuteCurrent);
draw2x2String(2, lineHeight*2, lineBuffer); //draw hour, min. blink ":" depending on odd/even seconds
if (useAMPM) drawString(12, lineHeight*2, (isitAM ? "AM" : "PM"), true); //draw am/pm if using 12 time
drawStatusIcons(); //icons power, wifi, timer, etc
knownMinute = minuteCurrent;
knownHour = hourCurrent;
}
if (showSeconds && secondCurrent != lastSecond) {
lastSecond = secondCurrent;
draw2x2String(6, lineHeight*2, secondCurrent%2 ? " " : ":");
sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
}
drawing = false;
}
public: public:
// gets called once at boot. Do all initialization that doesn't depend on // gets called once at boot. Do all initialization that doesn't depend on
@ -205,13 +312,32 @@ class FourLineDisplayUsermod : public Usermod {
bool isHW, isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64); bool isHW, isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
PinOwner po = PinOwner::UM_FourLineDisplay; PinOwner po = PinOwner::UM_FourLineDisplay;
if (isSPI) { if (isSPI) {
isHW = (ioPin[0]==HW_PIN_CLOCKSPI && ioPin[1]==HW_PIN_DATASPI); uint8_t hw_sclk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
PinManagerPinType pins[5] = { { ioPin[0], true }, { ioPin[1], true }, { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true }}; uint8_t hw_mosi = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
if (!pinManager.allocateMultiplePins(pins, 5, po)) { type=NONE; return; } if (ioPin[0] < 0 || ioPin[1] < 0) {
} else { ioPin[0] = hw_sclk;
isHW = (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA); ioPin[1] = hw_mosi;
}
isHW = (ioPin[0]==hw_sclk && ioPin[1]==hw_mosi);
PinManagerPinType cspins[3] = { { ioPin[2], true }, { ioPin[3], true }, { ioPin[4], true } };
if (!pinManager.allocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay)) { type=NONE; return; }
if (isHW) po = PinOwner::HW_SPI; // allow multiple allocations of HW I2C bus pins
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true } };
if (!pinManager.allocateMultiplePins(pins, 2, po)) {
pinManager.deallocateMultiplePins(cspins, 3, PinOwner::UM_FourLineDisplay);
type = NONE;
return;
}
} else {
uint8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
uint8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
if (ioPin[0] < 0 || ioPin[1] < 0) {
ioPin[0] = hw_scl;
ioPin[1] = hw_sda;
}
isHW = (ioPin[0]==hw_scl && ioPin[1]==hw_sda);
if (isHW) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
PinManagerPinType pins[2] = { {ioPin[0], true }, { ioPin[1], true } }; PinManagerPinType pins[2] = { {ioPin[0], true }, { ioPin[1], true } };
if (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins
if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; } if (!pinManager.allocateMultiplePins(pins, 2, po)) { type=NONE; return; }
} }
@ -276,10 +402,12 @@ class FourLineDisplayUsermod : public Usermod {
else u8x8 = (U8X8 *) new U8X8_SSD1305_128X64_ADAFRUIT_HW_I2C(U8X8_PIN_NONE, ioPin[0], ioPin[1]); // Pins are Reset, SCL, SDA else u8x8 = (U8X8 *) new U8X8_SSD1305_128X64_ADAFRUIT_HW_I2C(U8X8_PIN_NONE, ioPin[0], ioPin[1]); // Pins are Reset, SCL, SDA
break; break;
case SSD1306_SPI: case SSD1306_SPI:
// u8x8 uses global SPI variable that is attached to VSPI bus on ESP32
if (!isHW) u8x8 = (U8X8 *) new U8X8_SSD1306_128X32_UNIVISION_4W_SW_SPI(ioPin[0], ioPin[1], ioPin[2], ioPin[3], ioPin[4]); if (!isHW) u8x8 = (U8X8 *) new U8X8_SSD1306_128X32_UNIVISION_4W_SW_SPI(ioPin[0], ioPin[1], ioPin[2], ioPin[3], ioPin[4]);
else u8x8 = (U8X8 *) new U8X8_SSD1306_128X32_UNIVISION_4W_HW_SPI(ioPin[2], ioPin[3], ioPin[4]); // Pins are cs, dc, reset else u8x8 = (U8X8 *) new U8X8_SSD1306_128X32_UNIVISION_4W_HW_SPI(ioPin[2], ioPin[3], ioPin[4]); // Pins are cs, dc, reset
break; break;
case SSD1306_SPI64: case SSD1306_SPI64:
// u8x8 uses global SPI variable that is attached to VSPI bus on ESP32
if (!isHW) u8x8 = (U8X8 *) new U8X8_SSD1306_128X64_NONAME_4W_SW_SPI(ioPin[0], ioPin[1], ioPin[2], ioPin[3], ioPin[4]); if (!isHW) u8x8 = (U8X8 *) new U8X8_SSD1306_128X64_NONAME_4W_SW_SPI(ioPin[0], ioPin[1], ioPin[2], ioPin[3], ioPin[4]);
else u8x8 = (U8X8 *) new U8X8_SSD1306_128X64_NONAME_4W_HW_SPI(ioPin[2], ioPin[3], ioPin[4]); // Pins are cs, dc, reset else u8x8 = (U8X8 *) new U8X8_SSD1306_128X64_NONAME_4W_HW_SPI(ioPin[2], ioPin[3], ioPin[4]); // Pins are cs, dc, reset
break; break;
@ -304,6 +432,7 @@ class FourLineDisplayUsermod : public Usermod {
setPowerSave(0); setPowerSave(0);
//drawString(0, 0, "Loading..."); //drawString(0, 0, "Loading...");
overlayLogo(3500); overlayLogo(3500);
onUpdateBegin(false); // create Display task
initDone = true; initDone = true;
} }
@ -319,63 +448,13 @@ class FourLineDisplayUsermod : public Usermod {
* Da loop. * Da loop.
*/ */
void loop() { void loop() {
#ifndef ARDUINO_ARCH_ESP32
if (!enabled || strip.isUpdating()) return; if (!enabled || strip.isUpdating()) return;
unsigned long now = millis(); unsigned long now = millis();
if (now < nextUpdate) return; if (now < nextUpdate) return;
nextUpdate = now + ((displayTurnedOff && clockMode && showSeconds) ? 1000 : refreshRate); nextUpdate = now + ((displayTurnedOff && clockMode && showSeconds) ? 1000 : refreshRate);
redraw(false); redraw(false);
} #endif
/**
* Wrappers for screen drawing
*/
void setFlipMode(uint8_t mode) {
if (type == NONE || !enabled) return;
u8x8->setFlipMode(mode);
}
void setContrast(uint8_t contrast) {
if (type == NONE || !enabled) return;
u8x8->setContrast(contrast);
}
void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) {
if (type == NONE || !enabled) return;
u8x8->setFont(u8x8_font_chroma48medium8_r);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
else u8x8->drawString(col, row, string);
}
void draw2x2String(uint8_t col, uint8_t row, const char *string) {
if (type == NONE || !enabled) return;
u8x8->setFont(u8x8_font_chroma48medium8_r);
u8x8->draw2x2String(col, row, string);
}
void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) {
if (type == NONE || !enabled) return;
u8x8->setFont(font);
if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph);
else u8x8->drawGlyph(col, row, glyph);
}
void draw2x2Glyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font) {
if (type == NONE || !enabled) return;
u8x8->setFont(font);
u8x8->draw2x2Glyph(col, row, glyph);
}
uint8_t getCols() {
if (type==NONE || !enabled) return 0;
return u8x8->getCols();
}
void clear() {
if (type == NONE || !enabled) return;
u8x8->clear();
}
void setPowerSave(uint8_t save) {
if (type == NONE || !enabled) return;
u8x8->setPowerSave(save);
}
void center(String &line, uint8_t width) {
int len = line.length();
if (len<width) for (byte i=(width-len)/2; i>0; i--) line = ' ' + line;
for (byte i=line.length(); i<width; i++) line += ' ';
} }
//function to update lastredraw //function to update lastredraw
@ -404,6 +483,8 @@ class FourLineDisplayUsermod : public Usermod {
} }
} }
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
if (apActive && WLED_WIFI_CONFIGURED && now<15000) { if (apActive && WLED_WIFI_CONFIGURED && now<15000) {
knownSsid = apSSID; knownSsid = apSSID;
networkOverlay(PSTR("NETWORK INFO"),30000); networkOverlay(PSTR("NETWORK INFO"),30000);
@ -529,22 +610,6 @@ class FourLineDisplayUsermod : public Usermod {
} }
} }
void draw2x2GlyphIcons() {
if (lineHeight == 2) {
drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x2, true); //brightness icon
drawGlyph( 5, 0, 2, u8x8_4LineDisplay_WLED_icons_2x2, true); //speed icon
drawGlyph( 9, 0, 3, u8x8_4LineDisplay_WLED_icons_2x2, true); //intensity icon
drawGlyph(14, 2*lineHeight, 4, u8x8_4LineDisplay_WLED_icons_2x2, true); //palette icon
drawGlyph(14, 3*lineHeight, 5, u8x8_4LineDisplay_WLED_icons_2x2, true); //effect icon
} else {
drawGlyph( 1, 0, 1, u8x8_4LineDisplay_WLED_icons_2x1); //brightness icon
drawGlyph( 5, 0, 2, u8x8_4LineDisplay_WLED_icons_2x1); //speed icon
drawGlyph( 9, 0, 3, u8x8_4LineDisplay_WLED_icons_2x1); //intensity icon
drawGlyph(15, 2, 4, u8x8_4LineDisplay_WLED_icons_1x1); //palette icon
drawGlyph(15, 3, 5, u8x8_4LineDisplay_WLED_icons_1x1); //effect icon
}
}
void drawStatusIcons() { void drawStatusIcons() {
uint8_t col = 15; uint8_t col = 15;
uint8_t row = 0; uint8_t row = 0;
@ -581,6 +646,10 @@ class FourLineDisplayUsermod : public Usermod {
// remove "* " from dynamic palettes // remove "* " from dynamic palettes
for (byte i=2; i<=printedChars; i++) lineBuffer[i-2] = lineBuffer[i]; //include '\0' for (byte i=2; i<=printedChars; i++) lineBuffer[i-2] = lineBuffer[i]; //include '\0'
printedChars -= 2; printedChars -= 2;
} else if ((lineBuffer[0]==' ' && lineBuffer[1]>127)) {
// remove note symbol from effect names
for (byte i=5; i<=printedChars; i++) lineBuffer[i-5] = lineBuffer[i]; //include '\0'
printedChars -= 5;
} }
if (lineHeight == 2) { // use this code for 8 line display if (lineHeight == 2) { // use this code for 8 line display
char smallBuffer1[MAX_MODE_LINE_SPACE]; char smallBuffer1[MAX_MODE_LINE_SPACE];
@ -635,10 +704,14 @@ class FourLineDisplayUsermod : public Usermod {
bool wakeDisplay() { bool wakeDisplay() {
if (type == NONE || !enabled) return false; if (type == NONE || !enabled) return false;
if (displayTurnedOff) { if (displayTurnedOff) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
clear(); clear();
// Turn the display back on // Turn the display back on
sleepOrClock(false); sleepOrClock(false);
//lastRedraw = millis(); //lastRedraw = millis();
drawing = false;
return true; return true;
} }
return false; return false;
@ -650,6 +723,9 @@ class FourLineDisplayUsermod : public Usermod {
* Used in Rotary Encoder usermod. * Used in Rotary Encoder usermod.
*/ */
void overlay(const char* line1, long showHowLong, byte glyphType) { void overlay(const char* line1, long showHowLong, byte glyphType) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
// Turn the display back on // Turn the display back on
if (!wakeDisplay()) clear(); if (!wakeDisplay()) clear();
// Print the overlay // Print the overlay
@ -663,6 +739,7 @@ class FourLineDisplayUsermod : public Usermod {
drawString(0, (glyphType<255?3:0)*lineHeight, buf.c_str()); drawString(0, (glyphType<255?3:0)*lineHeight, buf.c_str());
} }
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false;
} }
/** /**
@ -670,6 +747,9 @@ class FourLineDisplayUsermod : public Usermod {
* Clears the screen and prints. * Clears the screen and prints.
*/ */
void overlayLogo(long showHowLong) { void overlayLogo(long showHowLong) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
// Turn the display back on // Turn the display back on
if (!wakeDisplay()) clear(); if (!wakeDisplay()) clear();
// Print the overlay // Print the overlay
@ -719,6 +799,7 @@ class FourLineDisplayUsermod : public Usermod {
} }
} }
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false;
} }
/** /**
@ -727,6 +808,9 @@ class FourLineDisplayUsermod : public Usermod {
* Used in Auto Save usermod * Used in Auto Save usermod
*/ */
void overlay(const char* line1, const char* line2, long showHowLong) { void overlay(const char* line1, const char* line2, long showHowLong) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
// Turn the display back on // Turn the display back on
if (!wakeDisplay()) clear(); if (!wakeDisplay()) clear();
// Print the overlay // Print the overlay
@ -741,9 +825,14 @@ class FourLineDisplayUsermod : public Usermod {
drawString(0, 2*lineHeight, buf.c_str()); drawString(0, 2*lineHeight, buf.c_str());
} }
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false;
} }
void networkOverlay(const char* line1, long showHowLong) { void networkOverlay(const char* line1, long showHowLong) {
unsigned long now = millis();
while (drawing && millis()-now < 250) delay(1); // wait if someone else is drawing
drawing = true;
String line; String line;
// Turn the display back on // Turn the display back on
if (!wakeDisplay()) clear(); if (!wakeDisplay()) clear();
@ -774,6 +863,7 @@ class FourLineDisplayUsermod : public Usermod {
center(line, getCols()); center(line, getCols());
drawString(0, lineHeight*3, line.c_str()); drawString(0, lineHeight*3, line.c_str());
overlayUntil = millis() + showHowLong; overlayUntil = millis() + showHowLong;
drawing = false;
} }
@ -794,52 +884,6 @@ class FourLineDisplayUsermod : public Usermod {
} }
} }
/**
* Display the current date and time in large characters
* on the middle rows. Based 24 or 12 hour depending on
* the useAMPM configuration.
*/
void showTime() {
if (type == NONE || !enabled || !displayTurnedOff) return;
char lineBuffer[LINE_BUFFER_SIZE];
static byte lastSecond;
byte secondCurrent = second(localTime);
byte minuteCurrent = minute(localTime);
byte hourCurrent = hour(localTime);
if (knownMinute != minuteCurrent) { //only redraw clock if it has changed
//updateLocalTime();
byte AmPmHour = hourCurrent;
boolean isitAM = true;
if (useAMPM) {
if (AmPmHour > 11) { AmPmHour -= 12; isitAM = false; }
if (AmPmHour == 0) { AmPmHour = 12; }
}
if (knownHour != hourCurrent) {
// only update date when hour changes
sprintf_P(lineBuffer, PSTR("%s %2d "), monthShortStr(month(localTime)), day(localTime));
draw2x2String(2, lineHeight==1 ? 0 : lineHeight, lineBuffer); // adjust for 8 line displays, draw month and day
}
sprintf_P(lineBuffer,PSTR("%2d:%02d"), (useAMPM ? AmPmHour : hourCurrent), minuteCurrent);
draw2x2String(2, lineHeight*2, lineBuffer); //draw hour, min. blink ":" depending on odd/even seconds
if (useAMPM) drawString(12, lineHeight*2, (isitAM ? "AM" : "PM"), true); //draw am/pm if using 12 time
drawStatusIcons(); //icons power, wifi, timer, etc
knownMinute = minuteCurrent;
knownHour = hourCurrent;
} else {
if (secondCurrent == lastSecond) return;
}
if (showSeconds) {
lastSecond = secondCurrent;
draw2x2String(6, lineHeight*2, secondCurrent%2 ? " " : ":");
sprintf_P(lineBuffer, PSTR("%02d"), secondCurrent);
drawString(12, lineHeight*2+1, lineBuffer, true); // even with double sized rows print seconds in 1 line
}
}
/** /**
* handleButton() can be used to override default button behaviour. Returning true * handleButton() can be used to override default button behaviour. Returning true
* will prevent button working in a default way. * will prevent button working in a default way.
@ -914,6 +958,43 @@ class FourLineDisplayUsermod : public Usermod {
return handled; return handled;
} }
#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
void onUpdateBegin(bool init) {
#ifdef ARDUINO_ARCH_ESP32
if (init && Display_Task) {
vTaskSuspend(Display_Task); // update is about to begin, disable task to prevent crash
} else {
// update has failed or create task requested
if (Display_Task)
vTaskResume(Display_Task);
else
xTaskCreatePinnedToCore(
[](void * par) { // Function to implement the task
// see https://www.freertos.org/vtaskdelayuntil.html
const TickType_t xFrequency = REFRESH_RATE_MS * portTICK_PERIOD_MS / 2;
TickType_t xLastWakeTime = xTaskGetTickCount();
for(;;) {
delay(1); // DO NOT DELETE THIS LINE! It is needed to give the IDLE(0) task enough time and to keep the watchdog happy.
// taskYIELD(), yield(), vTaskDelay() and esp_task_wdt_feed() didn't seem to work.
vTaskDelayUntil(&xLastWakeTime, xFrequency); // release CPU, by doing nothing for REFRESH_RATE_MS millis
FourLineDisplayUsermod::getInstance()->redraw(false);
}
},
"4LD", // Name of the task
3072, // Stack size in words
NULL, // Task input parameter
1, // Priority of the task (not idle)
&Display_Task, // Task handle
ARDUINO_RUNNING_CORE
);
}
#endif
}
/* /*
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API. * addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI. * Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
@ -941,6 +1022,23 @@ class FourLineDisplayUsermod : public Usermod {
// if (!initDone) return; // prevent crash on boot applyPreset() // 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 (-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');"));
}
/* /*
* addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object. * 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) * It will be called by WLED when settings are actually saved (for example, LED settings are saved)
@ -956,17 +1054,32 @@ class FourLineDisplayUsermod : public Usermod {
* I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings! * I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings!
*/ */
void addToConfig(JsonObject& root) { void addToConfig(JsonObject& root) {
// determine if we are using global HW pins (data & clock)
int8_t hw_dta, hw_clk;
if ((type == SSD1306_SPI || type == SSD1306_SPI64)) {
hw_clk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
hw_dta = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
} else {
hw_clk = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
hw_dta = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
}
JsonObject top = root.createNestedObject(FPSTR(_name)); JsonObject top = root.createNestedObject(FPSTR(_name));
top[FPSTR(_enabled)] = enabled; top[FPSTR(_enabled)] = enabled;
JsonArray io_pin = top.createNestedArray("pin"); JsonArray io_pin = top.createNestedArray("pin");
for (byte i=0; i<5; i++) io_pin.add(ioPin[i]); for (int i=0; i<5; i++) {
top["help4Pins"] = F("Clk,Data,CS,DC,RST"); // help for Settings page if (i==0 && ioPin[i]==hw_clk) io_pin.add(-1); // do not store global HW pin
else if (i==1 && ioPin[i]==hw_dta) io_pin.add(-1); // do not store global HW pin
else io_pin.add(ioPin[i]);
}
top["type"] = type; 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(_flip)] = (bool) flip;
top[FPSTR(_contrast)] = contrast; top[FPSTR(_contrast)] = contrast;
top[FPSTR(_contrastFix)] = (bool) contrastFix; top[FPSTR(_contrastFix)] = (bool) contrastFix;
#ifndef ARDUINO_ARCH_ESP32
top[FPSTR(_refreshRate)] = refreshRate; top[FPSTR(_refreshRate)] = refreshRate;
#endif
top[FPSTR(_screenTimeOut)] = screenTimeout/1000; top[FPSTR(_screenTimeOut)] = screenTimeout/1000;
top[FPSTR(_sleepMode)] = (bool) sleepMode; top[FPSTR(_sleepMode)] = (bool) sleepMode;
top[FPSTR(_clockMode)] = (bool) clockMode; top[FPSTR(_clockMode)] = (bool) clockMode;
@ -986,7 +1099,7 @@ class FourLineDisplayUsermod : public Usermod {
bool readFromConfig(JsonObject& root) { bool readFromConfig(JsonObject& root) {
bool needsRedraw = false; bool needsRedraw = false;
DisplayType newType = type; DisplayType newType = type;
int8_t newPin[5]; for (byte i=0; i<5; i++) newPin[i] = ioPin[i]; int8_t oldPin[5]; for (byte i=0; i<5; i++) oldPin[i] = ioPin[i];
JsonObject top = root[FPSTR(_name)]; JsonObject top = root[FPSTR(_name)];
if (top.isNull()) { if (top.isNull()) {
@ -997,11 +1110,13 @@ class FourLineDisplayUsermod : public Usermod {
enabled = top[FPSTR(_enabled)] | enabled; enabled = top[FPSTR(_enabled)] | enabled;
newType = top["type"] | newType; newType = top["type"] | newType;
for (byte i=0; i<5; i++) newPin[i] = top["pin"][i] | ioPin[i]; for (byte i=0; i<5; i++) ioPin[i] = top["pin"][i] | ioPin[i];
flip = top[FPSTR(_flip)] | flip; flip = top[FPSTR(_flip)] | flip;
contrast = top[FPSTR(_contrast)] | contrast; contrast = top[FPSTR(_contrast)] | contrast;
#ifndef ARDUINO_ARCH_ESP32
refreshRate = top[FPSTR(_refreshRate)] | refreshRate; refreshRate = top[FPSTR(_refreshRate)] | refreshRate;
refreshRate = min(5000, max(250, (int)refreshRate)); refreshRate = min(5000, max(250, (int)refreshRate));
#endif
screenTimeout = (top[FPSTR(_screenTimeOut)] | screenTimeout/1000) * 1000; screenTimeout = (top[FPSTR(_screenTimeOut)] | screenTimeout/1000) * 1000;
sleepMode = top[FPSTR(_sleepMode)] | sleepMode; sleepMode = top[FPSTR(_sleepMode)] | sleepMode;
clockMode = top[FPSTR(_clockMode)] | clockMode; clockMode = top[FPSTR(_clockMode)] | clockMode;
@ -1015,24 +1130,31 @@ class FourLineDisplayUsermod : public Usermod {
DEBUG_PRINT(FPSTR(_name)); DEBUG_PRINT(FPSTR(_name));
if (!initDone) { if (!initDone) {
// first run: reading from cfg.json // first run: reading from cfg.json
for (byte i=0; i<5; i++) ioPin[i] = newPin[i];
type = newType; type = newType;
DEBUG_PRINTLN(F(" config loaded.")); DEBUG_PRINTLN(F(" config loaded."));
} else { } else {
DEBUG_PRINTLN(F(" config (re)loaded.")); DEBUG_PRINTLN(F(" config (re)loaded."));
// changing parameters from settings page // changing parameters from settings page
bool pinsChanged = false; bool pinsChanged = false;
for (byte i=0; i<5; i++) if (ioPin[i] != newPin[i]) { pinsChanged = true; break; } for (byte i=0; i<5; i++) if (ioPin[i] != oldPin[i]) { pinsChanged = true; break; }
if (pinsChanged || type!=newType) { if (pinsChanged || type!=newType) {
if (type != NONE) delete u8x8; if (type != NONE) delete u8x8;
PinOwner po = PinOwner::UM_FourLineDisplay; PinOwner po = PinOwner::UM_FourLineDisplay;
if (ioPin[0]==HW_PIN_SCL && ioPin[1]==HW_PIN_SDA) po = PinOwner::HW_I2C; // allow multiple allocations of HW I2C bus pins bool isSPI = (type == SSD1306_SPI || type == SSD1306_SPI64);
pinManager.deallocateMultiplePins((const uint8_t *)ioPin, (type == SSD1306_SPI || type == SSD1306_SPI64) ? 5 : 2, po); if (isSPI) {
for (byte i=0; i<5; i++) ioPin[i] = newPin[i]; pinManager.deallocateMultiplePins((const uint8_t *)(&oldPin[2]), 3, po);
if (ioPin[0]<0 || ioPin[1]<0) { // data & clock must be > -1 uint8_t hw_sclk = spi_sclk<0 ? HW_PIN_CLOCKSPI : spi_sclk;
type = NONE; uint8_t hw_mosi = spi_mosi<0 ? HW_PIN_DATASPI : spi_mosi;
return true; bool isHW = (oldPin[0]==hw_sclk && oldPin[1]==hw_mosi);
} else type = newType; if (isHW) po = PinOwner::HW_SPI;
} else {
uint8_t hw_scl = i2c_scl<0 ? HW_PIN_SCL : i2c_scl;
uint8_t hw_sda = i2c_sda<0 ? HW_PIN_SDA : i2c_sda;
bool isHW = (oldPin[0]==hw_scl && oldPin[1]==hw_sda);
if (isHW) po = PinOwner::HW_I2C;
}
pinManager.deallocateMultiplePins((const uint8_t *)oldPin, 2, po);
type = newType;
setup(); setup();
needsRedraw |= true; needsRedraw |= true;
} else { } else {
@ -1070,3 +1192,5 @@ const char FourLineDisplayUsermod::_clockMode[] PROGMEM = "clockMode";
const char FourLineDisplayUsermod::_showSeconds[] PROGMEM = "showSeconds"; const char FourLineDisplayUsermod::_showSeconds[] PROGMEM = "showSeconds";
const char FourLineDisplayUsermod::_busClkFrequency[] PROGMEM = "i2c-freq-kHz"; const char FourLineDisplayUsermod::_busClkFrequency[] PROGMEM = "i2c-freq-kHz";
const char FourLineDisplayUsermod::_contrastFix[] PROGMEM = "contrastFix"; const char FourLineDisplayUsermod::_contrastFix[] PROGMEM = "contrastFix";
FourLineDisplayUsermod *FourLineDisplayUsermod::instance = nullptr;

View File

@ -162,7 +162,6 @@ public:
break; break;
} }
} }
re_sortModes(palettes_qstrings, palettes_alpha_indexes, strip.getPaletteCount(), skipPaletteCount); re_sortModes(palettes_qstrings, palettes_alpha_indexes, strip.getPaletteCount(), skipPaletteCount);
} }
@ -189,6 +188,7 @@ public:
bool complete = false; bool complete = false;
for (size_t i = 0; i < strlen_P(json); i++) { for (size_t i = 0; i < strlen_P(json); i++) {
singleJsonSymbol = pgm_read_byte_near(json + i); singleJsonSymbol = pgm_read_byte_near(json + i);
if (singleJsonSymbol == '\0') break;
switch (singleJsonSymbol) { switch (singleJsonSymbol) {
case '"': case '"':
insideQuotes = !insideQuotes; insideQuotes = !insideQuotes;
@ -200,18 +200,14 @@ public:
case '[': case '[':
break; break;
case ']': case ']':
complete = true; if (!insideQuotes) complete = true;
break; break;
case ',': case ',':
modeIndex++; if (!insideQuotes) modeIndex++;
default: default:
if (!insideQuotes) { if (!insideQuotes) break;
break;
}
}
if (complete) {
break;
} }
if (complete) break;
} }
return modeStrings; return modeStrings;
} }

View File

@ -16,10 +16,16 @@ This file should be placed in the same directory as `platformio.ini`.
### Define Your Options ### Define Your Options
* `USERMOD_ROTARY_ENCODER_UI` - define this to have this user mod included wled00\usermods_list.cpp * `USERMOD_ROTARY_ENCODER_UI` - define this to have this user mod included wled00\usermods_list.cpp
* `USERMOD_FOUR_LINE_DISPLAY` - define this to have this the Four Line Display mod included wled00\usermods_list.cpp - also tells this usermod that the display is available (see the Four Line Display usermod `readme.md` for more details) * `USERMOD_ROTARY_ENCODER_GPIO` - define the GPIO function (INPUT, INPUT_PULLUP, etc...)
* `USERMOD_FOUR_LINE_DISPLAY` - define this to have this the Four Line Display mod included wled00\usermods_list.cpp
also tells this usermod that the display is available
(see the Four Line Display usermod `readme.md` for more details)
* `ENCODER_DT_PIN` - The encoders DT pin, defaults to 12 * `ENCODER_DT_PIN` - The encoders DT pin, defaults to 12
* `ENCODER_CLK_PIN` - The encoders CLK pin, defaults to 14 * `ENCODER_CLK_PIN` - The encoders CLK pin, defaults to 14
* `ENCODER_SW_PIN` - The encoders SW pin, defaults to 13 * `ENCODER_SW_PIN` - The encoders SW pin, defaults to 13
* `USERMOD_ROTARY_ENCODER_GPIO` - The GPIO functionality:
`INPUT_PULLUP` to use internal pull-up
`INPUT` to use pull-up on the PCB
### PlatformIO requirements ### PlatformIO requirements

View File

@ -97,6 +97,7 @@ public:
*/ */
void setup() void setup()
{ {
DEBUG_PRINTLN(F("Usermod Rotary Encoder init."));
PinManagerPinType pins[3] = { { pinA, false }, { pinB, false }, { pinC, false } }; PinManagerPinType pins[3] = { { pinA, false }, { pinB, false }, { pinC, false } };
if (!pinManager.allocateMultiplePins(pins, 3, PinOwner::UM_RotaryEncoderUI)) { if (!pinManager.allocateMultiplePins(pins, 3, PinOwner::UM_RotaryEncoderUI)) {
// BUG: configuring this usermod with conflicting pins // BUG: configuring this usermod with conflicting pins
@ -109,9 +110,13 @@ public:
return; return;
} }
pinMode(pinA, INPUT_PULLUP); #ifndef USERMOD_ROTARY_ENCODER_GPIO
pinMode(pinB, INPUT_PULLUP); #define USERMOD_ROTARY_ENCODER_GPIO INPUT_PULLUP
pinMode(pinC, INPUT_PULLUP); #endif
pinMode(pinA, USERMOD_ROTARY_ENCODER_GPIO);
pinMode(pinB, USERMOD_ROTARY_ENCODER_GPIO);
pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO);
currentTime = millis(); currentTime = millis();
loopTime = currentTime; loopTime = currentTime;
@ -439,14 +444,11 @@ public:
DEBUG_PRINTLN(F(": No config found. (Using defaults.)")); DEBUG_PRINTLN(F(": No config found. (Using defaults.)"));
return false; return false;
} }
int8_t newDTpin = pinA; int8_t newDTpin = top[FPSTR(_DT_pin)] | pinA;
int8_t newCLKpin = pinB; int8_t newCLKpin = top[FPSTR(_CLK_pin)] | pinB;
int8_t newSWpin = pinC; int8_t newSWpin = top[FPSTR(_SW_pin)] | pinC;
enabled = top[FPSTR(_enabled)] | enabled; enabled = top[FPSTR(_enabled)] | enabled;
newDTpin = top[FPSTR(_DT_pin)] | newDTpin;
newCLKpin = top[FPSTR(_CLK_pin)] | newCLKpin;
newSWpin = top[FPSTR(_SW_pin)] | newSWpin;
DEBUG_PRINT(FPSTR(_name)); DEBUG_PRINT(FPSTR(_name));
if (!initDone) { if (!initDone) {

View File

@ -47,7 +47,7 @@
// The last UI state, remove color and saturation option if diplay not active(too many options) // The last UI state, remove color and saturation option if diplay not active(too many options)
#ifdef USERMOD_FOUR_LINE_DISPLAY #ifdef USERMOD_FOUR_LINE_DISPLAY
#define LAST_UI_STATE 8 #define LAST_UI_STATE 11
#else #else
#define LAST_UI_STATE 4 #define LAST_UI_STATE 4
#endif #endif
@ -56,7 +56,7 @@
#define MODE_SORT_SKIP_COUNT 1 #define MODE_SORT_SKIP_COUNT 1
// Which list is being sorted // Which list is being sorted
static char **listBeingSorted; static const char **listBeingSorted;
/** /**
* Modes and palettes are stored as strings that * Modes and palettes are stored as strings that
@ -65,8 +65,8 @@ static char **listBeingSorted;
* JSON_mode_names or JSON_palette_names. * JSON_mode_names or JSON_palette_names.
*/ */
static int re_qstringCmp(const void *ap, const void *bp) { static int re_qstringCmp(const void *ap, const void *bp) {
char *a = listBeingSorted[*((byte *)ap)]; const char *a = listBeingSorted[*((byte *)ap)];
char *b = listBeingSorted[*((byte *)bp)]; const char *b = listBeingSorted[*((byte *)bp)];
int i = 0; int i = 0;
do { do {
char aVal = pgm_read_byte_near(a + i); char aVal = pgm_read_byte_near(a + i);
@ -139,13 +139,13 @@ private:
#endif #endif
// Pointers the start of the mode names within JSON_mode_names // Pointers the start of the mode names within JSON_mode_names
char **modes_qstrings = nullptr; const char **modes_qstrings = nullptr;
// Array of mode indexes in alphabetical order. // Array of mode indexes in alphabetical order.
byte *modes_alpha_indexes = nullptr; byte *modes_alpha_indexes = nullptr;
// Pointers the start of the palette names within JSON_palette_names // Pointers the start of the palette names within JSON_palette_names
char **palettes_qstrings = nullptr; const char **palettes_qstrings = nullptr;
// Array of palette indexes in alphabetical order. // Array of palette indexes in alphabetical order.
byte *palettes_alpha_indexes = nullptr; byte *palettes_alpha_indexes = nullptr;
@ -161,7 +161,6 @@ private:
uint8_t knownPalette = 0; uint8_t knownPalette = 0;
uint8_t currentCCT = 128; uint8_t currentCCT = 128;
bool isRgbw = false;
byte presetHigh = 0; byte presetHigh = 0;
byte presetLow = 0; byte presetLow = 0;
@ -186,7 +185,8 @@ private:
* modes_alpha_indexes and palettes_alpha_indexes. * modes_alpha_indexes and palettes_alpha_indexes.
*/ */
void sortModesAndPalettes() { void sortModesAndPalettes() {
modes_qstrings = re_findModeStrings(JSON_mode_names, strip.getModeCount()); //modes_qstrings = re_findModeStrings(JSON_mode_names, strip.getModeCount());
modes_qstrings = strip.getModeDataSrc();
modes_alpha_indexes = re_initIndexArray(strip.getModeCount()); modes_alpha_indexes = re_initIndexArray(strip.getModeCount());
re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT); re_sortModes(modes_qstrings, modes_alpha_indexes, strip.getModeCount(), MODE_SORT_SKIP_COUNT);
@ -212,8 +212,8 @@ private:
* Return an array of mode or palette names from the JSON string. * Return an array of mode or palette names from the JSON string.
* They don't end in '\0', they end in '"'. * They don't end in '\0', they end in '"'.
*/ */
char **re_findModeStrings(const char json[], int numModes) { const char **re_findModeStrings(const char json[], int numModes) {
char **modeStrings = (char **)malloc(sizeof(char *) * numModes); const char **modeStrings = (const char **)malloc(sizeof(const char *) * numModes);
uint8_t modeIndex = 0; uint8_t modeIndex = 0;
bool insideQuotes = false; bool insideQuotes = false;
// advance past the mark for markLineNum that may exist. // advance past the mark for markLineNum that may exist.
@ -250,7 +250,8 @@ private:
/** /**
* Sort either the modes or the palettes using quicksort. * Sort either the modes or the palettes using quicksort.
*/ */
void re_sortModes(char **modeNames, byte *indexes, int count, int numSkip) { void re_sortModes(const char **modeNames, byte *indexes, int count, int numSkip) {
if (!modeNames) return;
listBeingSorted = modeNames; listBeingSorted = modeNames;
qsort(indexes + numSkip, count - numSkip, sizeof(byte), re_qstringCmp); qsort(indexes + numSkip, count - numSkip, sizeof(byte), re_qstringCmp);
listBeingSorted = nullptr; listBeingSorted = nullptr;
@ -277,16 +278,14 @@ public:
return; return;
} }
pinMode(pinA, INPUT_PULLUP); #ifndef USERMOD_ROTARY_ENCODER_GPIO
pinMode(pinB, INPUT_PULLUP); #define USERMOD_ROTARY_ENCODER_GPIO INPUT_PULLUP
pinMode(pinC, INPUT_PULLUP); #endif
loopTime = millis(); pinMode(pinA, USERMOD_ROTARY_ENCODER_GPIO);
pinMode(pinB, USERMOD_ROTARY_ENCODER_GPIO);
pinMode(pinC, USERMOD_ROTARY_ENCODER_GPIO);
for (uint8_t s = 0; s < busses.getNumBusses(); s++) { loopTime = millis();
Bus *bus = busses.getBus(s);
if (!bus || bus->getLength()==0) break;
isRgbw |= bus->isRgbw();
}
currentCCT = (approximateKelvinFromRGB(RGBW32(col[0], col[1], col[2], col[3])) - 1900) >> 5; currentCCT = (approximateKelvinFromRGB(RGBW32(col[0], col[1], col[2], col[3])) - 1900) >> 5;
@ -372,19 +371,43 @@ public:
if (buttonWaitTime && currentTime-buttonWaitTime>350 && !buttonPressedBefore) { //same speed as in button.cpp if (buttonWaitTime && currentTime-buttonWaitTime>350 && !buttonPressedBefore) { //same speed as in button.cpp
buttonWaitTime = 0; buttonWaitTime = 0;
char newState = select_state + 1; char newState = select_state + 1;
bool changedState = true; bool changedState = false;
if (newState > LAST_UI_STATE || (newState == 8 && presetHigh==0 && presetLow == 0)) newState = 0; char lineBuffer[64];
do {
// finde new state
switch (newState) {
case 0: strcpy_P(lineBuffer, PSTR("Brightness")); changedState = true; break;
case 1: if (!extractModeSlider(effectCurrent, 0, lineBuffer, 63)) newState++; else changedState = true; break; // speed
case 2: if (!extractModeSlider(effectCurrent, 1, lineBuffer, 63)) newState++; else changedState = true; break; // intensity
case 3: strcpy_P(lineBuffer, PSTR("Color Palette")); changedState = true; break;
case 4: strcpy_P(lineBuffer, PSTR("Effect")); changedState = true; break;
case 5: strcpy_P(lineBuffer, PSTR("Main Color")); changedState = true; break;
case 6: strcpy_P(lineBuffer, PSTR("Saturation")); changedState = true; break;
case 7:
if (!(strip.getSegment(applyToAll ? strip.getFirstSelectedSegId() : strip.getMainSegmentId()).getLightCapabilities() & 0x04)) newState++;
else { strcpy_P(lineBuffer, PSTR("CCT")); changedState = true; }
break;
case 8: if (presetHigh==0 || presetLow == 0) newState++; else { strcpy_P(lineBuffer, PSTR("Preset")); changedState = true; } break;
case 9:
case 10:
case 11: if (!extractModeSlider(effectCurrent, newState-7, lineBuffer, 63)) newState++; else changedState = true; break; // custom
}
if (newState > LAST_UI_STATE) newState = 0;
} while (!changedState);
if (display != nullptr) { if (display != nullptr) {
switch (newState) { switch (newState) {
case 0: changedState = changeState(PSTR("Brightness"), 1, 0, 1); break; //1 = sun case 0: changedState = changeState(lineBuffer, 1, 0, 1); break; //1 = sun
case 1: changedState = changeState(PSTR("Speed"), 1, 4, 2); break; //2 = skip forward case 1: changedState = changeState(lineBuffer, 1, 4, 2); break; //2 = skip forward
case 2: changedState = changeState(PSTR("Intensity"), 1, 8, 3); break; //3 = fire case 2: changedState = changeState(lineBuffer, 1, 8, 3); break; //3 = fire
case 3: changedState = changeState(PSTR("Color Palette"), 2, 0, 4); break; //4 = custom palette case 3: changedState = changeState(lineBuffer, 2, 0, 4); break; //4 = custom palette
case 4: changedState = changeState(PSTR("Effect"), 3, 0, 5); break; //5 = puzzle piece case 4: changedState = changeState(lineBuffer, 3, 0, 5); break; //5 = puzzle piece
case 5: changedState = changeState(PSTR("Main Color"), 255, 255, 7); break; //7 = brush case 5: changedState = changeState(lineBuffer, 255, 255, 7); break; //7 = brush
case 6: changedState = changeState(PSTR("Saturation"), 255, 255, 8); break; //8 = contrast case 6: changedState = changeState(lineBuffer, 255, 255, 8); break; //8 = contrast
case 7: changedState = changeState(PSTR("CCT"), 255, 255, 10); break; //10 = star case 7: changedState = changeState(lineBuffer, 255, 255, 10); break; //10 = star
case 8: changedState = changeState(PSTR("Preset"), 255, 255, 11); break; //11 = heart case 8: changedState = changeState(lineBuffer, 255, 255, 11); break; //11 = heart
case 9: changedState = changeState(lineBuffer, 255, 255, 10); break; //10 = star
case 10: changedState = changeState(lineBuffer, 255, 255, 10); break; //10 = star
case 11: changedState = changeState(lineBuffer, 255, 255, 10); break; //10 = star
} }
} }
if (changedState) select_state = newState; if (changedState) select_state = newState;
@ -406,6 +429,9 @@ public:
case 6: changeSat(true); break; case 6: changeSat(true); break;
case 7: changeCCT(true); break; case 7: changeCCT(true); break;
case 8: changePreset(true); break; case 8: changePreset(true); break;
case 9: changeCustom(1,true); break;
case 10: changeCustom(2,true); break;
case 11: changeCustom(3,true); break;
} }
} }
else if (Enc_B == HIGH) else if (Enc_B == HIGH)
@ -420,6 +446,9 @@ public:
case 6: changeSat(false); break; case 6: changeSat(false); break;
case 7: changeCCT(false); break; case 7: changeCCT(false); break;
case 8: changePreset(false); break; case 8: changePreset(false); break;
case 9: changeCustom(1,false); break;
case 10: changeCustom(2,false); break;
case 11: changeCustom(3,false); break;
} }
} }
} }
@ -503,14 +532,14 @@ public:
effectCurrent = modes_alpha_indexes[effectCurrentIndex]; effectCurrent = modes_alpha_indexes[effectCurrentIndex];
stateChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive()) continue; if (!seg.isActive()) continue;
strip.setMode(i, effectCurrent); seg.setMode(effectCurrent);
} }
} else { } else {
//WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); Segment& seg = strip.getSegment(strip.getMainSegmentId());
strip.setMode(strip.getMainSegmentId(), effectCurrent); seg.setMode(effectCurrent);
} }
lampUdated(); lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY #ifdef USERMOD_FOUR_LINE_DISPLAY
@ -531,13 +560,13 @@ public:
effectSpeed = max(min((increase ? effectSpeed+fadeAmount : effectSpeed-fadeAmount), 255), 0); effectSpeed = max(min((increase ? effectSpeed+fadeAmount : effectSpeed-fadeAmount), 255), 0);
stateChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive()) continue; if (!seg.isActive()) continue;
seg.speed = effectSpeed; seg.speed = effectSpeed;
} }
} else { } else {
WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); Segment& seg = strip.getSegment(strip.getMainSegmentId());
seg.speed = effectSpeed; seg.speed = effectSpeed;
} }
lampUdated(); lampUdated();
@ -559,13 +588,13 @@ public:
effectIntensity = max(min((increase ? effectIntensity+fadeAmount : effectIntensity-fadeAmount), 255), 0); effectIntensity = max(min((increase ? effectIntensity+fadeAmount : effectIntensity-fadeAmount), 255), 0);
stateChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive()) continue; if (!seg.isActive()) continue;
seg.intensity = effectIntensity; seg.intensity = effectIntensity;
} }
} else { } else {
WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); Segment& seg = strip.getSegment(strip.getMainSegmentId());
seg.intensity = effectIntensity; seg.intensity = effectIntensity;
} }
lampUdated(); lampUdated();
@ -575,6 +604,51 @@ public:
} }
void changeCustom(uint8_t par, bool increase) {
uint8_t val = 0;
#ifdef USERMOD_FOUR_LINE_DISPLAY
if (display && display->wakeDisplay()) {
display->redraw(true);
// Throw away wake up input
return;
}
display->updateRedrawTime();
#endif
stateChanged = true;
if (applyToAll) {
uint8_t id = strip.getFirstSelectedSegId();
Segment& sid = strip.getSegment(id);
switch (par) {
case 3: val = sid.custom3 = max(min((increase ? sid.custom3+fadeAmount : sid.custom3-fadeAmount), 255), 0); break;
case 2: val = sid.custom2 = max(min((increase ? sid.custom2+fadeAmount : sid.custom2-fadeAmount), 255), 0); break;
default: val = sid.custom1 = max(min((increase ? sid.custom1+fadeAmount : sid.custom1-fadeAmount), 255), 0); break;
}
for (byte i=0; i<strip.getSegmentsNum(); i++) {
Segment& seg = strip.getSegment(i);
if (!seg.isActive() || i == id) continue;
switch (par) {
case 3: seg.custom3 = sid.custom3; break;
case 2: seg.custom2 = sid.custom2; break;
default: seg.custom1 = sid.custom1; break;
}
}
} else {
Segment& seg = strip.getMainSegment();
switch (par) {
case 3: val = seg.custom3 = max(min((increase ? seg.custom3+fadeAmount : seg.custom3-fadeAmount), 255), 0); break;
case 2: val = seg.custom2 = max(min((increase ? seg.custom2+fadeAmount : seg.custom2-fadeAmount), 255), 0); break;
default: val = seg.custom1 = max(min((increase ? seg.custom1+fadeAmount : seg.custom1-fadeAmount), 255), 0); break;
}
}
lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
char lineBuffer[64];
sprintf(lineBuffer, "%d", val);
display->overlay(lineBuffer, 500, 10); // use star
#endif
}
void changePalette(bool increase) { void changePalette(bool increase) {
#ifdef USERMOD_FOUR_LINE_DISPLAY #ifdef USERMOD_FOUR_LINE_DISPLAY
if (display && display->wakeDisplay()) { if (display && display->wakeDisplay()) {
@ -588,14 +662,14 @@ public:
effectPalette = palettes_alpha_indexes[effectPaletteIndex]; effectPalette = palettes_alpha_indexes[effectPaletteIndex];
stateChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive()) continue; if (!seg.isActive()) continue;
seg.palette = effectPalette; seg.setPalette(effectPalette);
} }
} else { } else {
WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); Segment& seg = strip.getSegment(strip.getMainSegmentId());
seg.palette = effectPalette; seg.setPalette(effectPalette);
} }
lampUdated(); lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY #ifdef USERMOD_FOUR_LINE_DISPLAY
@ -617,16 +691,21 @@ public:
colorHStoRGB(currentHue1*256, currentSat1, col); colorHStoRGB(currentHue1*256, currentSat1, col);
stateChanged = true; stateChanged = true;
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive()) continue; if (!seg.isActive()) continue;
seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]); seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]);
} }
} else { } else {
WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); Segment& seg = strip.getSegment(strip.getMainSegmentId());
seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]); seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]);
} }
lampUdated(); lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
char lineBuffer[64];
sprintf(lineBuffer, "%d", currentHue1);
display->overlay(lineBuffer, 500, 7); // use brush
#endif
} }
void changeSat(bool increase){ void changeSat(bool increase){
@ -641,16 +720,21 @@ public:
currentSat1 = max(min((increase ? currentSat1+fadeAmount : currentSat1-fadeAmount), 255), 0); currentSat1 = max(min((increase ? currentSat1+fadeAmount : currentSat1-fadeAmount), 255), 0);
colorHStoRGB(currentHue1*256, currentSat1, col); colorHStoRGB(currentHue1*256, currentSat1, col);
if (applyToAll) { if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive()) continue; if (!seg.isActive()) continue;
seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]); seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]);
} }
} else { } else {
WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); Segment& seg = strip.getSegment(strip.getMainSegmentId());
seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]); seg.colors[0] = RGBW32(col[0], col[1], col[2], col[3]);
} }
lampUdated(); lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
char lineBuffer[64];
sprintf(lineBuffer, "%d", currentSat1);
display->overlay(lineBuffer, 500, 8); // use contrast
#endif
} }
void changePreset(bool increase) { void changePreset(bool increase) {
@ -663,6 +747,12 @@ public:
display->updateRedrawTime(); display->updateRedrawTime();
#endif #endif
if (presetHigh && presetLow && presetHigh > presetLow) { if (presetHigh && presetLow && presetHigh > presetLow) {
StaticJsonDocument<64> root;
char str[64];
sprintf_P(str, PSTR("%d~%d~%s"), presetLow, presetHigh, increase?"":"-");
root[F("ps")] = str;
deserializeState(root.as<JsonObject>(), CALL_MODE_BUTTON_PRESET);
/*
String apireq = F("win&PL=~"); String apireq = F("win&PL=~");
if (!increase) apireq += '-'; if (!increase) apireq += '-';
apireq += F("&P1="); apireq += F("&P1=");
@ -670,7 +760,12 @@ public:
apireq += F("&P2="); apireq += F("&P2=");
apireq += presetHigh; apireq += presetHigh;
handleSet(nullptr, apireq, false); handleSet(nullptr, apireq, false);
*/
lampUdated(); lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
sprintf(str, "%d", currentPreset);
display->overlay(str, 500, 11); // use heart
#endif
} }
} }
@ -685,16 +780,21 @@ public:
#endif #endif
currentCCT = max(min((increase ? currentCCT+fadeAmount : currentCCT-fadeAmount), 255), 0); currentCCT = max(min((increase ? currentCCT+fadeAmount : currentCCT-fadeAmount), 255), 0);
// if (applyToAll) { // if (applyToAll) {
for (byte i=0; i<strip.getMaxSegments(); i++) { for (byte i=0; i<strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive()) continue; if (!seg.isActive()) continue;
seg.setCCT(currentCCT, i); seg.setCCT(currentCCT);
} }
// } else { // } else {
// WS2812FX::Segment& seg = strip.getSegment(strip.getMainSegmentId()); // Segment& seg = strip.getSegment(strip.getMainSegmentId());
// seg.setCCT(currentCCT, strip.getMainSegmentId()); // seg.setCCT(currentCCT, strip.getMainSegmentId());
// } // }
lampUdated(); lampUdated();
#ifdef USERMOD_FOUR_LINE_DISPLAY
char lineBuffer[64];
sprintf(lineBuffer, "%d", currentCCT);
display->overlay(lineBuffer, 500, 10); // use star
#endif
} }
/* /*

View File

@ -1,11 +1,12 @@
# Word Clock Usermod V2 # Word Clock Usermod V2
This usermod can be used to drive a wordclock with a 11x10 pixel matrix with WLED. There are also 4 additional dots for the minutes. This usermod can be used to drive a wordclock with a 11x10 pixel matrix with WLED. There are also 4 additional dots for the minutes.
The visualisation is desribed in 4 mask with LED numbers (single dots for minutes, minutes, hours and "clock/Uhr"). The visualisation is desribed in 4 mask with LED numbers (single dots for minutes, minutes, hours and "clock/Uhr"). The index of the LEDs in the masks always starts with the index 0, even if the ledOffset is not 0.
There are 2 parameters to chnage the behaviour: There are 3 parameters to change the behaviour:
active: enable/disable usermod active: enable/disable usermod
diplayItIs: enable/disable display of "Es ist" on the clock. diplayItIs: enable/disable display of "Es ist" on the clock
ledOffset: number of LEDs before the wordclock LEDs
### Update for alternatative wiring pattern ### Update for alternatative wiring pattern
Based on this fantastic work I added an alternative wiring pattern. Based on this fantastic work I added an alternative wiring pattern.

View File

@ -23,6 +23,7 @@ class WordClockUsermod : public Usermod
// set your config variables to their boot default value (this can also be done in readFromConfig() or a constructor if you prefer) // set your config variables to their boot default value (this can also be done in readFromConfig() or a constructor if you prefer)
bool usermodActive = false; bool usermodActive = false;
bool displayItIs = false; bool displayItIs = false;
int ledOffset = 100;
bool meander = false; bool meander = false;
// defines for mask sizes // defines for mask sizes
@ -407,6 +408,7 @@ class WordClockUsermod : public Usermod
JsonObject top = root.createNestedObject("WordClockUsermod"); JsonObject top = root.createNestedObject("WordClockUsermod");
top["active"] = usermodActive; top["active"] = usermodActive;
top["displayItIs"] = displayItIs; top["displayItIs"] = displayItIs;
top["ledOffset"] = ledOffset;
top["Meander wiring?"] = meander; top["Meander wiring?"] = meander;
} }
@ -436,6 +438,7 @@ class WordClockUsermod : public Usermod
configComplete &= getJsonValue(top["active"], usermodActive); configComplete &= getJsonValue(top["active"], usermodActive);
configComplete &= getJsonValue(top["displayItIs"], displayItIs); configComplete &= getJsonValue(top["displayItIs"], displayItIs);
configComplete &= getJsonValue(top["ledOffset"], ledOffset);
configComplete &= getJsonValue(top["Meander wiring?"], meander); configComplete &= getJsonValue(top["Meander wiring?"], meander);
return configComplete; return configComplete;
@ -458,7 +461,7 @@ class WordClockUsermod : public Usermod
if (maskLedsOn[x] == 0) if (maskLedsOn[x] == 0)
{ {
// set pixel off // set pixel off
strip.setPixelColor(x, RGBW32(0,0,0,0)); strip.setPixelColor(x + ledOffset, RGBW32(0,0,0,0));
} }
} }
} }

View File

@ -27,14 +27,14 @@ saveMacro(1, "&FX=0&R=255&G=255&B=255", false);
//strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true); //strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true);
//select first two segments (background color + FX settable) //select first two segments (background color + FX settable)
WS2812FX::Segment &seg = strip.getSegment(0); Segment &seg = strip.getSegment(0);
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((0 & 0xFF) << 8) | ((0 & 0xFF))); seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((0 & 0xFF) << 8) | ((0 & 0xFF)));
strip.getSegment(0).setOption(0, false); strip.getSegment(0).setOption(0, false);
strip.getSegment(0).setOption(2, false); strip.getSegment(0).setOption(2, false);
//other segments are text //other segments are text
for (int i = 1; i < 10; i++) for (int i = 1; i < 10; i++)
{ {
WS2812FX::Segment &seg = strip.getSegment(i); Segment &seg = strip.getSegment(i);
seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((190 & 0xFF) << 8) | ((180 & 0xFF))); seg.colors[0] = ((0 << 24) | ((0 & 0xFF) << 16) | ((190 & 0xFF) << 8) | ((180 & 0xFF)));
strip.getSegment(i).setOption(0, true); strip.getSegment(i).setOption(0, true);
strip.setBrightness(128); strip.setBrightness(128);
@ -50,7 +50,7 @@ void selectWordSegments(bool state)
{ {
for (int i = 1; i < 10; i++) for (int i = 1; i < 10; i++)
{ {
//WS2812FX::Segment &seg = strip.getSegment(i); //Segment &seg = strip.getSegment(i);
strip.getSegment(i).setOption(0, state); strip.getSegment(i).setOption(0, state);
// strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true); // strip.getSegment(1).setOption(SEG_OPTION_SELECTED, true);
//seg.mode = 12; //seg.mode = 12;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

517
wled00/FX_2Dfcn.cpp Normal file
View File

@ -0,0 +1,517 @@
/*
FX_2Dfcn.cpp contains all 2D utility functions
LICENSE
The MIT License (MIT)
Copyright (c) 2022 Blaz Kristan (https://blaz.at/home)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Parts of the code adapted from WLED Sound Reactive
*/
#include "wled.h"
#include "FX.h"
#include "palettes.h"
// setUpMatrix() - constructs ledmap array from matrix of panels with WxH pixels
// this converts physical (possibly irregular) LED arrangement into well defined
// array of logical pixels: fist entry corresponds to left-topmost logical pixel
// followed by horizontal pixels, when matrixWidth logical pixels are added they
// are followed by next row (down) of matrixWidth pixels (and so forth)
// note: matrix may be comprised of multiple panels each with different orientation
// but ledmap takes care of that. ledmap is constructed upon initialization
// so matrix should disable regular ledmap processing
void WS2812FX::setUpMatrix() {
#ifndef WLED_DISABLE_2D
// erase old ledmap, just in case.
if (customMappingTable != nullptr) delete[] customMappingTable;
customMappingTable = nullptr;
customMappingSize = 0;
if (isMatrix) {
matrixWidth = hPanels * panelW;
matrixHeight = vPanels * panelH;
// safety check
if (matrixWidth * matrixHeight > MAX_LEDS) {
matrixWidth = _length;
matrixHeight = 1;
isMatrix = false;
return;
}
customMappingSize = matrixWidth * matrixHeight;
customMappingTable = new uint16_t[customMappingSize];
if (customMappingTable != nullptr) {
uint16_t startL; // index in custom mapping array (logical strip)
uint16_t startP; // position of 1st pixel of panel on (virtual) strip
uint16_t x, y, offset;
uint8_t h = matrix.vertical ? vPanels : hPanels;
uint8_t v = matrix.vertical ? hPanels : vPanels;
for (uint8_t j=0, p=0; j<v; j++) {
for (uint8_t i=0; i<h; i++, p++) {
y = (matrix.vertical ? matrix.rightStart : matrix.bottomStart) ? v - j - 1 : j;
x = (matrix.vertical ? matrix.bottomStart : matrix.rightStart) ? h - i - 1 : i;
x = matrix.serpentine && j%2 ? h - x - 1 : x;
startL = (matrix.vertical ? y : x) * panelW + (matrix.vertical ? x : y) * matrixWidth * panelH; // logical index (top-left corner)
startP = p * panelW * panelH; // physical index (top-left corner)
uint8_t H = panel[h*j + i].vertical ? panelW : panelH;
uint8_t W = panel[h*j + i].vertical ? panelH : panelW;
for (uint16_t l=0, q=0; l<H; l++) {
for (uint16_t k=0; k<W; k++, q++) {
y = (panel[h*j + i].vertical ? panel[h*j + i].rightStart : panel[h*j + i].bottomStart) ? H - l - 1 : l;
x = (panel[h*j + i].vertical ? panel[h*j + i].bottomStart : panel[h*j + i].rightStart) ? W - k - 1 : k;
x = (panel[h*j + i].serpentine && l%2) ? (W - x - 1) : x;
offset = (panel[h*j + i].vertical ? y : x) + (panel[h*j + i].vertical ? x : y) * matrixWidth;
customMappingTable[startL + offset] = startP + q;
}
}
}
}
#ifdef WLED_DEBUG
DEBUG_PRINT(F("Matrix ledmap:"));
for (uint16_t i=0; i<customMappingSize; i++) {
if (!(i%matrixWidth)) DEBUG_PRINTLN();
DEBUG_PRINTF("%4d,", customMappingTable[i]);
}
DEBUG_PRINTLN();
#endif
} else {
// memory allocation error
matrixWidth = _length;
matrixHeight = 1;
isMatrix = false;
return;
}
} else {
// not a matrix set up
matrixWidth = _length;
matrixHeight = 1;
}
#endif
}
// absolute matrix version of setPixelColor()
void IRAM_ATTR WS2812FX::setPixelColorXY(int x, int y, uint32_t col)
{
#ifndef WLED_DISABLE_2D
if (!isMatrix) return; // not a matrix set-up
uint16_t index = y * matrixWidth + x;
#else
uint16_t index = x;
#endif
if (index >= _length) return;
if (index < customMappingSize) index = customMappingTable[index];
busses.setPixelColor(index, col);
}
// returns RGBW values of pixel
uint32_t WS2812FX::getPixelColorXY(uint16_t x, uint16_t y) {
#ifndef WLED_DISABLE_2D
uint16_t index = (y * matrixWidth + x);
#else
uint16_t index = x;
#endif
if (index >= _length) return 0;
if (index < customMappingSize) index = customMappingTable[index];
return busses.getPixelColor(index);
}
///////////////////////////////////////////////////////////
// Segment:: routines
///////////////////////////////////////////////////////////
#ifndef WLED_DISABLE_2D
// XY(x,y) - gets pixel index within current segment (often used to reference leds[] array element)
uint16_t IRAM_ATTR Segment::XY(uint16_t x, uint16_t y) {
uint16_t width = virtualWidth(); // segment width in logical pixels
uint16_t height = virtualHeight(); // segment height in logical pixels
return (x%width) + (y%height) * width;
}
void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
{
if (!strip.isMatrix) return; // not a matrix set-up
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
if (leds) leds[XY(x,y)] = col;
uint8_t _bri_t = currentBri(on ? opacity : 0);
if (_bri_t < 255) {
byte r = scale8(R(col), _bri_t);
byte g = scale8(G(col), _bri_t);
byte b = scale8(B(col), _bri_t);
byte w = scale8(W(col), _bri_t);
col = RGBW32(r, g, b, w);
}
if (reverse ) x = virtualWidth() - x - 1;
if (reverse_y) y = virtualHeight() - y - 1;
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
x *= groupLength(); // expand to physical pixels
y *= groupLength(); // expand to physical pixels
if (x >= width() || y >= height()) return; // if pixel would fall out of segment just exit
for (int j = 0; j < grouping; j++) { // groupping vertically
for (int g = 0; g < grouping; g++) { // groupping horizontally
uint16_t xX = (x+g), yY = (y+j);
if (xX >= width() || yY >= height()) continue; // we have reached one dimension's end
strip.setPixelColorXY(start + xX, startY + yY, col);
if (mirror) { //set the corresponding horizontally mirrored pixel
if (transpose) strip.setPixelColorXY(start + xX, startY + height() - yY - 1, col);
else strip.setPixelColorXY(start + width() - xX - 1, startY + yY, col);
}
if (mirror_y) { //set the corresponding vertically mirrored pixel
if (transpose) strip.setPixelColorXY(start + width() - xX - 1, startY + yY, col);
else strip.setPixelColorXY(start + xX, startY + height() - yY - 1, col);
}
if (mirror_y && mirror) { //set the corresponding vertically AND horizontally mirrored pixel
strip.setPixelColorXY(width() - xX - 1, height() - yY - 1, col);
}
}
}
}
// anti-aliased version of setPixelColorXY()
void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
{
if (!strip.isMatrix) return; // not a matrix set-up
if (x<0.0f || x>1.0f || y<0.0f || y>1.0f) return; // not normalized
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
float fX = x * (cols-1);
float fY = y * (rows-1);
if (aa) {
uint16_t xL = roundf(fX-0.49f);
uint16_t xR = roundf(fX+0.49f);
uint16_t yT = roundf(fY-0.49f);
uint16_t yB = roundf(fY+0.49f);
float dL = (fX - xL)*(fX - xL);
float dR = (xR - fX)*(xR - fX);
float dT = (fY - yT)*(fY - yT);
float dB = (yB - fY)*(yB - fY);
uint32_t cXLYT = getPixelColorXY(xL, yT);
uint32_t cXRYT = getPixelColorXY(xR, yT);
uint32_t cXLYB = getPixelColorXY(xL, yB);
uint32_t cXRYB = getPixelColorXY(xR, yB);
if (xL!=xR && yT!=yB) {
setPixelColorXY(xL, yT, color_blend(col, cXLYT, uint8_t(sqrtf(dL*dT)*255.0f))); // blend TL pixel
setPixelColorXY(xR, yT, color_blend(col, cXRYT, uint8_t(sqrtf(dR*dT)*255.0f))); // blend TR pixel
setPixelColorXY(xL, yB, color_blend(col, cXLYB, uint8_t(sqrtf(dL*dB)*255.0f))); // blend BL pixel
setPixelColorXY(xR, yB, color_blend(col, cXRYB, uint8_t(sqrtf(dR*dB)*255.0f))); // blend BR pixel
} else if (xR!=xL && yT==yB) {
setPixelColorXY(xR, yT, color_blend(col, cXLYT, uint8_t(dL*255.0f))); // blend L pixel
setPixelColorXY(xR, yT, color_blend(col, cXRYT, uint8_t(dR*255.0f))); // blend R pixel
} else if (xR==xL && yT!=yB) {
setPixelColorXY(xR, yT, color_blend(col, cXLYT, uint8_t(dT*255.0f))); // blend T pixel
setPixelColorXY(xL, yB, color_blend(col, cXLYB, uint8_t(dB*255.0f))); // blend B pixel
} else {
setPixelColorXY(xL, yT, col); // exact match (x & y land on a pixel)
}
} else {
setPixelColorXY(uint16_t(roundf(fX)), uint16_t(roundf(fY)), col);
}
}
// returns RGBW values of pixel
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
int i = XY(x,y);
if (leds) return RGBW32(leds[i].r, leds[i].g, leds[i].b, 0);
if (reverse ) x = virtualWidth() - x - 1;
if (reverse_y) y = virtualHeight() - y - 1;
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
x *= groupLength(); // expand to physical pixels
y *= groupLength(); // expand to physical pixels
if (x >= width() || y >= height()) return 0;
return strip.getPixelColorXY(start + x, startY + y);
}
// Blends the specified color with the existing pixel color.
void Segment::blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t blend) {
setPixelColorXY(x, y, color_blend(getPixelColorXY(x,y), color, blend));
}
// Adds the specified color with the existing pixel color perserving color balance.
void Segment::addPixelColorXY(int x, int y, uint32_t color) {
setPixelColorXY(x, y, color_add(getPixelColorXY(x,y), color));
}
void Segment::fadePixelColorXY(uint16_t x, uint16_t y, uint8_t fade) {
CRGB pix = CRGB(getPixelColorXY(x,y)).nscale8_video(fade);
setPixelColor(x, y, pix);
}
// blurRow: perform a blur on a row of a rectangular matrix
void Segment::blurRow(uint16_t row, fract8 blur_amount) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
if (row >= rows) return;
// blur one row
uint8_t keep = 255 - blur_amount;
uint8_t seep = blur_amount >> 1;
CRGB carryover = CRGB::Black;
for (uint16_t x = 0; x < cols; x++) {
CRGB cur = getPixelColorXY(x, row);
CRGB part = cur;
part.nscale8(seep);
cur.nscale8(keep);
cur += carryover;
if (x) {
CRGB prev = CRGB(getPixelColorXY(x-1, row)) + part;
setPixelColorXY(x-1, row, prev);
}
setPixelColorXY(x, row, cur);
carryover = part;
}
}
// blurCol: perform a blur on a column of a rectangular matrix
void Segment::blurCol(uint16_t col, fract8 blur_amount) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
if (col >= cols) return;
// blur one column
uint8_t keep = 255 - blur_amount;
uint8_t seep = blur_amount >> 1;
CRGB carryover = CRGB::Black;
for (uint16_t i = 0; i < rows; i++) {
CRGB cur = getPixelColorXY(col, i);
CRGB part = cur;
part.nscale8(seep);
cur.nscale8(keep);
cur += carryover;
if (i) {
CRGB prev = CRGB(getPixelColorXY(col, i-1)) + part;
setPixelColorXY(col, i-1, prev);
}
setPixelColorXY(col, i, cur);
carryover = part;
}
}
// 1D Box blur (with added weight - blur_amount: [0=no blur, 255=max blur])
void Segment::box_blur(uint16_t i, bool vertical, fract8 blur_amount) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
const uint16_t dim1 = vertical ? rows : cols;
const uint16_t dim2 = vertical ? cols : rows;
if (i >= dim2) return;
const float seep = blur_amount/255.f;
const float keep = 3.f - 2.f*seep;
// 1D box blur
CRGB tmp[dim1];
for (uint16_t j = 0; j < dim1; j++) {
uint16_t x = vertical ? i : j;
uint16_t y = vertical ? j : i;
uint16_t xp = vertical ? x : x-1;
uint16_t yp = vertical ? y-1 : y;
uint16_t xn = vertical ? x : x+1;
uint16_t yn = vertical ? y+1 : y;
CRGB curr = getPixelColorXY(x,y);
CRGB prev = (xp<0 || yp<0) ? CRGB::Black : getPixelColorXY(xp,yp);
CRGB next = ((vertical && yn>=dim1) || (!vertical && xn>=dim1)) ? CRGB::Black : getPixelColorXY(xn,yn);
uint16_t r, g, b;
r = (curr.r*keep + (prev.r + next.r)*seep) / 3;
g = (curr.g*keep + (prev.g + next.g)*seep) / 3;
b = (curr.b*keep + (prev.b + next.b)*seep) / 3;
tmp[j] = CRGB(r,g,b);
}
for (uint16_t j = 0; j < dim1; j++) {
uint16_t x = vertical ? i : j;
uint16_t y = vertical ? j : i;
setPixelColorXY(x, y, tmp[j]);
}
}
// blur1d: one-dimensional blur filter. Spreads light to 2 line neighbors.
// blur2d: two-dimensional blur filter. Spreads light to 8 XY neighbors.
//
// 0 = no spread at all
// 64 = moderate spreading
// 172 = maximum smooth, even spreading
//
// 173..255 = wider spreading, but increasing flicker
//
// Total light is NOT entirely conserved, so many repeated
// calls to 'blur' will also result in the light fading,
// eventually all the way to black; this is by design so that
// it can be used to (slowly) clear the LEDs to black.
void Segment::blur1d(fract8 blur_amount) {
const uint16_t rows = virtualHeight();
for (uint16_t y = 0; y < rows; y++) blurRow(y, blur_amount);
}
void Segment::moveX(int8_t delta) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
if (!delta) return;
if (delta > 0) {
for (uint8_t y = 0; y < rows; y++) for (uint8_t x = 0; x < cols-1; x++) {
if (x + delta >= cols) break;
setPixelColorXY(x, y, getPixelColorXY((x + delta)%cols, y));
}
} else {
for (uint8_t y = 0; y < rows; y++) for (int16_t x = cols-1; x >= 0; x--) {
if (x + delta < 0) break;
setPixelColorXY(x, y, getPixelColorXY(x + delta, y));
}
}
}
void Segment::moveY(int8_t delta) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
if (!delta) return;
if (delta > 0) {
for (uint8_t x = 0; x < cols; x++) for (uint8_t y = 0; y < rows-1; y++) {
if (y + delta >= rows) break;
setPixelColorXY(x, y, getPixelColorXY(x, (y + delta)));
}
} else {
for (uint8_t x = 0; x < cols; x++) for (int16_t y = rows-1; y >= 0; y--) {
if (y + delta < 0) break;
setPixelColorXY(x, y, getPixelColorXY(x, y + delta));
}
}
}
// move() - move all pixels in desired direction delta number of pixels
// @param dir direction: 0=left, 1=left-up, 2=up, 3=right-up, 4=right, 5=right-down, 6=down, 7=left-down
// @param delta number of pixels to move
void Segment::move(uint8_t dir, uint8_t delta) {
if (delta==0) return;
switch (dir) {
case 0: moveX( delta); break;
case 1: moveX( delta); moveY( delta); break;
case 2: moveY( delta); break;
case 3: moveX(-delta); moveY( delta); break;
case 4: moveX(-delta); break;
case 5: moveX(-delta); moveY(-delta); break;
case 6: moveY(-delta); break;
case 7: moveX( delta); moveY(-delta); break;
}
}
// by stepko, taken from https://editor.soulmatelights.com/gallery/573-blobs
void Segment::fill_circle(uint16_t cx, uint16_t cy, uint8_t radius, CRGB col) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
for (int16_t y = -radius; y <= radius; y++) {
for (int16_t x = -radius; x <= radius; x++) {
if (x * x + y * y <= radius * radius &&
int16_t(cx)+x>=0 && int16_t(cy)+y>=0 &&
int16_t(cx)+x<cols && int16_t(cy)+y<rows)
addPixelColorXY(cx + x, cy + y, col);
}
}
}
void Segment::nscale8(uint8_t scale) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
for(uint16_t y = 0; y < rows; y++) for (uint16_t x = 0; x < cols; x++) {
setPixelColorXY(x, y, CRGB(getPixelColorXY(x, y)).nscale8(scale));
}
}
//line function
void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t c) {
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
if (x0 >= cols || x1 >= cols || y0 >= rows || y1 >= rows) return;
const int16_t dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
const int16_t dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
int16_t err = (dx>dy ? dx : -dy)/2, e2;
for (;;) {
addPixelColorXY(x0,y0,c);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}
#include "src/font/console_font_4x6.h"
#include "src/font/console_font_5x8.h"
#include "src/font/console_font_5x12.h"
#include "src/font/console_font_6x8.h"
#include "src/font/console_font_7x9.h"
// draws a raster font character on canvas
// only supports: 4x6=24, 5x8=40, 5x12=60, 6x8=48 and 7x9=63 fonts ATM
void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color) {
if (chr < 32 || chr > 126) return; // only ASCII 32-126 supported
chr -= 32; // align with font table entries
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
const int font = w*h;
//if (w<5 || w>6 || h!=8) return;
for (int i = 0; i<h; i++) { // character height
int16_t y0 = y + i;
if (y0 < 0) continue; // drawing off-screen
if (y0 >= rows) break; // drawing off-screen
uint8_t bits = 0;
switch (font) {
case 24: bits = pgm_read_byte_near(&console_font_4x6[(chr * h) + i]); break; // 5x8 font
case 40: bits = pgm_read_byte_near(&console_font_5x8[(chr * h) + i]); break; // 5x8 font
case 48: bits = pgm_read_byte_near(&console_font_6x8[(chr * h) + i]); break; // 6x8 font
case 63: bits = pgm_read_byte_near(&console_font_7x9[(chr * h) + i]); break; // 7x9 font
case 60: bits = pgm_read_byte_near(&console_font_5x12[(chr * h) + i]); break; // 5x12 font
default: return;
}
for (int j = 0; j<w; j++) { // character width
int16_t x0 = x + (w-1) - j;
if ((x0 >= 0 || x0 < cols) && ((bits>>(j+(8-w))) & 0x01)) { // bit set & drawing on-screen
addPixelColorXY(x0, y0, color);
}
}
}
}
#define WU_WEIGHT(a,b) ((uint8_t) (((a)*(b)+(a)+(b))>>8))
void Segment::wu_pixel(uint32_t x, uint32_t y, CRGB c) { //awesome wu_pixel procedure by reddit u/sutaburosu
// extract the fractional parts and derive their inverses
uint8_t xx = x & 0xff, yy = y & 0xff, ix = 255 - xx, iy = 255 - yy;
// calculate the intensities for each affected pixel
uint8_t wu[4] = {WU_WEIGHT(ix, iy), WU_WEIGHT(xx, iy),
WU_WEIGHT(ix, yy), WU_WEIGHT(xx, yy)};
// multiply the intensities by the colour, and saturating-add them to the pixels
for (int i = 0; i < 4; i++) {
CRGB led = getPixelColorXY((x >> 8) + (i & 1), (y >> 8) + ((i >> 1) & 1));
led.r = qadd8(led.r, c.r * wu[i] >> 8);
led.g = qadd8(led.g, c.g * wu[i] >> 8);
led.b = qadd8(led.b, c.b * wu[i] >> 8);
setPixelColorXY(int((x >> 8) + (i & 1)), int((y >> 8) + ((i >> 1) & 1)), led);
}
}
#undef WU_WEIGHT
#endif // WLED_DISABLE_2D

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,6 @@ struct NodeStruct
{ {
String nodeName; String nodeName;
IPAddress ip; IPAddress ip;
uint8_t unit;
uint8_t age; uint8_t age;
uint8_t nodeType; uint8_t nodeType;
uint32_t build; uint32_t build;

View File

@ -92,7 +92,7 @@ void onAlexaChange(EspalexaDevice* dev)
} else { } else {
colorKtoRGB(k, rgbw); colorKtoRGB(k, rgbw);
} }
strip.setColor(0, rgbw[0], rgbw[1], rgbw[2], rgbw[3]); strip.setColor(0, RGBW32(rgbw[0], rgbw[1], rgbw[2], rgbw[3]));
} else { } else {
uint32_t color = espalexaDevice->getRGB(); uint32_t color = espalexaDevice->getRGB();
strip.setColor(0, color); strip.setColor(0, color);

View File

@ -1,5 +1,7 @@
#include "wled.h" #include "wled.h"
#ifndef WLED_DISABLE_BLYNK
#include "src/dependencies/blynk/Blynk/BlynkHandlers.h" #include "src/dependencies/blynk/Blynk/BlynkHandlers.h"
#endif
/* /*
* Remote light control with the free Blynk app * Remote light control with the free Blynk app

View File

@ -41,18 +41,19 @@ void colorRGBtoRGBW(byte* rgb);
//temporary struct for passing bus configuration to bus //temporary struct for passing bus configuration to bus
struct BusConfig { struct BusConfig {
uint8_t type = TYPE_WS2812_RGB; uint8_t type;
uint16_t count; uint16_t count;
uint16_t start; uint16_t start;
uint8_t colorOrder; uint8_t colorOrder;
bool reversed; bool reversed;
uint8_t skipAmount; uint8_t skipAmount;
bool refreshReq; bool refreshReq;
uint8_t autoWhite;
uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255}; uint8_t pins[5] = {LEDPIN, 255, 255, 255, 255};
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0) { BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY) {
refreshReq = (bool) GET_BIT(busType,7); refreshReq = (bool) GET_BIT(busType,7);
type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh) type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh)
count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip; count = len; start = pstart; colorOrder = pcolorOrder; reversed = rev; skipAmount = skip; autoWhite = aw;
uint8_t nPins = 1; uint8_t nPins = 1;
if (type >= TYPE_NET_DDP_RGB && type < 96) nPins = 4; //virtual network bus. 4 "pins" store IP address if (type >= TYPE_NET_DDP_RGB && type < 96) nPins = 4; //virtual network bus. 4 "pins" store IP address
else if (type > 47) nPins = 2; else if (type > 47) nPins = 2;
@ -115,10 +116,11 @@ struct ColorOrderMap {
inline uint8_t IRAM_ATTR getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const { inline uint8_t IRAM_ATTR getPixelColorOrder(uint16_t pix, uint8_t defaultColorOrder) const {
if (_count == 0) return defaultColorOrder; if (_count == 0) return defaultColorOrder;
// upper nibble containd W swap information
uint8_t swapW = defaultColorOrder >> 4;
for (uint8_t i = 0; i < _count; i++) { for (uint8_t i = 0; i < _count; i++) {
if (pix >= _mappings[i].start && pix < (_mappings[i].start + _mappings[i].len)) { if (pix >= _mappings[i].start && pix < (_mappings[i].start + _mappings[i].len)) {
return _mappings[i].colorOrder; return _mappings[i].colorOrder | (swapW << 4);
} }
} }
return defaultColorOrder; return defaultColorOrder;
@ -132,20 +134,26 @@ struct ColorOrderMap {
//parent class of BusDigital, BusPwm, and BusNetwork //parent class of BusDigital, BusPwm, and BusNetwork
class Bus { class Bus {
public: public:
Bus(uint8_t type, uint16_t start) { Bus(uint8_t type, uint16_t start, uint8_t aw)
: _bri(255)
, _len(1)
, _valid(false)
, _needsRefresh(false)
{
_type = type; _type = type;
_start = start; _start = start;
_autoWhiteMode = Bus::isRgbw(_type) ? aw : RGBW_MODE_MANUAL_ONLY;
}; };
virtual ~Bus() {} //throw the bus under the bus virtual ~Bus() {} //throw the bus under the bus
virtual void show() {} virtual void show() = 0;
virtual bool canShow() { return true; } virtual bool canShow() { return true; }
virtual void setStatusPixel(uint32_t c) {} virtual void setStatusPixel(uint32_t c) {}
virtual void setPixelColor(uint16_t pix, uint32_t c) {} virtual void setPixelColor(uint16_t pix, uint32_t c) = 0;
virtual uint32_t getPixelColor(uint16_t pix) { return 0; } virtual uint32_t getPixelColor(uint16_t pix) { return 0; }
virtual void setBrightness(uint8_t b) {} virtual void setBrightness(uint8_t b) { _bri = b; };
virtual void cleanup() {} virtual void cleanup() = 0;
virtual uint8_t getPins(uint8_t* pinArray) { return 0; } virtual uint8_t getPins(uint8_t* pinArray) { return 0; }
virtual uint16_t getLength() { return _len; } virtual uint16_t getLength() { return _len; }
virtual void setColorOrder() {} virtual void setColorOrder() {}
@ -162,6 +170,16 @@ class Bus {
static bool isRgbw(uint8_t type) { static bool isRgbw(uint8_t type) {
if (type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true; if (type == TYPE_SK6812_RGBW || type == TYPE_TM1814) return true;
if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true; if (type > TYPE_ONOFF && type <= TYPE_ANALOG_5CH && type != TYPE_ANALOG_3CH) return true;
if (type == TYPE_NET_DDP_RGBW) return true;
return false;
}
virtual bool hasRGB() {
if (_type == TYPE_WS2812_1CH || _type == TYPE_WS2812_WWA || _type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ONOFF) return false;
return true;
}
virtual bool hasWhite() {
if (_type == TYPE_SK6812_RGBW || _type == TYPE_TM1814 || _type == TYPE_WS2812_1CH || _type == TYPE_WS2812_WWA ||
_type == TYPE_ANALOG_1CH || _type == TYPE_ANALOG_2CH || _type == TYPE_ANALOG_4CH || _type == TYPE_ANALOG_5CH || _type == TYPE_NET_DDP_RGBW) return true;
return false; return false;
} }
static void setCCT(uint16_t cct) { static void setCCT(uint16_t cct) {
@ -175,32 +193,37 @@ class Bus {
if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND; if (_cctBlend > WLED_MAX_CCT_BLEND) _cctBlend = WLED_MAX_CCT_BLEND;
#endif #endif
} }
inline static void setAutoWhiteMode(uint8_t m) { if (m < 4) _autoWhiteMode = m; } inline void setAWMode(uint8_t m) { if (m < 4) _autoWhiteMode = m; }
inline static uint8_t getAutoWhiteMode() { return _autoWhiteMode; } inline uint8_t getAWMode() { return _autoWhiteMode; }
inline static void setAutoWhiteMode(uint8_t m) { if (m < 4) _gAWM = m; else _gAWM = 255; }
inline static uint8_t getAutoWhiteMode() { return _gAWM; }
bool reversed = false; bool reversed = false;
protected: protected:
uint8_t _type = TYPE_NONE; uint8_t _type;
uint8_t _bri = 255; uint8_t _bri;
uint16_t _start = 0; uint16_t _start;
uint16_t _len = 1; uint16_t _len;
bool _valid = false; bool _valid;
bool _needsRefresh = false; bool _needsRefresh;
static uint8_t _autoWhiteMode; uint8_t _autoWhiteMode;
static int16_t _cct; static uint8_t _gAWM; // definition in FX_fcn.cpp
static uint8_t _cctBlend; static int16_t _cct; // definition in FX_fcn.cpp
static uint8_t _cctBlend; // definition in FX_fcn.cpp
uint32_t autoWhiteCalc(uint32_t c) { uint32_t autoWhiteCalc(uint32_t c) {
if (_autoWhiteMode == RGBW_MODE_MANUAL_ONLY) return c; uint8_t aWM = _autoWhiteMode;
if (_gAWM < 255) aWM = _gAWM;
if (aWM == RGBW_MODE_MANUAL_ONLY) return c;
uint8_t w = W(c); uint8_t w = W(c);
//ignore auto-white calculation if w>0 and mode DUAL (DUAL behaves as BRIGHTER if w==0) //ignore auto-white calculation if w>0 and mode DUAL (DUAL behaves as BRIGHTER if w==0)
if (w > 0 && _autoWhiteMode == RGBW_MODE_DUAL) return c; if (w > 0 && aWM == RGBW_MODE_DUAL) return c;
uint8_t r = R(c); uint8_t r = R(c);
uint8_t g = G(c); uint8_t g = G(c);
uint8_t b = B(c); uint8_t b = B(c);
w = r < g ? (r < b ? r : b) : (g < b ? g : b); w = r < g ? (r < b ? r : b) : (g < b ? g : b);
if (_autoWhiteMode == RGBW_MODE_AUTO_ACCURATE) { r -= w; g -= w; b -= w; } //subtract w in ACCURATE mode if (aWM == RGBW_MODE_AUTO_ACCURATE) { r -= w; g -= w; b -= w; } //subtract w in ACCURATE mode
return RGBW32(r, g, b, w); return RGBW32(r, g, b, w);
} }
}; };
@ -208,7 +231,7 @@ class Bus {
class BusDigital : public Bus { class BusDigital : public Bus {
public: public:
BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) : Bus(bc.type, bc.start), _colorOrderMap(com) { BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) : Bus(bc.type, bc.start, bc.autoWhite), _colorOrderMap(com) {
if (!IS_DIGITAL(bc.type) || !bc.count) return; if (!IS_DIGITAL(bc.type) || !bc.count) return;
if (!pinManager.allocatePin(bc.pins[0], true, PinOwner::BusDigital)) return; if (!pinManager.allocatePin(bc.pins[0], true, PinOwner::BusDigital)) return;
_pins[0] = bc.pins[0]; _pins[0] = bc.pins[0];
@ -227,7 +250,7 @@ class BusDigital : public Bus {
_busPtr = PolyBus::create(_iType, _pins, _len, nr); _busPtr = PolyBus::create(_iType, _pins, _len, nr);
_valid = (_busPtr != nullptr); _valid = (_busPtr != nullptr);
_colorOrder = bc.colorOrder; _colorOrder = bc.colorOrder;
DEBUG_PRINTF("Successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n",nr, _len, bc.type, _pins[0],_pins[1],_iType); DEBUG_PRINTF("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u)\n", _valid?"S":"Uns", nr, _len, bc.type, _pins[0],_pins[1],_iType);
}; };
inline void show() { inline void show() {
@ -245,7 +268,7 @@ class BusDigital : public Bus {
if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) PolyBus::begin(_busPtr, _iType, _pins); if (_pins[0] == LED_BUILTIN || _pins[1] == LED_BUILTIN) PolyBus::begin(_busPtr, _iType, _pins);
} }
#endif #endif
_bri = b; Bus::setBrightness(b);
PolyBus::setBrightness(_busPtr, _iType, b); PolyBus::setBrightness(_busPtr, _iType, b);
} }
@ -287,7 +310,8 @@ class BusDigital : public Bus {
} }
void setColorOrder(uint8_t colorOrder) { void setColorOrder(uint8_t colorOrder) {
if (colorOrder > 5) return; // upper nibble contains W swap information
if ((colorOrder & 0x0F) > 5) return;
_colorOrder = colorOrder; _colorOrder = colorOrder;
} }
@ -325,7 +349,7 @@ class BusDigital : public Bus {
class BusPwm : public Bus { class BusPwm : public Bus {
public: public:
BusPwm(BusConfig &bc) : Bus(bc.type, bc.start) { BusPwm(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
_valid = false; _valid = false;
if (!IS_PWM(bc.type)) return; if (!IS_PWM(bc.type)) return;
uint8_t numPins = NUM_PWM_PINS(bc.type); uint8_t numPins = NUM_PWM_PINS(bc.type);
@ -400,7 +424,6 @@ class BusPwm : public Bus {
_data[0] = ww; _data[0] = ww;
break; break;
case TYPE_ANALOG_5CH: //RGB + warm white + cold white case TYPE_ANALOG_5CH: //RGB + warm white + cold white
// perhaps a non-linear adjustment would be in order. need to test
_data[4] = cw; _data[4] = cw;
w = ww; w = ww;
case TYPE_ANALOG_4CH: //RGBW case TYPE_ANALOG_4CH: //RGBW
@ -431,10 +454,6 @@ class BusPwm : public Bus {
} }
} }
inline void setBrightness(uint8_t b) {
_bri = b;
}
uint8_t getPins(uint8_t* pinArray) { uint8_t getPins(uint8_t* pinArray) {
if (!_valid) return 0; if (!_valid) return 0;
uint8_t numPins = NUM_PWM_PINS(_type); uint8_t numPins = NUM_PWM_PINS(_type);
@ -444,7 +463,7 @@ class BusPwm : public Bus {
return numPins; return numPins;
} }
inline void cleanup() { void cleanup() {
deallocatePins(); deallocatePins();
} }
@ -477,9 +496,66 @@ class BusPwm : public Bus {
}; };
class BusOnOff : public Bus {
public:
BusOnOff(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
_valid = false;
if (bc.type != TYPE_ONOFF) return;
uint8_t currentPin = bc.pins[0];
if (!pinManager.allocatePin(currentPin, true, PinOwner::BusOnOff)) {
return;
}
_pin = currentPin; //store only after allocatePin() succeeds
pinMode(_pin, OUTPUT);
reversed = bc.reversed;
_valid = true;
};
void setPixelColor(uint16_t pix, uint32_t c) {
if (pix != 0 || !_valid) return; //only react to first pixel
c = autoWhiteCalc(c);
uint8_t r = R(c);
uint8_t g = G(c);
uint8_t b = B(c);
uint8_t w = W(c);
_data = bool((r+g+b+w) && _bri) ? 0xFF : 0;
}
uint32_t getPixelColor(uint16_t pix) {
if (!_valid) return 0;
return RGBW32(_data, _data, _data, _data);
}
void show() {
if (!_valid) return;
digitalWrite(_pin, reversed ? !(bool)_data : (bool)_data);
}
uint8_t getPins(uint8_t* pinArray) {
if (!_valid) return 0;
pinArray[0] = _pin;
return 1;
}
void cleanup() {
pinManager.deallocatePin(_pin, PinOwner::BusOnOff);
}
~BusOnOff() {
cleanup();
}
private:
uint8_t _pin = 255;
uint8_t _data = 0;
};
class BusNetwork : public Bus { class BusNetwork : public Bus {
public: public:
BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start) { BusNetwork(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWhite) {
_valid = false; _valid = false;
// switch (bc.type) { // switch (bc.type) {
// case TYPE_NET_ARTNET_RGB: // case TYPE_NET_ARTNET_RGB:
@ -494,9 +570,9 @@ class BusNetwork : public Bus {
// _rgbw = false; // _rgbw = false;
// _UDPtype = 0; // _UDPtype = 0;
// break; // break;
// default: // default: // TYPE_NET_DDP_RGB / TYPE_NET_DDP_RGBW
_rgbw = false; _rgbw = bc.type == TYPE_NET_DDP_RGBW;
_UDPtype = bc.type - TYPE_NET_DDP_RGB; _UDPtype = 0;
// break; // break;
// } // }
_UDPchannels = _rgbw ? 4 : 3; _UDPchannels = _rgbw ? 4 : 3;
@ -509,6 +585,9 @@ class BusNetwork : public Bus {
_valid = true; _valid = true;
}; };
bool hasRGB() { return true; }
bool hasWhite() { return _rgbw; }
void setPixelColor(uint16_t pix, uint32_t c) { void setPixelColor(uint16_t pix, uint32_t c) {
if (!_valid || pix >= _len) return; if (!_valid || pix >= _len) return;
if (isRgbw()) c = autoWhiteCalc(c); if (isRgbw()) c = autoWhiteCalc(c);
@ -538,10 +617,6 @@ class BusNetwork : public Bus {
return !_broadcastLock; return !_broadcastLock;
} }
inline void setBrightness(uint8_t b) {
_bri = b;
}
uint8_t getPins(uint8_t* pinArray) { uint8_t getPins(uint8_t* pinArray) {
for (uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
pinArray[i] = _client[i]; pinArray[i] = _client[i];
@ -570,7 +645,6 @@ class BusNetwork : public Bus {
private: private:
IPAddress _client; IPAddress _client;
uint8_t _bri = 255;
uint8_t _UDPtype; uint8_t _UDPtype;
uint8_t _UDPchannels; uint8_t _UDPchannels;
bool _rgbw; bool _rgbw;
@ -581,9 +655,7 @@ class BusNetwork : public Bus {
class BusManager { class BusManager {
public: public:
BusManager() { BusManager() {};
};
//utility to get the approx. memory usage of a given BusConfig //utility to get the approx. memory usage of a given BusConfig
static uint32_t memUsage(BusConfig &bc) { static uint32_t memUsage(BusConfig &bc) {
@ -613,6 +685,8 @@ class BusManager {
busses[numBusses] = new BusNetwork(bc); busses[numBusses] = new BusNetwork(bc);
} else if (IS_DIGITAL(bc.type)) { } else if (IS_DIGITAL(bc.type)) {
busses[numBusses] = new BusDigital(bc, numBusses, colorOrderMap); busses[numBusses] = new BusDigital(bc, numBusses, colorOrderMap);
} else if (bc.type == TYPE_ONOFF) {
busses[numBusses] = new BusOnOff(bc);
} else { } else {
busses[numBusses] = new BusPwm(bc); busses[numBusses] = new BusPwm(bc);
} }

View File

@ -3,6 +3,21 @@
#include "NeoPixelBrightnessBus.h" #include "NeoPixelBrightnessBus.h"
// temporary - these defines should actually be set in platformio.ini
// C3: I2S0 and I2S1 methods not supported (has one I2S bus)
// S2: I2S1 methods not supported (has one I2S bus)
// S3: I2S0 and I2S1 methods not supported yet (has two I2S buses)
// https://github.com/Makuna/NeoPixelBus/blob/b32f719e95ef3c35c46da5c99538017ef925c026/src/internal/Esp32_i2s.h#L4
// https://github.com/Makuna/NeoPixelBus/blob/b32f719e95ef3c35c46da5c99538017ef925c026/src/internal/NeoEsp32RmtMethod.h#L857
#if !defined(WLED_NO_I2S0_PIXELBUS) && (defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3))
#define WLED_NO_I2S0_PIXELBUS
#endif
#if !defined(WLED_NO_I2S1_PIXELBUS) && (defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2))
#define WLED_NO_I2S1_PIXELBUS
#endif
// temporary end
//Hardware SPI Pins //Hardware SPI Pins
#define P_8266_HS_MOSI 13 #define P_8266_HS_MOSI 13
#define P_8266_HS_CLK 14 #define P_8266_HS_CLK 14
@ -33,45 +48,58 @@
#define I_8266_U1_TM1_4 14 #define I_8266_U1_TM1_4 14
#define I_8266_DM_TM1_4 15 #define I_8266_DM_TM1_4 15
#define I_8266_BB_TM1_4 16 #define I_8266_BB_TM1_4 16
//TM1829 (RGB)
#define I_8266_U0_TM2_3 17
#define I_8266_U1_TM2_3 18
#define I_8266_DM_TM2_3 19
#define I_8266_BB_TM2_3 20
/*** ESP32 Neopixel methods ***/ /*** ESP32 Neopixel methods ***/
//RGB //RGB
#define I_32_RN_NEO_3 17 #define I_32_RN_NEO_3 21
#define I_32_I0_NEO_3 18 #define I_32_I0_NEO_3 22
#define I_32_I1_NEO_3 19 #define I_32_I1_NEO_3 23
#define I_32_BB_NEO_3 24 // bitbangging on ESP32 not recommended
//RGBW //RGBW
#define I_32_RN_NEO_4 20 #define I_32_RN_NEO_4 25
#define I_32_I0_NEO_4 21 #define I_32_I0_NEO_4 26
#define I_32_I1_NEO_4 22 #define I_32_I1_NEO_4 27
#define I_32_BB_NEO_4 28 // bitbangging on ESP32 not recommended
//400Kbps //400Kbps
#define I_32_RN_400_3 23 #define I_32_RN_400_3 29
#define I_32_I0_400_3 24 #define I_32_I0_400_3 30
#define I_32_I1_400_3 25 #define I_32_I1_400_3 31
#define I_32_BB_400_3 32 // bitbangging on ESP32 not recommended
//TM1814 (RGBW) //TM1814 (RGBW)
#define I_32_RN_TM1_4 26 #define I_32_RN_TM1_4 33
#define I_32_I0_TM1_4 27 #define I_32_I0_TM1_4 34
#define I_32_I1_TM1_4 28 #define I_32_I1_TM1_4 35
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
//TM1829 (RGB)
#define I_32_RN_TM2_3 36
#define I_32_I0_TM2_3 37
#define I_32_I1_TM2_3 38
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S) //Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
//APA102 //APA102
#define I_HS_DOT_3 29 //hardware SPI #define I_HS_DOT_3 39 //hardware SPI
#define I_SS_DOT_3 30 //soft SPI #define I_SS_DOT_3 40 //soft SPI
//LPD8806 //LPD8806
#define I_HS_LPD_3 31 #define I_HS_LPD_3 41
#define I_SS_LPD_3 32 #define I_SS_LPD_3 42
//WS2801 //WS2801
#define I_HS_WS1_3 33 #define I_HS_WS1_3 43
#define I_SS_WS1_3 34 #define I_SS_WS1_3 44
//P9813 //P9813
#define I_HS_P98_3 35 #define I_HS_P98_3 45
#define I_SS_P98_3 36 #define I_SS_P98_3 46
//LPD6803 //LPD6803
#define I_HS_LPO_3 37 #define I_HS_LPO_3 47
#define I_SS_LPO_3 38 #define I_SS_LPO_3 48
/*** ESP8266 Neopixel methods ***/ /*** ESP8266 Neopixel methods ***/
@ -96,43 +124,60 @@
#define B_8266_U1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266Uart1Tm1814Method> #define B_8266_U1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266Uart1Tm1814Method>
#define B_8266_DM_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266DmaTm1814Method> #define B_8266_DM_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266DmaTm1814Method>
#define B_8266_BB_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266BitBangTm1814Method> #define B_8266_BB_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp8266BitBangTm1814Method>
//TM1829 (RGB)
#define B_8266_U0_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Uart0Tm1829Method>
#define B_8266_U1_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266Uart1Tm1829Method>
#define B_8266_DM_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266DmaTm1829Method>
#define B_8266_BB_TM2_4 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp8266BitBangTm1829Method>
#endif #endif
/*** ESP32 Neopixel methods ***/ /*** ESP32 Neopixel methods ***/
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
//RGB //RGB
#define B_32_RN_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32RmtNWs2812xMethod> #define B_32_RN_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32RmtNWs2812xMethod>
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
#define B_32_I0_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s0800KbpsMethod> #define B_32_I0_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s0800KbpsMethod>
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
#define B_32_I1_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1800KbpsMethod> #define B_32_I1_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1800KbpsMethod>
#endif #endif
//#define B_32_BB_NEO_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32BitBang800KbpsMethod> // NeoEsp8266BitBang800KbpsMethod
//RGBW //RGBW
#define B_32_RN_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32RmtNWs2812xMethod> #define B_32_RN_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32RmtNWs2812xMethod>
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
#define B_32_I0_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s0800KbpsMethod> #define B_32_I0_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s0800KbpsMethod>
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
#define B_32_I1_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s1800KbpsMethod> #define B_32_I1_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32I2s1800KbpsMethod>
#endif #endif
//#define B_32_BB_NEO_4 NeoPixelBrightnessBus<NeoGrbwFeature, NeoEsp32BitBang800KbpsMethod> // NeoEsp8266BitBang800KbpsMethod
//400Kbps //400Kbps
#define B_32_RN_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32RmtN400KbpsMethod> #define B_32_RN_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32RmtN400KbpsMethod>
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
#define B_32_I0_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s0400KbpsMethod> #define B_32_I0_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s0400KbpsMethod>
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
#define B_32_I1_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1400KbpsMethod> #define B_32_I1_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32I2s1400KbpsMethod>
#endif #endif
//#define B_32_BB_400_3 NeoPixelBrightnessBus<NeoGrbFeature, NeoEsp32BitBang400KbpsMethod> // NeoEsp8266BitBang400KbpsMethod
//TM1814 (RGBW) //TM1814 (RGBW)
#define B_32_RN_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32RmtNTm1814Method> #define B_32_RN_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32RmtNTm1814Method>
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
#define B_32_I0_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32I2s0Tm1814Method> #define B_32_I0_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32I2s0Tm1814Method>
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
#define B_32_I1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32I2s1Tm1814Method> #define B_32_I1_TM1_4 NeoPixelBrightnessBus<NeoWrgbTm1814Feature, NeoEsp32I2s1Tm1814Method>
#endif #endif
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S) //Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
//TM1829 (RGB)
#define B_32_RN_TM2_3 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp32RmtNTm1829Method>
#ifndef WLED_NO_I2S0_PIXELBUS
#define B_32_I0_TM2_3 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp32I2s0Tm1829Method>
#endif
#ifndef WLED_NO_I2S1_PIXELBUS
#define B_32_I1_TM2_3 NeoPixelBrightnessBus<NeoBrgFeature, NeoEsp32I2s1Tm1829Method>
#endif
//Bit Bang theoratically possible, but very undesirable and not needed (no pin restrictions on RMT and I2S)
#endif #endif
@ -149,10 +194,21 @@
#define B_SS_LPO_3 NeoPixelBrightnessBus<Lpd6803GrbFeature, Lpd6803Method> #define B_SS_LPO_3 NeoPixelBrightnessBus<Lpd6803GrbFeature, Lpd6803Method>
//WS2801 //WS2801
//#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi40MhzMethod> #if defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==40000
//#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi20MhzMethod> #define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi40MhzMethod> // fastest bus speed (not existing method?)
//#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801SpiMethod> // 10MHz #elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==20000
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi20MhzMethod> // 20MHz
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==10000
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801SpiMethod> // 10MHz
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==2000
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod> //slower, more compatible #define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod> //slower, more compatible
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==1000
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi1MhzMethod> //slower, more compatible
#elif defined(WLED_WS2801_SPEED_KHZ) && WLED_WS2801_SPEED_KHZ==500
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi500KhzMethod> //slower, more compatible
#else
#define B_HS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod> // 2MHz; slower, more compatible
#endif
#define B_SS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Method> #define B_SS_WS1_3 NeoPixelBrightnessBus<NeoRbgFeature, NeoWs2801Method>
//P9813 //P9813
@ -190,6 +246,10 @@ class PolyBus {
case I_8266_U1_TM1_4: beginTM1814<B_8266_U1_TM1_4*>(busPtr); break; case I_8266_U1_TM1_4: beginTM1814<B_8266_U1_TM1_4*>(busPtr); break;
case I_8266_DM_TM1_4: beginTM1814<B_8266_DM_TM1_4*>(busPtr); break; case I_8266_DM_TM1_4: beginTM1814<B_8266_DM_TM1_4*>(busPtr); break;
case I_8266_BB_TM1_4: beginTM1814<B_8266_BB_TM1_4*>(busPtr); break; case I_8266_BB_TM1_4: beginTM1814<B_8266_BB_TM1_4*>(busPtr); break;
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->Begin(); break;
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->Begin(); break;
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->Begin(); break;
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->Begin(); break;
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break; case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(); break;
case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break; case I_HS_LPD_3: (static_cast<B_HS_LPD_3*>(busPtr))->Begin(); break;
case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->Begin(); break; case I_HS_LPO_3: (static_cast<B_HS_LPO_3*>(busPtr))->Begin(); break;
@ -198,32 +258,38 @@ class PolyBus {
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Begin(); break; case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Begin(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->Begin(); break; case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->Begin(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->Begin(); break; case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->Begin(); break;
#endif #endif
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->Begin(); break;
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->Begin(); break; case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->Begin(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->Begin(); break; case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->Begin(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->Begin(); break; case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->Begin(); break;
#endif #endif
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->Begin(); break;
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->Begin(); break; case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->Begin(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Begin(); break; case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Begin(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Begin(); break; case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Begin(); break;
#endif #endif
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->Begin(); break;
case I_32_RN_TM1_4: beginTM1814<B_32_RN_TM1_4*>(busPtr); break; case I_32_RN_TM1_4: beginTM1814<B_32_RN_TM1_4*>(busPtr); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->Begin(); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: beginTM1814<B_32_I0_TM1_4*>(busPtr); break; case I_32_I0_TM1_4: beginTM1814<B_32_I0_TM1_4*>(busPtr); break;
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->Begin(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: beginTM1814<B_32_I1_TM1_4*>(busPtr); break; case I_32_I1_TM1_4: beginTM1814<B_32_I1_TM1_4*>(busPtr); break;
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->Begin(); break;
#endif #endif
// ESP32 can (and should, to avoid inadvertantly driving the chip select signal) specify the pins used for SPI, but only in begin() // ESP32 can (and should, to avoid inadvertantly driving the chip select signal) specify the pins used for SPI, but only in begin()
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break; case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Begin(pins[1], -1, pins[0], -1); break;
@ -260,35 +326,45 @@ class PolyBus {
case I_8266_U1_TM1_4: busPtr = new B_8266_U1_TM1_4(len, pins[0]); break; case I_8266_U1_TM1_4: busPtr = new B_8266_U1_TM1_4(len, pins[0]); break;
case I_8266_DM_TM1_4: busPtr = new B_8266_DM_TM1_4(len, pins[0]); break; case I_8266_DM_TM1_4: busPtr = new B_8266_DM_TM1_4(len, pins[0]); break;
case I_8266_BB_TM1_4: busPtr = new B_8266_BB_TM1_4(len, pins[0]); break; case I_8266_BB_TM1_4: busPtr = new B_8266_BB_TM1_4(len, pins[0]); break;
case I_8266_U0_TM2_3: busPtr = new B_8266_U0_TM2_4(len, pins[0]); break;
case I_8266_U1_TM2_3: busPtr = new B_8266_U1_TM2_4(len, pins[0]); break;
case I_8266_DM_TM2_3: busPtr = new B_8266_DM_TM2_4(len, pins[0]); break;
case I_8266_BB_TM2_3: busPtr = new B_8266_BB_TM2_4(len, pins[0]); break;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: busPtr = new B_32_RN_NEO_3(len, pins[0], (NeoBusChannel)channel); break; case I_32_RN_NEO_3: busPtr = new B_32_RN_NEO_3(len, pins[0], (NeoBusChannel)channel); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: busPtr = new B_32_I0_NEO_3(len, pins[0]); break; case I_32_I0_NEO_3: busPtr = new B_32_I0_NEO_3(len, pins[0]); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: busPtr = new B_32_I1_NEO_3(len, pins[0]); break; case I_32_I1_NEO_3: busPtr = new B_32_I1_NEO_3(len, pins[0]); break;
#endif #endif
// case I_32_BB_NEO_3: busPtr = new B_32_BB_NEO_3(len, pins[0], (NeoBusChannel)channel); break;
case I_32_RN_NEO_4: busPtr = new B_32_RN_NEO_4(len, pins[0], (NeoBusChannel)channel); break; case I_32_RN_NEO_4: busPtr = new B_32_RN_NEO_4(len, pins[0], (NeoBusChannel)channel); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: busPtr = new B_32_I0_NEO_4(len, pins[0]); break; case I_32_I0_NEO_4: busPtr = new B_32_I0_NEO_4(len, pins[0]); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: busPtr = new B_32_I1_NEO_4(len, pins[0]); break; case I_32_I1_NEO_4: busPtr = new B_32_I1_NEO_4(len, pins[0]); break;
#endif #endif
// case I_32_BB_NEO_4: busPtr = new B_32_BB_NEO_4(len, pins[0], (NeoBusChannel)channel); break;
case I_32_RN_400_3: busPtr = new B_32_RN_400_3(len, pins[0], (NeoBusChannel)channel); break; case I_32_RN_400_3: busPtr = new B_32_RN_400_3(len, pins[0], (NeoBusChannel)channel); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: busPtr = new B_32_I0_400_3(len, pins[0]); break; case I_32_I0_400_3: busPtr = new B_32_I0_400_3(len, pins[0]); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: busPtr = new B_32_I1_400_3(len, pins[0]); break; case I_32_I1_400_3: busPtr = new B_32_I1_400_3(len, pins[0]); break;
#endif #endif
// case I_32_BB_400_3: busPtr = new B_32_BB_400_3(len, pins[0], (NeoBusChannel)channel); break;
case I_32_RN_TM1_4: busPtr = new B_32_RN_TM1_4(len, pins[0], (NeoBusChannel)channel); break; case I_32_RN_TM1_4: busPtr = new B_32_RN_TM1_4(len, pins[0], (NeoBusChannel)channel); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: busPtr = new B_32_RN_TM2_3(len, pins[0], (NeoBusChannel)channel); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: busPtr = new B_32_I0_TM1_4(len, pins[0]); break; case I_32_I0_TM1_4: busPtr = new B_32_I0_TM1_4(len, pins[0]); break;
case I_32_I0_TM2_3: busPtr = new B_32_I0_TM2_3(len, pins[0]); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: busPtr = new B_32_I1_TM1_4(len, pins[0]); break; case I_32_I1_TM1_4: busPtr = new B_32_I1_TM1_4(len, pins[0]); break;
case I_32_I1_TM2_3: busPtr = new B_32_I1_TM2_3(len, pins[0]); break;
#endif #endif
#endif #endif
// for 2-wire: pins[1] is clk, pins[0] is dat. begin expects (len, clk, dat) // for 2-wire: pins[1] is clk, pins[0] is dat. begin expects (len, clk, dat)
@ -326,35 +402,45 @@ class PolyBus {
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->Show(); break; case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->Show(); break;
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->Show(); break; case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->Show(); break;
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->Show(); break; case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->Show(); break;
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->Show(); break;
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->Show(); break;
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->Show(); break;
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->Show(); break;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Show(); break; case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->Show(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->Show(); break; case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->Show(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->Show(); break; case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->Show(); break;
#endif #endif
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->Show(); break;
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->Show(); break; case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->Show(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->Show(); break; case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->Show(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->Show(); break; case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->Show(); break;
#endif #endif
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->Show(); break;
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->Show(); break; case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->Show(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Show(); break; case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->Show(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Show(); break; case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->Show(); break;
#endif #endif
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->Show(); break;
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->Show(); break; case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->Show(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->Show(); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->Show(); break; case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->Show(); break;
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->Show(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->Show(); break; case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->Show(); break;
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->Show(); break;
#endif #endif
#endif #endif
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Show(); break; case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->Show(); break;
@ -389,35 +475,45 @@ class PolyBus {
case I_8266_U1_TM1_4: return (static_cast<B_8266_U1_TM1_4*>(busPtr))->CanShow(); break; case I_8266_U1_TM1_4: return (static_cast<B_8266_U1_TM1_4*>(busPtr))->CanShow(); break;
case I_8266_DM_TM1_4: return (static_cast<B_8266_DM_TM1_4*>(busPtr))->CanShow(); break; case I_8266_DM_TM1_4: return (static_cast<B_8266_DM_TM1_4*>(busPtr))->CanShow(); break;
case I_8266_BB_TM1_4: return (static_cast<B_8266_BB_TM1_4*>(busPtr))->CanShow(); break; case I_8266_BB_TM1_4: return (static_cast<B_8266_BB_TM1_4*>(busPtr))->CanShow(); break;
case I_8266_U0_TM2_3: return (static_cast<B_8266_U0_TM2_4*>(busPtr))->CanShow(); break;
case I_8266_U1_TM2_3: return (static_cast<B_8266_U1_TM2_4*>(busPtr))->CanShow(); break;
case I_8266_DM_TM2_3: return (static_cast<B_8266_DM_TM2_4*>(busPtr))->CanShow(); break;
case I_8266_BB_TM2_3: return (static_cast<B_8266_BB_TM2_4*>(busPtr))->CanShow(); break;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: return (static_cast<B_32_RN_NEO_3*>(busPtr))->CanShow(); break; case I_32_RN_NEO_3: return (static_cast<B_32_RN_NEO_3*>(busPtr))->CanShow(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: return (static_cast<B_32_I0_NEO_3*>(busPtr))->CanShow(); break; case I_32_I0_NEO_3: return (static_cast<B_32_I0_NEO_3*>(busPtr))->CanShow(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: return (static_cast<B_32_I1_NEO_3*>(busPtr))->CanShow(); break; case I_32_I1_NEO_3: return (static_cast<B_32_I1_NEO_3*>(busPtr))->CanShow(); break;
#endif #endif
// case I_32_BB_NEO_3: return (static_cast<B_32_BB_NEO_3*>(busPtr))->CanShow(); break;
case I_32_RN_NEO_4: return (static_cast<B_32_RN_NEO_4*>(busPtr))->CanShow(); break; case I_32_RN_NEO_4: return (static_cast<B_32_RN_NEO_4*>(busPtr))->CanShow(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: return (static_cast<B_32_I0_NEO_4*>(busPtr))->CanShow(); break; case I_32_I0_NEO_4: return (static_cast<B_32_I0_NEO_4*>(busPtr))->CanShow(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: return (static_cast<B_32_I1_NEO_4*>(busPtr))->CanShow(); break; case I_32_I1_NEO_4: return (static_cast<B_32_I1_NEO_4*>(busPtr))->CanShow(); break;
#endif #endif
// case I_32_BB_NEO_4: return (static_cast<B_32_BB_NEO_4*>(busPtr))->CanShow(); break;
case I_32_RN_400_3: return (static_cast<B_32_RN_400_3*>(busPtr))->CanShow(); break; case I_32_RN_400_3: return (static_cast<B_32_RN_400_3*>(busPtr))->CanShow(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: return (static_cast<B_32_I0_400_3*>(busPtr))->CanShow(); break; case I_32_I0_400_3: return (static_cast<B_32_I0_400_3*>(busPtr))->CanShow(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: return (static_cast<B_32_I1_400_3*>(busPtr))->CanShow(); break; case I_32_I1_400_3: return (static_cast<B_32_I1_400_3*>(busPtr))->CanShow(); break;
#endif #endif
// case I_32_BB_400_3: return (static_cast<B_32_BB_400_3*>(busPtr))->CanShow(); break;
case I_32_RN_TM1_4: return (static_cast<B_32_RN_TM1_4*>(busPtr))->CanShow(); break; case I_32_RN_TM1_4: return (static_cast<B_32_RN_TM1_4*>(busPtr))->CanShow(); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: return (static_cast<B_32_RN_TM2_3*>(busPtr))->CanShow(); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: return (static_cast<B_32_I0_TM1_4*>(busPtr))->CanShow(); break; case I_32_I0_TM1_4: return (static_cast<B_32_I0_TM1_4*>(busPtr))->CanShow(); break;
case I_32_I0_TM2_3: return (static_cast<B_32_I0_TM2_3*>(busPtr))->CanShow(); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: return (static_cast<B_32_I1_TM1_4*>(busPtr))->CanShow(); break; case I_32_I1_TM1_4: return (static_cast<B_32_I1_TM1_4*>(busPtr))->CanShow(); break;
case I_32_I1_TM2_3: return (static_cast<B_32_I1_TM2_3*>(busPtr))->CanShow(); break;
#endif #endif
#endif #endif
case I_HS_DOT_3: return (static_cast<B_HS_DOT_3*>(busPtr))->CanShow(); break; case I_HS_DOT_3: return (static_cast<B_HS_DOT_3*>(busPtr))->CanShow(); break;
@ -440,22 +536,22 @@ class PolyBus {
uint8_t w = c >> 24; uint8_t w = c >> 24;
RgbwColor col; RgbwColor col;
//TODO make color order override possible on a per-strip basis
#ifdef COLOR_ORDER_OVERRIDE
if (pix >= COO_MIN && pix < COO_MAX) co = COO_ORDER;
#endif
// reorder channels to selected order // reorder channels to selected order
switch (co) switch (co & 0x0F) {
{ default: col.G = g; col.R = r; col.B = b; break; //0 = GRB, default
case 0: col.G = g; col.R = r; col.B = b; break; //0 = GRB, default
case 1: col.G = r; col.R = g; col.B = b; break; //1 = RGB, common for WS2811 case 1: col.G = r; col.R = g; col.B = b; break; //1 = RGB, common for WS2811
case 2: col.G = b; col.R = r; col.B = g; break; //2 = BRG case 2: col.G = b; col.R = r; col.B = g; break; //2 = BRG
case 3: col.G = r; col.R = b; col.B = g; break; //3 = RBG case 3: col.G = r; col.R = b; col.B = g; break; //3 = RBG
case 4: col.G = b; col.R = g; col.B = r; break; //4 = BGR case 4: col.G = b; col.R = g; col.B = r; break; //4 = BGR
default: col.G = g; col.R = b; col.B = r; break; //5 = GBR case 5: col.G = g; col.R = b; col.B = r; break; //5 = GBR
}
// upper nibble contains W swap information
switch (co >> 4) {
default: col.W = w; break; // no swapping
case 1: col.W = col.B; col.B = w; break; // swap W & B
case 2: col.W = col.G; col.G = w; break; // swap W & G
case 3: col.W = col.R; col.R = w; break; // swap W & R
} }
col.W = w;
switch (busType) { switch (busType) {
case I_NONE: break; case I_NONE: break;
@ -476,35 +572,45 @@ class PolyBus {
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break; case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetPixelColor(pix, col); break; case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetPixelColor(pix, col); break; case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break; case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break; case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break; case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#endif #endif
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetPixelColor(pix, col); break; case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetPixelColor(pix, col); break; case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetPixelColor(pix, col); break; case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
#endif #endif
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->SetPixelColor(pix, col); break;
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break; case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break; case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break; case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#endif #endif
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetPixelColor(pix, col); break; case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetPixelColor(pix, col); break; case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break; case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetPixelColor(pix, col); break;
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
#endif #endif
#endif #endif
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break; case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetPixelColor(pix, RgbColor(col.R,col.G,col.B)); break;
@ -539,35 +645,45 @@ class PolyBus {
case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetBrightness(b); break; case I_8266_U1_TM1_4: (static_cast<B_8266_U1_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetBrightness(b); break; case I_8266_DM_TM1_4: (static_cast<B_8266_DM_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetBrightness(b); break; case I_8266_BB_TM1_4: (static_cast<B_8266_BB_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_8266_U0_TM2_3: (static_cast<B_8266_U0_TM2_4*>(busPtr))->SetBrightness(b); break;
case I_8266_U1_TM2_3: (static_cast<B_8266_U1_TM2_4*>(busPtr))->SetBrightness(b); break;
case I_8266_DM_TM2_3: (static_cast<B_8266_DM_TM2_4*>(busPtr))->SetBrightness(b); break;
case I_8266_BB_TM2_3: (static_cast<B_8266_BB_TM2_4*>(busPtr))->SetBrightness(b); break;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetBrightness(b); break; case I_32_RN_NEO_3: (static_cast<B_32_RN_NEO_3*>(busPtr))->SetBrightness(b); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetBrightness(b); break; case I_32_I0_NEO_3: (static_cast<B_32_I0_NEO_3*>(busPtr))->SetBrightness(b); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetBrightness(b); break; case I_32_I1_NEO_3: (static_cast<B_32_I1_NEO_3*>(busPtr))->SetBrightness(b); break;
#endif #endif
// case I_32_BB_NEO_3: (static_cast<B_32_BB_NEO_3*>(busPtr))->SetBrightness(b); break;
case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetBrightness(b); break; case I_32_RN_NEO_4: (static_cast<B_32_RN_NEO_4*>(busPtr))->SetBrightness(b); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetBrightness(b); break; case I_32_I0_NEO_4: (static_cast<B_32_I0_NEO_4*>(busPtr))->SetBrightness(b); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetBrightness(b); break; case I_32_I1_NEO_4: (static_cast<B_32_I1_NEO_4*>(busPtr))->SetBrightness(b); break;
#endif #endif
// case I_32_BB_NEO_4: (static_cast<B_32_BB_NEO_4*>(busPtr))->SetBrightness(b); break;
case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetBrightness(b); break; case I_32_RN_400_3: (static_cast<B_32_RN_400_3*>(busPtr))->SetBrightness(b); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetBrightness(b); break; case I_32_I0_400_3: (static_cast<B_32_I0_400_3*>(busPtr))->SetBrightness(b); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetBrightness(b); break; case I_32_I1_400_3: (static_cast<B_32_I1_400_3*>(busPtr))->SetBrightness(b); break;
#endif #endif
// case I_32_BB_400_3: (static_cast<B_32_BB_400_3*>(busPtr))->SetBrightness(b); break;
case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetBrightness(b); break; case I_32_RN_TM1_4: (static_cast<B_32_RN_TM1_4*>(busPtr))->SetBrightness(b); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: (static_cast<B_32_RN_TM2_3*>(busPtr))->SetBrightness(b); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetBrightness(b); break; case I_32_I0_TM1_4: (static_cast<B_32_I0_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_I0_TM2_3: (static_cast<B_32_I0_TM2_3*>(busPtr))->SetBrightness(b); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetBrightness(b); break; case I_32_I1_TM1_4: (static_cast<B_32_I1_TM1_4*>(busPtr))->SetBrightness(b); break;
case I_32_I1_TM2_3: (static_cast<B_32_I1_TM2_3*>(busPtr))->SetBrightness(b); break;
#endif #endif
#endif #endif
case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetBrightness(b); break; case I_HS_DOT_3: (static_cast<B_HS_DOT_3*>(busPtr))->SetBrightness(b); break;
@ -603,35 +719,45 @@ class PolyBus {
case I_8266_U1_TM1_4: col = (static_cast<B_8266_U1_TM1_4*>(busPtr))->GetPixelColor(pix); break; case I_8266_U1_TM1_4: col = (static_cast<B_8266_U1_TM1_4*>(busPtr))->GetPixelColor(pix); break;
case I_8266_DM_TM1_4: col = (static_cast<B_8266_DM_TM1_4*>(busPtr))->GetPixelColor(pix); break; case I_8266_DM_TM1_4: col = (static_cast<B_8266_DM_TM1_4*>(busPtr))->GetPixelColor(pix); break;
case I_8266_BB_TM1_4: col = (static_cast<B_8266_BB_TM1_4*>(busPtr))->GetPixelColor(pix); break; case I_8266_BB_TM1_4: col = (static_cast<B_8266_BB_TM1_4*>(busPtr))->GetPixelColor(pix); break;
case I_8266_U0_TM2_3: col = (static_cast<B_8266_U0_TM2_4*>(busPtr))->GetPixelColor(pix); break;
case I_8266_U1_TM2_3: col = (static_cast<B_8266_U1_TM2_4*>(busPtr))->GetPixelColor(pix); break;
case I_8266_DM_TM2_3: col = (static_cast<B_8266_DM_TM2_4*>(busPtr))->GetPixelColor(pix); break;
case I_8266_BB_TM2_3: col = (static_cast<B_8266_BB_TM2_4*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: col = (static_cast<B_32_RN_NEO_3*>(busPtr))->GetPixelColor(pix); break; case I_32_RN_NEO_3: col = (static_cast<B_32_RN_NEO_3*>(busPtr))->GetPixelColor(pix); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: col = (static_cast<B_32_I0_NEO_3*>(busPtr))->GetPixelColor(pix); break; case I_32_I0_NEO_3: col = (static_cast<B_32_I0_NEO_3*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: col = (static_cast<B_32_I1_NEO_3*>(busPtr))->GetPixelColor(pix); break; case I_32_I1_NEO_3: col = (static_cast<B_32_I1_NEO_3*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
// case I_32_BB_NEO_3: col = (static_cast<B_32_BB_NEO_3*>(busPtr))->GetPixelColor(pix); break;
case I_32_RN_NEO_4: col = (static_cast<B_32_RN_NEO_4*>(busPtr))->GetPixelColor(pix); break; case I_32_RN_NEO_4: col = (static_cast<B_32_RN_NEO_4*>(busPtr))->GetPixelColor(pix); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: col = (static_cast<B_32_I0_NEO_4*>(busPtr))->GetPixelColor(pix); break; case I_32_I0_NEO_4: col = (static_cast<B_32_I0_NEO_4*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: col = (static_cast<B_32_I1_NEO_4*>(busPtr))->GetPixelColor(pix); break; case I_32_I1_NEO_4: col = (static_cast<B_32_I1_NEO_4*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
// case I_32_BB_NEO_4: col = (static_cast<B_32_BB_NEO_4*>(busPtr))->GetPixelColor(pix); break;
case I_32_RN_400_3: col = (static_cast<B_32_RN_400_3*>(busPtr))->GetPixelColor(pix); break; case I_32_RN_400_3: col = (static_cast<B_32_RN_400_3*>(busPtr))->GetPixelColor(pix); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: col = (static_cast<B_32_I0_400_3*>(busPtr))->GetPixelColor(pix); break; case I_32_I0_400_3: col = (static_cast<B_32_I0_400_3*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: col = (static_cast<B_32_I1_400_3*>(busPtr))->GetPixelColor(pix); break; case I_32_I1_400_3: col = (static_cast<B_32_I1_400_3*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
// case I_32_BB_400_3: col = (static_cast<B_32_BB_400_3*>(busPtr))->GetPixelColor(pix); break;
case I_32_RN_TM1_4: col = (static_cast<B_32_RN_TM1_4*>(busPtr))->GetPixelColor(pix); break; case I_32_RN_TM1_4: col = (static_cast<B_32_RN_TM1_4*>(busPtr))->GetPixelColor(pix); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: col = (static_cast<B_32_RN_TM2_3*>(busPtr))->GetPixelColor(pix); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: col = (static_cast<B_32_I0_TM1_4*>(busPtr))->GetPixelColor(pix); break; case I_32_I0_TM1_4: col = (static_cast<B_32_I0_TM1_4*>(busPtr))->GetPixelColor(pix); break;
case I_32_I0_TM2_3: col = (static_cast<B_32_I0_TM2_3*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: col = (static_cast<B_32_I1_TM1_4*>(busPtr))->GetPixelColor(pix); break; case I_32_I1_TM1_4: col = (static_cast<B_32_I1_TM1_4*>(busPtr))->GetPixelColor(pix); break;
case I_32_I1_TM2_3: col = (static_cast<B_32_I1_TM2_3*>(busPtr))->GetPixelColor(pix); break;
#endif #endif
#endif #endif
case I_HS_DOT_3: col = (static_cast<B_HS_DOT_3*>(busPtr))->GetPixelColor(pix); break; case I_HS_DOT_3: col = (static_cast<B_HS_DOT_3*>(busPtr))->GetPixelColor(pix); break;
@ -646,14 +772,16 @@ class PolyBus {
case I_SS_P98_3: col = (static_cast<B_SS_P98_3*>(busPtr))->GetPixelColor(pix); break; case I_SS_P98_3: col = (static_cast<B_SS_P98_3*>(busPtr))->GetPixelColor(pix); break;
} }
#ifdef COLOR_ORDER_OVERRIDE // upper nibble contains W swap information
if (pix >= COO_MIN && pix < COO_MAX) co = COO_ORDER; uint8_t w = col.W;
#endif switch (co >> 4) {
case 1: col.W = col.B; col.B = w; break; // swap W & B
switch (co) case 2: col.W = col.G; col.G = w; break; // swap W & G
{ case 3: col.W = col.R; col.R = w; break; // swap W & R
}
switch (co & 0x0F) {
// W G R B // W G R B
case 0: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default default: return ((col.W << 24) | (col.G << 8) | (col.R << 16) | (col.B)); //0 = GRB, default
case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811 case 1: return ((col.W << 24) | (col.R << 8) | (col.G << 16) | (col.B)); //1 = RGB, common for WS2811
case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG case 2: return ((col.W << 24) | (col.B << 8) | (col.R << 16) | (col.G)); //2 = BRG
case 3: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //3 = RBG case 3: return ((col.W << 24) | (col.B << 8) | (col.G << 16) | (col.R)); //3 = RBG
@ -684,35 +812,45 @@ class PolyBus {
case I_8266_U1_TM1_4: delete (static_cast<B_8266_U1_TM1_4*>(busPtr)); break; case I_8266_U1_TM1_4: delete (static_cast<B_8266_U1_TM1_4*>(busPtr)); break;
case I_8266_DM_TM1_4: delete (static_cast<B_8266_DM_TM1_4*>(busPtr)); break; case I_8266_DM_TM1_4: delete (static_cast<B_8266_DM_TM1_4*>(busPtr)); break;
case I_8266_BB_TM1_4: delete (static_cast<B_8266_BB_TM1_4*>(busPtr)); break; case I_8266_BB_TM1_4: delete (static_cast<B_8266_BB_TM1_4*>(busPtr)); break;
case I_8266_U0_TM2_3: delete (static_cast<B_8266_U0_TM2_4*>(busPtr)); break;
case I_8266_U1_TM2_3: delete (static_cast<B_8266_U1_TM2_4*>(busPtr)); break;
case I_8266_DM_TM2_3: delete (static_cast<B_8266_DM_TM2_4*>(busPtr)); break;
case I_8266_BB_TM2_3: delete (static_cast<B_8266_BB_TM2_4*>(busPtr)); break;
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
case I_32_RN_NEO_3: delete (static_cast<B_32_RN_NEO_3*>(busPtr)); break; case I_32_RN_NEO_3: delete (static_cast<B_32_RN_NEO_3*>(busPtr)); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_3: delete (static_cast<B_32_I0_NEO_3*>(busPtr)); break; case I_32_I0_NEO_3: delete (static_cast<B_32_I0_NEO_3*>(busPtr)); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_3: delete (static_cast<B_32_I1_NEO_3*>(busPtr)); break; case I_32_I1_NEO_3: delete (static_cast<B_32_I1_NEO_3*>(busPtr)); break;
#endif #endif
// case I_32_BB_NEO_3: delete (static_cast<B_32_BB_NEO_3*>(busPtr)); break;
case I_32_RN_NEO_4: delete (static_cast<B_32_RN_NEO_4*>(busPtr)); break; case I_32_RN_NEO_4: delete (static_cast<B_32_RN_NEO_4*>(busPtr)); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_NEO_4: delete (static_cast<B_32_I0_NEO_4*>(busPtr)); break; case I_32_I0_NEO_4: delete (static_cast<B_32_I0_NEO_4*>(busPtr)); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_NEO_4: delete (static_cast<B_32_I1_NEO_4*>(busPtr)); break; case I_32_I1_NEO_4: delete (static_cast<B_32_I1_NEO_4*>(busPtr)); break;
#endif #endif
// case I_32_BB_NEO_4: delete (static_cast<B_32_BB_NEO_4*>(busPtr)); break;
case I_32_RN_400_3: delete (static_cast<B_32_RN_400_3*>(busPtr)); break; case I_32_RN_400_3: delete (static_cast<B_32_RN_400_3*>(busPtr)); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 #ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_400_3: delete (static_cast<B_32_I0_400_3*>(busPtr)); break; case I_32_I0_400_3: delete (static_cast<B_32_I0_400_3*>(busPtr)); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_400_3: delete (static_cast<B_32_I1_400_3*>(busPtr)); break; case I_32_I1_400_3: delete (static_cast<B_32_I1_400_3*>(busPtr)); break;
#endif #endif
// case I_32_BB_400_3: delete (static_cast<B_32_BB_400_3*>(busPtr)); break;
case I_32_RN_TM1_4: delete (static_cast<B_32_RN_TM1_4*>(busPtr)); break; case I_32_RN_TM1_4: delete (static_cast<B_32_RN_TM1_4*>(busPtr)); break;
#ifndef CONFIG_IDF_TARGET_ESP32C3 case I_32_RN_TM2_3: delete (static_cast<B_32_RN_TM2_3*>(busPtr)); break;
#ifndef WLED_NO_I2S0_PIXELBUS
case I_32_I0_TM1_4: delete (static_cast<B_32_I0_TM1_4*>(busPtr)); break; case I_32_I0_TM1_4: delete (static_cast<B_32_I0_TM1_4*>(busPtr)); break;
case I_32_I0_TM2_3: delete (static_cast<B_32_I0_TM2_3*>(busPtr)); break;
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) #ifndef WLED_NO_I2S1_PIXELBUS
case I_32_I1_TM1_4: delete (static_cast<B_32_I1_TM1_4*>(busPtr)); break; case I_32_I1_TM1_4: delete (static_cast<B_32_I1_TM1_4*>(busPtr)); break;
case I_32_I1_TM2_3: delete (static_cast<B_32_I1_TM2_3*>(busPtr)); break;
#endif #endif
#endif #endif
case I_HS_DOT_3: delete (static_cast<B_HS_DOT_3*>(busPtr)); break; case I_HS_DOT_3: delete (static_cast<B_HS_DOT_3*>(busPtr)); break;
@ -736,7 +874,9 @@ class PolyBus {
#ifdef ESP8266 #ifdef ESP8266
if (pins[0] == P_8266_HS_MOSI && pins[1] == P_8266_HS_CLK) isHSPI = true; if (pins[0] == P_8266_HS_MOSI && pins[1] == P_8266_HS_CLK) isHSPI = true;
#else #else
if(!num) isHSPI = true; // temporary hack to limit use of hardware SPI to a single SPI peripheral: only allow ESP32 hardware serial on segment 0 // temporary hack to limit use of hardware SPI to a single SPI peripheral (HSPI): only allow ESP32 hardware serial on segment 0
// SPI global variable is normally linked to VSPI on ESP32 (or FSPI C3, S3)
if (!num) isHSPI = true;
#endif #endif
uint8_t t = I_NONE; uint8_t t = I_NONE;
switch (busType) { switch (busType) {
@ -763,15 +903,27 @@ class PolyBus {
return I_8266_U0_400_3 + offset; return I_8266_U0_400_3 + offset;
case TYPE_TM1814: case TYPE_TM1814:
return I_8266_U0_TM1_4 + offset; return I_8266_U0_TM1_4 + offset;
case TYPE_TM1829:
return I_8266_U0_TM2_3 + offset;
} }
#else //ESP32 #else //ESP32
uint8_t offset = 0; //0 = RMT (num 0-7) 8 = I2S0 9 = I2S1 uint8_t offset = 0; //0 = RMT (num 0-7) 8 = I2S0 9 = I2S1
#ifndef CONFIG_IDF_TARGET_ESP32S2 #if defined(CONFIG_IDF_TARGET_ESP32S2)
// ESP32-S2 only has 4 RMT channels
if (num > 4) return I_NONE;
if (num > 3) offset = 1; // only one I2S
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
// On ESP32-C3 only the first 2 RMT channels are usable for transmitting
if (num > 1) return I_NONE;
//if (num > 1) offset = 1; // I2S not supported yet (only 1 I2S)
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
// On ESP32-S3 only the first 4 RMT channels are usable for transmitting
if (num > 3) return I_NONE;
//if (num > 3) offset = num -4; // I2S not supported yet
#else
// standard ESP32 has 8 RMT and 2 I2S channels
if (num > 9) return I_NONE; if (num > 9) return I_NONE;
if (num > 7) offset = num -7; if (num > 7) offset = num -7;
#else //ESP32 S2 only has 4 RMT channels
if (num > 5) return I_NONE;
if (num > 4) offset = num -4;
#endif #endif
switch (busType) { switch (busType) {
case TYPE_WS2812_RGB: case TYPE_WS2812_RGB:
@ -783,6 +935,8 @@ class PolyBus {
return I_32_RN_400_3 + offset; return I_32_RN_400_3 + offset;
case TYPE_TM1814: case TYPE_TM1814:
return I_32_RN_TM1_4 + offset; return I_32_RN_TM1_4 + offset;
case TYPE_TM1829:
return I_32_RN_TM2_3 + offset;
} }
#endif #endif
} }

View File

@ -18,7 +18,7 @@ void shortPressAction(uint8_t b)
if (!macroButton[b]) { if (!macroButton[b]) {
switch (b) { switch (b) {
case 0: toggleOnOff(); stateUpdated(CALL_MODE_BUTTON); break; case 0: toggleOnOff(); stateUpdated(CALL_MODE_BUTTON); break;
case 1: ++effectCurrent %= strip.getModeCount(); colorUpdated(CALL_MODE_BUTTON); break; case 1: ++effectCurrent %= strip.getModeCount(); stateChanged = true; colorUpdated(CALL_MODE_BUTTON); break;
} }
} else { } else {
applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET); applyPreset(macroButton[b], CALL_MODE_BUTTON_PRESET);
@ -195,12 +195,12 @@ void handleAnalog(uint8_t b)
colorHStoRGB(aRead*256,255,col); colorHStoRGB(aRead*256,255,col);
} else { } else {
// otherwise use "double press" for segment selection // otherwise use "double press" for segment selection
WS2812FX::Segment& seg = strip.getSegment(macroDoublePress[b]); Segment& seg = strip.getSegment(macroDoublePress[b]);
if (aRead == 0) { if (aRead == 0) {
seg.setOption(SEG_OPTION_ON, 0); // off seg.setOption(SEG_OPTION_ON, false); // off (use transition)
} else { } else {
seg.setOpacity(aRead, macroDoublePress[b]); seg.setOpacity(aRead);
seg.setOption(SEG_OPTION_ON, 1); seg.setOption(SEG_OPTION_ON, true); // on (use transition)
} }
// this will notify clients of update (websockets,mqtt,etc) // this will notify clients of update (websockets,mqtt,etc)
updateInterfaces(CALL_MODE_BUTTON); updateInterfaces(CALL_MODE_BUTTON);
@ -216,9 +216,13 @@ void handleAnalog(uint8_t b)
void handleButton() void handleButton()
{ {
static unsigned long lastRead = 0UL; static unsigned long lastRead = 0UL;
static unsigned long lastRun = 0UL;
bool analog = false; bool analog = false;
unsigned long now = millis();
if (strip.isUpdating()) return; // don't interfere with strip updates. Our button will still be there in 1ms (next cycle) //if (strip.isUpdating()) return; // don't interfere with strip updates. Our button will still be there in 1ms (next cycle)
if (strip.isUpdating() && (millis() - lastRun < 400)) return; // be niced, but avoid button starvation
lastRun = millis();
for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) { for (uint8_t b=0; b<WLED_MAX_BUTTONS; b++) {
#ifdef ESP8266 #ifdef ESP8266
@ -229,7 +233,7 @@ void handleButton()
if (usermods.handleButton(b)) continue; // did usermod handle buttons if (usermods.handleButton(b)) continue; // did usermod handle buttons
if ((buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) && millis() - lastRead > ANALOG_BTN_READ_CYCLE) { // button is not a button but a potentiometer if ((buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) && now - lastRead > ANALOG_BTN_READ_CYCLE) { // button is not a button but a potentiometer
analog = true; analog = true;
handleAnalog(b); continue; handleAnalog(b); continue;
} }
@ -242,21 +246,21 @@ void handleButton()
//momentary button logic //momentary button logic
if (isButtonPressed(b)) { //pressed if (isButtonPressed(b)) { //pressed
if (!buttonPressedBefore[b]) buttonPressedTime[b] = millis(); if (!buttonPressedBefore[b]) buttonPressedTime[b] = now;
buttonPressedBefore[b] = true; buttonPressedBefore[b] = true;
if (millis() - buttonPressedTime[b] > WLED_LONG_PRESS) { //long press if (now - buttonPressedTime[b] > WLED_LONG_PRESS) { //long press
if (!buttonLongPressed[b]) longPressAction(b); if (!buttonLongPressed[b]) longPressAction(b);
else if (b) { //repeatable action (~3 times per s) on button > 0 else if (b) { //repeatable action (~3 times per s) on button > 0
longPressAction(b); longPressAction(b);
buttonPressedTime[b] = millis() - WLED_LONG_REPEATED_ACTION; //300ms buttonPressedTime[b] = now - WLED_LONG_REPEATED_ACTION; //333ms
} }
buttonLongPressed[b] = true; buttonLongPressed[b] = true;
} }
} else if (!isButtonPressed(b) && buttonPressedBefore[b]) { //released } else if (!isButtonPressed(b) && buttonPressedBefore[b]) { //released
long dur = millis() - buttonPressedTime[b]; long dur = now - buttonPressedTime[b];
if (dur < WLED_DEBOUNCE_THRESHOLD) {buttonPressedBefore[b] = false; continue;} //too short "press", debounce if (dur < WLED_DEBOUNCE_THRESHOLD) {buttonPressedBefore[b] = false; continue;} //too short "press", debounce
bool doublePress = buttonWaitTime[b]; //did we have a short press before? bool doublePress = buttonWaitTime[b]; //did we have a short press before?
buttonWaitTime[b] = 0; buttonWaitTime[b] = 0;
@ -264,19 +268,22 @@ void handleButton()
if (b == 0 && dur > WLED_LONG_AP) { // long press on button 0 (when released) if (b == 0 && dur > WLED_LONG_AP) { // long press on button 0 (when released)
if (dur > WLED_LONG_FACTORY_RESET) { // factory reset if pressed > 10 seconds if (dur > WLED_LONG_FACTORY_RESET) { // factory reset if pressed > 10 seconds
WLED_FS.format(); WLED_FS.format();
#ifdef WLED_ADD_EEPROM_SUPPORT
clearEEPROM(); clearEEPROM();
#endif
doReboot = true; doReboot = true;
} else { } else {
WLED::instance().initAP(true); WLED::instance().initAP(true);
} }
} else if (!buttonLongPressed[b]) { //short press } else if (!buttonLongPressed[b]) { //short press
//NOTE: this interferes with double click handling in usermods so usermod needs to implement full button handling
if (b != 1 && !macroDoublePress[b]) { //don't wait for double press on buttons without a default action if no double press macro set if (b != 1 && !macroDoublePress[b]) { //don't wait for double press on buttons without a default action if no double press macro set
shortPressAction(b); shortPressAction(b);
} else { //double press if less than 350 ms between current press and previous short press release (buttonWaitTime!=0) } else { //double press if less than 350 ms between current press and previous short press release (buttonWaitTime!=0)
if (doublePress) { if (doublePress) {
doublePressAction(b); doublePressAction(b);
} else { } else {
buttonWaitTime[b] = millis(); buttonWaitTime[b] = now;
} }
} }
} }
@ -285,12 +292,12 @@ void handleButton()
} }
//if 350ms elapsed since last short press release it is a short press //if 350ms elapsed since last short press release it is a short press
if (buttonWaitTime[b] && millis() - buttonWaitTime[b] > WLED_DOUBLE_PRESS && !buttonPressedBefore[b]) { if (buttonWaitTime[b] && now - buttonWaitTime[b] > WLED_DOUBLE_PRESS && !buttonPressedBefore[b]) {
buttonWaitTime[b] = 0; buttonWaitTime[b] = 0;
shortPressAction(b); shortPressAction(b);
} }
} }
if (analog) lastRead = millis(); if (analog) lastRead = now;
} }
void handleIO() void handleIO()

View File

@ -31,6 +31,9 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
getStringFromJson(cmDNS, id[F("mdns")], 33); getStringFromJson(cmDNS, id[F("mdns")], 33);
getStringFromJson(serverDescription, id[F("name")], 33); getStringFromJson(serverDescription, id[F("name")], 33);
getStringFromJson(alexaInvocationName, id[F("inv")], 33); getStringFromJson(alexaInvocationName, id[F("inv")], 33);
#ifdef WLED_ENABLE_SIMPLE_UI
CJSON(simplifiedUI, id[F("sui")]);
#endif
JsonObject nw_ins_0 = doc["nw"]["ins"][0]; JsonObject nw_ins_0 = doc["nw"]["ins"][0];
getStringFromJson(clientSSID, nw_ins_0[F("ssid")], 33); getStringFromJson(clientSSID, nw_ins_0[F("ssid")], 33);
@ -78,16 +81,53 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
// initialize LED pins and lengths prior to other HW (except for ethernet) // initialize LED pins and lengths prior to other HW (except for ethernet)
JsonObject hw_led = hw["led"]; JsonObject hw_led = hw["led"];
uint8_t autoWhiteMode = RGBW_MODE_MANUAL_ONLY;
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]); CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]); CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
CJSON(strip.autoWhiteMode, hw_led[F("rgbwm")]); Bus::setAutoWhiteMode(hw_led[F("rgbwm")] | 255);
Bus::setAutoWhiteMode(strip.autoWhiteMode);
strip.fixInvalidSegments(); // refreshes segment light capabilities (in case auto white mode changed)
CJSON(correctWB, hw_led["cct"]); CJSON(correctWB, hw_led["cct"]);
CJSON(cctFromRgb, hw_led[F("cr")]); CJSON(cctFromRgb, hw_led[F("cr")]);
CJSON(strip.cctBlending, hw_led[F("cb")]); CJSON(strip.cctBlending, hw_led[F("cb")]);
Bus::setCCTBlend(strip.cctBlending); Bus::setCCTBlend(strip.cctBlending);
strip.setTargetFps(hw_led["fps"]); //NOP if 0, default 42 FPS strip.setTargetFps(hw_led["fps"]); //NOP if 0, default 42 FPS
CJSON(strip.useLedsArray, hw_led[F("ld")]);
#ifndef WLED_DISABLE_2D
// 2D Matrix Settings
JsonObject matrix = hw_led[F("matrix")];
if (!matrix.isNull()) {
strip.isMatrix = true;
CJSON(strip.panelH, matrix[F("ph")]);
CJSON(strip.panelW, matrix[F("pw")]);
CJSON(strip.hPanels, matrix[F("mph")]);
CJSON(strip.vPanels, matrix[F("mpv")]);
CJSON(strip.matrix.bottomStart, matrix[F("pb")]);
CJSON(strip.matrix.rightStart, matrix[F("pr")]);
CJSON(strip.matrix.vertical, matrix[F("pv")]);
CJSON(strip.matrix.serpentine, matrix[F("ps")]);
JsonArray panels = matrix[F("panels")];
uint8_t s = 0;
if (!panels.isNull()) {
for (JsonObject pnl : panels) {
CJSON(strip.panel[s].bottomStart, pnl["b"]);
CJSON(strip.panel[s].rightStart, pnl["r"]);
CJSON(strip.panel[s].vertical, pnl["v"]);
CJSON(strip.panel[s].serpentine, pnl["s"]);
if (++s >= WLED_MAX_PANELS) break; // max panels reached
}
}
// clear remaining panels
for (; s<WLED_MAX_PANELS; s++) {
strip.panel[s].bottomStart = 0;
strip.panel[s].rightStart = 0;
strip.panel[s].vertical = 0;
strip.panel[s].serpentine = 0;
}
strip.setUpMatrix();
}
#endif
JsonArray ins = hw_led["ins"]; JsonArray ins = hw_led["ins"];
@ -117,13 +157,14 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
bool reversed = elm["rev"]; bool reversed = elm["rev"];
bool refresh = elm["ref"] | false; bool refresh = elm["ref"] | false;
ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh
uint8_t AWmode = elm[F("rgbwm")] | autoWhiteMode;
if (fromFS) { if (fromFS) {
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst); BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode);
mem += BusManager::memUsage(bc); mem += BusManager::memUsage(bc);
if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip() if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip()
} else { } else {
if (busConfigs[s] != nullptr) delete busConfigs[s]; if (busConfigs[s] != nullptr) delete busConfigs[s];
busConfigs[s] = new BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst); busConfigs[s] = new BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode);
busesChanged = true; busesChanged = true;
} }
s++; s++;
@ -159,7 +200,11 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
int8_t pin = btn["pin"][0] | -1; int8_t pin = btn["pin"][0] | -1;
if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) { if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) {
btnPin[s] = pin; btnPin[s] = pin;
#ifdef ESP32
pinMode(btnPin[s], buttonType[s]==BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP);
#else
pinMode(btnPin[s], INPUT_PULLUP); pinMode(btnPin[s], INPUT_PULLUP);
#endif
} else { } else {
btnPin[s] = -1; btnPin[s] = -1;
} }
@ -226,6 +271,36 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
if (serialBaud < 96 || serialBaud > 15000) serialBaud = 1152; if (serialBaud < 96 || serialBaud > 15000) serialBaud = 1152;
updateBaudRate(serialBaud *100); updateBaudRate(serialBaud *100);
JsonArray hw_if_i2c = hw[F("if")][F("i2c-pin")];
CJSON(i2c_sda, hw_if_i2c[0]);
CJSON(i2c_scl, hw_if_i2c[1]);
PinManagerPinType i2c[2] = { { i2c_sda, true }, { i2c_scl, true } };
if (i2c_scl >= 0 && i2c_sda >= 0 && pinManager.allocateMultiplePins(i2c, 2, PinOwner::HW_I2C)) {
#ifdef ESP32
Wire.setPins(i2c_sda, i2c_scl); // this will fail if Wire is initilised (Wire.begin() called prior)
#endif
Wire.begin();
} else {
i2c_sda = -1;
i2c_scl = -1;
}
JsonArray hw_if_spi = hw[F("if")][F("spi-pin")];
CJSON(spi_mosi, hw_if_spi[0]);
CJSON(spi_sclk, hw_if_spi[1]);
CJSON(spi_miso, hw_if_spi[2]);
PinManagerPinType spi[3] = { { spi_mosi, true }, { spi_miso, true }, { spi_sclk, true } };
if (spi_mosi >= 0 && spi_sclk >= 0 && pinManager.allocateMultiplePins(spi, 3, PinOwner::HW_SPI)) {
#ifdef ESP32
SPI.begin(spi_sclk, spi_miso, spi_mosi); // SPI global uses VSPI on ESP32 and FSPI on C3, S3
#else
SPI.begin();
#endif
} else {
spi_mosi = -1;
spi_miso = -1;
spi_sclk = -1;
}
//int hw_status_pin = hw[F("status")]["pin"]; // -1 //int hw_status_pin = hw[F("status")]["pin"]; // -1
JsonObject light = doc[F("light")]; JsonObject light = doc[F("light")];
@ -235,10 +310,10 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
float light_gc_bri = light["gc"]["bri"]; float light_gc_bri = light["gc"]["bri"];
float light_gc_col = light["gc"]["col"]; // 2.8 float light_gc_col = light["gc"]["col"]; // 2.8
if (light_gc_bri > 1.5) strip.gammaCorrectBri = true; if (light_gc_bri > 1.5) gammaCorrectBri = true;
else if (light_gc_bri > 0.5) strip.gammaCorrectBri = false; else if (light_gc_bri > 0.5) gammaCorrectBri = false;
if (light_gc_col > 1.5) strip.gammaCorrectCol = true; if (light_gc_col > 1.5) gammaCorrectCol = true;
else if (light_gc_col > 0.5) strip.gammaCorrectCol = false; else if (light_gc_col > 0.5) gammaCorrectCol = false;
JsonObject light_tr = light["tr"]; JsonObject light_tr = light["tr"];
CJSON(fadeTransition, light_tr["mode"]); CJSON(fadeTransition, light_tr["mode"]);
@ -284,8 +359,9 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(notifyAlexa, if_sync_send["va"]); CJSON(notifyAlexa, if_sync_send["va"]);
CJSON(notifyHue, if_sync_send["hue"]); CJSON(notifyHue, if_sync_send["hue"]);
CJSON(notifyMacro, if_sync_send["macro"]); CJSON(notifyMacro, if_sync_send["macro"]);
CJSON(notifyTwice, if_sync_send[F("twice")]);
CJSON(syncGroups, if_sync_send["grp"]); CJSON(syncGroups, if_sync_send["grp"]);
if (if_sync_send[F("twice")]) udpNumRetries = 1; // import setting from 0.13 and earlier
CJSON(udpNumRetries, if_sync_send["ret"]);
JsonObject if_nodes = interfaces["nodes"]; JsonObject if_nodes = interfaces["nodes"];
CJSON(nodeListEnabled, if_nodes[F("list")]); CJSON(nodeListEnabled, if_nodes[F("list")]);
@ -302,6 +378,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
CJSON(e131Universe, if_live_dmx[F("uni")]); CJSON(e131Universe, if_live_dmx[F("uni")]);
CJSON(e131SkipOutOfSequence, if_live_dmx[F("seqskip")]); CJSON(e131SkipOutOfSequence, if_live_dmx[F("seqskip")]);
CJSON(DMXAddress, if_live_dmx[F("addr")]); CJSON(DMXAddress, if_live_dmx[F("addr")]);
if (!DMXAddress || DMXAddress > 510) DMXAddress = 1;
CJSON(DMXMode, if_live_dmx["mode"]); CJSON(DMXMode, if_live_dmx["mode"]);
tdd = if_live[F("timeout")] | -1; tdd = if_live[F("timeout")] | -1;
@ -467,21 +544,21 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
void deserializeConfigFromFS() { void deserializeConfigFromFS() {
bool success = deserializeConfigSec(); bool success = deserializeConfigSec();
if (!success) { //if file does not exist, try reading from EEPROM if (!success) { //if file does not exist, try reading from EEPROM
#ifdef WLED_ADD_EEPROM_SUPPORT
deEEPSettings(); deEEPSettings();
return; return;
#endif
} }
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock(1)) return; if (!requestJSONBufferLock(1)) return;
#endif
DEBUG_PRINTLN(F("Reading settings from /cfg.json...")); DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));
success = readObjectFromFile("/cfg.json", nullptr, &doc); success = readObjectFromFile("/cfg.json", nullptr, &doc);
if (!success) { //if file does not exist, try reading from EEPROM if (!success) { //if file does not exist, try reading from EEPROM
#ifdef WLED_ADD_EEPROM_SUPPORT
deEEPSettings(); deEEPSettings();
#endif
releaseJSONBufferLock(); releaseJSONBufferLock();
return; return;
} }
@ -499,11 +576,7 @@ void serializeConfig() {
DEBUG_PRINTLN(F("Writing settings to /cfg.json...")); DEBUG_PRINTLN(F("Writing settings to /cfg.json..."));
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock(2)) return; if (!requestJSONBufferLock(2)) return;
#endif
JsonArray rev = doc.createNestedArray("rev"); JsonArray rev = doc.createNestedArray("rev");
rev.add(1); //major settings revision rev.add(1); //major settings revision
@ -515,6 +588,9 @@ void serializeConfig() {
id[F("mdns")] = cmDNS; id[F("mdns")] = cmDNS;
id[F("name")] = serverDescription; id[F("name")] = serverDescription;
id[F("inv")] = alexaInvocationName; id[F("inv")] = alexaInvocationName;
#ifdef WLED_ENABLE_SIMPLE_UI
id[F("sui")] = simplifiedUI;
#endif
JsonObject nw = doc.createNestedObject("nw"); JsonObject nw = doc.createNestedObject("nw");
@ -585,7 +661,32 @@ void serializeConfig() {
hw_led[F("cr")] = cctFromRgb; hw_led[F("cr")] = cctFromRgb;
hw_led[F("cb")] = strip.cctBlending; hw_led[F("cb")] = strip.cctBlending;
hw_led["fps"] = strip.getTargetFps(); hw_led["fps"] = strip.getTargetFps();
hw_led[F("rgbwm")] = strip.autoWhiteMode; hw_led[F("rgbwm")] = Bus::getAutoWhiteMode(); // global override
hw_led[F("ld")] = strip.useLedsArray;
#ifndef WLED_DISABLE_2D
// 2D Matrix Settings
if (strip.isMatrix) {
JsonObject matrix = hw_led.createNestedObject(F("matrix"));
matrix[F("ph")] = strip.panelH;
matrix[F("pw")] = strip.panelW;
matrix[F("mph")] = strip.hPanels;
matrix[F("mpv")] = strip.vPanels;
matrix[F("pb")] = strip.matrix.bottomStart;
matrix[F("pr")] = strip.matrix.rightStart;
matrix[F("pv")] = strip.matrix.vertical;
matrix[F("ps")] = strip.matrix.serpentine;
JsonArray panels = matrix.createNestedArray(F("panels"));
for (uint8_t i=0; i<strip.hPanels*strip.vPanels; i++) {
JsonObject pnl = panels.createNestedObject();
pnl["b"] = strip.panel[i].bottomStart;
pnl["r"] = strip.panel[i].rightStart;
pnl["v"] = strip.panel[i].vertical;
pnl["s"] = strip.panel[i].serpentine;
}
}
#endif
JsonArray hw_led_ins = hw_led.createNestedArray("ins"); JsonArray hw_led_ins = hw_led.createNestedArray("ins");
@ -604,7 +705,7 @@ void serializeConfig() {
ins[F("skip")] = bus->skippedLeds(); ins[F("skip")] = bus->skippedLeds();
ins["type"] = bus->getType() & 0x7F; ins["type"] = bus->getType() & 0x7F;
ins["ref"] = bus->isOffRefreshRequired(); ins["ref"] = bus->isOffRefreshRequired();
//ins[F("rgbw")] = bus->isRgbw(); ins[F("rgbwm")] = bus->getAWMode();
} }
JsonArray hw_com = hw.createNestedArray(F("com")); JsonArray hw_com = hw.createNestedArray(F("com"));
@ -650,6 +751,15 @@ void serializeConfig() {
hw[F("baud")] = serialBaud; hw[F("baud")] = serialBaud;
JsonObject hw_if = hw.createNestedObject(F("if"));
JsonArray hw_if_i2c = hw_if.createNestedArray("i2c-pin");
hw_if_i2c.add(i2c_sda);
hw_if_i2c.add(i2c_scl);
JsonArray hw_if_spi = hw_if.createNestedArray("spi-pin");
hw_if_spi.add(spi_mosi);
hw_if_spi.add(spi_sclk);
hw_if_spi.add(spi_miso);
//JsonObject hw_status = hw.createNestedObject("status"); //JsonObject hw_status = hw.createNestedObject("status");
//hw_status["pin"] = -1; //hw_status["pin"] = -1;
@ -659,8 +769,8 @@ void serializeConfig() {
light[F("aseg")] = autoSegments; light[F("aseg")] = autoSegments;
JsonObject light_gc = light.createNestedObject("gc"); JsonObject light_gc = light.createNestedObject("gc");
light_gc["bri"] = (strip.gammaCorrectBri) ? 2.8 : 1.0; light_gc["bri"] = (gammaCorrectBri) ? 2.8 : 1.0;
light_gc["col"] = (strip.gammaCorrectCol) ? 2.8 : 1.0; light_gc["col"] = (gammaCorrectCol) ? 2.8 : 1.0;
JsonObject light_tr = light.createNestedObject("tr"); JsonObject light_tr = light.createNestedObject("tr");
light_tr["mode"] = fadeTransition; light_tr["mode"] = fadeTransition;
@ -698,8 +808,8 @@ void serializeConfig() {
if_sync_send["va"] = notifyAlexa; if_sync_send["va"] = notifyAlexa;
if_sync_send["hue"] = notifyHue; if_sync_send["hue"] = notifyHue;
if_sync_send["macro"] = notifyMacro; if_sync_send["macro"] = notifyMacro;
if_sync_send[F("twice")] = notifyTwice;
if_sync_send["grp"] = syncGroups; if_sync_send["grp"] = syncGroups;
if_sync_send["ret"] = udpNumRetries;
JsonObject if_nodes = interfaces.createNestedObject("nodes"); JsonObject if_nodes = interfaces.createNestedObject("nodes");
if_nodes[F("list")] = nodeListEnabled; if_nodes[F("list")] = nodeListEnabled;
@ -842,17 +952,15 @@ void serializeConfig() {
if (f) serializeJson(doc, f); if (f) serializeJson(doc, f);
f.close(); f.close();
releaseJSONBufferLock(); releaseJSONBufferLock();
doSerializeConfig = false;
} }
//settings in /wsec.json, not accessible via webserver, for passwords and tokens //settings in /wsec.json, not accessible via webserver, for passwords and tokens
bool deserializeConfigSec() { bool deserializeConfigSec() {
DEBUG_PRINTLN(F("Reading settings from /wsec.json...")); DEBUG_PRINTLN(F("Reading settings from /wsec.json..."));
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock(3)) return false; if (!requestJSONBufferLock(3)) return false;
#endif
bool success = readObjectFromFile("/wsec.json", nullptr, &doc); bool success = readObjectFromFile("/wsec.json", nullptr, &doc);
if (!success) { if (!success) {
@ -884,6 +992,9 @@ bool deserializeConfigSec() {
getStringFromJson(hueApiKey, interfaces["hue"][F("key")], 47); getStringFromJson(hueApiKey, interfaces["hue"][F("key")], 47);
#endif #endif
getStringFromJson(settingsPIN, doc["pin"], 5);
correctPIN = !strlen(settingsPIN);
JsonObject ota = doc["ota"]; JsonObject ota = doc["ota"];
getStringFromJson(otaPass, ota[F("pwd")], 33); getStringFromJson(otaPass, ota[F("pwd")], 33);
CJSON(otaLock, ota[F("lock")]); CJSON(otaLock, ota[F("lock")]);
@ -897,11 +1008,7 @@ bool deserializeConfigSec() {
void serializeConfigSec() { void serializeConfigSec() {
DEBUG_PRINTLN(F("Writing settings to /wsec.json...")); DEBUG_PRINTLN(F("Writing settings to /wsec.json..."));
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock(4)) return; if (!requestJSONBufferLock(4)) return;
#endif
JsonObject nw = doc.createNestedObject("nw"); JsonObject nw = doc.createNestedObject("nw");
@ -927,6 +1034,8 @@ void serializeConfigSec() {
if_hue[F("key")] = hueApiKey; if_hue[F("key")] = hueApiKey;
#endif #endif
doc["pin"] = settingsPIN;
JsonObject ota = doc.createNestedObject("ota"); JsonObject ota = doc.createNestedObject("ota");
ota[F("pwd")] = otaPass; ota[F("pwd")] = otaPass;
ota[F("lock")] = otaLock; ota[F("lock")] = otaLock;

View File

@ -1,12 +1,57 @@
#include "wled.h" #include "wled.h"
/* /*
* Color conversion methods * Color conversion & utility methods
*/ */
/*
* color blend function
*/
uint32_t color_blend(uint32_t color1, uint32_t color2, uint16_t blend, bool b16) {
if(blend == 0) return color1;
uint16_t blendmax = b16 ? 0xFFFF : 0xFF;
if(blend == blendmax) return color2;
uint8_t shift = b16 ? 16 : 8;
uint32_t w1 = W(color1);
uint32_t r1 = R(color1);
uint32_t g1 = G(color1);
uint32_t b1 = B(color1);
uint32_t w2 = W(color2);
uint32_t r2 = R(color2);
uint32_t g2 = G(color2);
uint32_t b2 = B(color2);
uint32_t w3 = ((w2 * blend) + (w1 * (blendmax - blend))) >> shift;
uint32_t r3 = ((r2 * blend) + (r1 * (blendmax - blend))) >> shift;
uint32_t g3 = ((g2 * blend) + (g1 * (blendmax - blend))) >> shift;
uint32_t b3 = ((b2 * blend) + (b1 * (blendmax - blend))) >> shift;
return RGBW32(r3, g3, b3, w3);
}
/*
* color add function that preserves ratio
* idea: https://github.com/Aircoookie/WLED/pull/2465 by https://github.com/Proto-molecule
*/
uint32_t color_add(uint32_t c1, uint32_t c2)
{
uint32_t r = R(c1) + R(c2);
uint32_t g = G(c1) + G(c2);
uint32_t b = B(c1) + B(c2);
uint32_t w = W(c1) + W(c2);
uint16_t max = r;
if (g > max) max = g;
if (b > max) max = b;
if (w > max) max = w;
if (max < 256) return RGBW32(r, g, b, w);
else return RGBW32(r * 255 / max, g * 255 / max, b * 255 / max, w * 255 / max);
}
void setRandomColor(byte* rgb) void setRandomColor(byte* rgb)
{ {
lastRandomIndex = strip.get_random_wheel_index(lastRandomIndex); lastRandomIndex = strip.getMainSegment().get_random_wheel_index(lastRandomIndex);
colorHStoRGB(lastRandomIndex*256,255,rgb); colorHStoRGB(lastRandomIndex*256,255,rgb);
} }
@ -274,3 +319,53 @@ uint16_t approximateKelvinFromRGB(uint32_t rgb) {
return (k > 10091) ? 10091 : k; return (k > 10091) ? 10091 : k;
} }
} }
//gamma 2.8 lookup table used for color correction
static byte gammaT[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
uint8_t gamma8_cal(uint8_t b, float gamma)
{
return (int)(powf((float)b / 255.0f, gamma) * 255.0f + 0.5f);
}
void calcGammaTable(float gamma)
{
for (uint16_t i = 0; i < 256; i++) {
gammaT[i] = gamma8_cal(i, gamma);
}
}
uint8_t gamma8(uint8_t b)
{
return gammaT[b];
}
uint32_t gamma32(uint32_t color)
{
if (!gammaCorrectCol) return color;
uint8_t w = W(color);
uint8_t r = R(color);
uint8_t g = G(color);
uint8_t b = B(color);
w = gammaT[w];
r = gammaT[r];
g = gammaT[g];
b = gammaT[b];
return RGBW32(r, g, b, w);
}

View File

@ -5,6 +5,8 @@
* Readability defines and their associated numerical values + compile-time constants * Readability defines and their associated numerical values + compile-time constants
*/ */
#define GRADIENT_PALETTE_COUNT 58
//Defaults //Defaults
#define DEFAULT_CLIENT_SSID "Your_Network" #define DEFAULT_CLIENT_SSID "Your_Network"
#define DEFAULT_AP_PASS "wled1234" #define DEFAULT_AP_PASS "wled1234"
@ -23,13 +25,25 @@
#ifdef ESP8266 #ifdef ESP8266
#define WLED_MAX_BUSSES 3 #define WLED_MAX_BUSSES 3
#else #else
#ifdef CONFIG_IDF_TARGET_ESP32S2 #if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
#define WLED_MAX_BUSSES 5 #define WLED_MAX_BUSSES 3 // will allow 2 digital & 1 analog (or the other way around)
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
#else
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog
#endif
#elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
#else
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 8
#else #else
#define WLED_MAX_BUSSES 10 #define WLED_MAX_BUSSES 10
#endif #endif
#endif #endif
#endif #endif
#endif
#ifndef WLED_MAX_BUTTONS #ifndef WLED_MAX_BUTTONS
#ifdef ESP8266 #ifdef ESP8266
@ -77,6 +91,7 @@
#define USERMOD_ID_MY9291 28 //Usermod "usermod_MY9291.h" #define USERMOD_ID_MY9291 28 //Usermod "usermod_MY9291.h"
#define USERMOD_ID_SI7021_MQTT_HA 29 //Usermod "usermod_si7021_mqtt_ha.h" #define USERMOD_ID_SI7021_MQTT_HA 29 //Usermod "usermod_si7021_mqtt_ha.h"
#define USERMOD_ID_BME280 30 //Usermod "usermod_bme280.h #define USERMOD_ID_BME280 30 //Usermod "usermod_bme280.h
#define USERMOD_ID_AUDIOREACTIVE 31 //Usermod "audioreactive.h"
//Access point behavior //Access point behavior
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot #define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot
@ -151,6 +166,7 @@
#define TYPE_WS2812_RGB 22 #define TYPE_WS2812_RGB 22
#define TYPE_GS8608 23 //same driver as WS2812, but will require signal 2x per second (else displays test pattern) #define TYPE_GS8608 23 //same driver as WS2812, but will require signal 2x per second (else displays test pattern)
#define TYPE_WS2811_400KHZ 24 //half-speed WS2812 protocol, used by very old WS2811 units #define TYPE_WS2811_400KHZ 24 //half-speed WS2812 protocol, used by very old WS2811 units
#define TYPE_TM1829 25
#define TYPE_SK6812_RGBW 30 #define TYPE_SK6812_RGBW 30
#define TYPE_TM1814 31 #define TYPE_TM1814 31
//"Analog" types (PWM) (32-47) //"Analog" types (PWM) (32-47)
@ -168,8 +184,9 @@
#define TYPE_LPD6803 54 #define TYPE_LPD6803 54
//Network types (master broadcast) (80-95) //Network types (master broadcast) (80-95)
#define TYPE_NET_DDP_RGB 80 //network DDP RGB bus (master broadcast bus) #define TYPE_NET_DDP_RGB 80 //network DDP RGB bus (master broadcast bus)
#define TYPE_NET_E131_RGB 81 //network E131 RGB bus (master broadcast bus) #define TYPE_NET_E131_RGB 81 //network E131 RGB bus (master broadcast bus, unused)
#define TYPE_NET_ARTNET_RGB 82 //network ArtNet RGB bus (master broadcast bus) #define TYPE_NET_ARTNET_RGB 82 //network ArtNet RGB bus (master broadcast bus, unused)
#define TYPE_NET_DDP_RGBW 88 //network DDP RGBW bus (master broadcast bus)
#define IS_DIGITAL(t) ((t) & 0x10) //digital are 16-31 and 48-63 #define IS_DIGITAL(t) ((t) & 0x10) //digital are 16-31 and 48-63
#define IS_PWM(t) ((t) > 40 && (t) < 46) #define IS_PWM(t) ((t) > 40 && (t) < 46)
@ -222,9 +239,12 @@
#define SEG_OPTION_REVERSED 1 #define SEG_OPTION_REVERSED 1
#define SEG_OPTION_ON 2 #define SEG_OPTION_ON 2
#define SEG_OPTION_MIRROR 3 //Indicates that the effect will be mirrored within the segment #define SEG_OPTION_MIRROR 3 //Indicates that the effect will be mirrored within the segment
#define SEG_OPTION_NONUNITY 4 //Indicates that the effect does not use FRAMETIME or needs getPixelColor #define SEG_OPTION_FREEZE 4 //Segment contents will not be refreshed
#define SEG_OPTION_FREEZE 5 //Segment contents will not be refreshed #define SEG_OPTION_RESET 5 //Segment runtime requires reset
#define SEG_OPTION_TRANSITIONAL 7 #define SEG_OPTION_TRANSITIONAL 6
#define SEG_OPTION_REVERSED_Y 7
#define SEG_OPTION_MIRROR_Y 8
#define SEG_OPTION_TRANSPOSED 9
//Segment differs return byte //Segment differs return byte
#define SEG_DIFFERS_BRI 0x01 #define SEG_DIFFERS_BRI 0x01
@ -241,6 +261,7 @@
// WLED Error modes // WLED Error modes
#define ERR_NONE 0 // All good :) #define ERR_NONE 0 // All good :)
#define ERR_EEP_COMMIT 2 // Could not commit to EEPROM (wrong flash layout?) #define ERR_EEP_COMMIT 2 // Could not commit to EEPROM (wrong flash layout?)
#define ERR_NOBUF 3 // JSON buffer was not released in time, request cannot be handled at this time
#define ERR_JSON 9 // JSON parsing failed (input too large?) #define ERR_JSON 9 // JSON parsing failed (input too large?)
#define ERR_FS_BEGIN 10 // Could not init filesystem (no partition?) #define ERR_FS_BEGIN 10 // Could not init filesystem (no partition?)
#define ERR_FS_QUOTA 11 // The FS is full or the maximum file size is reached #define ERR_FS_QUOTA 11 // The FS is full or the maximum file size is reached
@ -272,13 +293,17 @@
#ifndef MAX_LED_MEMORY #ifndef MAX_LED_MEMORY
#ifdef ESP8266 #ifdef ESP8266
#define MAX_LED_MEMORY 4000 #define MAX_LED_MEMORY 4000
#else
#if defined(ARDUINO_ARCH_ESP32S2) || defined(ARDUINO_ARCH_ESP32C3)
#define MAX_LED_MEMORY 32000
#else #else
#define MAX_LED_MEMORY 64000 #define MAX_LED_MEMORY 64000
#endif #endif
#endif #endif
#endif
#ifndef MAX_LEDS_PER_BUS #ifndef MAX_LEDS_PER_BUS
#define MAX_LEDS_PER_BUS 4096 #define MAX_LEDS_PER_BUS 2048 // may not be enough for fast LEDs (i.e. APA102)
#endif #endif
// string temp buffer (now stored in stack locally) // string temp buffer (now stored in stack locally)
@ -301,7 +326,9 @@
#ifndef ABL_MILLIAMPS_DEFAULT #ifndef ABL_MILLIAMPS_DEFAULT
#define ABL_MILLIAMPS_DEFAULT 850 // auto lower brightness to stay close to milliampere limit #define ABL_MILLIAMPS_DEFAULT 850 // auto lower brightness to stay close to milliampere limit
#else #else
#if ABL_MILLIAMPS_DEFAULT < 250 // make sure value is at least 250 #if ABL_MILLIAMPS_DEFAULT == 0 // disable ABL
#elif ABL_MILLIAMPS_DEFAULT < 250 // make sure value is at least 250
#warning "make sure value is at least 250"
#define ABL_MILLIAMPS_DEFAULT 250 #define ABL_MILLIAMPS_DEFAULT 250
#endif #endif
#endif #endif
@ -321,14 +348,11 @@
#ifdef ESP8266 #ifdef ESP8266
#define JSON_BUFFER_SIZE 10240 #define JSON_BUFFER_SIZE 10240
#else #else
#define JSON_BUFFER_SIZE 20480 #define JSON_BUFFER_SIZE 24576
#endif #endif
#ifdef WLED_USE_DYNAMIC_JSON //#define MIN_HEAP_SIZE (MAX_LED_MEMORY+2048)
#define MIN_HEAP_SIZE JSON_BUFFER_SIZE+512 #define MIN_HEAP_SIZE (8192)
#else
#define MIN_HEAP_SIZE 4096
#endif
// Maximum size of node map (list of other WLED instances) // Maximum size of node map (list of other WLED instances)
#ifdef ESP8266 #ifdef ESP8266
@ -339,10 +363,10 @@
//this is merely a default now and can be changed at runtime //this is merely a default now and can be changed at runtime
#ifndef LEDPIN #ifndef LEDPIN
#ifdef ESP8266 #if defined(ESP8266) || (defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)) || defined(CONFIG_IDF_TARGET_ESP32C3)
#define LEDPIN 2 // GPIO2 (D4) on Wemod D1 mini compatible boards #define LEDPIN 2 // GPIO2 (D4) on Wemod D1 mini compatible boards
#else #else
#define LEDPIN 2 // Changed from 16 to restore compatibility with ESP32-pico #define LEDPIN 16 // aligns with GPIO2 (D4) on Wemos D1 mini32 compatible boards
#endif #endif
#endif #endif
@ -360,4 +384,43 @@
#define INTERFACE_UPDATE_COOLDOWN 2000 //time in ms to wait between websockets, alexa, and MQTT updates #define INTERFACE_UPDATE_COOLDOWN 2000 //time in ms to wait between websockets, alexa, and MQTT updates
#if defined(ESP8266) && defined(HW_PIN_SCL)
#undef HW_PIN_SCL
#endif
#if defined(ESP8266) && defined(HW_PIN_SDA)
#undef HW_PIN_SDA
#endif
#ifndef HW_PIN_SCL
#define HW_PIN_SCL SCL
#endif
#ifndef HW_PIN_SDA
#define HW_PIN_SDA SDA
#endif
#if defined(ESP8266) && defined(HW_PIN_CLOCKSPI)
#undef HW_PIN_CLOCKSPI
#endif
#if defined(ESP8266) && defined(HW_PIN_DATASPI)
#undef HW_PIN_DATASPI
#endif
#if defined(ESP8266) && defined(HW_PIN_MISOSPI)
#undef HW_PIN_MISOSPI
#endif
#if defined(ESP8266) && defined(HW_PIN_CSSPI)
#undef HW_PIN_CSSPI
#endif
// defaults for VSPI
#ifndef HW_PIN_CLOCKSPI
#define HW_PIN_CLOCKSPI SCK
#endif
#ifndef HW_PIN_DATASPI
#define HW_PIN_DATASPI MOSI
#endif
#ifndef HW_PIN_MISOSPI
#define HW_PIN_MISOSPI MISO
#endif
#ifndef HW_PIN_CSSPI
#define HW_PIN_CSSPI SS
#endif
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -7,10 +7,52 @@
<meta content="yes" name="apple-mobile-web-app-capable"> <meta content="yes" name="apple-mobile-web-app-capable">
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAGACGAAAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAE1JREFUOI1j/P//PwOxgNGeAUMxE9G6cQCKDWAhpADZ2f8PMjBS3QW08QK20KaZC2gfC9hCnqouoNgARgY7zMxAyNlUdQHlXiAlO2MDAD63EVqNHAe0AAAAAElFTkSuQmCC"/> <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAGACGAAAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAE1JREFUOI1j/P//PwOxgNGeAUMxE9G6cQCKDWAhpADZ2f8PMjBS3QW08QK20KaZC2gfC9hCnqouoNgARgY7zMxAyNlUdQHlXiAlO2MDAD63EVqNHAe0AAAAAElFTkSuQmCC"/>
<title>WLED</title> <title>WLED</title>
<script>function feedback(){}</script> <script>
function feedback(){}
// instead of including [script src="iro.js"][/script] and [script src="rangetouch.js"][/script]
// (which would be inlined by nodeJS inliner during minimization and compression) we need to load them dynamically
// the following is needed to load iro.js and rangetouch.js as consecutive requests to allow ESP8266
// to keep up with requests (if requests happent too fast some may not get processed)
// it will also call onLoad() after last is loaded (it was removed from [body onload="onLoad()"]).
var h = document.getElementsByTagName('head')[0];
var l = document.createElement('script');
l.type = 'application/javascript';
l.src = 'iro.js';
l.addEventListener('load', (e) => {
// after iro is loaded initialize global variable
cpick = new iro.ColorPicker("#picker", {
width: 260,
wheelLightness: false,
wheelAngle: 270,
wheelDirection: "clockwise",
layout: [{
component: iro.ui.Wheel,
options: {}
}]
});
cpick.on("input:end", () => {setColor(1);});
cpick.on("color:change", () => {updatePSliders()});
var l = document.createElement('script');
l.type = 'application/javascript';
l.src = 'rangetouch.js';
l.addEventListener('load', (e) => {
// after rangetouch is loaded initialize global variable
ranges = RangeTouch.setup('input[type="range"]', {});
let stateCheck = setInterval(() => {
if (document.readyState === 'complete') {
clearInterval(stateCheck);
// document ready, start processing UI
onLoad();
}
}, 100);
});
setTimeout(()=>{h.appendChild(l)},100);
});
setTimeout(()=>{h.appendChild(l)},100);
</script>
<link rel="stylesheet" href="index.css"> <link rel="stylesheet" href="index.css">
</head> </head>
<body onload="onLoad()"> <body>
<div id="cv" class="overlay">Loading WLED UI...</div> <div id="cv" class="overlay">Loading WLED UI...</div>
<noscript><div class="overlay" style="opacity:1;">Sorry, WLED UI needs JavaScript!</div></noscript> <noscript><div class="overlay" style="opacity:1;">Sorry, WLED UI needs JavaScript!</div></noscript>
@ -24,7 +66,7 @@
<button id="buttonSync" onclick="toggleSync()"><i class="icons">&#xe116;</i><p class="tab-label">Sync</p></button> <button id="buttonSync" onclick="toggleSync()"><i class="icons">&#xe116;</i><p class="tab-label">Sync</p></button>
<button id="buttonSr" onclick="toggleLiveview()"><i class="icons">&#xe410;</i><p class="tab-label">Peek</p></button> <button id="buttonSr" onclick="toggleLiveview()"><i class="icons">&#xe410;</i><p class="tab-label">Peek</p></button>
<button id="buttonI" onclick="toggleInfo()"><i class="icons">&#xe066;</i><p class="tab-label">Info</p></button> <button id="buttonI" onclick="toggleInfo()"><i class="icons">&#xe066;</i><p class="tab-label">Info</p></button>
<button id="buttonNodes" onclick="toggleNodes()"><i class="icons">&#xe22d;</i><p class="tab-label">Nodes</p></button></div> <button id="buttonNodes" onclick="toggleNodes()"><i class="icons">&#xe22d;</i><p class="tab-label">Nodes</p></button>
<button onclick="window.location.href='/settings';"><i class="icons">&#xe0a2;</i><p class="tab-label">Config</p></button> <button onclick="window.location.href='/settings';"><i class="icons">&#xe0a2;</i><p class="tab-label">Config</p></button>
<button id="buttonPcm" onclick="togglePcMode(true)"><i class="icons">&#xe23d;</i><p class="tab-label">PC Mode</p></button> <button id="buttonPcm" onclick="togglePcMode(true)"><i class="icons">&#xe23d;</i><p class="tab-label">PC Mode</p></button>
</div> </div>
@ -36,6 +78,7 @@
<input id="sliderBri" onchange="setBri()" oninput="updateTrail(this)" max="255" min="1" type="range" value="128" /> <input id="sliderBri" onchange="setBri()" oninput="updateTrail(this)" max="255" min="1" type="range" value="128" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div> </div>
<output class="sliderbubble"></output>
</div> </div>
</div> </div>
<iframe id="liveview" src="about:blank"></iframe> <iframe id="liveview" src="about:blank"></iframe>
@ -44,45 +87,65 @@
<div class ="container"> <div class ="container">
<div id="Colors" class="tabcontent"> <div id="Colors" class="tabcontent">
<div id="pwrap">
<div id="picker" class="noslide"></div> <div id="picker" class="noslide"></div>
<div id="hwrap">
<!--p class="labels hd">Hue</p-->
<div class="sliderwrap il">
<input id="sliderH" class="noslide" oninput="fromH()" onchange="setColor(0)" max="359" min="0" type="range" value="0" step="any">
<div class="sliderdisplay" style="background: linear-gradient(90deg, #f00 2%, #ff0 19%, #0f0 35%, #0ff 52%, #00f 68%, #f0f 85%, #f00)"></div>
</div><br>
</div>
<div id="swrap">
<!--p class="labels hd">Saturation</p-->
<div class="sliderwrap il">
<input id="sliderS" class="noslide" oninput="fromS()" onchange="setColor(0)" max="100" min="0" type="range" value="100" step="any">
<div class="sliderdisplay" style="background: linear-gradient(90deg, #aaa 0%, #f00)"></div>
</div><br>
</div>
<div id="vwrap"> <div id="vwrap">
<div class="sliderwrap il" id="vwrap"> <!--p class="labels hd">Value</p-->
<input id="sliderV" class="noslide" oninput="fromV()" onchange="setColor(0)" max="100" min="0" type="range" value="128" step="any" /> <div class="sliderwrap il">
<input id="sliderV" class="noslide" oninput="fromV()" onchange="setColor(0)" max="100" min="0" type="range" value="100" step="any" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div><br> </div><br>
</div> </div>
</div>
<div id="kwrap"> <div id="kwrap">
<!--p class="labels hd">Temperature</p-->
<div class="sliderwrap il"> <div class="sliderwrap il">
<input id="sliderK" class="noslide" oninput="fromK()" onchange="setColor(0)" max="10091" min="1900" type="range" value="6550" /> <input id="sliderK" class="noslide" oninput="fromK()" onchange="setColor(0)" max="10091" min="1900" type="range" value="6550" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div> </div>
</div> </div>
<div id="rgbwrap"> <div id="rgbwrap">
<p class="labels">RGB color</p> <p class="labels hd">RGB color</p>
<div class="sliderwrap il" id="rwrap"> <div id="rwrap" class="il">
<input id="sliderR" class="noslide" onchange="setColor(0)" oninput="fromRgb()" max="255" min="0" type="range" value="128" /> <div class="sliderwrap il">
<input id="sliderR" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div><br> </div>
<div class="sliderwrap il" id="gwrap"> </div>
<input id="sliderG" class="noslide" onchange="setColor(0)" oninput="fromRgb()" max="255" min="0" type="range" value="128" /> <div id="gwrap" class="il">
<div class="sliderwrap il">
<input id="sliderG" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div><br> </div>
<div class="sliderwrap il" id="bwrap"> </div>
<input id="sliderB" class="noslide" onchange="setColor(0)" oninput="fromRgb()" max="255" min="0" type="range" value="128" /> <div id="bwrap" class="il">
<div class="sliderwrap il">
<input id="sliderB" class="noslide" oninput="fromRgb()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div><br> </div>
</div>
</div> </div>
<div id="wwrap"> <div id="wwrap">
<p class="labels">White channel</p> <p class="labels hd">White channel</p>
<div class="sliderwrap il"> <div id="whibri" class="sliderwrap il">
<input id="sliderW" class="noslide" onchange="setColor(0)" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" /> <input id="sliderW" class="noslide" oninput="fromW()" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div> </div>
</div> </div>
<div id="wbal"> <div id="wbal">
<p class="labels">White balance</p> <p class="labels hd">White balance</p>
<div class="sliderwrap il"> <div class="sliderwrap il">
<input id="sliderA" class="noslide" onchange="setBalance(this.value)" max="255" min="0" type="range" value="128" /> <input id="sliderA" class="noslide" onchange="setBalance(this.value)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
@ -99,63 +162,142 @@
<div class="qcs" onclick="pC('#0000ff');" title="Blue" style="background-color:#0000ff;"></div> <div class="qcs" onclick="pC('#0000ff');" title="Blue" style="background-color:#0000ff;"></div>
<div class="qcs" onclick="pC('#00ffc8');" title="Cyan" style="background-color:#00ffc8;"></div> <div class="qcs" onclick="pC('#00ffc8');" title="Cyan" style="background-color:#00ffc8;"></div>
<div class="qcs" onclick="pC('#08ff00');" title="Green" style="background-color:#08ff00;"></div> <div class="qcs" onclick="pC('#08ff00');" title="Green" style="background-color:#08ff00;"></div>
<div class="qcs" onclick="pC('rnd');" title="Random" style="background-color:var(--c-3); padding: 4px 8px; transform: translateY(-10px);">R</div> <div class="qcs" onclick="pC('rnd');" title="Random" style="background:linear-gradient(to right, red, orange, yellow, green, blue, purple);transform: translateY(-11px);">R</div>
</div> </div>
<div id="csl"> <div id="csl">
<button class="xxs cl btn" onclick="selectSlot(0);">1</button> <button id="csl0" class="btn xxs cl" onclick="selectSlot(0);" data-r="0" data-g="0" data-b="0" data-w="0">1</button>
<button class="xxs cl btn" onclick="selectSlot(1);">2</button> <button id="csl1" class="btn xxs cl" onclick="selectSlot(1);" data-r="0" data-g="0" data-b="0" data-w="0">2</button>
<button class="xxs cl btn" onclick="selectSlot(2);">3</button> <button id="csl2" class="btn xxs cl" onclick="selectSlot(2);" data-r="0" data-g="0" data-b="0" data-w="0">3</button>
</div> </div>
<p class="labels h" id="cslLabel"></p>
<div id="hexw"> <div id="hexw">
<i class="icons sel-icon" onclick="tglRgb()">&#xe22d;</i>
<input id="hexc" type="text" class="noslide" onkeydown="hexEnter()" autocomplete="off" maxlength="8" /> <input id="hexc" type="text" class="noslide" onkeydown="hexEnter()" autocomplete="off" maxlength="8" />
<button id="hexcnf" class="xxs btn" onclick="fromHex();"><i class="icons no-margin">&#xe390;</i></button> <button id="hexcnf" class="btn btn-xs" onclick="fromHex();"><i class="icons btn-icon">&#xe390;</i></button>
</div>
<p class="labels" id="pall"><i class="icons sel-icon" onclick="tglHex()">&#xe2b3;</i> Color palette</p>
<div id="palw" class="il">
<div class="staytop fnd">
<input type="text" placeholder="Search" oninput="search(this,'pallist')" onfocus="search(this,'pallist')" />
<i class="icons clear-icon" onclick="clean(this)">&#xe38f;</i>
<i class="icons search-icon">&#xe0a1;</i>
</div> </div>
<div id="palwrap">
<p class="labels">
<i class="icons sel-icon" onclick="tglHex()">&#xe2b3;</i>
Color palette
</p>
<div class="il">
<div id="pallist" class="list"> <div id="pallist" class="list">
<div class="lstI" data-id="0"> <div class="lstI">
<label class="check schkl"> <label class="radio schkl" onclick="loadPalettes()">
&nbsp;
<input type="radio" value="${palettes[i].id}" name="palette" onChange="setPalette()">
<span class="radiomark schk"></span>
</label>
<div class="lstIcontent"> <div class="lstIcontent">
<span class="lstIname"> <span class="lstIname">
Default Loading...
</span> </span>
</div> </div>
</div> </label>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div id="Effects" class="tabcontent"> <div id="Effects" class="tabcontent">
<p class="labels">Effect speed</p> <div id="fx">
<div class="staytop"> <p class="labels hd" id="modeLabel">Effect mode</p>
<i class="icons slider-icon" style="cursor: pointer;" title="Freeze" onclick="tglFreeze()">&#xe325;</i> <div class="staytop fnd" id="fxFind">
<input type="text" placeholder="Search" oninput="search(this,'fxlist')" onfocus="search(this,'fxlist');gId('filters').classList.add('fade');" onblur="gId('filters').classList.remove('fade')"/>
<i class="icons clear-icon" onclick="clean(this);">&#xe38f;</i>
<i class="icons search-icon" onclick="gId('filters').classList.toggle('hide');" style="cursor:pointer;">&#xe0a1;</i>
</div>
<div id="fxlist" class="list">
<div class="lstI">
<label class="radio schkl" onclick="loadFX()">
<div class="lstIcontent">
<span class="lstIname">
Loading...
</span>
</div>
</label>
</div>
</div>
</div>
<div id="sliders">
<div id="filters" class="filter">
<label id="filterPal" class="check fchkl">&#x1F3A8;
<input type="checkbox" data-flt="&#x1F3A8;" onchange="filterFx(this)">
<span class="checkmark"></span>
</label>
<label id="filter1D" class="check fchkl">&#8942;
<input type="checkbox" data-flt="&#8942;" onchange="filterFx(this)">
<span class="checkmark"></span>
</label>
<label id="filter2D" class="check fchkl">&#9638;
<input type="checkbox" data-flt="&#9638;" onchange="filterFx(this)">
<span class="checkmark"></span>
</label>
<label id="filterVol" class="check fchkl">&#9834;
<input type="checkbox" data-flt="&#9834;" onchange="filterFx(this)">
<span class="checkmark"></span>
</label>
<label id="filterFreq" class="check fchkl">&#9835;
<input type="checkbox" data-flt="&#9835;" onchange="filterFx(this)">
<span class="checkmark"></span>
</label>
</div>
<div id="slider0" class="slider">
<i class="icons slider-icon" style="cursor: pointer;" onclick="tglFreeze()">&#xe325;</i>
<div class="sliderwrap il"> <div class="sliderwrap il">
<input id="sliderSpeed" class="noslide" onchange="setSpeed()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" /> <input id="sliderSpeed" class="noslide" onchange="setSpeed()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
<output class="sliderbubble hidden"></output>
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div> </div>
<output class="sliderbubble"></output>
<span id="sliderLabel0" class="tooltiptext">Effect speed</span>
</div> </div>
<p class="labels">Effect intensity</p> <div id="slider1" class="slider">
<div class="staytop" id="staytop1"> <i class="icons slider-icon" style="cursor: pointer;" onclick="tglLabels()">&#xe409;</i>
<i class="icons slider-icon" onclick="tglLabels()">&#xe409;</i>
<div class="sliderwrap il"> <div class="sliderwrap il">
<input id="sliderIntensity" class="noslide" onchange="setIntensity()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" /> <input id="sliderIntensity" class="noslide" onchange="setIntensity()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
<output class="sliderbubble hidden"></output>
<div class="sliderdisplay"></div> <div class="sliderdisplay"></div>
</div> </div>
<output class="sliderbubble"></output>
<span class="tooltiptext" id="sliderLabel1">Effect intensity</span>
</div>
<div id="slider2" class="slider hide">
<i class="icons slider-icon">&#xe410;</i>
<div class="sliderwrap il">
<input id="sliderC1" class="noslide" onchange="setCustom(1)" oninput="updateTrail(this)" max="255" min="0" type="range" value="0" />
<div class="sliderdisplay"></div>
</div>
<output class="sliderbubble"></output>
<span class="tooltiptext" id="sliderLabel2">Custom 1</span>
</div>
<div id="slider3" class="slider hide">
<i class="icons slider-icon">&#xe0a2;</i>
<div class="sliderwrap il">
<input id="sliderC2" class="noslide" onchange="setCustom(2)" oninput="updateTrail(this)" max="255" min="0" type="range" value="0" />
<div class="sliderdisplay"></div>
</div>
<output class="sliderbubble"></output>
<span class="tooltiptext" id="sliderLabel3">Custom 2</span>
</div>
<div id="slider4" class="slider hide">
<i class="icons slider-icon">&#xe0e8;</i>
<div class="sliderwrap il">
<input id="sliderC3" class="noslide" onchange="setCustom(3)" oninput="updateTrail(this)" max="31" min="0" type="range" value="0" />
<div class="sliderdisplay"></div>
</div>
<output class="sliderbubble"></output>
<span class="tooltiptext" id="sliderLabel4">Custom 3</span>
</div>
<div id="fxopt" class="option fade">
<label id="opt0" class="check ochkl hide"><i class="icons">&#xe2b3;</i><span class="tooltiptext" id="optLabel0">Check 1</span>
<input type="checkbox" onchange="setOption(1, this.checked)">
<span class="checkmark"></span>
</label>
<label id="opt1" class="check ochkl hide"><i class="icons">&#xe34b;</i><span class="tooltiptext" id="optLabel1">Check 2</span>
<input type="checkbox" onchange="setOption(2, this.checked)">
<span class="checkmark"></span>
</label>
<label id="opt2" class="check ochkl hide"><i class="icons">&#xe04c;</i><span class="tooltiptext" id="optLabel2">Check 3</span>
<input type="checkbox" onchange="setOption(3, this.checked)">
<span class="checkmark"></span>
</label>
</div> </div>
<p class="labels">Effect mode</p>
<div id="fxlist" class="list">
Loading...
</div> </div>
</div> </div>
@ -163,24 +305,27 @@
<div id="segcont"> <div id="segcont">
Loading... Loading...
</div> </div>
<div id="segutil"> <div id="segutil" class="staybot">
</div> </div>
<div id="segutil2"> <div id="segutil2">
<button class="btn btn-s" id="rsbtn" onclick="rSegs()">Reset segments</button> <button class="btn btn-s" id="rsbtn" onclick="rSegs()">Reset segments</button>
</div> </div>
<p>Transition: <input id="tt" class="noslide" type="number" min="0" max="65.5" step="0.1" value="0.7">s</p> <p>Transition: <input id="tt" class="noslide" type="number" min="0" max="65.5" step="0.1" value="0.7">&nbsp;s</p>
</div> </div>
<div id="Presets" class="tabcontent"> <div id="Presets" class="tabcontent">
<div id="putil">
</div>
<div id="pql"> <div id="pql">
</div> </div>
<div id="pcont"> <p class="labels hd">Presets</p>
Loading... <div class="staytop fnd" id="psFind">
<input type="text" placeholder="Search" oninput="search(this,'pcont')" onfocus="search(this,'pcont')" />
<i class="icons clear-icon" onclick="clean(this);">&#xe38f;</i>
<i class="icons search-icon">&#xe0a1;</i>
</div>
<div id="pcont" class="list">
<span onclick="loadPresets()">Loading...</span>
</div>
<div id="putil" class="staybot">
</div> </div>
</div> </div>
</div> </div>
@ -193,25 +338,35 @@
</div> </div>
<div id="connind"></div> <div id="connind"></div>
<div id="toast"></div> <div id="toast" onclick="clearErrorToast(100);"></div>
<div id="namelabel" onclick="toggleNodes()"></div> <div id="namelabel" onclick="toggleNodes()"></div>
<div id="info" class="modal"> <div id="info" class="modal">
<button class="btn btn-xs close" onclick="toggleInfo()"><i class="icons rot45">&#xe18a;</i></button>
<div id="imgw"> <div id="imgw">
<img class="wi" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAFCAYAAAC5Fuf5AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABbSURBVChTlY9bDoAwDMNW7n9nwCipytQN4Z8tbrTHmDmF4oPzyldwRqp1SSdnV/NuZuzqerAByxXznBw3igkeFEfXyUuhK/yFM0CxJfyqXZEOc6/Sr9/bf7uIC5Nwd7orMvAPAAAAAElFTkSuQmCC" /> <img class="wi" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAFCAYAAAC5Fuf5AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABbSURBVChTlY9bDoAwDMNW7n9nwCipytQN4Z8tbrTHmDmF4oPzyldwRqp1SSdnV/NuZuzqerAByxXznBw3igkeFEfXyUuhK/yFM0CxJfyqXZEOc6/Sr9/bf7uIC5Nwd7orMvAPAAAAAElFTkSuQmCC" />
</div><br> </div>
<div id="kv">Loading...</div><br> <div id="kv">Loading...</div><br>
<button class="btn infobtn" onclick="requestJson(null)">Refresh</button> <div>
<button class="btn infobtn" onclick="toggleInfo()">Close Info</button><br> <button class="btn infobtn" onclick="requestJson()">Refresh</button>
<button class="btn infobtn" onclick="toggleNodes()">Instance List</button> <button class="btn infobtn" onclick="toggleNodes()">Instance List</button>
<button class="btn infobtn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button><br> <button class="btn infobtn" onclick="window.open('/update','_self');">Update WLED</button>
<span class="h">Made with <span id="heart">&#10084;&#xFE0E;</span> by Aircoookie and the WLED community</span> <button class="btn infobtn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button>
</div>
<br>
<span class="h">Made with <span id="heart">&#10084;&#xFE0E;</span> by Aircoookie and the <a href="https://wled.discourse.group/" target="_blank">WLED community</a></span>
</div> </div>
<div id="nodes" class="modal"> <div id="nodes" class="modal">
<button class="btn btn-xs close" onclick="toggleNodes()"><i class="icons rot45">&#xe18a;</i></button>
<div id="ndlt">WLED instances</div> <div id="ndlt">WLED instances</div>
<div id="kn">Loading...</div><br> <div id="kn">Loading...</div>
<div style="position:sticky;bottom:0;">
<button class="btn infobtn" onclick="loadNodes()">Refresh</button> <button class="btn infobtn" onclick="loadNodes()">Refresh</button>
<button class="btn infobtn" onclick="toggleNodes()">Close list</button><br> </div>
</div>
<div id="mliveview2D" class="modal">
<div id="kliveview2D" style="width:100%; height:100%">Loading...</div><br>
</div> </div>
<div id="rover" class="modal"> <div id="rover" class="modal">
@ -224,8 +379,6 @@
<span class="h">For best performance, it is recommended to turn off the streaming source when not in use.</span> <span class="h">For best performance, it is recommended to turn off the streaming source when not in use.</span>
</div> </div>
<i id="roverstar" class="icons huge" onclick="setLor(0)">&#xe410;</i><br> <i id="roverstar" class="icons huge" onclick="setLor(0)">&#xe410;</i><br>
<script src="iro.js"></script>
<script src="rangetouch.js"></script>
<script src="index.js"></script> <script src="index.js"></script>
</body> </body>
</html> </html>

File diff suppressed because it is too large Load Diff

View File

@ -19,49 +19,43 @@
</style> </style>
</head> </head>
<body> <body>
<div id="canv" /> <div id="canv"></div>
<script> <script>
function updatePreview(leds) { var ws;
var str = "linear-gradient(90deg,"; try {
var len = leds.length; ws = top.window.ws;
for (i = 2; i < len; i+=3) { } catch (e) {}
if (ws && ws.readyState === WebSocket.OPEN) {
//console.info("Peek uses top WS");
ws.send("{'lv':true}");
} else {
console.info("Peek WS opening");
ws = new WebSocket((window.location.protocol == "https:"?"wss":"ws")+"://"+document.location.host+"/ws");
ws.onopen = function () {
//console.info("Peek WS open");
ws.send("{'lv':true}");
}
}
ws.binaryType = "arraybuffer";
ws.addEventListener('message', (e) => {
try {
if (toString.call(e.data) === '[object ArrayBuffer]') {
let leds = new Uint8Array(event.data);
if (leds[0] != 76) return; //'L'
let str = "linear-gradient(90deg,";
let len = leds.length;
let start = leds[1]==2 ? 4 : 2; // 1 = 1D, 2 = 1D/2D (leds[2]=w, leds[3]=h)
for (i = start; i < len; i+=3) {
str += `rgb(${leds[i]},${leds[i+1]},${leds[i+2]})`; str += `rgb(${leds[i]},${leds[i+1]},${leds[i+2]})`;
if (i < len -3) str += "," if (i < len -3) str += ","
} }
str += ")"; str += ")";
document.getElementById("canv").style.background = str; document.getElementById("canv").style.background = str;
} }
} catch (err) {
function getLiveJson(e) {
try {
if (toString.call(e.data) === '[object ArrayBuffer]') {
let leds = new Uint8Array(event.data);
if (leds[0] != 76) return; //'L'
updatePreview(leds);
}
}
catch (err) {
console.error("Peek WS error:",err); console.error("Peek WS error:",err);
} }
} });
var ws;
try {
ws = top.window.ws;
} catch (e) {}
if (ws && ws.readyState === WebSocket.OPEN) {
console.info("Peek uses top WS");
ws.send("{'lv':true}");
} else {
console.info("Peek WS opening");
ws = new WebSocket((window.location.protocol == "https:"?"wss":"ws")+"://"+document.location.host+"/ws");
ws.onopen = function () {
console.info("Peek WS open");
ws.send("{'lv':true}");
}
}
ws.binaryType = "arraybuffer";
ws.addEventListener('message',getLiveJson);
</script> </script>
</body> </body>
</html> </html>

View File

@ -0,0 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<meta charset="utf-8">
<meta name="theme-color" content="#222222">
<title>WLED Live Preview</title>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<canvas id="canv"></canvas>
<script>
var c = document.getElementById('canv');
var leds = "";
var throttled = false;
function setCanvas() {
c.width = window.innerWidth * 0.98; //remove scroll bars
c.height = window.innerHeight * 0.98; //remove scroll bars
}
setCanvas();
// Check for canvas support
var ctx = c.getContext('2d');
if (ctx) { // Access the rendering context
// use parent WS or open new
var ws;
try {
ws = top.window.ws;
} catch (e) {}
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send("{'lv':true}");
} else {
ws = new WebSocket((window.location.protocol == "https:"?"wss":"ws")+"://"+document.location.host+"/ws");
ws.onopen = ()=>{
ws.send("{'lv':true}");
}
}
ws.binaryType = "arraybuffer";
ws.addEventListener('message',(e)=>{
try {
if (toString.call(e.data) === '[object ArrayBuffer]') {
let leds = new Uint8Array(event.data);
if (leds[0] != 76 || leds[1] != 2 || !ctx) return; //'L', set in ws.cpp
let mW = leds[2]; // matrix width
let mH = leds[3]; // matrix height
let pPL = Math.min(c.width / mW, c.height / mH); // pixels per LED (width of circle)
let lOf = Math.floor((c.width - pPL*mW)/2); //left offeset (to center matrix)
var i = 4;
for (y=0.5;y<mH;y++) for (x=0.5; x<mW; x++) {
ctx.fillStyle = `rgb(${leds[i]},${leds[i+1]},${leds[i+2]})`;
ctx.beginPath();
ctx.arc(x*pPL+lOf, y*pPL, pPL*0.4, 0, 2 * Math.PI);
ctx.fill();
i+=3;
}
}
} catch (err) {
console.error("Peek WS error:",err);
}
});
}
// window.resize event listener
window.addEventListener('resize', (e)=>{
if (!throttled) { // only run if we're not throttled
setCanvas(); // actual callback action
throttled = true; // we're throttled!
setTimeout(()=>{ // set a timeout to un-throttle
throttled = false;
}, 250);
}
});
</script>
</body>
</html>

View File

@ -4,27 +4,13 @@
<head> <head>
<meta content='width=device-width' name='viewport'> <meta content='width=device-width' name='viewport'>
<title>WLED Message</title> <title>WLED Message</title>
<script>function B() { window.history.back() }; function RS() { window.location = "/settings"; } function RP() { top.location.href = "/"; }</script> <script>
function B() { window.history.back() };
function RS() { window.location = "/settings"; }
function RP() { top.location.href = "/"; }
</script>
<style> <style>
.bt { @import url("style.css");
background: #333;
color: #fff;
font-family: Verdana, sans-serif;
border: .3ch solid #333;
display: inline-block;
font-size: 20px;
margin: 8px;
margin-top: 12px
}
body {
font-family: Verdana, sans-serif;
text-align: center;
background: #222;
color: #fff;
line-height: 200%%;
margin: 0
}
</style> </style>
</head> </head>

View File

@ -1,7 +1,44 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head><meta charset="UTF-8"> <head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<title>WLED Settings</title> <title>WLED Settings</title>
<script>
var d=document;
var loc = false, locip;
function gId(n){return d.getElementById(n);}
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
GetV();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
}
function S(){
if (window.location.protocol == "file:") {
loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
}
}
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=0';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
}
</script>
<style> <style>
body { body {
text-align: center; text-align: center;
@ -10,29 +47,33 @@
margin: 0; margin: 0;
} }
html { html {
--h: 10.2vh; --h: 9vh;
} }
button { button {
background: #333; background: #333;
color: #fff; color: #fff;
font-family: Verdana, Helvetica, sans-serif; font-family: Verdana, Helvetica, sans-serif;
display: block;
border: 1px solid #333; border: 1px solid #333;
border-radius: var(--h); border-radius: var(--h);
font-size: 6vmin; font-size: 6vmin;
height: var(--h); height: var(--h);
width: calc(100% - 40px); width: calc(100% - 40px);
margin-top: 2vh; margin: 2vh auto 0;
cursor: pointer;
} }
</style> </style>
</head> </head>
<body> <body onload="S()">
<form action="/"><button type=submit id="b">Back</button></form> <button type=submit id="b" onclick="window.location='/'">Back</button>
<form action="/settings/wifi"><button type="submit">WiFi Setup</button></form> <button type="submit" onclick="window.location='./settings/wifi'">WiFi Setup</button>
<form action="/settings/leds"><button type="submit">LED Preferences</button></form> <button type="submit" onclick="window.location='./settings/leds'">LED Preferences</button>
<form action="/settings/ui"><button type="submit">User Interface</button></form> <button type="submit" onclick="window.location='./settings/2D'">2D Configuration</button>
<form action="/settings/sync"><button type="submit">Sync Interfaces</button></form> <button type="submit" onclick="window.location='./settings/ui'">User Interface</button>
<form action="/settings/time"><button type="submit">Time & Macros</button></form> <button id="dmxbtn" style="display: none;" type="submit" onclick="window.location='./settings/dmx'">DMX Output</button>
<form action="/settings/um"><button type="submit">Usermods</button></form> <button type="submit" onclick="window.location='./settings/sync'">Sync Interfaces</button>
<form action="/settings/sec"><button type="submit">Security & Updates</button></form> <button type="submit" onclick="window.location='./settings/time'">Time & Macros</button>
<button type="submit" onclick="window.location='./settings/um'">Usermods</button>
<button type="submit" onclick="window.location='./settings/sec'">Security & Updates</button>
</body> </body>
</html> </html>

150
wled00/data/settings_2D.htm Normal file
View File

@ -0,0 +1,150 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<title>2D Set-up</title>
<script>
var d=document;
var loc = false, locip;
function H(){window.open("https://kno.wled.ge/features/2D");}
function B(){window.open("/settings","_self");}
function gId(n){return d.getElementById(n);}
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
GetV();
UI();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
}
function S() {
if (window.location.protocol == "file:") {
loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
}
}
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=10';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
}
var maxPanels=64;
function UI(change=false)
{
if (gId("somp").value === "0") {
gId("mpdiv").style.display = "none";
resetPanels();
return;
}
gId("mpdiv").style.display = "block";
maxPanels = parseInt(d.Sf.MPH.value) * parseInt(d.Sf.MPV.value);
let i = gId("panels").children.length;
if (i<maxPanels) for (let j=i; j<maxPanels; j++) addPanel(j);
if (i>maxPanels) for (let j=i; j>maxPanels; j--) remPanel();
//btnPanel(gId("panels").children.length);
}
function addPanels() {
let h = parseInt(d.Sf.MPH.value);
let v = parseInt(d.Sf.MPV.value);
for (let i=0; i<h*v; i++) addPanel(i);
}
function addPanel(i=0) {
let p = gId("panels");
if (p.children.length >= maxPanels) return;
let b = `<div id="pnl${i}">${i===0?"":'<hr style="width:260px">'}Panel ${i}<br>1<sup>st</sup> LED: <select name="P${i}B">
<option value="0">Top</option>
<option value="1">Bottom</option>
</select><select name="P${i}R">
<option value="0">Left</option>
<option value="1">Right</option>
</select><br>
Orientation: <select name="P${i}V">
<option value="0">Horizontal</option>
<option value="1">Vertical</option>
</select><br>
Serpentine: <input type="checkbox" name="P${i}S"></div>`;
p.insertAdjacentHTML("beforeend", b);
}
function remPanel() {
let p = gId("panels").children;
var i = p.length;
if (i <= 1) return;
p[i-1].remove();
}
function resetPanels() {
d.Sf.MPH.value = 1;
d.Sf.MPV.value = 1;
for (let e of gId("panels").children) e.remove();
}
function btnPanel(i) {
gId("pnl_add").style.display = (i<maxPanels) ? "inline":"none";
gId("pnl_rem").style.display = (i>1) ? "inline":"none";
}
</script>
<style>@import url("style.css");</style>
</head>
<body onload="S()">
<form id="form_s" name="Sf" method="post">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
</div>
<h2>2D setup</h2>
Strip or panel:
<select id="somp" name="SOMP" onchange="resetPanels();addPanels();UI();" >
<option value="0">1D Strip</option>
<option value="1">2D Matrix</option>
</select><br>
<div id="mpdiv" style="display:none;">
<h3>Panel set-up</h3>
Panel dimensions (WxH): <input name="PW" type="number" min="1" max="128" value="8"> x <input name="PH" type="number" min="1" max="128" value="8"><br>
Horizontal panels: <input name="MPH" type="number" min="1" max="8" value="1" oninput="UI()">
Vertical panels: <input name="MPV" type="number" min="1" max="8" value="1" oninput="UI()"><br>
1<sup>st</sup> panel: <select name="PB">
<option value="0">Top</option>
<option value="1">Bottom</option>
</select><select name="PR">
<option value="0">Left</option>
<option value="1">Right</option>
</select><br>
Orientation: <select name="PV">
<option value="0">Horizontal</option>
<option value="1">Vertical</option>
</select><br>
Serpentine: <input type="checkbox" name="PS">
<hr style="width:260px">
<i>A matrix is made of 1 or more physical LED panels of the same dimensions.<br>
Panels should be arranged from top-left to bottom-right order, starting with lower panel number on the left (or top if transposed).<br>
Each panel can have different LED orientation and/or starting point and/or layout.</i><br>
<hr style="width:260px">
<h3>LED panel layout</h3>
<div id="panels">
</div>
</div>
<hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form>
</body>
</html>

View File

@ -1,15 +1,22 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"><head><meta name="viewport" content="width=500"><meta charset="utf-8"><title>DMX Settings</title> <html lang="en">
<head>
<meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<meta charset="utf-8">
<title>DMX Settings</title>
<script> <script>
var d=document;
var loc = false, locip;
function H(){window.open("https://github.com/Aircoookie/WLED/wiki/DMX");}
function B(){window.history.back();}
function GCH(num) { function GCH(num) {
d=document;
d.getElementById('dmxchannels').innerHTML += ""; d.getElementById('dmxchannels').innerHTML += "";
for (i=0;i<num;i++) { for (i=0;i<num;i++) {
d.getElementById('dmxchannels').innerHTML += "<span id=CH" + (i+1) + "s >Channel " + (i+1) + ": <select name=CH" + (i+1) + " id=\"CH" + (i+1) + "\"><option value=0>Set to 0</option><option value=1>Red</option><option value=2>Green</option><option value=3>Blue</option><option value=4>White</option><option value=5>Shutter (Brightness)</option><option value=6>Set to 255</option></select></span><br />\n"; d.getElementById('dmxchannels').innerHTML += "<span id=CH" + (i+1) + "s >Channel " + (i+1) + ": <select name=CH" + (i+1) + " id=\"CH" + (i+1) + "\"><option value=0>Set to 0</option><option value=1>Red</option><option value=2>Green</option><option value=3>Blue</option><option value=4>White</option><option value=5>Shutter (Brightness)</option><option value=6>Set to 255</option></select></span><br />\n";
} }
} }
function mMap(){ function mMap(){
d=document;
numCh=document.Sf.CN.value; numCh=document.Sf.CN.value;
numGap=document.Sf.CG.value; numGap=document.Sf.CG.value;
if (parseInt(numCh)>parseInt(numGap)) { if (parseInt(numCh)>parseInt(numGap)) {
@ -28,17 +35,45 @@ function mMap(){
} }
} }
} }
function S(){GCH(15);GetV();mMap();}function H(){window.open("https://github.com/Aircoookie/WLED/wiki/DMX");}function B(){window.history.back();} // https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function GetV(){} function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
GCH(15);GetV();mMap();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
}
function S(){
if (window.location.protocol == "file:") {
loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
}
}
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=7';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
}
</script> </script>
<style> <style>@import url("style.css");</style>
@import url("style.css");
</style>
</head> </head>
<body onload="S()"> <body onload="S()">
<form id="form_s" name="Sf" method="post"> <form id="form_s" name="Sf" method="post">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
</div>
<h2>Imma firin ma lazer (if it has DMX support)</h2><!-- TODO: Change to something less-meme-related //--> <h2>Imma firin ma lazer (if it has DMX support)</h2><!-- TODO: Change to something less-meme-related //-->
Proxy Universe <input name=PU type=number min=0 max=63999 required> from E1.31 to DMX (0=disabled)<br> Proxy Universe <input name=PU type=number min=0 max=63999 required> from E1.31 to DMX (0=disabled)<br>

View File

@ -8,10 +8,34 @@
<script> <script>
var d=document,laprev=55,maxB=1,maxM=4000,maxPB=4096,maxL=1333,maxLbquot=0; //maximum bytes for LED allocation: 4kB for 8266, 32kB for 32 var d=document,laprev=55,maxB=1,maxM=4000,maxPB=4096,maxL=1333,maxLbquot=0; //maximum bytes for LED allocation: 4kB for 8266, 32kB for 32
var customStarts=false,startsDirty=[],maxCOOverrides=5; var customStarts=false,startsDirty=[],maxCOOverrides=5;
var loc = false, locip;
function H(){window.open("https://kno.wled.ge/features/settings/#led-settings");} function H(){window.open("https://kno.wled.ge/features/settings/#led-settings");}
function B(){window.open("/settings","_self");} function B(){window.open("/settings","_self");}
function gId(n){return d.getElementById(n);} function gId(n){return d.getElementById(n);}
function off(n){d.getElementsByName(n)[0].value = -1;} function off(n){d.getElementsByName(n)[0].value = -1;}
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
d.um_p = [];
d.rsvd = [];
d.ro_pins = [];
d.max_gpio = 39;
GetV();checkSi();setABL();
if (d.um_p[0]==-1) d.um_p.shift();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
}
var timeout; var timeout;
function showToast(text, error = false) function showToast(text, error = false)
{ {
@ -38,9 +62,11 @@
//check for pin conflicts //check for pin conflicts
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR") if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
if (LCs[i].value!="" && LCs[i].value!="-1") { if (LCs[i].value!="" && LCs[i].value!="-1") {
if (d.um_p && d.um_p.some((e)=>e==parseInt(LCs[i].value,10))) {alert(`Sorry, pins ${JSON.stringify(d.um_p)} can't be used.`);LCs[i].value="";LCs[i].focus();return false;} var p = []; // used pin array
else if (LCs[i].value > 5 && LCs[i].value < 12) {alert("Sorry, pins 6-11 can not be used.");LCs[i].value="";LCs[i].focus();return false;} for (k=0;k<d.rsvd.length;k++) p.push(d.rsvd[k]); // fill with reservations
else if (!(nm == "IR" || nm=="BT") && LCs[i].value > 33) {alert("Sorry, pins >33 are input only.");LCs[i].value="";LCs[i].focus();return false;} for (k=0;k<d.um_p.length;k++) p.push(d.um_p[k]); // fill with usermod pins
if (p.some((e)=>e==parseInt(LCs[i].value,10))) {alert(`Sorry, pins ${JSON.stringify(p)} can't be used.`);LCs[i].value="";LCs[i].focus();return false;}
else if (!(nm == "IR" || nm=="BT") && d.ro_pins.some((e)=>e==parseInt(LCs[i].value,10))) {alert(`Sorry, pins ${JSON.stringify(d.ro_gpio)} are input only.`);LCs[i].value="";LCs[i].focus();return false;}
for (j=i+1; j<LCs.length; j++) for (j=i+1; j<LCs.length; j++)
{ {
var n2 = LCs[j].name.substring(0,2); var n2 = LCs[j].name.substring(0,2);
@ -157,15 +183,18 @@
gId("rf"+n).checked = (gId("rf"+n).checked || t == 31); // LEDs require data in off state gId("rf"+n).checked = (gId("rf"+n).checked || t == 31); // LEDs require data in off state
if (t > 31 && t < 48) d.getElementsByName("LC"+n)[0].value = 1; // for sanity change analog count just to 1 LED if (t > 31 && t < 48) d.getElementsByName("LC"+n)[0].value = 1; // for sanity change analog count just to 1 LED
} }
gId("rf"+n).onclick = (t == 31) ? (function(){return false}) : (function(){}); // prevent change for TM1814 gId("rf"+n).onclick = (t == 31) ? (()=>{return false}) : (()=>{}); // prevent change for TM1814
isRGBW |= (t == 30 || t == 31 || (t > 40 && t < 46 && t != 43)); // RGBW checkbox, TYPE_xxxx values from const.h isRGBW = (t == 30 || t == 31 || (t > 40 && t < 46 && t != 43) || t == 88); // RGBW checkbox, TYPE_xxxx values from const.h
gId("co"+n).style.display = ((t>=80 && t<96) || (t > 40 && t < 48)) ? "none":"inline"; // hide color order for PWM gId("co"+n).style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide color order for PWM
gId("dig"+n+"c").style.display = (t > 40 && t < 48) ? "none":"inline"; // hide count for analog gId("dig"+n+"w").style.display = (t == 30 || t == 31) ? "inline":"none"; // show swap channels dropdown
if (!(t == 30 || t == 31)) d.getElementsByName("WO"+n)[0].value = 0; // reset swapping
gId("dig"+n+"c").style.display = (t >= 40 && t < 48) ? "none":"inline"; // hide count for analog
gId("dig"+n+"r").style.display = (t >= 80 && t < 96) ? "none":"inline"; // hide reversed for virtual gId("dig"+n+"r").style.display = (t >= 80 && t < 96) ? "none":"inline"; // hide reversed for virtual
gId("dig"+n+"s").style.display = ((t>=80 && t<96) || (t > 40 && t < 48)) ? "none":"inline"; // hide skip 1st for virtual & analog gId("dig"+n+"s").style.display = ((t >= 80 && t < 96) || (t >= 40 && t < 48)) ? "none":"inline"; // hide skip 1st for virtual & analog
gId("dig"+n+"f").style.display = (t>=16 && t<32 || t>=50 && t<64) ? "inline":"none"; // hide refresh gId("dig"+n+"f").style.display = ((t >= 16 && t < 32) || (t >= 50 && t < 64)) ? "inline":"none"; // hide refresh
gId("rev"+n).innerHTML = (t > 40 && t < 48) ? "Inverted output":"Reversed (rotated 180°)"; // change reverse text for analog gId("dig"+n+"a").style.display = (isRGBW && t != 40) ? "inline":"none"; // auto calculate white
gId("psd"+n).innerHTML = (t > 40 && t < 48) ? "Index:":"Start:"; // change analog start description gId("rev"+n).innerHTML = (t >= 40 && t < 48) ? "Inverted output":"Reversed (rotated 180°)"; // change reverse text for analog
gId("psd"+n).innerHTML = (t >= 40 && t < 48) ? "Index:":"Start:"; // change analog start description
} }
} }
// display white channel calculation method // display white channel calculation method
@ -208,7 +237,7 @@
LCs[i].style.color="#fff"; LCs[i].style.color="#fff";
continue; // do not check conflicts continue; // do not check conflicts
} else { } else {
LCs[i].max = 33; LCs[i].max = d.max_gpio;
LCs[i].min = -1; LCs[i].min = -1;
} }
} }
@ -216,7 +245,8 @@
if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR") if (nm=="L0" || nm=="L1" || nm=="L2" || nm=="L3" || nm=="L4" || nm=="RL" || nm=="BT" || nm=="IR")
if (LCs[i].value!="" && LCs[i].value!="-1") { if (LCs[i].value!="" && LCs[i].value!="-1") {
var p = []; // used pin array var p = []; // used pin array
if (d.um_p && Array.isArray(d.um_p)) for (k=0;k<d.um_p.length;k++) p.push(d.um_p[k]); // fill with reservations for (k=0;k<d.rsvd.length;k++) p.push(d.rsvd[k]); // fill with reservations
for (k=0;k<d.um_p.length;k++) p.push(d.um_p[k]); // fill with usermod pins
for (j=0; j<LCs.length; j++) { for (j=0; j<LCs.length; j++) {
if (i==j) continue; if (i==j) continue;
var n2 = LCs[j].name.substring(0,2); var n2 = LCs[j].name.substring(0,2);
@ -230,7 +260,12 @@
} }
} }
// now check for conflicts // now check for conflicts
if (p.some((e)=>e==parseInt(LCs[i].value,10))) LCs[i].style.color="red"; else LCs[i].style.color=parseInt(LCs[i].value,10)>33?"orange":"#fff"; if (p.some((e)=>e==parseInt(LCs[i].value,10))) LCs[i].style.color="red"; else LCs[i].style.color=d.ro_gpio.some((e)=>e==parseInt(LCs[i].value,10))?"orange":"#fff";
}
// check buttons, IR & relay
if (nm=="IR" || nm=="BT" || nm=="RL") {
LCs[i].max = d.max_gpio;
LCs[i].min = -1;
} }
} }
// update total led count // update total led count
@ -240,7 +275,7 @@
// memory usage and warnings // memory usage and warnings
gId('m0').innerHTML = memu; gId('m0').innerHTML = memu;
bquot = memu / maxM * 100; bquot = memu / maxM * 100;
gId('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? (bquot > 90 ? "red":"orange"):"#ccc"} 0 ${bquot}%%, #444 ${bquot}%% 100%%)`; gId('dbar').style.background = `linear-gradient(90deg, ${bquot > 60 ? (bquot > 90 ? "red":"orange"):"#ccc"} 0 ${bquot}%, #444 ${bquot}% 100%)`;
gId('ledwarning').style.display = (maxLC > Math.min(maxPB,800) || bquot > 80) ? 'inline':'none'; gId('ledwarning').style.display = (maxLC > Math.min(maxPB,800) || bquot > 80) ? 'inline':'none';
gId('ledwarning').style.color = (maxLC > Math.max(maxPB,800) || bquot > 100) ? 'red':'orange'; gId('ledwarning').style.color = (maxLC > Math.max(maxPB,800) || bquot > 100) ? 'red':'orange';
gId('wreason').innerHTML = (bquot > 80) ? "80% of max. LED memory" +(bquot>100 ? ` (<b>ERROR: Using over ${maxM}B!</b>)` : "") : "800 LEDs per output"; gId('wreason').innerHTML = (bquot > 80) ? "80% of max. LED memory" +(bquot>100 ? ` (<b>ERROR: Using over ${maxM}B!</b>)` : "") : "800 LEDs per output";
@ -294,11 +329,13 @@ ${i+1}:
<option value="30">SK6812 RGBW</option> <option value="30">SK6812 RGBW</option>
<option value="31">TM1814</option> <option value="31">TM1814</option>
<option value="24">400kHz</option> <option value="24">400kHz</option>
<option value="25">TM1829</option>
<option value="50">WS2801</option> <option value="50">WS2801</option>
<option value="51">APA102</option> <option value="51">APA102</option>
<option value="52">LPD8806</option> <option value="52">LPD8806</option>
<option value="54">LPD6803</option> <option value="54">LPD6803</option>
<option value="53">P9813</option> <option value="53">P9813</option>
<option value="40">On/Off</option>
<option value="41">PWM White</option> <option value="41">PWM White</option>
<option value="42">PWM CCT</option> <option value="42">PWM CCT</option>
<option value="43">PWM RGB</option> <option value="43">PWM RGB</option>
@ -308,6 +345,7 @@ ${i+1}:
<option value="80">DDP RGB (network)</option> <option value="80">DDP RGB (network)</option>
<!--option value="81">E1.31 RGB (network)</option--> <!--option value="81">E1.31 RGB (network)</option-->
<!--option value="82">ArtNet RGB (network)</option--> <!--option value="82">ArtNet RGB (network)</option-->
<option value="88">DDP RGBW (network)</option>
</select><br> </select><br>
<div id="co${i}" style="display:inline">Color Order: <div id="co${i}" style="display:inline">Color Order:
<select name="CO${i}"> <select name="CO${i}">
@ -317,18 +355,21 @@ ${i+1}:
<option value="3">RBG</option> <option value="3">RBG</option>
<option value="4">BGR</option> <option value="4">BGR</option>
<option value="5">GBR</option> <option value="5">GBR</option>
</select><br></div> </select></div>
<div id="dig${i}w" style="display:none">Swap: <select name="WO${i}"><option value="0">None</option><option value="1">W & B</option><option value="2">W & G</option><option value="3">W & R</option></select></div>
<div>
<span id="psd${i}">Start:</span> <input type="number" name="LS${i}" id="ls${i}" class="l starts" min="0" max="8191" value="${lastEnd(i)}" oninput="startsDirty[${i}]=true;UI();" required />&nbsp; <span id="psd${i}">Start:</span> <input type="number" name="LS${i}" id="ls${i}" class="l starts" min="0" max="8191" value="${lastEnd(i)}" oninput="startsDirty[${i}]=true;UI();" required />&nbsp;
<div id="dig${i}c" style="display:inline">Length: <input type="number" name="LC${i}" class="l" min="1" max="${maxPB}" value="1" required oninput="UI()" /></div> <div id="dig${i}c" style="display:inline">Length: <input type="number" name="LC${i}" class="l" min="1" max="${maxPB}" value="1" required oninput="UI()" /></div><br>
<br> </div>
<span id="p0d${i}">GPIO:</span> <input type="number" name="L0${i}" min="0" max="33" required class="xs" onchange="UI()"/> <span id="p0d${i}">GPIO:</span> <input type="number" name="L0${i}" min="0" max="48" required class="s" onchange="UI()"/>
<span id="p1d${i}"></span><input type="number" name="L1${i}" min="0" max="33" class="xs" onchange="UI()"/> <span id="p1d${i}"></span><input type="number" name="L1${i}" min="0" max="48" class="s" onchange="UI()"/>
<span id="p2d${i}"></span><input type="number" name="L2${i}" min="0" max="33" class="xs" onchange="UI()"/> <span id="p2d${i}"></span><input type="number" name="L2${i}" min="0" max="48" class="s" onchange="UI()"/>
<span id="p3d${i}"></span><input type="number" name="L3${i}" min="0" max="33" class="xs" onchange="UI()"/> <span id="p3d${i}"></span><input type="number" name="L3${i}" min="0" max="48" class="s" onchange="UI()"/>
<span id="p4d${i}"></span><input type="number" name="L4${i}" min="0" max="33" class="xs" onchange="UI()"/> <span id="p4d${i}"></span><input type="number" name="L4${i}" min="0" max="48" class="s" onchange="UI()"/>
<div id="dig${i}r" style="display:inline"><br><span id="rev${i}">Reversed</span>: <input type="checkbox" name="CV${i}"></div> <div id="dig${i}r" style="display:inline"><br><span id="rev${i}">Reversed</span>: <input type="checkbox" name="CV${i}"></div>
<div id="dig${i}s" style="display:inline"><br>Skip first LEDs: <input type="number" name="SL${i}" min="0" max="255" value="0" oninput="UI()"></div> <div id="dig${i}s" style="display:inline"><br>Skip first LEDs: <input type="number" name="SL${i}" min="0" max="255" value="0" oninput="UI()"></div>
<div id="dig${i}f" style="display:inline"><br>Off Refresh: <input id="rf${i}" type="checkbox" name="RF${i}"></div> <div id="dig${i}f" style="display:inline"><br>Off Refresh: <input id="rf${i}" type="checkbox" name="RF${i}"></div>
<div id="dig${i}a" style="display:inline"><br>Auto-calculate white channel from RGB:<br><select name="AW${i}"><option value=0>None</option><option value=1>Brighter</option><option value=2>Accurate</option><option value=3>Dual</option></select>&nbsp;</div>
</div>`; </div>`;
f.insertAdjacentHTML("beforeend", cn); f.insertAdjacentHTML("beforeend", cn);
} }
@ -394,7 +435,7 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
var c = gId("btns").innerHTML; var c = gId("btns").innerHTML;
var bt = "BT" + String.fromCharCode((i<10?48:55)+i); var bt = "BT" + String.fromCharCode((i<10?48:55)+i);
var be = "BE" + String.fromCharCode((i<10?48:55)+i); var be = "BE" + String.fromCharCode((i<10?48:55)+i);
c += `Button ${i} GPIO: <input type="number" min="-1" max="40" name="${bt}" onchange="UI()" class="xs" value="${p}">`; c += `Button ${i} GPIO: <input type="number" min="-1" max="48" name="${bt}" onchange="UI()" class="xs" value="${p}">`;
c += `&nbsp;<select name="${be}">` c += `&nbsp;<select name="${be}">`
c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`; c += `<option value="0" ${t==0?"selected":""}>Disabled</option>`;
c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`; c += `<option value="2" ${t==2?"selected":""}>Pushbutton</option>`;
@ -405,7 +446,7 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
c += `<option value="7" ${t==7?"selected":""}>Analog</option>`; c += `<option value="7" ${t==7?"selected":""}>Analog</option>`;
c += `<option value="8" ${t==8?"selected":""}>Analog inverted</option>`; c += `<option value="8" ${t==8?"selected":""}>Analog inverted</option>`;
c += `</select>`; c += `</select>`;
c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`; c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#x2715;</span><br>`;
gId("btns").innerHTML = c; gId("btns").innerHTML = c;
} }
function tglSi(cs) { function tglSi(cs) {
@ -419,7 +460,7 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
var v = parseInt(gId("ls"+(i-1)).value) + parseInt(d.getElementsByName("LC"+(i-1))[0].value); var v = parseInt(gId("ls"+(i-1)).value) + parseInt(d.getElementsByName("LC"+(i-1))[0].value);
if (v != parseInt(gId("ls"+i).value)) {cs = true; startsDirty[i] = true;} if (v != parseInt(gId("ls"+i).value)) {cs = true; startsDirty[i] = true;}
} }
if (parseInt(gId("ls0").value) != 0) {cs = true; startsDirty[0] = true;} if (gId("ls0") && parseInt(gId("ls0").value) != 0) {cs = true; startsDirty[0] = true;}
gId("si").checked = cs; gId("si").checked = cs;
tglSi(cs); tglSi(cs);
} }
@ -500,21 +541,27 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
} }
} }
} }
function S(){GetV();checkSi();setABL();} function S(){
function GetV() if (window.location.protocol == "file:") {
{ loc = true;
//values injected by server while sending HTML locip = localStorage.getItem('locIp');
//d.um_p=[6,7,8,9,10,11,14,15,13,1,21,19,22,25,26,27,5,23,18,17];bLimits(10,2048,64000,8192);d.Sf.MS.checked=1;d.Sf.CCT.checked=0;addLEDs(1);d.Sf.L00.value=192;d.Sf.L10.value=168;d.Sf.L20.value=0;d.Sf.L30.value=61;d.Sf.LC0.value=421;d.Sf.LT0.value=80;d.Sf.CO0.value=1;d.Sf.LS0.value=0;d.Sf.CV0.checked=0;d.Sf.SL0.checked=0;d.Sf.RF0.checked=0;d.Sf.MA.value=850;d.Sf.LA.value=0;d.Sf.CA.value=127;d.Sf.AW.value=3;d.Sf.BO.checked=0;d.Sf.BP.value=0;d.Sf.GB.checked=0;d.Sf.GC.checked=1;d.Sf.TF.checked=1;d.Sf.TD.value=700;d.Sf.PF.checked=1;d.Sf.BF.value=100;d.Sf.TB.value=0;d.Sf.TL.value=60;d.Sf.TW.value=1;d.Sf.PB.selectedIndex=0;d.Sf.RL.value=-1;d.Sf.RM.checked=1;addBtn(0,-1,0);addBtn(1,-1,0);addBtn(2,-1,0);addBtn(3,-1,0);d.Sf.TT.value=32;d.Sf.IR.value=-1;d.Sf.IT.value=8; if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
}
}
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=2';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
} }
</script> </script>
<style> <style>@import url("style.css");</style>
@import url("style.css");
</style>
</head> </head>
<body onload="S()"> <body onload="S()">
<form id="form_s" name="Sf" method="post"> <form id="form_s" name="Sf" method="post">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
</div>
<h2>LED &amp; Hardware setup</h2> <h2>LED &amp; Hardware setup</h2>
Total LEDs: <span id="lc">?</span> <span id="pc"></span><br> Total LEDs: <span id="lc">?</span> <span id="pc"></span><br>
<i>Recommended power supply for brightest white:</i><br> <i>Recommended power supply for brightest white:</i><br>
@ -548,8 +595,8 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
<h3>Hardware setup</h3> <h3>Hardware setup</h3>
<div id="mLC">LED outputs:</div> <div id="mLC">LED outputs:</div>
<hr style="width:260px"> <hr style="width:260px">
<button type="button" id="+" onclick="addLEDs(1,false)" style="display:none;border-radius:20px;height:36px;">+</button> <button type="button" id="+" onclick="addLEDs(1,false)">+</button>
<button type="button" id="-" onclick="addLEDs(-1,false)" style="display:none;border-radius:20px;width:36px;height:36px;">-</button><br> <button type="button" id="-" onclick="addLEDs(-1,false)">-</button><br>
LED Memory Usage: <span id="m0">0</span> / <span id="m1">?</span> B<br> LED Memory Usage: <span id="m0">0</span> / <span id="m1">?</span> B<br>
<div id="dbar" style="display:inline-block; width: 100px; height: 10px; border-radius: 20px;"></div><br> <div id="dbar" style="display:inline-block; width: 100px; height: 10px; border-radius: 20px;"></div><br>
<div id="ledwarning" style="color: orange; display: none;"> <div id="ledwarning" style="color: orange; display: none;">
@ -559,18 +606,19 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
<hr style="width:260px"> <hr style="width:260px">
Make a segment for each output: <input type="checkbox" name="MS"><br> Make a segment for each output: <input type="checkbox" name="MS"><br>
Custom bus start indices: <input type="checkbox" onchange="tglSi(this.checked)" id="si"><br> Custom bus start indices: <input type="checkbox" onchange="tglSi(this.checked)" id="si"><br>
Use global LED buffer: <input type="checkbox" name="LD"><br>
<hr style="width:260px"> <hr style="width:260px">
<div id="color_order_mapping"> <div id="color_order_mapping">
Color Order Override: Color Order Override:
<div id="com_entries"></div> <div id="com_entries"></div>
<hr style="width:260px"> <hr style="width:260px">
<button type="button" id="com_add" onclick="addCOM();UI()" style="display:none;border-radius:20px;height:36px;">+</button> <button type="button" id="com_add" onclick="addCOM()">+</button>
<button type="button" id="com_rem" onclick="remCOM();UI()" style="display:none;border-radius:20px;width:36px;height:36px;">-</button><br> <button type="button" id="com_rem" onclick="remCOM()">-</button><br>
</div> </div>
<hr style="width:260px"> <hr style="width:260px">
<div id="btns"></div> <div id="btns"></div>
Touch threshold: <input type="number" class="s" min="0" max="100" name="TT" required><br> Touch threshold: <input type="number" class="s" min="0" max="100" name="TT" required><br>
IR GPIO: <input type="number" min="-1" max="40" name="IR" onchange="UI()" class="xs"><select name="IT" onchange="UI()"> IR GPIO: <input type="number" min="-1" max="48" name="IR" onchange="UI()" class="xs"><select name="IT" onchange="UI()">
<option value=0>Remote disabled</option> <option value=0>Remote disabled</option>
<option value=1>24-key RGB</option> <option value=1>24-key RGB</option>
<option value=2>24-key with CT</option> <option value=2>24-key with CT</option>
@ -580,27 +628,27 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
<option value=6>6-key black</option> <option value=6>6-key black</option>
<option value=7>9-key red</option> <option value=7>9-key red</option>
<option value=8>JSON remote</option> <option value=8>JSON remote</option>
</select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#215;</span><br> </select><span style="cursor: pointer;" onclick="off('IR')">&nbsp;&#x2715;</span><br>
Apply IR change to main segment only: <input type="checkbox" name="MSO"><br> Apply IR change to main segment only: <input type="checkbox" name="MSO"><br>
<div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"> <input type="button" value="Upload" onclick="uploadFile('/ir.json');"><br></div> <div id="json" style="display:none;">JSON file: <input type="file" name="data" accept=".json"><button type="button" class="sml" onclick="uploadFile('/ir.json')">Upload</button><br></div>
<a href="https://kno.wled.ge/interfaces/infrared/" target="_blank">IR info</a><br> <a href="https://kno.wled.ge/interfaces/infrared/" target="_blank">IR info</a><br>
Relay GPIO: <input type="number" min="-1" max="33" name="RL" onchange="UI()" class="xs"> Invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#215;</span><br> Relay GPIO: <input type="number" min="-1" max="48" name="RL" onchange="UI()" class="xs"> Invert <input type="checkbox" name="RM"><span style="cursor: pointer;" onclick="off('RL')">&nbsp;&#x2715;</span><br>
<hr style="width:260px"> <hr style="width:260px">
<h3>Defaults</h3> <h3>Defaults</h3>
Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br> Turn LEDs on after power up/reset: <input type="checkbox" name="BO"><br>
Default brightness: <input name="CA" type="number" class="s" min="0" max="255" required> (0-255)<br><br> Default brightness: <input name="CA" type="number" class="m" min="0" max="255" required> (0-255)<br><br>
Apply preset <input name="BP" type="number" class="s" min="0" max="250" required> at boot (0 uses defaults) Apply preset <input name="BP" type="number" class="m" min="0" max="250" required> at boot (0 uses defaults)
<br><br> <br><br>
Use Gamma correction for color: <input type="checkbox" name="GC"> (strongly recommended)<br> Use Gamma correction for color: <input type="checkbox" name="GC"> (strongly recommended)<br>
Use Gamma correction for brightness: <input type="checkbox" name="GB"> (not recommended)<br><br> Use Gamma correction for brightness: <input type="checkbox" name="GB"> (not recommended)<br><br>
Brightness factor: <input name="BF" type="number" class="s" min="1" max="255" required> %% Brightness factor: <input name="BF" type="number" class="m" min="1" max="255" required> %
<h3>Transitions</h3> <h3>Transitions</h3>
Crossfade: <input type="checkbox" name="TF"><br> Crossfade: <input type="checkbox" name="TF"><br>
Transition Time: <input name="TD" type="number" class="l" min="0" max="65500"> ms<br> Transition Time: <input name="TD" type="number" class="xl" min="0" max="65500"> ms<br>
Enable Palette transitions: <input type="checkbox" name="PF"> Enable Palette transitions: <input type="checkbox" name="PF">
<h3>Timed light</h3> <h3>Timed light</h3>
Default Duration: <input name="TL" type="number" class="s" min="1" max="255" required> min<br> Default Duration: <input name="TL" type="number" class="m" min="1" max="255" required> min<br>
Default Target brightness: <input name="TB" type="number" class="s" min="0" max="255" required><br> Default Target brightness: <input name="TB" type="number" class="m" min="0" max="255" required><br>
Mode: Mode:
<select name="TW"> <select name="TW">
<option value="0">Wait and set</option> <option value="0">Wait and set</option>
@ -611,8 +659,9 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
<h3>White management</h3> <h3>White management</h3>
White Balance correction: <input type="checkbox" name="CCT"> <br> White Balance correction: <input type="checkbox" name="CCT"> <br>
<span class="wc"> <span class="wc">
Auto-calculate white channel from RGB:<br> Global override for Auto-calculate white:<br>
<select name="AW"> <select name="AW">
<option value=255>Disabled</option>
<option value=0>None</option> <option value=0>None</option>
<option value=1>Brighter</option> <option value=1>Brighter</option>
<option value=2>Accurate</option> <option value=2>Accurate</option>
@ -620,7 +669,7 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
</select> </select>
<br> <br>
Calculate CCT from RGB: <input type="checkbox" name="CR"> <br> Calculate CCT from RGB: <input type="checkbox" name="CR"> <br>
CCT additive blending: <input type="number" class="s" min="0" max="100" name="CB" required> %%</span> CCT additive blending: <input type="number" class="s" min="0" max="100" name="CB" required> %</span>
<h3>Advanced</h3> <h3>Advanced</h3>
Palette blending: Palette blending:
<select name="PB"> <select name="PB">
@ -631,7 +680,7 @@ Length: <input type="number" name="XC${i}" id="xc${i}" class="l" min="1" max="65
</select><br> </select><br>
Target refresh rate: <input type="number" class="s" min="1" max="120" name="FR" required> FPS Target refresh rate: <input type="number" class="s" min="1" max="120" name="FR" required> FPS
<hr style="width:260px"> <hr style="width:260px">
<div id="cfg">Config template: <input type="file" name="data2" accept=".json"> <input type="button" value="Apply" onclick="loadCfg(d.Sf.data2);"><br></div> <div id="cfg">Config template: <input type="file" name="data2" accept=".json"><button type="button" class="sml" onclick="loadCfg(d.Sf.data2)">Apply</button><br></div>
<hr> <hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button> <button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form> </form>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<meta charset="utf-8">
<title>PIN required</title>
<script>
var d = document;
function B() { window.open("/settings","_self"); }
</script>
<style>
@import url("style.css");
</style>
</head>
<body onload="d.getElementsByName('PIN')[0].focus()">
<form id="form_s" name="Sf" method="post">
<h2>Please enter settings PIN code</h2>
<input type="password" name="PIN" size="4" maxlength="4" minlength="4" pattern="[0-9]*" inputmode="numeric" autofocus>
<hr>
<button type="button" onclick="B()">Back</button><button type="submit">Submit</button>
</form>
</body>
</html>

View File

@ -2,38 +2,46 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta name="viewport" content="width=500"> <meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Misc Settings</title> <title>Misc Settings</title>
<script> <script>
var d = document; var d = document;
function H() var loc = false, locip;
{ function H() { window.open("https://kno.wled.ge/features/settings/#security-settings"); }
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#security-settings"); function B() { window.open("/settings","_self"); }
} function U() { window.open("/update","_self"); }
function B() function gId(s) { return d.getElementById(s); }
{ function isObj(o) { return (o && typeof o === 'object' && !Array.isArray(o)); }
window.open("/settings","_self"); // https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
} function loadJS(FILE_URL, async = true) {
function U() let scE = d.createElement("script");
{ scE.setAttribute("src", FILE_URL);
window.open("/update","_self"); scE.setAttribute("type", "text/javascript");
} scE.setAttribute("async", async);
function gId(s) d.body.appendChild(scE);
{ // success event
return d.getElementById(s); scE.addEventListener("load", () => {
} //console.log("File loaded");
function isObject(item) { GetV();
return (item && typeof item === 'object' && !Array.isArray(item)); setBckFilename(gId("bckcfg"));
setBckFilename(gId("bckpresets"));
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
} }
var timeout; var timeout;
function showToast(text, error = false) function showToast(text, error = false)
{ {
var x = gId("toast"); var x = gId("toast");
x.innerHTML = text; x.innerHTML = text;
x.className = error ? "error":"show"; x.classList.add(error ? "error":"show");
clearTimeout(timeout); clearTimeout(timeout);
x.style.animation = 'none'; x.style.animation = 'none';
timeout = setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2900); timeout = setTimeout(function(){ x.classList.remove("show"); }, 2900);
} }
function uploadFile(fO,name) { function uploadFile(fO,name) {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
@ -46,20 +54,42 @@
fO.value = ''; fO.value = '';
return false; return false;
} }
function GetV() function checkNum(o) {
{ const specialkeys = ["Backspace", "Tab", "Enter", "Shift", "Control", "Alt", "Pause", "CapsLock", "Escape", "Space", "PageUp", "PageDown", "End", "Home", "ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown", "Insert", "Delete"];
//values injected by server while sending HTML // true if key is a number or a special key
if(event.key.match(/[0-9]/) || specialkeys.includes(event.key)) return true;
event.preventDefault();
return false;
}
function setBckFilename(x) {
x.setAttribute("download","wled_" + x.getAttribute("download") + (sd=="WLED"?"":("_" +sd)));
}
function S() {
if (window.location.protocol == "file:") {
loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
}
}
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=6';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
} }
</script> </script>
<style> <style>
@import url("style.css"); @import url("style.css");
</style> </style>
</head> </head>
<body onload="GetV()"> <body onload="S()">
<form id="form_s" name="Sf" method="post"> <form id="form_s" name="Sf" method="post">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save & Reboot</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
</div>
<h2>Security & Update setup</h2> <h2>Security & Update setup</h2>
Settings PIN: <input type="password" id="PIN" name="PIN" size="4" maxlength="4" minlength="4" onkeydown="checkNum(this)" pattern="[0-9]*" inputmode="numeric" title="Please enter a 4 digit number"><br>
<div style="color: #fa0;">&#9888; Unencrypted transmission. Be prudent when selecting PIN, do NOT use your banking, door, SIM, etc. pin!</div><br><br>
Lock wireless (OTA) software update: <input type="checkbox" name="NO"><br> Lock wireless (OTA) software update: <input type="checkbox" name="NO"><br>
Passphrase: <input type="password" name="OP" maxlength="32"><br> Passphrase: <input type="password" name="OP" maxlength="32"><br>
To enable OTA, for security reasons you need to also enter the correct password!<br> To enable OTA, for security reasons you need to also enter the correct password!<br>
@ -69,18 +99,21 @@
Deny access to WiFi settings if locked: <input type="checkbox" name="OW"><br><br> Deny access to WiFi settings if locked: <input type="checkbox" name="OW"><br><br>
Factory reset: <input type="checkbox" name="RS"><br> Factory reset: <input type="checkbox" name="RS"><br>
All settings and presets will be erased.<br><br> All settings and presets will be erased.<br><br>
HTTP traffic is unencrypted. An attacker in the same network can intercept form data! <div style="color: #fa0;">&#9888; Unencrypted transmission. An attacker on the same network can intercept form data!</div>
<hr>
<h3>Software Update</h3> <h3>Software Update</h3>
<button type="button" onclick="U()">Manual OTA Update</button><br> <button type="button" onclick="U()">Manual OTA Update</button><br>
Enable ArduinoOTA: <input type="checkbox" name="AO"><br> Enable ArduinoOTA: <input type="checkbox" name="AO">
<hr>
<h3>Backup & Restore</h3> <h3>Backup & Restore</h3>
<a class="btn lnk" href="/presets.json?download" target="download-frame">Backup presets</a><br> <a class="btn lnk" id="bckcfg" href="/presets.json" download="presets">Backup presets</a><br>
<div>Restore presets<br><input type="file" name="data" accept=".json"> <input type="button" value="Upload" onclick="uploadFile(d.Sf.data,'/presets.json');"><br></div><br> <div>Restore presets<br><input type="file" name="data" accept=".json"> <button type="button" onclick="uploadFile(d.Sf.data,'/presets.json');">Upload</button><br></div><br>
<a class="btn lnk" href="/cfg.json?download" target="download-frame">Backup configuration</a><br> <a class="btn lnk" id="bckpresets" href="/cfg.json" download="cfg">Backup configuration</a><br>
<div>Restore configuration<br><input type="file" name="data2" accept=".json"> <input type="button" value="Upload" onclick="uploadFile(d.Sf.data2,'/cfg.json');"><br></div> <div>Restore configuration<br><input type="file" name="data2" accept=".json"> <button type="button" onclick="uploadFile(d.Sf.data2,'/cfg.json');">Upload</button><br></div>
<div style="color: #fa0;">&#9888; Restoring presets/configuration will OVERWRITE your current presets/configuration.<br> <div style="color: #fa0;">&#9888; Restoring presets/configuration will OVERWRITE your current presets/configuration.<br>
Incorrect configuration may require a factory reset or re-flashing of your ESP.</div> Incorrect configuration may require a factory reset or re-flashing of your ESP.</div>
For security reasons, passwords are not backed up. For security reasons, passwords are not backed up.
<hr>
<h3>About</h3> <h3>About</h3>
<a href="https://github.com/Aircoookie/WLED/" target="_blank">WLED</a> version ##VERSION##<!-- Autoreplaced from package.json --><br><br> <a href="https://github.com/Aircoookie/WLED/" target="_blank">WLED</a> version ##VERSION##<!-- Autoreplaced from package.json --><br><br>
<a href="https://github.com/Aircoookie/WLED/wiki/Contributors-and-credits" target="_blank">Contributors, dependencies and special thanks</a><br> <a href="https://github.com/Aircoookie/WLED/wiki/Contributors-and-credits" target="_blank">Contributors, dependencies and special thanks</a><br>
@ -89,8 +122,7 @@
<i>Licensed under the <a href="https://github.com/Aircoookie/WLED/blob/master/LICENSE" target="_blank">MIT license</a></i><br><br> <i>Licensed under the <a href="https://github.com/Aircoookie/WLED/blob/master/LICENSE" target="_blank">MIT license</a></i><br><br>
Server message: <span class="sip"> Response error! </span><hr> Server message: <span class="sip"> Response error! </span><hr>
<div id="toast"></div> <div id="toast"></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save & Reboot</button> <button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form> </form>
<iframe name=download-frame style='display:none;'></iframe>
</body> </body>
</html> </html>

View File

@ -1,14 +1,38 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"><head><meta name="viewport" content="width=500"><meta charset="utf-8"><title>Sync Settings</title> <html lang="en">
<head>
<meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<meta charset="utf-8">
<title>Sync Settings</title>
<script>var d=document; <script>var d=document;
var loc = false, locip;
function gId(s) function gId(s)
{ {
return d.getElementById(s); return d.getElementById(s);
} }
function H(){window.open("https://kno.wled.ge/interfaces/udp-notifier/");} function H(){window.open("https://kno.wled.ge/interfaces/udp-notifier/");}
function B(){window.open("/settings","_self");} function B(){window.open("/settings","_self");}
function adj(){if (d.Sf.DI.value == 6454) {if (d.Sf.DA.value == 1) d.Sf.DA.value = 0; if (d.Sf.EU.value == 1) d.Sf.EU.value = 0;} function adj(){if (d.Sf.DI.value == 6454) {if (d.Sf.EU.value == 1) d.Sf.EU.value = 0;}
else if (d.Sf.DI.value == 5568) {if (d.Sf.DA.value == 0) d.Sf.DA.value = 1; if (d.Sf.EU.value == 0) d.Sf.EU.value = 1;} } else if (d.Sf.DI.value == 5568) {if (d.Sf.DA.value == 0) d.Sf.DA.value = 1; if (d.Sf.EU.value == 0) d.Sf.EU.value = 1;} }
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
GetV();SetVal();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
}
function FC() function FC()
{ {
for(j=0;j<8;j++) for(j=0;j<8;j++)
@ -33,14 +57,27 @@ function GC()
} }
function SP(){var p = d.Sf.DI.value; gId("xp").style.display = (p > 0)?"none":"block"; if (p > 0) d.Sf.EP.value = p;} function SP(){var p = d.Sf.DI.value; gId("xp").style.display = (p > 0)?"none":"block"; if (p > 0) d.Sf.EP.value = p;}
function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568: d.Sf.DI.value = 5568; break; case 6454: d.Sf.DI.value = 6454; break; case 4048: d.Sf.DI.value = 4048; break; }; SP();FC();} function SetVal(){switch(parseInt(d.Sf.EP.value)){case 5568: d.Sf.DI.value = 5568; break; case 6454: d.Sf.DI.value = 6454; break; case 4048: d.Sf.DI.value = 4048; break; }; SP();FC();}
function S(){GetV();SetVal();} function S(){
function GetV(){var d=document;} if (window.location.protocol == "file:") {
loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
}
}
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=4';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
}
</script> </script>
<style>@import url("style.css");</style></head> <style>@import url("style.css");</style>
</head>
<body onload="S()"> <body onload="S()">
<form id="form_s" name="Sf" method="post" onsubmit="GC()"> <form id="form_s" name="Sf" method="post" onsubmit="GC()">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
</div>
<h2>Sync setup</h2> <h2>Sync setup</h2>
<h3>WLED Broadcast</h3> <h3>WLED Broadcast</h3>
UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required><br> UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required><br>
@ -48,8 +85,9 @@ UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required
<input name="GS" id="GS" type="number" style="display: none;"> <!-- hidden inputs for bitwise group checkboxes --> <input name="GS" id="GS" type="number" style="display: none;"> <!-- hidden inputs for bitwise group checkboxes -->
<input name="GR" id="GR" type="number" style="display: none;"> <input name="GR" id="GR" type="number" style="display: none;">
<table style="margin: 0 auto;"> <table style="margin: 0 auto;">
<tr><td colspan="9" style="text-align:center">Sync groups</td></tr>
<tr> <tr>
<td>Sync groups</td> <td></td>
<td>1</td> <td>1</td>
<td>2</td> <td>2</td>
<td>3</td> <td>3</td>
@ -82,14 +120,14 @@ UDP Port: <input name="UP" type="number" min="1" max="65535" class="d5" required
<td><input type="checkbox" id="R8" name="R8"></td> <td><input type="checkbox" id="R8" name="R8"></td>
</tr> </tr>
</table><br> </table><br>
Receive: <input type="checkbox" name="RB"> Brightness, <input type="checkbox" name="RC"> Color, and <input type="checkbox" name="RX"> Effects<br> Receive: <nowrap><input type="checkbox" name="RB">Brightness,</nowrap> <nowrap><input type="checkbox" name="RC">Color,</nowrap> <nowrap>and <input type="checkbox" name="RX">Effects</nowrap><br>
<input type="checkbox" name="SO"> Segment options, <input type="checkbox" name="SG"> bounds<br> <input type="checkbox" name="SO"> Segment options, <input type="checkbox" name="SG"> bounds<br>
Send notifications on direct change: <input type="checkbox" name="SD"><br> Send notifications on direct change: <input type="checkbox" name="SD"><br>
Send notifications on button press or IR: <input type="checkbox" name="SB"><br> Send notifications on button press or IR: <input type="checkbox" name="SB"><br>
Send Alexa notifications: <input type="checkbox" name="SA"><br> Send Alexa notifications: <input type="checkbox" name="SA"><br>
Send Philips Hue change notifications: <input type="checkbox" name="SH"><br> Send Philips Hue change notifications: <input type="checkbox" name="SH"><br>
Send Macro notifications: <input type="checkbox" name="SM"><br> Send Macro notifications: <input type="checkbox" name="SM"><br>
Send notifications twice: <input type="checkbox" name="S2"><br> UDP packet retransmissions: <input name="UR" type="number" min="0" max="30" class="d5" required><br><br>
<i>Reboot required to apply changes. </i> <i>Reboot required to apply changes. </i>
<h3>Instance List</h3> <h3>Instance List</h3>
Enable instance list: <input type="checkbox" name="NL"><br> Enable instance list: <input type="checkbox" name="NL"><br>
@ -109,7 +147,7 @@ Multicast: <input type="checkbox" name="EM"><br>
Start universe: <input name="EU" type="number" min="0" max="63999" required><br> Start universe: <input name="EU" type="number" min="0" max="63999" required><br>
<i>Reboot required.</i> Check out <a href="https://github.com/LedFx/LedFx" target="_blank">LedFx</a>!<br> <i>Reboot required.</i> Check out <a href="https://github.com/LedFx/LedFx" target="_blank">LedFx</a>!<br>
Skip out-of-sequence packets: <input type="checkbox" name="ES"><br> Skip out-of-sequence packets: <input type="checkbox" name="ES"><br>
DMX start address: <input name="DA" type="number" min="0" max="510" required><br> DMX start address: <input name="DA" type="number" min="1" max="510" required><br>
DMX mode: DMX mode:
<select name=DM> <select name=DM>
<option value=0>Disabled</option> <option value=0>Disabled</option>

View File

@ -2,31 +2,47 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta name="viewport" content="width=500"> <meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Time Settings</title> <title>Time Settings</title>
<script> <script>
var d=document; var d=document;
var loc = false, locip;
var el=false; var el=false;
var ms=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; var ms=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var cals = 'style="font-size:27px;margin-top:-6px;cursor:pointer"'; //hack as to not repeat CSS on all pages function H() { window.open("https://kno.wled.ge/features/settings/#time-settings"); }
function H() function B() { window.open("/settings","_self"); }
{ function gId(s) { return d.getElementById(s); }
window.open("https://kno.wled.ge/features/settings/#time-settings"); function gN(s) { return d.getElementsByName(s)[0]; }
} // https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function B() function loadJS(FILE_URL, async = true) {
{ let scE = d.createElement("script");
window.open("/settings","_self"); scE.setAttribute("src", FILE_URL);
} scE.setAttribute("type", "text/javascript");
function S() scE.setAttribute("async", async);
{ d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
BTa();GetV();updLoc();Cs();FC(); BTa();GetV();updLoc();Cs();FC();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
} }
function gId(s) function S() {
{ if (window.location.protocol == "file:") {
return d.getElementById(s); loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
} }
function gN(s) { }
return d.getElementsByName(s)[0]; var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=5';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
} }
function expand(o,i) function expand(o,i)
{ {
@ -34,27 +50,22 @@
t.style.display = t.style.display!=="none" ? "none" : ""; t.style.display = t.style.display!=="none" ? "none" : "";
o.innerHTML = t.style.display==="none" ? "&#128197;" : "&#x2715;"; o.innerHTML = t.style.display==="none" ? "&#128197;" : "&#x2715;";
} }
function Cs() function Cs() { gId("cac").style.display=(gN("OL").checked)?"block":"none"; }
{
gId("cac").style.display=(gN("OL").checked)?"block":"none";
}
function BTa() function BTa()
{ {
var ih="<tr><th>En.</th><th>Hour</th><th>Minute</th><th>Preset</th><th></th></tr>"; var ih="<thead><tr><th>En.</th><th>Hour</th><th>Minute</th><th>Preset</th><th></th></tr></thead>";
for (i=0;i<8;i++) { for (i=0;i<8;i++) {
ih+=`<tr><td><input name="W${i}" id="W${i}" type="hidden"><input id="W${i}0" type="checkbox"></td> ih+=`<tr><td><input name="W${i}" id="W${i}" type="hidden"><input id="W${i}0" type="checkbox"></td>
<td><input name="H${i}" class="xs" type="number" min="0" max="24"></td> <td><input name="H${i}" class="xs" type="number" min="0" max="24"></td>
<td><input name="N${i}" class="xs" type="number" min="0" max="59"></td> <td><input name="N${i}" class="xs" type="number" min="0" max="59"></td>
<td><input name="T${i}" class="s" type="number" min="0" max="250"></td> <td><input name="T${i}" class="s" type="number" min="0" max="250"></td>
<td><div id="CB${i}" onclick="expand(this,${i})" ${cals}>&#128467;</div></td></tr>`; <td><div id="CB${i}" onclick="expand(this,${i})" class="cal">&#128197;</div></td></tr>`;
ih+=`<tr><td colspan=5><div id="WD${i}" style="display:none;">Run on weekdays`; ih+=`<tr><td colspan=5><div id="WD${i}" style="display:none;background-color:#444;"><hr>Run on weekdays`;
ih+=`<table style="width:100%%;"><tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr><tr>` ih+=`<table><tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr><tr>`
for (j=1;j<8;j++) ih+=`<td><input id="W${i}${j}" type="checkbox"></td>`; for (j=1;j<8;j++) ih+=`<td><input id="W${i}${j}" type="checkbox"></td>`;
ih+=`</tr></table>from ih+=`</tr></table>from <select name="M${i}">`;
<select name="M${i}">`;
for (j=0;j<12;j++) ih+=`<option value="${j+1}">${ms[j]}</option>`; for (j=0;j<12;j++) ih+=`<option value="${j+1}">${ms[j]}</option>`;
ih+=`</select><input name="D${i}" class="xs" type="number" min="1" max="31"></input> to ih+=`</select><input name="D${i}" class="xs" type="number" min="1" max="31"></input> to <select name="P${i}">`;
<select name="P${i}">`;
for (j=0;j<12;j++) ih+=`<option value="${j+1}">${ms[j]}</option>`; for (j=0;j<12;j++) ih+=`<option value="${j+1}">${ms[j]}</option>`;
ih+=`</select><input name="E${i}" class="xs" type="number" min="1" max="31"></input> ih+=`</select><input name="E${i}" class="xs" type="number" min="1" max="31"></input>
<hr></div></td></tr>`; <hr></div></td></tr>`;
@ -63,16 +74,16 @@
<td>Sunrise<input name="H8" value="255" type="hidden"></td> <td>Sunrise<input name="H8" value="255" type="hidden"></td>
<td><input name="N8" class="xs" type="number" min="-59" max="59"></td> <td><input name="N8" class="xs" type="number" min="-59" max="59"></td>
<td><input name="T8" class="s" type="number" min="0" max="250"></td> <td><input name="T8" class="s" type="number" min="0" max="250"></td>
<td><div id="CB8" onclick="expand(this,8)" ${cals}>&#128467;</div></td></tr><tr><td colspan=5>`; <td><div id="CB8" onclick="expand(this,8)" class="cal">&#128197;</div></td></tr><tr><td colspan=5>`;
ih+=`<div id="WD8"style="display:none;"><table style="width:100%%;"><tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr><tr>`; ih+=`<div id="WD8" style="display:none;background-color:#444;"><hr><table><tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr><tr>`;
for (j=1;j<8;j++) ih+=`<td><input id="W8${j}" type="checkbox"></td>`; for (j=1;j<8;j++) ih+=`<td><input id="W8${j}" type="checkbox"></td>`;
ih+="</tr></table><hr></div></td></tr>"; ih+="</tr></table><hr></div></td></tr>";
ih+=`<tr><td><input name="W9" id="W9" type="hidden"><input id="W90" type="checkbox"></td> ih+=`<tr><td><input name="W9" id="W9" type="hidden"><input id="W90" type="checkbox"></td>
<td>Sunset<input name="H9" value="255" type="hidden"></td> <td>Sunset<input name="H9" value="255" type="hidden"></td>
<td><input name="N9" class="xs" type="number" min="-59" max="59"></td> <td><input name="N9" class="xs" type="number" min="-59" max="59"></td>
<td><input name="T9" class="s" type="number" min="0" max="250"></td> <td><input name="T9" class="s" type="number" min="0" max="250"></td>
<td><div id="CB9" onclick="expand(this,9)" ${cals}>&#128467;</div></td></tr><tr><td colspan=5>`; <td><div id="CB9" onclick="expand(this,9)" class="cal">&#128197;</div></td></tr><tr><td colspan=5>`;
ih+=`<div id="WD9" style="display:none;"><table style="width:100%%;"><tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr><tr>`; ih+=`<div id="WD9" style="display:none;background-color:#444;"><hr><table><tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr><tr>`;
for (j=1;j<8;j++) ih+=`<td><input id="W9${j}" type="checkbox"></td>`; for (j=1;j<8;j++) ih+=`<td><input id="W9${j}" type="checkbox"></td>`;
ih+="</tr></table><hr></div></td></tr>"; ih+="</tr></table><hr></div></td></tr>";
gId("TMT").innerHTML=ih; gId("TMT").innerHTML=ih;
@ -134,19 +145,15 @@
if (parseFloat(d.Sf.LT.value)<0) { d.Sf.LTR.value = "S"; d.Sf.LT.value = -1*parseFloat(d.Sf.LT.value); } else d.Sf.LTR.value = "N"; if (parseFloat(d.Sf.LT.value)<0) { d.Sf.LTR.value = "S"; d.Sf.LT.value = -1*parseFloat(d.Sf.LT.value); } else d.Sf.LTR.value = "N";
if (parseFloat(d.Sf.LN.value)<0) { d.Sf.LNR.value = "W"; d.Sf.LN.value = -1*parseFloat(d.Sf.LN.value); } else d.Sf.LNR.value = "E"; if (parseFloat(d.Sf.LN.value)<0) { d.Sf.LNR.value = "W"; d.Sf.LN.value = -1*parseFloat(d.Sf.LN.value); } else d.Sf.LNR.value = "E";
} }
function GetV()
{
//values injected by server while sending HTML
}
</script> </script>
<style> <style>@import url("style.css");</style>
@import url("style.css");
</style>
</head> </head>
<body onload="S()"> <body onload="S()">
<form id="form_s" name="Sf" method="post" onsubmit="Wd()"> <form id="form_s" name="Sf" method="post" onsubmit="Wd()">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save</button><hr>
</div>
<h2>Time setup</h2> <h2>Time setup</h2>
Get time from NTP server: <input type="checkbox" name="NT"><br> Get time from NTP server: <input type="checkbox" name="NT"><br>
<input type="text" name="NS" maxlength="32"><br> <input type="text" name="NS" maxlength="32"><br>
@ -175,6 +182,7 @@
<option value="19">NOVT (Novosibirsk)</option> <option value="19">NOVT (Novosibirsk)</option>
<option value="20">AKST/AKDT (Anchorage)</option> <option value="20">AKST/AKDT (Anchorage)</option>
<option value="21">MX-CST/CDT</option> <option value="21">MX-CST/CDT</option>
<option value="22">PKT (Pakistan)</option>
</select><br> </select><br>
UTC offset: <input name="UO" type="number" min="-65500" max="65500" required> seconds (max. 18 hours)<br> UTC offset: <input name="UO" type="number" min="-65500" max="65500" required> seconds (max. 18 hours)<br>
Current local time is <span class="times">unknown</span>.<br> Current local time is <span class="times">unknown</span>.<br>
@ -194,7 +202,7 @@
Countdown Mode: <input type="checkbox" name="CE"><br> Countdown Mode: <input type="checkbox" name="CE"><br>
Countdown Goal:<br> Countdown Goal:<br>
Date:&nbsp;<nowrap>20<input name="CY" class="xs" type="number" min="0" max="99" required>-<input name="CI" class="xs" type="number" min="1" max="12" required>-<input name="CD" class="xs" type="number" min="1" max="31" required></nowrap><br> Date:&nbsp;<nowrap>20<input name="CY" class="xs" type="number" min="0" max="99" required>-<input name="CI" class="xs" type="number" min="1" max="12" required>-<input name="CD" class="xs" type="number" min="1" max="31" required></nowrap><br>
Time: <nowrap><input name="CH" class="xs" type="number" min="0" max="23" required>:<input name="CM" class="xs" type="number" min="0" max="59" required>:<input name="CS" class="xs" type="number" min="0" max="59" required></nowrap><br> Time:&nbsp;<nowrap><input name="CH" class="xs" type="number" min="0" max="23" required>:<input name="CM" class="xs" type="number" min="0" max="59" required>:<input name="CS" class="xs" type="number" min="0" max="59" required></nowrap><br>
<h3>Macro presets</h3> <h3>Macro presets</h3>
<b>Macros have moved!</b><br> <b>Macros have moved!</b><br>
<i>Presets now also can be used as macros to save both JSON and HTTP API commands.<br> <i>Presets now also can be used as macros to save both JSON and HTTP API commands.<br>

View File

@ -3,10 +3,12 @@
<head lang="en"> <head lang="en">
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=500"> <meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<title>UI Settings</title> <title>UI Settings</title>
<script> <script>
var d = document; var d = document;
var initial_ds, initial_st; var loc = false, locip;
var initial_ds, initial_st, initial_su;
var sett = null; var sett = null;
var l = { var l = {
"comp":{ "comp":{
@ -21,6 +23,8 @@
"pcmbot": "Show bottom tab bar in PC mode", "pcmbot": "Show bottom tab bar in PC mode",
"pid": "Show preset IDs", "pid": "Show preset IDs",
"seglen": "Set segment length instead of stop LED", "seglen": "Set segment length instead of stop LED",
"segpwr": "Hide segment power &amp; brightness",
"segexp" : "Always expand first segment",
"css": "Enable custom CSS", "css": "Enable custom CSS",
"hdays": "Enable custom Holidays list" "hdays": "Enable custom Holidays list"
}, },
@ -38,10 +42,7 @@
} }
} }
}; };
function gId(s) function gId(s) { return d.getElementById(s); }
{
return d.getElementById(s);
}
function isObject(item) { function isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item)); return (item && typeof item === 'object' && !Array.isArray(item));
} }
@ -61,10 +62,10 @@
{ {
var x = gId("toast"); var x = gId("toast");
x.innerHTML = text; x.innerHTML = text;
x.className = error ? "error":"show"; x.classList.add(error ? "error":"show");
clearTimeout(timeout); clearTimeout(timeout);
x.style.animation = 'none'; x.style.animation = 'none';
timeout = setTimeout(function(){ x.className = x.className.replace("show", ""); }, 2900); timeout = setTimeout(function(){ x.classList.remove("show"); }, 2900);
} }
function addRec(s, path = "", label = null) function addRec(s, path = "", label = null)
{ {
@ -148,26 +149,56 @@
} }
} }
function Save() { function cLS()
SetLS(); {
if (d.Sf.DS.value != initial_ds || d.Sf.ST.checked != initial_st) d.Sf.submit(); localStorage.removeItem('wledP');
localStorage.removeItem('wledPmt');
localStorage.removeItem('wledPalx');
showToast("Cleared.");
} }
function S() function Save() {
{ SetLS();
if (d.Sf.DS.value != initial_ds || d.Sf.ST.checked != initial_st || d.Sf.SU.checked != initial_su) d.Sf.submit();
}
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
GetV(); GetV();
initial_ds = d.Sf.DS.value; initial_ds = d.Sf.DS.value;
initial_st = d.Sf.ST.checked; initial_st = d.Sf.ST.checked;
initial_su = d.Sf.SU.checked;
GetLS(); GetLS();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
} }
function H() function S()
{ {
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#user-interface-settings"); if (window.location.protocol == "file:") {
loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
} }
function B()
{
window.open("/settings","_self");
} }
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=3';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
}
function H() { window.open("https://kno.wled.ge/features/settings/#user-interface-settings"); }
function B() { window.open("/settings","_self"); }
function UI() function UI()
{ {
gId('idonthateyou').style.display = (gId('dm').checked) ? 'inline':'none'; gId('idonthateyou').style.display = (gId('dm').checked) ? 'inline':'none';
@ -202,21 +233,21 @@
fO.value = ''; fO.value = '';
return false; return false;
} }
function GetV(){var d=document;}
</script> </script>
<style>@import url("style.css");</style> <style>@import url("style.css");</style>
</head> </head>
<body onload="S()"> <body onload="S()">
<form id="form_s" name="Sf" method="post"> <form id="form_s" name="Sf" method="post">
<div style="position:sticky;top:0;background-color:#222;z-index:1;"> <div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="button" onclick="Save()">Save</button><br> <button type="button" onclick="B()">Back</button><button type="button" onclick="Save()">Save</button><br>
<span id="lssuc" style="color:green; display:none">&#10004; Local UI settings saved!</span> <span id="lssuc" style="color:green; display:none">&#10004; Local UI settings saved!</span>
<span id="lserr" style="color:red; display:none">&#9888; Could not access local storage. Make sure it is enabled in your browser.</span><hr> <span id="lserr" style="color:red; display:none">&#9888; Could not access local storage. Make sure it is enabled in your browser.</span><hr>
</div> </div>
<h2>Web Setup</h2> <h2>Web Setup</h2>
Server description: <input name="DS" maxlength="32"><br> Server description: <input type="text" name="DS" maxlength="32"><br>
Sync button toggles both send and receive: <input type="checkbox" name="ST"><br> Sync button toggles both send and receive: <input type="checkbox" name="ST"><br>
Enable simplified UI: <input type="checkbox" name="SU"><br>
<i>The following UI customization settings are unique both to the WLED device and this browser.<br> <i>The following UI customization settings are unique both to the WLED device and this browser.<br>
You will need to set them again if using a different browser, device or WLED IP address.<br> You will need to set them again if using a different browser, device or WLED IP address.<br>
Refresh the main UI to apply changes.</i><br> Refresh the main UI to apply changes.</i><br>
@ -228,12 +259,14 @@
<span class="l"></span>: <input type="checkbox" id="comp_pcmbot" class="agi cb"><br> <span class="l"></span>: <input type="checkbox" id="comp_pcmbot" class="agi cb"><br>
<span class="l"></span>: <input type="checkbox" id="comp_pid" class="agi cb"><br> <span class="l"></span>: <input type="checkbox" id="comp_pid" class="agi cb"><br>
<span class="l"></span>: <input type="checkbox" id="comp_seglen" class="agi cb"><br> <span class="l"></span>: <input type="checkbox" id="comp_seglen" class="agi cb"><br>
<span class="l"></span>: <input type="checkbox" id="comp_segpwr" class="agi cb"><br>
<span class="l"></span>: <input type="checkbox" id="comp_segexp" class="agi cb"><br>
I hate dark mode: <input type="checkbox" id="dm" onchange="UI()"><br> I hate dark mode: <input type="checkbox" id="dm" onchange="UI()"><br>
<span id="idonthateyou" style="display:none"><i>Why would you? </i>&#x1F97A;<br></span> <span id="idonthateyou" style="display:none"><i>Why would you? </i>&#x1F97A;<br></span>
<span class="l"></span>: <input type="number" min=0.0 max=1.0 step=0.01 id="theme_alpha_tab" class="agi"><br> <span class="l"></span>: <input type="number" min=0.0 max=1.0 step=0.01 id="theme_alpha_tab" class="agi"><br>
<span class="l"></span>: <input type="number" min=0.0 max=1.0 step=0.01 id="theme_alpha_bg" class="agi"><br> <span class="l"></span>: <input type="number" min=0.0 max=1.0 step=0.01 id="theme_alpha_bg" class="agi"><br>
<span class="l"></span>: <input id="theme_color_bg" maxlength="9" class="agi"><br> <span class="l"></span>: <input type="text" id="theme_color_bg" maxlength="9" class="agi"><br>
<span class="l">BG image URL</span>: <input id="theme_bg_url" class="agi" oninput="checkRandomBg()"><br> <span class="l">BG image URL</span>: <input type="text" id="theme_bg_url" class="agi" oninput="checkRandomBg()"><br>
<span class="l">Random BG image</span>: <input type="checkbox" id="theme_bg_random" class="agi cb" onchange="setRandomBg()"><br> <span class="l">Random BG image</span>: <input type="checkbox" id="theme_bg_random" class="agi cb" onchange="setRandomBg()"><br>
<input id="theme_base" class="agi" style="display:none"> <input id="theme_base" class="agi" style="display:none">
<span class="l"></span>: <input type="checkbox" id="comp_css" class="agi cb"><br> <span class="l"></span>: <input type="checkbox" id="comp_css" class="agi cb"><br>
@ -241,6 +274,7 @@
<span class="l"></span>: <input type="checkbox" id="comp_hdays" class="agi cb"><br> <span class="l"></span>: <input type="checkbox" id="comp_hdays" class="agi cb"><br>
<div id="holidays">Holidays: <input type="file" name="data2" accept=".json"> <input type="button" value="Upload" onclick="uploadFile(d.Sf.data2,'/holidays.json');"><br></div> <div id="holidays">Holidays: <input type="file" name="data2" accept=".json"> <input type="button" value="Upload" onclick="uploadFile(d.Sf.data2,'/holidays.json');"><br></div>
<div id="toast"></div> <div id="toast"></div>
<hr><button type="button" onclick="cLS()">Clear local storage</button>
<hr><button type="button" onclick="B()">Back</button><button type="button" onclick="Save()">Save</button> <hr><button type="button" onclick="B()">Back</button><button type="button" onclick="Save()">Save</button>
</form> </form>
</body> </body>

View File

@ -3,12 +3,12 @@
<head lang="en"> <head lang="en">
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=500"> <meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<title>Usermod Settings</title> <title>Usermod Settings</title>
<script> <script>
var d = document; var d = document;
var umCfg = {}; var umCfg = {};
var pins = [6,7,8,9,10,11]; var pins = [], pinO = [], owner;
var pinO = ["rsvd","rsvd","rsvd","rsvd","rsvd","rsvd"], owner;
var loc = false, locip; var loc = false, locip;
var urows; var urows;
var numM = 0; var numM = 0;
@ -16,6 +16,35 @@
function isO(i) { return (i && typeof i === 'object' && !Array.isArray(i)); } function isO(i) { return (i && typeof i === 'object' && !Array.isArray(i)); }
function H() { window.open("https://github.com/Aircoookie/WLED/wiki/Settings#usermod-settings"); } function H() { window.open("https://github.com/Aircoookie/WLED/wiki/Settings#usermod-settings"); }
function B() { window.open("/settings","_self"); } function B() { window.open("/settings","_self"); }
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
d.um_p = [];
d.rsvd = [];
d.ro_pins = [];
d.max_gpio = 39;
GetV();
for (let k=0; k<d.rsvd.length; k++) { pins.push(d.rsvd[k]); pinO.push("rsvd"); }
if (d.um_p[0]==-1) d.um_p.shift();
d.Sf.SDA.max = d.max_gpio;
d.Sf.SCL.max = d.max_gpio;
d.Sf.MOSI.max = d.max_gpio;
d.Sf.SCLK.max = d.max_gpio;
d.Sf.MISO.max = d.max_gpio;
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
}
function S() { function S() {
if (window.location.protocol == "file:") { if (window.location.protocol == "file:") {
loc = true; loc = true;
@ -25,9 +54,8 @@
localStorage.setItem('locIp', locip); localStorage.setItem('locIp', locip);
} }
} }
GetV(); ldS();
if (numM > 0 || locip) ldS(); if (!numM) gId("um").innerHTML = "No Usermods installed.";
else gId("um").innerHTML = "No Usermods installed.";
} }
// https://stackoverflow.com/questions/3885817/how-do-i-check-that-a-number-is-float-or-integer // https://stackoverflow.com/questions/3885817/how-do-i-check-that-a-number-is-float-or-integer
function isF(n) { return n === +n && n !== (n|0); } function isF(n) { return n === +n && n !== (n|0); }
@ -37,7 +65,22 @@
if (o.type=="number" && n.substr(0,3)=="pin") { if (o.type=="number" && n.substr(0,3)=="pin") {
for (var i=0; i<pins.length; i++) { for (var i=0; i<pins.length; i++) {
if (k==pinO[i]) continue; if (k==pinO[i]) continue;
if (o.value==pins[i] || o.value<-1 || o.value>39) { o.style.color="red"; break; } else o.style.color=o.value>33?"orange":"#fff"; if (o.value==pins[i] && pinO[i]==="if") { o.style.color="lime"; break; }
if (o.value==pins[i] || o.value<-1 || o.value>d.max_gpio) { o.style.color="red"; break; } else o.style.color=d.ro_gpio.some((e)=>e==parseInt(o.value,10))?"orange":"#fff";
}
} else {
switch (o.name) {
case "SDA": break;
case "SCL": break;
case "MOSI": break;
case "SCLK": break;
case "MISO": break;
default: return;
}
for (var i=0; i<pins.length; i++) {
//if (k==pinO[i]) continue; // same owner
if (o.value==pins[i] && pinO[i]==="if") { o.style.color="tomato"; break; }
if (o.value==pins[i] || o.value<-1 || o.value>d.max_gpio) { o.style.color="red"; break; } else o.style.color=d.ro_gpio.some((e)=>e==parseInt(o.value,10))?"orange":"#fff";
} }
} }
} }
@ -63,6 +106,7 @@
} }
function addField(k,f,o,a=false) { //key, field, (sub)object, isArray function addField(k,f,o,a=false) { //key, field, (sub)object, isArray
if (isO(o)) { if (isO(o)) {
urows += '<hr style="width:260px">';
for (const [s,v] of Object.entries(o)) { for (const [s,v] of Object.entries(o)) {
// possibility to nest objects (only 1 level) // possibility to nest objects (only 1 level)
if (f!=='unknown' && !k.includes(":")) addField(k+":"+f,s,v); if (f!=='unknown' && !k.includes(":")) addField(k+":"+f,s,v);
@ -81,10 +125,10 @@
case "number": case "number":
c = `value="${o}"`; c = `value="${o}"`;
if (f.substr(-3)==="pin") { if (f.substr(-3)==="pin") {
c += ' max="39" min="-1" style="width:40px;"'; c += ` max="${d.max_gpio}" min="-1" class="s"`;
t = "int"; t = "int";
} else { } else {
c += ' step="any" style="width:100px;"'; c += ' step="any" class="xxl"';
} }
break; break;
default: default:
@ -99,6 +143,49 @@
urows += `<input type="${t==="int"?"number":t}" name="${k}:${f}${a?"[]":""}" ${c} oninput="check(this,'${k.substr(k.indexOf(":")+1)}')"><br>`; urows += `<input type="${t==="int"?"number":t}" name="${k}:${f}${a?"[]":""}" ${c} oninput="check(this,'${k.substr(k.indexOf(":")+1)}')"><br>`;
} }
} }
// 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 sel;
}
return null;
}
function addOption(sel,txt,val) {
if (sel===null) return; // select object missing
let opt = d.createElement("option");
opt.value = val;
opt.text = txt;
sel.appendChild(opt);
for (let i=0; i<sel.childNodes.length; i++) {
let c = sel.childNodes[i];
if (c.value == sel.dataset.val) sel.selectedIndex = i;
}
}
// https://stackoverflow.com/questions/26440494/insert-text-after-this-input-element-with-javascript
function addInfo(name,el,txt) {
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);
}
// load settings and insert values into DOM
function ldS() { function ldS() {
var url = (loc?`http://${locip}`:'') + '/cfg.json'; var url = (loc?`http://${locip}`:'') + '/cfg.json';
fetch(url, { fetch(url, {
@ -120,22 +207,20 @@
} }
if (urows==="") urows = "Usermods configuration not found.<br>Press <i>Save</i> to initialize defaults."; if (urows==="") urows = "Usermods configuration not found.<br>Press <i>Save</i> to initialize defaults.";
gId("um").innerHTML = urows; gId("um").innerHTML = urows;
var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=8';
loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
}) })
.catch(function (error) { .catch((error)=>{
gId('lserr').style.display = "inline" gId('lserr').style.display = "inline";
console.log(error); console.log(error);
}); });
} }
function svS(e) { function svS(e) {
e.preventDefault(); e.preventDefault();
console.log(d.Sf);
if (d.Sf.checkValidity()) d.Sf.submit(); //https://stackoverflow.com/q/37323914 if (d.Sf.checkValidity()) d.Sf.submit(); //https://stackoverflow.com/q/37323914
} }
function GetV() {}
</script> </script>
<style> <style>@import url("style.css");</style>
@import url("style.css");
</style>
</head> </head>
<body onload="S()"> <body onload="S()">
@ -147,6 +232,16 @@
<span id="lserr" style="color:red; display:none">&#9888; Could not load configuration.</span><hr> <span id="lserr" style="color:red; display:none">&#9888; Could not load configuration.</span><hr>
</div> </div>
<h2>Usermod Setup</h2> <h2>Usermod Setup</h2>
Global I<sup>2</sup>C GPIOs (HW)<br>
<i style="color: orange;">(only changable on ESP32, change requires reboot!)</i><br>
SDA:<input type="number" min="-1" max="48" name="SDA" onchange="check(this,'if')" class="s" placeholder="SDA">
SCL:<input type="number" min="-1" max="48" name="SCL" onchange="check(this,'if')" class="s" placeholder="SCL">
<hr style="width:260px">
Global SPI GPIOs (HW)<br>
<i style="color: orange;">(only changable on ESP32, change requires reboot!)</i><br>
MOSI:<input type="number" min="-1" max="48" name="MOSI" onchange="check(this,'if')" class="s" placeholder="MOSI">
MISO:<input type="number" min="-1" max="48" name="MISO" onchange="check(this,'if')" class="s" placeholder="MISO">
SCLK:<input type="number" min="-1" max="48" name="SCLK" onchange="check(this,'if')" class="s" placeholder="SCLK">
<div id="um">Loading settings...</div> <div id="um">Loading settings...</div>
<hr><button type="button" onclick="B()">Back</button><button type="submit">Save</button> <hr><button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form> </form>

View File

@ -3,32 +3,55 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=500"> <meta name="viewport" content="width=500">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
<title>WiFi Settings</title> <title>WiFi Settings</title>
<script> <script>
function H() var d=document;
{ var loc = false, locip;
window.open("https://github.com/Aircoookie/WLED/wiki/Settings#wifi-settings"); function H(){window.open("https://kno.wled.ge/features/settings/#wifi-settings");}
function B(){window.open("/settings","_self");}
// https://www.educative.io/edpresso/how-to-dynamically-load-a-js-file-in-javascript
function loadJS(FILE_URL, async = true) {
let scE = d.createElement("script");
scE.setAttribute("src", FILE_URL);
scE.setAttribute("type", "text/javascript");
scE.setAttribute("async", async);
d.body.appendChild(scE);
// success event
scE.addEventListener("load", () => {
//console.log("File loaded");
GetV();
});
// error event
scE.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
alert("Loading of configuration script failed.\nIncomplete page data!");
});
} }
function B() function S() {
{ if (window.location.protocol == "file:") {
window.open("/settings","_self"); loc = true;
locip = localStorage.getItem('locIp');
if (!locip) {
locip = prompt("File Mode. Please enter WLED IP!");
localStorage.setItem('locIp', locip);
} }
function GetV() }
{ var url = (loc?`http://${locip}`:'') + '/settings/s.js?p=1';
//values injected by server while sending HTML loadJS(url, false); // If we set async false, file is loaded and executed, then next statement is processed
} }
</script> </script>
<style> <style>@import url("style.css");</style>
@import url("style.css");
</style>
</head> </head>
<body onload="GetV()"> <body onload="S()">
<form id="form_s" name="Sf" method="post"> <form id="form_s" name="Sf" method="post">
<div class="toprow">
<div class="helpB"><button type="button" onclick="H()">?</button></div> <div class="helpB"><button type="button" onclick="H()">?</button></div>
<button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button><hr> <button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button><hr>
</div>
<h2>WiFi setup</h2> <h2>WiFi setup</h2>
<h3>Connect to existing network</h3> <h3>Connect to existing network</h3>
Network name (SSID, empty to not connect): <br><input name="CS" maxlength="32"><br> Network name (SSID, empty to not connect): <br><input type="text" name="CS" maxlength="32"><br>
Network password: <br> <input type="password" name="CP" maxlength="63"><br> Network password: <br> <input type="password" name="CP" maxlength="63"><br>
Static IP (leave at 0.0.0.0 for DHCP):<br> Static IP (leave at 0.0.0.0 for DHCP):<br>
<input name="I0" type="number" class="s" min="0" max="255" required> . <input name="I0" type="number" class="s" min="0" max="255" required> .
@ -46,10 +69,10 @@
<input name="S2" type="number" class="s" min="0" max="255" required> . <input name="S2" type="number" class="s" min="0" max="255" required> .
<input name="S3" type="number" class="s" min="0" max="255" required><br> <input name="S3" type="number" class="s" min="0" max="255" required><br>
mDNS address (leave empty for no mDNS):<br/> mDNS address (leave empty for no mDNS):<br/>
http:// <input name="CM" maxlength="32"> .local<br> http:// <input type="text" name="CM" maxlength="32"> .local<br>
Client IP: <span class="sip"> Not connected </span> <br> Client IP: <span class="sip"> Not connected </span> <br>
<h3>Configure Access Point</h3> <h3>Configure Access Point</h3>
AP SSID (leave empty for no AP):<br> <input name="AS" maxlength="32"><br> AP SSID (leave empty for no AP):<br> <input type="text" name="AS" maxlength="32"><br>
Hide AP name: <input type="checkbox" name="AH"><br> Hide AP name: <input type="checkbox" name="AH"><br>
AP password (leave empty for open):<br> <input type="password" name="AP" maxlength="63" pattern="(.{8,63})|()" title="Empty or min. 8 characters"><br> AP password (leave empty for open):<br> <input type="password" name="AP" maxlength="63" pattern="(.{8,63})|()" title="Empty or min. 8 characters"><br>
Access Point WiFi channel: <input name="AC" type="number" class="xs" min="1" max="13" required><br> Access Point WiFi channel: <input name="AC" type="number" class="xs" min="1" max="13" required><br>
@ -75,7 +98,8 @@
<option value="5">TwilightLord-ESP32</option> <option value="5">TwilightLord-ESP32</option>
<option value="3">WESP32</option> <option value="3">WESP32</option>
<option value="1">WT32-ETH01</option> <option value="1">WT32-ETH01</option>
</select><br><br></div> </select><br><br>
</div>
<hr> <hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button> <button type="button" onclick="B()">Back</button><button type="submit">Save & Connect</button>
</form> </form>

933
wled00/data/simple.css Normal file
View File

@ -0,0 +1,933 @@
@font-face {
font-family: "WIcons";
src: url(data:font/woff2;charset=utf-8;base64,d09GMgABAAAAAAnUAAsAAAAAE1AAAAmFAAGZmgAAAAAAAAAAAAAAAAAAAAAAAAAABmAAgXwRCAqcYJZIATYCJANwCzoABCAFgwYHIBs7D8iOwzgm3MXMnzZCktnjcbN+QlJLaJ3ulULplpW6UqWioeS91Jye0jUlJwZr5nTdE3LntdPvAg+ft/fbsLsGlNLuhlmQjKi7NPDEIgwTmP//a6mdl+SHUBhEIdHFxak7s4E/yzhJSjC7BQQLfDwopF/i6aqSElEFDXx8ZVWjy3rym4N6FlZQ4hu+nXsGIDMQF3gAxa14AgArtVMhfkgjfEAbiChwuSIwEUCmudPhiQdT6rvIjLSRZEwDhF9BIsooI53TIRIoIUD8kyNZI7UjAyMrR/aM/DwaOpozah9LGCsY2zN2YOzs2L3xqeNp4zXjq8bXT/hMBLj/53YDAIS+7u668n3H+HRPdZd1u3TzdRZdVMTfIl5HfKgd1b7Svqd9W9uprdP8QTOmeaz5TPORJlDDjHVjG0ANMQYsmRrKlmpyqV7kubIQC2GSIkFS+MneCJ48JJFVChQfuwKMp2yU9pmq1VKUR6ret0Gp0SjVYRRF+Xj7+OiUSk/GIzu1miHZWx+g8Y1RUktPmqIitRTXVNzzCtuFPKcH0zRBG+Y9/CnhBa20v5oHfsEUMgXMPEfO5ZcJx0FIPiVywgjb6MIuV+oZ4v2kk6/znIxDKrguM22y+bW8wUGqi7aL8fQJzwnCj8tIppdI9bYDSVJVCQInipW0HbtclcT7vCyLmXaSVrQSNMybaJJBh2PiXrXbgd6AbqecdDTO9EQEIeW0VPWQcdQ8ltPOEu+76q2IxUToJeWpfjQiHHH5AsADLj1bHgQxXsUoHfKYbg+CxCxC69eHcOvWheJ1l6b0nD7jG+bSA1dCZVxmw8ZJ/IYtxPtbJxlpQ/LGjSq00TmdNIZxrGel+y+rZJro+nUh3PrNIGwK6WrXNMV2xTeRWHSjScktLJfe1rc7spyvk3b6V4k48Sr3Am1Pv/QifhsI2uMvc863OiQQRNoedpPfHnSwcete+aDEE67cKzTgBlQgjpjgTDnJtGnX2qbmXJ6FOBLZ7wsr+JZzYnbjdbkCuEfU0HvlwqbtUgJ7zRXFNJsvSxlwz2WYta4xjri/fsulnnFVPyonpP0RL5oVNKkkfElG4csTDNAsgzC38G7gSKVgSZ7m/cEvKALmxKz//u7h6egHF7MrH4jJp/Zx4q32a8T71xnHVRCGlfFZNttd2FcUaay6e9PkhucyR0oPu1z1z/DB+8wixAFdMU1gnmB4xAw68pwHcWjlFrBnXxLjj63UGgvNGVGAJFzxFw+Womn7MAibVbu6leHRB5sc10fLtbrdr/JqV6Yr+ovwFtRHE7M4zG90qNB6YREoo51kFJabq3NeHVKdef/hsMFFSpt5m8XmJqDDAnR0c418mxmxrQzQuyPnspRwfAYkpthzr7gST1xNSf4WtBMM9DQT19uL+gb47gFLP3cT08F8I4dZxJl41Gsx9WHzLBOHzWjRS9NLCOUBCFQ+uGhB/V7ZzUwKESTmDriJ+UecdD/bFXFMLLsjgiAt4pp7ulpxb2tzE8I8xhyHODBK3SGg6QP12BiP3YMw2rDFtWUDXL+esnv3H9QxqfmbDnbMLjGUFpqqZbnWSg0lhWv9wU35qTHqP9zqUrL7kqKj8YjZzg01pb9+yQ8sXZpYxKGiFJTNsIwwpyR44gEOnV/+ennFdHD/2lQ3uS5y1qzIztXUNPE6odYJ0PqUiWJtgKGKMILY60dxeYynbb+sFKKqNn0Wz2rLtMbBQWPnYtmJa4WqFRob/9mmuycQVv7ifCNvXrlhzgDLDvAGA+8H5xjK948cDet+FaXfS+Lko/Wt+vScqarq6kZTbk4NaKqpObkEEpsac9L1rRNXJgPbrWyDdYje6tBQAztkbYC0wDe4UnNipmnZtInu/ujf6Kf7ve112Huf92Ev/7enB/+nP7pbrPiQJZbi0jCSpoN9UNPTkj7JMwpbWgopAbhtbOWkytAF3K+/qo0SASNW2G2bLfnshpB4a9dmz7/Hx//dc3OXNZ46YRyXUV2dYRsD97qKL79qazu+vSI1vPXT7375bWSGocBofD2eIRzJ0cMC0tenwQ0gfvuSdvd14f1uEooLPE3JJHL6uCd/n5n8d35UOKPn6nhr8kyrV3ad3nz2iTiNL414EnefL/JGLlWZtZWaqoEh4xSjvsGb/6m9raFlsLm4uHkQWlv7T/weZzjHHe7xZiUzpJ5WAWBLDNwRKxwRYnFoXGxcaKxN6DR8BNn2o9Nqmmutvra5TnIjXMBlmIFZ3yPYX3Mt9v5mmHuwYvvxPverL9eSvszXNjUXrkbqcGOVW2bEbDGKi3MLVTWzzWHF54Bu/2rA1qko6l9fFgVbBurfVBWFFlVW1ugxOwcs+8W//FcUZJieLl9WXA8eGL5crB7fhOMyxl8bjQWGjB1bW/ok6Ucqensr7F8H7utsmdqoHmz99rvyeE/Pz7u64mvVXLjyY8v8j5XhZeH3aPX75dpiO5eN/OzwcG7zkflt/sd5e7YcqbOowfRg22R5585at2vXX87W1Y0gQ079497eYT1EkyoEqMYABmHd8QvKGrRG6bJYTDCCZYGEWcm5G1jXM2i54Y9WtiBuklP57YtBZMAWlu2fYzDM7Q+5FmxKS3Oz5jwK6IactbWPowuQgNyHluKlaw9wnbOmtuajo/VSw9FrBSRwMcuUV2ZwFhh6s7hsqriWCsgA2s3nFcri4I7O+asxwxZbtLL03E9bhcR6Yz9mIbF0U96K0xGA7bx9y+l2//73j+H2i0EGd27uAVNI/WhCYuWqIDaYxads0lcVFV+dOlHmBx/qO7c6/uZX0tReUtJQv64y3adAvX6xDezAX/8Wm8Cgh/95O9OxsNCYnsXWQ+7pCz8/NMZ57ZAIGEdTw+ap8V+I3NUVe375wiv+lccqj172X7Yw5gJAUQGYPQ6QyxRfgeC+Qc5WnAMCAHFv6TJtet3pn/83b4YCAIBv35ofpTRyt5PjZEwT8KYAEQK8nFgBcE/yUwn2oqHSBKoEG7KZQLMpjo5uha/PI2yuBWOCTSDZajpqQ68+Za18jgGgYMT8nBhjKcFrKCYF6yKSZRLF5tR5YKhUzzNWM52mBvuPMiL7xPx4UaRgFiJZAVFscZ2HUIhUPcEaH5WWDvvmvdPfl5KaCvO8o1+fFCBb6hvuLz8lMROwfjPN8iar90RCCiRCJr3ugqHf6LqgUYYs5hzvu9tMIOUr/xpvRsNVvdZ/p+mB8n7V2Spo0T+aRhPpNhsNFOqxoE2u0suqTipgx58IJA0AAAA=) format('woff');
}
:root {
--c-1: #111;
--c-f: #fff;
--c-2: #222;
--c-3: #333;
--c-4: #444;
--c-5: #555;
--c-6: #666;
--c-8: #888;
--c-b: #bbb;
--c-c: #ccc;
--c-e: #eee;
--c-d: #ddd;
--c-r: #e42;
--c-g: #4e2;
--c-l: #48a;
--t-b: 0.5;
--c-o: rgba(34, 34, 34, 0.9);
--c-tb : rgba(34, 34, 34, var(--t-b));
--c-tba: rgba(102, 102, 102, var(--t-b));
--c-tbh: rgba(51, 51, 51, var(--t-b));
/*following are internal*/
--th: 70px;
--tp: 70px;
--bh: 63px;
--tbp: 14px 8px 10px;
--bbp: 9px 0 7px 0;
--bhd: none;
--bmt: 0px;
}
html {
touch-action: manipulation;
}
body {
margin: 0;
background-color: var(--c-1);
font-family: Helvetica, Verdana, sans-serif;
font-size: 17px;
color: var(--c-f);
text-align: center;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
scrollbar-width: 6px;
scrollbar-color: var(--c-sb) transparent;
}
html,
body {
height: 100%;
width: 100%;
position: fixed;
overscroll-behavior: none;
}
#bg {
height: 100vh;
width: 100vw;
position: fixed;
z-index: -10;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
opacity: 0;
transition: opacity 2s;
}
p {
margin: 10px 0 2px 0;
}
a, p, a:visited {
color: var(--c-d);
}
a, a:visited {
text-decoration: none;
}
button {
outline: none;
cursor: pointer;
background-color: transparent;
border: none;
transition: color 0.3s, background-color 0.3s;
font-size: 19px;
color: var(--c-c);
min-width: 40px;
min-height: 40px;
}
button:hover {
background: var(--c-4);
}
.label {
margin: 0;
padding: 6px 0 0;
}
#namelabel {
position: fixed;
bottom: calc(var(--bh) + 6px);
right: 4px;
color: var(--c-6);
cursor: pointer;
writing-mode: vertical-rl;
}
.wrapper {
position: fixed;
top: 0;
left: 0;
right: 0;
background: var(--c-tb);
z-index: 1;
}
.center {
margin: 0 auto;
width: 320px;
}
.icons {
font-family: 'WIcons';
font-style: normal;
font-size: 24px;
line-height: 1;
display: inline-block;
margin: -2px 0 4px 0;
text-shadow: -1px -1px 0 var(--c-3), 1px -1px 0 var(--c-3), -1px 1px 0 var(--c-3), 1px 1px 0 var(--c-3);
}
.huge {
font-size: 42px;
}
.infot {
table-layout: fixed;
width: 100%;
}
.keytd {
text-align: left;
padding-bottom: 8px;
}
.valtd {
text-align: right;
padding-bottom: 8px;
}
.valtd i {
font-size: small;
}
.slider-icon
{
transform: translate(4px,3px);
color: var(--c-d);
}
.il {
display: inline-block;
vertical-align: middle;
}
.tab {
background-color: transparent;
color: var(--c-d);
}
.tab button {
background-color: transparent;
float: left;
border: none;
transition: color 0.3s, background-color 0.3s;
font-size: 17px;
color: var(--c-c);
min-width: 44px;
}
.top button {
padding: var(--tbp);
margin: 0;
}
.tab button:hover {
background-color: var(--c-tbh);
color: var(--c-e);
}
.tab button.active {
background-color: var(--c-tba) !important;
color: var(--c-f);
}
.active {
background-color: var(--c-6) !important;
color: var(--c-f);
}
.container {
width: 100%;
height: calc(100% - var(--tp) - var(--bh));
margin-top: var(--tp);
overscroll-behavior: none;
}
.tabcontent {
position: relative;
width: 100%;
box-sizing: border-box;
border: 0px;
overflow: auto;
height: 100%;
overscroll-behavior: none;
}
.smooth { transition: transform calc(var(--f, 1)*.5s) ease-out }
.tab-label {
margin: 0 0 -5px 0;
padding-bottom: 4px;
}
.overlay {
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
background-color: var(--c-3);
font-size: 24px;
display: flex;
align-items: center;
justify-content: center;
z-index: 11;
opacity: 0.95;
transition: 0.7s;
pointer-events: none;
}
#toast {
opacity: 0;
background-color: var(--c-5);
max-width: 90%;
color: var(--c-f);
text-align: center;
border-radius: 5px;
padding: 16px;
position: fixed;
z-index: 5;
left: 50%;
transform: translateX(-50%);
bottom: calc(var(--bh) + 22px);
font-size: 17px;
pointer-events: none;
}
#toast.show {
opacity: 1;
animation: fadein 0.5s, fadein 0.5s 2.5s reverse;
}
#toast.error {
opacity: 1;
background-color: #b21;
animation: fadein 0.5s;
}
.modal {
position:fixed;
left: 0px;
bottom: 0px;
right: 0px;
top: calc(var(--th) - 1px);
background-color: var(--c-o);
transform: translateY(100%);
transition: transform 0.4s;
padding: 8px;
font-size: 20px;
overflow: auto;
}
#info, #nodes {
z-index: 3;
}
#rover {
z-index: 2;
}
#ndlt {
margin: 12px 0;
}
#roverstar {
position: fixed;
top: calc(var(--th) + 5px);
left: 1px;
display: none;
cursor: pointer;
}
#connind {
position: fixed;
bottom: calc(var(--bh) + 5px);
left: 4px;
padding: 5px;
border-radius: 5px;
background-color: #a90;
z-index: -2;
}
#imgw {
display: inline-block;
margin: 8px;
}
#kv, #kn {
/*max-width: 490px;*/
display: inline-block;
}
#info table, #nodes table {
table-layout: fixed;
width: 100%;
}
#info td, #nodes td {
padding-bottom: 8px;
}
#info .btn {
margin: 5px;
}
#info table .btn, #nodes table .btn {
margin: 0;
width: 180px;
}
#info div, #nodes div {
width: 490px;
margin: 0 auto;
}
#kn td {
padding-bottom: 12px;
}
#heart {
transition: color 0.9s;
font-size: 16px;
color: #f00;
}
img {
max-width: 100%;
max-height: 100%;
}
.wi {
image-rendering: pixelated;
image-rendering: crisp-edges;
width: 210px;
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: calc(var(--bh) + 22px); opacity: 1;}
}
.sliderwrap {
height: 30px;
width: 250px;
position: relative;
margin: 4px 0;
}
#Colors .sliderwrap {
width: 260px;
margin: 10px 0 0;
}
.sliderdisplay {
content:'';
position: absolute;
top: 10px; left: 8px; right: 8px;
height: 8px;
background: var(--c-4);
border-radius: 16px;
pointer-events: none;
z-index: -1;
}
#Colors .sliderdisplay {
height: 28px;
top: 0; bottom: 0;
left: 0; right: 0;
/*border: 1px solid var(--c-b);*/
}
#rwrap .sliderdisplay { background: linear-gradient(90deg, #000 0%, #f00); }
#gwrap .sliderdisplay { background: linear-gradient(90deg, #000 0%, #0f0); }
#bwrap .sliderdisplay { background: linear-gradient(90deg, #000 0%, #00f); }
#wwrap .sliderdisplay { background: linear-gradient(90deg, #000 0%, #fff); }
#kwrap .sliderdisplay { background: linear-gradient(90deg, #ff8f1f 0%, #fff 50%, #cbdbff); }
#wbal .sliderdisplay { background: linear-gradient(90deg, #ff8f1f 0%, #fff 50%, #d4e0ff); }
.sliderbubble {
width: 24px;
position: relative;
display: inline-block;
border-radius: 10px;
background: var(--c-3);
color: var(--c-f);
padding: 4px 4px 2px;
font-size: 14px;
right: 3px;
transition: visibility 0.25s ease, opacity 0.25s ease;
opacity: 0;
visibility: hidden;
}
output.sliderbubbleshow {
visibility: visible;
opacity: 1;
}
.hidden {
display: none;
}
input[type=range] {
-webkit-appearance: none;
width: 100%;
padding: 0;
margin: 0;
background-color: transparent;
cursor: pointer;
}
#Colors input[type=range] {
width: 252px;
margin: 0;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 30px;
cursor: pointer;
background: transparent;
}
input[type=range]::-webkit-slider-thumb {
border: 2px solid #000;
height: 20px;
width: 20px;
border-radius: 50%;
background: var(--c-f);
cursor: pointer;
-webkit-appearance: none;
margin-top: 4px;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 30px;
background-color: var(--c-0);
}
input[type=range]::-moz-range-thumb {
border: 2px solid var(--c-3);
height: 20px;
width: 20px;
border-radius: 50%;
background: var(--c-f);
transform: translateY(5px);
}
#Colors input[type=range]::-webkit-slider-thumb {
border: 2px solid #000;
}
#Colors input[type=range]::-moz-range-thumb {
border: 2px solid var(--c-1);
}
#Presets .list {
max-height: 215px;
overflow-y: scroll;
overflow-x: hidden;
width: 280px;
margin: 0 0 0 20px;
-ms-overflow-style: none;
scrollbar-width: none; /* Firefox */
}
/* Hide scrollbar for Chrome, Safari and Opera */
#Presets .list::-webkit-scrollbar {
display: none;
}
#Segments .sliderwrap{
width: 225px;
}
#picker, #rgbwrap, #kwrap, #vwrap, #wwrap, #wbal {
display: none;
}
.hd {
display: var(--bhd);
}
#briwrap {
float: right;
margin-top: var(--bmt);
}
#picker {
width: 260px;
}
#picker, #csl, #segcont {
margin: 10px auto 0;
}
.btn {
margin: 10px auto 0;
width: 280px;
font-size: 19px;
background-color: var(--c-3);
color: var(--c-d);
cursor: pointer;
border: 1px solid var(--c-3);
border-radius: 25px;
transition-duration: 0.3s;
-webkit-backface-visibility: hidden;
-webkit-transform:translate3d(0,0,0);
overflow: clip;
text-overflow: clip;
min-height: 40px;
line-height: 40px;
}
.btn:hover {
background-color: var(--c-4);
border: 1px solid var(--c-4);
}
.btn-xs {
width: 42px;
height: 42px;
margin: 4px;
padding: 0;
}
#fxBtn, #palBtn {
background-color: var(--c-2);
border: 1px solid var(--c-2);
}
#fxBtn:hover, #palBtn:hover {
background-color: var(--c-3);
border: 1px solid var(--c-3);
}
.btn-icon {
margin-right: 8px;
vertical-align: middle;
display: inline-block;
}
.qcs {
margin: 2px;
border-radius: 14px;
display: inline-block;
width: 28px;
height: 28px;
line-height: 28px;}
.qcsb {
width: 26px;
height: 26px;
line-height: 26px;
border: 1px solid var(--c-f);
}
option {
background-color: var(--c-3);
color: var(--c-f);
}
input[type=number], input[type=text] {
background: var(--c-3);
color: var(--c-f);
border: 0px solid var(--c-f);
border-radius: 5px;
padding: 8px;
margin: 6px 6px 6px 0;
font-size: 19px;
transition: background-color 0.2s;
outline: none;
width: 50px;
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
}
::selection {
background: var(--c-b);
}
input[type=number]:focus, input[type=text]:focus {
background: var(--c-6);
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}
.pid {
position: absolute;
top: 0px;
left: 0px;
padding: 12px 0px 0px 12px;
font-size: 16px;
width: 20px;
text-align: center;
color: var(--c-b);
}
.xxs {
border: 2px solid var(--c-e) !important;
width: 44px;
height: 44px;
margin: 5px;
padding: 0;
}
.xxs-w {
border-width: 4px !important;
margin: 2px;
width: 50px;
height: 50px;
padding: 0;
}
.qcs, .xxs {
text-shadow: -1px -1px 0 var(--c-6), 1px -1px 0 var(--c-6), -1px 1px 0 var(--c-6), 1px 1px 0 var(--c-6);
}
.psts {
color: var(--c-f);
margin: 6px;
}
.pwr {
color: var(--c-6);
cursor: pointer;
}
.act {
color: var(--c-f);
}
.check, .radio {
display: inline-block;
position: relative;
cursor: pointer;
text-align: center;
}
.schkl {
width: 24px;
top: -2px;
}
.check input, .radio input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkmark, .radiomark {
position: absolute;
top: 0;
bottom: 0;
left: 0;
background-color: var(--c-3);
border: 1px solid var(--c-2);
}
.radiomark {
height: 24px;
width: 24px;
border-radius: 50%;
}
.checkmark {
height: 25px;
width: 25px;
border-radius: 10px;
}
.check:hover input ~ .checkmark {
background-color: var(--c-4);
}
.check input:checked ~ .checkmark {
background-color: var(--c-6);
}
.checkmark:after, .radiomark:after {
content: "";
position: absolute;
display: none;
}
.check input:checked ~ .checkmark:after, .radio input:checked ~ .radiomark:after {
display: block;
}
.check .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid var(--c-f);
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.radio .radiomark:after {
width: 12px;
height: 12px;
top: 50%;
left: 50%;
margin: -6px;
border-radius: 50%;
background: var(--c-f);
}
.h {
font-size: 13px;
color: var(--c-b);
}
.list {
position: relative;
width: 280px;
transition: background-color 0.5s;
margin: auto auto 20px;
font-size: 19px;
line-height: 24px;
}
.lstI {
cursor: pointer;
background-color: var(--c-2);
overflow: hidden;
border-radius: 20px;
display: block;
position: relative;
border: 1px solid var(--c-2);
padding: 8px 10px;
margin: 10px 0;
min-height: 24px;
}
.selected { /* has to be after .lstI */
background: var(--c-5);
}
.lstI:hover {
background: var(--c-4);
}
/*
.lstI:last-child {
border: none;
border-radius: 0 0 20px 20px;
padding-bottom: 10px;
}
*/
.lstIcontent {
width: 100%;
vertical-align: middle;
padding: 0 20px 0 5px;
text-align: left;
}
.lstIname {
white-space: nowrap;
cursor: pointer;
}
.lstIprev {
width: 100%;
height: 8px;
position: absolute;
bottom: 0;
left: 0;
}
/* Dropdown Content (Hidden by Default) */
.dd-content {
display: none;
position: absolute;
width: 284px;
z-index: 1;
height: 260px;
overflow-y: scroll;
overflow-x: hidden;
padding: 0 18px;
margin-top: 10px;
-ms-overflow-style: none;
scrollbar-width: none; /* Firefox */
}
/* Hide scrollbar for Chrome, Safari and Opera */
.dd-content::-webkit-scrollbar {
display: none;
}
.fnd {
position: sticky;
top: 0;
z-index: 1;
width: 280px;
margin: 0 auto;
}
.search-icon {
position: absolute;
top: 10px;
left: 13px;
pointer-events: none;
width: 24px;
height: 24px;
margin-top: -1px;
z-index: 1;
}
.clear-icon {
position: absolute;
display: none;
top: 10px;
right: 13px;
cursor: pointer;
margin-top: -1px;
z-index: 1;
}
input[type=text].fnd {
display: block;
width: 100%;
box-sizing: border-box;
padding: 8px 48px 8px 48px;
margin: 5px auto 0;
text-align: left;
border-radius: 25px;
background-color: var(--c-2);
border: 1px solid var(--c-4);
}
input[type=text].fnd:focus {
background-color: var(--c-4);
}
input[type=text].fnd:not(:placeholder-shown), input[type=text].fnd:hover {
background-color: var(--c-3);
}
.h, .c {
text-align: center;
}
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: var(--c-sb);
opacity: 0.2;
border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--c-sbh);
}
@media not all and (hover: none) {
.sliderwrap:hover + output.sliderbubble {
visibility: visible;
opacity: 1;
}
}
@media all and (max-width: 335px) {
.sliderbubble {
display: none;
}
}
@media all and (max-width: 550px) and (min-width: 374px) {
#info .btn, #nodes .btn {
width: 150px;
}
#info div, #nodes div {
width: 320px;
}
}
@media all and (max-width: 540px) {
.top button {
width: 16.6%;
padding: 8px 0 4px 0;
}
}
@media all and (min-width: 541px) and (max-width: 719px) {
.top button {
width: 14.2%;
padding: 8px 0 4px 0;
}
}
@media all and (max-width: 719px) {
.hd {
display: none !important;
}
#briwrap {
margin-top: 0px !important;
float: none;
}
}

263
wled00/data/simple.htm Normal file
View File

@ -0,0 +1,263 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<meta charset="utf-8">
<meta name="theme-color" content="#222222">
<meta content="yes" name="apple-mobile-web-app-capable">
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAGACGAAAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAQAAAAEAgGAAAAH/P/YQAAAE1JREFUOI1j/P//PwOxgNGeAUMxE9G6cQCKDWAhpADZ2f8PMjBS3QW08QK20KaZC2gfC9hCnqouoNgARgY7zMxAyNlUdQHlXiAlO2MDAD63EVqNHAe0AAAAAElFTkSuQmCC"/>
<title>WLED</title>
<script>
function feedback(){}
// instead of including [script src="iro.js"][/script] and [script src="rangetouch.js"][/script]
// (which would be inlined by nodeJS inliner during minimization and compression) we need to load them dynamically
// the following is needed to load iro.js and rangetouch.js as consecutive requests to allow ESP8266
// to keep up with requests (if requests happent too fast some may not get processed)
// it will also call onLoad() after last is loaded (it was removed from [body onload="onLoad()"]).
var h = document.getElementsByTagName('head')[0];
var l = document.createElement('script');
l.type = 'application/javascript';
l.src = 'iro.js';
l.addEventListener('load', (e) => {
// after iro is loaded initialize global variable
cpick = new iro.ColorPicker("#picker", {
width: 260,
wheelLightness: false,
wheelAngle: 270,
wheelDirection: "clockwise",
layout: [{
component: iro.ui.Wheel,
options: {}
}]
});
cpick.on("input:end", () => {setColor(1);});
cpick.on("color:change", () => {updatePSliders()});
var l = document.createElement('script');
l.type = 'application/javascript';
l.src = 'rangetouch.js';
l.addEventListener('load', (e) => {
// after rangetouch is loaded initialize global variable
ranges = RangeTouch.setup('input[type="range"]', {});
let stateCheck = setInterval(() => {
if (document.readyState === 'complete') {
clearInterval(stateCheck);
// document ready, start processing UI
onLoad();
}
}, 100);
});
setTimeout(function(){h.appendChild(l)},50);
});
setTimeout(function(){h.appendChild(l)},50);
</script>
<link rel="stylesheet" href="simple.css">
</head>
<body>
<div id="cv" class="overlay">Loading WLED UI...</div>
<noscript><div class="overlay" style="opacity:1;">Sorry, WLED UI needs JavaScript!</div></noscript>
<div id="bg"></div>
<div class="wrapper" id="top">
<div class="tab top">
<div class="btnwrap">
<button id="buttonPower" onclick="togglePower()"><i class="icons">&#xe08f;</i><p class="tab-label">Power</p></button>
<button id="buttonI" onclick="toggleInfo()"><i class="icons">&#xe066;</i><p class="tab-label">Info</p></button>
<button id="buttonNodes" onclick="toggleNodes()"><i class="icons">&#xe22d;</i><p class="tab-label">Nodes</p></button></div>
<button onclick="window.location.href='/settings';"><i class="icons">&#xe0a2;</i><p class="tab-label">Config</p></button>
<button id="buttonCP" onclick="tglCP()"><i class="icons">&#xe2b3;</i><p class="tab-label">Expand</p></button>
<!--button id="buttonBri" onclick="tglBri()"><i class="icons">&#xe2a6;</i><p class="tab-label">Brightness</p></button-->
</div>
<div id="briwrap">
<p class="label hd">Global brightness</p>
<div class="il">
<i class="icons slider-icon" onclick="tglTheme()">&#xe2a6;</i>
<div class="sliderwrap il">
<input id="sliderBri" onchange="setBri()" oninput="updateTrail(this)" max="255" min="1" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
<output class="sliderbubble"></output>
</div>
</div>
</div>
</div>
<div class ="container">
<div class="tabcontent">
<div id="QuickLoad" class="center">
<p class="label h">Quick Load</p>
<div id="pql"></div>
</div>
<div id="QCS" class="center">
<p class="label h">Solid color</p>
<div id="qcs-w" class="center">
<div class="qcs" onclick="pC('#ff0000');" title="Red" style="background-color:#ff0000;"></div>
<div class="qcs" onclick="pC('#ffa000');" title="Orange" style="background-color:#ffa000;"></div>
<div class="qcs" onclick="pC('#ffc800');" title="Yellow" style="background-color:#ffc800;"></div>
<div class="qcs" onclick="pC('#ffe0a0');" title="Warm White" style="background-color:#ffe0a0;"></div>
<div class="qcs" onclick="pC('#ffffff');" title="White" style="background-color:#ffffff;"></div>
<div class="qcs qcsb" onclick="pC('#000000');" title="Black" style="background-color:#000000;"></div><br>
<div class="qcs" onclick="pC('#ff00ff');" title="Pink" style="background-color:#ff00ff;"></div>
<div class="qcs" onclick="pC('#0000ff');" title="Blue" style="background-color:#0000ff;"></div>
<div class="qcs" onclick="pC('#00ffc8');" title="Cyan" style="background-color:#00ffc8;"></div>
<div class="qcs" onclick="pC('#08ff00');" title="Green" style="background-color:#08ff00;"></div>
<div class="qcs" onclick="pC('rnd');" title="Random" style="background:linear-gradient(to right, red, orange, yellow, green, blue, purple);transform: translateY(-11px);">R</div>
</div>
</div>
<div id="picker" class="center"></div>
<div id="Colors" class="center">
<div id="vwrap">
<!--p class="label h">Value</p-->
<div class="sliderwrap il">
<input id="sliderV" class="noslide" oninput="fromV()" onchange="setColor(0)" max="100" min="0" type="range" value="100" step="any" />
<div class="sliderdisplay"></div>
</div><br>
</div>
<div id="kwrap">
<!--p class="label h">Temperature</p-->
<div class="sliderwrap il">
<input id="sliderK" class="noslide" oninput="fromK()" onchange="setColor(0)" max="10091" min="1900" type="range" value="6550" />
<div class="sliderdisplay"></div>
</div>
</div>
<div id="rgbwrap" class="center">
<p class="label h">RGB channels</p>
<div id="rwrap" class="il">
<div class="sliderwrap il">
<input id="sliderR" onchange="fromRgb()" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
</div><br>
<div id="gwrap" class="il">
<div class="sliderwrap il">
<input id="sliderG" onchange="fromRgb()" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
</div><br>
<div id="bwrap" class="il">
<div class="sliderwrap il">
<input id="sliderB" onchange="fromRgb()" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
</div><br>
</div>
<div id="wwrap" class="center">
<p class="label h">White channel</p>
<div class="sliderwrap il">
<input id="sliderW" onchange="setColor(0)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
</div>
<div id="wbal">
<p class="label h">White balance</p>
<div class="sliderwrap il">
<input id="sliderA" onchange="setBalance(this.value)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
</div>
</div>
<div id="Slots" class="center">
<p class="label h">Color slots</p>
<div id="csl" class="center" style="display: none;">
<button class="xxs btn" onclick="selectSlot(0);">1</button>
<button class="xxs btn" onclick="selectSlot(1);">2</button>
<button class="xxs btn" onclick="selectSlot(2);">3</button>
</div>
</div>
<div id="Segments" class="center">
<div id="segcont"></div>
</div>
<div id="Presets" class="center">
<p class="label h">Presets</p>
<div class="fnd">
<input type="text" class="fnd" placeholder="Search" oninput="search(this,'pcont')" onfocus="search(this)" />
<i class="icons clear-icon" onclick="clean(this);">&#xe38f;</i>
<i class="icons search-icon">&#xe0a1;</i>
</div>
<div id="pcont" class="list"></div>
</div>
<div id="Effects" class="center">
<p class="label h">Effect</p>
<div title="Effect speed">
<i class="icons slider-icon">&#xe325;</i>
<div class="sliderwrap il">
<input id="sliderSpeed" onchange="setSpeed()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
<output class="sliderbubble"></output>
</div>
<div title="Effect intensity">
<i class="icons slider-icon" onclick="tglLabels()">&#xe409;</i>
<div class="sliderwrap il">
<input id="sliderIntensity" onchange="setIntensity()" oninput="updateTrail(this)" max="255" min="0" type="range" value="128" />
<div class="sliderdisplay"></div>
</div>
<output class="sliderbubble"></output>
</div>
<div style="padding-bottom:20px;">
<div onclick="tglFxDropdown()" class="c btn" id="fxBtn"><i class="icons">&#xe0e8;</i> Solid</div>
<div onclick="tglPalDropdown()" class="c btn" id="palBtn"><i class="icons">&#xe2b3;</i>Default</div>
<div id="fxDropdown" class="dd-content">
<div class="fnd">
<input type="text" class="fnd" placeholder="Search" oninput="search(this,'fxlist')" onfocus="search(this)" />
<i class="icons clear-icon" onclick="clean(this);">&#xe38f;</i>
<i class="icons search-icon">&#xe0a1;</i>
</div>
<div id="fxlist" class="list">
<div class="lstI" data-id="0" onClick="setEffect(0)"><a href="#0" onClick="setEffect(0)">Solid</a></div>
</div>
</div>
<div id="palDropdown" class="dd-content">
<div class="fnd">
<input type="text" class="fnd" placeholder="Search" oninput="search(this,'pallist')" onfocus="search(this)" />
<i class="icons clear-icon" onclick="clean(this);">&#xe38f;</i>
<i class="icons search-icon">&#xe0a1;</i>
</div>
<div id="pallist" class="list">
<div class="lstI" data-id="0" onClick="setPalette(0)"><a href="#0" onClick="setPalette(0)">Default</a><div class="lstIprev"></div></div>
</div>
</div>
<br>
</div>
</div>
</div>
</div>
<div id="connind"></div>
<div id="toast"></div>
<div id="namelabel" onclick="toggleNodes()"></div>
<div id="info" class="modal">
<div id="imgw">
<img class="wi" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAFCAYAAAC5Fuf5AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABbSURBVChTlY9bDoAwDMNW7n9nwCipytQN4Z8tbrTHmDmF4oPzyldwRqp1SSdnV/NuZuzqerAByxXznBw3igkeFEfXyUuhK/yFM0CxJfyqXZEOc6/Sr9/bf7uIC5Nwd7orMvAPAAAAAElFTkSuQmCC" />
</div><br>
<div id="kv">Loading...</div><br>
<div>
<button class="btn" onclick="requestJson()">Refresh</button>
<button class="btn" onclick="toggleInfo()">Close Info</button>
<button class="btn" onclick="toggleNodes()">Instance List</button>
<button class="btn" id="resetbtn" onclick="cnfReset()">Reboot WLED</button>
</div>
<span class="h">Made with <span id="heart">&#10084;&#xFE0E;</span> by Aircoookie and the <a href="https://wled.discourse.group/" target="_blank">WLED community</a></span>
</div>
<div id="nodes" class="modal">
<div id="ndlt">WLED instances</div>
<div id="kn">Loading...</div><br>
<div>
<button class="btn" onclick="loadNodes()">Refresh</button>
<button class="btn" onclick="toggleNodes()">Close list</button>
</div>
</div>
<i id="roverstar" class="icons huge" onclick="setLor(0)">&#xe410;</i><br>
<script src="simple.js"></script>
</body>
</html>

1452
wled00/data/simple.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,19 @@
html {
touch-action: manipulation;
}
body { body {
font-family: Verdana, sans-serif; font-family: Verdana, sans-serif;
font-size: 1rem;
text-align: center; text-align: center;
background: #222; background: #222;
color: #fff; color: #fff;
line-height: 200%%; /* %% because of AsyncWebServer */ line-height: 200%;
margin: 0; margin: 0;
} }
hr { hr {
border-color: #666; border-color: #666;
} }
a { a, a:hover {
color: #28f; color: #28f;
text-decoration: none; text-decoration: none;
} }
@ -18,13 +22,28 @@ button, .btn {
color: #fff; color: #fff;
font-family: Verdana, sans-serif; font-family: Verdana, sans-serif;
border: 0.3ch solid #333; border: 0.3ch solid #333;
border-radius: 24px;
display: inline-block; display: inline-block;
font-size: 20px; font-size: 20px;
margin: 12px 8px 8px; margin: 12px 8px 8px;
padding: 1px 6px; padding: 8px 12px;
min-width: 48px;
cursor: pointer; cursor: pointer;
text-decoration: none; text-decoration: none;
} }
button.sml {
padding: 8px;
border-radius: 20px;
font-size: 15px;
min-width: 40px;
margin: 0 0 0 10px;
}
.toprow {
top: 0;
position: sticky;
background-color:#222;
z-index:1;
}
.lnk { .lnk {
border: 0; border: 0;
} }
@ -42,9 +61,14 @@ input {
input:disabled { input:disabled {
color: #888; color: #888;
} }
input[type="text"],
input[type="number"],
select {
font-size: medium;
margin: 2px;
}
input[type="number"] { input[type="number"] {
width: 4em; width: 4em;
margin: 2px;
} }
input[type="number"].xxl { input[type="number"].xxl {
width: 100px; width: 100px;
@ -53,32 +77,55 @@ input[type="number"].xl {
width: 85px; width: 85px;
} }
input[type="number"].l { input[type="number"].l {
width: 63px; width: 64px;
} }
input[type="number"].m { input[type="number"].m {
width: 56px; width: 56px;
} }
input[type="number"].s { input[type="number"].s {
width: 49px; width: 48px;
} }
input[type="number"].xs { input[type="number"].xs {
width: 42px; width: 40px;
} }
input[type="checkbox"] { input[type="checkbox"] {
transform: scale(1.5); transform: scale(1.5);
margin-right: 10px;
}
td input[type="checkbox"] {
margin-right: revert;
}
input[type=file] {
font-size: 16px
} }
select { select {
margin: 2px;
background: #333; background: #333;
color: #fff; color: #fff;
font-family: Verdana, sans-serif; font-family: Verdana, sans-serif;
border: 0.5ch solid #333; border: 0.5ch solid #333;
} }
tr {
line-height: 100%;
}
td { td {
padding: 2px; padding: 2px;
} }
.d5 { .d5 {
width: 4.5em !important; width: 4rem !important;
} }
.cal {
font-size:1.5rem;
cursor:pointer
}
#TMT table {
width: 100%;
}
#msg {
display: none;
}
#toast { #toast {
opacity: 0; opacity: 0;
background-color: #444; background-color: #444;
@ -91,9 +138,9 @@ td {
position: fixed; position: fixed;
text-align: center; text-align: center;
z-index: 5; z-index: 5;
transform: translateX(-50%%); /* %% because of AsyncWebServer */ transform: translateX(-50%);
max-width: 90%%; /* %% because of AsyncWebServer */ max-width: 90%;
left: 50%%; /* %% because of AsyncWebServer */ left: 50%;
} }
#toast.show { #toast.show {
@ -107,3 +154,29 @@ td {
background-color: #b21; background-color: #b21;
animation: fadein 0.5s; animation: fadein 0.5s;
} }
@media screen and (max-width: 767px) {
input[type="text"],
input[type="file"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="password"] {
font-size: 16px;
}
}
@media screen and (max-width: 480px) {
input[type="number"].s {
width: 40px;
}
input[type="number"].xs {
width: 32px;
}
input[type="file"] {
width: 224px;
}
#btns select {
width: 144px;
}
}

View File

@ -1,52 +1,28 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta content='width=device-width' name='viewport'> <meta content='width=device-width' name='viewport'>
<title>WLED Update</title> <title>WLED Update</title>
<script>function B() { window.history.back() } <script>
function B() { window.history.back(); }
function U() { document.getElementById("uf").style.display="none";document.getElementById("msg").style.display="block"; } function U() { document.getElementById("uf").style.display="none";document.getElementById("msg").style.display="block"; }
function GetV() {/*injected values here*/}
</script> </script>
<style> <style>
.bt { @import url("style.css");
background: #333;
color: #fff;
font-family: Verdana, sans-serif;
border: .3ch solid #333;
display: inline-block;
font-size: 20px;
margin: 8px;
margin-top: 12px
}
input[type=file] {
font-size: 16px
}
body {
font-family: Verdana, sans-serif;
text-align: center;
background: #222;
color: #fff;
line-height: 200%
}
#msg {
display: none;
}
</style> </style>
</head> </head>
<body> <body onload="GetV()">
<h2>WLED Software Update</h2> <h2>WLED Software Update</h2>
<form method='POST' action='/update' id='uf' enctype='multipart/form-data' onsubmit="U()"> <form method='POST' action='/update' id='uf' enctype='multipart/form-data' onsubmit="U()">
Installed version: ##VERSION##<br> Installed version: <span class="sip">##VERSION##</span><br>
Download the latest binary: <a href="https://github.com/Aircoookie/WLED/releases" target="_blank"> Download the latest binary: <a href="https://github.com/Aircoookie/WLED/releases" target="_blank">
<img src="https://img.shields.io/github/release/Aircoookie/WLED.svg?style=flat-square"></a><br> <img src="https://img.shields.io/github/release/Aircoookie/WLED.svg?style=flat-square"></a><br>
<input type='file' class="bt" name='update' required><br> <!--should have accept='.bin', but it prevents file upload from android app--> <input type='file' name='update' required><br> <!--should have accept='.bin', but it prevents file upload from android app-->
<input type='submit' class="bt" value='Update!' ><br> <button type="submit">Update!</button><br>
<button type="button" class="bt" onclick="B()">Back</button></form> <button type="button" onclick="B()">Back</button>
</form>
<div id="msg"><b>Updating...</b><br>Please do not close or refresh the page :)</div> <div id="msg"><b>Updating...</b><br>Please do not close or refresh the page :)</div>
</body> </body>
</html> </html>

View File

@ -25,19 +25,21 @@ void handleDDPPacket(e131_packet_t* p) {
} }
} }
uint32_t start = htonl(p->channelOffset) /3; uint8_t ddpChannelsPerLed = (p->dataType == DDP_TYPE_RGBW32) ? 4 : 3; // data type 0x1A is RGBW (type 3, 8 bit/channel)
start += DMXAddress /3;
uint16_t stop = start + htons(p->dataLen) /3; uint32_t start = htonl(p->channelOffset) / ddpChannelsPerLed;
start += DMXAddress / ddpChannelsPerLed;
uint16_t stop = start + htons(p->dataLen) / ddpChannelsPerLed;
uint8_t* data = p->data; uint8_t* data = p->data;
uint16_t c = 0; uint16_t c = 0;
if (p->flags & DDP_TIMECODE_FLAG) c = 4; //packet has timecode flag, we do not support it, but data starts 4 bytes later if (p->flags & DDP_TIMECODE_FLAG) c = 4; //packet has timecode flag, we do not support it, but data starts 4 bytes later
realtimeLock(realtimeTimeoutMs, REALTIME_MODE_DDP); realtimeLock(realtimeTimeoutMs, REALTIME_MODE_DDP);
if (!realtimeOverride) { if (!realtimeOverride || (realtimeMode && useMainSegmentOnly)) {
for (uint16_t i = start; i < stop; i++) { for (uint16_t i = start; i < stop; i++) {
setRealtimePixel(i, data[c], data[c+1], data[c+2], 0); setRealtimePixel(i, data[c], data[c+1], data[c+2], ddpChannelsPerLed >3 ? data[c+3] : 0);
c+=3; c += ddpChannelsPerLed;
} }
} }
@ -58,6 +60,10 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
if (protocol == P_ARTNET) if (protocol == P_ARTNET)
{ {
if (p->art_opcode == ARTNET_OPCODE_OPPOLL) {
handleArtnetPollReply(clientIP);
return;
}
uni = p->art_universe; uni = p->art_universe;
dmxChannels = htons(p->art_length); dmxChannels = htons(p->art_length);
e131_data = p->art_data; e131_data = p->art_data;
@ -84,14 +90,14 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
#endif #endif
// only listen for universes we're handling & allocated memory // only listen for universes we're handling & allocated memory
if (uni >= (e131Universe + E131_MAX_UNIVERSE_COUNT)) return; if (uni < e131Universe || uni >= (e131Universe + E131_MAX_UNIVERSE_COUNT)) return;
uint8_t previousUniverses = uni - e131Universe; uint8_t previousUniverses = uni - e131Universe;
if (e131SkipOutOfSequence) if (e131SkipOutOfSequence)
if (seq < e131LastSequenceNumber[uni-e131Universe] && seq > 20 && e131LastSequenceNumber[uni-e131Universe] < 250){ if (seq < e131LastSequenceNumber[previousUniverses] && seq > 20 && e131LastSequenceNumber[previousUniverses] < 250){
DEBUG_PRINT("skipping E1.31 frame (last seq="); DEBUG_PRINT("skipping E1.31 frame (last seq=");
DEBUG_PRINT(e131LastSequenceNumber[uni-e131Universe]); DEBUG_PRINT(e131LastSequenceNumber[previousUniverses]);
DEBUG_PRINT(", current seq="); DEBUG_PRINT(", current seq=");
DEBUG_PRINT(seq); DEBUG_PRINT(seq);
DEBUG_PRINT(", universe="); DEBUG_PRINT(", universe=");
@ -99,15 +105,23 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
DEBUG_PRINTLN(")"); DEBUG_PRINTLN(")");
return; return;
} }
e131LastSequenceNumber[uni-e131Universe] = seq; e131LastSequenceNumber[previousUniverses] = seq;
// update status info // update status info
realtimeIP = clientIP; realtimeIP = clientIP;
byte wChannel = 0; byte wChannel = 0;
uint16_t totalLen = strip.getLengthTotal(); uint16_t totalLen = strip.getLengthTotal();
uint16_t availDMXLen = dmxChannels - DMXAddress + 1; uint16_t availDMXLen = 0;
uint16_t dataOffset = DMXAddress; uint16_t dataOffset = DMXAddress;
// For legacy DMX start address 0 the available DMX length offset is 0
const uint16_t dmxLenOffset = (DMXAddress == 0) ? 0 : 1;
// Check if DMX start address fits in available channels
if (dmxChannels >= DMXAddress) {
availDMXLen = (dmxChannels - DMXAddress) + dmxLenOffset;
}
// DMX data in Art-Net packet starts at index 0, for E1.31 at index 1 // DMX data in Art-Net packet starts at index 0, for E1.31 at index 1
if (protocol == P_ARTNET && dataOffset > 0) { if (protocol == P_ARTNET && dataOffset > 0) {
dataOffset--; dataOffset--;
@ -121,8 +135,11 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
case DMX_MODE_SINGLE_RGB: // RGB only case DMX_MODE_SINGLE_RGB: // RGB only
if (uni != e131Universe) return; if (uni != e131Universe) return;
if (availDMXLen < 3) return; if (availDMXLen < 3) return;
realtimeLock(realtimeTimeoutMs, mde); realtimeLock(realtimeTimeoutMs, mde);
if (realtimeOverride) return;
if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) return;
wChannel = (availDMXLen > 3) ? e131_data[dataOffset+3] : 0; wChannel = (availDMXLen > 3) ? e131_data[dataOffset+3] : 0;
for (uint16_t i = 0; i < totalLen; i++) for (uint16_t i = 0; i < totalLen; i++)
setRealtimePixel(i, e131_data[dataOffset+0], e131_data[dataOffset+1], e131_data[dataOffset+2], wChannel); setRealtimePixel(i, e131_data[dataOffset+0], e131_data[dataOffset+1], e131_data[dataOffset+2], wChannel);
@ -131,14 +148,16 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
case DMX_MODE_SINGLE_DRGB: // Dimmer + RGB case DMX_MODE_SINGLE_DRGB: // Dimmer + RGB
if (uni != e131Universe) return; if (uni != e131Universe) return;
if (availDMXLen < 4) return; if (availDMXLen < 4) return;
realtimeLock(realtimeTimeoutMs, mde); realtimeLock(realtimeTimeoutMs, mde);
if (realtimeOverride) return; if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) return;
wChannel = (availDMXLen > 4) ? e131_data[dataOffset+4] : 0; wChannel = (availDMXLen > 4) ? e131_data[dataOffset+4] : 0;
if (DMXOldDimmer != e131_data[dataOffset+0]) {
DMXOldDimmer = e131_data[dataOffset+0]; if (bri != e131_data[dataOffset+0]) {
bri = e131_data[dataOffset+0]; bri = e131_data[dataOffset+0];
strip.setBrightness(bri, true); strip.setBrightness(bri, true);
} }
for (uint16_t i = 0; i < totalLen; i++) for (uint16_t i = 0; i < totalLen; i++)
setRealtimePixel(i, e131_data[dataOffset+1], e131_data[dataOffset+2], e131_data[dataOffset+3], wChannel); setRealtimePixel(i, e131_data[dataOffset+1], e131_data[dataOffset+2], e131_data[dataOffset+3], wChannel);
break; break;
@ -150,11 +169,11 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
applyPreset(e131_data[dataOffset+0], CALL_MODE_NOTIFICATION); applyPreset(e131_data[dataOffset+0], CALL_MODE_NOTIFICATION);
return; return;
} }
if (DMXOldDimmer != e131_data[dataOffset+0]) {
DMXOldDimmer = e131_data[dataOffset+0]; if (bri != e131_data[dataOffset+0]) {
bri = e131_data[dataOffset+0]; bri = e131_data[dataOffset+0];
} }
if (e131_data[dataOffset+1] < MODE_COUNT) if (e131_data[dataOffset+1] < strip.getModeCount())
effectCurrent = e131_data[dataOffset+ 1]; effectCurrent = e131_data[dataOffset+ 1];
effectSpeed = e131_data[dataOffset+ 2]; // flickers effectSpeed = e131_data[dataOffset+ 2]; // flickers
effectIntensity = e131_data[dataOffset+ 3]; effectIntensity = e131_data[dataOffset+ 3];
@ -179,19 +198,19 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
case DMX_MODE_MULTIPLE_RGB: case DMX_MODE_MULTIPLE_RGB:
case DMX_MODE_MULTIPLE_RGBW: case DMX_MODE_MULTIPLE_RGBW:
{ {
realtimeLock(realtimeTimeoutMs, mde);
bool is4Chan = (DMXMode == DMX_MODE_MULTIPLE_RGBW); bool is4Chan = (DMXMode == DMX_MODE_MULTIPLE_RGBW);
const uint16_t dmxChannelsPerLed = is4Chan ? 4 : 3; const uint16_t dmxChannelsPerLed = is4Chan ? 4 : 3;
const uint16_t ledsPerUniverse = is4Chan ? MAX_4_CH_LEDS_PER_UNIVERSE : MAX_3_CH_LEDS_PER_UNIVERSE; const uint16_t ledsPerUniverse = is4Chan ? MAX_4_CH_LEDS_PER_UNIVERSE : MAX_3_CH_LEDS_PER_UNIVERSE;
if (realtimeOverride) return; uint8_t stripBrightness = bri;
uint16_t previousLeds, dmxOffset, ledsTotal; uint16_t previousLeds, dmxOffset, ledsTotal;
if (previousUniverses == 0) { if (previousUniverses == 0) {
if (availDMXLen < 1) return; if (availDMXLen < 1) return;
dmxOffset = dataOffset; dmxOffset = dataOffset;
previousLeds = 0; previousLeds = 0;
// First DMX address is dimmer in DMX_MODE_MULTIPLE_DRGB mode. // First DMX address is dimmer in DMX_MODE_MULTIPLE_DRGB mode.
if (DMXMode == DMX_MODE_MULTIPLE_DRGB) { if (DMXMode == DMX_MODE_MULTIPLE_DRGB) {
strip.setBrightness(e131_data[dmxOffset++], true); stripBrightness = e131_data[dmxOffset++];
ledsTotal = (availDMXLen - 1) / dmxChannelsPerLed; ledsTotal = (availDMXLen - 1) / dmxChannelsPerLed;
} else { } else {
ledsTotal = availDMXLen / dmxChannelsPerLed; ledsTotal = availDMXLen / dmxChannelsPerLed;
@ -199,11 +218,31 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
} else { } else {
// All subsequent universes start at the first channel. // All subsequent universes start at the first channel.
dmxOffset = (protocol == P_ARTNET) ? 0 : 1; dmxOffset = (protocol == P_ARTNET) ? 0 : 1;
uint16_t dimmerOffset = (DMXMode == DMX_MODE_MULTIPLE_DRGB) ? 1 : 0; const uint16_t dimmerOffset = (DMXMode == DMX_MODE_MULTIPLE_DRGB) ? 1 : 0;
uint16_t ledsInFirstUniverse = ((MAX_CHANNELS_PER_UNIVERSE - DMXAddress + 1) - dimmerOffset) / dmxChannelsPerLed; uint16_t ledsInFirstUniverse = (((MAX_CHANNELS_PER_UNIVERSE - DMXAddress) + dmxLenOffset) - dimmerOffset) / dmxChannelsPerLed;
previousLeds = ledsInFirstUniverse + (previousUniverses - 1) * ledsPerUniverse; previousLeds = ledsInFirstUniverse + (previousUniverses - 1) * ledsPerUniverse;
ledsTotal = previousLeds + (dmxChannels / dmxChannelsPerLed); ledsTotal = previousLeds + (dmxChannels / dmxChannelsPerLed);
} }
// All LEDs already have values
if (previousLeds >= totalLen) {
return;
}
realtimeLock(realtimeTimeoutMs, mde);
if (realtimeOverride && !(realtimeMode && useMainSegmentOnly)) return;
if (ledsTotal > totalLen) {
ledsTotal = totalLen;
}
if (DMXMode == DMX_MODE_MULTIPLE_DRGB && previousUniverses == 0) {
if (bri != stripBrightness) {
bri = stripBrightness;
strip.setBrightness(bri, true);
}
}
if (!is4Chan) { if (!is4Chan) {
for (uint16_t i = previousLeds; i < ledsTotal; i++) { for (uint16_t i = previousLeds; i < ledsTotal; i++) {
setRealtimePixel(i, e131_data[dmxOffset], e131_data[dmxOffset+1], e131_data[dmxOffset+2], 0); setRealtimePixel(i, e131_data[dmxOffset], e131_data[dmxOffset+1], e131_data[dmxOffset+2], 0);
@ -225,3 +264,197 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
e131NewData = true; e131NewData = true;
} }
void handleArtnetPollReply(IPAddress ipAddress) {
ArtPollReply artnetPollReply;
prepareArtnetPollReply(&artnetPollReply);
uint16_t startUniverse = e131Universe;
uint16_t endUniverse = e131Universe;
switch (DMXMode) {
case DMX_MODE_DISABLED:
return; // nothing to do
break;
case DMX_MODE_SINGLE_RGB:
case DMX_MODE_SINGLE_DRGB:
case DMX_MODE_EFFECT:
break; // 1 universe is enough
case DMX_MODE_MULTIPLE_DRGB:
case DMX_MODE_MULTIPLE_RGB:
case DMX_MODE_MULTIPLE_RGBW:
{
bool is4Chan = (DMXMode == DMX_MODE_MULTIPLE_RGBW);
const uint16_t dmxChannelsPerLed = is4Chan ? 4 : 3;
const uint16_t dimmerOffset = (DMXMode == DMX_MODE_MULTIPLE_DRGB) ? 1 : 0;
const uint16_t dmxLenOffset = (DMXAddress == 0) ? 0 : 1; // For legacy DMX start address 0
const uint16_t ledsInFirstUniverse = (((MAX_CHANNELS_PER_UNIVERSE - DMXAddress) + dmxLenOffset) - dimmerOffset) / dmxChannelsPerLed;
const uint16_t totalLen = strip.getLengthTotal();
if (totalLen > ledsInFirstUniverse) {
const uint16_t ledsPerUniverse = is4Chan ? MAX_4_CH_LEDS_PER_UNIVERSE : MAX_3_CH_LEDS_PER_UNIVERSE;
const uint16_t remainLED = totalLen - ledsInFirstUniverse;
endUniverse += (remainLED / ledsPerUniverse);
if ((remainLED % ledsPerUniverse) > 0) {
endUniverse++;
}
if ((endUniverse - startUniverse) > E131_MAX_UNIVERSE_COUNT) {
endUniverse = startUniverse + E131_MAX_UNIVERSE_COUNT - 1;
}
}
break;
}
default:
DEBUG_PRINTLN(F("unknown E1.31 DMX mode"));
return; // nothing to do
break;
}
for (uint16_t i = startUniverse; i <= endUniverse; ++i) {
sendArtnetPollReply(&artnetPollReply, ipAddress, i);
}
}
void prepareArtnetPollReply(ArtPollReply *reply) {
// Art-Net
reply->reply_id[0] = 0x41;
reply->reply_id[1] = 0x72;
reply->reply_id[2] = 0x74;
reply->reply_id[3] = 0x2d;
reply->reply_id[4] = 0x4e;
reply->reply_id[5] = 0x65;
reply->reply_id[6] = 0x74;
reply->reply_id[7] = 0x00;
reply->reply_opcode = ARTNET_OPCODE_OPPOLLREPLY;
IPAddress localIP = Network.localIP();
for (uint8_t i = 0; i < 4; i++) {
reply->reply_ip[i] = localIP[i];
}
reply->reply_port = ARTNET_DEFAULT_PORT;
char * numberEnd = versionString;
reply->reply_version_h = (uint8_t)strtol(numberEnd, &numberEnd, 10);
numberEnd++;
reply->reply_version_l = (uint8_t)strtol(numberEnd, &numberEnd, 10);
// Switch values depend on universe, set before sending
reply->reply_net_sw = 0x00;
reply->reply_sub_sw = 0x00;
reply->reply_oem_h = 0x00; // TODO add assigned oem code
reply->reply_oem_l = 0x00;
reply->reply_ubea_ver = 0x00;
// Indicators in Normal Mode
// All or part of Port-Address programmed by network or Web browser
reply->reply_status_1 = 0xE0;
reply->reply_esta_man = 0x0000;
strlcpy((char *)(reply->reply_short_name), serverDescription, 18);
strlcpy((char *)(reply->reply_long_name), serverDescription, 64);
reply->reply_node_report[0] = '\0';
reply->reply_num_ports_h = 0x00;
reply->reply_num_ports_l = 0x01; // One output port
reply->reply_port_types[0] = 0x80; // Output DMX data
reply->reply_port_types[1] = 0x00;
reply->reply_port_types[2] = 0x00;
reply->reply_port_types[3] = 0x00;
// No inputs
reply->reply_good_input[0] = 0x00;
reply->reply_good_input[1] = 0x00;
reply->reply_good_input[2] = 0x00;
reply->reply_good_input[3] = 0x00;
// One output
reply->reply_good_output_a[0] = 0x80; // Data is being transmitted
reply->reply_good_output_a[1] = 0x00;
reply->reply_good_output_a[2] = 0x00;
reply->reply_good_output_a[3] = 0x00;
// Values depend on universe, set before sending
reply->reply_sw_in[0] = 0x00;
reply->reply_sw_in[1] = 0x00;
reply->reply_sw_in[2] = 0x00;
reply->reply_sw_in[3] = 0x00;
// Values depend on universe, set before sending
reply->reply_sw_out[0] = 0x00;
reply->reply_sw_out[1] = 0x00;
reply->reply_sw_out[2] = 0x00;
reply->reply_sw_out[3] = 0x00;
reply->reply_sw_video = 0x00;
reply->reply_sw_macro = 0x00;
reply->reply_sw_remote = 0x00;
reply->reply_spare[0] = 0x00;
reply->reply_spare[1] = 0x00;
reply->reply_spare[2] = 0x00;
// A DMX to / from Art-Net device
reply->reply_style = 0x00;
Network.localMAC(reply->reply_mac);
for (uint8_t i = 0; i < 4; i++) {
reply->reply_bind_ip[i] = localIP[i];
}
reply->reply_bind_index = 1;
// Product supports web browser configuration
// Nodes IP is DHCP or manually configured
// Node is DHCP capable
// Node supports 15 bit Port-Address (Art-Net 3 or 4)
// Node is able to switch between ArtNet and sACN
reply->reply_status_2 = (staticIP[0] == 0) ? 0x1F : 0x1D;
// RDM is disabled
// Output style is continuous
reply->reply_good_output_b[0] = 0xC0;
reply->reply_good_output_b[1] = 0xC0;
reply->reply_good_output_b[2] = 0xC0;
reply->reply_good_output_b[3] = 0xC0;
// Fail-over state: Hold last state
// Node does not support fail-over
reply->reply_status_3 = 0x00;
for (uint8_t i = 0; i < 21; i++) {
reply->reply_filler[i] = 0x00;
}
}
void sendArtnetPollReply(ArtPollReply *reply, IPAddress ipAddress, uint16_t portAddress) {
reply->reply_net_sw = (uint8_t)((portAddress >> 8) & 0x007F);
reply->reply_sub_sw = (uint8_t)((portAddress >> 4) & 0x000F);
reply->reply_sw_out[0] = (uint8_t)(portAddress & 0x000F);
sprintf((char *)reply->reply_node_report, "#0001 [%04u] OK - WLED v" TOSTRING(WLED_VERSION), pollReplyCount);
if (pollReplyCount < 9999) {
pollReplyCount++;
} else {
pollReplyCount = 0;
}
notifierUdp.beginPacket(ipAddress, ARTNET_DEFAULT_PORT);
notifierUdp.write(reply->raw, sizeof(ArtPollReply));
notifierUdp.endPacket();
reply->reply_bind_index++;
}

View File

@ -58,21 +58,23 @@ bool getJsonValue(const JsonVariant& element, DestType& destination, const Defau
//colors.cpp //colors.cpp
uint32_t color_blend(uint32_t,uint32_t,uint16_t,bool b16=false);
uint32_t color_add(uint32_t,uint32_t);
inline uint32_t colorFromRgbw(byte* rgbw) { return uint32_t((byte(rgbw[3]) << 24) | (byte(rgbw[0]) << 16) | (byte(rgbw[1]) << 8) | (byte(rgbw[2]))); } inline uint32_t colorFromRgbw(byte* rgbw) { return uint32_t((byte(rgbw[3]) << 24) | (byte(rgbw[0]) << 16) | (byte(rgbw[1]) << 8) | (byte(rgbw[2]))); }
void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb
void colorKtoRGB(uint16_t kelvin, byte* rgb); void colorKtoRGB(uint16_t kelvin, byte* rgb);
void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb
void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO void colorXYtoRGB(float x, float y, byte* rgb); // only defined if huesync disabled TODO
void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO void colorRGBtoXY(byte* rgb, float* xy); // only defined if huesync disabled TODO
void colorFromDecOrHexString(byte* rgb, char* in); void colorFromDecOrHexString(byte* rgb, char* in);
bool colorFromHexString(byte* rgb, const char* in); bool colorFromHexString(byte* rgb, const char* in);
uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb); uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb);
uint16_t approximateKelvinFromRGB(uint32_t rgb); uint16_t approximateKelvinFromRGB(uint32_t rgb);
void setRandomColor(byte* rgb); void setRandomColor(byte* rgb);
uint8_t gamma8_cal(uint8_t b, float gamma);
void calcGammaTable(float gamma);
uint8_t gamma8(uint8_t b);
uint32_t gamma32(uint32_t);
//dmx.cpp //dmx.cpp
void initDMX(); void initDMX();
@ -80,6 +82,9 @@ void handleDMX();
//e131.cpp //e131.cpp
void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol); void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol);
void handleArtnetPollReply(IPAddress ipAddress);
void prepareArtnetPollReply(ArtPollReply* reply);
void sendArtnetPollReply(ArtPollReply* reply, IPAddress ipAddress, uint16_t portAddress);
//file.cpp //file.cpp
bool handleFileRead(AsyncWebServerRequest*, String path); bool handleFileRead(AsyncWebServerRequest*, String path);
@ -105,7 +110,6 @@ void sendImprovInfoResponse();
void sendImprovRPCResponse(uint8_t commandId); void sendImprovRPCResponse(uint8_t commandId);
//ir.cpp //ir.cpp
//bool decodeIRCustom(uint32_t code);
void applyRepeatActions(); void applyRepeatActions();
byte relativeChange(byte property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF); byte relativeChange(byte property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF);
void decodeIR(uint32_t code); void decodeIR(uint32_t code);
@ -130,9 +134,11 @@ void handleIR();
void deserializeSegment(JsonObject elem, byte it, byte presetId = 0); void deserializeSegment(JsonObject elem, byte it, byte presetId = 0);
bool deserializeState(JsonObject root, byte callMode = CALL_MODE_DIRECT_CHANGE, byte presetId = 0); bool deserializeState(JsonObject root, byte callMode = CALL_MODE_DIRECT_CHANGE, byte presetId = 0);
void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true); void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset = false, bool segmentBounds = true);
void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true); void serializeState(JsonObject root, bool forPreset = false, bool includeBri = true, bool segmentBounds = true, bool selectedSegmentsOnly = false);
void serializeInfo(JsonObject root); void serializeInfo(JsonObject root);
void serializeModeNames(JsonArray arr, const char *qstring);
void serializeModeData(JsonObject root);
void serveJson(AsyncWebServerRequest* request); void serveJson(AsyncWebServerRequest* request);
#ifdef WLED_ENABLE_JSONLIVE #ifdef WLED_ENABLE_JSONLIVE
bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient = 0); bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient = 0);
@ -186,8 +192,10 @@ void shufflePlaylist();
void unloadPlaylist(); void unloadPlaylist();
int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0); int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0);
void handlePlaylist(); void handlePlaylist();
void serializePlaylist(JsonObject obj);
//presets.cpp //presets.cpp
void handlePresets();
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE); bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE);
inline bool applyTemporaryPreset() {return applyPreset(255);}; inline bool applyTemporaryPreset() {return applyPreset(255);};
void savePreset(byte index, const char* pname = nullptr, JsonObject saveobj = JsonObject()); void savePreset(byte index, const char* pname = nullptr, JsonObject saveobj = JsonObject());
@ -198,9 +206,6 @@ void deletePreset(byte index);
bool isAsterisksOnly(const char* str, byte maxLen); bool isAsterisksOnly(const char* str, byte maxLen);
void handleSettingsSet(AsyncWebServerRequest *request, byte subPage); void handleSettingsSet(AsyncWebServerRequest *request, byte subPage);
bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply=true); bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply=true);
int getNumVal(const String* req, uint16_t pos);
void parseNumber(const char* str, byte* val, byte minv=0, byte maxv=255);
bool updateVal(const String* req, const char* key, byte* val, byte minv=0, byte maxv=255);
//udp.cpp //udp.cpp
void notify(byte callMode, bool followUp=false); void notify(byte callMode, bool followUp=false);
@ -212,25 +217,57 @@ void setRealtimePixel(uint16_t i, byte r, byte g, byte b, byte w);
void refreshNodeList(); void refreshNodeList();
void sendSysInfoUDP(); void sendSysInfoUDP();
//util.cpp //network.cpp
//bool oappend(const char* txt); // append new c string to temp buffer efficiently int getSignalQuality(int rssi);
//bool oappendi(int i); // append new number to temp buffer efficiently void WiFiEvent(WiFiEvent_t event);
//void sappend(char stype, const char* key, int val);
//void sappends(char stype, const char* key, char* val);
//void prepareHostname(char* hostname);
//bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(uint8_t module=255);
void releaseJSONBufferLock();
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
//um_manager.cpp //um_manager.cpp
typedef enum UM_Data_Types {
UMT_BYTE = 0,
UMT_UINT16,
UMT_INT16,
UMT_UINT32,
UMT_INT32,
UMT_FLOAT,
UMT_DOUBLE,
UMT_BYTE_ARR,
UMT_UINT16_ARR,
UMT_INT16_ARR,
UMT_UINT32_ARR,
UMT_INT32_ARR,
UMT_FLOAT_ARR,
UMT_DOUBLE_ARR
} um_types_t;
typedef struct UM_Exchange_Data {
// should just use: size_t arr_size, void **arr_ptr, byte *ptr_type
size_t u_size; // size of u_data array
um_types_t *u_type; // array of data types
void **u_data; // array of pointers to data
UM_Exchange_Data() {
u_size = 0;
u_type = nullptr;
u_data = nullptr;
}
~UM_Exchange_Data() {
if (u_type) delete[] u_type;
if (u_data) delete[] u_data;
}
} um_data_t;
const unsigned int um_data_size = sizeof(um_data_t); // 12 bytes
class Usermod { class Usermod {
protected:
um_data_t *um_data; // um_data should be allocated using new in (derived) Usermod's setup() or constructor
public: public:
virtual void loop() {} Usermod() { um_data = nullptr; }
virtual ~Usermod() { if (um_data) delete um_data; }
virtual void setup() = 0; // pure virtual, has to be overriden
virtual void loop() = 0; // pure virtual, has to be overriden
virtual void handleOverlayDraw() {} virtual void handleOverlayDraw() {}
virtual bool handleButton(uint8_t b) { return false; } virtual bool handleButton(uint8_t b) { return false; }
virtual void setup() {} virtual bool getUMData(um_data_t **data) { if (data) *data = nullptr; return false; };
virtual void connected() {} virtual void connected() {}
virtual void appendConfigData() {}
virtual void addToJsonState(JsonObject& obj) {} virtual void addToJsonState(JsonObject& obj) {}
virtual void addToJsonInfo(JsonObject& obj) {} virtual void addToJsonInfo(JsonObject& obj) {}
virtual void readFromJsonState(JsonObject& obj) {} virtual void readFromJsonState(JsonObject& obj) {}
@ -238,6 +275,7 @@ class Usermod {
virtual bool readFromConfig(JsonObject& obj) { return true; } // Note as of 2021-06 readFromConfig() now needs to return a bool, see usermod_v2_example.h virtual bool readFromConfig(JsonObject& obj) { return true; } // Note as of 2021-06 readFromConfig() now needs to return a bool, see usermod_v2_example.h
virtual void onMqttConnect(bool sessionPresent) {} virtual void onMqttConnect(bool sessionPresent) {}
virtual bool onMqttMessage(char* topic, char* payload) { return false; } virtual bool onMqttMessage(char* topic, char* payload) { return false; }
virtual void onUpdateBegin(bool) {}
virtual uint16_t getId() {return USERMOD_ID_UNSPECIFIED;} virtual uint16_t getId() {return USERMOD_ID_UNSPECIFIED;}
}; };
@ -250,8 +288,10 @@ class UsermodManager {
void loop(); void loop();
void handleOverlayDraw(); void handleOverlayDraw();
bool handleButton(uint8_t b); bool handleButton(uint8_t b);
bool getUMData(um_data_t **um_data, uint8_t mod_id = USERMOD_ID_RESERVED); // USERMOD_ID_RESERVED will poll all usermods
void setup(); void setup();
void connected(); void connected();
void appendConfigData();
void addToJsonState(JsonObject& obj); void addToJsonState(JsonObject& obj);
void addToJsonInfo(JsonObject& obj); void addToJsonInfo(JsonObject& obj);
void readFromJsonState(JsonObject& obj); void readFromJsonState(JsonObject& obj);
@ -259,9 +299,10 @@ class UsermodManager {
bool readFromConfig(JsonObject& obj); bool readFromConfig(JsonObject& obj);
void onMqttConnect(bool sessionPresent); void onMqttConnect(bool sessionPresent);
bool onMqttMessage(char* topic, char* payload); bool onMqttMessage(char* topic, char* payload);
void onUpdateBegin(bool);
bool add(Usermod* um); bool add(Usermod* um);
Usermod* lookup(uint16_t mod_id); Usermod* lookup(uint16_t mod_id);
byte getModCount(); byte getModCount() {return numMods;};
}; };
//usermods_list.cpp //usermods_list.cpp
@ -272,11 +313,55 @@ void userSetup();
void userConnected(); void userConnected();
void userLoop(); void userLoop();
//util.cpp
int getNumVal(const String* req, uint16_t pos);
void parseNumber(const char* str, byte* val, byte minv=0, byte maxv=255);
bool getVal(JsonVariant elem, byte* val, byte minv=0, byte maxv=255);
bool updateVal(const char* req, const char* key, byte* val, byte minv=0, byte maxv=255);
bool oappend(const char* txt); // append new c string to temp buffer efficiently
bool oappendi(int i); // append new number to temp buffer efficiently
void sappend(char stype, const char* key, int val);
void sappends(char stype, const char* key, char* val);
void prepareHostname(char* hostname);
bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(uint8_t module=255);
void releaseJSONBufferLock();
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxLen, uint8_t *var = nullptr);
int16_t extractModeDefaults(uint8_t mode, const char *segVar);
uint16_t crc16(const unsigned char* data_p, size_t length);
um_data_t* simulateSound(uint8_t simulationId);
void enumerateLedmaps();
#ifdef WLED_ADD_EEPROM_SUPPORT
//wled_eeprom.cpp //wled_eeprom.cpp
void applyMacro(byte index); void applyMacro(byte index);
void deEEP(); void deEEP();
void deEEPSettings(); void deEEPSettings();
void clearEEPROM(); void clearEEPROM();
#endif
//wled_math.cpp
#ifndef WLED_USE_REAL_MATH
template <typename T> T atan_t(T x);
float cos_t(float phi);
float sin_t(float x);
float tan_t(float x);
float acos_t(float x);
float asin_t(float x);
float floor_t(float x);
float fmod_t(float num, float denom);
#else
#include <math.h>
#define sin_t sin
#define cos_t cos
#define tan_t tan
#define asin_t asin
#define acos_t acos
#define atan_t atan
#define fmod_t fmod
#define floor_t floor
#endif
//wled_serial.cpp //wled_serial.cpp
void handleSerial(); void handleSerial();
@ -284,6 +369,7 @@ void updateBaudRate(uint32_t rate);
//wled_server.cpp //wled_server.cpp
bool isIp(String str); bool isIp(String str);
void createEditHandler(bool enable);
bool captivePortal(AsyncWebServerRequest *request); bool captivePortal(AsyncWebServerRequest *request);
void initServer(); void initServer();
void serveIndexOrWelcome(AsyncWebServerRequest *request); void serveIndexOrWelcome(AsyncWebServerRequest *request);
@ -293,6 +379,7 @@ void serveMessage(AsyncWebServerRequest* request, uint16_t code, const String& h
String settingsProcessor(const String& var); String settingsProcessor(const String& var);
String dmxProcessor(const String& var); String dmxProcessor(const String& var);
void serveSettings(AsyncWebServerRequest* request, bool post = false); void serveSettings(AsyncWebServerRequest* request, bool post = false);
void serveSettingsJS(AsyncWebServerRequest* request);
//ws.cpp //ws.cpp
void handleWs(); void handleWs();
@ -302,8 +389,6 @@ void sendDataWs(AsyncWebSocketClient * client = nullptr);
//xml.cpp //xml.cpp
void XML_response(AsyncWebServerRequest *request, char* dest = nullptr); void XML_response(AsyncWebServerRequest *request, char* dest = nullptr);
void URL_response(AsyncWebServerRequest *request); void URL_response(AsyncWebServerRequest *request);
void sappend(char stype, const char* key, int val);
void sappends(char stype, const char* key, char* val);
void getSettingsJS(byte subPage, char* dest); void getSettingsJS(byte subPage, char* dest);
#endif #endif

View File

@ -380,10 +380,10 @@ String getContentType(AsyncWebServerRequest* request, String filename){
else if(filename.endsWith(".htm")) return "text/html"; else if(filename.endsWith(".htm")) return "text/html";
else if(filename.endsWith(".html")) return "text/html"; else if(filename.endsWith(".html")) return "text/html";
else if(filename.endsWith(".css")) return "text/css"; else if(filename.endsWith(".css")) return "text/css";
// else if(filename.endsWith(".js")) return "application/javascript"; else if(filename.endsWith(".js")) return "application/javascript";
else if(filename.endsWith(".json")) return "application/json"; else if(filename.endsWith(".json")) return "application/json";
else if(filename.endsWith(".png")) return "image/png"; else if(filename.endsWith(".png")) return "image/png";
// else if(filename.endsWith(".gif")) return "image/gif"; else if(filename.endsWith(".gif")) return "image/gif";
else if(filename.endsWith(".jpg")) return "image/jpeg"; else if(filename.endsWith(".jpg")) return "image/jpeg";
else if(filename.endsWith(".ico")) return "image/x-icon"; else if(filename.endsWith(".ico")) return "image/x-icon";
// else if(filename.endsWith(".xml")) return "text/xml"; // else if(filename.endsWith(".xml")) return "text/xml";

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

1132
wled00/html_simple.h Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -101,7 +101,7 @@ void onHueData(void* arg, AsyncClient* client, void *data, size_t len)
hueError = HUE_ERROR_JSON_PARSING; return; hueError = HUE_ERROR_JSON_PARSING; return;
} }
int hueErrorCode = root[0][F("error")][F("type")]; int hueErrorCode = root[0][F("error")]["type"];
if (hueErrorCode)//hue bridge returned error if (hueErrorCode)//hue bridge returned error
{ {
hueError = hueErrorCode; hueError = hueErrorCode;

View File

@ -189,7 +189,7 @@ void sendImprovInfoResponse() {
out[11] = 4; //Firmware len ("WLED") out[11] = 4; //Firmware len ("WLED")
out[12] = 'W'; out[13] = 'L'; out[14] = 'E'; out[15] = 'D'; out[12] = 'W'; out[13] = 'L'; out[14] = 'E'; out[15] = 'D';
uint8_t lengthSum = 17; uint8_t lengthSum = 17;
uint8_t vlen = sprintf_P(out+lengthSum,PSTR("0.13.3/%i"),VERSION); uint8_t vlen = sprintf_P(out+lengthSum,PSTR("0.14.0-b0/%i"),VERSION);
out[16] = vlen; lengthSum += vlen; out[16] = vlen; lengthSum += vlen;
uint8_t hlen = 7; uint8_t hlen = 7;
#ifdef ESP8266 #ifdef ESP8266

View File

@ -1,5 +1,7 @@
#include "wled.h" #include "wled.h"
#include "ir_codes.h"
/* /*
* Infrared sensor support for generic 24/40/44 key RGB remotes * Infrared sensor support for generic 24/40/44 key RGB remotes
*/ */
@ -71,12 +73,10 @@ void decBrightness()
// apply preset or fallback to a effect and palette if it doesn't exist // apply preset or fallback to a effect and palette if it doesn't exist
void presetFallback(uint8_t presetID, uint8_t effectID, uint8_t paletteID) void presetFallback(uint8_t presetID, uint8_t effectID, uint8_t paletteID)
{ {
byte prevError = errorFlag; applyPreset(presetID, CALL_MODE_BUTTON_PRESET);
if (!applyPreset(presetID, CALL_MODE_BUTTON_PRESET)) { //these two will be overwritten if preset exists in handlePresets()
effectCurrent = effectID; effectCurrent = effectID;
effectPalette = paletteID; effectPalette = paletteID;
errorFlag = prevError; //clear error 12 from non-existent preset
}
} }
byte relativeChange(byte property, int8_t amount, byte lowerBoundary, byte higherBoundary) byte relativeChange(byte property, int8_t amount, byte lowerBoundary, byte higherBoundary)
@ -91,8 +91,8 @@ byte relativeChange(byte property, int8_t amount, byte lowerBoundary, byte highe
void changeEffect(uint8_t fx) void changeEffect(uint8_t fx)
{ {
if (irApplyToAllSelected) { if (irApplyToAllSelected) {
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
strip.setMode(i, fx); strip.setMode(i, fx);
} }
@ -107,8 +107,8 @@ void changeEffect(uint8_t fx)
void changePalette(uint8_t pal) void changePalette(uint8_t pal)
{ {
if (irApplyToAllSelected) { if (irApplyToAllSelected) {
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
seg.palette = pal; seg.palette = pal;
} }
@ -126,8 +126,8 @@ void changeEffectSpeed(int8_t amount)
int16_t new_val = (int16_t) effectSpeed + amount; int16_t new_val = (int16_t) effectSpeed + amount;
effectSpeed = (byte)constrain(new_val,0,255); effectSpeed = (byte)constrain(new_val,0,255);
if (irApplyToAllSelected) { if (irApplyToAllSelected) {
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
seg.speed = effectSpeed; seg.speed = effectSpeed;
} }
@ -137,7 +137,7 @@ void changeEffectSpeed(int8_t amount)
setValuesFromMainSeg(); setValuesFromMainSeg();
} }
} else { // if Effect == "solid Color", change the hue of the primary color } else { // if Effect == "solid Color", change the hue of the primary color
WS2812FX::Segment& sseg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment(); Segment& sseg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment();
CRGB fastled_col; CRGB fastled_col;
fastled_col.red = R(sseg.colors[0]); fastled_col.red = R(sseg.colors[0]);
fastled_col.green = G(sseg.colors[0]); fastled_col.green = G(sseg.colors[0]);
@ -149,8 +149,8 @@ void changeEffectSpeed(int8_t amount)
prim_hsv.h = (byte)new_val; prim_hsv.h = (byte)new_val;
hsv2rgb_rainbow(prim_hsv, fastled_col); hsv2rgb_rainbow(prim_hsv, fastled_col);
if (irApplyToAllSelected) { if (irApplyToAllSelected) {
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
seg.colors[0] = RGBW32(fastled_col.red, fastled_col.green, fastled_col.blue, W(sseg.colors[0])); seg.colors[0] = RGBW32(fastled_col.red, fastled_col.green, fastled_col.blue, W(sseg.colors[0]));
} }
@ -173,8 +173,8 @@ void changeEffectIntensity(int8_t amount)
int16_t new_val = (int16_t) effectIntensity + amount; int16_t new_val = (int16_t) effectIntensity + amount;
effectIntensity = (byte)constrain(new_val,0,255); effectIntensity = (byte)constrain(new_val,0,255);
if (irApplyToAllSelected) { if (irApplyToAllSelected) {
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
seg.intensity = effectIntensity; seg.intensity = effectIntensity;
} }
@ -184,7 +184,7 @@ void changeEffectIntensity(int8_t amount)
setValuesFromMainSeg(); setValuesFromMainSeg();
} }
} else { // if Effect == "solid Color", change the saturation of the primary color } else { // if Effect == "solid Color", change the saturation of the primary color
WS2812FX::Segment& sseg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment(); Segment& sseg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment();
CRGB fastled_col; CRGB fastled_col;
fastled_col.red = R(sseg.colors[0]); fastled_col.red = R(sseg.colors[0]);
fastled_col.green = G(sseg.colors[0]); fastled_col.green = G(sseg.colors[0]);
@ -194,8 +194,8 @@ void changeEffectIntensity(int8_t amount)
prim_hsv.s = (byte)constrain(new_val,0,255); // constrain to 0-255 prim_hsv.s = (byte)constrain(new_val,0,255); // constrain to 0-255
hsv2rgb_rainbow(prim_hsv, fastled_col); hsv2rgb_rainbow(prim_hsv, fastled_col);
if (irApplyToAllSelected) { if (irApplyToAllSelected) {
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
seg.colors[0] = RGBW32(fastled_col.red, fastled_col.green, fastled_col.blue, W(sseg.colors[0])); seg.colors[0] = RGBW32(fastled_col.red, fastled_col.green, fastled_col.blue, W(sseg.colors[0]));
} }
@ -216,36 +216,38 @@ void changeColor(uint32_t c, int16_t cct=-1)
{ {
if (irApplyToAllSelected) { if (irApplyToAllSelected) {
// main segment may not be selected! // main segment may not be selected!
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (!seg.isActive() || !seg.isSelected()) continue; if (!seg.isActive() || !seg.isSelected()) continue;
byte capabilities = seg.getLightCapabilities(); byte capabilities = seg.getLightCapabilities();
uint32_t mask = 0; uint32_t mask = 0;
bool isRGB = GET_BIT(capabilities, 0); // when RGBW_MODE_AUTO_ACCURATE this is always true bool isRGB = GET_BIT(capabilities, 0); // is segment RGB capable
bool hasW = GET_BIT(capabilities, 1); bool hasW = GET_BIT(capabilities, 1); // do we have white/CCT channel
bool isCCT = GET_BIT(capabilities, 2); bool isCCT = GET_BIT(capabilities, 2); // is segment CCT capable
bool wSlider = GET_BIT(capabilities, 3); // is white auto calculated (white slider NOT shown in UI)
if (isRGB) mask |= 0x00FFFFFF; // RGB if (isRGB) mask |= 0x00FFFFFF; // RGB
if (hasW) mask |= 0xFF000000; // white if (hasW) mask |= 0xFF000000; // white
if (hasW && (strip.autoWhiteMode == RGBW_MODE_AUTO_ACCURATE) && (c & 0xFF000000)) { // white channel & white specified if (hasW && !wSlider && (c & 0xFF000000)) { // segment has white channel & white channel is auto calculated & white specified
seg.setColor(0, c | 0xFFFFFF, i); // for accurate mode we fake white seg.setColor(0, c | 0xFFFFFF); // for accurate/brighter mode we fake white (since button may not set white color to 0xFFFFFF)
} else if (c & mask) seg.setColor(0, c & mask, i); // only apply if not black } else if (c & mask) seg.setColor(0, c & mask); // only apply if not black
if (isCCT && cct >= 0) seg.setCCT(cct, i); if (isCCT && cct >= 0) seg.setCCT(cct);
} }
setValuesFromFirstSelectedSeg(); setValuesFromFirstSelectedSeg();
} else { } else {
byte i = strip.getMainSegmentId(); byte i = strip.getMainSegmentId();
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
byte capabilities = seg.getLightCapabilities(); byte capabilities = seg.getLightCapabilities();
uint32_t mask = 0; uint32_t mask = 0;
bool isRGB = GET_BIT(capabilities, 0); bool isRGB = GET_BIT(capabilities, 0); // is segment RGB capable
bool hasW = GET_BIT(capabilities, 1); bool hasW = GET_BIT(capabilities, 1); // do we have white/CCT channel
bool isCCT = GET_BIT(capabilities, 2); bool isCCT = GET_BIT(capabilities, 2); // is segment CCT capable
bool wSlider = GET_BIT(capabilities, 3); // is white auto calculated (white slider NOT shown in UI)
if (isRGB) mask |= 0x00FFFFFF; // RGB if (isRGB) mask |= 0x00FFFFFF; // RGB
if (hasW) mask |= 0xFF000000; // white if (hasW) mask |= 0xFF000000; // white
if (hasW && (strip.autoWhiteMode == RGBW_MODE_AUTO_ACCURATE) && (c & 0xFF000000)) { // white channel & white specified if (hasW && !wSlider && (c & 0xFF000000)) { // segment has white channel & white channel is auto calculated & white specified
seg.setColor(0, c | 0xFFFFFF, i); // for accurate mode we fake white seg.setColor(0, c | 0xFFFFFF); // for accurate/brighter mode we fake white (since button may not set white color to 0xFFFFFF)
} else if (c & mask) seg.setColor(0, c & mask, i); // only apply if not black } else if (c & mask) seg.setColor(0, c & mask); // only apply if not black
if (isCCT && cct >= 0) seg.setCCT(cct, i); if (isCCT && cct >= 0) seg.setCCT(cct);
setValuesFromMainSeg(); setValuesFromMainSeg();
} }
stateChanged = true; stateChanged = true;
@ -253,7 +255,7 @@ void changeColor(uint32_t c, int16_t cct=-1)
void changeWhite(int8_t amount, int16_t cct=-1) void changeWhite(int8_t amount, int16_t cct=-1)
{ {
WS2812FX::Segment& seg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment(); Segment& seg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment();
byte r = R(seg.colors[0]); byte r = R(seg.colors[0]);
byte g = G(seg.colors[0]); byte g = G(seg.colors[0]);
byte b = B(seg.colors[0]); byte b = B(seg.colors[0]);
@ -424,7 +426,7 @@ void decodeIR24CT(uint32_t code)
void decodeIR40(uint32_t code) void decodeIR40(uint32_t code)
{ {
WS2812FX::Segment& seg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment(); Segment& seg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment();
byte r = R(seg.colors[0]); byte r = R(seg.colors[0]);
byte g = G(seg.colors[0]); byte g = G(seg.colors[0]);
byte b = B(seg.colors[0]); byte b = B(seg.colors[0]);
@ -502,8 +504,8 @@ void decodeIR44(uint32_t code)
case IR44_WARMWHITE : changeColor(COLOR_WARMWHITE, 63); changeEffect(FX_MODE_STATIC); break; case IR44_WARMWHITE : changeColor(COLOR_WARMWHITE, 63); changeEffect(FX_MODE_STATIC); break;
case IR44_COLDWHITE : changeColor(COLOR_COLDWHITE, 191); changeEffect(FX_MODE_STATIC); break; case IR44_COLDWHITE : changeColor(COLOR_COLDWHITE, 191); changeEffect(FX_MODE_STATIC); break;
case IR44_COLDWHITE2 : changeColor(COLOR_COLDWHITE2, 255); changeEffect(FX_MODE_STATIC); break; case IR44_COLDWHITE2 : changeColor(COLOR_COLDWHITE2, 255); changeEffect(FX_MODE_STATIC); break;
case IR44_REDPLUS : changeEffect(relativeChange(effectCurrent, 1, 0, MODE_COUNT -1)); break; case IR44_REDPLUS : changeEffect(relativeChange(effectCurrent, 1, 0, strip.getModeCount() -1)); break;
case IR44_REDMINUS : changeEffect(relativeChange(effectCurrent, -1, 0, MODE_COUNT -1)); break; case IR44_REDMINUS : changeEffect(relativeChange(effectCurrent, -1, 0, strip.getModeCount() -1)); break;
case IR44_GREENPLUS : changePalette(relativeChange(effectPalette, 1, 0, strip.getPaletteCount() -1)); break; case IR44_GREENPLUS : changePalette(relativeChange(effectPalette, 1, 0, strip.getPaletteCount() -1)); break;
case IR44_GREENMINUS : changePalette(relativeChange(effectPalette, -1, 0, strip.getPaletteCount() -1)); break; case IR44_GREENMINUS : changePalette(relativeChange(effectPalette, -1, 0, strip.getPaletteCount() -1)); break;
case IR44_BLUEPLUS : changeEffectIntensity( 16); break; case IR44_BLUEPLUS : changeEffectIntensity( 16); break;
@ -562,7 +564,7 @@ void decodeIR6(uint32_t code)
case IR6_POWER: toggleOnOff(); break; case IR6_POWER: toggleOnOff(); break;
case IR6_CHANNEL_UP: incBrightness(); break; case IR6_CHANNEL_UP: incBrightness(); break;
case IR6_CHANNEL_DOWN: decBrightness(); break; case IR6_CHANNEL_DOWN: decBrightness(); break;
case IR6_VOLUME_UP: changeEffect(relativeChange(effectCurrent, 1, 0, MODE_COUNT -1)); break; case IR6_VOLUME_UP: changeEffect(relativeChange(effectCurrent, 1, 0, strip.getModeCount() -1)); break;
case IR6_VOLUME_DOWN: changePalette(relativeChange(effectPalette, 1, 0, strip.getPaletteCount() -1)); case IR6_VOLUME_DOWN: changePalette(relativeChange(effectPalette, 1, 0, strip.getPaletteCount() -1));
switch(lastIR6ColourIdx) { switch(lastIR6ColourIdx) {
case 0: changeColor(COLOR_RED); break; case 0: changeColor(COLOR_RED); break;
@ -600,7 +602,7 @@ void decodeIR9(uint32_t code)
case IR9_DOWN : decBrightness(); break; case IR9_DOWN : decBrightness(); break;
case IR9_LEFT : changeEffectSpeed(-16); break; case IR9_LEFT : changeEffectSpeed(-16); break;
case IR9_RIGHT : changeEffectSpeed(16); break; case IR9_RIGHT : changeEffectSpeed(16); break;
case IR9_SELECT : changeEffect(relativeChange(effectCurrent, 1, 0, MODE_COUNT -1)); break; case IR9_SELECT : changeEffect(relativeChange(effectCurrent, 1, 0, strip.getModeCount() -1)); break;
default: return; default: return;
} }
lastValidCode = code; lastValidCode = code;
@ -637,11 +639,7 @@ void decodeIRJson(uint32_t code)
JsonObject fdo; JsonObject fdo;
JsonObject jsonCmdObj; JsonObject jsonCmdObj;
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock(13)) return; if (!requestJSONBufferLock(13)) return;
#endif
sprintf_P(objKey, PSTR("\"0x%lX\":"), (unsigned long)code); sprintf_P(objKey, PSTR("\"0x%lX\":"), (unsigned long)code);
@ -674,7 +672,7 @@ void decodeIRJson(uint32_t code)
decBrightness(); decBrightness();
} else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback } else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback
uint8_t p1 = fdo["PL"] | 1; uint8_t p1 = fdo["PL"] | 1;
uint8_t p2 = fdo["FX"] | random8(MODE_COUNT -1); uint8_t p2 = fdo["FX"] | random8(strip.getModeCount() -1);
uint8_t p3 = fdo["FP"] | 0; uint8_t p3 = fdo["FP"] | 0;
presetFallback(p1, p2, p3); presetFallback(p1, p2, p3);
} }
@ -716,7 +714,7 @@ void initIR()
void handleIR() void handleIR()
{ {
if (irEnabled > 0 && millis() - irCheckedTime > 120) if (irEnabled > 0 && millis() - irCheckedTime > 120 && !strip.isUpdating())
{ {
irCheckedTime = millis(); irCheckedTime = millis();
if (irEnabled > 0) if (irEnabled > 0)
@ -730,7 +728,7 @@ void handleIR()
{ {
if (results.value != 0) // only print results if anything is received ( != 0 ) if (results.value != 0) // only print results if anything is received ( != 0 )
{ {
if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut) //GPIO 1 - Serial TX pin if (!pinManager.isPinAllocated(hardwareTX) || pinManager.getPinOwner(hardwareTX) == PinOwner::DebugOut) // Serial TX pin (GPIO 1 on ESP32 and ESP8266)
Serial.printf_P(PSTR("IR recv: 0x%lX\n"), (unsigned long)results.value); Serial.printf_P(PSTR("IR recv: 0x%lX\n"), (unsigned long)results.value);
} }
decodeIR(results.value); decodeIR(results.value);

View File

@ -6,35 +6,31 @@
* JSON API (De)serialization * JSON API (De)serialization
*/ */
bool getVal(JsonVariant elem, byte* val, byte vmin=0, byte vmax=255) {
if (elem.is<int>()) {
if (elem < 0) return false; //ignore e.g. {"ps":-1}
*val = elem;
return true;
} else if (elem.is<const char*>()) {
const char* str = elem;
size_t len = strnlen(str, 12);
if (len == 0 || len > 10) return false;
parseNumber(str, val, vmin, vmax);
return true;
}
return false; //key does not exist
}
void deserializeSegment(JsonObject elem, byte it, byte presetId) void deserializeSegment(JsonObject elem, byte it, byte presetId)
{ {
byte id = elem["id"] | it; byte id = elem["id"] | it;
if (id >= strip.getMaxSegments()) return; if (id >= strip.getMaxSegments()) return;
WS2812FX::Segment& seg = strip.getSegment(id); int stop = elem["stop"] | -1;
WS2812FX::Segment prev = seg; //make a backup so we can tell if something changed
// if using vectors use this code to append segment
if (id >= strip.getSegmentsNum()) {
if (stop <= 0) return; // ignore empty/inactive segments
strip.appendSegment(Segment(0, strip.getLengthTotal()));
id = strip.getSegmentsNum()-1; // segments are added at the end of list
}
Segment& seg = strip.getSegment(id);
Segment prev = seg; //make a backup so we can tell if something changed
uint16_t start = elem["start"] | seg.start; uint16_t start = elem["start"] | seg.start;
int stop = elem["stop"] | -1;
if (stop < 0) { if (stop < 0) {
uint16_t len = elem["len"]; uint16_t len = elem["len"];
stop = (len > 0) ? start + len : seg.stop; stop = (len > 0) ? start + len : seg.stop;
} }
// 2D segments
uint16_t startY = elem["startY"] | seg.startY;
uint16_t stopY = elem["stopY"] | seg.stopY;
//repeat, multiplies segment until all LEDs are used, or max segments reached //repeat, multiplies segment until all LEDs are used, or max segments reached
bool repeat = elem["rpt"] | false; bool repeat = elem["rpt"] | false;
@ -43,9 +39,10 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
elem.remove("rpt"); // remove for recursive call elem.remove("rpt"); // remove for recursive call
elem.remove("n"); // remove for recursive call elem.remove("n"); // remove for recursive call
uint16_t len = stop - start; uint16_t len = stop - start;
for (byte i=id+1; i<strip.getMaxSegments(); i++) { for (size_t i=id+1; i<strip.getMaxSegments(); i++) {
start = start + len; start = start + len;
if (start >= strip.getLengthTotal()) break; if (start >= strip.getLengthTotal()) break;
//TODO: add support for 2D
elem["start"] = start; elem["start"] = start;
elem["stop"] = start + len; elem["stop"] = start + len;
elem["rev"] = !elem["rev"]; // alternate reverse on even/odd segments elem["rev"] = !elem["rev"]; // alternate reverse on even/odd segments
@ -82,6 +79,13 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
uint16_t grp = elem["grp"] | seg.grouping; uint16_t grp = elem["grp"] | seg.grouping;
uint16_t spc = elem[F("spc")] | seg.spacing; uint16_t spc = elem[F("spc")] | seg.spacing;
uint16_t of = seg.offset; uint16_t of = seg.offset;
uint8_t soundSim = elem["ssim"] | seg.soundSim;
uint8_t map1D2D = elem["mp12"] | seg.map1D2D;
if ((spc>0 && spc!=seg.spacing) || seg.map1D2D!=map1D2D) seg.fill(BLACK); // clear spacing gaps
seg.map1D2D = constrain(map1D2D, 0, 7);
seg.soundSim = constrain(soundSim, 0, 7);
uint16_t len = 1; uint16_t len = 1;
if (stop > start) len = stop - start; if (stop > start) len = stop - start;
@ -93,27 +97,27 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
of = offsetAbs; of = offsetAbs;
} }
if (stop > start && of > len -1) of = len -1; if (stop > start && of > len -1) of = len -1;
strip.setSegment(id, start, stop, grp, spc, of); strip.setSegment(id, start, stop, grp, spc, of, startY, stopY);
byte segbri = seg.opacity; byte segbri = seg.opacity;
if (getVal(elem["bri"], &segbri)) { if (getVal(elem["bri"], &segbri)) {
if (segbri > 0) seg.setOpacity(segbri, id); if (segbri > 0) seg.setOpacity(segbri);
seg.setOption(SEG_OPTION_ON, segbri, id); seg.setOption(SEG_OPTION_ON, segbri); // use transition
} }
bool on = elem["on"] | seg.getOption(SEG_OPTION_ON); bool on = elem["on"] | seg.on;
if (elem["on"].is<const char*>() && elem["on"].as<const char*>()[0] == 't') on = !on; if (elem["on"].is<const char*>() && elem["on"].as<const char*>()[0] == 't') on = !on;
seg.setOption(SEG_OPTION_ON, on, id); seg.setOption(SEG_OPTION_ON, on); // use transition
bool frz = elem["frz"] | seg.getOption(SEG_OPTION_FREEZE); bool frz = elem["frz"] | seg.freeze;
if (elem["frz"].is<const char*>() && elem["frz"].as<const char*>()[0] == 't') frz = !seg.getOption(SEG_OPTION_FREEZE); if (elem["frz"].is<const char*>() && elem["frz"].as<const char*>()[0] == 't') frz = !seg.freeze;
seg.setOption(SEG_OPTION_FREEZE, frz, id); seg.freeze = frz;
seg.setCCT(elem["cct"] | seg.cct, id); seg.setCCT(elem["cct"] | seg.cct);
JsonArray colarr = elem["col"]; JsonArray colarr = elem["col"];
if (!colarr.isNull()) if (!colarr.isNull())
{ {
for (uint8_t i = 0; i < 3; i++) for (size_t i = 0; i < 3; i++)
{ {
int rgbw[] = {0,0,0,0}; int rgbw[] = {0,0,0,0};
bool colValid = false; bool colValid = false;
@ -124,13 +128,13 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
if (hexCol == nullptr) { //Kelvin color temperature (or invalid), e.g 2400 if (hexCol == nullptr) { //Kelvin color temperature (or invalid), e.g 2400
int kelvin = colarr[i] | -1; int kelvin = colarr[i] | -1;
if (kelvin < 0) continue; if (kelvin < 0) continue;
if (kelvin == 0) seg.setColor(i, 0, id); if (kelvin == 0) seg.setColor(i, 0);
if (kelvin > 0) colorKtoRGB(kelvin, brgbw); if (kelvin > 0) colorKtoRGB(kelvin, brgbw);
colValid = true; colValid = true;
} else { //HEX string, e.g. "FFAA00" } else { //HEX string, e.g. "FFAA00"
colValid = colorFromHexString(brgbw, hexCol); colValid = colorFromHexString(brgbw, hexCol);
} }
for (uint8_t c = 0; c < 4; c++) rgbw[c] = brgbw[c]; for (size_t c = 0; c < 4; c++) rgbw[c] = brgbw[c];
} else { //Array of ints (RGB or RGBW color), e.g. [255,160,0] } else { //Array of ints (RGB or RGBW color), e.g. [255,160,0]
byte sz = colX.size(); byte sz = colX.size();
if (sz == 0) continue; //do nothing on empty array if (sz == 0) continue; //do nothing on empty array
@ -141,7 +145,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
if (!colValid) continue; if (!colValid) continue;
seg.setColor(i, RGBW32(rgbw[0],rgbw[1],rgbw[2],rgbw[3]), id); seg.setColor(i, RGBW32(rgbw[0],rgbw[1],rgbw[2],rgbw[3]));
if (seg.mode == FX_MODE_STATIC) strip.trigger(); //instant refresh if (seg.mode == FX_MODE_STATIC) strip.trigger(); //instant refresh
} }
} }
@ -158,40 +162,55 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
} }
#endif #endif
seg.setOption(SEG_OPTION_SELECTED, elem[F("sel")] | seg.getOption(SEG_OPTION_SELECTED)); seg.selected = elem["sel"] | seg.selected;
seg.setOption(SEG_OPTION_REVERSED, elem["rev"] | seg.getOption(SEG_OPTION_REVERSED)); seg.reverse = elem["rev"] | seg.reverse;
seg.setOption(SEG_OPTION_MIRROR , elem[F("mi")] | seg.getOption(SEG_OPTION_MIRROR )); seg.mirror = elem["mi"] | seg.mirror;
#ifndef WLED_DISABLE_2D
seg.reverse_y = elem["rY"] | seg.reverse_y;
seg.mirror_y = elem["mY"] | seg.mirror_y;
seg.transpose = elem[F("tp")] | seg.transpose;
#endif
byte fx = seg.mode; byte fx = seg.mode;
if (getVal(elem["fx"], &fx, 1, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 1-255 exact value) if (getVal(elem["fx"], &fx, 0, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 0-255 exact value)
if (!presetId && currentPlaylist>=0) unloadPlaylist(); if (!presetId && currentPlaylist>=0) unloadPlaylist();
strip.setMode(id, fx); if (fx != seg.mode) seg.setMode(fx, elem[F("fxdef")]);
} }
//getVal also supports inc/decrementing and random //getVal also supports inc/decrementing and random
getVal(elem[F("sx")], &seg.speed, 0, 255); getVal(elem["sx"], &seg.speed);
getVal(elem[F("ix")], &seg.intensity, 0, 255); getVal(elem["ix"], &seg.intensity);
getVal(elem["pal"], &seg.palette, 1, strip.getPaletteCount());
uint8_t pal = seg.palette;
if (getVal(elem["pal"], &pal, 1, strip.getPaletteCount())) seg.setPalette(pal);
getVal(elem["c1"], &seg.custom1);
getVal(elem["c2"], &seg.custom2);
uint8_t cust3 = seg.custom3;
getVal(elem["c3"], &cust3); // we can't pass reference to bifield
seg.custom3 = constrain(cust3, 0, 31);
seg.check1 = elem["o1"] | seg.check1;
seg.check2 = elem["o2"] | seg.check2;
seg.check3 = elem["o3"] | seg.check3;
JsonArray iarr = elem[F("i")]; //set individual LEDs JsonArray iarr = elem[F("i")]; //set individual LEDs
if (!iarr.isNull()) { if (!iarr.isNull()) {
uint8_t oldSegId = strip.setPixelSegment(id);
// set brightness immediately and disable transition // set brightness immediately and disable transition
transitionDelayTemp = 0; transitionDelayTemp = 0;
jsonTransitionOnce = true; jsonTransitionOnce = true;
strip.setBrightness(scaledBri(bri), true); strip.setBrightness(scaledBri(bri), true);
// freeze and init to black // freeze and init to black
if (!seg.getOption(SEG_OPTION_FREEZE)) { if (!seg.freeze) {
seg.setOption(SEG_OPTION_FREEZE, true); seg.freeze = true;
strip.fill(0); seg.fill(BLACK);
} }
uint16_t start = 0, stop = 0; uint16_t start = 0, stop = 0;
byte set = 0; //0 nothing set, 1 start set, 2 range set byte set = 0; //0 nothing set, 1 start set, 2 range set
for (uint16_t i = 0; i < iarr.size(); i++) { for (size_t i = 0; i < iarr.size(); i++) {
if(iarr[i].is<JsonInteger>()) { if(iarr[i].is<JsonInteger>()) {
if (!set) { if (!set) {
start = iarr[i]; start = iarr[i];
@ -201,7 +220,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
set = 2; set = 2;
} }
} else { //color } else { //color
int rgbw[] = {0,0,0,0}; uint8_t rgbw[] = {0,0,0,0};
JsonArray icol = iarr[i]; JsonArray icol = iarr[i];
if (!icol.isNull()) { //array, e.g. [255,0,0] if (!icol.isNull()) { //array, e.g. [255,0,0]
byte sz = icol.size(); byte sz = icol.size();
@ -210,35 +229,28 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
byte brgbw[] = {0,0,0,0}; byte brgbw[] = {0,0,0,0};
const char* hexCol = iarr[i]; const char* hexCol = iarr[i];
if (colorFromHexString(brgbw, hexCol)) { if (colorFromHexString(brgbw, hexCol)) {
for (uint8_t c = 0; c < 4; c++) rgbw[c] = brgbw[c]; for (size_t c = 0; c < 4; c++) rgbw[c] = brgbw[c];
} }
} }
if (set < 2) stop = start + 1; if (set < 2) stop = start + 1;
for (uint16_t i = start; i < stop; i++) { uint32_t c = gamma32(RGBW32(rgbw[0], rgbw[1], rgbw[2], rgbw[3]));
if (strip.gammaCorrectCol) { for (int i = start; i < stop; i++) {
strip.setPixelColor(i, strip.gamma8(rgbw[0]), strip.gamma8(rgbw[1]), strip.gamma8(rgbw[2]), strip.gamma8(rgbw[3])); seg.setPixelColor(i, c);
} else {
strip.setPixelColor(i, rgbw[0], rgbw[1], rgbw[2], rgbw[3]);
}
} }
if (!set) start++; if (!set) start++;
set = 0; set = 0;
} }
} }
strip.setPixelSegment(oldSegId);
strip.trigger(); strip.trigger();
// } else if (!elem["frz"] && iarr.isNull()) { //return to regular effect
// seg.setOption(SEG_OPTION_FREEZE, false);
} }
// send UDP if not in preset and something changed that is not just selection // send UDP if not in preset and something changed that is not just selection
//if (!presetId && (seg.differs(prev) & 0x7F)) stateChanged = true; // send UDP if something changed that is not just selection or segment power/opacity
// send UDP if something changed that is not just selection if ((seg.differs(prev) & 0x7E) && seg.on == prev.on) stateChanged = true;
if (seg.differs(prev) & 0x7F) stateChanged = true;
return;
} }
// deserializes WLED state (fileDoc points to doc object if called from web server) // deserializes WLED state (fileDoc points to doc object if called from web server)
// presetId is non-0 if called from handlePreset()
bool deserializeState(JsonObject root, byte callMode, byte presetId) bool deserializeState(JsonObject root, byte callMode, byte presetId)
{ {
bool stateResponse = root[F("v")] | false; bool stateResponse = root[F("v")] | false;
@ -249,14 +261,16 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
bool on = root["on"] | (bri > 0); bool on = root["on"] | (bri > 0);
if (!on != !bri) toggleOnOff(); if (!on != !bri) toggleOnOff();
if (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't') toggleOnOff(); if (root["on"].is<const char*>() && root["on"].as<const char*>()[0] == 't') {
if (onBefore || !bri) toggleOnOff(); // do not toggle off again if just turned on by bri (makes e.g. "{"on":"t","bri":32}" work)
}
if (bri && !onBefore) { // unfreeze all segments when turning on if (bri && !onBefore) { // unfreeze all segments when turning on
for (uint8_t s=0; s < strip.getMaxSegments(); s++) { for (size_t s=0; s < strip.getSegmentsNum(); s++) {
strip.getSegment(s).setOption(SEG_OPTION_FREEZE, false, s); strip.getSegment(s).freeze = false;
} }
if (realtimeMode && !realtimeOverride && useMainSegmentOnly) { // keep live segment frozen if live if (realtimeMode && !realtimeOverride && useMainSegmentOnly) { // keep live segment frozen if live
strip.getMainSegment().setOption(SEG_OPTION_FREEZE, true, strip.getMainSegmentId()); strip.getMainSegment().freeze = true;
} }
} }
@ -271,6 +285,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
} }
} }
// temporary transition (applies only once)
tr = root[F("tt")] | -1; tr = root[F("tt")] | -1;
if (tr >= 0) if (tr >= 0)
{ {
@ -294,7 +309,7 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
receiveNotifications = udpn["recv"] | receiveNotifications; receiveNotifications = udpn["recv"] | receiveNotifications;
if ((bool)udpn[F("nn")]) callMode = CALL_MODE_NO_NOTIFY; //send no notification just for this request if ((bool)udpn[F("nn")]) callMode = CALL_MODE_NO_NOTIFY; //send no notification just for this request
unsigned long timein = root[F("time")] | UINT32_MAX; //backup time source if NTP not synced unsigned long timein = root["time"] | UINT32_MAX; //backup time source if NTP not synced
if (timein != UINT32_MAX) { if (timein != UINT32_MAX) {
setTimeFromAPI(timein); setTimeFromAPI(timein);
if (presetsModifiedTime == 0) presetsModifiedTime = timein; if (presetsModifiedTime == 0) presetsModifiedTime = timein;
@ -302,12 +317,13 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
doReboot = root[F("rb")] | doReboot; doReboot = root[F("rb")] | doReboot;
strip.setMainSegmentId(root[F("mainseg")] | strip.getMainSegmentId()); // must be before realtimeLock() if "live" // do not allow changing main segment while in realtime mode (may get odd results else)
if (!realtimeMode) strip.setMainSegmentId(root[F("mainseg")] | strip.getMainSegmentId()); // must be before realtimeLock() if "live"
realtimeOverride = root[F("lor")] | realtimeOverride; realtimeOverride = root[F("lor")] | realtimeOverride;
if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS; if (realtimeOverride > 2) realtimeOverride = REALTIME_OVERRIDE_ALWAYS;
if (realtimeMode && useMainSegmentOnly) { if (realtimeMode && useMainSegmentOnly) {
strip.getMainSegment().setOption(SEG_OPTION_FREEZE, !realtimeOverride, strip.getMainSegmentId()); strip.getMainSegment().freeze = !realtimeOverride;
} }
if (root.containsKey("live")) { if (root.containsKey("live")) {
@ -328,25 +344,22 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
//if "seg" is not an array and ID not specified, apply to all selected/checked segments //if "seg" is not an array and ID not specified, apply to all selected/checked segments
if (id < 0) { if (id < 0) {
//apply all selected segments //apply all selected segments
bool didSet = false; //bool didSet = false;
for (byte s = 0; s < strip.getMaxSegments(); s++) { for (size_t s = 0; s < strip.getSegmentsNum(); s++) {
WS2812FX::Segment &sg = strip.getSegment(s); Segment &sg = strip.getSegment(s);
if (sg.isActive()) {
if (sg.isSelected()) { if (sg.isSelected()) {
deserializeSegment(segVar, s, presetId); deserializeSegment(segVar, s, presetId);
didSet = true; //didSet = true;
} }
} }
} //TODO: not sure if it is good idea to change first active but unselected segment
//if none selected, apply to the main segment //if (!didSet) deserializeSegment(segVar, strip.getMainSegmentId(), presetId);
if (!didSet) deserializeSegment(segVar, strip.getMainSegmentId(), presetId);
} else { } else {
deserializeSegment(segVar, id, presetId); //apply only the segment with the specified ID deserializeSegment(segVar, id, presetId); //apply only the segment with the specified ID
} }
} else { } else {
JsonArray segs = segVar.as<JsonArray>(); JsonArray segs = segVar.as<JsonArray>();
for (JsonObject elem : segs) for (JsonObject elem : segs) {
{
deserializeSegment(elem, it, presetId); deserializeSegment(elem, it, presetId);
it++; it++;
} }
@ -357,28 +370,40 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
loadLedmap = root[F("ledmap")] | loadLedmap; loadLedmap = root[F("ledmap")] | loadLedmap;
byte ps = root[F("psave")]; byte ps = root[F("psave")];
if (ps > 0) { if (ps > 0 && ps < 251) savePreset(ps, nullptr, root);
savePreset(ps, nullptr, root);
} else {
ps = root[F("pdel")]; //deletion ps = root[F("pdel")]; //deletion
if (ps > 0) { if (ps > 0 && ps < 251) deletePreset(ps);
deletePreset(ps);
}
ps = presetCycCurr; // HTTP API commands (must be handled before "ps")
if (getVal(root["ps"], &ps, presetCycMin, presetCycMax)) { //load preset (clears state request!)
if (!presetId) unloadPlaylist(); //stop playlist if preset changed manually
if (ps >= presetCycMin && ps <= presetCycMax) presetCycCurr = ps;
applyPreset(ps, callMode);
return stateResponse;
}
//HTTP API commands
const char* httpwin = root["win"]; const char* httpwin = root["win"];
if (httpwin) { if (httpwin) {
String apireq = "win&"; String apireq = "win"; apireq += '&'; // reduce flash string usage
apireq += httpwin; apireq += httpwin;
handleSet(nullptr, apireq, false); handleSet(nullptr, apireq, false); // may set stateChanged
}
// applying preset (2 cases: a) API call includes all preset values, b) API only specifies preset ID)
if (!root["ps"].isNull()) {
ps = presetCycCurr;
if (stateChanged) {
// a) already applied preset content (requires "seg" or "win" but will ignore the rest)
currentPreset = root["ps"] | currentPreset;
// if preset contains HTTP API call do not change presetCycCurr
if (root["win"].isNull()) presetCycCurr = currentPreset;
stateChanged = false; // cancel state change update (preset was set directly by applying values stored in UI JSON array)
} else if (root["win"].isNull() && getVal(root["ps"], &ps, 0, 0) && ps > 0 && ps < 251 && ps != currentPreset) {
// b) preset ID only or preset that does not change state (use embedded cycling limits if they exist in getVal())
presetCycCurr = ps;
presetId = ps;
root.remove("v"); // may be added in UI call
root.remove("time"); // may be added in UI call
root.remove("ps");
if (root.size() == 0) {
unloadPlaylist(); // we need to unload playlist
applyPreset(ps, callMode); // async load (only preset ID was specified)
return stateResponse;
}
} }
} }
@ -387,8 +412,6 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
//do not notify here, because the first playlist entry will do //do not notify here, because the first playlist entry will do
if (root["on"].isNull()) callMode = CALL_MODE_NO_NOTIFY; if (root["on"].isNull()) callMode = CALL_MODE_NO_NOTIFY;
else callMode = CALL_MODE_DIRECT_CHANGE; // possible bugfix for playlist only containing HTTP API preset FX=~ else callMode = CALL_MODE_DIRECT_CHANGE; // possible bugfix for playlist only containing HTTP API preset FX=~
} else {
interfaceUpdateCallMode = CALL_MODE_WS_SEND;
} }
stateUpdated(callMode); stateUpdated(callMode);
@ -396,19 +419,23 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
return stateResponse; return stateResponse;
} }
void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool forPreset, bool segmentBounds) void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, bool segmentBounds)
{ {
root["id"] = id; root["id"] = id;
if (segmentBounds) { if (segmentBounds) {
root["start"] = seg.start; root["start"] = seg.start;
root["stop"] = seg.stop; root["stop"] = seg.stop;
if (strip.isMatrix) {
root[F("startY")] = seg.startY;
root[F("stopY")] = seg.stopY;
}
} }
if (!forPreset) root["len"] = seg.stop - seg.start; if (!forPreset) root["len"] = seg.stop - seg.start;
root["grp"] = seg.grouping; root["grp"] = seg.grouping;
root[F("spc")] = seg.spacing; root[F("spc")] = seg.spacing;
root[F("of")] = seg.offset; root[F("of")] = seg.offset;
root["on"] = seg.getOption(SEG_OPTION_ON); root["on"] = seg.on;
root["frz"] = seg.getOption(SEG_OPTION_FREEZE); root["frz"] = seg.freeze;
byte segbri = seg.opacity; byte segbri = seg.opacity;
root["bri"] = (segbri) ? segbri : 255; root["bri"] = (segbri) ? segbri : 255;
root["cct"] = seg.cct; root["cct"] = seg.cct;
@ -419,7 +446,7 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
// this will reduce RAM footprint from ~300 bytes to 84 bytes per segment // this will reduce RAM footprint from ~300 bytes to 84 bytes per segment
char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255) char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255)
const char *format = strip.hasWhiteChannel() ? PSTR("[%u,%u,%u,%u]") : PSTR("[%u,%u,%u]"); const char *format = strip.hasWhiteChannel() ? PSTR("[%u,%u,%u,%u]") : PSTR("[%u,%u,%u]");
for (uint8_t i = 0; i < 3; i++) for (size_t i = 0; i < 3; i++)
{ {
byte segcol[4]; byte* c = segcol; byte segcol[4]; byte* c = segcol;
segcol[0] = R(seg.colors[i]); segcol[0] = R(seg.colors[i]);
@ -434,15 +461,28 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
root["col"] = serialized(colstr); root["col"] = serialized(colstr);
root["fx"] = seg.mode; root["fx"] = seg.mode;
root[F("sx")] = seg.speed; root["sx"] = seg.speed;
root[F("ix")] = seg.intensity; root["ix"] = seg.intensity;
root["pal"] = seg.palette; root["pal"] = seg.palette;
root[F("sel")] = seg.isSelected(); root["c1"] = seg.custom1;
root["rev"] = seg.getOption(SEG_OPTION_REVERSED); root["c2"] = seg.custom2;
root[F("mi")] = seg.getOption(SEG_OPTION_MIRROR); root["c3"] = seg.custom3;
root["sel"] = seg.isSelected();
root["rev"] = seg.reverse;
root["mi"] = seg.mirror;
if (strip.isMatrix) {
root["rY"] = seg.reverse_y;
root["mY"] = seg.mirror_y;
root[F("tp")] = seg.transpose;
}
root["o1"] = seg.check1;
root["o2"] = seg.check2;
root["o3"] = seg.check3;
root["ssim"] = seg.soundSim;
root["mp12"] = seg.map1D2D;
} }
void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segmentBounds) void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segmentBounds, bool selectedSegmentsOnly)
{ {
if (includeBri) { if (includeBri) {
root["on"] = (bri > 0); root["on"] = (bri > 0);
@ -479,8 +519,17 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme
root[F("mainseg")] = strip.getMainSegmentId(); root[F("mainseg")] = strip.getMainSegmentId();
JsonArray seg = root.createNestedArray("seg"); JsonArray seg = root.createNestedArray("seg");
for (byte s = 0; s < strip.getMaxSegments(); s++) { for (size_t s = 0; s < strip.getMaxSegments(); s++) {
WS2812FX::Segment &sg = strip.getSegment(s); if (s >= strip.getSegmentsNum()) {
if (forPreset && segmentBounds && !selectedSegmentsOnly) { //disable segments not part of preset
JsonObject seg0 = seg.createNestedObject();
seg0["stop"] = 0;
continue;
} else
break;
}
Segment &sg = strip.getSegment(s);
if (forPreset && selectedSegmentsOnly && !sg.isSelected()) continue;
if (sg.isActive()) { if (sg.isActive()) {
JsonObject seg0 = seg.createNestedObject(); JsonObject seg0 = seg.createNestedObject();
serializeSegment(seg0, sg, s, forPreset, segmentBounds); serializeSegment(seg0, sg, s, forPreset, segmentBounds);
@ -491,26 +540,6 @@ void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segme
} }
} }
//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp
int getSignalQuality(int rssi)
{
int quality = 0;
if (rssi <= -100)
{
quality = 0;
}
else if (rssi >= -50)
{
quality = 100;
}
else
{
quality = 2 * (rssi + 100);
}
return quality;
}
void serializeInfo(JsonObject root) void serializeInfo(JsonObject root)
{ {
root[F("ver")] = versionString; root[F("ver")] = versionString;
@ -519,17 +548,27 @@ void serializeInfo(JsonObject root)
JsonObject leds = root.createNestedObject("leds"); JsonObject leds = root.createNestedObject("leds");
leds[F("count")] = strip.getLengthTotal(); leds[F("count")] = strip.getLengthTotal();
leds[F("pwr")] = strip.currentMilliamps; leds[F("pwr")] = strip.currentMilliamps;
leds["fps"] = strip.getFps(); leds["fps"] = strip.getFps();
leds[F("maxpwr")] = (strip.currentMilliamps)? strip.ablMilliampsMax : 0; leds[F("maxpwr")] = (strip.currentMilliamps)? strip.ablMilliampsMax : 0;
leds[F("maxseg")] = strip.getMaxSegments(); leds[F("maxseg")] = strip.getMaxSegments();
//leds[F("actseg")] = strip.getActiveSegmentsNum();
//leds[F("seglock")] = false; //might be used in the future to prevent modifications to segment config //leds[F("seglock")] = false; //might be used in the future to prevent modifications to segment config
leds[F("cpal")] = strip.customPalettes.size(); //number of custom palettes
#ifndef WLED_DISABLE_2D
if (strip.isMatrix) {
JsonObject matrix = leds.createNestedObject("matrix");
matrix["w"] = strip.matrixWidth;
matrix["h"] = strip.matrixHeight;
}
#endif
uint8_t totalLC = 0; uint8_t totalLC = 0;
JsonArray lcarr = leds.createNestedArray(F("seglc")); JsonArray lcarr = leds.createNestedArray(F("seglc"));
uint8_t nSegs = strip.getLastActiveSegmentId(); size_t nSegs = strip.getSegmentsNum();
for (byte s = 0; s <= nSegs; s++) { for (size_t s = 0; s < nSegs; s++) {
if (!strip.getSegment(s).isActive()) continue;
uint8_t lc = strip.getSegment(s).getLightCapabilities(); uint8_t lc = strip.getSegment(s).getLightCapabilities();
totalLC |= lc; totalLC |= lc;
lcarr.add(lc); lcarr.add(lc);
@ -541,13 +580,22 @@ void serializeInfo(JsonObject root)
leds[F("wv")] = totalLC & 0x02; // deprecated, true if white slider should be displayed for any segment leds[F("wv")] = totalLC & 0x02; // deprecated, true if white slider should be displayed for any segment
leds["cct"] = totalLC & 0x04; // deprecated, use info.leds.lc leds["cct"] = totalLC & 0x04; // deprecated, use info.leds.lc
#ifdef WLED_DEBUG
JsonArray i2c = root.createNestedArray(F("i2c"));
i2c.add(i2c_sda);
i2c.add(i2c_scl);
JsonArray spi = root.createNestedArray(F("spi"));
spi.add(spi_mosi);
spi.add(spi_sclk);
spi.add(spi_miso);
#endif
root[F("str")] = syncToggleReceive; root[F("str")] = syncToggleReceive;
root[F("name")] = serverDescription; root[F("name")] = serverDescription;
root[F("udpport")] = udpPort; root[F("udpport")] = udpPort;
root["live"] = (bool)realtimeMode; root["live"] = (bool)realtimeMode;
root[F("liveseg")] = useMainSegmentOnly ? strip.getMainSegmentId() : -1; // if using main segment only for live root[F("liveseg")] = useMainSegmentOnly ? strip.getMainSegmentId() : -1; // if using main segment only for live
//root[F("mso")] = useMainSegmentOnly; // using main segment only for live
switch (realtimeMode) { switch (realtimeMode) {
case REALTIME_MODE_INACTIVE: root["lm"] = ""; break; case REALTIME_MODE_INACTIVE: root["lm"] = ""; break;
@ -577,6 +625,11 @@ void serializeInfo(JsonObject root)
root[F("fxcount")] = strip.getModeCount(); root[F("fxcount")] = strip.getModeCount();
root[F("palcount")] = strip.getPaletteCount(); root[F("palcount")] = strip.getPaletteCount();
JsonArray ledmaps = root.createNestedArray(F("maps"));
for (size_t i=0; i<10; i++) {
if ((ledMaps>>i) & 0x0001) ledmaps.add(i);
}
JsonObject wifi_info = root.createNestedObject("wifi"); JsonObject wifi_info = root.createNestedObject("wifi");
wifi_info[F("bssid")] = WiFi.BSSIDstr(); wifi_info[F("bssid")] = WiFi.BSSIDstr();
int qrssi = WiFi.RSSI(); int qrssi = WiFi.RSSI();
@ -596,7 +649,11 @@ void serializeInfo(JsonObject root)
wifi_info[F("txPower")] = (int) WiFi.getTxPower(); wifi_info[F("txPower")] = (int) WiFi.getTxPower();
wifi_info[F("sleep")] = (bool) WiFi.getSleep(); wifi_info[F("sleep")] = (bool) WiFi.getSleep();
#endif #endif
#if !defined(CONFIG_IDF_TARGET_ESP32C2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32S3)
root[F("arch")] = "esp32"; root[F("arch")] = "esp32";
#else
root[F("arch")] = ESP.getChipModel();
#endif
root[F("core")] = ESP.getSdkVersion(); root[F("core")] = ESP.getSdkVersion();
//root[F("maxalloc")] = ESP.getMaxAllocHeap(); //root[F("maxalloc")] = ESP.getMaxAllocHeap();
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
@ -703,6 +760,7 @@ void setPaletteColors(JsonArray json, byte* tcp)
void serializePalettes(JsonObject root, AsyncWebServerRequest* request) void serializePalettes(JsonObject root, AsyncWebServerRequest* request)
{ {
byte tcp[72];
#ifdef ESP8266 #ifdef ESP8266
int itemPerPage = 5; int itemPerPage = 5;
#else #else
@ -715,19 +773,20 @@ void serializePalettes(JsonObject root, AsyncWebServerRequest* request)
} }
int palettesCount = strip.getPaletteCount(); int palettesCount = strip.getPaletteCount();
int customPalettes = strip.customPalettes.size();
int maxPage = (palettesCount -1) / itemPerPage; int maxPage = (palettesCount + customPalettes -1) / itemPerPage;
if (page > maxPage) page = maxPage; if (page > maxPage) page = maxPage;
int start = itemPerPage * page; int start = itemPerPage * page;
int end = start + itemPerPage; int end = start + itemPerPage;
if (end >= palettesCount) end = palettesCount; if (end > palettesCount + customPalettes) end = palettesCount + customPalettes;
root[F("m")] = maxPage; root[F("m")] = maxPage; // inform caller how many pages there are
JsonObject palettes = root.createNestedObject("p"); JsonObject palettes = root.createNestedObject("p");
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
JsonArray curPalette = palettes.createNestedArray(String(i)); JsonArray curPalette = palettes.createNestedArray(String(i>=palettesCount ? 255 - i + palettesCount : i));
switch (i) { switch (i) {
case 0: //default palette case 0: //default palette
setPaletteColors(curPalette, PartyColors_p); setPaletteColors(curPalette, PartyColors_p);
@ -752,8 +811,7 @@ void serializePalettes(JsonObject root, AsyncWebServerRequest* request)
curPalette.add("c2"); curPalette.add("c2");
curPalette.add("c1"); curPalette.add("c1");
break; break;
case 5: {//primary + secondary (+tert if not off), more distinct case 5: //primary + secondary (+tert if not off), more distinct
curPalette.add("c1"); curPalette.add("c1");
curPalette.add("c1"); curPalette.add("c1");
curPalette.add("c1"); curPalette.add("c1");
@ -770,7 +828,7 @@ void serializePalettes(JsonObject root, AsyncWebServerRequest* request)
curPalette.add("c3"); curPalette.add("c3");
curPalette.add("c3"); curPalette.add("c3");
curPalette.add("c1"); curPalette.add("c1");
break;} break;
case 6: //Party colors case 6: //Party colors
setPaletteColors(curPalette, PartyColors_p); setPaletteColors(curPalette, PartyColors_p);
break; break;
@ -792,14 +850,15 @@ void serializePalettes(JsonObject root, AsyncWebServerRequest* request)
case 12: //Rainbow stripe colors case 12: //Rainbow stripe colors
setPaletteColors(curPalette, RainbowStripeColors_p); setPaletteColors(curPalette, RainbowStripeColors_p);
break; break;
default: default:
if (i < 13) { {
break; if (i>=palettesCount) {
} setPaletteColors(curPalette, strip.customPalettes[i - palettesCount]);
byte tcp[72]; } else {
memcpy_P(tcp, (byte*)pgm_read_dword(&(gGradientPalettes[i - 13])), 72); memcpy_P(tcp, (byte*)pgm_read_dword(&(gGradientPalettes[i - 13])), 72);
setPaletteColors(curPalette, tcp); setPaletteColors(curPalette, tcp);
}
}
break; break;
} }
} }
@ -823,6 +882,33 @@ void serializeNodes(JsonObject root)
} }
} }
void serializeModeData(JsonArray fxdata)
{
char lineBuffer[128];
for (size_t i = 0; i < strip.getModeCount(); i++) {
strncpy_P(lineBuffer, strip.getModeData(i), 127);
if (lineBuffer[0] != 0) {
char* dataPtr = strchr(lineBuffer,'@');
if (dataPtr) fxdata.add(dataPtr);
else fxdata.add("");
}
}
}
// deserializes mode names string into JsonArray
// also removes WLED-SR extensions (@...) from deserialised names
void serializeModeNames(JsonArray arr) {
char lineBuffer[128];
for (size_t i = 0; i < strip.getModeCount(); i++) {
strncpy_P(lineBuffer, strip.getModeData(i), 127);
if (lineBuffer[0] != 0) {
char* dataPtr = strchr(lineBuffer,'@');
if (dataPtr) *dataPtr = 0; // terminate mode data after name
arr.add(lineBuffer);
}
}
}
void serveJson(AsyncWebServerRequest* request) void serveJson(AsyncWebServerRequest* request)
{ {
byte subJson = 0; byte subJson = 0;
@ -832,6 +918,7 @@ void serveJson(AsyncWebServerRequest* request)
else if (url.indexOf("si") > 0) subJson = 3; else if (url.indexOf("si") > 0) subJson = 3;
else if (url.indexOf("nodes") > 0) subJson = 4; else if (url.indexOf("nodes") > 0) subJson = 4;
else if (url.indexOf("palx") > 0) subJson = 5; else if (url.indexOf("palx") > 0) subJson = 5;
else if (url.indexOf("fxda") > 0) subJson = 6;
#ifdef WLED_ENABLE_JSONLIVE #ifdef WLED_ENABLE_JSONLIVE
else if (url.indexOf("live") > 0) { else if (url.indexOf("live") > 0) {
serveLiveLeds(request); serveLiveLeds(request);
@ -839,7 +926,17 @@ void serveJson(AsyncWebServerRequest* request)
} }
#endif #endif
else if (url.indexOf(F("eff")) > 0) { else if (url.indexOf(F("eff")) > 0) {
request->send_P(200, "application/json", JSON_mode_names); // this serves just effect names without FX data extensions in names
if (requestJSONBufferLock(19)) {
AsyncJsonResponse* response = new AsyncJsonResponse(&doc, true); // array document
JsonArray lDoc = response->getRoot();
serializeModeNames(lDoc); // remove WLED-SR extensions from effect names
response->setLength();
request->send(response);
releaseJSONBufferLock();
} else {
request->send(503, "application/json", F("{\"error\":3}"));
}
return; return;
} }
else if (url.indexOf("pal") > 0) { else if (url.indexOf("pal") > 0) {
@ -854,14 +951,13 @@ void serveJson(AsyncWebServerRequest* request)
return; return;
} }
#ifdef WLED_USE_DYNAMIC_JSON if (!requestJSONBufferLock(17)) {
AsyncJsonResponse* response = new AsyncJsonResponse(JSON_BUFFER_SIZE); request->send(503, "application/json", F("{\"error\":3}"));
#else return;
if (!requestJSONBufferLock(17)) return; }
AsyncJsonResponse *response = new AsyncJsonResponse(&doc); AsyncJsonResponse *response = new AsyncJsonResponse(&doc, subJson==6);
#endif
JsonObject lDoc = response->getRoot(); JsonVariant lDoc = response->getRoot();
switch (subJson) switch (subJson)
{ {
@ -873,6 +969,8 @@ void serveJson(AsyncWebServerRequest* request)
serializeNodes(lDoc); break; serializeNodes(lDoc); break;
case 5: //palettes case 5: //palettes
serializePalettes(lDoc, request); break; serializePalettes(lDoc, request); break;
case 6: // FX helper data
serializeModeData(lDoc.as<JsonArray>()); break;
default: //all default: //all
JsonObject state = lDoc.createNestedObject("state"); JsonObject state = lDoc.createNestedObject("state");
serializeState(state); serializeState(state);
@ -880,13 +978,14 @@ void serveJson(AsyncWebServerRequest* request)
serializeInfo(info); serializeInfo(info);
if (subJson != 3) if (subJson != 3)
{ {
doc[F("effects")] = serialized((const __FlashStringHelper*)JSON_mode_names); JsonArray effects = lDoc.createNestedArray(F("effects"));
doc[F("palettes")] = serialized((const __FlashStringHelper*)JSON_palette_names); serializeModeNames(effects); // remove WLED-SR extensions from effect names
lDoc[F("palettes")] = serialized((const __FlashStringHelper*)JSON_palette_names);
} }
//lDoc["m"] = lDoc.memoryUsage(); // JSON buffer usage, for remote debugging
} }
DEBUG_PRINT("JSON buffer size: "); DEBUG_PRINTF("JSON buffer size: %u for request: %d\n", lDoc.memoryUsage(), subJson);
DEBUG_PRINTLN(lDoc.memoryUsage());
response->setLength(); response->setLength();
request->send(response); request->send(response);
@ -913,7 +1012,7 @@ bool serveLiveLeds(AsyncWebServerRequest* request, uint32_t wsClient)
obuf = buffer; obuf = buffer;
olen = 9; olen = 9;
for (uint16_t i= 0; i < used; i += n) for (size_t i= 0; i < used; i += n)
{ {
uint32_t c = strip.getPixelColor(i); uint32_t c = strip.getPixelColor(i);
uint8_t r = qadd8(W(c), R(c)); //add white channel to RGB channels as a simple RGBW -> RGB map uint8_t r = qadd8(W(c), R(c)); //add white channel to RGB channels as a simple RGBW -> RGB map

View File

@ -8,7 +8,7 @@ void setValuesFromMainSeg() { setValuesFromSegment(strip.getMainSegment
void setValuesFromFirstSelectedSeg() { setValuesFromSegment(strip.getFirstSelectedSegId()); } void setValuesFromFirstSelectedSeg() { setValuesFromSegment(strip.getFirstSelectedSegId()); }
void setValuesFromSegment(uint8_t s) void setValuesFromSegment(uint8_t s)
{ {
WS2812FX::Segment& seg = strip.getSegment(s); Segment& seg = strip.getSegment(s);
col[0] = R(seg.colors[0]); col[0] = R(seg.colors[0]);
col[1] = G(seg.colors[0]); col[1] = G(seg.colors[0]);
col[2] = B(seg.colors[0]); col[2] = B(seg.colors[0]);
@ -30,9 +30,9 @@ void applyValuesToSelectedSegs()
{ {
// copy of first selected segment to tell if value was updated // copy of first selected segment to tell if value was updated
uint8_t firstSel = strip.getFirstSelectedSegId(); uint8_t firstSel = strip.getFirstSelectedSegId();
WS2812FX::Segment selsegPrev = strip.getSegment(firstSel); Segment selsegPrev = strip.getSegment(firstSel);
for (uint8_t i = 0; i < strip.getMaxSegments(); i++) { for (uint8_t i = 0; i < strip.getSegmentsNum(); i++) {
WS2812FX::Segment& seg = strip.getSegment(i); Segment& seg = strip.getSegment(i);
if (i != firstSel && (!seg.isActive() || !seg.isSelected())) continue; if (i != firstSel && (!seg.isActive() || !seg.isSelected())) continue;
if (effectSpeed != selsegPrev.speed) {seg.speed = effectSpeed; stateChanged = true;} if (effectSpeed != selsegPrev.speed) {seg.speed = effectSpeed; stateChanged = true;}
@ -41,8 +41,8 @@ void applyValuesToSelectedSegs()
if (effectCurrent != selsegPrev.mode) {strip.setMode(i, effectCurrent); stateChanged = true;} if (effectCurrent != selsegPrev.mode) {strip.setMode(i, effectCurrent); stateChanged = true;}
uint32_t col0 = RGBW32( col[0], col[1], col[2], col[3]); uint32_t col0 = RGBW32( col[0], col[1], col[2], col[3]);
uint32_t col1 = RGBW32(colSec[0], colSec[1], colSec[2], colSec[3]); uint32_t col1 = RGBW32(colSec[0], colSec[1], colSec[2], colSec[3]);
if (col0 != selsegPrev.colors[0]) {seg.setColor(0, col0, i); stateChanged = true;} if (col0 != selsegPrev.colors[0]) {seg.setColor(0, col0); stateChanged = true;}
if (col1 != selsegPrev.colors[1]) {seg.setColor(1, col1, i); stateChanged = true;} if (col1 != selsegPrev.colors[1]) {seg.setColor(1, col1); stateChanged = true;}
} }
} }
@ -63,6 +63,7 @@ void toggleOnOff()
briLast = bri; briLast = bri;
bri = 0; bri = 0;
} }
stateChanged = true;
} }
@ -130,7 +131,7 @@ void stateUpdated(byte callMode) {
if (fadeTransition) { if (fadeTransition) {
//set correct delay if not using notification delay //set correct delay if not using notification delay
if (callMode != CALL_MODE_NOTIFICATION && !jsonTransitionOnce) transitionDelayTemp = transitionDelay; if (callMode != CALL_MODE_NOTIFICATION && !jsonTransitionOnce) transitionDelayTemp = transitionDelay; // load actual transition duration
jsonTransitionOnce = false; jsonTransitionOnce = false;
strip.setTransition(transitionDelayTemp); strip.setTransition(transitionDelayTemp);
if (transitionDelayTemp == 0) { if (transitionDelayTemp == 0) {
@ -143,7 +144,7 @@ void stateUpdated(byte callMode) {
briOld = briT; briOld = briT;
tperLast = 0; tperLast = 0;
} }
strip.setTransitionMode(true); strip.setTransitionMode(true); // force all segments to transition mode
transitionActive = true; transitionActive = true;
transitionStartTime = millis(); transitionStartTime = millis();
} else { } else {
@ -171,17 +172,14 @@ void updateInterfaces(uint8_t callMode)
callMode != CALL_MODE_NO_NOTIFY) updateBlynk(); callMode != CALL_MODE_NO_NOTIFY) updateBlynk();
#endif #endif
doPublishMqtt = true; doPublishMqtt = true;
interfaceUpdateCallMode = 0; //disable
} }
void handleTransitions() void handleTransitions()
{ {
//handle still pending interface update //handle still pending interface update
if (interfaceUpdateCallMode && millis() - lastInterfaceUpdate > INTERFACE_UPDATE_COOLDOWN) if (interfaceUpdateCallMode && millis() - lastInterfaceUpdate > INTERFACE_UPDATE_COOLDOWN) updateInterfaces(interfaceUpdateCallMode);
{
updateInterfaces(interfaceUpdateCallMode);
interfaceUpdateCallMode = 0; //disable
}
if (doPublishMqtt) publishMqtt(); if (doPublishMqtt) publishMqtt();
if (transitionActive && transitionDelayTemp > 0) if (transitionActive && transitionDelayTemp > 0)
@ -213,13 +211,12 @@ void colorUpdated(byte callMode){
void handleNightlight() void handleNightlight()
{ {
/*
static unsigned long lastNlUpdate; static unsigned long lastNlUpdate;
unsigned long now = millis(); unsigned long now = millis();
if (now < 100 && lastNlUpdate > 0) lastNlUpdate = 0; //take care of millis() rollover if (now < 100 && lastNlUpdate > 0) lastNlUpdate = 0; //take care of millis() rollover
if (now - lastNlUpdate < 100) return; //allow only 10 NL updates per second if (now - lastNlUpdate < 100) return; //allow only 10 NL updates per second
lastNlUpdate = now; lastNlUpdate = now;
*/
if (nightlightActive) if (nightlightActive)
{ {
if (!nightlightActiveOld) //init if (!nightlightActiveOld) //init

View File

@ -69,7 +69,7 @@ void parseLxJson(int lxValue, byte segId, bool secondary)
} else { } else {
DEBUG_PRINT(F("LX: segment ")); DEBUG_PRINT(F("LX: segment "));
DEBUG_PRINTLN(segId); DEBUG_PRINTLN(segId);
strip.getSegment(segId).setColor(secondary, ((rgbw[3] << 24) | ((rgbw[0]&0xFF) << 16) | ((rgbw[1]&0xFF) << 8) | ((rgbw[2]&0xFF))), segId); strip.getSegment(segId).setColor(secondary, RGBW32(rgbw[0], rgbw[1], rgbw[2], rgbw[3]));
} }
} }
} }

View File

@ -90,20 +90,16 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
colorFromDecOrHexString(col, (char*)payloadStr); colorFromDecOrHexString(col, (char*)payloadStr);
colorUpdated(CALL_MODE_DIRECT_CHANGE); colorUpdated(CALL_MODE_DIRECT_CHANGE);
} else if (strcmp_P(topic, PSTR("/api")) == 0) { } else if (strcmp_P(topic, PSTR("/api")) == 0) {
if (!requestJSONBufferLock(15)) { delete[] payloadStr; return; }
if (payload[0] == '{') { //JSON API if (payload[0] == '{') { //JSON API
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock(15)) return;
#endif
deserializeJson(doc, payloadStr); deserializeJson(doc, payloadStr);
deserializeState(doc.as<JsonObject>()); deserializeState(doc.as<JsonObject>());
releaseJSONBufferLock();
} else { //HTTP API } else { //HTTP API
String apireq = "win&"; String apireq = "win"; apireq += '&'; // reduce flash string usage
apireq += (char*)payloadStr; apireq += (char*)payloadStr;
handleSet(nullptr, apireq); handleSet(nullptr, apireq);
} }
releaseJSONBufferLock();
} else if (strlen(topic) != 0) { } else if (strlen(topic) != 0) {
// non standard topic, check with usermods // non standard topic, check with usermods
usermods.onMqttMessage(topic, payloadStr); usermods.onMqttMessage(topic, payloadStr);

163
wled00/network.cpp Normal file
View File

@ -0,0 +1,163 @@
#include "wled.h"
#include "fcn_declare.h"
#include "wled_ethernet.h"
#ifdef WLED_USE_ETHERNET
// The following six pins are neither configurable nor
// can they be re-assigned through IOMUX / GPIO matrix.
// See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-ethernet-kit-v1.1.html#ip101gri-phy-interface
const managed_pin_type esp32_nonconfigurable_ethernet_pins[WLED_ETH_RSVD_PINS_COUNT] = {
{ 21, true }, // RMII EMAC TX EN == When high, clocks the data on TXD0 and TXD1 to transmitter
{ 19, true }, // RMII EMAC TXD0 == First bit of transmitted data
{ 22, true }, // RMII EMAC TXD1 == Second bit of transmitted data
{ 25, false }, // RMII EMAC RXD0 == First bit of received data
{ 26, false }, // RMII EMAC RXD1 == Second bit of received data
{ 27, true }, // RMII EMAC CRS_DV == Carrier Sense and RX Data Valid
};
const ethernet_settings ethernetBoards[] = {
// None
{
},
// WT32-EHT01
// Please note, from my testing only these pins work for LED outputs:
// IO2, IO4, IO12, IO14, IO15
// These pins do not appear to work from my testing:
// IO35, IO36, IO39
{
1, // eth_address,
16, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO0_IN // eth_clk_mode
},
// ESP32-POE
{
0, // eth_address,
12, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
},
// WESP32
{
0, // eth_address,
-1, // eth_power,
16, // eth_mdc,
17, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO0_IN // eth_clk_mode
},
// QuinLed-ESP32-Ethernet
{
0, // eth_address,
5, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
},
// TwilightLord-ESP32 Ethernet Shield
{
0, // eth_address,
5, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
},
// ESP3DEUXQuattro
{
1, // eth_address,
-1, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_LAN8720, // eth_type,
ETH_CLOCK_GPIO17_OUT // eth_clk_mode
},
// ESP32-ETHERNET-KIT-VE
{
0, // eth_address,
5, // eth_power,
23, // eth_mdc,
18, // eth_mdio,
ETH_PHY_IP101, // eth_type,
ETH_CLOCK_GPIO0_IN // eth_clk_mode
}
};
#endif
//by https://github.com/tzapu/WiFiManager/blob/master/WiFiManager.cpp
int getSignalQuality(int rssi)
{
int quality = 0;
if (rssi <= -100)
{
quality = 0;
}
else if (rssi >= -50)
{
quality = 100;
}
else
{
quality = 2 * (rssi + 100);
}
return quality;
}
//handle Ethernet connection event
void WiFiEvent(WiFiEvent_t event)
{
#ifdef WLED_USE_ETHERNET
char hostname[25] = "wled-";
#endif
switch (event) {
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
case SYSTEM_EVENT_ETH_START:
DEBUG_PRINT(F("ETH Started"));
break;
case SYSTEM_EVENT_ETH_CONNECTED:
DEBUG_PRINT(F("ETH Connected"));
if (!apActive) {
WiFi.disconnect(true);
}
if (staticIP != (uint32_t)0x00000000 && staticGateway != (uint32_t)0x00000000) {
ETH.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8));
} else {
ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
}
// convert the "serverDescription" into a valid DNS hostname (alphanumeric)
prepareHostname(hostname);
ETH.setHostname(hostname);
showWelcomePage = false;
break;
case SYSTEM_EVENT_ETH_DISCONNECTED:
DEBUG_PRINT(F("ETH Disconnected"));
// This doesn't really affect ethernet per se,
// as it's only configured once. Rather, it
// may be necessary to reconnect the WiFi when
// ethernet disconnects, as a way to provide
// alternative access to the device.
forceReconnect = true;
break;
#endif
default:
break;
}
}

View File

@ -1,6 +1,6 @@
#include "src/dependencies/timezone/Timezone.h" #include "src/dependencies/timezone/Timezone.h"
#include "wled.h" #include "wled.h"
#include "wled_math.h" #include "fcn_declare.h"
/* /*
* Acquires time from NTP server * Acquires time from NTP server
@ -32,6 +32,7 @@ Timezone* tz;
#define TZ_NOVOSIBIRSK 19 #define TZ_NOVOSIBIRSK 19
#define TZ_ANCHORAGE 20 #define TZ_ANCHORAGE 20
#define TZ_MX_CENTRAL 21 #define TZ_MX_CENTRAL 21
#define TZ_PAKISTAN 22
#define TZ_INIT 255 #define TZ_INIT 255
byte tzCurrent = TZ_INIT; //uninitialized byte tzCurrent = TZ_INIT; //uninitialized
@ -93,12 +94,12 @@ void updateTimezone() {
break; break;
} }
case TZ_AUSTRALIA_EASTERN : { case TZ_AUSTRALIA_EASTERN : {
tcrDaylight = {Second, Sun, Oct, 2, 660}; //AEDT = UTC + 11 hours tcrDaylight = {First, Sun, Oct, 2, 660}; //AEDT = UTC + 11 hours
tcrStandard = {First, Sun, Apr, 3, 600}; //AEST = UTC + 10 hours tcrStandard = {First, Sun, Apr, 3, 600}; //AEST = UTC + 10 hours
break; break;
} }
case TZ_NEW_ZEALAND : { case TZ_NEW_ZEALAND : {
tcrDaylight = {Second, Sun, Sep, 2, 780}; //NZDT = UTC + 13 hours tcrDaylight = {Last, Sun, Sep, 2, 780}; //NZDT = UTC + 13 hours
tcrStandard = {First, Sun, Apr, 3, 720}; //NZST = UTC + 12 hours tcrStandard = {First, Sun, Apr, 3, 720}; //NZST = UTC + 12 hours
break; break;
} }
@ -147,6 +148,11 @@ void updateTimezone() {
tcrStandard = {Last, Sun, Oct, 2, -360}; //CST = UTC - 6 hours tcrStandard = {Last, Sun, Oct, 2, -360}; //CST = UTC - 6 hours
break; break;
} }
case TZ_PAKISTAN : {
tcrDaylight = {Last, Sun, Mar, 1, 300}; //Pakistan Standard Time = UTC + 5 hours
tcrStandard = tcrDaylight;
break;
}
} }
tzCurrent = currentTimezone; tzCurrent = currentTimezone;

View File

@ -13,8 +13,6 @@
#ifndef PalettesWLED_h #ifndef PalettesWLED_h
#define PalettesWLED_h #define PalettesWLED_h
#define GRADIENT_PALETTE_COUNT 58
const byte ib_jul01_gp[] PROGMEM = { const byte ib_jul01_gp[] PROGMEM = {
0, 194, 1, 1, 0, 194, 1, 1,
94, 1, 29, 18, 94, 1, 29, 18,

Some files were not shown because too many files have changed in this diff Show More