2021-10-11 14:13:34 +02:00
|
|
|
#include "wled.h"
|
|
|
|
#include "fcn_declare.h"
|
|
|
|
#include "const.h"
|
|
|
|
|
|
|
|
|
2021-11-23 20:20:19 +01:00
|
|
|
//helper to get int value at a position in string
|
|
|
|
int getNumVal(const String* req, uint16_t pos)
|
|
|
|
{
|
|
|
|
return req->substring(pos+3).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//helper to get int value with in/decrementing support via ~ syntax
|
|
|
|
void parseNumber(const char* str, byte* val, byte minv, byte maxv)
|
|
|
|
{
|
|
|
|
if (str == nullptr || str[0] == '\0') return;
|
2022-06-03 18:38:46 +02:00
|
|
|
if (str[0] == 'r') {*val = random8(minv,maxv?maxv:255); return;} // maxv for random cannot be 0
|
2022-03-04 21:49:07 +01:00
|
|
|
bool wrap = false;
|
|
|
|
if (str[0] == 'w' && strlen(str) > 1) {str++; wrap = true;}
|
2021-11-23 20:20:19 +01:00
|
|
|
if (str[0] == '~') {
|
|
|
|
int out = atoi(str +1);
|
2022-06-03 18:38:46 +02:00
|
|
|
if (out == 0) {
|
2021-11-23 20:20:19 +01:00
|
|
|
if (str[1] == '0') return;
|
2022-06-03 18:38:46 +02:00
|
|
|
if (str[1] == '-') {
|
2021-11-23 20:20:19 +01:00
|
|
|
*val = (int)(*val -1) < (int)minv ? maxv : min((int)maxv,(*val -1)); //-1, wrap around
|
|
|
|
} else {
|
|
|
|
*val = (int)(*val +1) > (int)maxv ? minv : max((int)minv,(*val +1)); //+1, wrap around
|
|
|
|
}
|
|
|
|
} else {
|
2022-03-04 21:49:07 +01:00
|
|
|
if (wrap && *val == maxv && out > 0) out = minv;
|
|
|
|
else if (wrap && *val == minv && out < 0) out = maxv;
|
2023-01-06 09:24:29 +01:00
|
|
|
else {
|
2022-03-04 21:49:07 +01:00
|
|
|
out += *val;
|
|
|
|
if (out > maxv) out = maxv;
|
|
|
|
if (out < minv) out = minv;
|
|
|
|
}
|
2021-11-23 20:20:19 +01:00
|
|
|
*val = out;
|
|
|
|
}
|
2022-06-03 18:38:46 +02:00
|
|
|
return;
|
|
|
|
} else if (minv == maxv && minv == 0) { // limits "unset" i.e. both 0
|
2021-11-23 20:20:19 +01:00
|
|
|
byte p1 = atoi(str);
|
2022-06-03 18:38:46 +02:00
|
|
|
const char* str2 = strchr(str,'~'); // min/max range (for preset cycle, e.g. "1~5~")
|
2021-11-23 20:20:19 +01:00
|
|
|
if (str2) {
|
2022-06-03 18:38:46 +02:00
|
|
|
byte p2 = atoi(++str2); // skip ~
|
|
|
|
if (p2 > 0) {
|
|
|
|
while (isdigit(*(++str2))); // skip digits
|
|
|
|
parseNumber(str2, val, p1, p2);
|
|
|
|
return;
|
|
|
|
}
|
2021-11-23 20:20:19 +01:00
|
|
|
}
|
|
|
|
}
|
2022-06-03 18:38:46 +02:00
|
|
|
*val = atoi(str);
|
2021-11-23 20:20:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool getVal(JsonVariant elem, byte* val, byte vmin, byte vmax) {
|
|
|
|
if (elem.is<int>()) {
|
2021-12-03 21:09:53 +01:00
|
|
|
if (elem < 0) return false; //ignore e.g. {"ps":-1}
|
2021-11-23 20:20:19 +01:00
|
|
|
*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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-03 22:22:18 +02:00
|
|
|
bool updateVal(const char* req, const char* key, byte* val, byte minv, byte maxv)
|
2021-11-23 20:20:19 +01:00
|
|
|
{
|
2022-06-03 22:22:18 +02:00
|
|
|
const char *v = strstr(req, key);
|
|
|
|
if (v) v += strlen(key);
|
|
|
|
else return false;
|
|
|
|
parseNumber(v, val, minv, maxv);
|
2021-11-23 20:20:19 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-11 14:13:34 +02:00
|
|
|
//append a numeric setting to string buffer
|
|
|
|
void sappend(char stype, const char* key, int val)
|
|
|
|
{
|
|
|
|
char ds[] = "d.Sf.";
|
|
|
|
|
|
|
|
switch(stype)
|
|
|
|
{
|
|
|
|
case 'c': //checkbox
|
|
|
|
oappend(ds);
|
|
|
|
oappend(key);
|
|
|
|
oappend(".checked=");
|
|
|
|
oappendi(val);
|
|
|
|
oappend(";");
|
|
|
|
break;
|
|
|
|
case 'v': //numeric
|
|
|
|
oappend(ds);
|
|
|
|
oappend(key);
|
|
|
|
oappend(".value=");
|
|
|
|
oappendi(val);
|
|
|
|
oappend(";");
|
|
|
|
break;
|
|
|
|
case 'i': //selectedIndex
|
|
|
|
oappend(ds);
|
|
|
|
oappend(key);
|
|
|
|
oappend(SET_F(".selectedIndex="));
|
|
|
|
oappendi(val);
|
|
|
|
oappend(";");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//append a string setting to buffer
|
|
|
|
void sappends(char stype, const char* key, char* val)
|
|
|
|
{
|
|
|
|
switch(stype)
|
|
|
|
{
|
|
|
|
case 's': {//string (we can interpret val as char*)
|
|
|
|
String buf = val;
|
|
|
|
//convert "%" to "%%" to make EspAsyncWebServer happy
|
2021-12-08 10:00:31 +01:00
|
|
|
//buf.replace("%","%%");
|
2021-10-11 14:13:34 +02:00
|
|
|
oappend("d.Sf.");
|
|
|
|
oappend(key);
|
|
|
|
oappend(".value=\"");
|
|
|
|
oappend(buf.c_str());
|
|
|
|
oappend("\";");
|
|
|
|
break;}
|
|
|
|
case 'm': //message
|
|
|
|
oappend(SET_F("d.getElementsByClassName"));
|
|
|
|
oappend(key);
|
|
|
|
oappend(SET_F(".innerHTML=\""));
|
|
|
|
oappend(val);
|
|
|
|
oappend("\";");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool oappendi(int i)
|
|
|
|
{
|
|
|
|
char s[11];
|
|
|
|
sprintf(s, "%d", i);
|
|
|
|
return oappend(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool oappend(const char* txt)
|
|
|
|
{
|
|
|
|
uint16_t len = strlen(txt);
|
2021-11-09 17:49:05 +01:00
|
|
|
if (olen + len >= SETTINGS_STACK_BUF_SIZE)
|
2021-10-11 14:13:34 +02:00
|
|
|
return false; // buffer full
|
|
|
|
strcpy(obuf + olen, txt);
|
|
|
|
olen += len;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void prepareHostname(char* hostname)
|
|
|
|
{
|
2022-10-10 16:46:23 +02:00
|
|
|
sprintf_P(hostname, "wled-%*s", 6, escapedMac.c_str() + 6);
|
2021-10-11 14:13:34 +02:00
|
|
|
const char *pC = serverDescription;
|
2022-10-10 16:46:23 +02:00
|
|
|
uint8_t pos = 5; // keep "wled-"
|
2021-10-11 14:13:34 +02:00
|
|
|
while (*pC && pos < 24) { // while !null and not over length
|
|
|
|
if (isalnum(*pC)) { // if the current char is alpha-numeric append it to the hostname
|
|
|
|
hostname[pos] = *pC;
|
|
|
|
pos++;
|
|
|
|
} else if (*pC == ' ' || *pC == '_' || *pC == '-' || *pC == '+' || *pC == '!' || *pC == '?' || *pC == '*') {
|
|
|
|
hostname[pos] = '-';
|
|
|
|
pos++;
|
|
|
|
}
|
2022-10-10 16:46:23 +02:00
|
|
|
// else do nothing - no leading hyphens and do not include hyphens for all other characters.
|
|
|
|
pC++;
|
|
|
|
}
|
|
|
|
//last character must not be hyphen
|
2022-10-13 14:25:01 +02:00
|
|
|
if (pos > 5) {
|
|
|
|
while (pos > 4 && hostname[pos -1] == '-') pos--;
|
|
|
|
hostname[pos] = '\0'; // terminate string (leave at least "wled")
|
2022-10-10 16:46:23 +02:00
|
|
|
}
|
2021-10-11 14:13:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool isAsterisksOnly(const char* str, byte maxLen)
|
|
|
|
{
|
|
|
|
for (byte i = 0; i < maxLen; i++) {
|
|
|
|
if (str[i] == 0) break;
|
|
|
|
if (str[i] != '*') return false;
|
|
|
|
}
|
|
|
|
//at this point the password contains asterisks only
|
|
|
|
return (str[0] != 0); //false on empty string
|
|
|
|
}
|
2021-11-12 23:33:10 +01:00
|
|
|
|
|
|
|
|
2021-12-04 01:05:01 +01:00
|
|
|
//threading/network callback details: https://github.com/Aircoookie/WLED/pull/2336#discussion_r762276994
|
2021-11-14 16:56:34 +01:00
|
|
|
bool requestJSONBufferLock(uint8_t module)
|
2021-11-12 23:33:10 +01:00
|
|
|
{
|
|
|
|
unsigned long now = millis();
|
|
|
|
|
|
|
|
while (jsonBufferLock && millis()-now < 1000) delay(1); // wait for a second for buffer lock
|
|
|
|
|
2021-11-14 16:56:34 +01:00
|
|
|
if (millis()-now >= 1000) {
|
|
|
|
DEBUG_PRINT(F("ERROR: Locking JSON buffer failed! ("));
|
|
|
|
DEBUG_PRINT(jsonBufferLock);
|
|
|
|
DEBUG_PRINTLN(")");
|
|
|
|
return false; // waiting time-outed
|
|
|
|
}
|
2021-11-12 23:33:10 +01:00
|
|
|
|
2021-11-14 16:56:34 +01:00
|
|
|
jsonBufferLock = module ? module : 255;
|
2022-05-20 19:35:22 +02:00
|
|
|
DEBUG_PRINT(F("JSON buffer locked. ("));
|
|
|
|
DEBUG_PRINT(jsonBufferLock);
|
|
|
|
DEBUG_PRINTLN(")");
|
2021-11-12 23:33:10 +01:00
|
|
|
fileDoc = &doc; // used for applying presets (presets.cpp)
|
|
|
|
doc.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void releaseJSONBufferLock()
|
|
|
|
{
|
2021-11-14 16:56:34 +01:00
|
|
|
DEBUG_PRINT(F("JSON buffer released. ("));
|
|
|
|
DEBUG_PRINT(jsonBufferLock);
|
|
|
|
DEBUG_PRINTLN(")");
|
2021-11-12 23:33:10 +01:00
|
|
|
fileDoc = nullptr;
|
2021-11-14 16:56:34 +01:00
|
|
|
jsonBufferLock = 0;
|
2021-11-12 23:33:10 +01:00
|
|
|
}
|
2022-01-31 20:35:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
// extracts effect mode (or palette) name from names serialized string
|
2022-01-31 20:43:35 +01:00
|
|
|
// caller must provide large enough buffer for name (incluing SR extensions)!
|
2022-01-31 20:35:11 +01:00
|
|
|
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen)
|
|
|
|
{
|
2022-05-24 13:45:35 +02:00
|
|
|
if (src == JSON_mode_names || src == nullptr) {
|
2022-06-26 23:01:22 +02:00
|
|
|
if (mode < strip.getModeCount()) {
|
2022-05-21 18:37:09 +02:00
|
|
|
char lineBuffer[256];
|
2022-05-22 00:41:45 +02:00
|
|
|
//strcpy_P(lineBuffer, (const char*)pgm_read_dword(&(WS2812FX::_modeData[mode])));
|
2022-06-21 22:49:45 +02:00
|
|
|
strcpy_P(lineBuffer, strip.getModeData(mode));
|
2022-07-10 22:23:25 +02:00
|
|
|
size_t len = strlen(lineBuffer);
|
|
|
|
size_t j = 0;
|
|
|
|
for (; j < maxLen && j < len; j++) {
|
|
|
|
if (lineBuffer[j] == '\0' || lineBuffer[j] == '@') break;
|
|
|
|
dest[j] = lineBuffer[j];
|
2022-05-21 18:37:09 +02:00
|
|
|
}
|
2022-07-10 22:23:25 +02:00
|
|
|
dest[j] = 0; // terminate string
|
2022-05-21 18:37:09 +02:00
|
|
|
return strlen(dest);
|
|
|
|
} else return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-31 20:35:11 +01:00
|
|
|
uint8_t qComma = 0;
|
|
|
|
bool insideQuotes = false;
|
|
|
|
uint8_t printedChars = 0;
|
|
|
|
char singleJsonSymbol;
|
|
|
|
size_t len = strlen_P(src);
|
|
|
|
|
|
|
|
// Find the mode name in JSON
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
singleJsonSymbol = pgm_read_byte_near(src + i);
|
|
|
|
if (singleJsonSymbol == '\0') break;
|
|
|
|
if (singleJsonSymbol == '@' && insideQuotes && qComma == mode) break; //stop when SR extension encountered
|
|
|
|
switch (singleJsonSymbol) {
|
|
|
|
case '"':
|
|
|
|
insideQuotes = !insideQuotes;
|
|
|
|
break;
|
|
|
|
case '[':
|
|
|
|
case ']':
|
|
|
|
break;
|
|
|
|
case ',':
|
|
|
|
if (!insideQuotes) qComma++;
|
|
|
|
default:
|
|
|
|
if (!insideQuotes || (qComma != mode)) break;
|
|
|
|
dest[printedChars++] = singleJsonSymbol;
|
|
|
|
}
|
|
|
|
if ((qComma > mode) || (printedChars >= maxLen)) break;
|
|
|
|
}
|
|
|
|
dest[printedChars] = '\0';
|
|
|
|
return strlen(dest);
|
|
|
|
}
|
2022-05-20 14:48:40 +02:00
|
|
|
|
2022-05-24 13:45:35 +02:00
|
|
|
|
|
|
|
// extracts effect slider data (1st group after @)
|
2022-07-23 22:00:19 +02:00
|
|
|
uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxLen, uint8_t *var)
|
2022-05-24 13:45:35 +02:00
|
|
|
{
|
|
|
|
dest[0] = '\0'; // start by clearing buffer
|
|
|
|
|
2022-06-26 23:01:22 +02:00
|
|
|
if (mode < strip.getModeCount()) {
|
2022-08-03 21:36:47 +02:00
|
|
|
String lineBuffer = FPSTR(strip.getModeData(mode));
|
2022-05-24 13:45:35 +02:00
|
|
|
if (lineBuffer.length() > 0) {
|
|
|
|
int16_t start = lineBuffer.indexOf('@');
|
|
|
|
int16_t stop = lineBuffer.indexOf(';', start);
|
|
|
|
if (start>0 && stop>0) {
|
2022-07-23 22:00:19 +02:00
|
|
|
String names = lineBuffer.substring(start, stop); // include @
|
|
|
|
int16_t nameBegin = 1, nameEnd, nameDefault;
|
|
|
|
if (slider < 10) {
|
|
|
|
for (size_t i=0; i<=slider; i++) {
|
|
|
|
const char *tmpstr;
|
|
|
|
dest[0] = '\0'; //clear dest buffer
|
|
|
|
if (nameBegin == 0) break; // there are no more names
|
|
|
|
nameEnd = names.indexOf(',', nameBegin);
|
|
|
|
if (i == slider) {
|
|
|
|
nameDefault = names.indexOf('=', nameBegin); // find default value
|
|
|
|
if (nameDefault > 0 && var && ((nameEnd>0 && nameDefault<nameEnd) || nameEnd<0)) {
|
|
|
|
*var = (uint8_t)atoi(names.substring(nameDefault+1).c_str());
|
|
|
|
}
|
|
|
|
if (names.charAt(nameBegin) == '!') {
|
|
|
|
switch (slider) {
|
|
|
|
case 0: tmpstr = PSTR("FX Speed"); break;
|
|
|
|
case 1: tmpstr = PSTR("FX Intensity"); break;
|
|
|
|
case 2: tmpstr = PSTR("FX Custom 1"); break;
|
|
|
|
case 3: tmpstr = PSTR("FX Custom 2"); break;
|
|
|
|
case 4: tmpstr = PSTR("FX Custom 3"); break;
|
|
|
|
default: tmpstr = PSTR("FX Custom"); break;
|
|
|
|
}
|
2022-08-03 22:27:45 +02:00
|
|
|
strncpy_P(dest, tmpstr, maxLen); // copy the name into buffer (replacing previous)
|
|
|
|
dest[maxLen-1] = '\0';
|
2022-07-23 22:00:19 +02:00
|
|
|
} else {
|
|
|
|
if (nameEnd<0) tmpstr = names.substring(nameBegin).c_str(); // did not find ",", last name?
|
|
|
|
else tmpstr = names.substring(nameBegin, nameEnd).c_str();
|
2022-08-03 22:27:45 +02:00
|
|
|
strlcpy(dest, tmpstr, maxLen); // copy the name into buffer (replacing previous)
|
2022-07-23 22:00:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nameBegin = nameEnd+1; // next name (if "," is not found it will be 0)
|
|
|
|
} // next slider
|
|
|
|
} else if (slider == 255) {
|
|
|
|
// palette
|
|
|
|
strlcpy(dest, "pal", maxLen);
|
|
|
|
names = lineBuffer.substring(stop+1); // stop has index of color slot names
|
|
|
|
nameBegin = names.indexOf(';'); // look for palette
|
|
|
|
if (nameBegin >= 0) {
|
2022-07-23 22:38:35 +02:00
|
|
|
nameEnd = names.indexOf(';', nameBegin+1);
|
2022-07-23 22:00:19 +02:00
|
|
|
if (!isdigit(names[nameBegin+1])) nameBegin = names.indexOf('=', nameBegin+1); // look for default value
|
2022-07-23 22:38:35 +02:00
|
|
|
if (nameEnd >= 0 && nameBegin > nameEnd) nameBegin = -1;
|
2022-07-23 22:00:19 +02:00
|
|
|
if (nameBegin >= 0 && var) {
|
|
|
|
*var = (uint8_t)atoi(names.substring(nameBegin+1).c_str());
|
2022-05-24 13:45:35 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-23 22:00:19 +02:00
|
|
|
}
|
2022-05-24 13:45:35 +02:00
|
|
|
// we have slider name (including default value) in the dest buffer
|
|
|
|
for (size_t i=0; i<strlen(dest); i++) if (dest[i]=='=') { dest[i]='\0'; break; } // truncate default value
|
2023-01-06 09:24:29 +01:00
|
|
|
|
2022-05-24 13:45:35 +02:00
|
|
|
} else {
|
|
|
|
// defaults to just speed and intensity since there is no slider data
|
|
|
|
switch (slider) {
|
|
|
|
case 0: strncpy_P(dest, PSTR("FX Speed"), maxLen); break;
|
|
|
|
case 1: strncpy_P(dest, PSTR("FX Intensity"), maxLen); break;
|
|
|
|
}
|
2022-07-23 22:00:19 +02:00
|
|
|
dest[maxLen] = '\0'; // strncpy does not necessarily null terminate string
|
2022-05-24 13:45:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return strlen(dest);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 02:26:26 +02:00
|
|
|
// extracts mode parameter defaults from last section of mode data (e.g. "Juggle@!,Trail;!,!,;!;sx=16,ix=240,1d")
|
2022-07-23 22:00:19 +02:00
|
|
|
int16_t extractModeDefaults(uint8_t mode, const char *segVar)
|
|
|
|
{
|
|
|
|
if (mode < strip.getModeCount()) {
|
2022-08-31 02:26:26 +02:00
|
|
|
char lineBuffer[128] = "";
|
2022-08-31 04:31:56 +02:00
|
|
|
strncpy_P(lineBuffer, strip.getModeData(mode), 127);
|
|
|
|
lineBuffer[127] = '\0'; // terminate string
|
|
|
|
if (lineBuffer[0] != 0) {
|
2022-08-31 02:26:26 +02:00
|
|
|
char* startPtr = strrchr(lineBuffer, ';'); // last ";" in FX data
|
|
|
|
if (!startPtr) return -1;
|
|
|
|
|
|
|
|
char* stopPtr = strstr(startPtr, segVar);
|
|
|
|
if (!stopPtr) return -1;
|
2022-07-23 22:00:19 +02:00
|
|
|
|
2022-08-31 04:31:56 +02:00
|
|
|
stopPtr += strlen(segVar) +1; // skip "="
|
2022-08-31 02:26:26 +02:00
|
|
|
return atoi(stopPtr);
|
2022-07-23 22:00:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-20 14:48:40 +02:00
|
|
|
uint16_t crc16(const unsigned char* data_p, size_t length) {
|
|
|
|
uint8_t x;
|
|
|
|
uint16_t crc = 0xFFFF;
|
|
|
|
if (!length) return 0x1D0F;
|
|
|
|
while (length--) {
|
|
|
|
x = crc >> 8 ^ *data_p++;
|
|
|
|
x ^= x>>4;
|
|
|
|
crc = (crc << 8) ^ ((uint16_t)(x << 12)) ^ ((uint16_t)(x <<5)) ^ ((uint16_t)x);
|
|
|
|
}
|
|
|
|
return crc;
|
2022-07-25 21:31:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Begin simulateSound (to enable audio enhanced effects to display something)
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Currently 4 types defined, to be fine tuned and new types added
|
|
|
|
typedef enum UM_SoundSimulations {
|
|
|
|
UMS_BeatSin = 0,
|
|
|
|
UMS_WeWillRockYou,
|
|
|
|
UMS_10_3,
|
|
|
|
UMS_14_3
|
|
|
|
} um_soundSimulations_t;
|
|
|
|
|
2023-01-06 09:24:29 +01:00
|
|
|
um_data_t* simulateSound(uint8_t simulationId)
|
2022-07-25 21:31:50 +02:00
|
|
|
{
|
|
|
|
static uint8_t samplePeak;
|
|
|
|
static float FFT_MajorPeak;
|
|
|
|
static uint8_t maxVol;
|
|
|
|
static uint8_t binNum;
|
|
|
|
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
static float volumeSmth;
|
|
|
|
static uint16_t volumeRaw;
|
|
|
|
static float my_magnitude;
|
2022-07-25 21:31:50 +02:00
|
|
|
|
|
|
|
//arrays
|
|
|
|
uint8_t *fftResult;
|
|
|
|
|
|
|
|
static um_data_t* um_data = nullptr;
|
|
|
|
|
|
|
|
if (!um_data) {
|
|
|
|
//claim storage for arrays
|
|
|
|
fftResult = (uint8_t *)malloc(sizeof(uint8_t) * 16);
|
|
|
|
|
|
|
|
// initialize um_data pointer structure
|
|
|
|
// NOTE!!!
|
|
|
|
// This may change as AudioReactive usermod may change
|
|
|
|
um_data = new um_data_t;
|
2022-07-29 15:50:09 +02:00
|
|
|
um_data->u_size = 8;
|
2022-07-25 21:31:50 +02:00
|
|
|
um_data->u_type = new um_types_t[um_data->u_size];
|
|
|
|
um_data->u_data = new void*[um_data->u_size];
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
um_data->u_data[0] = &volumeSmth;
|
|
|
|
um_data->u_data[1] = &volumeRaw;
|
2023-01-06 09:24:29 +01:00
|
|
|
um_data->u_data[2] = fftResult;
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
um_data->u_data[3] = &samplePeak;
|
|
|
|
um_data->u_data[4] = &FFT_MajorPeak;
|
|
|
|
um_data->u_data[5] = &my_magnitude;
|
|
|
|
um_data->u_data[6] = &maxVol;
|
|
|
|
um_data->u_data[7] = &binNum;
|
2022-07-25 21:31:50 +02:00
|
|
|
} else {
|
|
|
|
// get arrays from um_data
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
fftResult = (uint8_t*)um_data->u_data[2];
|
2022-07-25 21:31:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ms = millis();
|
|
|
|
|
|
|
|
switch (simulationId) {
|
|
|
|
default:
|
|
|
|
case UMS_BeatSin:
|
|
|
|
for (int i = 0; i<16; i++)
|
|
|
|
fftResult[i] = beatsin8(120 / (i+1), 0, 255);
|
|
|
|
// fftResult[i] = (beatsin8(120, 0, 255) + (256/16 * i)) % 256;
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = fftResult[8];
|
2022-07-25 21:31:50 +02:00
|
|
|
break;
|
|
|
|
case UMS_WeWillRockYou:
|
|
|
|
if (ms%2000 < 200) {
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = random8(255);
|
2022-07-25 21:31:50 +02:00
|
|
|
for (int i = 0; i<5; i++)
|
|
|
|
fftResult[i] = random8(255);
|
|
|
|
}
|
|
|
|
else if (ms%2000 < 400) {
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = 0;
|
2022-07-25 21:31:50 +02:00
|
|
|
for (int i = 0; i<16; i++)
|
|
|
|
fftResult[i] = 0;
|
|
|
|
}
|
|
|
|
else if (ms%2000 < 600) {
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = random8(255);
|
2022-07-25 21:31:50 +02:00
|
|
|
for (int i = 5; i<11; i++)
|
|
|
|
fftResult[i] = random8(255);
|
|
|
|
}
|
|
|
|
else if (ms%2000 < 800) {
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = 0;
|
2022-07-25 21:31:50 +02:00
|
|
|
for (int i = 0; i<16; i++)
|
|
|
|
fftResult[i] = 0;
|
|
|
|
}
|
|
|
|
else if (ms%2000 < 1000) {
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = random8(255);
|
2022-07-25 21:31:50 +02:00
|
|
|
for (int i = 11; i<16; i++)
|
|
|
|
fftResult[i] = random8(255);
|
|
|
|
}
|
|
|
|
else {
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = 0;
|
2022-07-25 21:31:50 +02:00
|
|
|
for (int i = 0; i<16; i++)
|
|
|
|
fftResult[i] = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UMS_10_3:
|
|
|
|
for (int i = 0; i<16; i++)
|
|
|
|
fftResult[i] = inoise8(beatsin8(90 / (i+1), 0, 200)*15 + (ms>>10), ms>>3);
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = fftResult[8];
|
2022-07-25 21:31:50 +02:00
|
|
|
break;
|
|
|
|
case UMS_14_3:
|
|
|
|
for (int i = 0; i<16; i++)
|
|
|
|
fftResult[i] = inoise8(beatsin8(120 / (i+1), 10, 30)*10 + (ms>>14), ms>>3);
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeSmth = fftResult[8];
|
2022-07-25 21:31:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
samplePeak = random8() > 250;
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
FFT_MajorPeak = volumeSmth;
|
2022-07-25 21:31:50 +02:00
|
|
|
maxVol = 10; // this gets feedback fro UI
|
|
|
|
binNum = 8; // this gets feedback fro UI
|
Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
|
|
|
volumeRaw = volumeSmth;
|
|
|
|
my_magnitude = 10000.0 / 8.0f; //no idea if 10000 is a good value for FFT_Magnitude ???
|
|
|
|
if (volumeSmth < 1 ) my_magnitude = 0.001f; // noise gate closed - mute
|
2022-07-25 21:31:50 +02:00
|
|
|
|
|
|
|
return um_data;
|
|
|
|
}
|
2022-08-10 20:53:11 +02:00
|
|
|
|
|
|
|
|
2023-02-14 17:11:58 +01:00
|
|
|
// enumerate all ledmapX.json files on FS and extract ledmap names if existing
|
2022-08-10 20:53:11 +02:00
|
|
|
void enumerateLedmaps() {
|
|
|
|
ledMaps = 1;
|
2023-02-14 17:11:58 +01:00
|
|
|
for (size_t i=1; i<WLED_MAX_LEDMAPS; i++) {
|
|
|
|
char fileName[33];
|
2022-08-10 20:53:11 +02:00
|
|
|
sprintf_P(fileName, PSTR("/ledmap%d.json"), i);
|
|
|
|
bool isFile = WLED_FS.exists(fileName);
|
2023-02-14 17:11:58 +01:00
|
|
|
|
|
|
|
#ifndef ESP8266
|
|
|
|
if (ledmapNames[i-1]) { //clear old name
|
|
|
|
delete[] ledmapNames[i-1];
|
|
|
|
ledmapNames[i-1] = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (isFile) {
|
|
|
|
ledMaps |= 1 << i;
|
|
|
|
|
|
|
|
#ifndef ESP8266
|
|
|
|
if (requestJSONBufferLock(21)) {
|
|
|
|
if (readObjectFromFile(fileName, nullptr, &doc)) {
|
|
|
|
size_t len = 0;
|
|
|
|
if (!doc["n"].isNull()) {
|
|
|
|
// name field exists
|
|
|
|
const char *name = doc["n"].as<const char*>();
|
|
|
|
if (name != nullptr) len = strlen(name);
|
|
|
|
if (len > 0 && len < 33) {
|
|
|
|
ledmapNames[i-1] = new char[len+1];
|
|
|
|
if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], name, 33);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ledmapNames[i-1]) {
|
|
|
|
char tmp[33];
|
|
|
|
snprintf_P(tmp, 32, PSTR("ledmap%d.json"), i);
|
|
|
|
len = strlen(tmp);
|
|
|
|
ledmapNames[i-1] = new char[len+1];
|
|
|
|
if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], tmp, 33);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
releaseJSONBufferLock();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-10 20:53:11 +02:00
|
|
|
}
|
|
|
|
}
|